commit 759a8968a280083a212658774bcf15aaab0c71a1 Author: Francisco Jesús Martínez Mimbrera Date: Sat May 23 00:32:57 2026 +0200 public code v1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b3a2109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +.DS_Store +/.metadata/ +# https://stackoverflow.com/questions/1470572/ignoring-any-bin-directory-on-a-git-project +*.class +bin/ +target/ + +# Ignore Maven Output +target/ + +# Ignore Visual Studio Code +.vs/ \ No newline at end of file diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml new file mode 100644 index 0000000..8332e3f --- /dev/null +++ b/.mvn/extensions.xml @@ -0,0 +1,7 @@ + + + org.eclipse.tycho.extras + tycho-pomless + 2.0.0 + + \ No newline at end of file diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1462bc0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM maven:3.8.6-eclipse-temurin-11 + +# GTK3 + X11 para poder ejecutar la app dentro del contenedor +RUN apt-get update && apt-get install -y \ + libgtk-3-0 \ + libwebkit2gtk-4.0-37 \ + libcanberra-gtk-module \ + libcanberra-gtk3-module \ + xvfb \ + x11vnc \ + x11-utils \ + fonts-dejavu \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /project + +# Pre-cacheamos dependencias de Maven (se ejecuta solo si pom.xml cambia) +COPY pom.xml . +COPY .mvn .mvn +COPY releng/flintstones.application.configuration/pom.xml releng/flintstones.application.configuration/pom.xml +RUN mvn dependency:go-offline -N -f releng/flintstones.application.configuration/pom.xml 2>/dev/null || true + +# Copiamos el resto del proyecto +COPY . . + +# Build completo +RUN mvn clean install -Dmaven.test.skip=true + +CMD ["bash"] diff --git a/Dockerfile.run b/Dockerfile.run new file mode 100644 index 0000000..fe844d0 --- /dev/null +++ b/Dockerfile.run @@ -0,0 +1,27 @@ +FROM --platform=linux/amd64 eclipse-temurin:11-jre-focal + +RUN apt-get update && apt-get install -y \ + libgtk-3-0 \ + libwebkit2gtk-4.0-37 \ + libcanberra-gtk3-module \ + libglib2.0-0 \ + tigervnc-standalone-server \ + tigervnc-common \ + novnc \ + websockify \ + openbox \ + x11-xkb-utils \ + xkb-data \ + fonts-dejavu \ + fonts-liberation \ + && rm -rf /var/lib/apt/lists/* + +EXPOSE 6080 + +ENV DISPLAY=:1 +ENV LANG=es_ES.UTF-8 + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..e058524 --- /dev/null +++ b/README.md @@ -0,0 +1,409 @@ +# Flintstones + +Plataforma de escritorio para **Toma de Decisiones Multi-Criterio (MCDM/MCDA)** desarrollada por el grupo de investigación [Sinbad2](http://sinbad2.ujaen.es/) de la Universidad de Jaén. + +Flintstones permite definir un problema de decisión (alternativas, criterios, expertos, dominios) y resolverlo con una amplia colección de métodos de ayuda a la decisión, desde AHP clásico hasta modelos lingüísticos avanzados basados en conjuntos difusos y 2-tuplas. + +--- + +## Tabla de contenidos + +- [Requisitos](#requisitos) +- [Compilar](#compilar) +- [Ejecutar](#ejecutar) +- [Métodos disponibles](#métodos-disponibles) +- [Tipos de información](#tipos-de-información) +- [Operadores](#operadores) +- [Arquitectura del proyecto](#arquitectura-del-proyecto) +- [Estructura de directorios](#estructura-de-directorios) +- [Flujo de trabajo en la aplicación](#flujo-de-trabajo-en-la-aplicación) +- [Problemas conocidos resueltos](#problemas-conocidos-resueltos) + +--- + +## Requisitos + +| Herramienta | Versión mínima | Notas | +|---|---|---| +| Docker | 20+ | Para compilar sin instalar nada más | +| Java | 11 | Solo para ejecutar el producto compilado | +| Maven | 3.8+ | Solo si compilas fuera de Docker | + +> **Sin Docker:** necesitas JDK 11 y Maven 3.8+. +> **Con Docker:** solo Docker. El contenedor lleva Maven 3.8.6 y JDK 11. + +--- + +## Compilar + +### Con Docker (recomendado) + +```bash +./build.sh +``` + +O directamente: + +```bash +docker compose run --rm build +``` + +La primera vez descarga dependencias de Eclipse (~1-2 GB). Las siguientes compilaciones usan caché y son mucho más rápidas. + +Los productos quedan en: + +``` +releng/flintstones.application.product/target/products/ + RCP product-linux.gtk.x86_64.zip + RCP product-macosx.cocoa.x86_64.zip + RCP product-win32.win32.x86_64.zip +``` + +### Sin Docker + +```bash +mvn clean install -Dmaven.test.skip=true +``` + +--- + +## Ejecutar + +### macOS + +```bash +cd releng/flintstones.application.product/target/products/ +unzip "RCP product-macosx.cocoa.x86_64.zip" +open Eclipse.app +``` + +> El ejecutable se llama `Eclipse.app` por herencia del launcher de Eclipse RCP. +> En Apple Silicon (M1/M2/M3) funciona vía Rosetta 2 (arquitectura x86_64). + +### Linux + +```bash +cd releng/flintstones.application.product/target/products/ +unzip "RCP product-linux.gtk.x86_64.zip" +./"RCP product"/linux/gtk/x86_64/flinstones +``` + +Requiere GTK3: +```bash +sudo apt install libgtk-3-0 # Debian/Ubuntu +``` + +### Linux con VNC (desde Docker) + +Levanta el contenedor con display virtual accesible en `localhost:5900`: + +```bash +docker compose run --rm run-vnc +``` + +Conéctate con cualquier cliente VNC (RealVNC, TigerVNC, etc.) a `localhost:5900`. + +### Windows + +Descomprime `RCP product-win32.win32.x86_64.zip` y ejecuta `flinstones.exe`. + +--- + +## Métodos disponibles + +### Métodos clásicos / Ranking + +| Método | Bundle | Descripción | +|---|---|---| +| **AHP** | `flintstones.method.ahp` | Analytic Hierarchy Process. Descomposición jerárquica de un problema con comparaciones por pares. | +| **AHP-Sort** | `flintstones.method.ahp.sort` | Variante de clasificación (sorting) sobre AHP. | +| **AHP-SortII** | `flintstones.method.ahp.sortii` | Segunda versión de AHP-Sort con agregación grupal mejorada. | +| **AHP-Sort Fuzzy** | `flintstones.method.ahp.sort.fuzzy` | AHP-Sort con información difusa. | +| **Numeric TOPSIS** | `flintstones.method.decision.topsis.numeric` | TOPSIS clásico (Hwang & Yoon, 1981). Alternativa más próxima a la solución ideal positiva y más alejada de la negativa. | +| **VIKOR** | `flintstones.method.vikor` | Método de compromiso para criterios conflictivos (Opricovic). | +| **Fuzzy VIKOR** | `flintstones.method.vikorFuzzy` | VIKOR con pesos y criterios como números difusos triangulares. | +| **ELECTRE** | `flintstones.method.electre` | Método de superación (outranking) con relaciones de concordancia y discordancia. | +| **PROMETHEE** | `flintstones.method.promethee` | Outranking basado en flujos netos de preferencia. | +| **FlowSort** | `flintstones.method.flowsort` | Extensión de PROMETHEE para problemas de clasificación. | +| **TODIM** | `flintstones.method.todim` | Basado en la Teoría Prospectiva, modela el comportamiento del decisor ante ganancias y pérdidas. | +| **MMOORA** | `flintstones.method.mmoora` | Multi-MOORA: combina ratio system, reference point y full multiplicative form. | +| **Fuzzy MMOORA** | `flintstones.method.mmooraFuzzy` | MMOORA con información difusa. | +| **WASPAS** | `flintstones.method.waspas` | Weighted Aggregated Sum Product ASsessment: combinación de WSM y WPM. | +| **Fuzzy WASPAS** | `flintstones.method.waspasFuzzy` | WASPAS con números difusos. | +| **dEvaluation** | `flintstones.method.dEvaluation` | *(en desarrollo)* | + +### Métodos lingüísticos y difusos + +| Método | Bundle | Descripción | +|---|---|---| +| **2-Tuple** | `flintstones.method.twoTuple` | Modelo 2-tupla lingüística (Herrera & Martínez, 2000). Elimina pérdida de información en la fusión lingüística. | +| **Hesitant Linguistic** | `flintstones.method.linguistic.hesitant` | MCDM con expresiones lingüísticas comparativas y 2-tuplas para retranslación. | +| **HFLTS** | `flintstones.method.linguistic.hflts` | Hesitant Fuzzy Linguistic Term Sets. Para expertos que dudan entre varios términos lingüísticos. | +| **ELICIT** | `flintstones.method.linguistic.elicit` | Extended Comparative Linguistic Expressions with Symbolic Translation. Modelo de representación lingüística más rico que la 2-tupla. | +| **Linguistic TOPSIS** | `flintstones.method.linguistic.topsis` | TOPSIS con modelo 2-tupla y función de distancia mejorada. | +| **Heterogeneous Fusion** | `flintstones.method.linguistic.heterogeneous.fusion` | Fusión de información heterogénea (numérica, lingüística, intervalar) con 2-tuplas. | +| **Unbalanced Linguistic** | `flintstones.method.linguistic.unbalanced` | Conjuntos de términos lingüísticos no uniformes ni simétricos. | +| **Multigranular LH** | `flintstones.method.linguistic.multigranular.lh` | Jerarquías lingüísticas para información multigranular. | +| **Multigranular ELH** | `flintstones.method.linguistic.multigranular.elh` | Jerarquía lingüística extendida (ELH) para mayor flexibilidad de escalas. | +| **Multigranular Fusion** | `flintstones.method.linguistic.multigranular.fusion` | Fusión multigranular sin restricciones en las escalas, con principio de extensión. | +| **Fuzzy TOPSIS** | `flintstones.method.topsisFuzzy` | TOPSIS con valoraciones difusas. | +| **Numeric Common Aggregation** | `flintstones.method.numeric.common.aggregation` | Agregación con información numérica. | + +--- + +## Tipos de información + +### Dominios de valoración + +| Tipo | Bundle | Descripción | +|---|---|---| +| **Fuzzy Set** | `flintstones.domain.fuzzyset` | Conjuntos difusos (números difusos triangulares). | +| **Unbalanced Fuzzy Set** | `flintstones.domain.fuzzyset.unbalanced` | Conjuntos difusos con distribución no uniforme. | +| **Integer Numeric** | `flintstones.domain.numeric.integer` | Dominio numérico entero. | +| **Real Numeric** | `flintstones.domain.numeric.real` | Dominio numérico real. | + +### Tipos de valoración (Valuations) + +| Tipo | Bundle | +|---|---| +| Lingüística (2-tupla) | `flintstones.valuation.linguistic` | +| ELICIT | `flintstones.valuation.elicit` | +| Hesitant (HFLTS) | `flintstones.valuation.hesitant` | +| Unbalanced | `flintstones.valuation.unbalanced` | +| 2-Tupla | `flintstones.valuation.twoTuple` | +| Proporcional 2-Tupla | `flintstones.valuation.proportionaltwotuple` | +| AHP | `flintstones.valuation.ahp` | +| Numérica entera | `flintstones.valuation.numeric.integer` | +| Numérica entera (intervalo) | `flintstones.valuation.numeric.integer.interval` | +| Numérica real | `flintstones.valuation.numeric.real` | +| Numérica real (intervalo) | `flintstones.valuation.numeric.real.interval` | +| Unificada | `flintstones.valuation.unifiedValuation` | +| Difusa | `flintstones.valuation.fuzzy` | + +--- + +## Operadores + +### Agregación + +| Operador | Bundle | +|---|---| +| Media aritmética | `flintstones.operator.aggregation.arithmeticmean` | +| Media geométrica | `flintstones.operator.aggregation.geometricMean` | +| Media armónica | `flintstones.operator.aggregation.harmonicmean` | +| OWA (Ordered Weighted Averaging) | `flintstones.operator.aggregation.owa` | +| Mínimo | `flintstones.operator.aggregation.min` | +| Máximo | `flintstones.operator.aggregation.max` | +| MinMax | `flintstones.operator.aggregation.minmax` | +| Mediana | `flintstones.operator.aggregation.median` | +| Integral de Choquet | `flintstones.operator.aggregation.choquetIntegral` | +| Media de Bonferroni | `flintstones.operator.aggregation.bonferroniMean` | + +Los pesos para OWA se calculan con cuantificadores de Yager (`flintstones.quantifiers.yager`). + +### Normalización (métodos numéricos) + +| Operador | Bundle | +|---|---| +| Ideal | `flintstones.operator.normalization.numeric.ideal` | +| Distribuida | `flintstones.operator.normalization.numeric.distributed` | + +### Unificación (métodos lingüísticos) + +| Operador | Bundle | +|---|---| +| 2-Tupla | `flintstones.operator.unification.twotuple` | +| ELICIT | `flintstones.operator.unification.elicit` | +| Difusa | `flintstones.operator.unification.fuzzy` | + +--- + +## Arquitectura del proyecto + +Flintstones es una aplicación **Eclipse 4 RCP** (Rich Client Platform) basada en OSGi. Cada funcionalidad se encapsula como un bundle independiente con dependencias declaradas en `META-INF/MANIFEST.MF`. + +``` +┌─────────────────────────────────────────────────────┐ +│ Eclipse E4 RCP Shell │ +│ (workbench, perspectives, parts, DI) │ +├──────────────┬──────────────┬───────────────────────┤ +│ application │ framework │ perspective.* │ +│ (UI global) │ (UI MCDM) │ (panels por etapa) │ +├──────────────┴──────────────┴───────────────────────┤ +│ method.* (implementación métodos) │ +├─────────────────────────────────────────────────────┤ +│ entity.* │ valuation.* │ domain.* │ operator.* │ +│ (modelo) │ (valoraciones)│ (dominios)│ (operadores│ +├───────────┴───────────────┴────────────┴────────────┤ +│ model.*.service / model.*.provider │ +│ (capa de servicios OSGi, acceso a datos) │ +├─────────────────────────────────────────────────────┤ +│ helper.* (utilidades: I/O, datos, validación) │ +└─────────────────────────────────────────────────────┘ +``` + +### Patrón service / provider + +Cada modelo de datos tiene dos bundles: +- `flintstones.model.X.service` — interfaz OSGi (contrato) +- `flintstones.model.X.provider` — implementación concreta + +Los bundles se conectan vía inyección de dependencias de Eclipse E4 (`@Inject`). + +### Motor R + +El bundle `flintstones.engine.R` integra el motor estadístico R para cálculos avanzados. + +--- + +## Estructura de directorios + +``` +flintstones-develop/ +├── bundles/ # Todos los plugins OSGi (~250 bundles) +│ ├── flintstones.application/ # Bundle principal (E4 app model) +│ ├── flintstones.application.*/ # UI de la aplicación +│ ├── flintstones.domain.*/ # Tipos de dominio de valoración +│ ├── flintstones.entity.*/ # Entidades del modelo de dominio +│ ├── flintstones.method.*/ # Implementaciones de métodos MCDM +│ ├── flintstones.model.*.service/ # Interfaces de servicio OSGi +│ ├── flintstones.model.*.provider/ # Implementaciones de servicio +│ ├── flintstones.operator.*/ # Operadores de agregación/unificación +│ ├── flintstones.valuation.*/ # Tipos de valoración +│ ├── flintstones.helper.*/ # Utilidades (I/O, datos, UI, validación) +│ ├── flintstones.quantifiers.*/ # Cuantificadores lingüísticos +│ ├── flintstones.engine.R/ # Integración con el motor R +│ ├── flintstones.clustering.*/ # Clustering aglomerativo +│ ├── flintstones.theme/ # Tema visual +│ ├── org.apache.commons.math3/ # Dependencia: Apache Commons Math +│ ├── org.jfree.chart.jfreechart/ # Dependencia: JFreeChart +│ ├── de.jaret.util.swt/ # Dependencia: Jaret SWT utils +│ ├── de.kupzog.ktable/ # Dependencia: KTable +│ └── org.eclipse.nebula.*/ # Dependencia: Eclipse Nebula widgets +│ +├── features/ # Features Eclipse (agrupaciones de bundles) +│ ├── flintstones.feature.application/ +│ ├── flintstones.feature.domain/ +│ ├── flintstones.feature.element/ +│ ├── flintstones.feature.engine/ +│ ├── flintstones.feature.entity/ +│ ├── flintstones.feature.helper/ +│ ├── flintstones.feature.libraries/ +│ ├── flintstones.feature.method/ +│ ├── flintstones.feature.model/ +│ ├── flintstones.feature.operator/ +│ ├── flintstones.feature.quantifiers/ +│ ├── flintstones.feature.theme/ +│ └── flintstones.feature.valuation/ +│ +├── releng/ # Release engineering +│ ├── flintstones.application.configuration/ # POM raíz con config de Tycho +│ ├── flintstones.application.product/ # Definición del producto (.product) +│ └── flintstones.application.update/ # Update site +│ +├── Dockerfile # Imagen Docker para compilar y ejecutar +├── docker-compose.yml # Servicios: build, run (Xvfb), run-vnc +├── build.sh # Script de compilación +└── pom.xml # POM raíz Maven +``` + +--- + +## Flujo de trabajo en la aplicación + +La aplicación guía al usuario a través de **perspectivas** secuenciales: + +``` +1. Framework + └─ Definir: alternativas, criterios (con pesos y dominios), expertos + +2. Framework Structuring + └─ Organizar la estructura jerárquica del problema + +3. Gathering + └─ Recoger las valoraciones de cada experto sobre cada alternativa/criterio + +4. Method Selection + └─ Elegir el método MCDM a aplicar y configurarlo + +5. Execution / Results + └─ Ejecutar el método y visualizar el ranking de alternativas + +6. Sensitive Analysis + └─ Analizar la robustez de los resultados ante variaciones en los pesos +``` + +Los ficheros de problema se guardan/cargan desde **File → Save / Open**. +El formato de archivo es propio de Flintstones (XML interno). + +--- + +## Problemas conocidos resueltos + +Los siguientes problemas estaban presentes en el repositorio y han sido corregidos: + +### 1. Bundles inexistentes en `feature.xml` +`flintstones.feature.method/feature.xml` referenciaba tres bundles que ya no existen en el código: + +``` +flintstones.method.linguistic.elicit.topsis +flintstones.method.linguistic.elicit.topsis.phase.experts +flintstones.method.linguistic.elicit.topsis.phase.experts.ui +``` + +**Fix:** eliminados del `feature.xml`. + +### 2. Entradas duplicadas en `feature.xml` +El mismo `feature.xml` contenía dos veces las entradas de `flintstones.method.linguistic.topsis.*`. +**Fix:** eliminada la segunda ocurrencia. + +### 3. URLs HTTP obsoletas en el POM +El POM de configuración usaba URLs `http://` que ya no funcionan: + +| Antes | Después | +|---|---| +| `http://download.eclipse.org/releases/photon` | `https://download.eclipse.org/releases/2018-09` | +| `http://central.maven.org/maven2/` | `https://repo1.maven.org/maven2/` | + +El repositorio de Eclipse Photon (2018) se actualizó a **2018-09** porque Photon no incluía el perfil JRE para JavaSE-11 en su repositorio p2 y los bundles del proyecto lo requieren. + +### 4. Plataformas de 32 bits incompatibles con JavaSE-11 +Los targets `linux/gtk/x86` y `win32/win32/x86` no pueden resolver `osgi.ee=JavaSE(version=11)` porque no hay JDK 11 de 32 bits disponible. +**Fix:** eliminados. Solo se compila para x86_64 (Linux, Windows, macOS). + +### 5. Tycho no encontraba el perfil JavaSE-11 +**Fix:** añadidas al `target-platform-configuration`: +```xml +JavaSE-11 +false +``` + +### Bundles huérfanos (pendientes de integrar) +Existen en el código pero no están incluidos en ninguna feature (no se empaquetan en el producto): + +| Bundle | Estado | +|---|---| +| `flintstones.operator.aggregation.bonferroniMean` | En disco, no en `pom.xml` ni en features | +| `flintstones.operator.unification.fuzzy` | En disco, no en `pom.xml` ni en features | +| `flintstones.method.dEvaluation` (+ sub-bundles) | En `pom.xml`, no en features | +| `flintstones.valuation.fuzzy` | En `pom.xml`, no en features | +| `flintstones.valuation.proportionaltwotuple` | En `pom.xml`, no en features | +| `flintstones.clustering.agglomerative` | En `pom.xml`, no en features | + +--- + +## Tecnologías + +| Tecnología | Uso | +|---|---| +| **Java 11** | Lenguaje principal | +| **OSGi / Equinox** | Framework de componentes | +| **Eclipse E4 RCP** | Framework de aplicación de escritorio | +| **Eclipse SWT + JFace** | Widgets y UI | +| **Maven Tycho 2.0.0** | Sistema de build para proyectos Eclipse | +| **EMF** | Eclipse Modeling Framework (modelos de datos) | +| **Apache Commons Math 3** | Cálculos matemáticos y estadísticos | +| **JFreeChart** | Gráficas y visualización | +| **R Engine** | Cálculos estadísticos avanzados | +| **Eclipse Nebula** | Widgets SWT adicionales | +| **Docker** | Entorno de build reproducible | diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..8cdfa8c --- /dev/null +++ b/build.bat @@ -0,0 +1,10 @@ +:: Hacer los SET + +:: Actualizar POM + +:: Build +mvn clean install + +pause +pause +pause \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..327e986 --- /dev/null +++ b/build.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Compila Flintstones en Docker (no hace falta tener Maven ni Java 11 local) +set -e + +PRODUCTS_DIR="releng/flintstones.application.product/target/products" + +echo "==> Compilando Flintstones con Maven 3.8 + JDK 11 en Docker..." +docker compose run --rm build + +echo "" +echo "==> Build completado. Productos:" +ls "$PRODUCTS_DIR/"*.zip 2>/dev/null | while read f; do echo " $f"; done + +echo "" +echo "==> Para ejecutar en macOS:" +echo " cd '$PRODUCTS_DIR'" +MACOS_ZIP=$(ls "$PRODUCTS_DIR"/*macosx*.zip 2>/dev/null | head -1) +if [ -n "$MACOS_ZIP" ]; then + echo " unzip -o '$MACOS_ZIP'" + echo " open Eclipse.app" + echo " (o doble clic en Eclipse.app desde el Finder)" +fi + +echo "" +echo "==> Para ejecutar en Linux con VNC (puerto 5900):" +echo " docker compose run --rm run-vnc" +echo " Conectar con cualquier cliente VNC a localhost:5900" diff --git a/bundles/.settings/org.eclipse.core.resources.prefs b/bundles/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/.settings/org.eclipse.m2e.core.prefs b/bundles/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/de.jaret.util.swt/.classpath b/bundles/de.jaret.util.swt/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/de.jaret.util.swt/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/de.jaret.util.swt/.polyglot.META-INF b/bundles/de.jaret.util.swt/.polyglot.META-INF new file mode 100644 index 0000000..d95d89c --- /dev/null +++ b/bundles/de.jaret.util.swt/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + de.jaret.util.swt + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Swt + diff --git a/bundles/de.jaret.util.swt/.project b/bundles/de.jaret.util.swt/.project new file mode 100644 index 0000000..7692ed7 --- /dev/null +++ b/bundles/de.jaret.util.swt/.project @@ -0,0 +1,45 @@ + + + de.jaret.util.swt + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362508 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/de.jaret.util.swt/.settings/org.eclipse.core.resources.prefs b/bundles/de.jaret.util.swt/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/de.jaret.util.swt/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/de.jaret.util.swt/.settings/org.eclipse.jdt.core.prefs b/bundles/de.jaret.util.swt/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/de.jaret.util.swt/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/de.jaret.util.swt/.settings/org.eclipse.m2e.core.prefs b/bundles/de.jaret.util.swt/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/de.jaret.util.swt/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/de.jaret.util.swt/META-INF/MANIFEST.MF b/bundles/de.jaret.util.swt/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d7183d4 --- /dev/null +++ b/bundles/de.jaret.util.swt/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Swt +Bundle-SymbolicName: de.jaret.util.swt +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: de.jaret.util.swt +Require-Bundle: org.eclipse.swt +Export-Package: de.jaret.util.swt +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/bundles/de.jaret.util.swt/build.properties b/bundles/de.jaret.util.swt/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/de.jaret.util.swt/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/de.jaret.util.swt/src/de/jaret/util/swt/SwtGraphicsHelper.java b/bundles/de.jaret.util.swt/src/de/jaret/util/swt/SwtGraphicsHelper.java new file mode 100644 index 0000000..f5cb274 --- /dev/null +++ b/bundles/de.jaret.util.swt/src/de/jaret/util/swt/SwtGraphicsHelper.java @@ -0,0 +1,488 @@ +/* + * File: SwtGraphicsHelper.java + * Copyright (c) 2004-2007 Peter Kliem (Peter.Kliem@jaret.de) + * A commercial license is available, see http://www.jaret.de. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + */ +package de.jaret.util.swt; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.PaletteData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.Transform; + +/** + * A simple class containing several static methods for convenient painting with a SWT gc. + * + * @author Peter Kliem + * @version $Id: SwtGraphicsHelper.java 726 2008-03-18 21:06:14Z kliem $ + */ +public class SwtGraphicsHelper { + + /** + * Draw a string centered between x,y at top y. + * @param gc gc + * @param string string + * @param left left bound + * @param right right bound + * @param y top y + */ + public static void drawStringCentered(GC gc, String string, int left, int right, int y) { + Point extent = gc.textExtent(string); + int width = right - left; + int xx = (int) ((width - extent.x) / 2); + gc.drawString(string, left+xx, y); + } + + public static void drawStringCenteredMidX(GC gc, String string, int midx, int y) { + Point extent = gc.textExtent(string); + int xx = (int) (midx - (extent.x / 2)); + gc.drawString(string, xx, y); + } + + public static void drawStringCenteredVCenter(GC gc, String string, int left, int right, int yCenter) { + Point extent = gc.textExtent(string); + // int descent = graphics.getFontMetrics().getDescent(); + int descent = 0; + int width = right - left; + int xx = (int) ((width - extent.x) / 2); + int y = yCenter - (int) (extent.y / 2 - descent); + gc.drawString(string, left + xx, y); + + } + + public static void drawStringRightAlignedVCenter(GC gc, String string, int x, int y) { + Point extent = gc.textExtent(string); + + int xx = (int) (x - extent.x); + int yy = (int) (y - (extent.y / 2)); + gc.drawString(string, xx, yy); + } + + public static void drawStringLeftAlignedVCenter(GC gc, String string, int x, int y) { + Point extent = gc.textExtent(string); + + int xx = x; + int yy = (int) (y - (extent.y / 2)); + gc.drawString(string, xx, yy); + } + + public static void drawStringCentered(GC gc, String string, int xCenter, int yBase) { + Point extent = gc.textExtent(string); + int xx = xCenter - (int) ((extent.x) / 2); + gc.drawText(string, xx, yBase - extent.y, true); + } + + public static void drawStringCenteredAroundPoint(GC gc, String string, int xCenter, int yCenter) { + Point extent = gc.textExtent(string); + int xx = xCenter - (int) ((extent.x) / 2); + int yy = yCenter - (int) ((extent.y) / 2); + gc.drawText(string, xx, yy, true); + } + + /** + * Draw the string centered in the given rectangle (specified by plain values) + * + * @param gc + * @param string + * @param x + * @param y + * @param width + * @param height + */ + public static void drawStringCentered(GC gc, String string, int x, int y, int width, int height) { + Point extent = gc.textExtent(string); + int xx = x + (width - extent.x) / 2; + int yy = y + (height - extent.y) / 2; + gc.drawText(string, xx, yy, true); + } + + /** + * Draw String centered in the given rectangle. + * + * @param gc + * @param string + * @param rect + */ + public static void drawStringCentered(GC gc, String string, Rectangle rect) { + drawStringCentered(gc, string, rect.x, rect.y, rect.width, rect.height); + } + + public static int getStringDrawingWidth(GC gc, String string) { + return gc.textExtent(string).x; + } + + public static int getStringDrawingHeight(GC gc, String string) { + return gc.textExtent(string).y; + } + + /** + * Draws a String right aligned with the y coordinate denoting the top of the string. + * @param gc GC + * @param string string to draw + * @param x right x position + * @param yTop top y position + */ + public static void drawStringRightAlignedVTop(GC gc, String string, int x, int yTop) { + Point extent = gc.textExtent(string); + int xx = (int) (x - extent.x); + gc.drawText(string, xx, yTop, true); + } + + public static void drawArrowLine(GC gc, int x1, int y1, int x2, int y2, int dist, int height, boolean arrowLeft, + boolean arrowRight) { + int off = height; + gc.drawLine(x1 + off + 1, y1, x2 - off - 1, y2); + if (arrowLeft) { + gc.drawLine(x1, y1, x1 + dist, y1 - off); + gc.drawLine(x1, y1, x1 + dist, y1 + off); + gc.drawLine(x1 + dist, y1 - off, x1 + dist, y1 + off); + } + if (arrowRight) { + gc.drawLine(x2, y2, x2 - dist, y2 - off); + gc.drawLine(x2, y2, x2 - dist, y2 + off); + gc.drawLine(x2 - dist, y2 - off, x2 - dist, y2 + off); + } + } + + public static void drawArrowLineVertical(GC gc, int x1, int y1, int x2, int y2, int dist, int height, + boolean arrowUp, boolean arrowDown) { + int off = height; + gc.drawLine(x1, y1 + off + 1, x2, y2 - off - 1); + if (arrowUp) { + gc.drawLine(x1, y1, x1 - off, y1 + dist); + gc.drawLine(x1, y1, x1 + off, y1 + dist); + gc.drawLine(x1 - off, y1 + dist, x1 + off, y1 + dist); + } + if (arrowDown) { + gc.drawLine(x2, y2, x2 - off, y2 - dist); + gc.drawLine(x2, y2, x2 + off, y2 - dist); + gc.drawLine(x2 - off, y2 - dist, x2 + off, y2 - dist); + } + } + + /** + * Draw a string vertical centered beetween upper and lower y left aligned to x. + * + * @param gc GC + * @param label label to draw + * @param x left x + * @param upperY upper y bound + * @param lowerY lower y bound + */ + public static void drawStringVCentered(GC gc, String label, int x, int upperY, int lowerY) { + Point extent = gc.textExtent(label); + + int yy = (int) upperY + (lowerY - upperY - extent.y) / 2; + gc.drawText(label, x, yy, true); + } + + /** + * Draw a String vertical. This method might be quite costly since it uses an image to buffer. + * + * @param gc gc + * @param string strin gto to draw + * @param x upper left x + * @param y upper left y + */ + public static void drawStringVertical(GC gc, String string, int x, int y) { + Point extent = gc.textExtent(string); + Image img = new Image(gc.getDevice(), extent.x, extent.y); + GC imageGC = new GC(img); + imageGC.drawString(string, 0, 0); + imageGC.dispose(); + + + Image vertImg = new Image(gc.getDevice(), extent.y, extent.x); + ImageData iData = img.getImageData(); + ImageData destIData = vertImg.getImageData(); + + for (int xx = 0; xx < iData.width; xx++) { + for (int yy = 0; yy < iData.height; yy++) { + destIData.setPixel(yy, iData.width-xx-1, iData.getPixel(xx, yy)); + } + } + + img.dispose(); + Image destImg = new Image(gc.getDevice(), destIData); + + gc.drawImage(destImg, x, y); + vertImg.dispose(); + destImg.dispose(); + + } + /** + * Create an image with a drop shadow. This method is (c) 2007 Nicholas Rajendram, IBM Canada, see + * http://www.eclipse.org/articles/article.php?file=Article-SimpleImageEffectsForSWT/index.html. + * + * @param originalImageData The original image. Transparency information will be ignored. + * @param color The color of the drop shadow + * @param radius The radius of the drop shadow in pixels + * @param highlightRadius The radius of the highlight area + * @param opacity The opacity of the drop shadow + * @return The drop shadowed image. This image data will be larger than the original. The same image data will be + * returned if the shadow radius is 0, or null if an error occured. + */ + public static ImageData dropShadow(ImageData originalImageData, Color color, int radius, int highlightRadius, + int opacity) { + /* + * This method will create a drop shadowto the bottom-right of an existing image. This drop shadow is created by + * creating an altered one-sided glow, and shifting its position around the image. See the Glow class for more + * details of how the glow is calculated. + */ + if (originalImageData == null) + return null; + if (color == null) + return null; + if (radius == 0) + return originalImageData; + int shift = (int) (radius * 1.5); // distance to shift "glow" from image + // the percent increase in color intensity in the highlight radius + double highlightRadiusIncrease = radius < highlightRadius * 2 ? .15 : radius < highlightRadius * 3 ? .09 : .02; + opacity = opacity > 255 ? 255 : opacity < 0 ? 0 : opacity; + // prepare new image data with 24-bit direct palette to hold shadowed copy of image + ImageData newImageData = new ImageData(originalImageData.width + radius * 2, originalImageData.height + radius + * 2, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000)); + int[] pixels = new int[originalImageData.width]; + // copy image data + for (int row = radius; row < radius + originalImageData.height; row++) { + originalImageData.getPixels(0, row - radius, originalImageData.width, pixels, 0); + for (int col = 0; col < pixels.length; col++) + pixels[col] = newImageData.palette.getPixel(originalImageData.palette.getRGB(pixels[col])); + newImageData.setPixels(radius, row, originalImageData.width, pixels, 0); + } + // initialize glow pixel data + int colorInt = newImageData.palette.getPixel(color.getRGB()); + pixels = new int[newImageData.width]; + for (int i = 0; i < newImageData.width; i++) { + pixels[i] = colorInt; + } + // initialize alpha values + byte[] alphas = new byte[newImageData.width]; + // deal with alpha values on rows above and below the photo + for (int row = 0; row < newImageData.height; row++) { + if (row < radius) { + // only calculate alpha values for top border. they will reflect to the bottom border + byte intensity = (byte) (opacity * ((((row + 1)) / (double) (radius)))); + for (int col = 0; col < alphas.length / 2 + alphas.length % 2; col++) { + if (col < radius) { + // deal with corners: + // calculate pixel's distance from image corner + double hypotenuse = Math + .sqrt(Math.pow(radius - col - 1, 2.0) + Math.pow(radius - 1 - row, 2.0)); + // calculate alpha based on percent distance from image + alphas[col + shift] = alphas[alphas.length - col - 1] = (byte) (opacity * Math.max( + ((radius - hypotenuse) / radius), 0)); + // add highlight radius + if (hypotenuse < Math.min(highlightRadius, radius * .5)) { + alphas[col + shift] = alphas[alphas.length - col - 1] = (byte) Math.min(255, (alphas[col + + shift] & 0x0FF) + * (1 + highlightRadiusIncrease * Math.max(((radius - hypotenuse) / radius), 0))); + } + } else { + alphas[col + shift] = alphas[alphas.length - col - 1] = (byte) ((row > Math.max(radius + - highlightRadius - 1, radius * .5)) ? Math.min(255, (intensity & 0x0FF) + * (1 + highlightRadiusIncrease * row / radius)) : intensity); + } + } + if (row + shift < newImageData.height) { + newImageData.setAlphas(newImageData.width - radius, row + shift, radius, alphas, alphas.length + - radius); + newImageData.setPixels(newImageData.width - radius, row + shift, radius, pixels, alphas.length + - radius); + } + newImageData.setAlphas(0, newImageData.height - 1 - row, newImageData.width, alphas, 0); + newImageData.setPixels(0, newImageData.height - 1 - row, newImageData.width, pixels, 0); + } + // deal with rows the image resides on + else if (row <= newImageData.height / 2) { + // calculate alpha values + double intensity = 0; + for (int col = 0; col < alphas.length; col++) { + if (col < radius) { + intensity = (opacity * ((col + 1) / (double) radius)); + if (col > Math.max(radius - highlightRadius - 1, radius * .5)) { + intensity = Math.min(255, (intensity) * (1 + highlightRadiusIncrease * col / radius)); + } + alphas[newImageData.width - col - 1] = (byte) (int) (intensity); + alphas[col] = 0; + } else if (col <= newImageData.width / 2 + newImageData.width % 2) { + // original image pixels are full opacity + alphas[col] = alphas[newImageData.width - col - 1] = (byte) (255); + } + } + newImageData.setPixels(0, newImageData.height - 1 - row, radius, pixels, 0); + newImageData.setPixels(originalImageData.width + radius, newImageData.height - 1 - row, radius, pixels, + 0); + newImageData.setAlphas(0, newImageData.height - 1 - row, newImageData.width, alphas, 0); + if (row >= shift + radius) { + newImageData.setPixels(0, row, radius, pixels, 0); + newImageData.setPixels(originalImageData.width + radius, row, radius, pixels, 0); + newImageData.setAlphas(0, row, newImageData.width, alphas, 0); + } else { + newImageData.setPixels(0, row, radius, pixels, 0); + newImageData.setAlphas(0, row, newImageData.width - radius, alphas, 0); + } + } + } + return newImageData; + } + + /** + * Create an image with a glow effect. This method is (c) 2007 Nicholas Rajendram, IBM Canada, see + * http://www.eclipse.org/articles/article.php?file=Article-SimpleImageEffectsForSWT/index.html. + * + * @param originalImageData The original image. Transparency information will be ignored. + * @param color The color of the glow + * @param radius The radius of the glow in pixels + * @param highlightRadius The radius of the highlight area + * @param opacity The opacity of the glow + * @return The glowing image. This image data will be larger than the original. The same image data will be returned + * if the glow radius is 0, or null if an error occured. + */ + public static ImageData glow(ImageData originalImageData, Color color, int radius, int highlightRadius, int opacity) { + /* + * This method will surround an existing image with a glowing border. This glow is created by adding a solid + * colored border around an image. Alpha values are then manipulated in order to blend the border with its + * background. This gives a glowing appearance. + * + * To obtain the alpha value of a glow pixel, its position in the border radius as a percent of the radius' + * total width is first calculated. This percentage is multipled by the maximum opacity level, giving pixels an + * outward linear blend from the image from opaque to transparent. + * + * A highlight radius increases the intensity of a given radius of pixels surrounding the image to better + * highlight it. When there is a highlight radius, the entire glow's overall alpha blending is non-linear. + */ + if (originalImageData == null) + return null; + if (color == null) + return null; + if (radius == 0) + return originalImageData; + // the percent increase in color intensity in the highlight radius + double highlightRadiusIncrease = radius < highlightRadius * 2 ? .15 : radius < highlightRadius * 3 ? .09 : .02; + opacity = opacity > 255 ? 255 : opacity < 0 ? 0 : opacity; + // prepare new image data with 24-bit direct palette to hold glowing copy of image + ImageData newImageData = new ImageData(originalImageData.width + radius * 2, originalImageData.height + radius + * 2, 24, new PaletteData(0xFF, 0xFF00, 0xFF0000)); + int[] pixels = new int[originalImageData.width]; + // copy image data + for (int row = radius; row < radius + originalImageData.height; row++) { + originalImageData.getPixels(0, row - radius, originalImageData.width, pixels, 0); + for (int col = 0; col < pixels.length; col++) + pixels[col] = newImageData.palette.getPixel(originalImageData.palette.getRGB(pixels[col])); + newImageData.setPixels(radius, row, originalImageData.width, pixels, 0); + } + // initialize glow pixel data + int colorInt = newImageData.palette.getPixel(color.getRGB()); + pixels = new int[newImageData.width]; + for (int i = 0; i < newImageData.width; i++) { + pixels[i] = colorInt; + } + // initialize alpha values + byte[] alphas = new byte[newImageData.width]; + // deal with alpha values on rows above and below the photo + for (int row = 0; row < newImageData.height; row++) { + if (row < radius) { + // only calculate alpha values for top border. they will reflect to the bottom border + byte intensity = (byte) (opacity * ((((row + 1)) / (double) (radius)))); + for (int col = 0; col < alphas.length / 2 + alphas.length % 2; col++) { + if (col < radius) { + // deal with corners: + // calculate pixel's distance from image corner + double hypotenuse = Math + .sqrt(Math.pow(radius - col - 1, 2.0) + Math.pow(radius - 1 - row, 2.0)); + // calculate alpha based on percent distance from image + alphas[col] = alphas[alphas.length - col - 1] = (byte) (opacity * Math.max( + ((radius - hypotenuse) / radius), 0)); + // add highlight radius + if (hypotenuse < Math.min(highlightRadius, radius * .5)) { + alphas[col] = alphas[alphas.length - col - 1] = (byte) Math.min(255, (alphas[col] & 0x0FF) + * (1 + highlightRadiusIncrease * Math.max(((radius - hypotenuse) / radius), 0))); + } + } else { + alphas[col] = alphas[alphas.length - 1 - col] = (byte) ((row > Math.max(radius + - highlightRadius - 1, radius * .5)) ? Math.min(255, (intensity & 0x0FF) + * (1 + highlightRadiusIncrease * row / radius)) : intensity); + } + } + newImageData.setAlphas(0, row, newImageData.width, alphas, 0); + newImageData.setAlphas(0, newImageData.height - 1 - row, newImageData.width, alphas, 0); + newImageData.setPixels(0, row, newImageData.width, pixels, 0); + newImageData.setPixels(0, newImageData.height - 1 - row, newImageData.width, pixels, 0); + } + // deal with rows the image resides on + else if (row <= newImageData.height / 2) { + // calculate alpha values + double intensity = 0; + for (int col = 0; col < alphas.length; col++) { + if (col < radius) { + intensity = (opacity * ((col + 1) / (double) radius)); + if (col > Math.max(radius - highlightRadius - 1, radius * .5)) { + intensity = Math.min(255, (intensity) * (1 + highlightRadiusIncrease * col / radius)); + } + alphas[col] = alphas[newImageData.width - col - 1] = (byte) (intensity); + } else if (col <= newImageData.width / 2 + newImageData.width % 2) { + // original image pixels are full opacity + alphas[col] = alphas[newImageData.width - col - 1] = (byte) (255); + } + } + newImageData.setPixels(0, row, radius, pixels, 0); + newImageData.setPixels(originalImageData.width + radius, row, radius, pixels, 0); + newImageData.setAlphas(0, row, newImageData.width, alphas, 0); + newImageData.setPixels(0, newImageData.height - 1 - row, radius, pixels, 0); + newImageData.setPixels(originalImageData.width + radius, newImageData.height - 1 - row, radius, pixels, + 0); + newImageData.setAlphas(0, newImageData.height - 1 - row, newImageData.width, alphas, 0); + } + } + return newImageData; + } + /** + * Create a reflection image (Idea taken from Daniel Spiewak: see + * http://www.eclipsezone.com/eclipse/forums/t91013.html?start=0). + * + * @param img image to reflect + * @param device device + * @return image (larger than the original) containing a reflectd version of the original image + */ + public static Image reflect(Image img, Device device) { + + int height = img.getImageData().height; + int width = img.getImageData().width; + + Image reflect = new Image(device, width, height / 2); + GC imageGC = new GC(reflect); + + Transform rTransform = new Transform(imageGC.getDevice(), 1, 0, 0, -.5f, 0, height / 2); + imageGC.setTransform(rTransform); + + imageGC.setAlpha(100); + + imageGC.drawImage(img, 0, 0); + // imageGC.setTransform(null); + // // shade it + // int alpha =100; + // imageGC.setAlpha(100); + // imageGC.setForeground(imageGC.getDevice().getSystemColor(SWT.COLOR_WHITE)); + // for (int y = 0;y lines = breakInLines(gc, rect.width, wrap, text); + + if (!textResize || lines.size() != 1) { + int height = getHeight(gc, rect.width, wrap, lines, lineSpacing); + int offy = 0; + if (height < rect.height) { + if (valign == CENTER) { + offy = (rect.height - height) / 2; + } else if (valign == BOTTOM) { + offy = rect.height - height; + } + } + + int lineheight = SwtGraphicsHelper.getStringDrawingHeight(gc, + "WgyAqQ"); + for (int row = 0; row < lines.size(); row++) { + int y = rect.y + (row * lineheight) + (row * lineSpacing); + drawLine(gc, rect.x, y + offy, rect.width, lines.get(row), + halign, isTransparent); + } + } else { + drawLineResize(gc, rect.x, rect.y, rect.width, rect.height, + lines.get(0), halign, valign, isTransparent); + } + gc.setClipping(clipSave); + } + + public static int getHeight(GC gc, int width, boolean wrap, String text) { + List lines = breakInLines(gc, width, wrap, text); + return getHeight(gc, width, wrap, lines, 3); + } + + public static int getHeight(GC gc, int width, boolean wrap, String text, + int lineSpacing) { + List lines = breakInLines(gc, width, wrap, text); + return getHeight(gc, width, wrap, lines, lineSpacing); + } + + private static int getHeight(GC gc, int width, boolean wrap, + List lines, int lineSpacing) { + if (lines.size() == 0) { + return 0; + } + int lineheight = SwtGraphicsHelper.getStringDrawingHeight(gc, + lines.get(0)); + int height = (lines.size() * lineheight) + + ((lines.size() - 1) * lineSpacing); + return height; + } + + private static void drawLine(GC gc, int x, int y, int width, String string, + int halign, boolean isTransparent) { + int xx; + int textWidth = SwtGraphicsHelper.getStringDrawingWidth(gc, string); + + switch (halign) { + case LEFT: + xx = x; + break; + case RIGHT: + xx = x + (width - textWidth); + break; + case CENTER: + xx = x + ((width - textWidth) / 2); + break; + default: + throw new RuntimeException("illegal alignment"); + } + gc.drawText(string, xx, y, isTransparent); + + } + + private static void drawLineResize(GC gc, int x, int y, int width, + int height, String string, int halign, int valign, + boolean isTransparent) { + int xx; + + int textWidth = SwtGraphicsHelper.getStringDrawingWidth(gc, string); + double widthRatio = (double) width / (double) textWidth; + + Font gcFont = gc.getFont(); + FontData[] fontData = gcFont.getFontData(); + + Display display = Display.getCurrent(); + Font systemFont = display.getSystemFont(); + FontData[] systemFontData = systemFont.getFontData(); + + int newFontSize = (int) (fontData[0].getHeight() * widthRatio); + + if (newFontSize != fontData[0].getHeight()) { + + fontData[0].setHeight(newFontSize); + + gc.setFont(new Font(display, fontData[0])); + + while (SwtGraphicsHelper.getStringDrawingWidth(gc, string) < width + && SwtGraphicsHelper.getStringDrawingHeight(gc, string) < height) { + newFontSize++; + fontData[0].setHeight(newFontSize); + gc.getFont().dispose(); + gc.setFont(new Font(display, fontData[0])); + } + + while (SwtGraphicsHelper.getStringDrawingWidth(gc, string) > width + || SwtGraphicsHelper.getStringDrawingHeight(gc, string) > height) { + newFontSize--; + fontData[0].setHeight(newFontSize); + gc.getFont().dispose(); + gc.setFont(new Font(display, fontData[0])); + if (newFontSize <= systemFontData[0].getHeight()) { + break; + } + } + + if (newFontSize < systemFontData[0].getHeight()) { + newFontSize = systemFontData[0].getHeight(); + fontData[0].setHeight(newFontSize); + gc.getFont().dispose(); + gc.setFont(new Font(display, fontData[0])); + } + + } + int textHeight = SwtGraphicsHelper.getStringDrawingHeight(gc, string); + + if (textHeight < height) { + if (valign == CENTER) { + y += (height / 2) - (textHeight / 2); + } else if (valign == BOTTOM) { + y += height - textHeight; + } + } + + textWidth = SwtGraphicsHelper.getStringDrawingWidth(gc, string); + + switch (halign) { + case LEFT: + xx = x; + break; + case RIGHT: + xx = x + (width - textWidth); + break; + case CENTER: + xx = x + ((width - textWidth) / 2); + break; + default: + throw new RuntimeException("illegal alignment"); + } + gc.drawText(string, xx, y, isTransparent); + + if (gc.getFont() != gcFont && gc.getFont() != systemFont) { + gc.getFont().dispose(); + } + } + + public static List breakInLines(GC gc, int width, boolean wrap, + String text) { + List result = new ArrayList(); + StringTokenizer tokenizer = new StringTokenizer(text, "\n", false); + while (tokenizer.hasMoreTokens()) { + result.add(tokenizer.nextToken()); + } + if (wrap) { + List brokenLines = new ArrayList(); + Iterator it = result.iterator(); + while (it.hasNext()) { + String line = (String) it.next(); + List brLines = wrapLines(gc, width, line); + brokenLines.addAll(brLines); + } + + return brokenLines; + } else { + return result; + } + } + + /** + * @param gc + * @param width + * @param text + * @return + */ + private static List wrapLines(GC gc, int width, String text) { + List result = new ArrayList(); + StringTokenizer tokenizer = new StringTokenizer(text, " ", false); + StringBuffer buf = new StringBuffer(); + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + addToken(gc, width, buf, token, result); + } + + if (buf.length() > 0) { + result.add(buf.toString()); + } + + return result; + } + + private static void addToken(GC gc, int width, StringBuffer buf, + String token, List result) { + String testString; + if (buf.length() > 0) { + testString = " " + token; + } else { + testString = token; + } + + if (SwtGraphicsHelper.getStringDrawingWidth(gc, buf.toString() + + testString) < width) { + buf.append(testString); + } else if (buf.length() == 0) { + // a single word did not fit + List brWord = breakWord(gc, width, token); + if (brWord.size() == 1) { + result.add(brWord.get(0)); + } else { + for (int i = 0; i < (brWord.size() - 1); i++) { + result.add(brWord.get(i)); + } + addToken(gc, width, buf, brWord.get(brWord.size() - 1), result); + } + } else { + result.add(buf.toString()); + buf.setLength(0); + addToken(gc, width, buf, token, result); + } + + } + + /** + * break a word into strings fitting into width. + * + * @param gc + * @param width + * @param word + * @return + */ + private static List breakWord(GC gc, int width, String word) { + List result = new ArrayList(); + + for (int bidx = 0, eidx = 1; eidx <= word.length(); eidx++) { + String wordPart = word.substring(bidx, eidx); + int wordPartExtent = SwtGraphicsHelper.getStringDrawingWidth(gc, + wordPart); + if (wordPartExtent > width) { + if ((eidx - 1) > bidx) { + eidx--; + } + result.add(word.substring(bidx, eidx)); + bidx = eidx; + } else if (eidx == word.length()) { + result.add(word.substring(bidx, eidx)); + } + } + + return result; + } +} diff --git a/bundles/de.kupzog.ktable/.classpath b/bundles/de.kupzog.ktable/.classpath new file mode 100644 index 0000000..fbf8d0b --- /dev/null +++ b/bundles/de.kupzog.ktable/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/de.kupzog.ktable/.polyglot.META-INF b/bundles/de.kupzog.ktable/.polyglot.META-INF new file mode 100644 index 0000000..feca07e --- /dev/null +++ b/bundles/de.kupzog.ktable/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + de.kupzog.ktable + 2.2.0 + eclipse-plugin + [bundle] de.kupzog.ktable + diff --git a/bundles/de.kupzog.ktable/.project b/bundles/de.kupzog.ktable/.project new file mode 100644 index 0000000..81beda8 --- /dev/null +++ b/bundles/de.kupzog.ktable/.project @@ -0,0 +1,45 @@ + + + de.kupzog.ktable + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362510 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/de.kupzog.ktable/.settings/org.eclipse.core.resources.prefs b/bundles/de.kupzog.ktable/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/de.kupzog.ktable/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/de.kupzog.ktable/.settings/org.eclipse.core.runtime.prefs b/bundles/de.kupzog.ktable/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000..5a0ad22 --- /dev/null +++ b/bundles/de.kupzog.ktable/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/bundles/de.kupzog.ktable/.settings/org.eclipse.jdt.core.prefs b/bundles/de.kupzog.ktable/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..f42de36 --- /dev/null +++ b/bundles/de.kupzog.ktable/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/bundles/de.kupzog.ktable/.settings/org.eclipse.m2e.core.prefs b/bundles/de.kupzog.ktable/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/de.kupzog.ktable/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/de.kupzog.ktable/KTable.jar b/bundles/de.kupzog.ktable/KTable.jar new file mode 100644 index 0000000..7ceb8f2 Binary files /dev/null and b/bundles/de.kupzog.ktable/KTable.jar differ diff --git a/bundles/de.kupzog.ktable/META-INF/MANIFEST.MF b/bundles/de.kupzog.ktable/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5c64324 --- /dev/null +++ b/bundles/de.kupzog.ktable/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: de.kupzog.ktable +Bundle-Version: 2.2.0 +Bundle-ClassPath: ., + KTable.jar +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: de.kupzog.ktable, + de.kupzog.ktable.editors, + de.kupzog.ktable.renderers, + icons +Require-Bundle: org.eclipse.jface +Automatic-Module-Name: de.kupzog.ktable diff --git a/bundles/de.kupzog.ktable/OSGI-INF/l10n/bundle.properties b/bundles/de.kupzog.ktable/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..9fcf62e --- /dev/null +++ b/bundles/de.kupzog.ktable/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for de.kupzog.ktable +Bundle-Name = de.kupzog.ktable \ No newline at end of file diff --git a/bundles/de.kupzog.ktable/build.properties b/bundles/de.kupzog.ktable/build.properties new file mode 100644 index 0000000..4b08a7b --- /dev/null +++ b/bundles/de.kupzog.ktable/build.properties @@ -0,0 +1,3 @@ +bin.includes = META-INF/,\ + KTable.jar,\ + OSGI-INF/ diff --git a/bundles/de.kupzog.ktable/source.zip b/bundles/de.kupzog.ktable/source.zip new file mode 100644 index 0000000..108b5c0 Binary files /dev/null and b/bundles/de.kupzog.ktable/source.zip differ diff --git a/bundles/flintstones.application.constants/.classpath b/bundles/flintstones.application.constants/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.application.constants/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.constants/.polyglot.META-INF b/bundles/flintstones.application.constants/.polyglot.META-INF new file mode 100644 index 0000000..fb70b44 --- /dev/null +++ b/bundles/flintstones.application.constants/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.constants + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Events + diff --git a/bundles/flintstones.application.constants/.project b/bundles/flintstones.application.constants/.project new file mode 100644 index 0000000..1ddd3a5 --- /dev/null +++ b/bundles/flintstones.application.constants/.project @@ -0,0 +1,45 @@ + + + flintstones.application.constants + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362512 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.constants/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.constants/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.constants/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.constants/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.constants/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.constants/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.constants/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.constants/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.constants/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.constants/META-INF/MANIFEST.MF b/bundles/flintstones.application.constants/META-INF/MANIFEST.MF new file mode 100644 index 0000000..116309f --- /dev/null +++ b/bundles/flintstones.application.constants/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.application.constants +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.application.constants +Automatic-Module-Name: flintstones.framework.events diff --git a/bundles/flintstones.application.constants/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.application.constants/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..dbe9155 --- /dev/null +++ b/bundles/flintstones.application.constants/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.framework.events +Bundle-Name = Events \ No newline at end of file diff --git a/bundles/flintstones.application.constants/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.application.constants/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..dbe9155 --- /dev/null +++ b/bundles/flintstones.application.constants/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.framework.events +Bundle-Name = Events \ No newline at end of file diff --git a/bundles/flintstones.application.constants/build.properties b/bundles/flintstones.application.constants/build.properties new file mode 100644 index 0000000..fc6c97e --- /dev/null +++ b/bundles/flintstones.application.constants/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.application.constants/src/flintstones/application/constants/ApplicationContants.java b/bundles/flintstones.application.constants/src/flintstones/application/constants/ApplicationContants.java new file mode 100644 index 0000000..a40ef21 --- /dev/null +++ b/bundles/flintstones.application.constants/src/flintstones/application/constants/ApplicationContants.java @@ -0,0 +1,68 @@ +package flintstones.application.constants; + +@SuppressWarnings("javadoc") +public interface ApplicationContants { + + String MWindow_Main = "flintstones.application.trimmedwindow.flintstones"; + + // 0.APP MAIN MENU + String MHandledToolItem_Menu_FrameworkStructuring = "flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.frameworkstructuring"; + String MHandledToolItem_Menu_Gathering = "flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.gathering"; + String MHandledToolItem_Change_Problem_Type = "flintstones.application.directtoolitem.problem.type"; + + // 1.FRAMEWORK + String MPartStack_Domain = "flintstones.framework.ui.partstack.domains"; + String MPartStack_DomainViewer = "flintstones.framework.ui.partstack.domain"; + String MPartStack_AHPClasses = "flintstones.framework.ui.partstack.ahpclasses"; + String MPartStack_AHPPRofiles = "flintstones.framework.ui.partstack.ahpprofiles"; + String MPartStack_AHPViewer = "flintstones.framework.ui.partstack.ahpviewer"; + + + // 3.GATHERING + String MPart_Gatehring_Selector = "flintstones.gathering.ui.part.selectorpart"; + + // 3 - Generic AHP GATHERING + String MPartStack_AHP_Gathering = "flintstones.application.perspective.ahpgathering.partstack"; + String MPartStack_AHP_Comparing = "flintstones.application.perspective.ahpcomparing.partstack"; + String MPerspective_AHP_Comparing = "flintstones.application.perspective.ahpcomparing"; + String MPerspective_AHP_Gathering = "flintstones.application.perspective.ahpgathering"; + + String MPerspective_AHP = "flintstones.application.perspective.ahpgathering"; + // 3.GATHERING AHP + String MPerspective_Rating_AHP = "flintstones.application.perspective.gathering.ahp.ui"; + + // 3.GATHERING AHPSORT + String MPerspective_Rating_AHPSort = "flintstones.application.perspective.gathering.ahpsort.ui"; + + // 3.GATHERING AHPSORTII + String MPart_Gathering_ReferencePoints = "flintstones.application.perspective.gathering.ahpsortii.ui.referencepoints"; + // 4.RATING + String MMenu_Rating = "flintstones.application.menu.rating"; + String MPerspective_Rating = "flintstones.application.perspective.rating"; + + // 4.Rating > Select Method Menu + String MCommand_Rating_Selectmethod = "flintstones.application.command.rating.selectmethod"; + String MHandler_Rating_Selectmethod = "flintstones.application.handler.rating.selectmethod"; + String MParameter_Rating_Selectmethod = "flintstones.application.commandparameter.rating.selectmethod"; + String MParameter_Rating_Selectmethod__label = "method_id"; + + // 4.1 + String MPerspective_Phase = "flintstones.application.perspective.phase"; + String MPartSashContainer_Phase_Container = "flintstones.application.perspective.phase.ui.partsashcontainer.container"; + + // 4.1 - Aggregation + String MPerspective_Phase_Phantom = "flintstones.application.perspective.phase.phantomphasecontainer"; + + // Select Locale Menu + String MCommand_Global_Selectlocale = "flintstones.application.command.locale"; + String MParameter_Global_Selectlocale = "flintstones.application.commandparameter.localeId"; + + // Debug > Send broker events menu + String MMenu_Sendbroker = "flintstones.application.menu.sendbroker"; + String MCommand_General_Sendbroker = "flintstones.application.command.debug.sendbroker"; + String MHandler_General_Sendbroker = "flintstones.application.handler.debug.sendbroker"; + String MParameter_General_Sendbroker = "flintstones.application.commandparameter.debug.sendbroker.brokerevent"; + String MParameter__General_Sendbroker__label = "event_id"; + + +} diff --git a/bundles/flintstones.application.constants/src/flintstones/application/constants/FrameworkConstants.java b/bundles/flintstones.application.constants/src/flintstones/application/constants/FrameworkConstants.java new file mode 100644 index 0000000..92ee335 --- /dev/null +++ b/bundles/flintstones.application.constants/src/flintstones/application/constants/FrameworkConstants.java @@ -0,0 +1,91 @@ +package flintstones.application.constants; + +import java.util.HashMap; +import java.util.Map; + +/** + * @noimplement This interface is not intended to be implemented. + * + * Only used for constants definitions. + * + */ +@SuppressWarnings({ "nls", "javadoc" }) +public interface FrameworkConstants { + String TOPIC_FRAMEWORK = "TOPIC_FRAMEWORK"; + + String TOPIC_FRAMEWORK_ALLTOPICS = "TOPIC_FRAMEWORK/*"; + + String TOPIC_FRAMEWORK_ALTERNATIVE_ALLTOPICS = "TOPIC_FRAMEWORK/PROBLEMELEMENT/ALTERNATIVE/*"; + String TOPIC_FRAMEWORK_ALTERNATIVE_MODIFIED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/ALTERNATIVE/MODIFIED"; + String TOPIC_FRAMEWORK_ALTERNATIVE_CREATED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/ALTERNATIVE/CREATED"; + String TOPIC_FRAMEWORK_ALTERNATIVE_DELETED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/ALTERNATIVE/DELETED"; + + String TOPIC_FRAMEWORK_EXPERT_ALLTOPICS = "TOPIC_FRAMEWORK/PROBLEMELEMENT/EXPERT/*"; + String TOPIC_FRAMEWORK_EXPERT_CREATED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/EXPERT/CREATED"; + String TOPIC_FRAMEWORK_EXPERT_MODIFIED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/EXPERT/MODIFIED"; + String TOPIC_FRAMEWORK_EXPERT_DELETED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/EXPERT/DELETED"; + + String TOPIC_FRAMEWORK_CRITERION_ALLTOPICS = "TOPIC_FRAMEWORK/PROBLEMELEMENT/CRITERION/*"; + String TOPIC_FRAMEWORK_CRITERION_CREATED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/CRITERION/CREATED"; + String TOPIC_FRAMEWORK_CRITERION_MODIFIED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/CRITERION/MODIFIED"; + String TOPIC_FRAMEWORK_CRITERION_DELETED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/CRITERION/DELETED"; + + String TOPIC_FRAMEWORK_SORTINGCLASS_ALLTOPICS = "TOPIC_FRAMEWORK/PROBLEMELEMENT/SORTINGCLASS/*"; + String TOPIC_FRAMEWORK_SORTINGCLASS_MODIFIED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/SORTINGCLASS/MODIFIED"; + String TOPIC_FRAMEWORK_SORTINGCLASS_CREATED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/SORTINGCLASS/CREATED"; + String TOPIC_FRAMEWORK_SORTINGCLASS_DELETED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/SORTINGCLASS/DELETED"; + + String TOPIC_FRAMEWORK_SORTINGPROFILE_ALLTOPICS = "TOPIC_FRAMEWORK/PROBLEMELEMENT/SORTINGPROFILE/*"; + String TOPIC_FRAMEWORK_SORTINGPROFILE_MODIFIED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/SORTINGPROFILE/MODIFIED"; + String TOPIC_FRAMEWORK_SORTINGPROFILE_CREATED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/SORTINGPROFILE/CREATED"; + String TOPIC_FRAMEWORK_SORTINGPROFILE_DELETED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/SORTINGPROFILE/DELETED"; + + String TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS = "TOPIC_FRAMEWORK/PROBLEMELEMENT/*"; + String TOPIC_FRAMEWORK_PROBLEMELEMENT_MODIFIED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/MODIFIED"; + String TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/CREATED"; + String TOPIC_FRAMEWORK_PROBLEMELEMENT_DELETED = "TOPIC_FRAMEWORK/PROBLEMELEMENT/DELETED"; + + String TOPIC_FRAMEWORK_DOMAIN_ALLTOPICS = "TOPIC_FRAMEWORK/DOMAIN/*"; + String TOPIC_FRAMEWORK_DOMAIN_CREATED = "TOPIC_FRAMEWORK/DOMAIN/CREATED"; + String TOPIC_FRAMEWORK_DOMAIN_MODIFIED = "TOPIC_FRAMEWORK/DOMAIN/MODIFIED"; + String TOPIC_FRAMEWORK_DOMAIN_DELETED = "TOPIC_FRAMEWORK/DOMAIN/DELETED"; + + String TOPIC_VALUATION = "TOPIC_VALUATION"; + + String TOPIC_VALUATION_ALLTOPICS = "TOPIC_VALUATION/*"; + + String TOPIC_VALUATION_MODIFIED = "TOPIC_VALUATION/MODIFIED"; + String TOPIC_VALUATION_CREATED = "TOPIC_VALUATION/CREATED"; + String TOPIC_VALUATION_DELETED = "TOPIC_VALUATION/DELETED"; + String TOPIC_VALUATION_ASSIGNED = "TOPIC_VALUATION/ASSIGNED"; + + String TOPIC_METHOD_ALLTOPICS = "TOPIC_METHOD/*"; + String TOPIC_METHOD_LOAD = "TOPIC_METHOD/LOAD"; + String TOPIC_METHOD_PHASE_REFRESH = "TOPIC_METHOD/PHASE/REFRESH"; + String TOPIC_METHOD_PHASE_POSTCONSTRUCT = "TOPIC_METHOD/PHASE/POSTCONSTRUCT"; + String TOPIC_METHOD_PHASE_PHANTOM = "TOPIC_METHOD/PHASE/PHANTOM"; + String TOPIC_METHOD_PHASE_PHANTOM_RESPONSE = "TOPIC_METHOD/PHASE/PHANTOM_RESPONSE"; + + String TOPIC_PERSPECTIVE_ALLTOPICS = "TOPIC_PERSPECTIVE/*"; + String TOPIC_PERSPECTIVE_CHANGE = "TOPIC_PERSPECTIVE/CHANGE"; + + String TOPIC_SELECTION_VALUATION = "TOPIC_SELECTION/VALUATION"; + String TOPIC_SELECTION_FRAMEWORK_ALLTOPICS = "TOPIC_SELECTION/FRAMEWORK/*"; + String TOPIC_SELECTION_FRAMEWORK_DOMAIN = "TOPIC_SELECTION/FRAMEWORK/DOMAIN"; + String TOPIC_SELECTION_FRAMEWORK_PROBLEMELEMENT = "TOPIC_SELECTION/FRAMEWORK/PROBLEMELEMENT"; + String TOPIC_SELECTION_METHOD = "TOPIC_SELECTION/METHOD"; + String TOPIC_SELECTION_DOCUMENTATION = "TOPIC_SELECTION/DOCUMENTATION"; + + + + public static Map map(String key, Object item) { + Map m = new HashMap<>(); + m.put(key, item); + return m; + } + + public static Map empty(){ + Map m = new HashMap<>(); + return m; + } +} diff --git a/bundles/flintstones.application.control/.classpath b/bundles/flintstones.application.control/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.application.control/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.control/.polyglot.META-INF b/bundles/flintstones.application.control/.polyglot.META-INF new file mode 100644 index 0000000..fdca2f4 --- /dev/null +++ b/bundles/flintstones.application.control/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.control + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Control + diff --git a/bundles/flintstones.application.control/.project b/bundles/flintstones.application.control/.project new file mode 100644 index 0000000..7c8b4ed --- /dev/null +++ b/bundles/flintstones.application.control/.project @@ -0,0 +1,45 @@ + + + flintstones.application.control + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362513 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.control/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.control/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.control/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.control/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.control/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.control/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.control/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.control/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.control/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.control/META-INF/MANIFEST.MF b/bundles/flintstones.application.control/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e4a288b --- /dev/null +++ b/bundles/flintstones.application.control/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Control +Bundle-SymbolicName: flintstones.application.control +Bundle-Version: 1.0.0.qualifier +Require-Bundle: flintstones.application, + flintstones.model.application.service, + flintstones.model.ui.service, + flintstones.helper.ui, + org.eclipse.e4.core.services, + org.eclipse.e4.ui.services, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + javax.inject, + javax.annotation +Automatic-Module-Name: flintstones.application.control +Bundle-RequiredExecutionEnvironment: JavaSE-11 diff --git a/bundles/flintstones.application.control/build.properties b/bundles/flintstones.application.control/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.application.control/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/ConsolaControl.java b/bundles/flintstones.application.control/src/flintstones/application/control/ConsolaControl.java new file mode 100644 index 0000000..faa5be8 --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/ConsolaControl.java @@ -0,0 +1,57 @@ +package flintstones.application.control; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +import flintstones.model.ui.service.UiService; + +/** + * The Class ConsolaControl. + */ +public class ConsolaControl { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The text. */ + private Text text; + + /** + * Creates the part control. + * + * @param parent the parent + */ + @PostConstruct + public void createPartControl(Composite parent) { + text = new Text(parent, SWT.READ_ONLY | SWT.MULTI); + OutputStream out = new OutputStream() { + @Override + public void write(int b) throws IOException { + if (text.isDisposed()) + return; + text.append(String.valueOf((char) b)); + } + }; + final PrintStream oldOut = System.out; + System.setOut(new PrintStream(out)); + text.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + System.setOut(oldOut); + } + }); + text.setBackground(UiService.getColor(255)); + } + +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/SpacerControl.java b/bundles/flintstones.application.control/src/flintstones/application/control/SpacerControl.java new file mode 100644 index 0000000..62bbecf --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/SpacerControl.java @@ -0,0 +1,17 @@ +package flintstones.application.control; + +import javax.annotation.PostConstruct; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; + +@SuppressWarnings("javadoc") +public class SpacerControl { + @PostConstruct + public void postConstruct(final Composite parent) { + Composite body = new Composite(parent, SWT.NONE); + + body.setLayout(new FillLayout()); + } +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/ExitHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/ExitHandler.java new file mode 100644 index 0000000..1549f70 --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/ExitHandler.java @@ -0,0 +1,25 @@ +package flintstones.application.control.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.application.model.IApplicationService; + +/** + * The Class ExitHandler. Hanlder that close the app. + */ +public class ExitHandler { + + /** The app service. */ + @Inject + IApplicationService appService; + + /** + * Execute. + */ + @Execute + public void execute() { + this.appService.close(); + } +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/NewHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/NewHandler.java new file mode 100644 index 0000000..c578727 --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/NewHandler.java @@ -0,0 +1,37 @@ +package flintstones.application.control.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.application.model.IApplicationService; +import flintstones.application.handlers.PerspectiveSwitcher; + +/** + * The Class NewHandler creates a new proyect. + */ +public class NewHandler { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The app service. */ + @Inject + IApplicationService appService; + + /** + * Execute. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + @Execute + public void execute() { + this.appService.newProblem(); + ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective("flintstones.application.perspective.framework"); + + } + +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/OpenFs4FolderHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/OpenFs4FolderHandler.java new file mode 100644 index 0000000..d00b55e --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/OpenFs4FolderHandler.java @@ -0,0 +1,30 @@ + +package flintstones.application.control.handler; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.application.model.IApplicationService; + +public class OpenFs4FolderHandler { + + @Inject + IApplicationService appService; + + @Execute + public void execute() { + String folder = appService.getFS4FolderPath(); + try { + Desktop.getDesktop().open(new File(folder)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/OpenHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/OpenHandler.java new file mode 100644 index 0000000..ddfc0a8 --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/OpenHandler.java @@ -0,0 +1,65 @@ +package flintstones.application.control.handler; + +import javax.inject.Inject; +import javax.inject.Named; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import flintstones.application.model.IApplicationService; + +/** + * The Class OpenHandler opens a file from disk. + */ +public class OpenHandler { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** The app service. */ + @Inject + IApplicationService appService; + + /** The shell. */ + @Inject + @Named(IServiceConstants.ACTIVE_SHELL) + Shell shell; + + /** The Constant FILTER_NAMES. */ + private static final String[] FILTER_NAMES = { "Flintstones files (*.flintstones)", "XML(*.xml)" }; //$NON-NLS-1$ //$NON-NLS-2$ + + /** The Constant FILTER_EXTS. */ + private static final String[] FILTER_EXTS = { "*.flintstones", "*.xml" }; //$NON-NLS-1$ //$NON-NLS-2$ + + /** + * Execute. + * + * @throws ParserConfigurationException the parser configuration exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws SAXException the SAX exception + * @throws XMLStreamException the XML stream exception + */ + @Execute + public void execute() { + + FileDialog dlg = new FileDialog(this.shell, SWT.OPEN); + dlg.setFilterNames(OpenHandler.FILTER_NAMES); + dlg.setFilterExtensions(OpenHandler.FILTER_EXTS); + dlg.setFilterPath(appService.getFS4FolderPath()); + + String fileName = dlg.open(); + + if (fileName != null) + this.appService.loadProblem(fileName); + + } + +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/RedoHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/RedoHandler.java new file mode 100644 index 0000000..ba987c4 --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/RedoHandler.java @@ -0,0 +1,11 @@ +package flintstones.application.control.handler; + +import org.eclipse.e4.core.di.annotations.Execute; + +@SuppressWarnings("javadoc") +public class RedoHandler { + @Execute + public void execute() { + System.err.println("Redo handler called."); //$NON-NLS-1$ + } +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveAndCloseHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveAndCloseHandler.java new file mode 100644 index 0000000..bbf68d5 --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveAndCloseHandler.java @@ -0,0 +1,11 @@ +package flintstones.application.control.handler; + +import org.eclipse.e4.core.di.annotations.Execute; + +@SuppressWarnings("javadoc") +public class SaveAndCloseHandler { + @Execute + public void execute() { + // System.out.println("Save and close handler called."); //$NON-NLS-1$ + } +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveAsHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveAsHandler.java new file mode 100644 index 0000000..2e620bc --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveAsHandler.java @@ -0,0 +1,63 @@ +package flintstones.application.control.handler; + +import javax.inject.Inject; +import javax.inject.Named; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import flintstones.application.model.IApplicationService; + +/** + * The Class SaveAsHandler. + */ +public class SaveAsHandler { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** The app service. */ + @Inject + IApplicationService appService; + + /** The shell. */ + @Inject + @Named(IServiceConstants.ACTIVE_SHELL) + Shell shell; + + /** The Constant FILTER_NAMES. */ + private static final String[] FILTER_NAMES = { "Flintstones files (*.flintstones)" }; //$NON-NLS-1$ + + /** The Constant FILTER_EXTS. */ + private static final String[] FILTER_EXTS = { "*.flintstones" }; //$NON-NLS-1$ + + /** + * Execute. + * + * @throws ParserConfigurationException the parser configuration exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws SAXException the SAX exception + * @throws XMLStreamException the XML stream exception + */ + @Execute + public void execute() { + + FileDialog dlg = new FileDialog(this.shell, SWT.SAVE); + dlg.setFilterNames(SaveAsHandler.FILTER_NAMES); + dlg.setFilterExtensions(SaveAsHandler.FILTER_EXTS); + String fileName = dlg.open(); + + if (fileName != null) + this.appService.saveProblemAs(fileName); + + } + +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveHandler.java new file mode 100644 index 0000000..8270c84 --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/SaveHandler.java @@ -0,0 +1,26 @@ +package flintstones.application.control.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.application.model.IApplicationService; + +/** + * The Class SaveHandler. + */ +public class SaveHandler { + + /** The app service. */ + @Inject + IApplicationService appService; + + /** + * Execute. + */ + @Execute + public void execute() { + this.appService.saveProblem(); + } + +} diff --git a/bundles/flintstones.application.control/src/flintstones/application/control/handler/UndoHandler.java b/bundles/flintstones.application.control/src/flintstones/application/control/handler/UndoHandler.java new file mode 100644 index 0000000..1bbd129 --- /dev/null +++ b/bundles/flintstones.application.control/src/flintstones/application/control/handler/UndoHandler.java @@ -0,0 +1,11 @@ +package flintstones.application.control.handler; + +import org.eclipse.e4.core.di.annotations.Execute; + +@SuppressWarnings("javadoc") +public class UndoHandler { + @Execute + public void execute() { + System.err.println("Undo handler called."); //$NON-NLS-1$ + } +} diff --git a/bundles/flintstones.application.debug/.classpath b/bundles/flintstones.application.debug/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.application.debug/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.debug/.polyglot.META-INF b/bundles/flintstones.application.debug/.polyglot.META-INF new file mode 100644 index 0000000..9eddde6 --- /dev/null +++ b/bundles/flintstones.application.debug/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.debug + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Debug + diff --git a/bundles/flintstones.application.debug/.project b/bundles/flintstones.application.debug/.project new file mode 100644 index 0000000..7e70566 --- /dev/null +++ b/bundles/flintstones.application.debug/.project @@ -0,0 +1,45 @@ + + + flintstones.application.debug + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362514 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.debug/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.debug/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.debug/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.debug/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.debug/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.debug/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.debug/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.debug/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.debug/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.debug/META-INF/MANIFEST.MF b/bundles/flintstones.application.debug/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3609876 --- /dev/null +++ b/bundles/flintstones.application.debug/META-INF/MANIFEST.MF @@ -0,0 +1,44 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Debug +Bundle-SymbolicName: flintstones.application.debug;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.application.debug +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.helper.data, + javax.inject, + flintstones.model.problemelement.service, + flintstones.model.valuation.service, + flintstones.entity.valuation, + flintstones.entity.problemelement, + flintstones.application.constants, + flintstones.model.domain.ui.service, + org.eclipse.e4.core.contexts, + flintstones.model.domain.service, + flintstones.domain.fuzzyset, + org.apache.commons.lang, + flintstones.model.ahppreferences.service, + flintstones.model.application.service, + flintstones.model.ahpsort.profileassignment.service, + flintstones.operator, + flintstones.valuation.ui, + org.eclipse.e4.ui.workbench, + org.eclipse.e4.core.di, + org.eclipse.jface, + javax.annotation, + flintstones.model.method.service, + flintstones.model.method.phase.service, + flintstones.entity.method.phase.ui, + org.eclipse.e4.ui.model.workbench, + flintstones.model.ahp.referencepoint.service, + flintstones.helper.debug, + flintstones.model.engine.r.service, + flintstones.entity.method.phase, + flintstones.entity.method, + flintstones.domain.numeric.integer, + flintstones.valuation.linguistic, + flintstones.valuation.hesitant, + flintstones.valuation.numeric.real, + flintstones.valuation.numeric.integer +Import-Package: org.eclipse.core.runtime +Export-Package: flintstones.application.debug.handler diff --git a/bundles/flintstones.application.debug/borrar/faq.en.md b/bundles/flintstones.application.debug/borrar/faq.en.md new file mode 100644 index 0000000..b42e544 --- /dev/null +++ b/bundles/flintstones.application.debug/borrar/faq.en.md @@ -0,0 +1,3 @@ +# Wenas info + +![imagen](borrar/tpr.jpg) \ No newline at end of file diff --git a/bundles/flintstones.application.debug/borrar/tpr.jpg b/bundles/flintstones.application.debug/borrar/tpr.jpg new file mode 100644 index 0000000..a56a9e8 Binary files /dev/null and b/bundles/flintstones.application.debug/borrar/tpr.jpg differ diff --git a/bundles/flintstones.application.debug/build.properties b/bundles/flintstones.application.debug/build.properties new file mode 100644 index 0000000..32bb993 --- /dev/null +++ b/bundles/flintstones.application.debug/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + borrar/ diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/addon/AutoAddon.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/addon/AutoAddon.java new file mode 100644 index 0000000..231365f --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/addon/AutoAddon.java @@ -0,0 +1,89 @@ +package flintstones.application.debug.addon; + +import java.util.Arrays; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.application.model.IApplicationService; +import flintstones.helper.data.text.DebugStream; +import flintstones.helper.debug.DH; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.engine.r.service.IREngineService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; + +// Importante: +// 1 - Nada de javadoc aqui. +// 2 - El c�digo que se quede aqui debe poder borrarse y que todo funcione. +// 3 - Usar solo para pruebas +// 4 - No tocar init ni el constructor. Colocad el programa/prueba en auto() + +@SuppressWarnings({ "nls", "javadoc" }) +public class AutoAddon { + + @Inject + IEclipseContext context; + + @Inject + IApplicationService appService; + + @Inject + IValuationService valuationService; + + @Inject + IDomainService domainService; + + @Inject + IDomainUIService domainUI; + + @Inject + IOperatorService operatorService; + + @Inject + IProblemElementService problemService; + + @Inject + IREngineService rService; + + public AutoAddon() { + } + + @PostConstruct + public void init(IEclipseContext context) { + String[] args = Platform.getCommandLineArgs(); + + if (Arrays.asList(args).stream().anyMatch(flag -> flag.equals("-autoAddon"))) { + DH.out("!INFO Ejecutando AutoAddon ya que -autoAddon esta presente"); + this.auto(context); + } + + if (Arrays.asList(args).stream().anyMatch(flag -> flag.equals("-autoSystemOut"))) { + DH.out("!INFO Mejorando System.Out.Print ya que -autoSystemOut esta presente"); + DebugStream.activate(); + } + +// DH.hide("router"); + DH.hide("router"); +// DH.hide("I/O"); + DH.hide("locale"); + } + + public void auto(IEclipseContext context) { + +// ContextInjectionFactory.make(ExecuteDebugHandler.class, context).execute(); +// BrowserShell shell = new BrowserShell(); +// SvgBrowser br = new SvgBrowser(shell.get()); +// br.setCanvas(new SortingDiagram()); +// shell.setWidget(br); +// br.render(); +// +// shell.open(); + } + +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ChangeProblemTypeHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ChangeProblemTypeHandler.java new file mode 100644 index 0000000..20ed726 --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ChangeProblemTypeHandler.java @@ -0,0 +1,36 @@ +package flintstones.application.debug.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.workbench.modeling.EModelService; + +import flintstones.application.model.IApplicationService; +import flintstones.application.model.ProblemType; + +public class ChangeProblemTypeHandler { + + @Inject + IApplicationService appService; + + @Inject + EModelService modelService; + + @Inject + MApplication application; + + @Execute + public void execute() { + + ProblemType type = appService.getProblemType(); + type = type.equals(ProblemType.Ranking) ? ProblemType.Sorting : ProblemType.Ranking; + appService.launchProblem(type); + + +// MUIElement uiElement = (MUIElement) modelService.find(ApplicationContants.MHandledToolItem_Change_Problem_Type, this.application); // $NON-NLS-1$ +// MHandledToolItem item = (MHandledToolItem)uiElement; +// item.setLabel(type.toString() + " Problem"); + + } +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ClearDomainDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ClearDomainDebugHandler.java new file mode 100644 index 0000000..d7596e0 --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ClearDomainDebugHandler.java @@ -0,0 +1,49 @@ +package flintstones.application.debug.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.helper.debug.DH; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.valuation.service.IValuationService; + +@SuppressWarnings("javadoc") +public class ClearDomainDebugHandler { + + /** The broker. */ + @Inject + IEventBroker broker; + + /** The context. */ + @Inject + IEclipseContext context; + + @Inject + IDomainService domainService; + + @Inject + IValuationService valuationService; + + @Execute + public void execute() { + + DH.out("[DEBUG] Eliminando todos los dominios" ); + + domainService.clear(); + valuationService.clear(); + sendEvents(); + } + + + private void sendEvents() { + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_DELETED, null); + this.broker.post(FrameworkConstants.TOPIC_VALUATION_DELETED, null); + } + + + +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpExtensionPointDataDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpExtensionPointDataDebugHandler.java new file mode 100644 index 0000000..e2fb02f --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpExtensionPointDataDebugHandler.java @@ -0,0 +1,72 @@ +package flintstones.application.debug.handler; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.helper.debug.DH; + +@SuppressWarnings("javadoc") +public class DumpExtensionPointDataDebugHandler { + + @Execute + public void execute() { + + IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); + IExtensionPoint[] extensionPoints = extensionRegistry.getExtensionPoints(); + + DH.l(5); + + DH.out(" MOSTRANDO PUNTOS DE EXTENSIÓN"); + DH.out(" RECOMENDADO PEGAR TODO EN UN EDITOR DE TEXTO"); + DH.out(" Y FORMATEAR COMO YAML"); + DH.l(2); + for(IExtensionPoint extensionPoint : extensionPoints) { + if(extensionPoint.getUniqueIdentifier().contains("flintstones")) { + show(extensionPoint); + DH.l(2); + } + + } + } + + private void show(IExtensionPoint extensionPoint) { + DH.out("IDENTIFICADOR " + extensionPoint.getUniqueIdentifier() + " ==================================== :" ); + + // LEVEL 1 - El de eclipse. Tiene X atributos, almenos uno debe ser nuestro. + IExtension[] extensions = extensionPoint.getExtensions(); + for(IExtension extension : extensions) { + IConfigurationElement[] configurationElements = extension.getConfigurationElements(); + for( IConfigurationElement configElement : configurationElements ) { + showConfig(configElement,2); + DH.out(""); + } + } + } + + private void showConfig(IConfigurationElement configElement, int level) { + + String indentText = new String(new char[level-1]).replace("\0", " "); + DH.out(indentText + configElement.getName()+":"); + + // LEVEL 2 - AQUí ESTAN NUESTROS VALORES + String[] atributes = configElement.getAttributeNames(); + indentText = new String(new char[level]).replace("\0", " "); + + for( String atribute : atributes ) { + DH.out( indentText + atribute + " : " + configElement.getAttribute(atribute)); + } + + // Si hay sub-valores, recursividad + IConfigurationElement[] children = configElement.getChildren(); + if( children.length > 0 ) { + for( IConfigurationElement subConfig : children ) { + showConfig(subConfig, level +1); + } + } + + } +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpPhasesOutputDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpPhasesOutputDebugHandler.java new file mode 100644 index 0000000..dfdc9e2 --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpPhasesOutputDebugHandler.java @@ -0,0 +1,59 @@ +package flintstones.application.debug.handler; + +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.entity.method.Method; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.data.text.ClassToString; +import flintstones.helper.debug.DH; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.method.service.IMethodService; + +@SuppressWarnings("javadoc") +public class DumpPhasesOutputDebugHandler { + + @Inject + IPhaseMethodService phaseService; + + @Inject + IMethodService methodService; + + @Execute + public void execute() { + + DH.l(); + PhaseMethodUI[] phases = phaseService.getAll(); + for (PhaseMethodUI phase : phases) { + DH.out("===== Export " + phase.getModel().getName() + "(" + phase.getPosition() + ")" + " - " + + phase.getModel().getId()); + DH.out(phase.getModel().getExportedSummary() + "\n"); + } + + DH.l(3); + + for(Method m : methodService.getAll()) { + + HashMap data = m.getExportedData(); + DH.out("===== Export " + m.getName() + " - "+ m.getId()); + + for(Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = ClassToString.getClassAsString(entry.getValue()); + + DH.out(key + " => " + value); + + } + + } + + DH.l(); + + + } + +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpServicesDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpServicesDebugHandler.java new file mode 100644 index 0000000..2743478 --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/DumpServicesDebugHandler.java @@ -0,0 +1,83 @@ +package flintstones.application.debug.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.application.model.IApplicationService; +import flintstones.helper.debug.DH; +import flintstones.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.method.service.IMethodService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.ui.service.IValuationUIService; + +@SuppressWarnings("javadoc") +public class DumpServicesDebugHandler { + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + @Inject + IDomainUIService uiDomainService; + + @Inject + IValuationService valuationService; + + @Inject + IValuationUIService valuationUIService; + + @Inject + IOperatorService operatorService; + + @Inject + IMethodService methodService; + + @Inject + IPhaseMethodService phaseService; + + @Inject + IApplicationService appService; + + @Inject + IProblemPreferencesService ppService; + + @Inject + IProfileAssignmentService profileService; + + @Inject + IReferencePointService referencePointService; + + @Execute + public void execute() { + show(problemService, "problemService"); + show(domainService, "domainService"); + show(valuationService, "valuationService"); + show(appService, "appService"); + show(methodService, "methodService"); + show(phaseService, "phaseService"); + show(ppService, "problemPreferencesService"); + show(profileService, "profileService"); + show(referencePointService, "referencePointService"); + } + + private void show(Object service, String name) { + + String preText = "========= " + name + " =========\n"; + String text = service.toString(); + String postText = "\n\n"; + + DH.out(preText + text + postText); + } + +} + diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ExecuteDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ExecuteDebugHandler.java new file mode 100644 index 0000000..6256e3b --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ExecuteDebugHandler.java @@ -0,0 +1,136 @@ +package flintstones.application.debug.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + +import flintstones.application.model.IApplicationService; +import flintstones.application.model.ProblemType; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; + +@SuppressWarnings("javadoc") +public class ExecuteDebugHandler { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + @Inject + EModelService modelService; + + @Inject + MApplication application; + + @Inject + EPartService partService; + + @Inject + IApplicationService appService; + + @Inject + IProfileAssignmentService profileService; + + @Execute + public void execute() { + +// ahpService.unregister("AHPAlternativeRatingPart"); + +// ahpService.register("Title", +// "flintstones.domain.ahp", +// "flintstones.application.perspective.gathering.ahp.ui", +// "flintstones.application.perspective.gathering.ahp.ui", +// "AHPAlternativeRatingPart"); +// +// ProblemElement[] experts = problemService.getAll(Expert.Type); +// ProblemElement[] crits = problemService.getAll(Criterion.Type); +// +// if(experts.length > 0 && crits.length > 0) { +// +// Expert e = (Expert) experts[0]; +// Criterion c = (Criterion) crits[0]; +// ProfileAssignment pas = profileService.get(e, c); +// +// BrowserShell shell = new BrowserShell(); +// SvgBrowser br = new SvgBrowser(shell.get()); +// +// SortingDiagram diagram = new SortingDiagram(); +// AHPSortProfile p; +// diagram.setProfiles(pas.getAllProfiles()); +// br.setCanvas(diagram); +// shell.setWidget(br); +// br.render(); +// +// shell.open(); +// +// } + + + + ProblemType type = appService.getProblemType(); + type = type.equals(ProblemType.Ranking) ? ProblemType.Sorting : ProblemType.Ranking; + appService.launchProblem(type); + +// int x = 0; + + + + + + + +// +// BrowserShell shell = new BrowserShell(); +// +// SvgChart chart = new SvgChart(1666, 1000, 1, 1); +// SvgBrowser br = new SvgBrowser(shell.get(), chart); +// +// double min = 0.0; +// double max = 1.0; +// +// LineSeries redSeries = new LineSeries(); +// for(int i = 0; i < 11; i++) { +// +// Random r = new Random(); +// double a = (double)i/10; +// double b = min + (max - min) * r.nextDouble(); +// +// redSeries.add(a, b); +// +// } +// redSeries.setColor("#ff0000"); +// redSeries.showLegend(true); +// redSeries.showMarkers(true); +// +// // lines +// double[][] points = new double[4][2]; +// points[0][0] = .10; +// points[0][1] = .10; +// points[1][0] = .20; +// points[1][1] = .20; +// points[2][0] = .30; +// points[2][1] = .30; +// points[3][0] = .40; +// points[3][1] = .15; +// +// LineSeries series = new LineSeries(points); +// series.setColor("#0000ff"); +// series.showLegend(false); +// +// chart.drawLineSeries(series); +// chart.drawLineSeries(redSeries); +// chart.drawMarkers(false, false, 0.1); +// +// shell.setWidget(br); +// br.render(); +// +// shell.open(); + + } +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ExportToAFRYCA.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ExportToAFRYCA.java new file mode 100644 index 0000000..76281b0 --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/ExportToAFRYCA.java @@ -0,0 +1,262 @@ +package flintstones.application.debug.handler; + +import java.io.FileWriter; +import java.io.IOException; + +import javax.inject.Inject; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.hesitant.HesitantValuation; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.numeric.integer.IntegerValuation; +import flintstones.valuation.numeric.real.RealValuation; + +public class ExportToAFRYCA { + + private static final String AFRYCA_INTEGER_DOMAIN = "afryca.domain.integer"; + private static final String AFRYCA_REAL_DOMAIN = "afryca.domain.real"; + private static final String AFRYCA_LINGUISTIC_DOMAIN = "afryca.domain.fuzzyset"; + private static final String AFRYCA_STRUCTURE = "afryca.decisionmatrix"; + + private static final String[] FILTER_NAMES = { "AFRYCA files (*.afryca)" }; //$NON-NLS-1$ + private static final String[] FILTER_EXTS = { "*.afryca" }; //$NON-NLS-1$ + + private static final String SEMICOLON = ";"; + public static final String SEPARATOR = "_SEPARATOR_"; + + @Inject + IProblemElementService problemService; + + @Inject + private IDomainService domainService; + + @Inject + private IValuationService valuationService; + + + @Execute + public void execute() { + try { + export(); + } catch (IOException | XMLStreamException e) { + e.printStackTrace(); + } + + } + + private void export() throws IOException, XMLStreamException { + FileDialog dlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); + dlg.setFilterNames(FILTER_NAMES); + dlg.setFilterExtensions(FILTER_EXTS); + + String fileName = dlg.open(); + if(fileName != null) + write(fileName); + } + + private void write(String fileName) throws IOException, XMLStreamException { + XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileWriter(fileName)); + streamWriter.writeStartElement("gdmp"); //$NON-NLS-1$ + streamWriter.writeStartElement("file"); //$NON-NLS-1$ + streamWriter.writeEndElement(); //$NON-NLS-1$ + writeExperts(streamWriter); + writeCriteria(streamWriter); + writeAlternatives(streamWriter); + writeDomains(streamWriter); + writeStructure(streamWriter); + writePreferences(streamWriter); + writeDomainsStructures(streamWriter); + streamWriter.writeEndElement(); + streamWriter.writeEndDocument(); + streamWriter.flush(); + streamWriter.close(); + } + + private void writeExperts(XMLStreamWriter streamWriter) throws XMLStreamException { + streamWriter.writeStartElement("experts"); //$NON-NLS-1$ + for(ProblemElement e: problemService.getSubElements(Expert.Type)) { + streamWriter.writeStartElement("expert");//$NON-NLS-1$ + streamWriter.writeCharacters(e.getName()); + streamWriter.writeEndElement(); + } + streamWriter.writeEndElement(); + } + + private void writeCriteria(XMLStreamWriter streamWriter) throws XMLStreamException { + streamWriter.writeStartElement("criteria"); //$NON-NLS-1$ + for(ProblemElement c: problemService.getSubElements(Criterion.Type)) { + streamWriter.writeStartElement("criterion");//$NON-NLS-1$ + streamWriter.writeCharacters(c.getName()); + streamWriter.writeEndElement(); + } + streamWriter.writeEndElement(); + } + + private void writeAlternatives(XMLStreamWriter streamWriter) throws XMLStreamException { + streamWriter.writeStartElement("alternatives"); //$NON-NLS-1$ + for(ProblemElement a: problemService.getAll(Alternative.Type)) { + streamWriter.writeStartElement("alternative"); + streamWriter.writeCharacters(a.getName()); + streamWriter.writeEndElement(); + } + streamWriter.writeEndElement(); //$NON-NLS-1$ + } + + private void writeDomains(XMLStreamWriter streamWriter) throws XMLStreamException { + streamWriter.writeStartElement("domains"); //$NON-NLS-1$ + for(Domain d: domainService.getAll()) { + streamWriter.writeStartElement("domain"); + if(d instanceof NumericIntegerDomain) { + streamWriter.writeCharacters(AFRYCA_INTEGER_DOMAIN); + streamWriter.writeCharacters(SEMICOLON); + streamWriter.writeCharacters(d.getName()); + streamWriter.writeCharacters(SEMICOLON); + streamWriter.writeCharacters(d.toString()); + } else if(d instanceof NumericRealDomain) { + streamWriter.writeCharacters(AFRYCA_REAL_DOMAIN); + streamWriter.writeCharacters(SEMICOLON); + streamWriter.writeCharacters(d.getName()); + streamWriter.writeCharacters(SEMICOLON); + streamWriter.writeCharacters(d.toString()); + } else if(d instanceof FuzzySet) { + streamWriter.writeCharacters(AFRYCA_LINGUISTIC_DOMAIN); + streamWriter.writeCharacters(SEMICOLON); + streamWriter.writeCharacters(d.getName()); + streamWriter.writeCharacters(SEMICOLON); + streamWriter.writeCharacters(toStringLinguisticDomain((FuzzySet) d)); + } + streamWriter.writeEndElement(); + } + streamWriter.writeEndElement(); + } + + private String toStringLinguisticDomain(FuzzySet domain) { + String result = ""; //$NON-NLS-1$ + int cardinality = domain.getLabelSet().getCardinality(); + + if(cardinality > 0) { + for(int i = 0; i < cardinality; ++i) { + if(i > 0) { + result += "separator"; //$NON-NLS-1$ + } + result += "[" + toStringLabel(domain.getLabelSet().getLabels().get(i)) + ";" + domain.getValues().get(i) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + } + + return result; + } + + private String toStringLabel(LabelLinguisticDomain label) { + return label.getName() + ";" + toStringSemantic((TrapezoidalFunction) label.getSemantic()); + } + + private String toStringSemantic(TrapezoidalFunction semantic) { + return ("Trapezoidal(" + semantic.getLimits()[0] + ", " + semantic.getLimits()[1] + ", " + + semantic.getLimits()[2] + ", " + semantic.getLimits()[3] + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + } + + private void writeStructure(XMLStreamWriter streamWriter) throws XMLStreamException { + streamWriter.writeStartElement("structure"); + streamWriter.writeCharacters(AFRYCA_STRUCTURE); + streamWriter.writeEndElement(); + } + + private void writePreferences(XMLStreamWriter streamWriter) throws XMLStreamException { + streamWriter.writeStartElement("preferences"); + double value; + LabelLinguisticDomain label; + + ProblemElement exp, alt, crit; + for(int expert = 0; expert < problemService.getSubElements(Expert.Type).length; ++expert) { + exp = problemService.getSubElements(Expert.Type)[expert]; + for(int row = 0; row < problemService.getSubElements(Criterion.Type).length; ++row) { + streamWriter.writeStartElement("preference"); + crit = problemService.getSubElements(Criterion.Type)[row]; + for(int col = 0; col < problemService.getAll(Alternative.Type).length; ++col) { + alt = problemService.getAll(Alternative.Type)[col]; + ProblemElementKey pek = new ProblemElementKey((Expert) exp, (Alternative) alt, (Criterion) crit); + Valuation v = valuationService.getValuationFor(pek); + if(v instanceof IntegerValuation) { + value = ((IntegerValuation) v).getValue(); + streamWriter.writeCharacters(Integer.toString((int) value)); + } else if(v instanceof RealValuation) { + value = ((RealValuation) v).getValue(); + streamWriter.writeCharacters(Double.toString(value)); + } else if(v instanceof LinguisticValuation) { + label = ((LinguisticValuation) v).getLabel(); + streamWriter.writeCharacters(label.getName()); + } else if(v instanceof HesitantValuation) { + streamWriter.writeCharacters(toStringAFRYCA((HesitantValuation) v)); + } + + if(col != problemService.getAll(Alternative.Type).length - 1) + streamWriter.writeCharacters(","); + + } + streamWriter.writeEndElement(); + } + } + streamWriter.writeEndElement(); + } + + public String toStringAFRYCA(HesitantValuation v) { + if (v.isPrimary()) { + return v.getLabel().toString(); + } else if (v.isUnary()) { + return (v.getUnaryRelation().toString() + SEPARATOR + v.getTerm()); //$NON-NLS-1$ + } else if (v.isBinary()) { + return ("Between" + SEPARATOR + v.getLowerTerm() + SEPARATOR + "and" + SEPARATOR + v.getUpperTerm()); + } else { + return " "; //$NON-NLS-1$ + } + } + + private void writeDomainsStructures(XMLStreamWriter streamWriter) throws XMLStreamException { + streamWriter.writeStartElement("domains_structures"); + + ProblemElement exp, alt, crit; + for(int expert = 0; expert < problemService.getSubElements(Expert.Type).length; ++expert) { + exp = problemService.getSubElements(Expert.Type)[expert]; + for(int row = 0; row < problemService.getSubElements(Criterion.Type).length; ++row) { + streamWriter.writeStartElement("domain_structure"); + crit = problemService.getSubElements(Criterion.Type)[row]; + for(int col = 0; col < problemService.getAll(Alternative.Type).length; ++col) { + alt = problemService.getAll(Alternative.Type)[col]; + ProblemElementKey pek = new ProblemElementKey((Expert) exp, (Alternative) alt, (Criterion) crit); + Valuation v = valuationService.getValuationFor(pek); + + streamWriter.writeCharacters(v.getDomain().getName()); + + if(col != problemService.getAll(Alternative.Type).length - 1) + streamWriter.writeCharacters("separator"); + + } + streamWriter.writeEndElement(); + } + } + streamWriter.writeEndElement(); + } + +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/FillOperatorsAggregation.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/FillOperatorsAggregation.java new file mode 100644 index 0000000..09446aa --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/FillOperatorsAggregation.java @@ -0,0 +1,25 @@ +package flintstones.application.debug.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.model.method.phase.IPhaseMethodService; + +@SuppressWarnings("javadoc") +public class FillOperatorsAggregation { + + @Inject + IPhaseMethodService phaseService; + + @Inject + IEventBroker broker; + + @Execute + public void execute() { + System.err.println("Hay que rehacerlo"); + broker.post(PhaseMethodUI.REFRESH_SUB_ID, null); + } +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/FillValuationsDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/FillValuationsDebugHandler.java new file mode 100644 index 0000000..1a63d12 --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/FillValuationsDebugHandler.java @@ -0,0 +1,87 @@ +package flintstones.application.debug.handler; + +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +@SuppressWarnings("javadoc") +public class FillValuationsDebugHandler { + + @Inject + IPhaseMethodService phaseService; + + @Inject + IEventBroker broker; + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + Valuation[] valuations; + + + @Execute + public void execute() { + fill(); + sendEvents(); + } + + private void fill() { + valuations = Arrays.stream(valuationService.getAll()).filter( k -> k.isEvaluated()).toArray(Valuation[]::new); + ProblemElement[] criterions = problemService.getSubElements(Criterion.Type); + ProblemElement[] experts = problemService.getSubElements(Expert.Type); + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + + fillValuations(criterions, experts, alternatives); + + } + + + private void fillValuations(ProblemElement[] cs, ProblemElement[] es, ProblemElement[] as) { + + + for(ProblemElement c : cs ) + for(ProblemElement e : es ) + for(ProblemElement a : as ) { + ProblemElementKey pek = new ProblemElementKey((Expert)e, (Alternative)a, (Criterion)c); + if(valuationService.getValuationFor( pek ) == null || !valuationService.getValuationFor(pek).isEvaluated() ) + fillWithRandomValuation(c,e,a); + } + + } + + + private void fillWithRandomValuation(ProblemElement c, ProblemElement e, ProblemElement a) { + if(valuations.length == 0) + throw new RuntimeException("Es necesario tener al menos 1 evaluación puesta. Se elige al azar entre las disponibles"); + + int rnd = (int) (Math.random() * valuations.length) + 1; + Valuation v = valuations[rnd-1]; + ProblemElementKey pek = new ProblemElementKey((Expert)e, (Alternative)a, (Criterion)c); + + valuationService.addOrUpdate(pek, v); + } + + private void sendEvents() { + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, FrameworkConstants.empty() ); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_CREATED, null); + this.broker.post(FrameworkConstants.TOPIC_VALUATION_CREATED, null); + } + +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/OpenSaveFileDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/OpenSaveFileDebugHandler.java new file mode 100644 index 0000000..dedac39 --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/OpenSaveFileDebugHandler.java @@ -0,0 +1,31 @@ +package flintstones.application.debug.handler; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; + +import javax.inject.Inject; +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.application.model.IApplicationService; + +@SuppressWarnings("javadoc") +public class OpenSaveFileDebugHandler { + + @Inject + IApplicationService appService; + + @Execute + public void execute() { + + String fileName = appService.getSavePath(); + File f = new File(fileName); + + try { + Desktop.getDesktop().open(f); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/SendBrokerDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/SendBrokerDebugHandler.java new file mode 100644 index 0000000..f9aa02b --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/SendBrokerDebugHandler.java @@ -0,0 +1,117 @@ +package flintstones.application.debug.handler; + +import java.lang.reflect.Field; +import java.util.HashMap; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.commands.MCommand; +import org.eclipse.e4.ui.model.application.commands.MParameter; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; +import org.eclipse.e4.ui.model.application.ui.menu.MMenu; +import org.eclipse.e4.ui.workbench.modeling.EModelService; + +import flintstones.application.constants.ApplicationContants; +import flintstones.application.constants.FrameworkConstants; +import flintstones.helper.data.Pair; +import flintstones.helper.data.PairList; +import flintstones.helper.debug.DH; + +@SuppressWarnings("javadoc") +public class SendBrokerDebugHandler { + + @Inject + IEventBroker broker; + + @Inject + MApplication application; + + @Inject + EModelService modelService; + + @Inject + MApplication app; + + MMenu menu; + + @Execute + public void execute(@Optional ParameterizedCommand command) { + @SuppressWarnings("unchecked") + HashMap map = (HashMap) command.getParameterMap(); + String eventID = map.get(ApplicationContants.MParameter_General_Sendbroker); + + // Change selected method + DH.out("Lanzado evento " + eventID); + broker.send(eventID, null); + } + + + @PostConstruct + private void postConstruct() { + buildMenu(); + } + + private void buildMenu() { + + String commandId = ApplicationContants.MCommand_General_Sendbroker; + String menuId = ApplicationContants.MMenu_Sendbroker; + String windowId = ApplicationContants.MWindow_Main; + + MWindow window = (MWindow) this.modelService.find(windowId, this.application); + MCommand command = modelService.findElements(app, commandId, MCommand.class, null).get(0); + MMenu mainMenu = window.getMainMenu(); + + menu = (MMenu) mainMenu.getChildren().stream().filter(k -> k.getElementId().equals(menuId)).findFirst().get(); + + PairList events = getEvents(); + + for(Pair event : events ) { + + MHandledMenuItem menuItem = modelService.createModelElement(MHandledMenuItem.class); + MParameter parameter = modelService.createModelElement(MParameter.class); + + menuItem.setLabel(event.getLeft()); + menuItem.setCommand(command); + + parameter.setName(ApplicationContants.MParameter_General_Sendbroker); + parameter.setValue(event.getRight()); + + menuItem.getParameters().add(parameter); + + menu.getChildren().add(menuItem); + + } + + } + + private PairList getEvents(){ + + PairList pairlist = new PairList<>(); + + Field[] fields = FrameworkConstants.class.getFields(); + for(Field f : fields) { + try { + String name = f.getName(); + String value = (String)f.get(null); + name = name.replaceAll("TOPIC_", ""); + + pairlist.put(name, value); + +// System.out.println(name + " -> " + value ); + + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + return pairlist; + } + +} diff --git a/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/SystemOutDebugHandler.java b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/SystemOutDebugHandler.java new file mode 100644 index 0000000..e2987dc --- /dev/null +++ b/bundles/flintstones.application.debug/src/flintstones/application/debug/handler/SystemOutDebugHandler.java @@ -0,0 +1,14 @@ +package flintstones.application.debug.handler; + +import org.eclipse.e4.core.di.annotations.Execute; + +import flintstones.helper.data.text.DebugStream; + +@SuppressWarnings("javadoc") +public class SystemOutDebugHandler { + + @Execute + private void execute() { + DebugStream.activate(); + } +} diff --git a/bundles/flintstones.application.perspective.documentation.ui/.classpath b/bundles/flintstones.application.perspective.documentation.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.perspective.documentation.ui/.polyglot.META-INF b/bundles/flintstones.application.perspective.documentation.ui/.polyglot.META-INF new file mode 100644 index 0000000..992ca6b --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.perspective.documentation.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.application.perspective.documentation.ui/.project b/bundles/flintstones.application.perspective.documentation.ui/.project new file mode 100644 index 0000000..d4b36f7 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.application.perspective.documentation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362526 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.perspective.documentation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.application.perspective.documentation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c124f5f --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.application.perspective.documentation.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.core.di, + org.eclipse.e4.core.contexts, + flintstones.application, + org.eclipse.e4.core.services, + flintstones.model.ui.service, + org.eclipse.jface, + flintstones.application.constants, + org.eclipse.e4.ui.di, + flintstones.helper.html, + flintstones.helper.data, + javax.annotation +Automatic-Module-Name: flintstones.application.perspective.documentation.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Import-Package: javax.inject;version="1.0.0" diff --git a/bundles/flintstones.application.perspective.documentation.ui/build.properties b/bundles/flintstones.application.perspective.documentation.ui/build.properties new file mode 100644 index 0000000..a14e838 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/build.properties @@ -0,0 +1,6 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + fragment.e4xmi,\ + plugin.xml +source.. = src/ diff --git a/bundles/flintstones.application.perspective.documentation.ui/fragment.e4xmi b/bundles/flintstones.application.perspective.documentation.ui/fragment.e4xmi new file mode 100644 index 0000000..bd8b73c --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/fragment.e4xmi @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.documentation.ui/plugin.xml b/bundles/flintstones.application.perspective.documentation.ui/plugin.xml new file mode 100644 index 0000000..b225c20 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/DocumentationInformation.java b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/DocumentationInformation.java new file mode 100644 index 0000000..5bfd3f7 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/DocumentationInformation.java @@ -0,0 +1,87 @@ +package flintstones.application.perspective.documentation.ui; + + +import java.io.IOException; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.helper.FileHelper; +import flintstones.helper.html.HtmlMarkdown; +import flintstones.model.ui.service.UiService; + +public class DocumentationInformation { + + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + @Inject + MPart part; + + Composite markdownBase; + + @PostConstruct + public void init(Composite parent) { + + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + + markdownBase = new Composite(parent,SWT.BORDER); + UiService.setGridLayout(markdownBase, 1); + UiService.setGridData(markdownBase, 9, 9, true, true); + + } + + private void draw(String path) { + + +// FaqHelper faq = ContextInjectionFactory.make(FaqHelper.class, context); + String content = null; + try { + content = FileHelper.readFile(path); + } catch (IOException e) { + e.printStackTrace(); + } + + HtmlMarkdown markdownViewer = new HtmlMarkdown(markdownBase); + markdownViewer.setFile(content); + markdownViewer.render(); + + + part.setVisible(true); + + } + + private void hide() { + part.setVisible(false); + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_SELECTION_DOCUMENTATION) String path) { + if( path != null ) + draw(path); + else + hide(); + } + + +} diff --git a/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/DocumentationSelectorPart.java b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/DocumentationSelectorPart.java new file mode 100644 index 0000000..af61da0 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/DocumentationSelectorPart.java @@ -0,0 +1,90 @@ +package flintstones.application.perspective.documentation.ui; + +import java.io.File; +import java.text.DateFormat; +import java.util.Arrays; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +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.Tree; +import org.eclipse.swt.widgets.TreeItem; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.documentation.ui.provider.FileModifiedLabelProvider; +import flintstones.application.perspective.documentation.ui.provider.ViewContentProvider; +import flintstones.application.perspective.documentation.ui.provider.ViewLabelProvider; +import flintstones.model.ui.service.UiService; + +public class DocumentationSelectorPart { + + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + TreeViewer viewer; + + private static final DateFormat dateFormat = DateFormat.getDateInstance(); + + @PostConstruct + public void init(Composite parent) { + + viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL); + viewer.setContentProvider(new ViewContentProvider()); + viewer.getTree().setHeaderVisible(true); + + TreeViewerColumn mainColumn = new TreeViewerColumn(viewer, SWT.NONE); + mainColumn.getColumn().setText("Name"); + mainColumn.getColumn().setWidth(300); + mainColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(new ViewLabelProvider(UiService.getImage("new.png")))); + + TreeViewerColumn modifiedColumn = new TreeViewerColumn(viewer, SWT.NONE); + modifiedColumn.getColumn().setText("Last Modified"); + modifiedColumn.getColumn().setWidth(100); + modifiedColumn.getColumn().setAlignment(SWT.RIGHT); + modifiedColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(new FileModifiedLabelProvider(dateFormat))); + + File folder = new File("C:\\Users\\igmunoz\\Desktop\\wiki"); + File[] files = Arrays.stream(folder.listFiles()).filter(k -> k.getName().contains(".md")).toArray(File[]::new); + + viewer.setInput(files); + + + +// parent.addControlListener(new ControlAdapter() { +// @Override +// public void controlResized(ControlEvent e) { +// Composite composite = (Composite) e.widget; +// int width = composite.getBounds().width; +// mainColumn.getColumn().setWidth(width); +// } +// }); + + Tree tree = (Tree) viewer.getControl(); + tree.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + TreeItem item = (TreeItem) e.item; + + File file = (File) item.getData(); + String path = file.getAbsolutePath(); + broker.send(FrameworkConstants.TOPIC_SELECTION_DOCUMENTATION, path); + + } + }); + + } + +} diff --git a/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/handler/DocumentationHandler.java b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/handler/DocumentationHandler.java new file mode 100644 index 0000000..3b0f7cb --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/handler/DocumentationHandler.java @@ -0,0 +1,22 @@ + +package flintstones.application.perspective.documentation.ui.handler; + +import flintstones.application.handlers.PerspectiveSwitcher; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; + +public class DocumentationHandler { + + @Inject + IEclipseContext context; + + @Execute + public void execute() { + ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective("flintstones.application.perspective.documentation"); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/FileModifiedLabelProvider.java b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/FileModifiedLabelProvider.java new file mode 100644 index 0000000..efb2b20 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/FileModifiedLabelProvider.java @@ -0,0 +1,28 @@ +package flintstones.application.perspective.documentation.ui.provider; + +import java.io.File; +import java.text.DateFormat; +import java.util.Date; + +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; + +public class FileModifiedLabelProvider extends LabelProvider implements IStyledLabelProvider { + + private DateFormat dateLabelFormat; + + public FileModifiedLabelProvider(DateFormat dateFormat) { + dateLabelFormat = dateFormat; + } + + @Override + public StyledString getStyledText(Object element) { + if (element instanceof File) { + File file = (File) element; + long lastModified = file.lastModified(); + return new StyledString(dateLabelFormat.format(new Date(lastModified))); + } + return null; + } +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/ViewContentProvider.java b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/ViewContentProvider.java new file mode 100644 index 0000000..3756a52 --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/ViewContentProvider.java @@ -0,0 +1,42 @@ +package flintstones.application.perspective.documentation.ui.provider; + +import java.io.File; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +public class ViewContentProvider implements ITreeContentProvider { + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + + @Override + public void dispose() { + } + + @Override + public Object[] getElements(Object inputElement) { + return (File[]) inputElement; + } + + @Override + public Object[] getChildren(Object parentElement) { + File file = (File) parentElement; + return file.listFiles(); + } + + @Override + public Object getParent(Object element) { + File file = (File) element; + return file.getParentFile(); + } + + @Override + public boolean hasChildren(Object element) { + File file = (File) element; + if (file.isDirectory()) { + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/ViewLabelProvider.java b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/ViewLabelProvider.java new file mode 100644 index 0000000..d59ba6e --- /dev/null +++ b/bundles/flintstones.application.perspective.documentation.ui/src/flintstones/application/perspective/documentation/ui/provider/ViewLabelProvider.java @@ -0,0 +1,70 @@ +package flintstones.application.perspective.documentation.ui.provider; + +import java.io.File; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Image; + +public class ViewLabelProvider extends LabelProvider implements IStyledLabelProvider { + + private ImageDescriptor directoryImage; + private ResourceManager resourceManager; + + public ViewLabelProvider(ImageDescriptor directoryImage) { + this.directoryImage = directoryImage; + } + + @Override + public StyledString getStyledText(Object element) { + if (element instanceof File) { + File file = (File) element; + StyledString styledString = new StyledString(getFileName(file)); + String[] files = file.list(); + if (files != null) { + styledString.append(" ( " + files.length + " ) ", StyledString.COUNTER_STYLER); + } + return styledString; + } + return null; + } + + @Override + public Image getImage(Object element) { + if (element instanceof File) { + if (((File) element).isDirectory()) { + return getResourceManager().createImage(directoryImage); + } + } + + return super.getImage(element); + } + + @Override + public void dispose() { + // garbage collection system resources + if (resourceManager != null) { + resourceManager.dispose(); + resourceManager = null; + } + } + + protected ResourceManager getResourceManager() { + if (resourceManager == null) { + resourceManager = new LocalResourceManager(JFaceResources.getResources()); + } + return resourceManager; + } + + private String getFileName(File file) { + + String name = file.getName(); + name = name.replace("_",".").replace("-"," ").replace(".md",""); + return name.isEmpty() ? file.getPath() : name; + } +} diff --git a/bundles/flintstones.application.perspective.framework.ui/.classpath b/bundles/flintstones.application.perspective.framework.ui/.classpath new file mode 100644 index 0000000..0cbf1e6 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.perspective.framework.ui/.polyglot.META-INF b/bundles/flintstones.application.perspective.framework.ui/.polyglot.META-INF new file mode 100644 index 0000000..0a9cede --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.perspective.framework.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] FrameworkUI + + Sinbad2 + + diff --git a/bundles/flintstones.application.perspective.framework.ui/.project b/bundles/flintstones.application.perspective.framework.ui/.project new file mode 100644 index 0000000..ba6e1eb --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.application.perspective.framework.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362526 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..9212373 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//OSGI-INF/l10n/bundle_zh_cn.properties=UTF-8 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.perspective.framework.ui/META-INF/MANIFEST.MF b/bundles/flintstones.application.perspective.framework.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f0e60c5 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/META-INF/MANIFEST.MF @@ -0,0 +1,40 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.application.perspective.framework.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: %Bundle-Vendor +Export-Package: flintstones.application.perspective.framework.ui.interfaces, + flintstones.application.perspective.framework.ui.providers, + flintstones.application.perspective.framework.ui.viewer +Require-Bundle: flintstones.element.common.ui, + flintstones.entity.problemelement;visibility:=reexport, + org.eclipse.e4.ui.services, + flintstones.model.problemelement.service, + org.eclipse.e4.core.services, + flintstones.helper.ui, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di, + flintstones.model.domain.service, + flintstones.entity.domain, + flintstones.model.valuation.service, + flintstones.entity.domain.ui.chart, + flintstones.model.domain.ui.service, + flintstones.entity.domain.ui.dialog, + javax.annotation, + flintstones.model.ui.service, + org.eclipse.nebula.widgets.opal.notifier, + flintstones.helper.html, + flintstones.helper.data, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.problemelement.ui, + flintstones.entity.ahpsort.profileassignment, + flintstones.entity.sorting.ui, + flintstones.model.ahppreferences.service, + flintstones.model.ahp.referencepoint.service, + flintstones.helper.extensionpoint, + flintstones.entity.domain.ui.provider, + flintstones.helper.debug +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Automatic-Module-Name: flintstones.framework.ui diff --git a/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..1b3031f --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,82 @@ +flintstones.framework.ui.part.experts.label = Experts +flintstones.framework.ui.part.experts.handledtoolitem.addexpert.label = Add expert +flintstones.framework.ui.part.experts.handledtoolitem.addexpert.tooltip = Add expert +flintstones.framework.ui.part.experts.handledtoolitem.addseveralexperts.label = Add auto-generated expert +flintstones.framework.ui.part.experts.handledtoolitem.addseveralexperts.tooltip = Add auto-generated expert +flintstones.framework.ui.part.experts.handledtoolitem.modifyexpert.label = Modify expert +flintstones.framework.ui.part.experts.handledtoolitem.modifyexpert.tooltip = Modify expert +flintstones.framework.ui.part.experts.handledtoolitem.removeexpert.label = Remove expert +flintstones.framework.ui.part.experts.handledtoolitem.removeexpert.tooltip = Remove expert +flintstones.framework.ui.part.alternatives.label = Alternatives +flintstones.framework.ui.part.alternatives.handledtoolitem.addalternative.label = Add alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.addalternative.tooltip = Add alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.addseveralalternatives.label = Add auto-generated alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.addseveralalternatives.tooltip = Add auto-generated alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.modifyalternative.label = Modify alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.modifyalternative.tooltip = Modify alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.removealternative.label = Remove alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.removealternative.tooltip = Remove alternative +flintstones.framework.ui.part.criteria.label = Criteria +flintstones.framework.ui.part.criteria.handledtoolitem.addcriterion.label = Add criterion +flintstones.framework.ui.part.criteria.handledtoolitem.addcriterion.tooltip = Add criterion +flintstones.framework.ui.part.criteria.handledtoolitem.addseveralcriteria.label = Add auto-generated criterion +flintstones.framework.ui.part.criteria.handledtoolitem.addseveralcriteria.tooltip = Add auto-generated criterion +flintstones.framework.ui.part.criteria.handledtoolitem.modifycriterion.label = Modify criterion +flintstones.framework.ui.part.criteria.handledtoolitem.modifycriterion.tooltip = Modify criterion +flintstones.framework.ui.part.criteria.handledtoolitem.removecriterion.label = Remove criterion +flintstones.framework.ui.part.criteria.handledtoolitem.removecriterion.tooltip = Remove criterion +flintstones.framework.ui.part.domains.label = Domains +flintstones.framework.ui.part.domains.handledtoolitem.adddomain.label = Add domain +flintstones.framework.ui.part.domains.handledtoolitem.adddomain.tooltip = Add domain +flintstones.framework.ui.part.domains.handledtoolitem.addfastdomain.label = Add auto-generated domain +flintstones.framework.ui.part.domains.handledtoolitem.addfastdomain.tooltip = Add auto-generated domain +flintstones.framework.ui.part.domains.handledtoolitem.modifydomain.label = Modify domain +flintstones.framework.ui.part.domains.handledtoolitem.modifydomain.tooltip = Modify domain +flintstones.framework.ui.part.domains.handledtoolitem.removedomain.label = Remove domain +flintstones.framework.ui.part.domains.handledtoolitem.removedomain.tooltip = Remove domain +flintstones.framework.ui.part.sortingclasses.label = Sorting classes +flintstones.framework.ui.part.sortingclasses.handledtoolitem.addsortingclass.label = Add class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.addsortingclass.tooltip = Add class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.modifysortingclass.label = Modify class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.modifysortingclass.tooltip = Modify class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.removesortingclass.label = Remove class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.removesortingclass.tooltip = Remove class +flintstones.framework.ui.part.domain.label = Domain +flintstones.framework.ui.part.clasification.label = Classification +flintstones.framework.ui.command.addpe.label = Add problem element +flintstones.framework.ui.command.modifype.label = Modify problem element +flintstones.framework.ui.command.removepe.label = Remove problem element +flintstones.framework.ui.command.modifyexpert.label = Modify expert +flintstones.framework.ui.command.removeexpert.label = Remove expert +flintstones.framework.ui.command.modifyalternative.label = Modify alternative +flintstones.framework.ui.command.removealternative.label = Remove alternative +flintstones.framework.ui.command.modifycriterion.label = Modify criterion +flintstones.framework.ui.command.removecriterion.label = Remove criterion +flintstones.framework.ui.command.adddomain.label = Add domain +flintstones.framework.ui.command.modifydomain.label = Modify domain +flintstones.framework.ui.command.removedomain.label = Remove domain +flintstones.framework.ui.command.modifysortingclass.label = Modify sorting class +flintstones.framework.ui.command.removesortingclass.label = Remove sorting class +flintstones.framework.ui.menu.framework.label = Framework +flintstones.framework.ui.menu.experts.label = Experts +flintstones.framework.ui.menu.experts.handledmenuitem.addexpert.label = Add +flintstones.framework.ui.menu.experts.handledmenuitem.modifyexpert.label = Modify +flintstones.framework.ui.menu.experts.handledmenuitem.removeexpert.label = Remove +flintstones.framework.ui.menu.alternatives.label = Alternatives +flintstones.framework.ui.menu.alternatives.handledmenuitem.addalternative.label = Add +flintstones.framework.ui.menu.alternatives.handledmenuitem.modifyalternative.label = Modify +flintstones.framework.ui.menu.alternatives.handledmenuitem.removealternative.label = Remove +flintstones.framework.ui.menu.criteria.label = Criteria +flintstones.framework.ui.menu.criteria.handledmenuitem.addcriterion.label = Add +flintstones.framework.ui.menu.criteria.handledmenuitem.modifycriterion.label = Modify +flintstones.framework.ui.menu.criteria.handledmenuitem.removecriterion.label = Remove +flintstones.framework.ui.menu.domains.label = Domains +flintstones.framework.ui.menu.domains.handledmenuitem.adddomain.label = Add +flintstones.framework.ui.menu.domains.handledmenuitem.modifydomain.label = Modify +flintstones.framework.ui.menu.domains.handledmenuitem.removedomain.label = Remove +flintstones.framework.ui.menu.sortingclasses.label = Sorting classes +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.addsortingclass.label = Add +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.modifysortingclass.label = Modify +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.removesortingclass.label = Remove +Bundle-Vendor = Sinbad2 +Bundle-Name = FrameworkUI \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..82c78f5 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,75 @@ + +flintstones.framework.ui.part.experts.label = Expertos +flintstones.framework.ui.part.experts.handledtoolitem.addexpert.label = Aadir experto +flintstones.framework.ui.part.experts.handledtoolitem.addexpert.tooltip = Aadir experto +flintstones.framework.ui.part.experts.handledtoolitem.addseveralexperts.label = Aadir experto autogenerado +flintstones.framework.ui.part.experts.handledtoolitem.addseveralexperts.tooltip = Aadir experto autogenerado +flintstones.framework.ui.part.experts.handledtoolitem.modifyexpert.label = Modificar experto +flintstones.framework.ui.part.experts.handledtoolitem.modifyexpert.tooltip = Modificar experto +flintstones.framework.ui.part.experts.handledtoolitem.removeexpert.label = Eliminar experto +flintstones.framework.ui.part.experts.handledtoolitem.removeexpert.tooltip = Eliminar experto +flintstones.framework.ui.part.alternatives.label = Alternativas +flintstones.framework.ui.part.alternatives.handledtoolitem.addalternative.label = Aadir alternativa +flintstones.framework.ui.part.alternatives.handledtoolitem.addalternative.tooltip = Aadir alternativa +flintstones.framework.ui.part.alternatives.handledtoolitem.addseveralalternatives.label = Aadir alternativa autogenerada +flintstones.framework.ui.part.alternatives.handledtoolitem.addseveralalternatives.tooltip = Aadir alternativa autogenerada +flintstones.framework.ui.part.alternatives.handledtoolitem.modifyalternative.label = Modificar alternativa +flintstones.framework.ui.part.alternatives.handledtoolitem.modifyalternative.tooltip = Modificar alternativa +flintstones.framework.ui.part.alternatives.handledtoolitem.removealternative.label = Eliminar alternativa +flintstones.framework.ui.part.alternatives.handledtoolitem.removealternative.tooltip = Eliminar alternativa +flintstones.framework.ui.part.criteria.label = Criterios +flintstones.framework.ui.part.criteria.handledtoolitem.addcriterion.label = Aadir criterio +flintstones.framework.ui.part.criteria.handledtoolitem.addcriterion.tooltip = Aadir criterion +flintstones.framework.ui.part.criteria.handledtoolitem.addseveralcriteria.label = Aadir criterio autogenerado +flintstones.framework.ui.part.criteria.handledtoolitem.addseveralcriteria.tooltip = Aadir criterio autogenerado +flintstones.framework.ui.part.criteria.handledtoolitem.modifycriterion.label = Modificar criterio +flintstones.framework.ui.part.criteria.handledtoolitem.modifycriterion.tooltip = Modificar criterio +flintstones.framework.ui.part.criteria.handledtoolitem.removecriterion.label = Eliminar criterio +flintstones.framework.ui.part.criteria.handledtoolitem.removecriterion.tooltip = Eliminar criterio +flintstones.framework.ui.part.domains.label = Dominios +flintstones.framework.ui.part.domains.handledtoolitem.adddomain.label = Aadir dominio +flintstones.framework.ui.part.domains.handledtoolitem.adddomain.tooltip = Aadir dominio +flintstones.framework.ui.part.domains.handledtoolitem.addfastdomain.label = Aadir dominio autogenerado +flintstones.framework.ui.part.domains.handledtoolitem.addfastdomain.tooltip = Aadir dominio autogenerado +flintstones.framework.ui.part.domains.handledtoolitem.modifydomain.label = Modificar dominio +flintstones.framework.ui.part.domains.handledtoolitem.modifydomain.tooltip = Modificar dominio +flintstones.framework.ui.part.domains.handledtoolitem.removedomain.label = Eliminar dominio +flintstones.framework.ui.part.domains.handledtoolitem.removedomain.tooltip = Eliminar dominio +flintstones.framework.ui.part.sortingclass.label = Clases +flintstones.framework.ui.part.sortingclasses.handledtoolitem.addsortingclass.label = Aadir clase +flintstones.framework.ui.part.sortingclasses.handledtoolitem.addsortingclass.tooltip = Aadir clase +flintstones.framework.ui.part.sortingclasses.handledtoolitem.modifysortingclass.label = Modificar clase +flintstones.framework.ui.part.sortingclasses.handledtoolitem.modifysortingclass.tooltip = Modificar clase +flintstones.framework.ui.part.sortingclasses.handledtoolitem.removesortingclass.label = Eliminar clase +flintstones.framework.ui.part.sortingclasses.handledtoolitem.removesortingclass.tooltip = Eliminar clase +flintstones.framework.ui.part.domain.label = Dominio +flintstones.framework.ui.part.clasification.label = Clasificacin +flintstones.framework.ui.command.addpe.label = Aadir elemento de problema +flintstones.framework.ui.command.modifype.label = Modificar elemento del problema +flintstones.framework.ui.command.removepe.label = Eliminar elemento del problema +flintstones.framework.ui.command.adddomain.label = Aadir dominio +flintstones.framework.ui.command.modifydomain.label = Modificar dominio +flintstones.framework.ui.command.removedomain.label = Eliminar dominio +flintstones.framework.ui.menu.framework.label = Framework +flintstones.framework.ui.menu.experts.label = Expertos +flintstones.framework.ui.menu.experts.handledmenuitem.addexpert.label = Aadir +flintstones.framework.ui.menu.experts.handledmenuitem.modifyexpert.label = Modificar +flintstones.framework.ui.menu.experts.handledmenuitem.removeexpert.label = Eliminar +flintstones.framework.ui.menu.alternatives.label = Alternativas +flintstones.framework.ui.menu.alternatives.handledmenuitem.addalternative.label Aadir +flintstones.framework.ui.menu.alternatives.handledmenuitem.modifyalternative.label = Modificar +flintstones.framework.ui.menu.alternatives.handledmenuitem.removealternative.label = Eliminar +flintstones.framework.ui.menu.criteria.label = Criterios +flintstones.framework.ui.menu.criteria.handledmenuitem.addcriterion.label = Aadir +flintstones.framework.ui.menu.criteria.handledmenuitem.modifycriterion.label = Modificar +flintstones.framework.ui.menu.criteria.handledmenuitem.removecriterion.label = Eliminar +flintstones.framework.ui.menu.domains.label = Dominios +flintstones.framework.ui.menu.domains.handledmenuitem.adddomain.label = Aadir +flintstones.framework.ui.menu.domains.handledmenuitem.modifydomain.label = Modificar +flintstones.framework.ui.menu.domains.handledmenuitem.removedomain.label = Eliminar +flintstones.framework.ui.menu.sortingclasses.label = Clases +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.addsortingclass.label = Aadir +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.modifysortingclass.label = Modificar +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.removesortingclass.label = Eliminar +Bundle-Vendor = Sinbad2 +Bundle-Name = FrameworkUI \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle_zh_cn.properties b/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle_zh_cn.properties new file mode 100644 index 0000000..333089b --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/OSGI-INF/l10n/bundle_zh_cn.properties @@ -0,0 +1,74 @@ +flintstones.framework.ui.part.experts.label = 发框架 +flintstones.framework.ui.part.experts.handledtoolitem.addexpert.label = Add expert +flintstones.framework.ui.part.experts.handledtoolitem.addexpert.tooltip = Add expert +flintstones.framework.ui.part.experts.handledtoolitem.modifyexpert.label = Modify expert +flintstones.framework.ui.part.experts.handledtoolitem.modifyexpert.tooltip = Modify expert +flintstones.framework.ui.part.experts.handledtoolitem.removeexpert.label = Remove expert +flintstones.framework.ui.part.experts.handledtoolitem.removeexpert.tooltip = Remove expert +flintstones.framework.ui.part.alternatives.label = Alternatives +flintstones.framework.ui.part.alternatives.handledtoolitem.addalternative.label = Add alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.addalternative.tooltip = Add alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.modifyalternative.label = Modify alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.modifyalternative.tooltip = Modify alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.removealternative.label = Remove alternative +flintstones.framework.ui.part.alternatives.handledtoolitem.removealternative.tooltip = Remove alternative +flintstones.framework.ui.part.criteria.label = Criteria +flintstones.framework.ui.part.criteria.handledtoolitem.addcriterion.label = Add criterion +flintstones.framework.ui.part.criteria.handledtoolitem.addcriterion.tooltip = Add criterion +flintstones.framework.ui.part.criteria.handledtoolitem.modifycriterion.label = Modify criterion +flintstones.framework.ui.part.criteria.handledtoolitem.modifycriterion.tooltip = Modify criterion +flintstones.framework.ui.part.criteria.handledtoolitem.removecriterion.label = Remove criterion +flintstones.framework.ui.part.criteria.handledtoolitem.removecriterion.tooltip = Remove criterion +flintstones.framework.ui.part.domains.label = Domains +flintstones.framework.ui.part.domains.handledtoolitem.adddomain.label = Add domain +flintstones.framework.ui.part.domains.handledtoolitem.adddomain.tooltip = Add domain +flintstones.framework.ui.part.domains.handledtoolitem.modifydomain.label = Modify domain +flintstones.framework.ui.part.domains.handledtoolitem.modifydomain.tooltip = Modify domain +flintstones.framework.ui.part.domains.handledtoolitem.removedomain.label = Remove domain +flintstones.framework.ui.part.domains.handledtoolitem.removedomain.tooltip = Remove domain +flintstones.framework.ui.part.sortingclasses.label = Sorting classes +flintstones.framework.ui.part.sortingclasses.handledtoolitem.addsortingclass.label = Add class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.addsortingclass.tooltip = Add class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.modifysortingclass.label = Modify class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.modifysortingclass.tooltip = Modify class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.removesortingclass.label = Remove class +flintstones.framework.ui.part.sortingclasses.handledtoolitem.removesortingclass.tooltip = Remove class +flintstones.framework.ui.part.domain.label = Domain +flintstones.framework.ui.part.clasification.label = Classification +flintstones.framework.ui.command.addpe.label = Add problem element +flintstones.framework.ui.command.modifype.label = Modify problem element +flintstones.framework.ui.command.removepe.label = Remove problem element +flintstones.framework.ui.command.modifyexpert.label = Modify expert +flintstones.framework.ui.command.removeexpert.label = Remove expert +flintstones.framework.ui.command.modifyalternative.label = Modify alternative +flintstones.framework.ui.command.removealternative.label = Remove alternative +flintstones.framework.ui.command.modifycriterion.label = Modify criterion +flintstones.framework.ui.command.removecriterion.label = Remove criterion +flintstones.framework.ui.command.adddomain.label = Add domain +flintstones.framework.ui.command.modifydomain.label = Modify domain +flintstones.framework.ui.command.removedomain.label = Remove domain +flintstones.framework.ui.command.modifysortingclass.label = Modify sorting class +flintstones.framework.ui.command.removesortingclass.label = Remove sorting class +flintstones.framework.ui.menu.framework.label = Framework +flintstones.framework.ui.menu.experts.label = Experts +flintstones.framework.ui.menu.experts.handledmenuitem.addexpert.label = Add +flintstones.framework.ui.menu.experts.handledmenuitem.modifyexpert.label = Modify +flintstones.framework.ui.menu.experts.handledmenuitem.removeexpert.label = Remove +flintstones.framework.ui.menu.alternatives.label = Alternatives +flintstones.framework.ui.menu.alternatives.handledmenuitem.addalternative.label = Add +flintstones.framework.ui.menu.alternatives.handledmenuitem.modifyalternative.label = Modify +flintstones.framework.ui.menu.alternatives.handledmenuitem.removealternative.label = Remove +flintstones.framework.ui.menu.criteria.label = Criteria +flintstones.framework.ui.menu.criteria.handledmenuitem.addcriterion.label = Add +flintstones.framework.ui.menu.criteria.handledmenuitem.modifycriterion.label = Modify +flintstones.framework.ui.menu.criteria.handledmenuitem.removecriterion.label = Remove +flintstones.framework.ui.menu.domains.label = Domains +flintstones.framework.ui.menu.domains.handledmenuitem.adddomain.label = Add +flintstones.framework.ui.menu.domains.handledmenuitem.modifydomain.label = Modify +flintstones.framework.ui.menu.domains.handledmenuitem.removedomain.label = Remove +flintstones.framework.ui.menu.sortingclasses.label = Sorting classes +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.addsortingclass.label = Add +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.modifysortingclass.label = Modify +flintstones.framework.ui.menu.sortingclasses.handledmenuitem.removesortingclass.label = Remove +Bundle-Vendor = Sinbad2 +Bundle-Name = FrameworkUI \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/build.properties b/bundles/flintstones.application.perspective.framework.ui/build.properties new file mode 100644 index 0000000..0d30c20 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/build.properties @@ -0,0 +1,8 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + fragment.e4xmi,\ + plugin.xml,\ + OSGI-INF/,\ + OSGI-INF/l10n/bundle.properties +source.. = src/ diff --git a/bundles/flintstones.application.perspective.framework.ui/fragment.e4xmi b/bundles/flintstones.application.perspective.framework.ui/fragment.e4xmi new file mode 100644 index 0000000..7881f53 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/fragment.e4xmi @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.framework.ui/plugin.xml b/bundles/flintstones.application.perspective.framework.ui/plugin.xml new file mode 100644 index 0000000..21b1e0f --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/dialogs/FastAddDomainDialog.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/dialogs/FastAddDomainDialog.java new file mode 100644 index 0000000..a014027 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/dialogs/FastAddDomainDialog.java @@ -0,0 +1,166 @@ +package flintstones.application.perspective.framework.ui.dialogs; + +import java.util.Iterator; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.AbstractTreeViewer; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +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.Shell; + +import flintstones.entity.domain.DomainInstanceMockup; +import flintstones.entity.domain.DomainMockup; +import flintstones.entity.domain.ui.provider.DomainDomainMockupContentProvider; +import flintstones.entity.domain.ui.provider.DomainMockupLabelProvider; +import flintstones.model.ui.service.UiService; + +public class FastAddDomainDialog extends Dialog { + + @Inject + IEclipseContext context; + + private static final int DIALOG_SIZE_Y = 400; + + private static final int DIALOG_SIZE_X = 450; + + DomainMockup[] domains; + String selectedDomainId = null; + + Button okButton; + + @Inject + public FastAddDomainDialog(Shell parentShell) { + super(parentShell); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + + UiService.setGridLayout(parent, 1); + UiService.setGridDataAuto(parent); + + this.addTreeView(container); + + return container; + } + + public void setDomains(DomainInstanceMockup[] domains) { + this.domains = domains; + } + + private void addTreeView(Composite container) { + + DomainMockupLabelProvider delp = ContextInjectionFactory.make(DomainMockupLabelProvider.class, this.context); + DomainDomainMockupContentProvider dccp = ContextInjectionFactory.make(DomainDomainMockupContentProvider.class, + context); + + final TreeViewer tv = new TreeViewer(container); + tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); + tv.setContentProvider(dccp); + + TreeViewerColumn mainColumn = new TreeViewerColumn(tv, SWT.NONE); + mainColumn.getColumn().setText("Domains"); + mainColumn.getColumn().setWidth(300); + mainColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(delp)); + + tv.getTree().setHeaderVisible(true); + tv.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); + + tv.setInput(domains); + tv.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + ISelection selection = event.getSelection(); + Iterator selectedElements = ((IStructuredSelection) selection).iterator(); + + if (!selectedElements.hasNext()) + return; + + Object next = selectedElements.next(); + + DomainInstanceMockup domain = (DomainInstanceMockup) next; + + selectedDomainId = domain.getFastId(); + okButton.setEnabled(selectedDomainId != null); + + } + }); + + tv.addDoubleClickListener(new IDoubleClickListener() { + + @Override + public void doubleClick(DoubleClickEvent event) { + ISelection selection = event.getSelection(); + Iterator selectedElements = ((IStructuredSelection) selection).iterator(); + + if (!selectedElements.hasNext()) + return; + + Object next = selectedElements.next(); + + DomainInstanceMockup domain = (DomainInstanceMockup) next; + + selectedDomainId = domain.getFastId(); + if (selectedDomainId != null) + pushOk(); + } + }); + + } + + private void pushOk() { + super.okPressed(); + } + + public String getSelectedDomain() { + return this.selectedDomainId; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Select"); + + } + + @Override + protected Point getInitialSize() { + return new Point(DIALOG_SIZE_X, DIALOG_SIZE_Y); + } + + @Override + protected void okPressed() { + super.okPressed(); + } + + @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); + + this.okButton = this.getButton(IDialogConstants.OK_ID); + this.okButton.setEnabled(false); + this.okButton.setToolTipText("Doble click sobre el elemento"); + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/dialogs/UpsertProblemElementDialog.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/dialogs/UpsertProblemElementDialog.java new file mode 100644 index 0000000..c937155 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/dialogs/UpsertProblemElementDialog.java @@ -0,0 +1,443 @@ +package flintstones.application.perspective.framework.ui.dialogs; + +import java.text.MessageFormat; +import java.util.HashMap; + +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.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Point; +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.Shell; +import org.eclipse.swt.widgets.Text; + +import flintstones.application.perspective.framework.ui.messages.Messages; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +/** + * The Class UpsertProblemElementDialog. + */ +public class UpsertProblemElementDialog extends Dialog { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + @Inject + IProblemElementService problemService; + + /** The Constant DIALOG_SIZE. */ + private static final Point DIALOG_SIZE = new Point(400, 220); + + /** The ok button. */ + private Button okButton; + + // Tercera solución + Label errorLabel; + HashMap attributes = new HashMap(); + + /** + * Instantiates a new upsert problem element dialog. + * + * @param current the current + * @param parent the parent + */ + public UpsertProblemElementDialog(ProblemElement current, ProblemElement parent) { + super(Display.getCurrent().getActiveShell()); + + update("oldName", current.getName()); + + update("name", current.getName()); + update("type", current.getType()); + + String type = (String) get("type"); + if (!type.equals(Alternative.Type)) { + + if (parent == null) { + update("parentId", ""); + update("hasParent", false); + } else { + update("parentId", parent.getId()); + update("_parentName", parent.getName()); + update("hasParent", true); + } + + } else + update("hasParent", false); + + if (type.equals(Criterion.Type)) + update("isCost", ((Criterion) current).isCost()); + + if (type.equals(Expert.Type)) + update("mail", ((Expert) current).getMail()); + + } + + /* + * (non-Javadoc) /* (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets. + * Composite) + */ + @Override + protected Control createDialogArea(Composite base) { + super.createDialogArea(base); + + for (Control c : base.getChildren()) + c.dispose(); + + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + drawBlock1ProblemElementName(base); + drawBlock2Options(base); + drawBlock0Errors(base); + + return base; + } + + private void drawBlock0Errors(Composite parent) { + + Composite row = new Composite(parent, SWT.NONE); + UiService.setGridLayout(row, 1); + + errorLabel = new Label(row,1); + errorLabel.setText(" "); + UiService.setGridData(errorLabel, 9, 0, true, false); + UiService.setFontColor(errorLabel, UiService.COLOR_FG_ERROR); + UiService.setFont(errorLabel, UiService.FONT_TEXT_ERROR); + + } + + /** + * Draw block 1 problem element name. + * + * @param parent the parent + */ + private void drawBlock1ProblemElementName(Composite parent) { + + String name = (String) get("name"); + + // LABEL + Composite row = new Composite(parent, SWT.NONE); + UiService.setGridLayout(row, 2); + + Label nameLabel = new Label(row, SWT.NULL); + nameLabel.setText(this.messages.name); + UiService.setGridData(nameLabel, -1, 0, true, false); + UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE); + + // ERROR: name +// this.addErrorLabel(row, "name"); //$NON-NLS-1$ + + // INPUT + Composite row2 = new Composite(parent, SWT.NONE); + UiService.setGridData(row2, 9, 0, true, false); + UiService.setGridLayout(row2, 1); + + Text nameInput = new Text(row2, SWT.BORDER); + UiService.setGridData(nameInput, 9, 0, true, true); + nameInput.setText(name); //$NON-NLS-1$ + nameInput.addModifyListener(nameInputOnChange()); + } + + /** + * Draw block 2 options. + * + * @param parent the parent + */ + private void drawBlock2Options(Composite parent) { + + String type = (String) get("type"); + String parentName = (String) get("_parentName"); + Boolean hasParent = (Boolean) get("hasParent"); + + boolean isCriterion = type.equals(Criterion.Type); + boolean isExpert = type.equals(Expert.Type); + + if (isExpert) { + Composite row = new Composite(parent, 0); + UiService.setGridLayout(row, 2); + + Label emailTitleLabel = new Label(row, SWT.NULL); + emailTitleLabel.setText("E-mail"); + UiService.setGridData(emailTitleLabel, -1, 0, true, false); + UiService.setFont(emailTitleLabel, UiService.FONT_SECTION_TITLE); + + Composite row2 = new Composite(parent, SWT.NONE); + UiService.setGridData(row2, 9, 0, true, false); + UiService.setGridLayout(row2, 1); + + Text mailInput = new Text(row2, SWT.BORDER); + if(get("mail") != null) + mailInput.setText((String) get("mail")); + UiService.setGridData(mailInput, 9, 0, true, true); + mailInput.addModifyListener(this.mailInputOnChange()); + + } + + if (hasParent || isCriterion) { + Composite row = new Composite(parent, SWT.NONE); + UiService.setGridLayout(row, 1); + + Label titleLabel = new Label(row, SWT.NULL); + titleLabel.setText(this.messages.Options); + UiService.setGridData(titleLabel, -1, 0, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + } + + if (hasParent) { + + Composite row = new Composite(parent, SWT.NONE); + UiService.setGridData(row, 9, 0, true, false); + UiService.setGridLayout(row, 1); + + Button childCB = new Button(row, SWT.CHECK); + childCB.addSelectionListener(this.addParentSelectionAdapter()); + childCB.setSelection(hasParent); + + String template = this.messages.is_child_of; + String line = MessageFormat.format(template, parentName); + childCB.setText(line); + UiService.setFont(childCB, UiService.FONT_TEXT_NORMAL); + } + + if (isCriterion) { + + Composite row = new Composite(parent, SWT.NONE); + UiService.setGridData(row, 9, 0, true, false); + UiService.setGridLayout(row, 1); + + Button costCB = new Button(row, SWT.CHECK); + costCB.addSelectionListener(this.addCostSelectionAdapter()); + costCB.setText(this.messages.is_negative_cost); + costCB.setSelection((boolean) get("isCost")); + UiService.setFont(costCB, UiService.FONT_TEXT_NORMAL); + + } + + } + + /** + * Adds the parent selection adapter. + * + * @return the selection adapter + */ + private SelectionAdapter addParentSelectionAdapter() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean selected = ((Button) e.getSource()).getSelection(); + update("hasParent", selected); + redraw(); + + } + }; + } + + /** + * Adds the cost selection adapter. + * + * @return the selection adapter + */ + private SelectionAdapter addCostSelectionAdapter() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean selected = ((Button) e.getSource()).getSelection(); + update("isCost", selected); + redraw(); + } + }; + } + + /** + * Name input on change. + * + * @return the modify listener + */ + private ModifyListener nameInputOnChange() { + return e -> { + String name = ((Text) e.getSource()).getText(); + update("name", name); + redraw(); + }; + } + + private ModifyListener mailInputOnChange() { + return e -> { + String mail = ((Text) e.getSource()).getText(); + update("mail", mail); + redraw(); + }; + } + + /** + * Redraw. + */ + private void redraw() { + + String name = (String) get("name"); + String oldName = (String) get("oldName"); + String type = (String) get("type"); + + if(!name.equals(oldName) && problemService.getByName(type, name) != null) { + error("Nombre en uso"); + okButton.setEnabled(false); + } else { + error(""); + okButton.setEnabled(true); + } + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt. + * widgets.Composite) + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + this.okButton = this.createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + this.okButton.setEnabled(false); + this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + UiService.reLayoutShell(this.getShell()); + + this.redraw(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + @Override + protected void configureShell(Shell newShell) { + String type = (String) get("type"); + String name = (String) get("name"); + + super.configureShell(newShell); + String template = this.messages.upsert_pe_title_template; + String title = MessageFormat.format(template, + name.equals("") ? this.messages.creating : this.messages.modifying, type); //$NON-NLS-1$ + newShell.setText(title); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.Dialog#getInitialSize() + */ + @Override + protected Point getInitialSize() { + return UpsertProblemElementDialog.DIALOG_SIZE; + } + + + /** + * Gets the problem element. + * + * @return the problem element + */ + public ProblemElement getNewProblemElement() { + + String type = (String) get("type"); + String oldName = (String) get("oldName"); + String name = (String) get("name"); + Boolean hasParent = (Boolean) get("hasParent"); + String parentId = (String) get("parentId"); + + ProblemElement result = ProblemElementHelper.create(name,type); + if(!oldName.equals("")) + result.setName(oldName); + + result.setName((String) get("name")); + + ProblemElement parent = problemService.getByName(type, parentId); + if(hasParent) { + parent.removeChildren(result); + parent.addChildren(result); + } else { + if(parent != null) { + ProblemElement item = problemService.getByName(type, oldName); + parent.removeChildren(item); + } + } + + if(type.equals(Expert.Type)) { + ((Expert)result).setMail((String) get("mail")); + } + + if(type.equals(Criterion.Type)) { + ((Criterion)result).setCost((Boolean) get("isCost")); + } + + + return result; + } + + public ProblemElement getModifiedProblemElement(ProblemElement pe) { + String type = (String) get("type"); + String oldName = (String) get("oldName"); + String name = (String) get("name"); + Boolean hasParent = (Boolean) get("hasParent"); + String parentId = (String) get("parentId"); + + if(!oldName.equals("")) + pe.setName(oldName); + + pe.setName(name); + + ProblemElement parent = problemService.getByName(type, parentId); + if(hasParent) { + parent.removeChildren(pe); + parent.addChildren(pe); + } else { + if(parent != null) { + ProblemElement item = problemService.getByName(type, oldName); + parent.removeChildren(item); + } + } + + if(type.equals(Expert.Type)) + ((Expert) pe).setMail((String) get("mail")); + + if(type.equals(Criterion.Type)) + ((Criterion) pe).setCost((Boolean) get("isCost")); + + return pe; + } + + private void update(String key, Object value) { + attributes.put(key, value); + } + + private Object get(String key) { + return attributes.get(key); + } + + private void error(String err) { + errorLabel.setText(err); + } +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/draganddrop/ProblemElementDragListener.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/draganddrop/ProblemElementDragListener.java new file mode 100644 index 0000000..6813f81 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/draganddrop/ProblemElementDragListener.java @@ -0,0 +1,73 @@ +package flintstones.application.perspective.framework.ui.draganddrop; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.TextTransfer; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The listener interface for receiving problemElementDrag events. + * The class that is interested in processing a problemElementDrag + * event implements this interface, and the object created + * with that class is registered with a component using the + * component's addProblemElementDragListener method. When + * the problemElementDrag event occurs, that object's appropriate + * method is invoked. + * + * @see ProblemElementDragEvent + */ +public class ProblemElementDragListener implements DragSourceListener { + + /** The viewer. */ + private final Viewer _viewer; + + /** + * Instantiates a new problem element drag listener. + * + * @param viewer the viewer + */ + public ProblemElementDragListener(Viewer viewer) { + this._viewer = viewer; + } + + /* (non-Javadoc) + * + * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd. + * DragSourceEvent) */ + @Override + public void dragStart(DragSourceEvent event) { +// System.out.println("dragStart " + event); + event.doit = !this._viewer.getSelection() + .isEmpty(); + } + + /* (non-Javadoc) + * + * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd. + * DragSourceEvent) */ + @Override + public void dragSetData(DragSourceEvent event) { +// System.out.println("dragSetData " + event); + + IStructuredSelection selection = (IStructuredSelection) this._viewer.getSelection(); + ProblemElement firstElement = (ProblemElement) selection.getFirstElement(); + + if (TextTransfer.getInstance() + .isSupportedType(event.dataType)) + event.data = firstElement.getCanonicalName(); + + } + + /* (non-Javadoc) + * + * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd. + * DragSourceEvent) */ + @Override + public void dragFinished(DragSourceEvent event) { +// System.out.println("dragFinished " + event); + + } +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/draganddrop/ProblemElementDropListener.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/draganddrop/ProblemElementDropListener.java new file mode 100644 index 0000000..c2872e1 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/draganddrop/ProblemElementDropListener.java @@ -0,0 +1,146 @@ +package flintstones.application.perspective.framework.ui.draganddrop; + +import javax.inject.Inject; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerDropAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.TransferData; + +import flintstones.application.perspective.framework.ui.handlers.MoveProblemElementHandler; +import flintstones.application.perspective.framework.ui.handlers.ReorderProblemElementHandler; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The listener interface for receiving problemElementDrop events. + * The class that is interested in processing a problemElementDrop + * event implements this interface, and the object created + * with that class is registered with a component using the + * component's addProblemElementDropListener method. When + * the problemElementDrop event occurs, that object's appropriate + * method is invoked. + * + * @see ProblemElementDropEvent + */ +public class ProblemElementDropListener extends ViewerDropAdapter { + + /** The draggedElement. */ + private ProblemElement draggedElement; + + /** The new draggedElement. */ + private ProblemElement dropTarget; + + boolean droppedInside = false; + boolean droppedBefore = false; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + Viewer viewer; + /** + * Instantiates a new problem element drop listener. + * + * @param viewer the viewer + */ + public ProblemElementDropListener(Viewer viewer) { + super(viewer); + this.viewer = viewer; + } + + + @Override + public void drop(DropTargetEvent event) { + int location = this.determineLocation(event); +// ProblemElement target = (ProblemElement) determineTarget(event); +// String translatedLocation = ""; + switch (location) { + case 1: +// translatedLocation = "Dropped before the target "; + droppedInside = false; + droppedBefore = true; + break; + case 2: +// translatedLocation = "Dropped after the target "; + droppedInside = false; + droppedBefore = false; + break; + case 3: +// translatedLocation = "Dropped on the target "; + droppedInside = true; + droppedBefore = false; + break; + case 4: +// translatedLocation = "Dropped into nothing "; + droppedInside = false; + droppedBefore = false; + break; + } +// System.out.println(translatedLocation); +// System.out.println("The drop was done on the element: " + target); + super.drop(event); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object) + */ + @Override + public boolean performDrop(Object data) { + + if( droppedInside ) { + MoveProblemElementHandler handler = new MoveProblemElementHandler(this.draggedElement, this.dropTarget); + ContextInjectionFactory.inject(handler, this.context); + + try { + handler.execute(null); + } catch (ExecutionException e) { + return false; + } + } else { + + ReorderProblemElementHandler handler = new ReorderProblemElementHandler(draggedElement, dropTarget, droppedBefore ); + ContextInjectionFactory.inject(handler, this.context); + + handler.execute(); + + } + + + + + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData) + */ + @Override + public boolean validateDrop(Object target, int operation, TransferData transferType) { + + boolean result = false; + + Object selectedObject = this.getSelectedObject(); + + if (selectedObject instanceof ProblemElement) { + draggedElement = (ProblemElement) selectedObject; + if (target != null) + this.dropTarget = (ProblemElement) target; + + result = true; + + } + + return result; + } + + + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddDomainHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddDomainHandler.java new file mode 100644 index 0000000..3a1bcba --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddDomainHandler.java @@ -0,0 +1,127 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.handlers; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.jface.window.Window; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.dialog.AddDomainDialog; +import flintstones.entity.domain.ui.dialog.DomainDialog; +import flintstones.entity.domain.ui.dialog.SelectBetweenMultipleDomainsDialog; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.domain.ui.service.IDomainUIService; + +/** + * @author Sinbad2 Domain GUI + icon + * + */ +public class AddDomainHandler { + + @Inject + IDomainUIService uiDomainService; + + @Inject + IDomainService domainService; + + @Inject + IEventBroker broker; + + @Inject + IEclipseContext context; + + /** + * @param context + * Eclipse context injected + */ + @Execute + public void execute(IEclipseContext context) { + // Select domain type + String domainType = this.firstDialog(context); + + if (domainType != null) + this.secondDialog(domainType); + + } + + private String firstDialog(IEclipseContext context) { + AddDomainDialog dialog = ContextInjectionFactory.make(AddDomainDialog.class, context); + int status = dialog.open(); + + if (status == Window.OK) { + String ret = dialog.getSelectedDomainExtension(); + return ret; + } + return null; + } + + private void secondDialog(String domainType) { + // Create empty domain + + // Open create domain Dialog + String[] dialogIds = this.uiDomainService.getExtensionIdsForDomain(domainType,"new"); + + // If more than one id was found, chose one in a new dialog + String dialogId = ""; //$NON-NLS-1$ + if (dialogIds.length > 1) + dialogId = this.launchSelectDomain(dialogIds); + else if( dialogIds.length == 1) + dialogId = dialogIds[0]; + + // If the domain has a dialog, launch it and complete its data + Domain ret = domainService.create(domainType); + + if (dialogId != "" && dialogId != null) { + ret = this.launchDomainDialog(ret, dialogId); + // Save the new Domain + if(ret != null) { + this.domainService.add(ret); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_CREATED, ret); + } + } + } + + private String launchSelectDomain(String[] ids) { + + SelectBetweenMultipleDomainsDialog dialog = ContextInjectionFactory.make(SelectBetweenMultipleDomainsDialog.class, context); + + // Cache + HashMap descriptionIdMap = new HashMap<>(); + for(String id : ids) { + String description = uiDomainService.getDescriptionNewDomainDialog(id); + descriptionIdMap.put(description, id); + } + + String[] descriptions = descriptionIdMap.keySet().stream().toArray(String[]::new); + dialog.setDescriptions(descriptions); + + // Grab info from user + int status = dialog.open(); + String selectedId = descriptionIdMap.get( dialog.getSelected() ); + if (status == Window.OK) + return selectedId; + + return null; + } + + private Domain launchDomainDialog(Domain baseDomain, String dialogId) { + + DomainDialog newD = this.uiDomainService.newDomainDialog(baseDomain, dialogId); + int status = newD.open(); + + if (status == Window.OK) + return newD.getDomain(); + + return null; + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddProblemElementHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddProblemElementHandler.java new file mode 100644 index 0000000..646232d --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddProblemElementHandler.java @@ -0,0 +1,48 @@ +package flintstones.application.perspective.framework.ui.handlers; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.jface.window.Window; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.dialogs.UpsertProblemElementDialog; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.problemelement.service.IProblemElementService; + +public class AddProblemElementHandler { + + private String problemElementType; + + @Inject + IProblemElementService problemService; + + @Inject + IEventBroker broker; + + /** + * Execute. + * + * @param context the context + * @param nameParameter the name parameter + */ + @Execute + public void execute(IEclipseContext context, @Named("add_object_parameter") String nameParameter) { + problemElementType = nameParameter; + + UpsertProblemElementDialog dialog = new UpsertProblemElementDialog(ProblemElementHelper.create("", problemElementType), null); //$NON-NLS-1$ + ContextInjectionFactory.inject(dialog, context); + int dialogResult = dialog.open(); + + if (dialogResult == Window.OK) { + ProblemElement pe = dialog.getNewProblemElement(); + problemService.add(pe); + broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, FrameworkConstants.map("pe", pe)); + } + } +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddSomeProblemElementHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddSomeProblemElementHandler.java new file mode 100644 index 0000000..f91c095 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/AddSomeProblemElementHandler.java @@ -0,0 +1,88 @@ +package flintstones.application.perspective.framework.ui.handlers; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.services.IServiceConstants; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class AddSomeProblemElementHandler -> Quick PE creation. + */ +public class AddSomeProblemElementHandler { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Execute. + * + * @param context the context + * @param nameParameter the name parameter + */ + @Execute + public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SELECTION) ProblemElement selectedPE, + @Named("add_object_parameter") String nameParameter) { + + int numberCount = 1; + String nameObject = ""; + + ProblemElement parent = selectedPE != null && selectedPE.getType().equals(nameParameter) ? selectedPE : null; + + nameObject = parent != null ? selectedPE.getName() + "_" : nameParameter + " "; + + boolean alreadyExists = this.problemService.getByName(nameParameter, nameObject + numberCount) != null; + while (alreadyExists) { + numberCount++; + alreadyExists = this.problemService.getByName(nameParameter, nameObject + numberCount) != null; + } + + ProblemElement pE = ProblemElementHelper.create(nameObject + numberCount, nameParameter); + if (pE.getType().equals(Expert.Type)) + ((Expert) pE).setMail(pE.getName().replace(" ", "") + "@fs4.test"); + + if (parent != null) + pE.changeParent(parent); + + this.problemService.add(pE); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, FrameworkConstants.map("pe", pE)); + } + + @Execute + public void execute(IEclipseContext context, + @Named("add_object_parameter") String nameParameter) { + + int numberCount = 1; + String nameObject = ""; + + + nameObject = nameParameter + " "; + + boolean alreadyExists = this.problemService.getByName(nameParameter, nameObject + numberCount) != null; + while (alreadyExists) { + numberCount++; + alreadyExists = this.problemService.getByName(nameParameter, nameObject + numberCount) != null; + } + + ProblemElement pE = ProblemElementHelper.create(nameObject + numberCount, nameParameter); + if (pE.getType().equals(Expert.Type)) + ((Expert) pE).setMail(pE.getName().replace(" ", "") + "@fs4.test"); + + this.problemService.add(pE); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, FrameworkConstants.map("pe", pE)); + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/FastAddDomainHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/FastAddDomainHandler.java new file mode 100644 index 0000000..87ee995 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/FastAddDomainHandler.java @@ -0,0 +1,111 @@ +package flintstones.application.perspective.framework.ui.handlers; + +import java.util.ArrayList; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.jface.window.Window; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.dialogs.FastAddDomainDialog; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; +import flintstones.entity.domain.DomainInstanceMockup; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.domain.ui.service.IDomainUIService; + +public class FastAddDomainHandler { + + private HashMap fastDomainCounter = new HashMap(); + + @Inject + IDomainUIService uiDomainService; + + @Inject + IDomainService domainService; + + @Inject + IEventBroker broker; + + @Inject + IEclipseContext context; + + BaseRegistry instancesReg = new BaseRegistry("flintstones.entity.domain.fastadd"); + BaseRegistry domainReg = new BaseRegistry("flintstones.entity.domain"); + + @Execute + public void execute(IEclipseContext context) { + + FastAddDomainDialog dialog = ContextInjectionFactory.make(FastAddDomainDialog.class, context); + dialog.setDomains(getMockups()); + + if(dialog.open() == Window.OK) { + String id = dialog.getSelectedDomain(); + create(id); + + } + + } + + private DomainInstanceMockup[] getMockups() { + + ExtensionRegistry[] domainsReg = domainReg.getAllRegistries(); + + ArrayList mockups = new ArrayList<>(); + for(ExtensionRegistry registry : domainsReg) { + ExtensionRegistry[] regs = instancesReg.getAllRegistriesWhere("domain_id", registry.getAttribute("uid")); + + if(regs.length > 0) { + String catName = registry.getAttribute("label"); + String domainId = registry.getAttribute("uid"); + DomainInstanceMockup category = new DomainInstanceMockup(catName); + mockups.add(category); + + for(ExtensionRegistry instanceReg : regs) { + String id = instanceReg.getAttribute("uid"); + String label = instanceReg.getAttribute("label"); + DomainInstanceMockup mock = new DomainInstanceMockup(id, domainId, label, catName); + category.addDomain(mock); + } + + } + } + + return mockups.stream().toArray(DomainInstanceMockup[]::new); + + } + + + private void create(String id) { + ExtensionRegistry ex = instancesReg.getFirstRegistryWhere("uid", id); + + // Prepare data + String domainId = ex.getAttribute("domain_id"); + String label = ex.getAttribute("label"); + + DomainInstance dInstance = (DomainInstance) instancesReg.instantiate(ex); + Domain baseDomain = domainService.create(domainId); + dInstance.setCleanDomain(baseDomain); + + if(domainService.getByName(label) != null) + label += "_" + fastDomainCounter.put(label, fastDomainCounter.get(label) + 1); + else + fastDomainCounter.put(label, 1); + + dInstance.setLabel(label); + + Domain finalDomain = dInstance.getInstance(); + domainService.add(finalDomain); + + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_CREATED, finalDomain); + } + + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ModifyDomainHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ModifyDomainHandler.java new file mode 100644 index 0000000..1cfde8b --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ModifyDomainHandler.java @@ -0,0 +1,100 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.handlers; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.window.Window; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.dialog.DomainDialog; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class ModifyDomainHandler. + */ +public class ModifyDomainHandler { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The broker. */ + @Inject + IEventBroker broker; + + @Inject + IDomainUIService uiDomainService; + + /** The Constant BUS_ID. */ + private final static String BUS_ID = FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_MODIFIED; + + /** + * Execute. + * + * @param context Eclipse context injected + * @param selectedItem the selected item + */ + @Execute + public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SELECTION) Domain selectedItem) { + // Select domain type + String domainType = selectedItem.getType(); + + if (domainType != null) + this.secondDialog(domainType, selectedItem); + + } + + /** + * Second dialog. + * + * @param domainType the domain type + * @param d the d + * @param context the context + */ + private void secondDialog(String domainType, Domain d) { + DomainDialog domainDialog = this.uiDomainService.modifyDomainDialog(d); + + int status = domainDialog.open(); + if (status == Window.OK) + this.broker.post(ModifyDomainHandler.BUS_ID, d); + } + + /** + * Can execute. + * + * @param domain the domain + * @return true if the right item is selected + */ + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) Domain domain) { + + if (domain == null) + return false; + + if (uiDomainService.getModifyDomainDialogId(domain.getType()) == null) + return false; + + return true; + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ModifyProblemElementHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ModifyProblemElementHandler.java new file mode 100644 index 0000000..0d87bdb --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ModifyProblemElementHandler.java @@ -0,0 +1,75 @@ +package flintstones.application.perspective.framework.ui.handlers; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Shell; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.dialogs.UpsertProblemElementDialog; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; + +public class ModifyProblemElementHandler { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Execute. + * + * @param shell the shell + * @param pe the problem element + */ + @Execute + public void execute(Shell shell, @Named(IServiceConstants.ACTIVE_SELECTION) ProblemElement pe) { + this.handle(pe); + } + + /** + * Handle. + * + * @param item the item + */ + public void handle(ProblemElement item) { + UpsertProblemElementDialog dialog = new UpsertProblemElementDialog(item, item.getParent()); + ContextInjectionFactory.inject(dialog, this.context); + + if (dialog.open() == Window.OK) { + + dialog.getModifiedProblemElement(item); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_MODIFIED, FrameworkConstants.map("pe", item)); + } + } + + /** + * Can execute. + * + * @param alternative the alternative + * @return true, if successful + */ + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ProblemElement pe, + @Named("modify_object_parameter") String nameParameter) { + if (pe == null || ! ((ProblemElement) pe).getType() + .equals(nameParameter)) + return false; + return true; + } +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/MoveProblemElementHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/MoveProblemElementHandler.java new file mode 100644 index 0000000..b203be4 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/MoveProblemElementHandler.java @@ -0,0 +1,77 @@ +package flintstones.application.perspective.framework.ui.handlers; + +import javax.inject.Inject; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class MoveProblemElementHandler. + */ +public class MoveProblemElementHandler extends AbstractHandler { + + /** The broker. */ + @Inject + IEventBroker broker; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The pe. */ + final private ProblemElement pe; + + /** The new pe. */ + final private ProblemElement newPe; + + /** + * Instantiates a new move problem element handler. + * + * @param pe the pe + * @param newPe the new pe + */ + public MoveProblemElementHandler(ProblemElement pe, ProblemElement newPe) { + this.pe = pe; + this.newPe = newPe; + } + + /* (non-Javadoc) + * + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands. + * ExecutionEvent) */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + // If the item was moved + if (pe.changeParent(newPe)) { + + // Remove the valuation of the PE that now is parent. Now it is not a leaf so it + // cant have valuation. + this.valuationService.removeValuationFor(this.pe.getType(), this.newPe); + + // Refresh UI + if (this.pe instanceof Criterion) + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_CRITERION_MODIFIED, FrameworkConstants.empty()); + if (this.pe instanceof Expert) + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_EXPERT_MODIFIED, FrameworkConstants.empty()); + this.broker.post(FrameworkConstants.TOPIC_VALUATION_DELETED, null); + + } + + return null; + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/PasteProblemElementsHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/PasteProblemElementsHandler.java new file mode 100644 index 0000000..c8f7887 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/PasteProblemElementsHandler.java @@ -0,0 +1,79 @@ + +package flintstones.application.perspective.framework.ui.handlers; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.nebula.widgets.opal.notifier.NotifierColorsFactory.NotifierTheme; +import org.eclipse.nebula.widgets.opal.notifier.WNotifier; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.widgets.Display; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.messages.Messages; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.problemelement.service.IProblemElementService; + + +// http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/CopyandPaste.htm +public class PasteProblemElementsHandler { + + @Inject + IProblemElementService problemService; + + @Inject + IEventBroker broker; + + @Inject + @Translation + Messages messages; + + @Execute + public void execute(IEclipseContext context, @Named("paste_parameter_id") String type) { + + Clipboard clipboard = new Clipboard(Display.getCurrent()); + String plainText = (String) clipboard.getContents(TextTransfer.getInstance()); + + String[] elements = plainText.split("\r\n"); //$NON-NLS-1$ + if(elements.length == 1) + elements = plainText.split("\t"); //$NON-NLS-1$ + + for(int i = 0; i < elements.length; i++) + elements[i] = elements[i].replaceAll("\n","").replaceAll("\r","").replaceAll("\t",""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + + if(elements.length == 1) { + new WNotifier("Error", messages.Elements_have_to_be_separated_by_line_break_or_tabulations, NotifierTheme.YELLOW_THEME) //$NON-NLS-1$ + .withCloseOnClick(true) + .send(); + return ; + } + + if(problemService.getAll(type).length != 0) { + new WNotifier("Error", messages.Remove_all_the_elements_before_pasting,NotifierTheme.YELLOW_THEME) //$NON-NLS-1$ + .withCloseOnClick(true) + .withTimeout(60) + .send(); + + return ; + } + + for(String element : elements) { + + // Create + ProblemElement pe = ProblemElementHelper.create(element, type); + problemService.add(pe); + + } + + // Notify the change to the APP/UI + broker.send(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, null); + new WNotifier(messages.Successfully_completed, messages.Problem_elements_successfully_added, NotifierTheme.BLUE_THEME).send(); //$NON-NLS-1$ + + } +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/RemoveDomainHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/RemoveDomainHandler.java new file mode 100644 index 0000000..bf124d7 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/RemoveDomainHandler.java @@ -0,0 +1,86 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.handlers; + +import java.text.MessageFormat; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.messages.Messages; +import flintstones.entity.domain.Domain; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class RemoveDomainHandler. + */ +public class RemoveDomainHandler { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The Constant BUS_ID_VALUATION. */ + private final static String BUS_ID_VALUATION = FrameworkConstants.TOPIC_VALUATION_DELETED; + + /** + * Execute. + * + * @param shell the shell + * @param selectedItem the selected item + */ + @Execute + public void execute(Shell shell, @Named(IServiceConstants.ACTIVE_SELECTION) Domain selectedItem) { + + String template = this.messages.confirmRemoveDomainTemplate; + String confirmRemoveDomainMessage = MessageFormat.format(template, selectedItem.getName()); + + boolean result = MessageDialog.openConfirm(shell, this.messages.confirmRemoveDomainTitle, confirmRemoveDomainMessage); // $NON-NLS-2$ + + if (result) { + this.domainService.removeDomain(selectedItem.getId()); + this.valuationService.removeValuationFor(selectedItem); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_DELETED, null); + this.broker.post(RemoveDomainHandler.BUS_ID_VALUATION, null); + } + + } + + /** + * Can execute. + * + * @param domain the domain + * @return true, if successful + */ + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) Object domain) { + if (domain == null || !(domain instanceof Domain)) + return false; + return true; + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/RemoveProblemElementHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/RemoveProblemElementHandler.java new file mode 100644 index 0000000..c6f9c98 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/RemoveProblemElementHandler.java @@ -0,0 +1,78 @@ +package flintstones.application.perspective.framework.ui.handlers; + +import java.text.MessageFormat; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.messages.Messages; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +public class RemoveProblemElementHandler { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** + * Execute. + * + * @param shell the shell + * @param context the context + * @param problemService the problem service + * @param broker the broker + * @param pe the problem element + */ + @Execute + public void execute(Shell shell, IEclipseContext context, IProblemElementService problemService, + IEventBroker broker, @Named(IServiceConstants.ACTIVE_SELECTION) ProblemElement pe, + @Named("remove_object_parameter") String nameParameter) { + + String template = this.messages.confirmRemoveProblemElementTemplate; + String title = this.messages.confirmRemoveProblemElementTitle; + String confirmRemoveProblemElementMessage = MessageFormat.format(template, pe.getName()); + String confirmRemoveProblemElementTitleMessage = MessageFormat.format(title, pe.getName()); + + boolean result = MessageDialog.openConfirm(shell, confirmRemoveProblemElementTitleMessage, + confirmRemoveProblemElementMessage); // $NON-NLS-2$ + + if (result) { + problemService.delete(pe); + broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_DELETED, FrameworkConstants.empty()); + this.valuationService.removeValuationFor(nameParameter, pe); + broker.post(FrameworkConstants.TOPIC_VALUATION_DELETED, null); + } + } + + /** + * Can execute. + * + * @param alternative the alternative + * @return true, if successful + */ + @CanExecute + public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ProblemElement pe, + @Named("remove_object_parameter") String nameParameter) { + if (pe == null || ! ((ProblemElement) pe).getType().equals(nameParameter)) + return false; + return true; + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ReorderProblemElementHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ReorderProblemElementHandler.java new file mode 100644 index 0000000..f3a1449 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ReorderProblemElementHandler.java @@ -0,0 +1,54 @@ + +package flintstones.application.perspective.framework.ui.handlers; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.problemelement.service.IProblemElementService; + +public class ReorderProblemElementHandler { + + @Inject + IProblemElementService problemService; + + @Inject + IEventBroker broker; + + ProblemElement draggedElement; + ProblemElement targetElement; + boolean before; + + public ReorderProblemElementHandler(ProblemElement draggedElement, ProblemElement targetElement, boolean before) { + this.draggedElement = draggedElement; + this.targetElement = targetElement; + } + + @Execute + public void execute() { + + String type = draggedElement.getType(); + if(!targetElement.getType().equals(type)) + return ; + + int targetOrder = targetElement.getOrder(); + int newOrder = before ? targetOrder -1 : targetOrder +1; + + ProblemElement[] pes = ProblemElementHelper.getAsUserOrdered(problemService.getAll(type)); + for(ProblemElement current : pes) { + if( current.getOrder() >= newOrder ) { + current.setOrder( current.getOrder() +1 ); + problemService.add(current); + } + } + draggedElement.setOrder(newOrder); + problemService.add(draggedElement); + + broker.send(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, null); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ToggleProfilesHandler.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ToggleProfilesHandler.java new file mode 100644 index 0000000..7f1e301 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/handlers/ToggleProfilesHandler.java @@ -0,0 +1,41 @@ +package flintstones.application.perspective.framework.ui.handlers; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.CanExecute; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.workbench.modeling.ESelectionService; + +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; + +public class ToggleProfilesHandler { + + @Inject + IProfileAssignmentService profileService; + + @Inject + ESelectionService selectionService; + + @Execute + public void execute(IEclipseContext context, @Named("profile_type") String type) { + + if(type.equals(SortingProfile.SortingProfileType.Central.toString())) + profileService.setType(SortingProfile.SortingProfileType.Central); + if(type.equals(SortingProfile.SortingProfileType.Limiting.toString())) + profileService.setType(SortingProfile.SortingProfileType.Limiting); + + // Refresh canExecute + selectionService.setSelection(type); + } + + @CanExecute + public boolean canExecute(@Named("profile_type") String type) { + if(profileService.getType().toString().equals(type)) + return false; + return true; + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/interfaces/IProblemElementViewerOnDoubleClick.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/interfaces/IProblemElementViewerOnDoubleClick.java new file mode 100644 index 0000000..a9b9cb9 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/interfaces/IProblemElementViewerOnDoubleClick.java @@ -0,0 +1,17 @@ +package flintstones.application.perspective.framework.ui.interfaces; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Interface IProblemElementViewerOnDoubleClick. + */ +public interface IProblemElementViewerOnDoubleClick { + + /** + * Problem element viewer on double click. + * + * @param item the item + */ + void problemElementViewerOnDoubleClick(ProblemElement item); + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/interfaces/IProblemElementViewerOnSingleClick.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/interfaces/IProblemElementViewerOnSingleClick.java new file mode 100644 index 0000000..07f4b02 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/interfaces/IProblemElementViewerOnSingleClick.java @@ -0,0 +1,17 @@ +package flintstones.application.perspective.framework.ui.interfaces; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Interface IProblemElementViewerOnSingleClick. + */ +public interface IProblemElementViewerOnSingleClick { + + /** + * Problem element viewer on single click. + * + * @param item the item + */ + void problemElementViewerOnSingleClick(ProblemElement item); + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/Messages.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/Messages.java new file mode 100644 index 0000000..387c541 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/Messages.java @@ -0,0 +1,35 @@ +// This file has been auto-generated +package flintstones.application.perspective.framework.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String confirmRemoveDomainTemplate; + public String confirmRemoveDomainTitle; + public String confirmRemoveProblemElementTemplate; + public String confirmRemoveProblemElementTitle; + public String creating; + public String error_alredy_used_name; + public String error_name_empty; + public String is_child_of; + public String is_negative_cost; + public String modifying; + public String name; + public String label_domain_description; + public String label_domain_name; + public String label_domain_valuation; + public String Options; + public String upsert_pe_title_template; + public String label_experts; + public String label_criterions; + public String label_alternatives; + public String Elements_have_to_be_separated_by_line_break_or_tabulations; + public String Problem_elements_successfully_added; + public String Remove_all_the_elements_before_pasting; + public String Successfully_completed; + public String profiles_assignment; + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/messages.properties b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/messages.properties new file mode 100644 index 0000000..cb58ab0 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/messages.properties @@ -0,0 +1,24 @@ +confirmRemoveDomainTemplate=Do you really want to remove the domain {0}? +confirmRemoveDomainTitle=Confirm remove of domain +confirmRemoveProblemElementTemplate= Do you really want to remove {0}? +confirmRemoveProblemElementTitle= Confirm remove {0} +creating=Creating +error_alredy_used_name=This name is already been used +error_name_empty=The field name can not be empty +is_child_of=Is child of {0} +is_negative_cost=Is a cost criterion +modifying=Modifying +name=Name +label_domain_description=Description +label_domain_name=Domains +label_experts=Experts +label_criterions=Criteria +label_alternatives=Alternatives +label_domain_valuation=Valuation +Options=Options +Elements_have_to_be_separated_by_line_break_or_tabulations=Elements have to be separated by line breaks or tabulations +Problem_elements_successfully_added=Problem elements successfully added +Remove_all_the_elements_before_pasting=Remove all the elements before pasting +Successfully_completed=Successfully completed +upsert_pe_title_template={0} a {1} +profiles_assignment=Profiles asignment \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/messages_es.properties b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/messages_es.properties new file mode 100644 index 0000000..a9b3321 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/messages/messages_es.properties @@ -0,0 +1,24 @@ +confirmRemoveDomainTemplate=Quieres eliminar el dominio {0}? +confirmRemoveDomainTitle=Confirma el borrado del dominio +confirmRemoveProblemElementTemplate= Quieres eliminar {0}? +confirmRemoveProblemElementTitle= Confirma el borrado de {0} +creating=Creando +error_alredy_used_name=Ese nombre ya esta siendo usado +error_name_empty=El campo nombre no puede estar vacio +is_child_of=Es hijo de {0} +is_negative_cost=Es un criterio de coste +modifying=Modificar +name=Nombre +label_domain_description=Descripciones +label_domain_name=Dominios +label_domain_valuation=Evaluaciones +Options=Opciones +upsert_pe_title_template={0} a {1} +label_experts=Expertos +label_criterions=Criterios +label_alternatives=Alternativas +Elements_have_to_be_separated_by_line_break_or_tabulations=Debes pegar ms de un elemento separado por saltos de lnea \n o por tabulaciones +Problem_elements_successfully_added=Se han aadido elementos de problema correctamente +Remove_all_the_elements_before_pasting=No es posible aadir pegando sin borrar todos +Successfully_completed=Completado con xito +profiles_assignment=Asignar perfiles \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/AlternativesPart.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/AlternativesPart.java new file mode 100644 index 0000000..5ad3caf --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/AlternativesPart.java @@ -0,0 +1,52 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.parts; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewerV2; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class AlternativesPart. + */ +public class AlternativesPart { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + ProblemElementViewerV2 viewer; + + @PostConstruct + public void init(Composite parent) { + ProblemElement[] pes = problemService.getMainElements(Alternative.Type); + + viewer = ContextInjectionFactory.make(ProblemElementViewerV2.class, context); + viewer.buildProblemElementViewerV2(parent, pes, Alternative.Type); + viewer.isOpenedOnClick(true) + .isModifiedOnDoubleClick(true); + + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Object event) { + viewer.refresh(problemService.getMainElements(Alternative.Type)); + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/CriteriaPart.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/CriteriaPart.java new file mode 100644 index 0000000..d7e7df7 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/CriteriaPart.java @@ -0,0 +1,52 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.parts; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewerV2; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class CriteriaPart. + */ +public class CriteriaPart { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + ProblemElementViewerV2 viewer; + + @PostConstruct + public void init(Composite parent) { + ProblemElement[] pes = problemService.getMainElements(Criterion.Type); + + viewer = ContextInjectionFactory.make(ProblemElementViewerV2.class, context); + viewer.buildProblemElementViewerV2(parent, pes, Criterion.Type); + viewer.isOpenedOnClick(true) + .isModifiedOnDoubleClick(true); + + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Object event) { + viewer.refresh(problemService.getMainElements(Criterion.Type)); + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/DomainChartPart.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/DomainChartPart.java new file mode 100644 index 0000000..fccad65 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/DomainChartPart.java @@ -0,0 +1,127 @@ + +/* + * + */ +package flintstones.application.perspective.framework.ui.parts; + +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.chart.DomainChart; +import flintstones.model.domain.ui.service.IDomainUIService; + +/** + * The Class DomainChartPart. + */ +public class DomainChartPart { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The domain ui service. */ + @Inject + IDomainUIService uiDomainService; + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + /** The container. */ + private Composite container; + + /** The chart. */ + private DomainChart chart = null; + + /** The ranking. */ + private final Object ranking = null; + + /** The Constant SUB_ID. Subscribe to any change on domain */ + private final static String SUB_ID = FrameworkConstants.TOPIC_SELECTION_FRAMEWORK_DOMAIN; + + /** The container part. */ + @Inject + MPart part; + + /** + * Inits the. + * + * @param parent the parent + */ + @PostConstruct + public void init(Composite parent) { + this.container = parent; + this.part.getParent().setVisible(false); + } + + /** + * Refresh the domain chart. + * + * @param domain the domain + */ + public void refresh(Domain domain) { + + this.part.getParent().setVisible(false); + +// if (this.chart != null) + for (Control control : this.container.getChildren()) + if (!control.isDisposed()) + control.dispose(); + + if (domain != null) { + Point size = this.container.getSize(); + + chart = this.uiDomainService.createChart(domain.getType()); + if (chart != null) + showChart(domain, size); + + } + } + + private void showChart(Domain domain, Point size) { + this.part.getParent().setVisible(true); + this.chart.initialize(domain, this.container, size.x, size.y, SWT.NONE); + if (this.ranking != null) + this.chart.displayRanking(this.ranking); + this.container.layout(); + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribe(@UIEventTopic(DomainChartPart.SUB_ID) Map event) { + if (event != null) { + + Domain d = (Domain) event.get(this.domainMessages.Domain_entity); + this.refresh(d); + + } + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_ALLTOPICS) Domain d) { + this.part.getParent().setVisible(false); + chart = null; + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/DomainsPart.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/DomainsPart.java new file mode 100644 index 0000000..083772e --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/DomainsPart.java @@ -0,0 +1,57 @@ + +/* + * + */ +package flintstones.application.perspective.framework.ui.parts; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.element.common.ui.views.DomainViewer; +import flintstones.entity.domain.Domain; + +/** + * The Class DomainsPart. + */ +public class DomainsPart { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The domain viewer. */ + DomainViewer viewer; + + /** The Constant SUB_ID. Subscribe to any change on domains */ + private static final String SUB_ID = FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_ALLTOPICS; + + /** + * Inits the part. + * + * @param parent the parent + */ + @PostConstruct + public void init(Composite parent) { + this.viewer = ContextInjectionFactory.make(DomainViewer.class, this.context); + this.viewer.createControls(parent, true, true); + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribe(@UIEventTopic(DomainsPart.SUB_ID) Domain d) { + this.viewer.updateViewer(); + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ExpertsPart.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ExpertsPart.java new file mode 100644 index 0000000..095004f --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ExpertsPart.java @@ -0,0 +1,55 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.parts; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewerV2; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.debug.DH; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class ExpertsPart. + */ +public class ExpertsPart { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + ProblemElementViewerV2 viewer; + + @PostConstruct + public void init(Composite parent) { + ProblemElement[] pes = problemService.getMainElements(Expert.Type); + + viewer = ContextInjectionFactory.make(ProblemElementViewerV2.class, context); + viewer.buildProblemElementViewerV2(parent, pes, Expert.Type); + viewer.isOpenedOnClick(true) + .isModifiedOnDoubleClick(true); + + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Object event) { + DH.out(problemService.getMainElements(Expert.Type)); + + viewer.refresh(problemService.getMainElements(Expert.Type)); + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ProfilesClassesPart.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ProfilesClassesPart.java new file mode 100644 index 0000000..44c5e25 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ProfilesClassesPart.java @@ -0,0 +1,103 @@ +package flintstones.application.perspective.framework.ui.parts; + +import java.util.Arrays; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sorting.ui.SortingDiagram; +import flintstones.helper.data.Pair; +import flintstones.helper.html.svg.SvgBrowser; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; + +public class ProfilesClassesPart { + + + @Inject + IProblemElementService problemService; + + @Inject + IProfileAssignmentService profileService; + + Composite parent; + + Expert e; + Criterion c; + + @PostConstruct + public void init(Composite parent) { + this.parent = parent; + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_SORTINGPROFILE_ALLTOPICS) Pair pair) { + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + ProblemElement[] experts = problemService.getAll(Expert.Type); + ProblemElement[] crits = problemService.getAll(Criterion.Type); + + if(experts.length > 0 && crits.length > 0) { + e = pair != null ? (Expert) pair.getLeft() : (Expert) experts[0]; + c = pair != null ? (Criterion) pair.getRight() : (Criterion) crits[0]; + + ProfileAssignment pas = profileService.get(e, c); + + if(pas == null) + return ; + + SvgBrowser br = new SvgBrowser(parent); + + SortingDiagram diagram = new SortingDiagram(); + diagram.setProfiles(pas.getAllProfiles()); + + br.setCanvas(diagram); + br.render(); + } + parent.layout(); + + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribeCombo(@UIEventTopic("SORTING_COMBO_SELECTION") Pair pair) { + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + ProblemElement[] experts = problemService.getAll(Expert.Type); + ProblemElement[] crits = problemService.getAll(Criterion.Type); + + if(experts.length > 0 && crits.length > 0) { + e = (Expert) pair.getLeft(); + c = (Criterion) pair.getRight(); + ProfileAssignment pas = profileService.get(e, c); + + if(pas == null) + return ; + + SvgBrowser br = new SvgBrowser(parent); + + SortingDiagram diagram = new SortingDiagram(); + diagram.setProfiles(pas.getAllProfiles()); + + br.setCanvas(diagram); + br.render(); + } + parent.layout(); + + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ProfilesPart.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ProfilesPart.java new file mode 100644 index 0000000..52e981a --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/ProfilesPart.java @@ -0,0 +1,261 @@ +package flintstones.application.perspective.framework.ui.parts; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.messages.Messages; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.problemelement.ui.widget.ProblemElementPairSelector; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementPairChangedListener; +import flintstones.helper.DoubleHelper; +import flintstones.helper.data.Pair; +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.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class ProfilesPart implements WItemBeforeOperation, WItemChanged { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + @Inject + IProfileAssignmentService profileService; + + @Inject + IEventBroker broker; + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + WCollector collector; + ProblemElementPairSelector selectors; + Label executionError; + Composite parent; + + + @PostConstruct + public void init(Composite parent) { + this.parent = parent; + new Label(parent,0).setText("");; + } + + private void draw(Composite parent, ProblemElement[] experts, ProblemElement[] criterions ) { + + Composite base = new Composite(parent, 0); + UiService.setGridLayout(base, 1, true); + UiService.setGridData(base, 9, 9, true, true); + + Composite row1 = new Composite(base, 0); + UiService.setGridLayout(row1, 1, true); + UiService.setGridData(row1, 9, 0, true, false); + + Label titleRightLabel = new Label(row1, 0); + titleRightLabel.setText(messages.profiles_assignment); + UiService.setGridData(titleRightLabel, 9, 0, true, false); + UiService.setFont(titleRightLabel, UiService.FONT_SECTION_TITLE); + + Composite row2 = new Composite(base, 0); + UiService.setGridLayout(row2, 5, false); + UiService.setGridData(row2, 9, 0, true, false); + + selectors = new ProblemElementPairSelector(row2, experts, criterions); + selectors.setListener(new IProblemElementPairChangedListener() { + public void otherProblemElementChanged(ProblemElement pe) { + Pair pair = new Pair<>((Expert)selectors.getSelectedMain(), (Criterion)selectors.getSelectedOther()); + broker.post("SORTING_COMBO_SELECTION",pair); + refresh(); + + } + public void mainProblemElementChanged(ProblemElement pe) { + Pair pair = new Pair<>((Expert)selectors.getSelectedMain(), (Criterion)selectors.getSelectedOther()); + broker.post("SORTING_COMBO_SELECTION",pair); + refresh(); + } + }); + + executionError = new Label(row2, 0); + executionError.setText(" "); + UiService.setFont(executionError, UiService.FONT_TEXT_ERROR); + UiService.setGridData(executionError, 9, 0, true, false); + + collector = new WCollector(base); + collector.setBeforeOperationListener(this); + collector.setChangeListener(this); + + } + + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + + // Check if a number is added + if (operationType.equals(WEvent.ADD)) { + + String[] data = collector.getData(); + + // El valor es doble? + if (!DoubleHelper.IsDouble(before)) { + executionError.setText("Debe ser un número"); + return false; + } + +// Se respeta el número de perfiles del dominio? +// int max = domain.getNumberOfProfiles(); +// if (data.length == max) { +// executionError.setText("Máximo " + max + " valores"); +// return false; +// } + + // Los valores van en orden? + if (data.length > 0) { + + + double[] arr = DoubleHelper.Convert(data); + arr = DoubleHelper.Add(arr, DoubleHelper.ParseDouble(before)); + + if(!DoubleHelper.IsSorted(arr)) { + executionError.setText("Los limites deben introducirse ordenados"); + return false; + } + + } + + return true; + + } + + refresh(); + + return true; + } + + + + private void refresh() { + collector.clear(); + + ProblemElement e = getCurrentExpert(); + ProblemElement c = getCurrentCriterion(); + + ProfileAssignment assignment = profileService.get((Expert)e, (Criterion)c); + + if (assignment != null) { + Double[] valuesD = assignment.getValues(); + ArrayList values = new ArrayList<>(); + for (Double val : valuesD) + values.add(val + ""); + + collector.setValues(values); + } + + for (ProblemElement expert : problemService.getAll(Expert.Type)) { + for (ProblemElement criterion : problemService.getAll(Criterion.Type)) { + updateOtherStatus(expert, criterion, false); + } + } + selectors.refresh(); + + } + + + @Override + public void onWidgetChange() { + ProblemElement e = getCurrentExpert(); + ProblemElement c = getCurrentCriterion(); + + ProfileAssignment pa = profileService.create((Expert)e, (Criterion)c); + + String[] limitsS = collector.getData(); + Double[] limits = new Double[limitsS.length]; + + for (int i = 0; i < limitsS.length; i++) + limits[i] = Double.parseDouble(limitsS[i]); + + for (Double limit : limits) { + SortingProfile profile = new SortingProfile((Expert)getCurrentExpert(), (Criterion)getCurrentCriterion(), limit); + ContextInjectionFactory.inject(profile, context); + pa.addProfile(profile); + } + + profileService.addOrUpdate(pa); + + // Mini refresh + executionError.setText(""); + + updateOtherStatus(e, c, true); + Pair pair = new Pair<>((Expert)selectors.getSelectedMain(), (Criterion)selectors.getSelectedOther()); + broker.post(FrameworkConstants.TOPIC_FRAMEWORK_SORTINGPROFILE_CREATED,pair); + + } + + private void updateOtherStatus(ProblemElement expert, ProblemElement criterion, boolean refresh) { + ProfileAssignment pa = profileService.get((Expert)expert, (Criterion)criterion); + boolean status = pa != null; + + selectors.setStatus(expert, criterion, status, refresh); + } + + private ProblemElement getCurrentExpert() { + return selectors.getSelectedMain(); + } + + private ProblemElement getCurrentCriterion() { + return selectors.getSelectedOther(); + } + + private void onCriterionOrExpertCreated() { + UiService.setGridLayout(parent, 1, true); + UiService.setGridData(parent, 9, 9, true, true); + UiService.setBackgroundColor(parent, 255, 255, 255); + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + ProblemElement[] experts = problemService.getAll(Expert.Type); + ProblemElement[] criterions = problemService.getAll(Criterion.Type); + + if(experts.length > 0 && criterions.length > 0 ) { + + draw(parent, experts, criterions); + + refresh(); + } + + parent.layout(); + } + + @Inject + @Optional + private void subscribeExpert(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Map event) { + onCriterionOrExpertCreated(); + } +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/SortClassPart.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/SortClassPart.java new file mode 100644 index 0000000..783118f --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/parts/SortClassPart.java @@ -0,0 +1,45 @@ +package flintstones.application.perspective.framework.ui.parts; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewerV2; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; + +public class SortClassPart { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + ProblemElementViewerV2 viewer; + + @PostConstruct + public void init(Composite parent) { + ProblemElement[] pes = problemService.getMainElements(SortingClass.Type); + + viewer = ContextInjectionFactory.make(ProblemElementViewerV2.class, context); + viewer.buildProblemElementViewerV2(parent, pes, SortingClass.Type); + viewer.isOpenedOnClick(true) + .isModifiedOnDoubleClick(true); + + } + + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Object event) { + viewer.refresh(problemService.getMainElements(SortingClass.Type)); + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/CostLabelCriterionProvider.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/CostLabelCriterionProvider.java new file mode 100644 index 0000000..b112054 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/CostLabelCriterionProvider.java @@ -0,0 +1,66 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.providers; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.problemelement.entities.Criterion; + +/** + * The Class CostLabelCriterionProvider. + */ +public class CostLabelCriterionProvider extends LabelProvider implements IStyledLabelProvider { + + /** The profit image. */ + private final ImageDescriptor profitImage; + + /** The cost image. */ + private final ImageDescriptor costImage; + + /** + * Instantiates a new cost label criterion provider. + * + * @param costImage the cost image + * @param profitImage the profit image + */ + public CostLabelCriterionProvider(ImageDescriptor costImage, ImageDescriptor profitImage) { + this.costImage = costImage; + this.profitImage = profitImage; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + + if (element instanceof Criterion) { + if (((Criterion) element).isCost()) + return this.costImage.createImage(); + return this.profitImage.createImage(); + } + + return super.getImage(element); + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose() */ + @Override + public void dispose() { + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider. + * IStyledLabelProvider#getStyledText(java.lang.Object) */ + @Override + public StyledString getStyledText(Object element) { + return new StyledString(""); //$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/ProblemElementNameLabelProvider.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/ProblemElementNameLabelProvider.java new file mode 100644 index 0000000..774c801 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/ProblemElementNameLabelProvider.java @@ -0,0 +1,91 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.providers; + +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.ui.service.UiService; +import flintstones.model.ui.service.style.ForegroundStyler; + +/** + * The Class ProblemElementNameLabelProvider. + */ +public class ProblemElementNameLabelProvider extends LabelProvider implements IStyledLabelProvider { + + /** + * Instantiates a new problem element name label provider. + * + * @param individualImage the individual image + * @param groupImage the group image + */ + public ProblemElementNameLabelProvider() { + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider. + * IStyledLabelProvider#getStyledText(java.lang.Object) */ + @Override + public StyledString getStyledText(Object element) { + if (element instanceof ProblemElement) { + ProblemElement pe = (ProblemElement) element; + + StyledString styledString = new StyledString(pe.getName()); + if( pe.getType().equals(Expert.Type)) { + Expert e = (Expert)pe; + if(e.getMail() != null && !e.getMail().equals("")) + styledString = paint(pe.getName(), "[" + e.getMail() + "]"); + } + return styledString; + } + return null; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + if (element instanceof ProblemElement) { + + ProblemElement pe = (ProblemElement) element; + + boolean isCost = false; + if(pe.getType().equals(Criterion.Type)) { + isCost = ((Criterion)pe).isCost(); + } + + return UiService.getIcon(ProblemElementHelper.getImage(pe.getType(), pe.hasChildren(), isCost)).createImage(); + } + + return super.getImage(element); + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose() */ + @Override + public void dispose() { + } + + private StyledString paint(String leftText, String rightText) { + + Color foregroundColorLeft = UiService.COLOR_FG_NORMAL; + Color foregroundColorRight = UiService.COLOR_FG_SECONDARY; + + StyledString leftT = new StyledString(leftText, new ForegroundStyler(foregroundColorLeft)); + StyledString rightT = new StyledString(rightText, new ForegroundStyler(foregroundColorRight)); + return leftT.append(" ") + .append(rightT); + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/ProblemElementTreeContentProvider.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/ProblemElementTreeContentProvider.java new file mode 100644 index 0000000..97f737e --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/providers/ProblemElementTreeContentProvider.java @@ -0,0 +1,39 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.providers; + +import org.eclipse.jface.viewers.ITreeContentProvider; + +import flintstones.entity.problemelement.entities.ProblemElement; + +public class ProblemElementTreeContentProvider implements ITreeContentProvider { + + @Override + public boolean hasChildren(Object element) { + ProblemElement item = (ProblemElement) element; + return item.hasChildren(); + } + + @Override + public Object[] getElements(Object inputElement) { + return (Object[]) inputElement; + } + + @Override + public Object[] getChildren(Object parentElement) { + ProblemElement item = (ProblemElement) parentElement; + return item.getChildren(); + } + + @Override + public Object getParent(Object element) { + ProblemElement item = (ProblemElement) element; + + return item.getParent(); + } + + @Override + public void dispose() { + } +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementContentProviderV2.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementContentProviderV2.java new file mode 100644 index 0000000..0b56417 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementContentProviderV2.java @@ -0,0 +1,58 @@ +package flintstones.application.perspective.framework.ui.viewer; + +import org.eclipse.jface.viewers.ITreeContentProvider; + +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; + +public class ProblemElementContentProviderV2 implements ITreeContentProvider { + + /* Create a fake root elemtn */ + ProblemElement fake; + ProblemElement[] items; + + public ProblemElementContentProviderV2(String type, ProblemElement[] items) { + this.items = items; + fake = new FakeProblemElement(type).as(type); + } + + @Override + public Object[] getElements(Object inputElement) { + + items = (ProblemElement[]) inputElement; + + return new Object[] {fake}; + } + + @Override + public Object[] getChildren(Object parentElement) { + + if(parentElement.equals(fake)) + return items; + + ProblemElement item = (ProblemElement)parentElement; + return item.getChildren(); + } + + @Override + public Object getParent(Object element) { + + ProblemElement item = (ProblemElement)element; + if(item.getParent() == null) + return fake; + + return item.getParent(); + } + + @Override + public boolean hasChildren(Object element) { + + if(element.equals(fake)) + return true; + + ProblemElement item = (ProblemElement)element; + return item.hasChildren(); + + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementDragProviderV2.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementDragProviderV2.java new file mode 100644 index 0000000..822f46b --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementDragProviderV2.java @@ -0,0 +1,48 @@ +package flintstones.application.perspective.framework.ui.viewer; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; + +public class ProblemElementDragProviderV2 implements DragSourceListener { + +// private final Viewer viewer; + + /** + * Instantiates a new problem element drag listener. + * + * @param viewer the viewer + */ + public ProblemElementDragProviderV2(Viewer viewer) { +// this.viewer = viewer; + } + + @Override + public void dragStart(DragSourceEvent event) { +// System.out.println("A -> " + event.getSource()); +// System.out.println("A -> " + event.getSource()); + // TODO Auto-generated method stub + + } + + @Override + public void dragSetData(DragSourceEvent event) { +// System.out.println("B -> " + event.getSource()); + +// IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); +// ProblemElement firstElement = (ProblemElement) selection.getFirstElement(); + +// if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) +// event.data = firstElement; + + } + + @Override + public void dragFinished(DragSourceEvent event) { +// System.out.println("C -> " + event.getSource()); + + // TODO Auto-generated method stub + + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementDropProviderV2.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementDropProviderV2.java new file mode 100644 index 0000000..75c48dd --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementDropProviderV2.java @@ -0,0 +1,107 @@ +package flintstones.application.perspective.framework.ui.viewer; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerDropAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.TransferData; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; + +public class ProblemElementDropProviderV2 extends ViewerDropAdapter { + + @Optional + @Inject + IEventBroker broker; + + private final Viewer viewer; + + public ProblemElementDropProviderV2(Viewer viewer) { + super(viewer); + this.viewer = viewer; + } + + @Override + public void drop(DropTargetEvent event) { + int location = this.determineLocation(event); + // event.data; + ProblemElement target = (ProblemElement) determineTarget(event); + + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); + ProblemElement source = (ProblemElement) selection.getFirstElement(); + + if (target.equals(source)) + return; + + if (source != null && source.getParent() != null && source.getParent().equals(target)) + return; + + if (target != null && target.getParent() != null && target.getParent().equals(source)) + return; + + String translatedLocation = ""; + switch (location) { + case 1: + translatedLocation = "Dropped before the target "; + // Special case + if (target.getParent() == null) + target.addChildren(source); + else + target.getParent().addChildrenBefore(target, source); + break; + case 2: + translatedLocation = "Dropped after the target "; + + // Special case + if (target.getParent() == null) + target.addChildren(source); + else + target.getParent().addChildrenAfter(target, source); + break; + case 3: + translatedLocation = "Dropped on the target "; + if (target instanceof FakeProblemElement) { + if (source.getParent() != null) { + source.getParent().removeChildren(source); + } + } else + target.addChildren(source); + + break; + case 4: + translatedLocation = "Dropped into nothing "; + break; + } + + System.out.println(translatedLocation); + System.out.println("The drop was done on the element: " + target); + + // viewer.setInput(viewer.getInput()); + broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_MODIFIED, target); +// super.drop(event); + + } + + // This method performs the actual drop + // We simply add the String we receive to the model and trigger a refresh of the + // viewer by calling its setInput method. + @Override + public boolean performDrop(Object data) { +// ContentProviderTree.INSTANCE.getModel().add( data.toString()); +// viewer.setInput(ContentProviderTree.INSTANCE.getModel()); + return false; + } + + @Override + public boolean validateDrop(Object target, int operation, TransferData transferType) { + return true; + + } + +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementLabelProviderV2.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementLabelProviderV2.java new file mode 100644 index 0000000..2721913 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementLabelProviderV2.java @@ -0,0 +1,49 @@ +package flintstones.application.perspective.framework.ui.viewer; + +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.ui.service.UiService; + +public class ProblemElementLabelProviderV2 extends LabelProvider implements IStyledLabelProvider { + + @Override + public StyledString getStyledText(Object element) { + + ProblemElement item = (ProblemElement) element; + + StyledString styledString = new StyledString(item.getName()); + + if(item instanceof FakeProblemElement) + return styledString; + + if( item.getType().equals(Expert.Type) ) { + Expert e = (Expert)item; + if(e.getMail() != null && !e.getMail().equals("")) + styledString = UiService.paintTextWithBrackets(item.getName(), e.getMail(),UiService.COLOR_FG_SECONDARY); + + } + + return styledString; + } + + + @Override + public Image getImage(Object element) { + + ProblemElement item = (ProblemElement) element; + if(item instanceof FakeProblemElement) + item = new FakeProblemElement(""); + + String image = ProblemElementHelper.getImage(item); + if(image != null) + return UiService.getIcon(image).createImage(); + return null; + } +} diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementViewer.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementViewer.java new file mode 100644 index 0000000..0f8b893 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementViewer.java @@ -0,0 +1,396 @@ +/* + * + */ +package flintstones.application.perspective.framework.ui.viewer; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Locale; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.workbench.modeling.EPartService; +import org.eclipse.e4.ui.workbench.modeling.ESelectionService; +import org.eclipse.jface.viewers.AbstractTreeViewer; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ICheckStateProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.perspective.framework.ui.draganddrop.ProblemElementDragListener; +import flintstones.application.perspective.framework.ui.draganddrop.ProblemElementDropListener; +import flintstones.application.perspective.framework.ui.interfaces.IProblemElementViewerOnDoubleClick; +import flintstones.application.perspective.framework.ui.interfaces.IProblemElementViewerOnSingleClick; +import flintstones.application.perspective.framework.ui.providers.ProblemElementNameLabelProvider; +import flintstones.application.perspective.framework.ui.providers.ProblemElementTreeContentProvider; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class ProblemElementViewer. + */ +public class ProblemElementViewer { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The selection service. */ + @Inject + ESelectionService selectionService; + + /** The resource service. */ + + /** The part service. */ + @Inject + EPartService partService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The problem messages. */ + @Inject + @Translation + private flintstones.entity.problemelement.messages.Messages problemMessages; + + /** The viewer. */ + private TreeViewer viewer; + + /** The pe type. */ + private String peType; + + /** The name column. */ + // Translatables + TreeViewerColumn nameColumn; + + Composite parent; + + /** The header problem element. */ + // PE as header + private FakeProblemElement headerProblemElement; + + /** The open on click. */ + private boolean openOnClick = false; + + /** The checkable. */ + private boolean checkable = false; + + /** The check state provider. */ + private ICheckStateProvider checkStateProvider; + + /** The check statelisteners. */ + private ArrayList checkStatelisteners = new ArrayList<>(); + + /** The single click listeners. */ + private ArrayList singleClickListeners = new ArrayList<>(); + + /** The double click listeners. */ + private ArrayList doubleClickListeners = new ArrayList<>(); + + /** + * Instantiates a new problem element viewer. + */ + public ProblemElementViewer() { + } + + /** + * Creates the controls. + * + * @param type the type + * @param parent the parent + */ + public void createControls(String type, Composite parent) { + this.parent = parent; + + this.createTableViewer(parent); + this.createMainColumn(type); + this.peType = type; + + this.updateViewer(type); + + } + + /** + * Open on click. + * + * @param status the status + */ + public void openOnClick(boolean status) { + openOnClick = status; + } + + /** + * Use global parent. + * + * @param parentPe the parent pe + */ + public void useGlobalParent(FakeProblemElement parentPe) { + this.headerProblemElement = parentPe; + } + + /** + * Adds the listener. + * + * @param listener the listener + */ + public void addListener(IProblemElementViewerOnSingleClick listener) { + singleClickListeners.add(listener); + } + + /** + * Adds the listener. + * + * @param listener the listener + */ + public void addListener(IProblemElementViewerOnDoubleClick listener) { + doubleClickListeners.add(listener); + } + + /** + * Adds the check state provider. + * + * @param provider the provider + * @param listeners the listeners + */ + public void addCheckStateProvider(ICheckStateProvider provider, ArrayList listeners) { + checkable = true; + checkStateProvider = provider; + checkStatelisteners = listeners; + } + + /** + * Adds the listeners. + */ + public void loadListeners() { + + this.viewer.addSelectionChangedListener(e -> { + IStructuredSelection selection = (IStructuredSelection) ProblemElementViewer.this.viewer.getSelection(); + ProblemElementViewer.this.selectionService.setSelection(selection.getFirstElement()); + }); + + this.viewer.addDoubleClickListener(event -> { + IStructuredSelection selection = (IStructuredSelection) ProblemElementViewer.this.viewer.getSelection(); + ProblemElement item = (ProblemElement) selection.getFirstElement(); + + for (IProblemElementViewerOnDoubleClick listener : doubleClickListeners) { + listener.problemElementViewerOnDoubleClick(item); + } + + }); + + this.viewer.getTree().addListener(SWT.Selection, event -> { + + IStructuredSelection selection = (IStructuredSelection) ProblemElementViewer.this.viewer.getSelection(); + ProblemElement item = (ProblemElement) selection.getFirstElement(); + + // EVENTO CHECK + /* if (event.detail == SWT.CHECK) { System.out.println("CHECK"); } else */ + if (event.detail == SWT.NONE /* 0, click */) { + if (openOnClick) { + if (item != null) + ProblemElementViewer.this.viewer.setExpandedState(item, !ProblemElementViewer.this.viewer.getExpandedState(item)); + } + + for (IProblemElementViewerOnSingleClick listener : singleClickListeners) { + listener.problemElementViewerOnSingleClick(item); + } + + } + + }); + + } + + /** + * Adds the DND. + */ + public void addDND() { + int operations = DND.DROP_COPY | DND.DROP_MOVE; + Transfer[] transferTypes = new Transfer[] { TextTransfer.getInstance() }; + + ProblemElementDropListener drop = new ProblemElementDropListener(this.viewer); + ProblemElementDragListener drag = new ProblemElementDragListener(this.viewer); + + ContextInjectionFactory.inject(drop, this.context); + ContextInjectionFactory.inject(drag, this.context); + + this.viewer.addDragSupport(operations, transferTypes, drag); + this.viewer.addDropSupport(operations, transferTypes, drop); + + } + + /** + * Creates the main column. + * + * @param type the type + */ + private void createMainColumn(String type) { + this.nameColumn = new TreeViewerColumn(this.viewer, SWT.NONE); + this.drawMainColumn(type); + + parent.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + Composite composite = (Composite) e.widget; + int width = composite.getBounds().width; + nameColumn.getColumn().setWidth(width); + } + }); + } + + /** + * Draw main column. + * + * @param type the type + */ + private void drawMainColumn(String type) { + + this.nameColumn.getColumn().setWidth(300); + + String label = ""; //$NON-NLS-1$ + if (type.equals(Alternative.Type)) + label = this.problemMessages.ALTERNATIVE_GROUP_NAME; + else if (type.equals(Criterion.Type)) + label = this.problemMessages.CRITERION_GROUP_NAME; + else if (type.equals(Expert.Type)) + label = this.problemMessages.EXPERT_GROUP_NAME; + this.nameColumn.getColumn().setText(label); + + this.nameColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(getLabelProvider(type))); + this.viewer.getTree().setSortColumn(this.viewer.getTree().getColumn(0)); + + } + + /** + * Gets the label provider. + * + * @param type the type + * @return the label provider + */ + protected IStyledLabelProvider getLabelProvider(String type) { + return new ProblemElementNameLabelProvider(); + } + + /** + * Creates the table viewer. + * + * @param parent the parent + */ + private void createTableViewer(Composite parent) { + if (checkable) { + // Tree tree = new Tree(parent, SWT.NONE); + this.viewer = new CheckboxTreeViewer(parent); + if (checkStateProvider != null) + ((CheckboxTreeViewer) viewer).setCheckStateProvider(checkStateProvider); + + for (ICheckStateListener listener : checkStatelisteners) { + ((CheckboxTreeViewer) viewer).addCheckStateListener(listener); + } + + } else { + this.viewer = new TreeViewer(parent); + } + this.viewer.setContentProvider(new ProblemElementTreeContentProvider()); + this.viewer.getTree().setHeaderVisible(true); + this.viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); + } + + /** + * Update viewer. + * + * @param type the type + */ + public void updateViewer(String type) { + if (this.viewer != null) { + + ProblemElement[] items = ProblemElementHelper.getAsUserOrdered(problemService.getMainElements(type)); + Arrays.sort(items, new Comparator() { + public int compare(ProblemElement o1, ProblemElement o2) { + return transformToSInteger(o1.getName()) - transformToSInteger(o2.getName()); + } + + int transformToSInteger(String str) { + String number = str.replaceAll("\\D", ""); + return number.isEmpty() ? 0 : Integer.parseInt(number); + } + }); + + if ( this.headerProblemElement != null ) { + ProblemElement[] children = headerProblemElement.getChildren(); + for( ProblemElement child : children ) + headerProblemElement.removeChildren(child); + + for(ProblemElement item : items) + headerProblemElement.addChildren(item); + + items = new ProblemElement[1]; + items[0] = headerProblemElement; + } + + this.viewer.setInput(items); + } + } + + /** + * Gets the header problem element. + * + * @return the header problem element + */ + public FakeProblemElement getHeaderProblemElement() { + return headerProblemElement; + } + + + /** + * Gets the tree. + * + * @return the tree + */ + public TreeViewer getTree() { + return this.viewer; + } + + /** + * Sets the focus. + */ + public void setFocus() { + this.viewer.getControl().setFocus(); + } + + /** + * Gets the notified. + * + * @param s the s + */ + @SuppressWarnings("unused") + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + this.drawMainColumn(this.peType); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementViewerV2.java b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementViewerV2.java new file mode 100644 index 0000000..199a564 --- /dev/null +++ b/bundles/flintstones.application.perspective.framework.ui/src/flintstones/application/perspective/framework/ui/viewer/ProblemElementViewerV2.java @@ -0,0 +1,142 @@ +package flintstones.application.perspective.framework.ui.viewer; + +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.e4.ui.workbench.modeling.ESelectionService; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.handlers.ModifyProblemElementHandler; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.Config; + +public class ProblemElementViewerV2 { + + @Inject + ESelectionService selectionService; + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + private TreeViewer viewer; + private Config config = new Config().defaultEnabled( // + "openedOnClick" // + , "modifiedOnDoubleClick" // + , "isDragAndDropEnabled", // + "sendBrokerOnClick" // + ); + + public void buildProblemElementViewerV2(Composite parent, ProblemElement[] rootElements, String type) { + drawViewer(parent, rootElements, type); + } + + public ProblemElementViewerV2() { + + } + + public ProblemElementViewerV2 drawViewer(Composite parent, ProblemElement[] rootElements, String type) { + + viewer = new TreeViewer(parent); + viewer.setContentProvider(new ProblemElementContentProviderV2(type, rootElements)); + viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new ProblemElementLabelProviderV2())); + viewer.setAutoExpandLevel(4); + + refresh(rootElements); + + // One click + viewer.addSelectionChangedListener(event -> { + IStructuredSelection selection = event.getStructuredSelection(); + selectionService.setSelection(selection.getFirstElement()); + if(config.is("sendBrokerOnClick")) { + broker.post(FrameworkConstants.TOPIC_SELECTION_FRAMEWORK_PROBLEMELEMENT, selection.getFirstElement()); + } + + }); + + // Two click + viewer.addDoubleClickListener(event -> { + TreeSelection selection = (TreeSelection) event.getSelection(); + selectionService.setSelection(selection); + + if (selection.getFirstElement() instanceof FakeProblemElement) + return; + + if (config.is("modifiedOnDoubleClick")) { + ContextInjectionFactory.make(ModifyProblemElementHandler.class, context) + .handle((ProblemElement) selection.getFirstElement()); + } + + }); + + // Comparator + viewer.setComparator(new ViewerComparator() { + public int compare(Viewer viewer, Object e1, Object e2) { + ProblemElement a = (ProblemElement) e1; + ProblemElement b = (ProblemElement) e2; + return a.getOrder() > b.getOrder() ? 1 : -1; + }; + }); + + if (config.is("isDragAndDropEnabled")) { + // Drag & drop + int operations = DND.DROP_COPY | DND.DROP_MOVE; + Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() }; + + ProblemElementDragProviderV2 drag = new ProblemElementDragProviderV2(viewer); + ProblemElementDropProviderV2 drop = new ProblemElementDropProviderV2(viewer); + ContextInjectionFactory.inject(drag, context); + ContextInjectionFactory.inject(drop, context); + + viewer.addDragSupport(operations, transferTypes, drag); + viewer.addDropSupport(operations, transferTypes, drop); + } + + return this; + + } + + // Config + public ProblemElementViewerV2 isOpenedOnClick(boolean val) { + config.set("openedOnClick", val); + return this; + } + + public ProblemElementViewerV2 isModifiedOnDoubleClick(boolean val) { + config.set("modifiedOnDoubleClick", val); + return this; + } + + public ProblemElementViewerV2 isDragAndDropEnabled(boolean val) { + config.set("isDragAndDropEnabled", val); + return this; + } + + public ProblemElementViewerV2 sendBrokerOnClick(boolean val) { + config.set("sendBrokerOnClick", val); + return this; + } + + public void refresh(ProblemElement[] items) { + + viewer.setInput(items); + viewer.refresh(); + + } + +} diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/.classpath b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/.polyglot.META-INF b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.polyglot.META-INF new file mode 100644 index 0000000..be6414d --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.perspective.frameworkstructuring.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] FrameworkStructuringUI + + Sinbad2 + + diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/.project b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.project new file mode 100644 index 0000000..098b0b0 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.application.perspective.frameworkstructuring.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362527 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/META-INF/MANIFEST.MF b/bundles/flintstones.application.perspective.frameworkstructuring.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..475a5b7 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.application.perspective.frameworkstructuring.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: %Bundle-Vendor +Require-Bundle: flintstones.element.common.ui, + flintstones.helper.ui, + flintstones.helper.debug, + flintstones.model.problemelement.service, + javax.inject, + org.eclipse.e4.core.services, + org.eclipse.e4.core.contexts, + flintstones.model.domain.service, + org.eclipse.e4.core.di, + flintstones.entity.valuation, + flintstones.model.valuation.service, + javax.annotation, + flintstones.model.ui.service, + flintstones.application.perspective.framework.ui, + org.lorissecuro.ui +Automatic-Module-Name: flintstones.frameworkstructuring.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.application.perspective.frameworkstructuring.ui/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..a9b091b --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,7 @@ +#Properties file for flintstones.frameworkstructuring.ui +Bundle-Vendor = Sinbad2 +Bundle-Name = FrameworkStructuringUI +flintstones.frameworkstructuring.ui.part.assignmentsprovider.label = Assignments Provider +flintstones.frameworkstructuring.ui.part.elements = Elements +flintstones.frameworkstructuring.ui.part.domainindex = Domain Index +flintstones.frameworkstructuring.ui.part.elementassignments = Element Assignments \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.application.perspective.frameworkstructuring.ui/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..6b1ad77 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,5 @@ + +flintstones.frameworkstructuring.ui.part.assignmentsprovider.label = Proveedor de asignaciones +flintstones.frameworkstructuring.ui.part.elements = Elementos +flintstones.frameworkstructuring.ui.part.domainindex = ndice de dominios +flintstones.frameworkstructuring.ui.part.elementassignments = Asignacin de elementos \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/build.properties b/bundles/flintstones.application.perspective.frameworkstructuring.ui/build.properties new file mode 100644 index 0000000..af0d2fd --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/build.properties @@ -0,0 +1,8 @@ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + fragment.e4xmi,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ +source.. = src/ diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/fragment.e4xmi b/bundles/flintstones.application.perspective.frameworkstructuring.ui/fragment.e4xmi new file mode 100644 index 0000000..2120036 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/fragment.e4xmi @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/plugin.xml b/bundles/flintstones.application.perspective.frameworkstructuring.ui/plugin.xml new file mode 100644 index 0000000..7454818 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/plugin.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/Messages.java b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/Messages.java new file mode 100644 index 0000000..817b845 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/Messages.java @@ -0,0 +1,14 @@ +// This file has been auto-generated +package flintstones.application.perspective.frameworkstructuring.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String ElementsAssignmentStack_title_template; + public String AssignmentsProviderStack_appy; + public String WILDCARD; + +} diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/messages.properties b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/messages.properties new file mode 100644 index 0000000..0686448 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/messages.properties @@ -0,0 +1,3 @@ +ElementsAssignmentStack_title_template= {0} | {1} +AssignmentsProviderStack_appy=Apply +WILDCARD=* (All) diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/messages_es.properties b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/messages_es.properties new file mode 100644 index 0000000..792a2d0 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/messages/messages_es.properties @@ -0,0 +1,3 @@ +ElementsAssignmentStack_title_template= {0} | {1} +AssignmentsProviderStack_appy=Aplicar +WILDCARD=* (Todos) \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/AssignmentsProviderPart.java b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/AssignmentsProviderPart.java new file mode 100644 index 0000000..d2f7490 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/AssignmentsProviderPart.java @@ -0,0 +1,365 @@ +package flintstones.application.perspective.frameworkstructuring.ui.parts; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +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 org.eclipse.swt.widgets.Label; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.frameworkstructuring.ui.messages.Messages; +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.ui.components.ActionButton; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class AssignmentsProviderStack. + */ +public class AssignmentsProviderPart { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The broker. */ + @Inject + IEventBroker broker; + + @Inject + @Translation + private Messages messages; + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + @Inject + @Translation + private flintstones.entity.problemelement.messages.Messages problemMessages; + + /** The expert combo. */ + Combo expertCombo; + + /** The criterion combo. */ + Combo criterionCombo; + + /** The alternative combo. */ + Combo alternativeCombo; + + /** The domain combo. */ + Combo domainCombo; + + // Translatable + private Label expertLabel; + private Label alternativeLabel; + private Label criterionLabel; + private Label domainLabel; + private ActionButton apply; + + /** + * Creates the controls. + * + * @param parent the parent + */ + @PostConstruct + public void createControls(Composite parent) { + + // Create 4 combo boxes plus 1 button to apply + UiService.setGridLayout(parent, 9, false); + UiService.setGridData(parent, 9, 9, true, true); + + Composite l = new Composite(parent, 0); + UiService.setGridLayout(l, 8, false); + UiService.setGridData(l, 9, 1, true, false); + + Composite r = new Composite(parent, 0); + UiService.setGridLayout(r, 1, true); + UiService.setGridData(r, 9, 1, false, false); + + this.createCombos(l); + this.createButton(r); + + } + + /** + * Creates the label combo. + * + * @param parent the parent + * @param text the label + * @return the combo + */ + private Combo createCombo(Composite parent, String type) { + Combo combo = new Combo(parent, SWT.READ_ONLY); + + if (type != null) { + combo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + //String name = combo.getText(); + //ProblemElement element = problemService.getByName(type, name); + //broker.post(FrameworkConstants.TOPIC_SELECTION_FRAMEWORK_PROBLEMELEMENT, element); + } + }); + } + + UiService.setGridData(combo, 9, 1, true, false); + + return combo; + } + + private Label createLabel(Composite parent) { + Label label = new Label(parent, SWT.LEFT); + UiService.setGridData(label, -1, 0, false, false); + + return label; + } + + private void drawLabelCombo(Label label, Combo combo, String text) { + label.setText(text); + combo.setText(text); + }; + + /** + * Creates the combo. + * + * @param parent the parent + */ + public void createCombos(Composite parent) { + + // EXPERTS + this.expertLabel = this.createLabel(parent); + this.expertCombo = this.createCombo(parent, Expert.Type); + + // CRITERION + this.criterionLabel = this.createLabel(parent); + this.criterionCombo = this.createCombo(parent, Criterion.Type); + + // ALTERNATIVE + this.alternativeLabel = this.createLabel(parent); + this.alternativeCombo = this.createCombo(parent, Alternative.Type); + + // DOMAIN + this.domainLabel = this.createLabel(parent); + this.domainCombo = this.createCombo(parent, null); + + // Set Placeholder Texts + this.drawCombos(); + } + + private void drawCombos() { + + this.expertCombo.removeAll(); + this.criterionCombo.removeAll(); + this.alternativeCombo.removeAll(); + this.domainCombo.removeAll(); + + this.drawLabelCombo(this.expertLabel, this.expertCombo, this.problemMessages.EXPERT_ENTITY_NAME); + this.drawLabelCombo(this.criterionLabel, this.criterionCombo, this.problemMessages.CRITERION_ENTITY_NAME); + this.drawLabelCombo(this.alternativeLabel, this.alternativeCombo, this.problemMessages.ALTERNATIVE_ENTITY_NAME); + this.drawLabelCombo(this.domainLabel, this.domainCombo, this.domainMessages.Domain_entity); + + this.setExperts(); + this.setCriterion(); + this.setAlternatives(); + this.setDomains(); + + } + + /** + * Adds the domains. + */ + private void setDomains() { + + Domain[] domainArr = this.domainService.getAll(); + for (Domain d : domainArr) + this.domainCombo.add(d.getName()); + + if (domainArr.length > 0) + domainCombo.select(0); + } + + /** + * Adds the alternatives. + */ + private void setAlternatives() { + + this.alternativeCombo.add(this.messages.WILDCARD); + this.alternativeCombo.select(0); + + for (ProblemElement a : this.problemService.getSubElements(Alternative.Type)) + this.alternativeCombo.add(a.getName()); + + } + + /** + * Adds the criterion. + */ + private void setCriterion() { + + this.criterionCombo.add(this.messages.WILDCARD); + this.criterionCombo.select(0); + + for (ProblemElement a : this.problemService.getSubElements(Criterion.Type)) + this.criterionCombo.add(a.getName()); + + } + + /** + * Adds the experts. + */ + private void setExperts() { + this.expertCombo.add(this.messages.WILDCARD); + this.expertCombo.select(0); + + for (ProblemElement a : this.problemService.getSubElements(Expert.Type)) + this.expertCombo.add(a.getName()); + + } + + /** + * Creates the button. + * + * @param parent the parent + */ + public void createButton(Composite parent) { + + this.apply = new ActionButton(parent, 0, 12); + UiService.setGridData(apply.getButton(), -1, 1, true, false); + apply.setHeight(30); + + apply.getButton().setMarginHeight(0); + apply.getButton().setMarginWidth(0); + this.drawButton(); + + this.apply.getButton().addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + buttonClick(); + } + }); + + } + + private void drawButton() { + this.apply.setText(this.messages.AssignmentsProviderStack_appy); + } + + private void buttonClick() { + // 1. Grab IDs from ComboBoxes + String expertId = expertCombo.getText(); + String criterionId = criterionCombo.getText(); + String alternativeId = alternativeCombo.getText(); + String domainId = domainCombo.getText(); + + // If there is no domain there is nothing to do + if (domainId.equals("")) //$NON-NLS-1$ + return; + + // Fill some lists with the posible items + ArrayList experts = new ArrayList<>(); + ArrayList criterions = new ArrayList<>(); + ArrayList alternatives = new ArrayList<>(); + + if (expertId.equals(messages.WILDCARD)) + experts.addAll(Arrays.asList(problemService.getSubElements(Expert.Type))); + else { + ProblemElement e1 = problemService.getByName(Expert.Type, expertId); + experts.add(e1); + } + + if (criterionId.equals(messages.WILDCARD)) + criterions.addAll(Arrays.asList(problemService.getSubElements(Criterion.Type))); + else { + ProblemElement c1 = problemService.getByName(Criterion.Type, criterionId); + criterions.add(c1); + } + + if (alternativeId.equals(messages.WILDCARD)) + alternatives.addAll(Arrays.asList(problemService.getSubElements(Alternative.Type))); + else { + ProblemElement a1 = problemService.getByName(Alternative.Type, alternativeId); + alternatives.add(a1); + } + + Domain d1 = domainService.getByName(domainId); + + // Create a valuation for each one + for (ProblemElement ei : experts) + for (ProblemElement ai : alternatives) + for (ProblemElement ci : criterions) { + ProblemElementKey pek = new ProblemElementKey((Expert) ei, (Alternative) ai, (Criterion) ci); + Valuation v = valuationService.create(d1); + valuationService.addOrUpdate(pek, v); + } + + broker.post(FrameworkConstants.TOPIC_VALUATION_CREATED, null); + broker.post(FrameworkConstants.TOPIC_VALUATION_ASSIGNED, null); + + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_ALLTOPICS) Object o) { + this.drawCombos(); + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribeModifiedDomain(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_MODIFIED) Object o) { + this.drawCombos(); + } + + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + this.drawCombos(); + this.drawButton(); + } +} diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/DomainIndexPart.java b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/DomainIndexPart.java new file mode 100644 index 0000000..f3d453a --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/DomainIndexPart.java @@ -0,0 +1,55 @@ +package flintstones.application.perspective.frameworkstructuring.ui.parts; + +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.element.common.ui.views.DomainViewer; + +/** + * The Class DomainIndexStack. + */ +public class DomainIndexPart { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The domain viewer. */ + DomainViewer viewer; + + /** The Constant SUB_ID. */ + private static final String SUB_ID = FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_ALLTOPICS; + + /** + * Inits the part. + * + * @param parent the parent + */ + @PostConstruct + public void init(Composite parent) { + this.viewer = ContextInjectionFactory.make(DomainViewer.class, this.context); + this.viewer.createControls(parent, false, false); + } + + /** + * Subscribe. + * + * @param event the event + */ + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribe(@UIEventTopic(DomainIndexPart.SUB_ID) Map event) { + this.viewer.updateViewer(); + } + +} diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ElementPart.java b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ElementPart.java new file mode 100644 index 0000000..65673b2 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ElementPart.java @@ -0,0 +1,69 @@ +package flintstones.application.perspective.frameworkstructuring.ui.parts; + +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewerV2; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * @author UJA + * postConstruct + */ +public class ElementPart { + + @Inject + IProblemElementService problemService; + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + private static final String SUB_ID = FrameworkConstants.TOPIC_FRAMEWORK_ALLTOPICS; + + /** + * Function called after the construction of our MPart, basically creates the structure of the + * TableViewer and adds the data that has been added in the Framework perspective. + * @param parent + */ + + ProblemElementViewerV2 viewer; + + @PostConstruct + public void createControls(Composite base) { + + String type = (String) context.get("Type"); + + ProblemElement[] pes = problemService.getSubElements(type); + + viewer = new ProblemElementViewerV2() + .isOpenedOnClick(true) + .isModifiedOnDoubleClick(false) + .isDragAndDropEnabled(false) + .drawViewer(base, pes, type); + + ContextInjectionFactory.inject(viewer, context); + + } + + @Inject + @Optional + private void subscribe(@UIEventTopic(ElementPart.SUB_ID) Map event) { + String type = (String) context.get("Type"); + ProblemElement[] pes = problemService.getSubElements(type); + this.viewer.refresh(pes); + } +} diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ElementsAssignmentPart.java b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ElementsAssignmentPart.java new file mode 100644 index 0000000..81a1679 --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ElementsAssignmentPart.java @@ -0,0 +1,298 @@ + +package flintstones.application.perspective.frameworkstructuring.ui.parts; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.frameworkstructuring.ui.messages.Messages; +import flintstones.element.common.ui.providers.AssignmentsTableProvider; +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.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.debug.DH; +import flintstones.helper.wtable.WTable; +import flintstones.helper.wtable.WTableModel; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class ElementsAssignmentStack. + */ +public class ElementsAssignmentPart { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The part. */ + @Inject + MPart part; + + @Inject + @Translation + private Messages messages; + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + @Inject + @Translation + private flintstones.entity.problemelement.messages.Messages problemMessages; + + /** The table. */ + private WTable wtable; + + /** The table model. */ + private WTableModel tableModel; + + /** The table provider. */ + private AssignmentsTableProvider provider; + + /** The current problem element. */ + private ProblemElement currentProblemElement; + + /** The base composite. */ + private Composite baseComposite; + + /** is the table transposed */ + private boolean isTransposed = false; + + /** The Constant SUB_ID_PROBLEM. */ + private static final String SUB_ID_PROBLEM = FrameworkConstants.TOPIC_FRAMEWORK_ALLTOPICS; + + /** The Constant SUB_ID_SELECTION. */ + private static final String SUB_ID_SELECTION = FrameworkConstants.TOPIC_SELECTION_FRAMEWORK_PROBLEMELEMENT; + + /** The Constant SUB_ID_TRANSPOSE. */ + private static final String SUB_ID_TRANSPOSE = "TOPIC/COMMAND/TRANSPOSE"; //$NON-NLS-1$ + + /** + * Inits the part. + * + * @param parent the parent + */ + @PostConstruct + public void init(Composite parent) { + + this.baseComposite = parent; + parent.getParent().setLayout(new FillLayout()); + + ProblemElement[] items = this.problemService.getAll(Expert.Type); + + if (items.length > 0) + this.initPart(items[0]); + } + + + /** + * Draw table. + * + * @param parent the parent + */ + private void drawTable(Composite parent) { + Composite cc = new Composite(parent, SWT.NONE); + cc.setLayout(new FillLayout()); + this.wtable = new WTable(cc, SWT.V_SCROLL); + } + + /** + * Refresh table. + */ + public void refreshTable() { + if (this.currentProblemElement != null) + this.initPart(this.currentProblemElement); + baseComposite.layout(); + } + + /** + * Inits the part. + * + * @param pe Problem Element + * Draw a table for the given Problem Element + */ + public void initPart(ProblemElement pe) { + + if (this.wtable == null) + this.drawTable(this.baseComposite); + + this.currentProblemElement = pe; + + // Part title + this.drawPartTitle(); + + // Table + this.provider = ContextInjectionFactory.make(AssignmentsTableProvider.class, this.context); + this.provider.show(Domain.Fields.Domain.toString()); + this.provider.prepareTableContent(pe); + + if (this.isTransposed) + this.provider.transpose(); + + this.setTable(); + } + + private void drawPartTitle() { + ProblemElement pe = this.currentProblemElement; + String template = this.messages.ElementsAssignmentStack_title_template; + + String type = pe.getType(); + String label = ""; //$NON-NLS-1$ + + if (type.equals(Alternative.Type)) + label = this.problemMessages.ALTERNATIVE_ENTITY_NAME; + else if (type.equals(Criterion.Type)) + label = this.problemMessages.CRITERION_ENTITY_NAME; + else if (type.equals(Expert.Type)) + label = this.problemMessages.EXPERT_ENTITY_NAME; + + String message = MessageFormat.format(template, label, pe.getCanonicalName()); + this.part.setLabel(message); + } + + /** + * Sets the table. + */ + private void setTable() { + + // Clear last table listener if it exists + if (this.tableModel != null) + this.tableModel.clearListeners(); + + this.tableModel = new WTableModel(this.wtable); + + // Cabeceras + this.tableModel.setHorizontalHeaders(this.provider.getTableHeaderH()); + this.tableModel.setVerticalHeaders(this.provider.getTableHeaderV()); + + // Contenido, PH, Abbr + this.tableModel.addContent(this.provider.getTableValuations()); + + this.wtable.setModel(this.tableModel); + this.tableModel.init(); + } + + + /** + * Subscribe selection. + * + * @param event the event + */ + @Inject + @Optional + private void subscribeSelectionAlt(@UIEventTopic(ElementsAssignmentPart.SUB_ID_SELECTION) ProblemElement pe) { + + if(pe != null && !(pe instanceof FakeProblemElement)) { + this.initPart(pe); + this.refreshTable(); + } + + } + + /** + * Subscribe problem. + * + * @param event the event + */ + @Inject + @Optional + private void subscribeProblem(@UIEventTopic(ElementsAssignmentPart.SUB_ID_PROBLEM) Map event) { + this.refreshTable(); + + DH.out("refresh", "refreshTable"); + + } + + /** + * Subscribe transpose. + * + * @param event the event + */ + @Inject + @Optional + private void subscribeTranspose(@UIEventTopic(ElementsAssignmentPart.SUB_ID_TRANSPOSE) Map event) { + DH.out("refresh", "subscribeTranspose"); + + if (this.currentProblemElement != null) { + this.provider.transpose(); + this.setTable(); + this.isTransposed = !this.isTransposed; + } + } + + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + DH.out("refresh", "getNotified"); + + this.drawPartTitle(); + } + + @Inject + @Optional + private void subscribeFrameworkstructuring(@UIEventTopic(FrameworkConstants.TOPIC_VALUATION_ASSIGNED) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + if (items.length > 0) + refreshTable(); + DH.out("refresh", "subscribeFrameworkstructuring"); + } + + @Inject + @Optional + private void subscribeFramework(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_CREATED) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + if (items.length > 0) + this.initPart(items[0]); + DH.out("refresh", "subscribeFramework"); + } + + @Inject + @Optional + private void subscribeFramework2(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + if (items.length > 0) + this.initPart(items[0]); + DH.out("refresh", "subscribeFramework"); + } + + @Inject + @Optional + private void subscribeFrameworkModifiedDomain(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_MODIFIED) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + if (items.length > 0) + this.initPart(items[0]); + DH.out("refresh", "subscribeFrameworkModifiedDomain"); + } +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ViewElementsPart.java b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ViewElementsPart.java new file mode 100644 index 0000000..aea2d4d --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/ViewElementsPart.java @@ -0,0 +1,294 @@ + +package flintstones.application.perspective.frameworkstructuring.ui.parts; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.frameworkstructuring.ui.messages.Messages; +import flintstones.element.common.ui.providers.AssignmentsTableProvider; +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.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.debug.DH; +import flintstones.helper.wtable.WTable; +import flintstones.helper.wtable.WTableModel; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class ElementsAssignmentStack. + */ +public class ViewElementsPart { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The part. */ + @Inject + MPart part; + + @Inject + @Translation + private Messages messages; + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + @Inject + @Translation + private flintstones.entity.problemelement.messages.Messages problemMessages; + + /** The table. */ + private WTable wtable; + + /** The table model. */ + private WTableModel tableModel; + + /** The table provider. */ + private AssignmentsTableProvider provider; + + /** The current problem element. */ + private ProblemElement currentProblemElement; + + /** The base composite. */ + private Composite baseComposite; + + /** is the table transposed */ + private boolean isTransposed = false; + + /** The Constant SUB_ID_PROBLEM. */ + private static final String SUB_ID_PROBLEM = FrameworkConstants.TOPIC_FRAMEWORK_ALLTOPICS; + + /** The Constant SUB_ID_SELECTION. */ + private static final String SUB_ID_SELECTION = FrameworkConstants.TOPIC_SELECTION_FRAMEWORK_PROBLEMELEMENT; + + /** The Constant SUB_ID_TRANSPOSE. */ + private static final String SUB_ID_TRANSPOSE = "TOPIC/COMMAND/TRANSPOSE"; //$NON-NLS-1$ + + /** + * Inits the part. + * + * @param parent the parent + */ + @PostConstruct + public void init(Composite parent) { + + this.baseComposite = parent; + parent.getParent().setLayout(new FillLayout()); + + ProblemElement[] items = this.problemService.getAll(Expert.Type); + + if (items.length > 0) + this.initPart(items[0]); + } + + + /** + * Draw table. + * + * @param parent the parent + */ + private void drawTable(Composite parent) { + Composite cc = new Composite(parent, SWT.NONE); + cc.setLayout(new FillLayout()); + this.wtable = new WTable(cc, SWT.V_SCROLL); + } + + /** + * Refresh table. + */ + public void refreshTable() { + if (this.currentProblemElement != null) + this.initPart(this.currentProblemElement); + baseComposite.layout(); + } + + /** + * Inits the part. + * + * @param pe Problem Element + * Draw a table for the given Problem Element + */ + public void initPart(ProblemElement pe) { + + if (this.wtable == null) + this.drawTable(this.baseComposite); + + this.currentProblemElement = pe; + + // Part title + this.drawPartTitle(); + + // Table + this.provider = ContextInjectionFactory.make(AssignmentsTableProvider.class, this.context); + this.provider.show(Domain.Fields.Domain.toString()); + this.provider.prepareTableContent(pe); + + if (this.isTransposed) + this.provider.transpose(); + + this.setTable(); + } + + private void drawPartTitle() { + ProblemElement pe = this.currentProblemElement; + String template = this.messages.ElementsAssignmentStack_title_template; + + String type = pe.getType(); + String label = ""; //$NON-NLS-1$ + + if (type.equals(Alternative.Type)) + label = this.problemMessages.ALTERNATIVE_ENTITY_NAME; + else if (type.equals(Criterion.Type)) + label = this.problemMessages.CRITERION_ENTITY_NAME; + else if (type.equals(Expert.Type)) + label = this.problemMessages.EXPERT_ENTITY_NAME; + + String message = MessageFormat.format(template, label, pe.getCanonicalName()); + this.part.setLabel(message); + } + + /** + * Sets the table. + */ + private void setTable() { + + // Clear last table listener if it exists + if (this.tableModel != null) + this.tableModel.clearListeners(); + + this.tableModel = new WTableModel(this.wtable); + + // Cabeceras + this.tableModel.setHorizontalHeaders(this.provider.getTableHeaderH()); + this.tableModel.setVerticalHeaders(this.provider.getTableHeaderV()); + + // Contenido, PH, Abbr + this.tableModel.addContent(this.provider.getTableValuations()); + + this.wtable.setModel(this.tableModel); + this.tableModel.init(); + } + + + /** + * Subscribe selection. + * + * @param event the event + */ + @Inject + @Optional + private void subscribeSelectionAlt(@UIEventTopic(ViewElementsPart.SUB_ID_SELECTION) ProblemElement pe) { + + if(pe != null && !(pe instanceof FakeProblemElement)) { + this.initPart(pe); + this.refreshTable(); + } + + } + + /** + * Subscribe problem. + * + * @param event the event + */ + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribeProblem(@UIEventTopic(ViewElementsPart.SUB_ID_PROBLEM) Map event) { + this.refreshTable(); + + DH.out("refresh", "refreshTable"); + + } + + /** + * Subscribe transpose. + * + * @param event the event + */ + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribeTranspose(@UIEventTopic(ViewElementsPart.SUB_ID_TRANSPOSE) Map event) { + DH.out("refresh", "subscribeTranspose"); + + if (this.currentProblemElement != null) { + this.provider.transpose(); + this.setTable(); + this.isTransposed = !this.isTransposed; + } + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + DH.out("refresh", "getNotified"); + + this.drawPartTitle(); + } + + @Inject + @Optional + private void subscribeFrameworkstructuring(@UIEventTopic(FrameworkConstants.TOPIC_VALUATION_ASSIGNED) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + if (items.length > 0) + this.initPart(items[0]); + DH.out("refresh", "subscribeFrameworkstructuring"); + } + + @Inject + @Optional + private void subscribeFramework(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_CREATED) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + + if (items.length > 0) + this.initPart(items[0]); + DH.out("refresh", "subscribeFramework"); + } + + @Inject + @Optional + private void subscribeFramework2(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + + if (items.length > 0) + this.initPart(items[0]); + DH.out("refresh", "subscribeFramework"); + } +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/rename/AssignationItem.java b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/rename/AssignationItem.java new file mode 100644 index 0000000..516592e --- /dev/null +++ b/bundles/flintstones.application.perspective.frameworkstructuring.ui/src/flintstones/application/perspective/frameworkstructuring/ui/parts/rename/AssignationItem.java @@ -0,0 +1,183 @@ +package flintstones.application.perspective.frameworkstructuring.ui.parts.rename; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; + +public class AssignationItem { + + // Current item + ProblemElement element1; + ProblemElement element2 = null; + ProblemElement element3 = null; + + // Relatives + AssignationItem parent = null; + List children = new LinkedList<>(); + + // Data + String assignedDomainId = ""; + boolean isEnabled = true; + + + + public AssignationItem(FakeProblemElement rootItem, ProblemElement[] elements1, ProblemElement[] elements2, + ProblemElement[] elements3) { + + element1 = rootItem; + + for (ProblemElement element1 : elements1) { + children.add(new AssignationItem(element1, elements2, elements3)); + } + + } + + private AssignationItem(ProblemElement cElement1, ProblemElement[] elements2, ProblemElement[] elements3) { + + element1 = cElement1; + + if (cElement1.hasChildren()) { + ProblemElement[] childList = element1.getChildren(); + for (ProblemElement child : childList) { + AssignationItem agg = new AssignationItem(child, elements2, elements3); + agg.setParent(this); + children.add(agg); + } + } else { + for (ProblemElement cElement2 : elements2) { + AssignationItem agg = new AssignationItem(cElement1, cElement2, elements3); + agg.setParent(this); + children.add(agg); + } + + } + + } + + private AssignationItem(ProblemElement cElement1, ProblemElement cElement2, ProblemElement[] elements3) { + + element1 = cElement1; + element2 = cElement2; + + if (cElement2.hasChildren()) { + ProblemElement[] childList = element2.getChildren(); + for (ProblemElement child : childList) { + AssignationItem agg = new AssignationItem(cElement1, child, elements3); + agg.setParent(this); + children.add(agg); + } + } else { + for (ProblemElement criterion : elements3) { + AssignationItem agg = new AssignationItem(cElement1, cElement2, criterion); + agg.setParent(this); + children.add(agg); + } + + } + + } + + private AssignationItem(ProblemElement cElement1, ProblemElement cElement2, ProblemElement cElement3) { + + element1 = cElement1; + element2 = cElement2; + element3 = cElement3; + + if (element3.hasChildren()) { + ProblemElement[] criterions = cElement3.getChildren(); + for (ProblemElement c : criterions) { + AssignationItem agg = new AssignationItem(cElement1, cElement2, c); + agg.setParent(this); + children.add(agg); + } + } + + } + + @Override + public String toString() { + + String a = element1 != null ? element1.getName() : "1X"; + String e = element2 != null ? element2.getName() : "2X"; + String c = element3 != null ? element3.getName() : "3X"; + + return a + " : " + e + " : " + c; + } + + public ProblemElement getFinalItem() { + if (element3 != null) + return element3; + if (element2 != null) + return element2; + return element1; + } + + public void setParent(AssignationItem item) { + parent = item; + } + + public AssignationItem getParent() { + return parent; + } + + public boolean hasChildren() { + return children.size() != 0; + } + + public AssignationItem[] getChildren() { + return children.toArray(new AssignationItem[0]); + } + + public void setChildren(List children) { + this.children = children; + } + +// +// public ProblemElement getAlternative() { +// return element1; +// } +// +// public void setAlternative(Alternative item, boolean cascade) { +// this.element1 = item; +// if(cascade) +// children.stream().forEach(k -> k.setAlternative(item, cascade)); +// } +// + public ProblemElement getElement2() { + return element2; + } + + public ProblemElement getElement3() { + return element3; + } + + public void setEnabled(boolean x) { + isEnabled = x; + } + + public boolean isEnabled() { + return isEnabled; + } + + public String setDomainId() { + return assignedDomainId; + } + +// public void setOperatorId(String op) { +// this.assignedDomainId = op; +// } + + public void setDomainId(String op, boolean cascade) { + + // If the aggregation item is leaf, do assign operator + if (children.size() != 0) + return; + + this.assignedDomainId = op; + if (cascade) + children.stream().forEach(k -> k.setDomainId(op, true)); + } + +} diff --git a/bundles/flintstones.application.perspective.gathering.ui/.classpath b/bundles/flintstones.application.perspective.gathering.ui/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.perspective.gathering.ui/.polyglot.META-INF b/bundles/flintstones.application.perspective.gathering.ui/.polyglot.META-INF new file mode 100644 index 0000000..caeab34 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.perspective.gathering.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Gathering UI + diff --git a/bundles/flintstones.application.perspective.gathering.ui/.project b/bundles/flintstones.application.perspective.gathering.ui/.project new file mode 100644 index 0000000..eec4e3d --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.application.perspective.gathering.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362528 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.perspective.gathering.ui/META-INF/MANIFEST.MF b/bundles/flintstones.application.perspective.gathering.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ed267f9 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.application.perspective.gathering.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Export-Package: flintstones.application.perspective.gathering.ui.parts +Require-Bundle: flintstones.element.common.ui, + org.eclipse.e4.core.services, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.model.valuation.service, + flintstones.entity.valuation, + javax.annotation, + flintstones.helper.data, + flintstones.model.problemelement.service, + org.eclipse.nebula.widgets.opal.notifier, + flintstones.helper.faq +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Automatic-Module-Name: flintstones.gathering.ui diff --git a/bundles/flintstones.application.perspective.gathering.ui/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.application.perspective.gathering.ui/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..04e9083 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,7 @@ +#Properties file for flintstones.gathering.ui +Bundle-Name = Gathering UI +flintstones.application.perspective.gathering.label = Gathering +flintstones.gathering.ui.part.filterpart.label = Element | Expert +flintstones.gathering.ui.part.domainpart.label = Domain Index +flintstones.gathering.ui.part.selectorpart.label = Valuations | Expert +flintstones.gathering.ui.part.ratingpart.label = Valuation panel \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.gathering.ui/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.application.perspective.gathering.ui/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..0148532 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,7 @@ +#Properties file for flintstones.gathering.ui +Bundle-Name = Gathering UI +flintstones.application.perspective.gathering.label = Gathering +flintstones.gathering.ui.part.filterpart.label = Elemento | Experto +flintstones.gathering.ui.part.domainpart.label = Dominios +flintstones.gathering.ui.part.selectorpart.label = Valoraciones | Experto +flintstones.gathering.ui.part.ratingpart.label = Panel de valoracin \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.gathering.ui/build.properties b/bundles/flintstones.application.perspective.gathering.ui/build.properties new file mode 100644 index 0000000..89dfb29 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/build.properties @@ -0,0 +1,8 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + fragment.e4xmi,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ +source.. = src/ diff --git a/bundles/flintstones.application.perspective.gathering.ui/fragment.e4xmi b/bundles/flintstones.application.perspective.gathering.ui/fragment.e4xmi new file mode 100644 index 0000000..d5ed620 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/fragment.e4xmi @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.gathering.ui/plugin.xml b/bundles/flintstones.application.perspective.gathering.ui/plugin.xml new file mode 100644 index 0000000..172c189 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/ClearTableHandler.java b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/ClearTableHandler.java new file mode 100644 index 0000000..cac0393 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/ClearTableHandler.java @@ -0,0 +1,85 @@ +package flintstones.application.perspective.gathering.ui.handlers; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + +import flintstones.application.constants.ApplicationContants; +import flintstones.application.constants.FrameworkConstants; +import flintstones.element.common.ui.parts.SelectorPart; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +public class ClearTableHandler { + + @Inject + EPartService partService; + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + @Inject + IEventBroker broker; + + @Execute + public void execute() { + + MPart part = partService.findPart(ApplicationContants.MPart_Gatehring_Selector); + SelectorPart instance = (SelectorPart) part.getObject(); + + ProblemElement current = instance.getCurrentProblemElement(); + + String hHeaderType = getType(current.getType(), true, false); + String vHeaderType = getType(current.getType(), true, true); + + ProblemElement[] hHeaders = problemService.getAll(hHeaderType); + ProblemElement[] vHeaders = problemService.getAll(vHeaderType); + + for (ProblemElement item1 : vHeaders) { + for (ProblemElement item2 : hHeaders) { + ProblemElementKey pek = new ProblemElementKey(current, item2, item1); + valuationService.removeValuation(pek); + } + } + + broker.send(FrameworkConstants.TOPIC_VALUATION_CREATED, null); + + } + + private String getType(String type, boolean next, boolean nextnext) { + int x = 0; + + if (Alternative.Type.equals(type)) + x = 0; + else if (Expert.Type.equals(type)) + x = 1; + else if (Criterion.Type.equals(type)) + x = 2; + + if (next) + x++; + if (nextnext) + x++; + + x = x % 3; + + if (x == 0) + return Alternative.Type; + else if (x == 1) + return Expert.Type; + else if (x == 2) + return Criterion.Type; + return null; + } +} diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/PasteValuationHandler.java b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/PasteValuationHandler.java new file mode 100644 index 0000000..1f03f31 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/PasteValuationHandler.java @@ -0,0 +1,143 @@ + +package flintstones.application.perspective.gathering.ui.handlers; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.modeling.EPartService; +import org.eclipse.nebula.widgets.opal.notifier.NotifierColorsFactory.NotifierTheme; +import org.eclipse.nebula.widgets.opal.notifier.WNotifier; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.widgets.Display; + +import flintstones.application.constants.ApplicationContants; +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.gathering.ui.messages.Messages; +import flintstones.element.common.ui.parts.SelectorPart; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.entity.valuation.exception.InvalidValueException; +import flintstones.helper.MatrixHelper; +import flintstones.helper.StringHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +public class PasteValuationHandler { + + @Inject + EPartService partService; + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + @Inject + @Translation + Messages messages; + + @Inject + IEventBroker broker; + + @Execute + public void execute() { + + Clipboard clipboard = new Clipboard(Display.getCurrent()); + String plainText = (String) clipboard.getContents(TextTransfer.getInstance()); + + HashMatrix data = MatrixHelper.toHashMatrix(plainText, true); + MPart part = partService.findPart(ApplicationContants.MPart_Gatehring_Selector); + SelectorPart instance = (SelectorPart) part.getObject(); + + ProblemElement current = instance.getCurrentProblemElement(); + + String hHeaderType = getType(current.getType(), true, false); + String vHeaderType = getType(current.getType(), true, true); + + ProblemElement[] hHeaders = problemService.getSubElements(hHeaderType); + ProblemElement[] vHeaders = problemService.getSubElements(vHeaderType); + +// DH.out(hHeaders); +// DH.out(vHeaders); + + boolean error = false; + + for (ProblemElement item1 : vHeaders) { + for (ProblemElement item2 : hHeaders) { + + ProblemElementKey pek = new ProblemElementKey(current, item2, item1); + String sValue = data.get(StringHelper.Draw(item1.getName()), StringHelper.Draw(item2.getName())); + Valuation v = valuationService.getValuationFor(pek); + + try { + v.setValueFromString(sValue); + v.setEvaluated(true); + valuationService.addOrUpdate(pek, v); + } catch(InvalidValueException e) { + + new WNotifier("Error", e.getMessage() + "\n" + pek.toString() + messages.Fix_error) //$NON-NLS-1$ + .withCloseOnClick(true) + .withTimeout(60) + .send(); + + error = true; + } + + if(error) + break; + } + + if(error) + break; + + } + + if(!error) + new WNotifier(messages.Successfully_completed, messages.Valuations_successfully_added, NotifierTheme.BLUE_THEME) + .send(); + + broker.send(FrameworkConstants.TOPIC_VALUATION_CREATED, null); + +// System.out.println(data); + + } + + + + private String getType(String type, boolean next, boolean nextnext) { + int x = 0; + + if (Alternative.Type.equals(type)) + x = 0; + else if (Expert.Type.equals(type)) + x = 1; + else if (Criterion.Type.equals(type)) + x = 2; + + if (next) + x++; + if (nextnext) + x++; + + x = x % 3; + + if (x == 0) + return Alternative.Type; + else if (x == 1) + return Expert.Type; + else if (x == 2) + return Criterion.Type; + return null; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/SelectorFaqHandler.java b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/SelectorFaqHandler.java new file mode 100644 index 0000000..2dcacc9 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/SelectorFaqHandler.java @@ -0,0 +1,31 @@ +package flintstones.application.perspective.gathering.ui.handlers; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + +import flintstones.application.constants.ApplicationContants; +import flintstones.element.common.ui.parts.SelectorPart; +import flintstones.helper.faq.FaqHelper; + +public class SelectorFaqHandler { + + @Inject + EPartService partService; + + @Inject + IEclipseContext context; + + @Execute + public void execute() { + + MPart part = partService.findPart(ApplicationContants.MPart_Gatehring_Selector); + SelectorPart instance = (SelectorPart) part.getObject(); + + ContextInjectionFactory.make(FaqHelper.class, context).showFAQ(instance); + } +} diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/TransposeHandler.java b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/TransposeHandler.java new file mode 100644 index 0000000..d5eafc0 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/handlers/TransposeHandler.java @@ -0,0 +1,28 @@ +package flintstones.application.perspective.gathering.ui.handlers; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; + +/** + * The Class TransposeHandler. Handle transpose when button is pushed + */ +public class TransposeHandler { + + /** The event broker. */ + @Inject + IEventBroker eventBroker; + + /** The Constant BUS_ID. */ + private static final String BUS_ID = "TOPIC/COMMAND/TRANSPOSE"; //$NON-NLS-1$ + + /** + * Execute. + */ + @Execute + public void execute() { + this.eventBroker.post(TransposeHandler.BUS_ID, null); + } + +} diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/Messages.java b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/Messages.java new file mode 100644 index 0000000..34a6779 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/Messages.java @@ -0,0 +1,16 @@ +// This file has been auto-generated +package flintstones.application.perspective.gathering.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String RatingPart_label; + public String Fix_error; + public String Successfully_completed; + public String Valuations_successfully_added; + + +} diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/messages.properties b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/messages.properties new file mode 100644 index 0000000..8fbd156 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/messages.properties @@ -0,0 +1,4 @@ +Fix_error=\n Fix the error and remove the data to try again +Successfully_completed=Successfully completed +Valuations_successfully_added=Valuations successfully added +RatingPart_label=Valuation Panel - Evaluating {0} with {1} with {2} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/messages_es.properties b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/messages_es.properties new file mode 100644 index 0000000..3a042d1 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/messages/messages_es.properties @@ -0,0 +1,4 @@ +Fix_error=\n Corrige el error y elimina los datos para volver a intenarlo +Successfully_completed=Completado con xito +Valuations_successfully_added=Se han aadido los valoraciones correctamente +RatingPart_label=Panel de valoracin - Valorando {0} con {1} con {2} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/parts/DomainPart.java b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/parts/DomainPart.java new file mode 100644 index 0000000..ef73969 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/parts/DomainPart.java @@ -0,0 +1,56 @@ +package flintstones.application.perspective.gathering.ui.parts; + +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.element.common.ui.views.DomainViewer; + +/** + * The Class DomainPart. + * + * @author Sinbad2 + * The gathering UI domain list part + */ +public class DomainPart { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The domain viewer. */ + DomainViewer viewer; + + /** The Constant SUB_ID. */ + private static final String SUB_ID = FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_ALLTOPICS; + + /** + * Inits the part. + * + * @param parent the parent + */ + @PostConstruct + public void init(Composite parent) { + this.viewer = ContextInjectionFactory.make(DomainViewer.class, this.context); + this.viewer.createControls(parent, false, false); + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribe(@UIEventTopic(DomainPart.SUB_ID) Map event) { + this.viewer.updateViewer(); + } +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/parts/RatingPart.java b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/parts/RatingPart.java new file mode 100644 index 0000000..bff0bd6 --- /dev/null +++ b/bundles/flintstones.application.perspective.gathering.ui/src/flintstones/application/perspective/gathering/ui/parts/RatingPart.java @@ -0,0 +1,193 @@ +package flintstones.application.perspective.gathering.ui.parts; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.gathering.ui.messages.Messages; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.valuation.Valuation; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.cell.ValuationTableCell; +import flintstones.valuation.ui.ValuationPanel; +import flintstones.valuation.ui.listener.EValuationPanelEvent; +import flintstones.valuation.ui.listener.IValuationPanelListener; +import flintstones.valuation.ui.listener.ValuationPanelEvent; +import flintstones.valuation.ui.service.IValuationUIService; + +/** + * The Class RatingPart. + * + * @author Sinbad 2 The gathering ui rating part. + */ +public class RatingPart implements IValuationPanelListener { + + /** The base composite. */ + private Composite baseComposite; + + /** The valuation UI service. */ + @Inject + IValuationUIService valuationUIService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** The part. */ + @Inject + MPart part; + + @Inject + @Translation + Messages messages; + + /** The Constant SUB_ID_VALUATION_SELECTED. */ + private static final String SUB_ID_VALUATION_SELECTED = FrameworkConstants.TOPIC_SELECTION_VALUATION; + + /** The Constant BUS_ID_VALUATION_CREATED. */ + private static final String BUS_ID_VALUATION_CREATED = FrameworkConstants.TOPIC_VALUATION_CREATED; + + /** The Constant BUS_ID_VALUATION_MODIFIED. */ + private static final String BUS_ID_VALUATION_MODIFIED = FrameworkConstants.TOPIC_VALUATION_MODIFIED; + + /** The current pek. */ + private ProblemElementKey currentPek; + + /** + * Constructor real. + */ + RatingPart() { + } + + /** + * Creates the ui after constructor is called. + * + * @param parent The parent composite + */ + @PostConstruct + public void createControls(Composite parent) { + this.baseComposite = parent; + this.part.getParent().setVisible(false); + + } + + /** + * Draw the part. + * + * @param vtc the vtc + * @param pek the pek + */ + public void draw(ValuationTableCell vtc, ProblemElementKey pek) { + + String template = messages.RatingPart_label; + this.part.setLabel(MessageFormat.format(template, pek.getExpert().getName(), + pek.getAlternative().getName(), + pek.getCriterion().getName()).toString()); + this.part.getParent().setVisible(true); + + String domainId = vtc.getValuation().getDomain().getType(); + String valuationId = valuationService.getExtensionIdFor(domainId); + String valuationUiId = valuationUIService.getExtensionIdFor(valuationId); + ValuationPanel vp = valuationUIService.newValuationPanel(valuationUiId); + this.currentPek = pek; + + vp.registerValuationPanelListener(this); + + Composite ratingComposite = this.getEmptyBaseComposite(); + + // Patch for the old Valuation Panel code to work with the new data model. + Valuation v = vtc.getValuation(); + if (!v.isEvaluated()) + v = null; + + vp.initialize(ratingComposite, vtc.getValuation().getDomain(), v); + ratingComposite.layout(); + + } + + /** + * Gets the base composite after removing all its children. + * + * @return Returns an empty base composite + */ + public Composite getEmptyBaseComposite() { + for (Control c : this.baseComposite.getChildren()) + c.dispose(); + return this.baseComposite; + } + + /** + * Subscribe selected. + * + * @param event the event + */ + @Inject + @Optional + private void subscribeSelected(@UIEventTopic(RatingPart.SUB_ID_VALUATION_SELECTED) Map event) { + ValuationTableCell vtc = (ValuationTableCell) event.get("cell"); //$NON-NLS-1$ + ProblemElementKey pek = (ProblemElementKey) event.get("pek"); //$NON-NLS-1$ + this.draw(vtc, pek); + } + + /* + * (non-Javadoc) + * + * @see flintstones.valuation.ui.listener.IValuationPanelListener# + * notifyValuationPanelChange(flintstones.valuation.ui.listener. + * ValuationPanelEvent) + */ + @Override + public void notifyValuationPanelChange(ValuationPanelEvent event) { + + // Valuation oldValuation = event.getOldValuation(); + Valuation newValuation = event.getNewValuation(); + if(newValuation == null) + return ; + + EValuationPanelEvent e = event.getEvent(); + + switch (e) { + case NEW_VALUATION: + this.valuationService.addOrUpdate(this.currentPek, newValuation); + this.broker.post(RatingPart.BUS_ID_VALUATION_CREATED, null); + break; + case MODIFY_VALUATION: + this.valuationService.addOrUpdate(this.currentPek, newValuation); + this.broker.post(RatingPart.BUS_ID_VALUATION_MODIFIED, null); + break; + default: break; + + } + } + + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + this.part.getParent().setVisible(false); + } + + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Object o) { + this.part.getParent().setVisible(false); + } + + +} \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.method.ui/.classpath b/bundles/flintstones.application.perspective.method.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.perspective.method.ui/.polyglot.META-INF b/bundles/flintstones.application.perspective.method.ui/.polyglot.META-INF new file mode 100644 index 0000000..7c1830f --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.perspective.method.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.application.perspective.method.ui/.project b/bundles/flintstones.application.perspective.method.ui/.project new file mode 100644 index 0000000..6195061 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.application.perspective.method.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362529 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.perspective.method.ui/META-INF/MANIFEST.MF b/bundles/flintstones.application.perspective.method.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..67c51b7 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.application.perspective.method.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.e4.ui.model.workbench, + org.eclipse.swt, + javax.inject, + flintstones.helper.ui, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.eclipse.e4.core.services, + flintstones.application.constants, + org.eclipse.e4.ui.di, + flintstones.model.ui.service, + flintstones.helper.html, + flintstones.helper.faq, + org.eclipse.osgi, + javax.annotation, + flintstones.application, + flintstones.entity.method, + flintstones.model.method.service, + org.eclipse.e4.ui.workbench, + org.eclipse.osgi.services, + flintstones.helper.debug, + org.lorissecuro.ui, + flintstones.application.perspective.rating.ui +Automatic-Module-Name: flintstones.application.perspective.method.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 diff --git a/bundles/flintstones.application.perspective.method.ui/build.properties b/bundles/flintstones.application.perspective.method.ui/build.properties new file mode 100644 index 0000000..a14e838 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/build.properties @@ -0,0 +1,6 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + fragment.e4xmi,\ + plugin.xml +source.. = src/ diff --git a/bundles/flintstones.application.perspective.method.ui/fragment.e4xmi b/bundles/flintstones.application.perspective.method.ui/fragment.e4xmi new file mode 100644 index 0000000..4087e21 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/fragment.e4xmi @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.method.ui/plugin.xml b/bundles/flintstones.application.perspective.method.ui/plugin.xml new file mode 100644 index 0000000..6590e34 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/MethodInformationPart.java b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/MethodInformationPart.java new file mode 100644 index 0000000..d9f7a1a --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/MethodInformationPart.java @@ -0,0 +1,230 @@ +package flintstones.application.perspective.method.ui; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.osgi.framework.FrameworkUtil; + +import flintstones.application.constants.ApplicationContants; +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.method.Method; +import flintstones.helper.debug.DH; +import flintstones.helper.faq.FaqHelper; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.helper.html.HtmlMarkdown; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.helper.ui.components.ActionButton; +import flintstones.model.ui.service.UiService; +import flintstones.application.handlers.PerspectiveSwitcher; +import flintstones.application.perspective.method.ui.messages.Messages; +import flintstones.application.perspective.rating.ui.dialogs.Algorithm; + +public class MethodInformationPart { + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + @Inject + @Translation + Messages messages; + + @Inject + MPart part; + + // Draw + Label title; + + Composite markdownBase; + + Composite tableBase; + HtmlTextTable validationTable; + +// Button loadMethodButton; + ActionButton loadMethodButton; + + //Execution algorithm + Algorithm algorithm; + + // Data + Method lastMethod; + + @PostConstruct + public void init(Composite parent) { + + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + + title = new Label(parent,0); + UiService.setFont(title, UiService.FONT_BIG_TITLE); + UiService.setGridData(title, 9, -1, true, false); + + markdownBase = new Composite(parent, SWT.BORDER); + UiService.setGridLayout(markdownBase, 1); + GridData gd = UiService.setGridData(markdownBase, 9, 9, true, true); + gd.heightHint = 150; + + Label validationLabel = new Label(parent,0); + validationLabel.setText(messages.MethodInformationPart_Execution_conditions); + UiService.setFont(validationLabel, UiService.FONT_SECTION_TITLE); + gd = UiService.setGridData(validationLabel, 9, -1, true, false); + gd.verticalIndent = 5; + + tableBase = new Composite(parent, 0); + UiService.setGridLayout(tableBase, 1); + UiService.setGridData(tableBase, 9, 9, true, false); + + loadMethodButton = new ActionButton(parent,0, 20); + loadMethodButton.setText(messages.MethodInformationPart_Start); + loadMethodButton.getButton().addMouseListener(new MouseAdapter() { + + @Override + public void mouseUp(MouseEvent e) { + // 1.Change to the phase, it loads empty + ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective(ApplicationContants.MPerspective_Phase); + // 2.Send the method + broker.send(FrameworkConstants.TOPIC_METHOD_LOAD, lastMethod); + + } + + }); + +// UiService.setFontSize(loadMethodButton, 20); +// UiService.setBackgroundColor(loadMethodButton, UiService.COLOR_MAIN); +// UiService.setFontFamily(loadMethodButton, "Helvetica"); //$NON-NLS-1$ + UiService.setGridData(loadMethodButton.getButton(), 9, -1, true, false); + + + + } + + private void setEnabledLoadButton(boolean enabled) { + loadMethodButton.setEnabled(enabled); +// if(enabled) +// UiService.setBackgroundColor(loadMethodButton, UiService.COLOR_MAIN); +// else +// UiService.setBackgroundColor(loadMethodButton, UiService.getColor(255)); + } + + private void draw(Method method) { + + // Information + title.setText(method.getName()); + setEnabledLoadButton(method.canBeExecuted()); + + if(method instanceof IMarkdownFAQ) { + + FaqHelper faq = ContextInjectionFactory.make(FaqHelper.class, context); + String content = faq.getMarkdownFile(method); + + HtmlMarkdown markdownViewer = new HtmlMarkdown(markdownBase); + markdownViewer.setFile(content,FrameworkUtil.getBundle(method.getClass())); + markdownViewer.render(); + + } else { + HtmlMarkdown markdownViewer = new HtmlMarkdown(markdownBase); + markdownViewer.setFile(messages.MethodInformationPart_No_available_information,FrameworkUtil.getBundle(method.getClass())); + markdownViewer.render(); + } + + // Validation + if(algorithm == null) + algorithm = ContextInjectionFactory.make(Algorithm.class, context); + else + removeAlgorithm(); + + algorithm.clearStatements(); + algorithm.addStatement(method.getExecutionStatement()); + algorithm.drawAlgorithm(tableBase); + + tableBase.layout(); + + /*String[] failedValidation = method.getFailedExecuteConditions(); + String[] successValiation = method.getPassedExecuteConditions(); + + String[] headers = new String[] {messages.MethodInformationPart_Message, messages.MethodInformationPart_Type}; + String[][] content = new String[failedValidation.length + successValiation.length][ 2 ]; + + int row = 0; + for(String text : failedValidation) { + content[row][0] = text; + content[row][1] = "Error"; //$NON-NLS-1$ + row++; + } + + for(String text : successValiation) { + content[row][0] = text; + content[row][1] = messages.MethodInformationPart_Success; + row++; + } + + if(failedValidation.length != 0 || successValiation.length != 0 ) { + HtmlTextTable table = new HtmlTextTable(tableBase, content, headers); + table.render(); + }*/ + + + lastMethod = method; + + part.setVisible(true); + + } + + private void removeAlgorithm() { + for(Control child: tableBase.getChildren()) + child.dispose(); + } + + private void hide() { + part.setVisible(false); + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_SELECTION_METHOD) Method m) { + if( m != null ) + draw(m); + else { + hide(); + DH.out("refresh", "Ocultando MethodInformation"); + + } + } + + @Inject + @Optional + private void subscribeSelectionAlt(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_ALLTOPICS) Object o) { + hide(); + DH.out("refresh", "Ocultando MethodInformation"); + } + + @Inject + @Optional + private void subscribeSelectionValuation(@UIEventTopic(FrameworkConstants.TOPIC_VALUATION_ALLTOPICS) Object o) { + hide(); + DH.out("refresh", "Ocultando MethodInformation"); + } + + +} diff --git a/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/MethodSelectionPart.java b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/MethodSelectionPart.java new file mode 100644 index 0000000..9426402 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/MethodSelectionPart.java @@ -0,0 +1,127 @@ +package flintstones.application.perspective.method.ui; + +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.workbench.modeling.EPartService; +import org.eclipse.jface.viewers.AbstractTreeViewer; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +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.widgets.Composite; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.perspective.method.ui.messages.Messages; +import flintstones.application.perspective.method.ui.provider.CategorizedMethodContentProvider; +import flintstones.application.perspective.method.ui.provider.CategorizedMethodLabelProvider; +import flintstones.entity.method.Method; +import flintstones.helper.debug.DH; +import flintstones.model.method.service.IMethodService; + +public class MethodSelectionPart { + + @Inject + IEclipseContext context; + + @Inject + IMethodService methodService; + + @Inject + EPartService partService; + + @Inject + IEventBroker broker; + + @Inject + @Translation + Messages messages; + + private TreeViewer viewer; + + @PostConstruct + public void init(Composite parent) { + + CategorizedMethodLabelProvider labelProvider = ContextInjectionFactory + .make(CategorizedMethodLabelProvider.class, context); + CategorizedMethodContentProvider contentProvider = ContextInjectionFactory + .make(CategorizedMethodContentProvider.class, context); + + viewer = new TreeViewer(parent, SWT.NO_SCROLL); + viewer.setContentProvider(contentProvider); + + TreeViewerColumn mainColumn = new TreeViewerColumn(viewer, SWT.NONE); + mainColumn.getColumn().setText(messages.MethodSelectionPart_Methods); // $NON-NLS-1$ + mainColumn.getColumn().setWidth(300); + mainColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(labelProvider)); + + viewer.getTree().setHeaderVisible(true); + viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); + + String[] arr = methodService.getAllCategories(); + viewer.setInput(arr); + + parent.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + Composite composite = (Composite) e.widget; + int width = composite.getBounds().width; + mainColumn.getColumn().setWidth(width); + } + }); + + Tree tree = (Tree) viewer.getControl(); + tree.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + TreeItem item = (TreeItem) e.item; + if (item.getData() instanceof Method) { + Method m = (Method) item.getData(); + broker.send(FrameworkConstants.TOPIC_SELECTION_METHOD, m); + } else { + broker.send(FrameworkConstants.TOPIC_SELECTION_METHOD, null); + } + } + }); + } + + @Inject + @Optional + public void getNotifiedLocale(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + methodService.cacheAllMethods(); + ((CategorizedMethodContentProvider) viewer.getContentProvider()).init(); + viewer.setInput(methodService.getAllCategories()); + viewer.refresh(); + } + + @Inject + @Optional + private void subscribeSelectionAlt(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_ALLTOPICS) Object o) { + viewer.refresh(); + DH.out("refresh", "Refrescando MethodSelectionPart"); + } + + @Inject + @Optional + private void subscribeSelectionValuation(@UIEventTopic(FrameworkConstants.TOPIC_VALUATION_ALLTOPICS) Object o) { + viewer.refresh(); + DH.out("refresh", "Refrescando MethodSelectionPart"); + } + + +} diff --git a/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/Messages.java b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/Messages.java new file mode 100644 index 0000000..90eb34a --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/Messages.java @@ -0,0 +1,13 @@ +package flintstones.application.perspective.method.ui.messages; + +public class Messages { + + public String MethodInformationPart_Execution_conditions; + public String MethodInformationPart_Message; + public String MethodInformationPart_No_available_information; + public String MethodInformationPart_Start; + public String MethodInformationPart_Success; + public String MethodInformationPart_Type; + public String MethodSelectionPart_Methods; + +} diff --git a/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/messages.properties b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/messages.properties new file mode 100644 index 0000000..0177469 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/messages.properties @@ -0,0 +1,7 @@ +MethodInformationPart_Execution_conditions=Execution conditions +MethodInformationPart_Message=Condition +MethodInformationPart_No_available_information=No available information for this method. +MethodInformationPart_Start=Start +MethodInformationPart_Success=Success +MethodInformationPart_Type=State +MethodSelectionPart_Methods=Methods diff --git a/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/messages_es.properties b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/messages_es.properties new file mode 100644 index 0000000..42ef80c --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/messages/messages_es.properties @@ -0,0 +1,7 @@ +MethodInformationPart_Execution_conditions=Condiciones para la ejecucin +MethodInformationPart_Message=Condicin +MethodInformationPart_No_available_information=No exste informacin para este metodo en este momento. +MethodInformationPart_Start=Iniciar +MethodInformationPart_Success=Correcto +MethodInformationPart_Type=Estado +MethodSelectionPart_Methods=Mtodos diff --git a/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/provider/CategorizedMethodContentProvider.java b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/provider/CategorizedMethodContentProvider.java new file mode 100644 index 0000000..b1d2277 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/provider/CategorizedMethodContentProvider.java @@ -0,0 +1,63 @@ +package flintstones.application.perspective.method.ui.provider; + +import java.util.Arrays; +import java.util.HashMap; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; + +import flintstones.entity.method.Method; +import flintstones.model.method.service.IMethodService; + +public class CategorizedMethodContentProvider implements ITreeContentProvider { + + @Inject + IMethodService methodService; + + HashMap categories = new HashMap<>(); + + @PostConstruct + public void init() { + loadCategories(); + } + + private void loadCategories() { + categories.clear(); + for(String category: methodService.getAllCategories()) { + Method[] methods = methodService.getAllMethodForCategory(category); + Arrays.stream(methods).forEach(k -> categories.put(category, k)); + } + } + + @Override + public Method[] getChildren(Object parentElement) { + if (parentElement instanceof String) { + String category = (String) parentElement; + return methodService.getAllMethodForCategory(category); + } + return null; + } + + @Override + public Object[] getElements(Object inputElement) { + return ArrayContentProvider.getInstance().getElements(inputElement); + } + + @Override + public Object getParent(Object element) { + if (element instanceof String) + return null; + + Method m = (Method) element; + return categories.get(m.getCategory()); + } + + @Override + public boolean hasChildren(Object element) { + return categories.containsKey(element); + } + +} diff --git a/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/provider/CategorizedMethodLabelProvider.java b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/provider/CategorizedMethodLabelProvider.java new file mode 100644 index 0000000..25279f0 --- /dev/null +++ b/bundles/flintstones.application.perspective.method.ui/src/flintstones/application/perspective/method/ui/provider/CategorizedMethodLabelProvider.java @@ -0,0 +1,42 @@ +package flintstones.application.perspective.method.ui.provider; + +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; + +import flintstones.entity.method.Method; +import flintstones.model.ui.service.UiService; + +public class CategorizedMethodLabelProvider extends LabelProvider implements IStyledLabelProvider { + @Override + public StyledString getStyledText(Object element) { + + if (element instanceof String) + return new StyledString(element.toString()); + + Method m = (Method) element; + if(m.canBeExecuted()) + return UiService.paintText(m.getName(), "[✔]", UiService.COLOR_FG_SUCCESS, UiService.COLOR_FG_SUCCESS); + else + //return UiService.paintText(m.getName(), "[" + m.getFailedExecuteConditions()[0] + "]", UiService.COLOR_FG_ERROR); + return UiService.paintText(m.getName(), "[X]", UiService.COLOR_FG_ERROR, UiService.COLOR_FG_ERROR); + } + + @Override + public String getText(Object element) { + + if (element instanceof String) + element.toString(); + + Method m = (Method) element; + return m.getName(); + + } + + @Override + public Image getImage(Object element) { + return null; + } + +} diff --git a/bundles/flintstones.application.perspective.phase.ui/.classpath b/bundles/flintstones.application.perspective.phase.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.perspective.phase.ui/.polyglot.META-INF b/bundles/flintstones.application.perspective.phase.ui/.polyglot.META-INF new file mode 100644 index 0000000..038ec85 --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.perspective.phase.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.application.perspective.phase.ui/.project b/bundles/flintstones.application.perspective.phase.ui/.project new file mode 100644 index 0000000..25b4944 --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.application.perspective.phase.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362531 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.perspective.phase.ui/META-INF/MANIFEST.MF b/bundles/flintstones.application.perspective.phase.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9fe9e40 --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.application.perspective.phase.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.e4.ui.model.workbench, + org.eclipse.swt, + org.eclipse.nebula.widgets.opal.breadcrumb, + flintstones.helper.ui, + javax.inject, + flintstones.model.ui.service, + javax.annotation, + org.eclipse.e4.ui.di, + org.eclipse.e4.core.di.annotations, + flintstones.application.constants, + flintstones.helper.faq, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.entity.method.phasepage, + flintstones.entity.method, + flintstones.model.method.service, + flintstones.model.method.phase.service, + flintstones.entity.method.phase.ui, + flintstones.application, + org.eclipse.e4.core.services, + org.eclipse.osgi.services, + flintstones.entity.method.phase +Automatic-Module-Name: flintstones.application.perspective.phase.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Export-Package: flintstones.application.perspective.phase.ui diff --git a/bundles/flintstones.application.perspective.phase.ui/build.properties b/bundles/flintstones.application.perspective.phase.ui/build.properties new file mode 100644 index 0000000..a14e838 --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/build.properties @@ -0,0 +1,6 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + fragment.e4xmi,\ + plugin.xml +source.. = src/ diff --git a/bundles/flintstones.application.perspective.phase.ui/fragment.e4xmi b/bundles/flintstones.application.perspective.phase.ui/fragment.e4xmi new file mode 100644 index 0000000..a27c4aa --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/fragment.e4xmi @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.phase.ui/plugin.xml b/bundles/flintstones.application.perspective.phase.ui/plugin.xml new file mode 100644 index 0000000..e1dadea --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.application.perspective.phase.ui/src/flintstones/application/perspective/phase/ui/PhantomPhaseCanvasPart.java b/bundles/flintstones.application.perspective.phase.ui/src/flintstones/application/perspective/phase/ui/PhantomPhaseCanvasPart.java new file mode 100644 index 0000000..0f62b76 --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/src/flintstones/application/perspective/phase/ui/PhantomPhaseCanvasPart.java @@ -0,0 +1,132 @@ +package flintstones.application.perspective.phase.ui; + +import java.util.Arrays; +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.di.UIEventTopic; +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.Composite; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; + +import flintstones.application.constants.ApplicationContants; +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.method.phasepage.PhasePage; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.ui.service.UiService; +import flintstones.application.handlers.PerspectiveSwitcher; + +public class PhantomPhaseCanvasPart implements EventHandler { + + @Inject + IPhaseMethodService phaseService; + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + Composite canvas; + Button saveButton; + + PhaseMethodUI lastUI = null; + + @PostConstruct + private void createControls(Composite parent) { + + UiService.setGridDataAuto(parent); + UiService.setGridLayout(parent, 1); + + canvas = new Composite(parent, 0); + UiService.setGridDataAuto(canvas); + UiService.setGridLayout(canvas, 1); + + Composite controlRow = new Composite(parent,0); + UiService.setGridLayout(controlRow, 4, true); + UiService.setGridData(controlRow, 9, 0, true, false); + + saveButton = new Button(controlRow, SWT.PUSH ); + saveButton.setText("Save"); + saveButton.setEnabled(false); + saveButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective(ApplicationContants.MPerspective_Phase); + broker.send(FrameworkConstants.TOPIC_METHOD_PHASE_PHANTOM_RESPONSE, lastUI); + broker.unsubscribe(PhantomPhaseCanvasPart.this); + + } + + }); + UiService.setGridData(saveButton, 9, 0, true, false); + + + Button cancelButton = new Button(controlRow, SWT.PUSH ); + cancelButton.setText("Cancel"); + cancelButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective(ApplicationContants.MPerspective_Phase); + broker.unsubscribe(PhantomPhaseCanvasPart.this); + } + }); + UiService.setGridData(cancelButton, 9, 0, true, false); + + } + + private void draw(String phaseId) { + + Arrays.stream(canvas.getChildren()).forEach(k -> k.dispose()); + + PhaseMethodUI phaseUI = phaseService.createPhase(phaseId); + lastUI = phaseUI; + + Composite phaseBase = new Composite(canvas, 0); + UiService.setGridLayout(phaseBase, 1); + UiService.setGridData(phaseBase, 9, 9, true, true); + + PhasePage page = new PhasePage(phaseBase, phaseUI, null); + page.load(); + + } + + private void draw(PhaseMethodUI phaseUI) { + lastUI = phaseUI; + + Composite phaseBase = phaseUI.getBaseComposite(); + PhasePage page = new PhasePage(phaseBase, phaseUI, null); + page.load(); + } + + + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_METHOD_PHASE_PHANTOM) Object item) { + + if(item instanceof PhaseMethodUI) + draw((PhaseMethodUI)item); + else + draw((String)item); + + broker.subscribe(FrameworkConstants.TOPIC_METHOD_PHASE_REFRESH, this); + + } + + @Override + public void handleEvent(Event event) { + boolean status = lastUI.isPhaseCompleted(); + saveButton.setEnabled(status); + } + + +} diff --git a/bundles/flintstones.application.perspective.phase.ui/src/flintstones/application/perspective/phase/ui/PhaseContainer.java b/bundles/flintstones.application.perspective.phase.ui/src/flintstones/application/perspective/phase/ui/PhaseContainer.java new file mode 100644 index 0000000..b6acaa5 --- /dev/null +++ b/bundles/flintstones.application.perspective.phase.ui/src/flintstones/application/perspective/phase/ui/PhaseContainer.java @@ -0,0 +1,254 @@ +package flintstones.application.perspective.phase.ui; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.nebula.widgets.opal.breadcrumb.Breadcrumb; +import org.eclipse.nebula.widgets.opal.breadcrumb.BreadcrumbItem; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +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.application.constants.FrameworkConstants; +import flintstones.entity.method.Method; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.method.phasepage.PhasePage; +import flintstones.helper.faq.FaqHelper; +import flintstones.helper.faq.interfaces.IFAQ; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.method.service.IMethodService; +import flintstones.model.ui.service.UiService; + +public class PhaseContainer { + + @Inject + IPhaseMethodService phaseService; + + @Inject + IMethodService methodService; + + + @Inject + IEclipseContext context; + + Breadcrumb menu; + + Composite stackComposite; + StackLayout stackLayout = new StackLayout(); + + // Controls + Button nextButton; + Button prevButton; + Button infoButton; + + Label methodNameLabel; + Label phaseLabel; + + // DATA + int currentPage = 0; + ArrayList pages = new ArrayList<>(); + + public PhaseContainer() { + } + + @PostConstruct + private void createControls(Composite parent) { + + UiService.setGridData(parent, 9, 9, true, true); + UiService.setGridLayout(parent, 1); + + menu = new Breadcrumb(parent, SWT.BORDER); + UiService.setGridLayout(menu, 1); + UiService.setGridData(menu, 9, -1, true, false); + + stackComposite = new Composite(parent, SWT.BORDER); + UiService.setGridData(stackComposite, 9, 9, true, true); + UiService.setGridLayout(stackComposite, 1); + stackComposite.setLayout(stackLayout); + stackComposite.layout(); + + Composite footer = new Composite(parent, SWT.BORDER); + UiService.setGridLayout(footer, 3, true); + UiService.setGridData(footer, 9, -1, true, false); + + methodNameLabel = new Label(footer, 0); + methodNameLabel.setText("XXXXXXXXXXXXXXXX"); + UiService.setGridData(methodNameLabel, -1, 0, true, false); + + Composite controlsComposite = new Composite(footer, 0); + UiService.setGridLayout(controlsComposite, 3, true); + UiService.setGridData(controlsComposite, 0, 0, true, false); + + prevButton = new Button(controlsComposite, SWT.PUSH); + prevButton.setImage(UiService.getIcon("core/phase_left.png").createImage()); + prevButton.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + showPage(currentPage - 1); + } + }); + + infoButton = new Button(controlsComposite, SWT.PUSH); + infoButton.setImage(UiService.getImage("info.png").createImage()); + infoButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + PhasePage page = pages.get(currentPage); + FaqHelper faq = ContextInjectionFactory.make(FaqHelper.class, context); + faq.showFAQ(page.getUI().getModel()); + } + }); + + nextButton = new Button(controlsComposite, SWT.PUSH); + nextButton.setImage(UiService.getIcon("core/phase_right.png").createImage()); + nextButton.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + showPage(currentPage + 1); + } + }); + + phaseLabel = new Label(footer, 0); + phaseLabel.setText("XXXX2"); + UiService.setGridData(phaseLabel, 1, 0, true, false); + + } + + private void showPage(int pageNumber) { + + if (currentPage != pageNumber) + pages.get(currentPage).exit(); + + // Change page + currentPage = pageNumber; + + PhasePage page = pages.get(pageNumber); + page.load(); + + if (page.isItSkippable()) { + page.skip(); + showPage(pageNumber + 1); + } else { + setStackTop(page.getContainer()); + refreshUI(pageNumber); + } + + } + + private void refreshUI(int pageNumber) { + // Update UI state + for (int i = 0; i < pages.size(); i++) { + PhasePage page = pages.get(i); + boolean isSelected = i == pageNumber; + boolean isEnabled = i == 0 || pages.get(i - 1).getUI().isPhaseCompleted(); + page.update(isSelected, isEnabled); + } + + menu.redraw(); + + prevButton.setEnabled(pageNumber != 0); + nextButton.setEnabled(pageNumber != pages.size() - 1 && pages.get(pageNumber).getUI().isPhaseCompleted()); + infoButton.setEnabled(pages.get(pageNumber).getUI().getModel() instanceof IFAQ); + + phaseLabel.setText(pageNumber + 1 + "/" + pages.size()); + } + + private void loadMethod(Method currentMethod) { + + // CLEAN + currentPage = 0; + pages.stream().forEach(k -> k.dispose()); + pages.clear(); + + // LOAD + methodService.loadPhasesFor(currentMethod); + for (PhaseMethodUI phaseUI : currentMethod.getPhases()) { + PhasePage phasePage = getPage(phaseUI); + pages.add(phasePage); + } + + showPage(currentPage); + + menu.layout(); + methodNameLabel.setText(currentMethod.getName()); + + } + + private PhasePage getPage(PhaseMethodUI phaseUI) { + + Composite phaseBase = new Composite(stackComposite, 0); + UiService.setGridLayout(phaseBase, 1); + UiService.setGridData(phaseBase, 9, 9, true, true); + + BreadcrumbItem phaseMenu = getBreadcrumbItem(phaseUI); + + PhasePage page = new PhasePage(phaseBase, phaseUI, phaseMenu); + return page; + } + + private void setStackTop(Composite c) { + stackLayout.topControl = c; + c.layout(); + c.getParent().layout(); + } + + private BreadcrumbItem getBreadcrumbItem(PhaseMethodUI ui) { + + BreadcrumbItem item = new BreadcrumbItem(menu, SWT.PUSH); + + int index = pages.size() + 1; + String template = " {0} {1}"; //$NON-NLS-1$ + String phaseName = ui.getModel().getName(); + + String text = MessageFormat.format(template, index, phaseName); + item.setText(text); + + item.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + int index = Integer.parseInt(item.getText().trim().split(" ")[0]) - 1; + showPage(index); + } + }); + return item; + + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_METHOD_LOAD) Method m) { + if (m != null) + loadMethod(m); + } + + /** + * Subscribe next. + * + * @param event the event + */ + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribeNext(@UIEventTopic(FrameworkConstants.TOPIC_METHOD_PHASE_REFRESH) Map event) { + refreshUI(currentPage); + } +} diff --git a/bundles/flintstones.application.perspective.rating.ui/.classpath b/bundles/flintstones.application.perspective.rating.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application.perspective.rating.ui/.polyglot.META-INF b/bundles/flintstones.application.perspective.rating.ui/.polyglot.META-INF new file mode 100644 index 0000000..8eddb1e --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application.perspective.rating.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] RatingUI + + Sinbad2 + + diff --git a/bundles/flintstones.application.perspective.rating.ui/.project b/bundles/flintstones.application.perspective.rating.ui/.project new file mode 100644 index 0000000..08799ef --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.application.perspective.rating.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362532 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application.perspective.rating.ui/META-INF/MANIFEST.MF b/bundles/flintstones.application.perspective.rating.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f8d0fe2 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.application.perspective.rating.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: %Bundle-Vendor +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Automatic-Module-Name: flintstones.rating.ui +Import-Package: org.osgi.service.event +Require-Bundle: org.eclipse.jface, + javax.inject, + org.eclipse.e4.core.services, + org.eclipse.e4.core.contexts, + flintstones.model.domain.service, + flintstones.model.ui.service, + flintstones.helper.chainvalidator, + org.eclipse.e4.ui.services, + org.eclipse.e4.core.di, + flintstones.entity.domain +Export-Package: flintstones.application.perspective.rating.ui.dialogs diff --git a/bundles/flintstones.application.perspective.rating.ui/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.application.perspective.rating.ui/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..4207e64 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,6 @@ +#Properties file for flintstones.rating.ui +Bundle-Vendor = Sinbad2 +Bundle-Name = RatingUI +phase.name = Method selection +phasemethod_ui.description = DESC +phasemethod_ui.name = NAME \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.rating.ui/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.application.perspective.rating.ui/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..33314f4 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,6 @@ +#Properties file for flintstones.rating.ui +Bundle-Vendor = Sinbad2 +Bundle-Name = RatingUI +phase.name = Selecci\u00F3n de metodo +phasemethod_ui.description = DESC +phasemethod_ui.name = NAME \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.rating.ui/build.properties b/bundles/flintstones.application.perspective.rating.ui/build.properties new file mode 100644 index 0000000..869f4c2 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/build.properties @@ -0,0 +1,8 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + fragment.e4xmi,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/,\ + faq/ +source.. = src/ diff --git a/bundles/flintstones.application.perspective.rating.ui/faq/methodselection.en.md b/bundles/flintstones.application.perspective.rating.ui/faq/methodselection.en.md new file mode 100644 index 0000000..0eae10e --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/faq/methodselection.en.md @@ -0,0 +1,7 @@ +# Method Selection Phase + +From this phase you can select a method to be loaded. Green methods are the ones that can be executed with the data that was collected during the previous phases. + + +To check why a method can not be executed you can view the conditios for it to be executed in the show algorithm button. + diff --git a/bundles/flintstones.application.perspective.rating.ui/fragment.e4xmi b/bundles/flintstones.application.perspective.rating.ui/fragment.e4xmi new file mode 100644 index 0000000..d0649e7 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/fragment.e4xmi @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/dialogs/Algorithm.java b/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/dialogs/Algorithm.java new file mode 100644 index 0000000..45bc656 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/dialogs/Algorithm.java @@ -0,0 +1,276 @@ +package flintstones.application.perspective.rating.ui.dialogs; + +import java.util.ArrayList; + +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.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.perspective.rating.ui.messages.Messages; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.Statement; +import flintstones.helper.chainvalidator.operation.BaseOperation; +import flintstones.helper.chainvalidator.operation.method.ValidFuzzysetDomainsOperation; +import flintstones.helper.chainvalidator.pseudocode.Generator; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.ui.service.UiService; + +/** + * The Class AlgorithmDialog. + */ +public class Algorithm { + + /** The translation. */ + @Inject + @Translation + private Messages messages; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The ui service. */ + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The container. */ + private Composite container; + + /** The left box. */ + //private StyledText leftBox; + + /** The right box. */ + private StyledText rightBox; + + /** The bottom box. */ + private StyledText bottomBox; + + /** The IF statements. */ + ArrayList statements = new ArrayList<>(); + + /** + * Instantiates a new algorithm dialog. This dialog will show the method conditions to be executed. + * + * @param shell the shell + */ + + /* (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets. + * Composite) */ + public void drawAlgorithm(Composite parent) { + container = parent; + + Composite upContainer = new Composite(this.container, SWT.NONE); + UiService.setGridLayout(upContainer, 1); + UiService.setGridData(upContainer, 9, 9, true, false); + // UiService.setMargin(upContainer, 15); + + Composite bottomContainer = new Composite(this.container, SWT.NONE); + UiService.setGridLayout(bottomContainer, 1); + UiService.setGridData(bottomContainer, 9, 9, true, false); + // UiService.setMargin(container, 15); + + /*Label leftLabel = new Label(upContainer, SWT.NONE); + UiService.setFont(leftLabel, UiService.FONT_SECTION_TITLE); + leftLabel.setText(this.messages.AlgorithmDialog_Algorithm);*/ + + /*Label rightLabel = new Label(upContainer, SWT.NONE); + UiService.setFont(rightLabel, UiService.FONT_SECTION_TITLE); + rightLabel.setText(this.messages.AlgorithmDialog_Algorithm_instantation);*/ + + /*this.leftBox = new StyledText(upContainer, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.WRAP); + UiService.setGridLayout(this.leftBox, 1); + UiService.setGridData(this.leftBox, 9, 9, true, false);*/ + + this.rightBox = new StyledText(upContainer, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.WRAP); + UiService.setGridLayout(this.rightBox, 1); + UiService.setGridData(this.rightBox, 9, 9, true, false); + + this.bottomBox = new StyledText(bottomContainer, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.WRAP); + UiService.setGridLayout(this.bottomBox, 1); + UiService.setGridData(this.bottomBox, 9, 9, true, false); + //this.bottomBox.setText("\n"); //$NON-NLS-1$ + + this.drawContent(); + } + + /** + * Gets the demo generator. + * + * @return the demo generator + */ + @SuppressWarnings("nls") + private Generator getDemoGenerator() { + Generator generator = ContextInjectionFactory.make(Generator.class, this.context); + + // Variables que obtendr�amos en runtime + int tamEdLinList = 1; + boolean edNum = true; + boolean edIntFALLO = false; + boolean edLinUnb = true; + boolean edHesit = true; + int numExperts = 1; + int numDomains = 1; + + ArrayList validators = new ArrayList<>(); + + ChainValidator c = ContextInjectionFactory.make(ChainValidator.class, this.context) + .setReturn("Modelo computacional 2-tuplas") //$NON-NLS-1$ + .isTrue("ALGO?", true) //$NON-NLS-1$ + .named("edLin[1].2T") //$NON-NLS-1$ + .equals("N�mero de dominios linguisticos", 1, tamEdLinList) //$NON-NLS-1$ + .named("tamEdLinList"); //$NON-NLS-1$ + validators.add(c); + + c = ContextInjectionFactory.make(ChainValidator.class, this.context) + .setReturn("Enfoque de fusi�n para la manipulaci�n de informaci�nn heterog�nea") //$NON-NLS-1$ + .isTrue("Es dominio numerico", edNum) //$NON-NLS-1$ + .named("edNum") //$NON-NLS-1$ + .or() + .isTrue("Es dominio entero", edIntFALLO) //$NON-NLS-1$ + .named("edInt"); //$NON-NLS-1$ + validators.add(c); + + c = ContextInjectionFactory.make(ChainValidator.class, this.context) + .setReturn("Metodolog�a para tratar con conjuntos de t�rminos ling�isticos no balanceados") //$NON-NLS-1$ + .isTrue("Es dominio linguistico no balanceado", edLinUnb) //$NON-NLS-1$ + .named("edLinUnb"); //$NON-NLS-1$ + validators.add(c); + + c = ContextInjectionFactory.make(ChainValidator.class, this.context) + .setReturn("Informaci�n Ling�istica Hesitant 2-tuplas") //$NON-NLS-1$ + .isTrue("Es dominio hesitant", edHesit) //$NON-NLS-1$ + .named("edHesit") //$NON-NLS-1$ + .greaterThan("Numero de expertos", 1, numExperts) //$NON-NLS-1$ + .named("numExperts") //$NON-NLS-1$ + .equals("Numero de dominios", 1, numDomains) //$NON-NLS-1$ + .named("numDomains"); //$NON-NLS-1$ + validators.add(c); + + c = ContextInjectionFactory.make(ChainValidator.class, this.context) + .setReturn("Hesitant Fuzzy Linguistic Term Set") //$NON-NLS-1$ + .isTrue("Es dominio hesitant", edHesit) //$NON-NLS-1$ + .named("edHesit") //$NON-NLS-1$ + .equals("Numero de expertos", 1, numExperts) //$NON-NLS-1$ + .named("numExperts") //$NON-NLS-1$ + .equals("Numero de dominios", 1, numDomains) //$NON-NLS-1$ + .named("numDomains"); //$NON-NLS-1$ + validators.add(c); + + c = ContextInjectionFactory.make(ChainValidator.class, this.context) + .setReturn("Informaci�n Ling�istica Difusa Hesitant con terminos en 2-tuplas") //$NON-NLS-1$ + .isTrue("Es dominio hesitant", edHesit) //$NON-NLS-1$ + .named("edHesit") //$NON-NLS-1$ + .greaterThan("Numero de dominios", 1, numDomains) //$NON-NLS-1$ + .named("numDomains"); //$NON-NLS-1$ + validators.add(c); + + c = ContextInjectionFactory.make(ChainValidator.class, this.context) + .setReturn("Prueba") //$NON-NLS-1$ + .custom(new ValidFuzzysetDomainsOperation("dominios", this.domainService.getAll())) //$NON-NLS-1$ + .named("domains"); //$NON-NLS-1$ + validators.add(c); + + validators.stream() + .forEach(k -> { + generator.addStatement(k.getStatement()); + }); + + return generator; + } + + /** + * Draw content of the dialog. It will draw valid statement if avaliable. Else it will render the default example. + */ + private void drawContent() { + + Generator generator = ContextInjectionFactory.make(Generator.class, this.context); + if (this.statements.isEmpty()) + generator = this.getDemoGenerator(); + else + this.statements.stream() + .forEach(generator::addStatement); + + //generator.drawStyledPseudoCode(this.leftBox, false); + generator.drawStyledPseudoCode(this.rightBox, true); + + //this.addDescriptionListener(generator); + this.addValidationListener(generator); + + } + + /** + * Adds the description onclick listener. + * + * @param generator the generator + */ + /*private void addDescriptionListener(Generator generator) { + this.leftBox.addMouseListener(new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + } + + @Override + public void mouseDown(MouseEvent e) { + BaseOperation op = generator.getOperator(Algorithm.this.leftBox.getSelection()); + if (op != null && op.getDescription() != null) + Algorithm.this.bottomBox.setText(op.getDescription()); + + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + } + }); + }*/ + + /** + * Adds the validation box onclick listener. + * + * @param generator the generator + */ + private void addValidationListener(Generator generator) { + this.rightBox.addMouseListener(new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + } + + @Override + public void mouseDown(MouseEvent e) { + BaseOperation op = generator.getOperator(Algorithm.this.rightBox.getSelection()); + if (op != null && op.getValidationMessage() != null) + Algorithm.this.bottomBox.setText(op.getValidationMessage()); + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + } + }); + } + + /** + * Adds the If statements to be draw. + * + * @param statement the statement + */ + public void addStatement(Statement statement) { + this.statements.add(statement); + } + + public void clearStatements() { + this.statements.clear(); + } +} diff --git a/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/Messages.java b/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/Messages.java new file mode 100644 index 0000000..4e8ae85 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/Messages.java @@ -0,0 +1,31 @@ +// This file has been auto-generated +package flintstones.application.perspective.rating.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String AlgorithmDialog_Algorithm; + public String AlgorithmDialog_Algorithm_instantation; + public String AlgorithmDialog_btn_close; + public String checks; + public String Container_back_button; + public String Container_method_label; + public String Container_next_button; + public String Container_reset_button; + public String Container_step_label; + public String Container_step_label_default; + public String Container_step_template; + public String messagesFormat; + public String method_selection; + public String phasename; + public String RatingView_All_information_will_be_lost; + public String RatingView_Cancel_confirm; + public String RatingView_Method_description; + public String RatingView_Method_phases; + public String RatingView_SUITABLE; + public String show_algorith_button; + +} diff --git a/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/messages.properties b/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/messages.properties new file mode 100644 index 0000000..40cc856 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/messages.properties @@ -0,0 +1,27 @@ +AlgorithmDialog_Algorithm=Algorithm +AlgorithmDialog_Algorithm_instantation=Algorithm instantiation +AlgorithmDialog_btn_close=Close +checks=Checks +Container_back_button=Back +Container_method_label=Method: +Container_next_button=Next +Container_reset_button=Reset +Container_step_label=Step: +Container_step_label_default=(0/0) +Container_step_template=( %d / %d ) +messagesFormat={0} ({1}) +method_selection=Method Selection +phasename=Method Selection +RatingView_All_information_will_be_lost=All information will be lost +RatingView_Cancel_confirm=Cancel confirm +RatingView_Method_description=Method description +RatingView_Method_phases=Method phases +RatingView_SUITABLE=\ (SUITABLE) +show_algorith_button=Show Algorithm +RatingView_All_information_will_be_lost=All the information will be lost +RatingView_Cancel_confirm=Confirm cancel +RatingView_Method_description=Method Description +RatingView_Method_phases=Method phases +checks=Checks +phasename=Method selection +show_algorith_button=Show algorithm \ No newline at end of file diff --git a/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/messages_es.properties b/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/messages_es.properties new file mode 100644 index 0000000..a53ecf5 --- /dev/null +++ b/bundles/flintstones.application.perspective.rating.ui/src/flintstones/application/perspective/rating/ui/messages/messages_es.properties @@ -0,0 +1,18 @@ +RatingView_All_information_will_be_lost=Toda la informacin se perder +RatingView_Cancel_confirm=Confirmar cancelacin +RatingView_Method_description=Descripcin de mtodo +RatingView_Method_phases=Fases de mtodo +RatingView_SUITABLE=\ (RECOMENDADO) +checks=Condiciones +Container_back_button=Anterior +Container_method_label=Metodo: +Container_next_button=Siguiente +Container_reset_button=Reiniciar +Container_step_label=Paso: +Container_step_label_default=(0/0) +Container_step_template=( %d / %d ) +messagesFormat={0} ({1}) +method_selection=Seleccin de metodo +phasename=Seleccin de metodo +RatingView_All_information_will_be_lost=Toda la informacin se perder +show_algorith_button=Mostrar algoritmo diff --git a/bundles/flintstones.application/.classpath b/bundles/flintstones.application/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.application/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.application/.polyglot.META-INF b/bundles/flintstones.application/.polyglot.META-INF new file mode 100644 index 0000000..72f9a9f --- /dev/null +++ b/bundles/flintstones.application/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.application + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Plugin rcp flintstones + + Sinbad2 + + diff --git a/bundles/flintstones.application/.project b/bundles/flintstones.application/.project new file mode 100644 index 0000000..a5dd438 --- /dev/null +++ b/bundles/flintstones.application/.project @@ -0,0 +1,45 @@ + + + flintstones.application + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362511 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.application/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.application/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.application/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.application/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.application/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.application/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.application/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.application/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.application/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.application/.settings/org.eclipse.pde.core.prefs b/bundles/flintstones.application/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000..f29e940 --- /dev/null +++ b/bundles/flintstones.application/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/bundles/flintstones.application/Application.e4xmi b/bundles/flintstones.application/Application.e4xmi new file mode 100644 index 0000000..23994c8 --- /dev/null +++ b/bundles/flintstones.application/Application.e4xmi @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NO_MOVE + + no_move + NO_MOVE + + + + + + + NO_MOVE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + stretch + + + + stretch + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.application/META-INF/MANIFEST.MF b/bundles/flintstones.application/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b4689e3 --- /dev/null +++ b/bundles/flintstones.application/META-INF/MANIFEST.MF @@ -0,0 +1,44 @@ +Manifest-Version: 1.0 +Automatic-Module-Name: flintstones.application +Bundle-SymbolicName: flintstones.application;singleton:=true +Export-Package: flintstones.application.handlers +Bundle-Name: Plugin rcp flintstones +Bundle-Version: 1.0.0.qualifier +Require-Bundle: flintstones.model.application.service, + javax.annotation, + javax.inject, + org.eclipse.e4.ui.di, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.services, + flintstones.model.domain.service, + org.eclipse.e4.ui.services, + flintstones.entity.domain, + flintstones.helper.debug, + flintstones.helper.data, + org.eclipse.e4.ui.workbench, + org.eclipse.e4.ui.model.workbench, + org.eclipse.swt, + org.eclipse.core.runtime, + flintstones.helper.data.io, + org.eclipse.e4.core.di, + org.eclipse.jface, + flintstones.model.problemelement.service, + flintstones.application.constants, + flintstones.model.ui.service, + org.eclipse.nebula.widgets.opal.notifier, + flintstones.model.valuation.service, + org.eclipse.equinox.registry, + flintstones.helper.ui, + flintstones.application.perspective.framework.ui, + flintstones.domain.numeric.real, + flintstones.valuation.numeric.integer, + flintstones.model.application.provider, + flintstones.entity.method, + flintstones.model.method.service, + org.lorissecuro.ui, + flintstones.application.debug +Bundle-ManifestVersion: 2 +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-Vendor: Sinbad2 +Eclipse-BundleShape: dir + diff --git a/bundles/flintstones.application/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.application/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..f79206a --- /dev/null +++ b/bundles/flintstones.application/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,49 @@ + +flintstones.application.trimmedwindow.main.label = Flintstones +flintstones.application.perspective.framework.label = Framework +flintstones.application.perspective.frameworkstructuring.label = Framework Structuring +flintstones.application.perspective.gathering.label = Gathering +flintstones.application.perspective.rating.label = Rating +flintstones.application.perspective.sensitiveanalysis.label = Sensitive Analysis +flintstones.application.menu.file.label = File +flintstones.application.menu.file.handledmenuitem.new.label = New +flintstones.application.menu.file.handledmenuitem.open.label = Open +flintstones.application.menu.file.handledmenuitem.save.label = Save +flintstones.application.menu.file.handledmenuitem.saveas.label = Save as... +flintstones.application.menu.file.handledmenuitem.saveandclose.label = Save and close +flintstones.application.menu.file.handledmenuitem.exit.label = Exit +flintstones.application.menu.edit.label = Edit +flintstones.application.menu.edit.handledmenuitem.undo.label = Undo +flintstones.application.menu.edit.handledmenuitem.redo.label = Redo +flintstones.application.menu.edit.handledmenuitem.preferences.label = Preferences +flintstones.application.toolbar.file.handledtoolitem.new.label = New +flintstones.application.toolbar.file.handledtoolitem.new.tooltip = New +flintstones.application.toolbar.file.handledtoolitem.open.label = Open +flintstones.application.toolbar.file.handledtoolitem.open.tooltip = Open +flintstones.application.toolbar.file.handledtoolitem.save.label= Save +flintstones.application.toolbar.file.handledtoolitem.save.tooltip = Save +flintstones.application.toolbar.file.handledtoolitem.saveandclose.label = Save and close +flintstones.application.toolbar.file.handledtoolitem.saveandclose.tooltip = Save and close +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.framework.label = Framework +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.framework.tooltip = Framework +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.frameworkstructuring.label = Framework Structuring +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.frameworkstructuring.tooltip = Framework Structuring +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.gathering.label = Gathering +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.gathering.tooltip = Gathering +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.rating.label = Rating +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.rating.tooltip = Rating +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.sensitiveanalysis.label = Sensitive Analysis +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.sensitiveanalysis.tooltip = Sensitive Analysis +flintstones.application.command.perspectiveswitcher.name = Perspective switcher +flintstones.application.command.new.name = New +flintstones.application.command.open.name = Open +flintstones.application.command.save.name = Save +flintstones.application.command.saveas.name = Save as +flintstones.application.command.saveandclose.name = Save and close +flintstones.application.command.exit.name = Exit +flintstones.application.command.undo.name = Undo +flintstones.application.command.redo.name = Redo +flintstones.application.command.preferences.name = Preferences +flintstones.application.menu.locale.label=Language +flintstones.application.menu.locale.es.label=Spanish +flintstones.application.menu.locale.en.label=English diff --git a/bundles/flintstones.application/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.application/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..542ceb1 --- /dev/null +++ b/bundles/flintstones.application/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,49 @@ + +flintstones.application.trimmedwindow.main.label = Flintstones +flintstones.application.perspective.framework.label = Framework +flintstones.application.perspective.frameworkstructuring.label = Framework Structuring +flintstones.application.perspective.gathering.label = Gathering +flintstones.application.perspective.rating.label = Rating +flintstones.application.perspective.sensitiveanalysis.label = Sensitive Analysis +flintstones.application.menu.file.label = Archivo +flintstones.application.menu.file.handledmenuitem.new.label = Nuevo +flintstones.application.menu.file.handledmenuitem.open.label = Abrir +flintstones.application.menu.file.handledmenuitem.save.label = Guardar +flintstones.application.menu.file.handledmenuitem.saveas.label = Guardar como... +flintstones.application.menu.file.handledmenuitem.saveandclose.label = Guardar y salir +flintstones.application.menu.file.handledmenuitem.exit.label = Salir +flintstones.application.menu.edit.label = Editar +flintstones.application.menu.edit.handledmenuitem.undo.label = Deshacer +flintstones.application.menu.edit.handledmenuitem.redo.label = Rehacer +flintstones.application.menu.edit.handledmenuitem.preferences.label = Preferencias +flintstones.application.toolbar.file.handledtoolitem.new.label = Nuevo +flintstones.application.toolbar.file.handledtoolitem.new.tooltip = Nuevo +flintstones.application.toolbar.file.handledtoolitem.open.label = Abrir +flintstones.application.toolbar.file.handledtoolitem.open.tooltip = Abrir +flintstones.application.toolbar.file.handledtoolitem.save.label= Guardar +flintstones.application.toolbar.file.handledtoolitem.save.tooltip = Guardar +flintstones.application.toolbar.file.handledtoolitem.saveandclose.label = Guardar y salir +flintstones.application.toolbar.file.handledtoolitem.saveandclose.tooltip = Guardar y salir +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.framework.label = Framework +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.framework.tooltip = Framework +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.frameworkstructuring.label = Framework Structuring +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.frameworkstructuring.tooltip = Framework Structuring +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.gathering.label = Gathering +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.gathering.tooltip = Gathering +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.rating.label = Rating +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.rating.tooltip = Rating +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.sensitiveanalysis.label = Sensitive Analysis +flintstones.application.toolbar.perspectiveswitcher.handledtoolitem.sensitiveanalysis.tooltip = Sensitive Analysis +flintstones.application.command.perspectiveswitcher.name = Perspective switcher +flintstones.application.command.new.name = New +flintstones.application.command.open.name = Open +flintstones.application.command.save.name = Save +flintstones.application.command.saveas.name = Save as +flintstones.application.command.saveandclose.name = Save and close +flintstones.application.command.exit.name = Exit +flintstones.application.command.undo.name = Undo +flintstones.application.command.redo.name = Redo +flintstones.application.command.preferences.name = Preferences +flintstones.application.menu.locale.label=Idioma +flintstones.application.menu.locale.es.label=Espa�ol +flintstones.application.menu.locale.en.label=Ingl�s \ No newline at end of file diff --git a/bundles/flintstones.application/build.properties b/bundles/flintstones.application/build.properties new file mode 100644 index 0000000..d3cea4f --- /dev/null +++ b/bundles/flintstones.application/build.properties @@ -0,0 +1,9 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + Application.e4xmi,\ + OSGI-INF/,\ + plugin.xml,\ + build.txt,\ + version +source.. = src/ diff --git a/bundles/flintstones.application/build.txt b/bundles/flintstones.application/build.txt new file mode 100644 index 0000000..8ef7b2e --- /dev/null +++ b/bundles/flintstones.application/build.txt @@ -0,0 +1 @@ +5892025ce diff --git a/bundles/flintstones.application/css/default.css b/bundles/flintstones.application/css/default.css new file mode 100644 index 0000000..809816a --- /dev/null +++ b/bundles/flintstones.application/css/default.css @@ -0,0 +1,20 @@ +.MPartStack +{ + swt-maximize-visible: false; + swt-minimize-visible: false; +} +/* +.MPartStack > CTabItem:selected +{ + background-color: #FFFFFF; +} + +.MPartStack.active > CTabItem:selected +{ + background-color: #ffffff #2f83df 50% 100%; +} + +.MPartStack.active.noFocus > CTabItem:selected +{ + background-color: #FFFFFF; +}*/ \ No newline at end of file diff --git a/bundles/flintstones.application/plugin.xml b/bundles/flintstones.application/plugin.xml new file mode 100644 index 0000000..27e89b4 --- /dev/null +++ b/bundles/flintstones.application/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/ArrowSeparatorToolControl.java b/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/ArrowSeparatorToolControl.java new file mode 100644 index 0000000..13cdf22 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/ArrowSeparatorToolControl.java @@ -0,0 +1,16 @@ +package flintstones.applicaiton.toolcontrols; + +import javax.annotation.PostConstruct; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class ArrowSeparatorToolControl { + + @PostConstruct + public void createControls(Composite parent) { + Label l = new Label(parent,0); + l.setText(" > "); + } + +} diff --git a/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/MenuItemToolControl.java b/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/MenuItemToolControl.java new file mode 100644 index 0000000..b76e892 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/MenuItemToolControl.java @@ -0,0 +1,83 @@ +package flintstones.applicaiton.toolcontrols; + +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.menu.MToolControl; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.widgets.Composite; +import flintstones.application.handlers.PerspectiveSwitcher; +import flintstones.helper.ui.components.ActionButton; +import flintstones.model.ui.service.UiService; + +public class MenuItemToolControl { + + @Inject + MToolControl toolControl; + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + private static final String ID = "TOPIC_WINDOW_TRIMBAR"; + + String currentPerspective = ""; + + ActionButton button; + + @PostConstruct + public void createControls(Composite parent) { + + UiService.setGridLayout(parent, 5,true); + UiService.setGridDataAuto(parent); + + Map state = toolControl.getPersistedState(); + String label = state.get("position") + ". " + state.get("label"); + currentPerspective = state.get("perspective"); + + button = new ActionButton(parent,SWT.TOGGLE, 16); + UiService.setGridData(button.getButton(), 9, 9, true, true); + + button.setText(label); + button.setSelection(true); + + if(state.get("position").equals("1")) + button.setSelection(true); + else + button.setSelection(false); + + button.getButton().addMouseListener(new MouseAdapter() { + + @Override + public void mouseUp(MouseEvent e) { + ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective(currentPerspective); + broker.post(ID, currentPerspective); + } + + }); + + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribe(@UIEventTopic(ID) String perspective) { + if(perspective.equals(currentPerspective)) + button.setSelection(true); + else + button.setSelection(false); + + } + +} diff --git a/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/RankingToolControl.java b/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/RankingToolControl.java new file mode 100644 index 0000000..ae587e6 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/applicaiton/toolcontrols/RankingToolControl.java @@ -0,0 +1,82 @@ +package flintstones.applicaiton.toolcontrols; + +import javax.annotation.PostConstruct; +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.e4.ui.model.application.ui.menu.MToolControl; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.widgets.Composite; +import org.lorissecuro.ui.CustomButton; +import flintstones.application.debug.handler.ChangeProblemTypeHandler; +import flintstones.application.handlers.PerspectiveSwitcher; +import flintstones.application.model.IApplicationService; +import flintstones.model.ui.service.UiService; + +public class RankingToolControl { + + @Inject + MToolControl toolControl; + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + @Inject + IApplicationService appService; + + private static final String ID = "TOPIC_WINDOW_TRIMBAR"; + + CustomButton cb; + + @PostConstruct + public void createControls(Composite parent) { + + cb = new CustomButton(parent, 0); + + cb.setText(appService.getProblemType().toString()); + + cb.setBackground(UiService.COLOR_SECONDARY); + cb.setForeground(UiService.COLOR_SECONDARY_FG); + + cb.setBackgroundSelected(UiService.COLOR_SECONDARY); + cb.setForegroundSelected(UiService.COLOR_SECONDARY_FG); + + cb.setBackgroundHover(UiService.COLOR_SECONDARY_HOVER); + cb.setForegroundHover(UiService.COLOR_SECONDARY_FG); + + cb.setBackgroundPressed(UiService.COLOR_SECONDARY); + cb.setForegroundPressed(UiService.COLOR_SECONDARY_FG); + + + cb.setBorderWidth(0); + cb.setBorder2Width(0); + cb.setColorTransition(false); + + UiService.setFont(cb, UiService.FONT_BUTTON); + UiService.setFontSize(cb, 16); + UiService.setGridData(cb, 9, 9, true, true); + + cb.addMouseListener(new MouseAdapter() { + + @Override + public void mouseUp(MouseEvent e) { + ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective("flintstones.application.perspective.framework"); + broker.post(ID, "flintstones.application.perspective.framework"); + + ContextInjectionFactory.make(ChangeProblemTypeHandler.class, context).execute(); + cb.setText(appService.getProblemType().toString()); + + } + + }); + + } + + +} diff --git a/bundles/flintstones.application/src/flintstones/application/PerspectiveManager.java b/bundles/flintstones.application/src/flintstones/application/PerspectiveManager.java new file mode 100644 index 0000000..890c099 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/PerspectiveManager.java @@ -0,0 +1,146 @@ +package flintstones.application; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.nebula.widgets.opal.notifier.WNotifier; + +import flintstones.helper.data.HashMatrix; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +public class PerspectiveManager { + + @Inject + IDomainService domainService; + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + private HashMatrix blockedPerspectiveType = new HashMatrix<>(); + private HashMap blockedPerspectiveDomainNumber = new HashMap<>(); + private HashMatrix blockedPerspectiveProblemElementNumber = new HashMatrix<>(); + private HashMatrix blockedNotEvaluated = new HashMatrix<>(); + + public PerspectiveManager() { + } + + public void blockDomain(String perspective, String domainType) { + blockedPerspectiveType.put(getPerspectiveName(perspective), getDomainType(domainType), false); + } + + public void blockDomainNumber(String perspective, int domainNumber) { + blockedPerspectiveDomainNumber.put(getPerspectiveName(perspective), domainNumber); + } + + public void blockProblemElementNumber(String perspective, String type, int minNumber) { + blockedPerspectiveProblemElementNumber.put(getPerspectiveName(perspective), type, minNumber); + } + + public void blockNotFullyEvaluated(String perspective, String domainType) { + blockedNotEvaluated.put(getPerspectiveName(perspective), getDomainType(domainType), true); + } + + public String process(String perspective) { + + int domainNumber = domainService.getAll().length; + if (domainNumber == 0) { + if(perspective.equals("flintstones.application.perspective.framework")) { + return getPerspectiveName("framework"); + } else { + new WNotifier("No disponible", "Debes crear un dominio para continuar") + .send(); + return ""; + } + + } + + if(!requiredDomain(perspective)) + return ""; +// +// if (!requiredPE(perspective, Alternative.Type)) +// return ""; +// +// if (!requiredPE(perspective, Expert.Type)) +// return ""; +// +// if (!requiredPE(perspective, Criterion.Type)) +// return ""; + + if(perspective.equals("flintstones.application.perspective.gathering") && !valuationService.isAssignmentFilled()) { + new WNotifier("No disponible", "Debes finalizar la asignación de dominios").send(); + return ""; + } + + if(!fullyEvaluated(perspective)) + return ""; + + + return perspective; + } + + private boolean fullyEvaluated(String perspective) { + if(blockedNotEvaluated.get(getPerspectiveName(perspective), getDomainType()) != null) { + if(!valuationService.isEvaluationFilled()) { + new WNotifier("No disponible","La fase " + perspective + " no está disponible antes \n de añadir todas las evaluaciones en gathering ") + .send(); + return false; + } + } + + return true; + } + + private boolean requiredDomain(String perspective) { + + String domainType = getDomainType(); + + Boolean perspectiveAvaliable = blockedPerspectiveType.get(perspective, domainType); + if(perspectiveAvaliable == null) + return true; + + new WNotifier("No disponible","La fase " + perspective + " no está disponible para el dominio " + domainType) + .send(); + return false; + + } + + private String getDomainType() { + return domainService.getAll()[0].getType(); + } + + private String getPerspectiveName(String perspective) { + if (!perspective.contains(".")) { + perspective = "flintstones.application.perspective." + perspective; + } + return perspective; + } + + private String getDomainType(String type) { + if (!type.contains(".")) { + type = "flintstones.domain." + type; + } + return type; + } + +// private boolean requiredPE(String perspective, String type) { +// +// if (blockedPerspectiveProblemElementNumber.get(perspective, type) == null) +// return true; +// +// int number = blockedPerspectiveProblemElementNumber.get(perspective, type); +// +// if (problemService.getAll(type).length < number) { +// Notifier.notify("No disponible", "La fase " + perspective + " requiere minimo " + number + " " + type); +// return false; +// } +// +// return true; +// } + +} diff --git a/bundles/flintstones.application/src/flintstones/application/addons/LoadFileAddon.java b/bundles/flintstones.application/src/flintstones/application/addons/LoadFileAddon.java new file mode 100644 index 0000000..7dc1ffb --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/addons/LoadFileAddon.java @@ -0,0 +1,56 @@ +package flintstones.application.addons; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.helper.data.io.FlintstonesIO; +import flintstones.helper.debug.DH; + +/** + * The Class LoadFileAddon. + * + * @author UJA + */ +@SuppressWarnings("nls") +public class LoadFileAddon { + + /** The context. */ + @Inject + IEclipseContext context; + + /** + * Instantiates a new load file addon. + */ + public LoadFileAddon() { + } + + /** + * Inits the loader. + */ + @PostConstruct + public void init() { + + int pos = -1; + String[] args = Platform.getCommandLineArgs(); + for (int i = 0; i < args.length; i++) + if (args[i].equals("-loadFile")) { + pos = i; + continue; + } + + if (pos == -1) + return; + + String filePath = args[pos + 1]; + + DH.out("I/O","!INFO Cargando el fichero " + filePath + " ya que la flag -loadFile esta presente"); + FlintstonesIO fio = ContextInjectionFactory.make(FlintstonesIO.class, this.context); + fio.load(filePath); + + } + +} diff --git a/bundles/flintstones.application/src/flintstones/application/addons/LoadServicesAddon.java b/bundles/flintstones.application/src/flintstones/application/addons/LoadServicesAddon.java new file mode 100644 index 0000000..cad1241 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/addons/LoadServicesAddon.java @@ -0,0 +1,43 @@ +package flintstones.application.addons; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.application.model.IApplicationService; +import flintstones.application.model.service.ApplicationServiceProvider; + +/** + * The Class LoadServicesAddon. + */ +public class LoadServicesAddon { + + /** The context. */ + @Inject + IEclipseContext context; + + /** + * Instantiates a new load services addon. + */ + public LoadServicesAddon() { + } + + /** + * Inits the addon. + */ + @PostConstruct + private void init() { + + // Pre + MApplication application = this.context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + + // Services + IApplicationService appService = ContextInjectionFactory.make(ApplicationServiceProvider.class, this.context); + applicationContext.set(IApplicationService.class, appService); + } + +} diff --git a/bundles/flintstones.application/src/flintstones/application/addons/Pruebas.java b/bundles/flintstones.application/src/flintstones/application/addons/Pruebas.java new file mode 100644 index 0000000..51c8fb3 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/addons/Pruebas.java @@ -0,0 +1,40 @@ +package flintstones.application.addons; + +import java.util.Locale; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; + +@SuppressWarnings({ "nls", "javadoc" }) +public class Pruebas { + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + public int X = 0; + + @PostConstruct + private void init() { + } + + public Pruebas() { + + } + + public void setX(int x) { + this.X = x; + } + + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + System.out.println(s + " " + this.X); + System.out.println(this.domainMessages.Domain_entity); + } +} diff --git a/bundles/flintstones.application/src/flintstones/application/addons/RedirectErrorsAddon.java b/bundles/flintstones.application/src/flintstones/application/addons/RedirectErrorsAddon.java new file mode 100644 index 0000000..00b25c1 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/addons/RedirectErrorsAddon.java @@ -0,0 +1,64 @@ +package flintstones.application.addons; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.text.MessageFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; + +import javax.annotation.PostConstruct; + +import org.eclipse.core.runtime.Platform; + +import flintstones.helper.debug.DH; + +public class RedirectErrorsAddon { + + @PostConstruct + private void init() throws IOException { + + // https://stackoverflow.com/questions/1308755/launch-an-app-on-os-x-with-command-line + String[] args = Platform.getCommandLineArgs(); + + if (Arrays.asList(args) + .stream() + .anyMatch(flag -> flag.equals("-redirectErrors"))) { + redirectErrors(); + } + + + + } + + private void redirectErrors() throws IOException, FileNotFoundException { + String folder = System.getProperty("user.home") + File.separator + "Flintstones" + File.separator + "logs"; + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); //$NON-NLS-1$ + String dateS = dateFormat.format(date); + + String template = "log-{0}"; //$NON-NLS-1$ + String file = MessageFormat.format(template, dateS); + + String fullPath = folder + File.separator + file; + String outPath = fullPath+".out.log"; + String errPath = fullPath+".err.log"; + + File f1 = new File(outPath); + File f2 = new File(errPath); + + f1.getParentFile().mkdirs(); + f2.getParentFile().mkdirs(); + f1.createNewFile(); + f2.createNewFile(); + + System.setOut(new PrintStream(new FileOutputStream(outPath))); + System.setErr(new PrintStream(new FileOutputStream(errPath))); + DH.out("This is test output"); + } + + +} diff --git a/bundles/flintstones.application/src/flintstones/application/handlers/LocaleHandler.java b/bundles/flintstones.application/src/flintstones/application/handlers/LocaleHandler.java new file mode 100644 index 0000000..dfc0543 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/handlers/LocaleHandler.java @@ -0,0 +1,41 @@ +package flintstones.application.handlers; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; + +import flintstones.application.model.IApplicationService; +import flintstones.helper.debug.DH; + +/** + * @author UJA + * Changes the current locale + */ +public class LocaleHandler { + + @Inject + ILocaleChangeService lcs; + + @Inject + IApplicationService appService; + + /** + * @param command The command that launch the handler + */ + @Execute + @SuppressWarnings("unchecked") + public void execute(@Optional ParameterizedCommand command) { + HashMap map = (HashMap) command.getParameterMap(); + String id = map.get("flintstones.application.commandparameter.localeId"); + String locale = id.substring(id.lastIndexOf('.') + 1); // flintstones.xxxx.xxxx.xxxx.es / .en / .{locale} + DH.out("locale","Cambiando locale a " + locale); + this.lcs.changeApplicationLocale(locale); + + appService.setCurrentLocale(locale); + } +} diff --git a/bundles/flintstones.application/src/flintstones/application/handlers/PerspectiveSwitcher.java b/bundles/flintstones.application/src/flintstones/application/handlers/PerspectiveSwitcher.java new file mode 100644 index 0000000..55170b8 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/handlers/PerspectiveSwitcher.java @@ -0,0 +1,95 @@ +package flintstones.application.handlers; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.e4.ui.workbench.modeling.EPartService; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.helper.debug.DH; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +public class PerspectiveSwitcher { + + @Inject + MApplication app; + + @Inject + EPartService partService; + + @Inject + EModelService modelService; + + @Inject + MApplication application; + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + @Inject + IValuationService valuationService; + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + @Execute + public void execute(@Named("perspective_parameter") String perspectiveId) { + perspectiveId = patch(perspectiveId); + changePerspective(perspectiveId); + broker.post("TOPIC_WINDOW_TRIMBAR",perspectiveId); + + } + + private String patch(String perspectiveId) { + + return perspectiveId; +// PerspectiveManager manager = ContextInjectionFactory.make(PerspectiveManager.class, context); +// +// return manager.process(perspectiveId); +// + } + + public void changePerspective(String perspectiveId) { + + DH.out("router",perspectiveId); + List perspectives = modelService.findElements(app, perspectiveId, MPerspective.class, null); + + // switch to perspective with the ID if found + if (!perspectives.isEmpty()) + try { + partService.switchPerspective(perspectives.get(0)); + } catch(Exception e) {} + } + + /** + * Subscribe. + * + * @param event the event + */ + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_PERSPECTIVE_CHANGE) String perspectiveId ) { + if( perspectiveId != null ) + changePerspective(perspectiveId); + } + + +} diff --git a/bundles/flintstones.application/src/flintstones/application/handlers/PreferencesHandler.java b/bundles/flintstones.application/src/flintstones/application/handlers/PreferencesHandler.java new file mode 100644 index 0000000..4f2a7dc --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/handlers/PreferencesHandler.java @@ -0,0 +1,10 @@ +package flintstones.application.handlers; + +import org.eclipse.e4.core.di.annotations.Execute; + +public class PreferencesHandler { + @Execute + public void execute() { + System.out.println(""); //$NON-NLS-1$ + } +} diff --git a/bundles/flintstones.application/src/flintstones/application/handlers/SelectMethodHandler.java b/bundles/flintstones.application/src/flintstones/application/handlers/SelectMethodHandler.java new file mode 100644 index 0000000..762a3a3 --- /dev/null +++ b/bundles/flintstones.application/src/flintstones/application/handlers/SelectMethodHandler.java @@ -0,0 +1,121 @@ +package flintstones.application.handlers; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.commands.MCommand; +import org.eclipse.e4.ui.model.application.commands.MParameter; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; +import org.eclipse.e4.ui.model.application.ui.menu.MMenu; +import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; +import org.eclipse.e4.ui.workbench.modeling.EModelService; + +import flintstones.application.constants.ApplicationContants; +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.method.Method; +import flintstones.model.method.service.IMethodService; + +public class SelectMethodHandler { + + @Inject + MApplication application; + + @Inject + EModelService modelService; + + @Inject + MApplication app; + + @Inject + IMethodService methodService; + + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + MMenu menu; + + private static final String REFRESH_SUB_ID = FrameworkConstants.TOPIC_FRAMEWORK_ALLTOPICS; + + @PostConstruct + private void postConstruct() { + buildMenu(); + } + + @Execute + public void execute(@Optional ParameterizedCommand command) { + @SuppressWarnings("unchecked") + HashMap map = (HashMap) command.getParameterMap(); + String methodID = map.get(ApplicationContants.MParameter_Rating_Selectmethod); + + // 1.Change to the phase, it loads empty + ContextInjectionFactory.make(PerspectiveSwitcher.class, context).changePerspective(ApplicationContants.MPerspective_Phase); + // 2.Send the method + broker.post(FrameworkConstants.TOPIC_METHOD_LOAD, Arrays.stream(methodService.getAll()).filter(k -> k.getId().equals(methodID)).findFirst().get()); + + } + + private void buildMenu() { + + Method[] methods = methodService.getAll(); + + String commandId = ApplicationContants.MCommand_Rating_Selectmethod; + String menuId = ApplicationContants.MMenu_Rating; + String windowId = ApplicationContants.MWindow_Main; + + MWindow window = (MWindow) this.modelService.find(windowId, this.application); + MCommand command = modelService.findElements(app, commandId, MCommand.class, null).get(0); + MMenu mainMenu = window.getMainMenu(); + + menu = (MMenu) mainMenu.getChildren().stream().filter(k -> k.getElementId().equals(menuId)).findFirst().get(); + + for (Method method : methods) { + + MHandledMenuItem menuItem = modelService.createModelElement(MHandledMenuItem.class); + MParameter parameter = modelService.createModelElement(MParameter.class); + + menuItem.setLabel(method.getName()); + menuItem.setCommand(command); + + if (!method.canBeExecuted()) + menuItem.setVisible(false); + + parameter.setName(ApplicationContants.MParameter_Rating_Selectmethod); + parameter.setValue(method.getId()); + + menuItem.getParameters().add(parameter); + + menu.getChildren().add(menuItem); + + } + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribeClear(@UIEventTopic(REFRESH_SUB_ID) Map event) { + + Method[] methods = methodService.getAll(); + for (MMenuElement menuItem : menu.getChildren()) { + String label = menuItem.getLabel(); + Method method = Arrays.stream(methods).filter(k -> k.getName().equals(label)).findFirst().get(); + boolean canBeExecuted = method.canBeExecuted(); + menuItem.setVisible(canBeExecuted); + } + } +} diff --git a/bundles/flintstones.application/version b/bundles/flintstones.application/version new file mode 100644 index 0000000..b9e64dc --- /dev/null +++ b/bundles/flintstones.application/version @@ -0,0 +1,2 @@ +Version: Oxygen.3a Release (4.7.3a) +Build id: 20180405-1200 \ No newline at end of file diff --git a/bundles/flintstones.clustering.agglomerative/.classpath b/bundles/flintstones.clustering.agglomerative/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.clustering.agglomerative/.polyglot.META-INF b/bundles/flintstones.clustering.agglomerative/.polyglot.META-INF new file mode 100644 index 0000000..560927c --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.clustering.agglomerative + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Aglomerative Clustering + + Sinbad2 + + diff --git a/bundles/flintstones.clustering.agglomerative/.project b/bundles/flintstones.clustering.agglomerative/.project new file mode 100644 index 0000000..7e64552 --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/.project @@ -0,0 +1,45 @@ + + + flintstones.clustering.agglomerative + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362535 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.clustering.agglomerative/META-INF/MANIFEST.MF b/bundles/flintstones.clustering.agglomerative/META-INF/MANIFEST.MF new file mode 100644 index 0000000..33c8c2c --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Aglomerative Clustering +Bundle-SymbolicName: flintstones.clustering.agglomerative +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.clustering.aglomerative +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.clustering.agglomerative, + flintstones.clustering.agglomerative.exception, + flintstones.clustering.agglomerative.function +Require-Bundle: flintstones.entity.problemelement diff --git a/bundles/flintstones.clustering.agglomerative/build.properties b/bundles/flintstones.clustering.agglomerative/build.properties new file mode 100644 index 0000000..41eb6ad --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/AgglomerativeCluster.java b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/AgglomerativeCluster.java new file mode 100644 index 0000000..c101750 --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/AgglomerativeCluster.java @@ -0,0 +1,124 @@ +package flintstones.clustering.agglomerative; + +import java.util.Arrays; + +/** + * The Cluster class will contain a set of values and elements belonging to the cluster, along with the + * parents of that cluster (or null if none) and the distance between parents (0 if none). + */ +public class AgglomerativeCluster implements Comparable { + private double[] values; + private Object[] elements; + /** + * An array containing the parent clusters. + */ + private AgglomerativeCluster[] parents; + private double distance; + + public AgglomerativeCluster(double values, Object elements, AgglomerativeCluster[] parents, double distance) { + this.values = new double[]{values}; + this.elements = new Object[] {elements}; + this.parents = parents; + this.distance = distance; + } + + public AgglomerativeCluster(double[] values, Object[] elements, AgglomerativeCluster[] parents, double distance) { + this.values = values; + this.elements = elements; + this.parents = parents; + this.distance = distance; + } + + @Override + public String toString() { + return "Cluster{" + + "values=" + Arrays.toString(values) + + "elements=" + Arrays.toString(elements) + + //", parents=" + Arrays.toString(parents) + + //", distance=" + distance + + '}'; + } + + public double[] getValues() { + return values; + } + + public void setValues(double values[]) { + this.values = values; + } + + public Object[] getElements() { + return elements; + } + + public void setElements(Object elements[]) { + this.elements = elements; + } + + public AgglomerativeCluster[] getParents() { + return parents; + } + + public void setParents(AgglomerativeCluster[] parents) { + this.parents = parents; + } + + public double getDistance() { + return distance; + } + + public void setDistance(double distance) { + this.distance = distance; + } + + /** + * Given two clusters, merge the values into a new one. Also sets + * the new cluster parents and distance between parents. + * @param c1 the first cluster we want to merge + * @param c2 the second cluster we want to merge + * @param distance the distance between the two clusters we want to merge + * @return the new cluster + */ + public static AgglomerativeCluster mergeClusters(AgglomerativeCluster c1, AgglomerativeCluster c2, double distance) { + int length = c1.getValues().length + c2.getValues().length; + + double[] combinedArray = new double[length]; + System.arraycopy(c1.getValues(), 0, combinedArray, 0, c1.getValues().length); + System.arraycopy(c2.getValues(), 0, combinedArray, c1.getValues().length, c2.getValues().length); + + Object[] combinedElementsArray = new Object[length]; + System.arraycopy(c1.getElements(), 0, combinedElementsArray, 0, c1.getValues().length); + System.arraycopy(c2.getElements(), 0, combinedElementsArray, c1.getValues().length, c2.getValues().length); + + //Order values and elements + boolean swapped = true; + int j = 0; + double tmpValue; + Object tmpElement; + while (swapped) { + swapped = false; + j++; + for (int i = 0; i < combinedArray.length - j; i++) { + if (combinedArray[i] > combinedArray[i + 1]) { + tmpValue = combinedArray[i]; + combinedArray[i] = combinedArray[i + 1]; + combinedArray[i + 1] = tmpValue; + + tmpElement = combinedElementsArray[i]; + combinedElementsArray[i] = combinedElementsArray[i + 1]; + combinedElementsArray[i + 1] = tmpElement; + + swapped = true; + } + } + } + + return new AgglomerativeCluster(combinedArray, combinedElementsArray, new AgglomerativeCluster[]{c1, c2}, distance); + } + + @Override + public int compareTo(AgglomerativeCluster o) { + return Double.valueOf(this.values[0]).compareTo(o.getValues()[0]); + } + +} diff --git a/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/AgglomerativeClustering.java b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/AgglomerativeClustering.java new file mode 100644 index 0000000..dc5eafd --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/AgglomerativeClustering.java @@ -0,0 +1,98 @@ +package flintstones.clustering.agglomerative; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import flintstones.clustering.agglomerative.exception.InvalidClusterException; + +public class AgglomerativeClustering { + + private AgglomerativeClustering() { + throw new UnsupportedOperationException(); + } + + /** + * Perform an agglomeration given an array of doubles + * @param clusters array containing the clusters + * @param clustersAmount amount of clusters we want to end up with + * @param linkageCriterion the criteria that will be used to perform the agglomeration of two clusters + * @return a list of agglomerated clusters + * @throws InvalidClusterException if the clusters array are empty + */ + public static List process(Double[] clusters, Object[] elements, int clustersAmount, LinkageCriterion linkageCriterion) throws InvalidClusterException { + + if (clusters == null) { + throw new NullPointerException("Clusters were null"); + } + + List tempClusters = new ArrayList<>(); + int e = 0; + for (double cluster : clusters) { + tempClusters.add(new AgglomerativeCluster(cluster, elements[e], null, 0)); + e++; + } + + return process(tempClusters, clustersAmount, linkageCriterion); + } + + /** + * Perform an agglomeration given an list of Cluster + * @param agglomerativeClusters non-empty list containing Cluster objects + * @param clustersAmount amount of clusters we want to end up with + * @param linkageCriterion the criteria that will be used to perform the agglomeration of two clusters + * @return a list of agglomerated clusters + * @throws InvalidClusterException if the clusters array are empty + */ + public static List process(List agglomerativeClusters, int clustersAmount, LinkageCriterion linkageCriterion) throws InvalidClusterException { + + if (agglomerativeClusters == null) { + throw new NullPointerException("Clusters were null"); + } else if (agglomerativeClusters.isEmpty()) { + throw new InvalidClusterException("Cluster values were less than 1"); + } + + while (clustersAmount != agglomerativeClusters.size()) { + AgglomerativeCluster newCluster = agglomerate(agglomerativeClusters, linkageCriterion); + agglomerativeClusters.remove(newCluster.getParents()[0]); + agglomerativeClusters.remove(newCluster.getParents()[1]); + agglomerativeClusters.add(newCluster); + } + + Collections.sort(agglomerativeClusters); + + return agglomerativeClusters; + } + + /** + * This method will perform an agglomeration given a list of clusters + * following the specified linkage criteria. + * @param agglomerativeClusters the list of clusters + * @param linkageCriterion the linkage criterion we want to use + * @return a merged cluster + */ + private static AgglomerativeCluster agglomerate(List agglomerativeClusters, LinkageCriterion linkageCriterion) { + double distance = Double.POSITIVE_INFINITY; + + // To store the position in array of he closest pair. + int[] closestPair = new int[]{Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE}; + + for (int i = 0; i < agglomerativeClusters.size(); i++) { + for (int j = 0; j < agglomerativeClusters.size(); j++) { + // Do not calculate distance if i == j. It means they're the same item and distance will be 0. + if (j != i) { + double tempDistance = linkageCriterion.calculate(agglomerativeClusters.get(i), agglomerativeClusters.get(j)); + if (tempDistance < distance) { + distance = tempDistance; + closestPair[0] = i; + closestPair[1] = j; + } + } + } + } + + AgglomerativeCluster c1 = agglomerativeClusters.get(closestPair[0]); + AgglomerativeCluster c2 = agglomerativeClusters.get(closestPair[1]); + return AgglomerativeCluster.mergeClusters(c1, c2, distance); + } +} diff --git a/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/LinkageCriterion.java b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/LinkageCriterion.java new file mode 100644 index 0000000..e21ac99 --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/LinkageCriterion.java @@ -0,0 +1,5 @@ +package flintstones.clustering.agglomerative; + +public interface LinkageCriterion { + double calculate(AgglomerativeCluster c1, AgglomerativeCluster c2); +} \ No newline at end of file diff --git a/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/SingleLinkageCriterion.java b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/SingleLinkageCriterion.java new file mode 100644 index 0000000..db41a3c --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/SingleLinkageCriterion.java @@ -0,0 +1,33 @@ +package flintstones.clustering.agglomerative; + +import flintstones.clustering.agglomerative.function.DistanceFunction; + +public class SingleLinkageCriterion implements LinkageCriterion { + private DistanceFunction distanceFunction = null; + + public SingleLinkageCriterion(DistanceFunction distanceFunction) { + this.distanceFunction = distanceFunction; + } + + /** + * Given two clusters with 1 or more points, return the distance between the closest + * from both clusters. + * @param c1 The first cluster we are comparing + * @param c2 The second cluster we are comparing + * @return the minimum distance between two clusters + */ + @Override + public double calculate(AgglomerativeCluster c1, AgglomerativeCluster c2) { + double[] cluster1Values = c1.getValues(); + double[] cluster2Values = c2.getValues(); + double distance = Double.POSITIVE_INFINITY; + for (int i = 0; i < cluster1Values.length; i++) { + for (int j = 0; j < cluster2Values.length; j++) { + double tempDistance = distanceFunction.calculate(cluster1Values[i], cluster2Values[j]); + if (tempDistance < distance) + distance = tempDistance; + } + } + return distance; + } +} \ No newline at end of file diff --git a/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/exception/InvalidClusterException.java b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/exception/InvalidClusterException.java new file mode 100644 index 0000000..e7665d7 --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/exception/InvalidClusterException.java @@ -0,0 +1,14 @@ +package flintstones.clustering.agglomerative.exception; + +/** + * Exception to be throw if the values of the clusters are not valid. + * For example: empty cluster. + */ +public class InvalidClusterException extends Exception { + + private static final long serialVersionUID = 1L; + + public InvalidClusterException(String message) { + super(message); + } +} diff --git a/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/function/DistanceFunction.java b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/function/DistanceFunction.java new file mode 100644 index 0000000..7e7ae99 --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/function/DistanceFunction.java @@ -0,0 +1,5 @@ +package flintstones.clustering.agglomerative.function; + +public interface DistanceFunction { + double calculate(double value1, double value2); +} \ No newline at end of file diff --git a/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/function/EuclideanDistance.java b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/function/EuclideanDistance.java new file mode 100644 index 0000000..73d0001 --- /dev/null +++ b/bundles/flintstones.clustering.agglomerative/src/flintstones/clustering/agglomerative/function/EuclideanDistance.java @@ -0,0 +1,15 @@ +package flintstones.clustering.agglomerative.function; + +public class EuclideanDistance implements DistanceFunction{ + + /** + * Given two points, calculate a distance between them. + * @param value1 the first value of the Euclidean distance formula + * @param value2 the second value of the Euclidean distance formula + * @return the distance between two points + */ + @Override + public double calculate(double value1, double value2) { + return Math.sqrt(Math.pow(value1 - value2, 2)); + } +} \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/.classpath b/bundles/flintstones.domain.fuzzyset.ui.chart/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/.polyglot.META-INF b/bundles/flintstones.domain.fuzzyset.ui.chart/.polyglot.META-INF new file mode 100644 index 0000000..3b17965 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.fuzzyset.ui.chart + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Chart + diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/.project b/bundles/flintstones.domain.fuzzyset.ui.chart/.project new file mode 100644 index 0000000..ae24571 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.fuzzyset.ui.chart + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362538 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/META-INF/MANIFEST.MF b/bundles/flintstones.domain.fuzzyset.ui.chart/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9579be8 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Chart +Bundle-SymbolicName: flintstones.domain.fuzzyset.ui.chart;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.domain.fuzzyset.ui.chart +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.domain.ui.chart;visibility:=reexport, + flintstones.domain.fuzzyset, + org.eclipse.swt, + flintstones.entity.domain, + flintstones.domain.numeric.real, + javax.inject, + flintstones.entity.domain.ui, + javax.annotation, + org.jfree.chart.jfreechart +Export-Package: flintstones.domain.fuzzyset.ui.chart diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/build.properties b/bundles/flintstones.domain.fuzzyset.ui.chart/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/plugin.xml b/bundles/flintstones.domain.fuzzyset.ui.chart/plugin.xml new file mode 100644 index 0000000..e8e0e17 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/plugin.xml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/CreateManualDomainDialogChart.java b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/CreateManualDomainDialogChart.java new file mode 100644 index 0000000..83fcdef --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/CreateManualDomainDialogChart.java @@ -0,0 +1,198 @@ + +package flintstones.domain.fuzzyset.ui.chart; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.ValueMarker; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.jfree.chart.swt.ChartComposite; +import org.jfree.chart.ui.Layer; +import org.jfree.chart.ui.RectangleInsets; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.chart.DomainChart; + +@SuppressWarnings("javadoc") +public class CreateManualDomainDialogChart extends DomainChart { + + private LabelLinguisticDomain _label; + + public static final Color[] colors = { Color.RED, Color.CYAN, Color.GREEN, Color.MAGENTA, Color.LIGHT_GRAY, Color.ORANGE, Color.ORANGE, Color.MAGENTA, Color.PINK, Color.WHITE, Color.YELLOW }; + + private ValueMarker[] _alternativesMarkers; + + public CreateManualDomainDialogChart() { + this._label = null; + this._chart = null; + this._chartComposite = null; + } + + @Override + public void initialize(Domain domain, Composite container, int width, int height, int style) { + this.setDomain(domain); + this._chartComposite = new ChartComposite(container, style, this._chart, true); + this._chartComposite.setSize(width, height); + } + + @Override + public void setDomain(Domain domain) { + this._domain = domain; + this.refreshChart(); + } + + @Override + public void refreshChart() { + + if (this._chart == null) + this._chart = this.createChart(this.createDataset()); + else + this._chart.getXYPlot() + .setDataset(this.createDataset()); + + this.setBasicRenderer(this._chart.getXYPlot()); + + } + + @Override + public void setSelection(Object selection) { + } + + public void setLabel(LabelLinguisticDomain label) { + this._label = label; + this.refreshChart(); + } + + private JFreeChart createChart(XYSeriesCollection dataset) { + JFreeChart result = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, false, true, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + result.setBackgroundPaint(Color.WHITE); + XYPlot xyplot = (XYPlot) result.getPlot(); + xyplot.setBackgroundPaint(Color.WHITE); + xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); + xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); + xyplot.getDomainAxis() + .setRange(0d, 1d); + xyplot.getRangeAxis() + .setRange(0d, 1.1d); + + return result; + } + + private XYSeriesCollection createDataset() { + + XYSeriesCollection dataset = new XYSeriesCollection(); + + if (this._label != null) { + XYSeries series = new XYSeries(this._label.getName()); + IMembershipFunction membershipFunction = this._label.getSemantic(); + if (membershipFunction instanceof TrapezoidalFunction) { + TrapezoidalFunction trapezoidalFunction = (TrapezoidalFunction) membershipFunction; + series.add(trapezoidalFunction.getCoverage() + .getMin(), 0.0); + series.add(trapezoidalFunction.getCenter() + .getMin(), 1.0); + series.add(trapezoidalFunction.getCenter() + .getMax(), 1.0); + series.add(trapezoidalFunction.getCoverage() + .getMax(), 0.0); + } + dataset.addSeries(series); + } + + return dataset; + + } + + private void setBasicRenderer(XYPlot xyplot) { + xyplot = this._chart.getXYPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + + for (int i = 0; i < xyplot.getSeriesCount(); ++i) + renderer.setSeriesStroke(i, new BasicStroke(1)); + } + + @Override + public void displayRanking(Object ranking) { + + if (ranking != null) { + String[] alternatives = (String[]) ((Object[]) ranking)[0]; + int[] pos = (int[]) ((Object[]) ranking)[1]; + this.displayAlternatives(alternatives, pos, CreateManualDomainDialogChart.colors); + } + + } + + public void displayAlternatives(String[] alternatives, int[] pos, Color[] colors) { + + if (this._alternativesMarkers != null) + for (ValueMarker marker : this._alternativesMarkers) + this._chart.getXYPlot() + .removeRangeMarker(marker); + + this._alternativesMarkers = null; + + class MyItem implements Comparable { + public String alternative; + public Double pos; + public Color color; + + public MyItem(String alternative, double pos, Color color) { + this.alternative = alternative; + this.pos = pos; + this.color = color; + } + + @Override + public int compareTo(MyItem other) { + return Double.compare(this.pos, other.pos); + } + } + + List items = null; + if ((alternatives != null) && (pos != null) && (colors != null)) { + items = new LinkedList<>(); + for (int i = 0; i < pos.length; i++) + if (alternatives[i] != null) + items.add(new MyItem(alternatives[i], pos[i], colors[i])); + + Collections.sort(items); + } + + if (items != null) { + int size = items.size(); + if (size > 0) { + int height = (int) (this._chartComposite.getSize().y * 0.75f); + int offset = height / size; + this._alternativesMarkers = new ValueMarker[size]; + MyItem item; + for (int i = 0; i < size; i++) { + item = items.get(i); + this._alternativesMarkers[i] = new ValueMarker(item.pos); + this._alternativesMarkers[i].setPaint(item.color); + this._alternativesMarkers[i].setStroke(new BasicStroke(3)); + this._alternativesMarkers[i].setLabel(item.alternative); + this._alternativesMarkers[i].setLabelFont(new Font("TimesRoman", Font.BOLD, 20)); //$NON-NLS-1$ + this._alternativesMarkers[i].setLabelPaint(item.color); + this._alternativesMarkers[i].setLabelOffset(new RectangleInsets(offset + (offset * i), 15, 0, 0)); + this._chart.getXYPlot() + .addRangeMarker(0, this._alternativesMarkers[i], Layer.FOREGROUND); + } + } + } + } +} diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/LinguisticDomainChart.java b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/LinguisticDomainChart.java new file mode 100644 index 0000000..cbd6a6d --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/LinguisticDomainChart.java @@ -0,0 +1,368 @@ + +package flintstones.domain.fuzzyset.ui.chart; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.annotations.XYTextAnnotation; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.ValueMarker; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.chart.swt.ChartComposite; +import org.jfree.chart.ui.Layer; +import org.jfree.chart.ui.RectangleInsets; +import org.jfree.data.xy.XYDataItem; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.chart.DomainChart; + +@SuppressWarnings("javadoc") +public class LinguisticDomainChart extends DomainChart { + + private XYSeriesCollection _dataset; + + public static final Color[] colors = { Color.RED, Color.CYAN, Color.GREEN, Color.MAGENTA, Color.LIGHT_GRAY, Color.ORANGE, Color.ORANGE, Color.MAGENTA, + Color.PINK, Color.WHITE, Color.YELLOW }; + + private ValueMarker[] _alternativesMarkers; + + public LinguisticDomainChart() { + this._domain = null; + this._chart = null; + this._chartComposite = null; + } + + @Override + public void initialize(Domain domain, Composite container, int width, int height, int style) { + this.setDomain(domain); + this._chartComposite = new ChartComposite(container, style, this._chart, true); + this._chartComposite.setSize(width, height); + } + + public void initialize(Domain domain, Composite container, int width, int height, double initialPos, double finalPos, int style) { + this.setDomain(domain, initialPos, finalPos); + this._chartComposite = new ChartComposite(container, style, this._chart, true); + this._chartComposite.setSize(width, height); + } + + @Override + public void setDomain(Domain domain) { + this._domain = domain; + this.refreshChart(); + } + + public void setDomain(Domain domain, double initialPos, double finalPos) { + this._domain = domain; + this.refreshChart(initialPos, finalPos); + } + + @Override + public void refreshChart() { + if (this._chart == null) + this._chart = this.createChart(this.createDataset()); + else + this._chart.getXYPlot().setDataset(this.createDataset()); + + this.setBasicRenderer(this._chart.getXYPlot()); + } + + public void refreshChart(double initialPos, double finalPos) { + if (this._chart == null) + this._chart = this.createChart(this.createDataset(), initialPos, finalPos); + else + this._chart.getXYPlot().setDataset(this.createDataset()); + + this.setBasicRenderer(this._chart.getXYPlot()); + } + + @SuppressWarnings("unchecked") + @Override + public void setSelection(Object selection) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + + if (!(selection instanceof LinkedList)) { + for (int i = 0; i < xyplot.getSeriesCount(); ++i) + if (i != (Integer) selection) + renderer.setSeriesStroke(i, new BasicStroke(1)); + else + renderer.setSeriesStroke(i, new BasicStroke(3)); + } else if (((LinkedList) selection).size() > 1) { + int lower = ((LinkedList) selection).get(0); + int upper = ((LinkedList) selection).get(1); + for (int i = 0; i < xyplot.getSeriesCount(); ++i) + if ((lower <= i) && (i <= upper)) + renderer.setSeriesStroke(i, new BasicStroke(3)); + else + renderer.setSeriesStroke(i, new BasicStroke(1)); + } else if (((LinkedList) selection).size() == 1) { + int value = ((LinkedList) selection).get(0); + for (int i = 0; i < xyplot.getSeriesCount(); ++i) + if (i != value) + renderer.setSeriesStroke(i, new BasicStroke(1)); + else + renderer.setSeriesStroke(i, new BasicStroke(3)); + } + + } + + private JFreeChart createChart(XYSeriesCollection dataset) { + JFreeChart result = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + result.setBackgroundPaint(Color.WHITE); + XYPlot xyplot = (XYPlot) result.getPlot(); + xyplot.setBackgroundPaint(Color.WHITE); + xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); + xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); + xyplot.getDomainAxis().setRange(0d, 1d); + xyplot.getRangeAxis().setRange(0d, 1.1d); + this.setBasicRenderer(xyplot); + + return result; + } + + private JFreeChart createChart(XYSeriesCollection dataset, double initialPos, double finalPos) { + JFreeChart result = ChartFactory.createXYLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + result.setBackgroundPaint(Color.WHITE); + XYPlot xyplot = (XYPlot) result.getPlot(); + xyplot.setBackgroundPaint(Color.WHITE); + xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); + xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); + xyplot.getDomainAxis().setRange(initialPos, finalPos); + xyplot.getRangeAxis().setRange(0d, 1.1d); + this.setBasicRenderer(xyplot); + + return result; + } + + private XYSeriesCollection createDataset() { + + this._dataset = new XYSeriesCollection(); + + if (this._domain != null) + if (((FuzzySet) this._domain).getLabelSet().getCardinality() > 0) { + XYSeries series; + + for (LabelLinguisticDomain label : ((FuzzySet) this._domain).getLabelSet().getLabels()) { + series = new XYSeries(label.getName()); + IMembershipFunction membershipFunction = label.getSemantic(); + + if (membershipFunction instanceof TrapezoidalFunction) { + TrapezoidalFunction trapezoidalFunction = (TrapezoidalFunction) membershipFunction; + series.add(trapezoidalFunction.getCoverage().getMin(), 0.0); + series.add(trapezoidalFunction.getCenter().getMin(), 1.0); + series.add(trapezoidalFunction.getCenter().getMax(), 1.0); + series.add(trapezoidalFunction.getCoverage().getMax(), 0.0); + } + this._dataset.addSeries(series); + } + } + + return this._dataset; + + } + + private Color colorForEachLabel(int pos) { + int r, g, b; + + r = (63 * (pos + 1)) % 255; + g = (107 * (pos + 2)) % 255; + b = (217 * (pos + 3)) % 255; + + return new Color(r, g, b); + + } + + private void setBasicRenderer(XYPlot xyplot) { + XYItemRenderer renderer = xyplot.getRenderer(0); + + for (int i = 0; i < xyplot.getSeriesCount(); ++i) { + renderer.setSeriesStroke(i, new BasicStroke()); + renderer.setSeriesPaint(i, this.colorForEachLabel(i)); + } + } + + @Override + public void displayRanking(Object ranking) { + + Double[] values = null; + if (ranking != null) { + String[] alternatives = (String[]) ((Object[]) ranking)[0]; + if (((Object[]) ranking)[1] instanceof int[]) { + values = new Double[((int[]) ((Object[]) ranking)[1]).length]; + for (int i = 0; i < ((int[]) ((Object[]) ranking)[1]).length; ++i) + values[i] = (double) ((int[]) ((Object[]) ranking)[1])[i]; + } else if (((Object[]) ranking)[1] instanceof double[]) { + values = new Double[((double[]) ((Object[]) ranking)[1]).length]; + for (int i = 0; i < ((double[]) ((Object[]) ranking)[1]).length; ++i) + values[i] = (double) ((double[]) ((Object[]) ranking)[1])[i]; + } + if (((Object[]) ranking).length == 2) + this.displayAlternatives(alternatives, values, LinguisticDomainChart.colors); + else { + int[] pos = ((int[]) ((Object[]) ranking)[2]); + double[] alpha = ((double[]) ((Object[]) ranking)[3]); + this.displayAlternatives(alternatives, values, pos, alpha, LinguisticDomainChart.colors); + } + } + } + + public void displayAlternatives(String[] alternatives, Double[] pos, Color[] colors) { + + if (this._alternativesMarkers != null) + for (ValueMarker marker : this._alternativesMarkers) + this._chart.getXYPlot().removeRangeMarker(marker); + + this._alternativesMarkers = null; + + class MyItem implements Comparable { + public String alternative; + public Double pos; + public Color color; + + public MyItem(String alternative, double pos, Color color) { + this.alternative = alternative; + this.pos = pos; + this.color = color; + } + + @Override + public int compareTo(MyItem other) { + return Double.compare(this.pos, other.pos); + } + } + + List items = null; + if ((alternatives != null) && (pos != null) && (colors != null)) { + items = new LinkedList<>(); + for (int i = 0; i < pos.length; i++) + if (alternatives[i] != null) + items.add(new MyItem(alternatives[i], pos[i], colors[i])); + + Collections.sort(items); + } + + if (items != null) { + int size = items.size(); + if (size > 0) { + int height = (int) (this._chartComposite.getSize().y * 0.75f); + int offset = height / size; + this._alternativesMarkers = new ValueMarker[size]; + MyItem item; + for (int i = 0; i < size; i++) { + item = items.get(i); + this._alternativesMarkers[i] = new ValueMarker(item.pos); + this._alternativesMarkers[i].setPaint(item.color); + this._alternativesMarkers[i].setStroke(new BasicStroke(3)); + this._alternativesMarkers[i].setLabel(item.alternative); + this._alternativesMarkers[i].setLabelFont(new Font("TimesRoman", Font.BOLD, 20)); //$NON-NLS-1$ + this._alternativesMarkers[i].setLabelPaint(item.color); + this._alternativesMarkers[i].setLabelOffset(new RectangleInsets(offset * (i / offset), 25, 0, 0)); + this._chart.getXYPlot().addRangeMarker(0, this._alternativesMarkers[i], Layer.FOREGROUND); + } + } + } + } + + public void displayAlternatives(String[] alternatives, Double[] values, int[] pos, double[] alpha, Color[] colors) { + this.displayAlternatives(alternatives, values, colors); + this.displayAlternatives(alternatives, pos, alpha); + } + + @SuppressWarnings("unchecked") + public void displayAlternatives(String[] alternatives, int[] pos, double[] alpha) { + + int size = alternatives.length; + int cardinality = ((FuzzySet) this._domain).getLabelSet().getCardinality(); + XYSeries series, alternativeSeries; + double[] centers = new double[size]; + double x, y, factor; + + List dataItems; + for (int i = 0; i < size; i++) + if (alternatives[i] != null) { + series = this._dataset.getSeries(pos[i]); + alternativeSeries = new XYSeries(alternatives[i]); + + dataItems = series.getItems(); + if (alpha[i] >= 0) + factor = (dataItems.get(3).getX().doubleValue() - dataItems.get(2).getX().doubleValue()) * alpha[i]; + else + factor = (dataItems.get(1).getX().doubleValue() - dataItems.get(0).getX().doubleValue()) * alpha[i]; + XYDataItem item; + for (int itemPos = 0; itemPos < dataItems.size(); itemPos++) { + item = dataItems.get(itemPos); + x = item.getXValue(); + y = item.getYValue(); + if (itemPos == 0) { + if (x == dataItems.get(1).getX().doubleValue()) + x -= dataItems.get(3).getX().doubleValue() - dataItems.get(2).getX().doubleValue(); + } else if (itemPos == 1) + centers[i] = x + factor; + else if (itemPos == 3) + if (x == dataItems.get(2).getX().doubleValue()) + x += dataItems.get(1).getX().doubleValue() - dataItems.get(0).getX().doubleValue(); + alternativeSeries.add(x + factor, y); + + } + this._dataset.addSeries(alternativeSeries); + } + + this._chart.getXYPlot().setDataset(this._dataset); + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + XYTextAnnotation annotation; + for (int i = 0; i < xyplot.getSeriesCount(); i++) + if (i >= cardinality) { + renderer.setSeriesStroke(i, new BasicStroke(3)); + renderer.setSeriesPaint(i, this.colorForEachLabel(pos[i - cardinality])); + annotation = new XYTextAnnotation(alternatives[i - cardinality], centers[i - cardinality], 1.05); + annotation.setFont(new Font("SansSerif", Font.PLAIN, 10)); //$NON-NLS-1$ + xyplot.addAnnotation(annotation); + } else { + renderer.setSeriesStroke(i, new BasicStroke(1)); + renderer.setSeriesPaint(i, this.colorForEachLabel(i)); + } + } + + public void displayAlternatives(String[] alternatives, TrapezoidalFunction[] fuzzyNumbers) { + int size = fuzzyNumbers.length; + XYSeries alternativeSeries = null; + + for (int i = 0; i < size; i++) { + alternativeSeries = new XYSeries(alternatives[i]); + alternativeSeries.add(fuzzyNumbers[i].getLimits()[0], 0); + alternativeSeries.add(fuzzyNumbers[i].getLimits()[1], 1); + alternativeSeries.add(fuzzyNumbers[i].getLimits()[2], 1); + alternativeSeries.add(fuzzyNumbers[i].getLimits()[3], 0); + + this._dataset.addSeries(alternativeSeries); + } + + this._chart.getXYPlot().setDataset(this._dataset); + + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + for (int i = 0; i < xyplot.getSeriesCount(); i++) + if (i >= ((FuzzySet) this._domain).getLabelSet().getCardinality()) + renderer.setSeriesStroke(i, new BasicStroke(3)); + else { + renderer.setSeriesStroke(i, new BasicStroke()); + renderer.setSeriesPaint(i, this.colorForEachLabel(i)); + } + } + +} diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/PlainFuzzySetChart.java b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/PlainFuzzySetChart.java new file mode 100644 index 0000000..ee484ad --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/PlainFuzzySetChart.java @@ -0,0 +1,287 @@ +package flintstones.domain.fuzzyset.ui.chart; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.text.MessageFormat; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYItemRenderer; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; +import org.jfree.chart.swt.ChartComposite; +import org.jfree.chart.ui.RectangleInsets; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.domain.fuzzyset.ui.chart.messages.Messages; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.chart.DomainChart; + +@SuppressWarnings("javadoc") +public class PlainFuzzySetChart extends DomainChart { + + @Inject + @Translation + private Messages messages; + + private XYSeriesCollection _datasetSeries; + + private boolean _fixColor; + + private int _r; + + private int _g; + + private int _b; + + private boolean _dashed; + + public PlainFuzzySetChart() { + // No debería llamarse nunca directamente + this._domain = null; + this._chart = null; + this._chartComposite = null; + this._fixColor = false; + } + + @PostConstruct + private void init() { + this._domain = null; + this._chart = null; + this._chartComposite = null; + this._fixColor = false; + } + + @Override + public void initialize(Domain domain, Composite container, int width, int height, int style) { + this.setDomain(domain); + this._chartComposite = new ChartComposite(container, style, this._chart, true); + this._chartComposite.setSize(width, height); + } + + public void initialize(Domain domain, Composite container, int width, int height, int style, boolean dashed) { + this.setDomain(domain); + this._dashed = dashed; + this._chartComposite = new ChartComposite(container, style, this._chart, true); + this._chartComposite.setSize(width, height); + } + + public void initialize(FuzzySet domain, Composite composite, int width, int height, int style, int r, int g, int b, boolean dashed) { + this._dashed = dashed; + this._fixColor = true; + this._r = r; + this._g = g; + this._b = b; + this._domain = domain; + this._chart = this.createChart(this.createDataset()); + this._chartComposite = new ChartComposite(composite, style, this._chart, true); + this._chartComposite.setSize(width, height); + this._chartComposite.setBounds(-1, -1, width, height); + } + + private JFreeChart createChart(XYSeriesCollection xySeriesCollection) { + JFreeChart result = ChartFactory.createXYLineChart("", "", "", xySeriesCollection, PlotOrientation.VERTICAL, false, false, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + result.setBackgroundPaint(Color.white); + XYPlot xyplot = (XYPlot) result.getPlot(); + xyplot.setBackgroundPaint(Color.white); + xyplot.setDomainGridlinePaint(Color.lightGray); + xyplot.setRangeGridlinePaint(Color.lightGray); + xyplot.getDomainAxis() + .setRange(0d, 1d); + xyplot.getRangeAxis() + .setRange(0d, 1.01d); + xyplot.getDomainAxis() + .setVisible(false); + xyplot.getRangeAxis() + .setVisible(false); + xyplot.setAxisOffset(RectangleInsets.ZERO_INSETS); + xyplot.setInsets(RectangleInsets.ZERO_INSETS); + result.setPadding(RectangleInsets.ZERO_INSETS); + this.setBasicRenderer(xyplot); + return result; + } + + private XYSeriesCollection createDataset() { + + this._datasetSeries = new XYSeriesCollection(); + + if (this._domain != null) + if (((FuzzySet) this._domain).getLabelSet() + .getCardinality() > 0) { + + XYSeries series; + for (LabelLinguisticDomain label : ((FuzzySet) this._domain).getLabelSet() + .getLabels()) { + IMembershipFunction membershipFunction = label.getSemantic(); + + if (membershipFunction instanceof TrapezoidalFunction) { + TrapezoidalFunction tmf = (TrapezoidalFunction) membershipFunction; + String templateLeft = this.messages.PlainFuzzySetChart_template_left; + String text = MessageFormat.format(templateLeft, label.getName()); + series = new XYSeries(text); + series.add(tmf.getCoverage() + .getMin(), 0.0); + series.add(tmf.getCenter() + .getMin(), 1.0); + this._datasetSeries.addSeries(series); + + String templateRight = this.messages.PlainFuzzySetChart_template_right; + text = MessageFormat.format(templateRight, label.getName()); + series = new XYSeries(text); + series.add(tmf.getCenter() + .getMax(), 1.0); + series.add(tmf.getCoverage() + .getMax(), 0.0); + this._datasetSeries.addSeries(series); + } + } + } + + return this._datasetSeries; + } + + private Color getRGB(int pos) { + + if (!this._fixColor) { + this._r = (63 * ((pos / 2) + 1)) % 255; + this._g = (107 * ((pos / 2) + 2)) % 255; + this._b = (217 * ((pos / 2) + 3)) % 255; + } + + return new Color(this._r, this._g, this._b); + } + + public static Color getColor(int pos) { + + int r, g, b; + r = (63 * (pos + 1)) % 255; + g = (107 * (pos + 2)) % 255; + b = (217 * (pos + 3)) % 255; + + return new Color(r, g, b); + } + + private void setBasicRenderer(XYPlot xyplot) { + XYItemRenderer renderer = xyplot.getRenderer(0); + + BasicStroke stroke; + for (int i = 0; i < xyplot.getSeriesCount(); i++) { + if (this._dashed) + stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 20.0f }, 0.0f); + else + stroke = new BasicStroke(1); + renderer.setSeriesStroke(i, stroke); + renderer.setSeriesPaint(i, this.getRGB(i)); + } + } + + @Override + public void setDomain(Domain domain) { + this._domain = domain; + this.refreshChart(); + } + + @Override + public void refreshChart() { + if (this._chart == null) + this._chart = this.createChart(this.createDataset()); + else + this._chart.getXYPlot() + .setDataset(this.createDataset()); + this.setBasicRenderer(this._chart.getXYPlot()); + } + + + + public void setPosLeftColor(int pos, Color color) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + renderer.setSeriesPaint(pos * 2, color); + renderer.setSeriesStroke(pos * 2, new BasicStroke(1)); + } + + public void setPosRightColor(int pos, Color color) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + renderer.setSeriesPaint((pos * 2) + 1, color); + renderer.setSeriesStroke((pos * 2) + 1, new BasicStroke(1)); + } + + public void setPosColor(int pos, Color color) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + renderer.setSeriesPaint(pos * 2, color); + renderer.setSeriesPaint((pos * 2) + 1, color); + renderer.setSeriesStroke(pos * 2, new BasicStroke(1)); + renderer.setSeriesStroke((pos * 2) + 1, new BasicStroke(1)); + } + + public void selectLeft(int pos) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + renderer.setSeriesStroke(pos * 2, new BasicStroke(3)); + } + + public void selectRight(int pos) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + renderer.setSeriesStroke((pos * 2) + 1, new BasicStroke(3)); + } + + public void select(int pos) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + renderer.setSeriesStroke(pos * 2, new BasicStroke(3)); + renderer.setSeriesStroke((pos * 2) + 1, new BasicStroke(3)); + } + + public void setSelection(int lower, int upper) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + for (int i = 0; i < xyplot.getSeriesCount(); i++) + if (((lower * 2) <= i) && (i <= (upper * 2))) + renderer.setSeriesStroke(i, new BasicStroke(3)); + else + renderer.setSeriesStroke(i, new BasicStroke(1)); + } + + @SuppressWarnings("unchecked") + @Override + public void setSelection(Object selection) { + if (selection instanceof Integer) { + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + for (int i = 0; i < xyplot.getSeriesCount(); i++) + if ((i == ((Integer) selection * 2)) || (i == (((Integer) selection * 2) + 1))) + renderer.setSeriesStroke(i, new BasicStroke(3)); + else + renderer.setSeriesStroke(i, new BasicStroke(1)); + } else { + List lowerUpper = (List) selection; + XYPlot xyplot = (XYPlot) this._chart.getPlot(); + XYItemRenderer renderer = xyplot.getRenderer(0); + for (int i = 0; i < xyplot.getSeriesCount(); i++) + if (((lowerUpper.get(0) * 2) <= i) && (i <= (lowerUpper.get(1) * 2))) + renderer.setSeriesStroke(i, new BasicStroke(3)); + else + renderer.setSeriesStroke(i, new BasicStroke(1)); + } + + } + + @Override + public void displayRanking(Object ranking) { + } +} \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/Messages.java b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/Messages.java new file mode 100644 index 0000000..30f8cf6 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/Messages.java @@ -0,0 +1,36 @@ +// This file has been auto-generated +package flintstones.domain.fuzzyset.ui.chart.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String PlainFuzzySetChart_template_left; + public String PlainFuzzySetChart_template_right; + public String Domain_id; + public String Insert_label_names_with_separator_colon; + public String Preview; + public String Auto_generated_domain; + public String Empty_domain; + public String Duplicated_id; + public String Empty_value; + public String Labels; + public String Name; + public String Semantic; + public String Manually_create_domain; + public String Add; + public String Add_label; + public String Modify; + public String Modify_label; + public String Remove; + public String Remove_label; + public String Label_name; + public String Trapezoidal; + public String Values; + public String Duplicated_name; + public String Invalid_value; + public String Value_lower_than_the_previous; + +} diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/messages.properties b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/messages.properties new file mode 100644 index 0000000..2aad44a --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/messages.properties @@ -0,0 +1,25 @@ +Auto_generated_domain=Auto-generated domain +Empty_domain=Empty domain +Insert_label_names_with_separator_colon=Insert label names with separator ':' +PlainFuzzySetChart_template_left={0}_left +PlainFuzzySetChart_template_right={0}_right +Duplicated_name=Duplicated name +Invalid_value=Invalid value +Label_name=Label name +Trapezoidal=Trapezoidal +Value_lower_than_the_previous=Value lower than the previous +Values=Values +Add=Add +Add_label=Add label +Domain_id=Domain id +Duplicated_id=Duplicated id +Empty_value=Empty value +Labels=Labels +Manually_create_domain=Manually create domain +Modify=Modify +Modify_label=Modify label +Name=Name +Preview=Preview +Remove=Remove +Remove_label=Remove label +Semantic=Semantic \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/messages_es.properties b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/messages_es.properties new file mode 100644 index 0000000..b596cf7 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.chart/src/flintstones/domain/fuzzyset/ui/chart/messages/messages_es.properties @@ -0,0 +1,25 @@ +Auto_generated_domain=Dominio auto generador +Domain_id=Identificador de dominio +Duplicated_id=Id dupliacada +Empty_domain=Dominio vacio +Empty_value=Valor vaico +Insert_label_names_with_separator_colon=Inserta las etiquetas separadas por ':' +PlainFuzzySetChart_template_left={0}_left +PlainFuzzySetCharttemplate_right={0}_right +Duplicated_name=Nombre duplicado +Invalid_value=Valor no valido +Label_name=Nombre de la etiqueta +Preview=Previsualizacin +Semantic=Semantica +Trapezoidal=Trapezoidal +Value_lower_than_the_previous=Valor inferior que el previo +Values=Valores +Add=Aadir +Add_label=Aadir etiqueta +Labels=Etiquetas +Manually_create_domain=Crear dominio manualmente +Modify=Modificar +Modify_label=Modificar etiqueta +Name=Nombre +Remove=Eliminar +Remove_label=Eliminar etiqueta \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/.classpath b/bundles/flintstones.domain.fuzzyset.ui.dialog/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/.polyglot.META-INF b/bundles/flintstones.domain.fuzzyset.ui.dialog/.polyglot.META-INF new file mode 100644 index 0000000..efddb9b --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.fuzzyset.ui.dialog + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/.project b/bundles/flintstones.domain.fuzzyset.ui.dialog/.project new file mode 100644 index 0000000..7a7afbe --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.fuzzyset.ui.dialog + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362539 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/META-INF/MANIFEST.MF b/bundles/flintstones.domain.fuzzyset.ui.dialog/META-INF/MANIFEST.MF new file mode 100644 index 0000000..67e4427 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.fuzzyset.ui.dialog;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.domain.fuzzyset;visibility:=reexport, + org.eclipse.jface;visibility:=reexport, + flintstones.domain.numeric.real, + flintstones.helper.ui, + org.eclipse.wb.swt, + flintstones.entity.domain, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.entity.domain.ui.chart;visibility:=reexport, + flintstones.model.domain.ui.service, + flintstones.entity.domain.ui.dialog, + flintstones.domain.fuzzyset.ui.dialog, + flintstones.domain.fuzzyset.ui.chart, + flintstones.model.ui.service, + flintstones.model.domain.service, + org.eclipse.nebula.widgets.opal.commons, + flintstones.helper.data +Automatic-Module-Name: flintstones.domain.fuzzyset.ui diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.fuzzyset.ui.dialog/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..fff6c40 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,10 @@ +#Properties file for flintstones.domain.fuzzyset.ui +Bundle-Name = Ui +chart_ui.icon.linguistic = domain-L.png +chart_ui.icon.hesitant = domain-L.png +new_dialog.description.linguistic.manual = Create domain manually +new_dialog.description.linguistic.auto = Create auto-generated domain +new_dialog.description.hesitant.manual = Create domain manually +new_dialog.description.hesitant.auto = Create auto-generated domain +modify_dialog.description.linguistic.modifymanual = mod manual +modify_dialog.description.linguistic.modifyauto = mod auto \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.fuzzyset.ui.dialog/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..6e206b2 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,10 @@ +#Properties file for flintstones.domain.fuzzyset.ui +Bundle-Name = Ui +chart_ui.icon.linguistic = domain-L.png +chart_ui.icon.hesitant = domain-L.png +new_dialog.description.linguistic.manual = Crear dominio manualmente +new_dialog.description.linguistic.auto = Crear dominio autogenerado +new_dialog.description.hesitant.manual = Crear dominio manualmente +new_dialog.description.hesitant.auto = Crear dominio autogenerado +modify_dialog.description.linguistic.modifymanual = mod manual +modify_dialog.description.linguistic.modifyauto = mod auto \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/build.properties b/bundles/flintstones.domain.fuzzyset.ui.dialog/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/plugin.xml b/bundles/flintstones.domain.fuzzyset.ui.dialog/plugin.xml new file mode 100644 index 0000000..204ff5c --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/plugin.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/AutoGenerateLinguisticDomainDialog.java b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/AutoGenerateLinguisticDomainDialog.java new file mode 100644 index 0000000..48986a3 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/AutoGenerateLinguisticDomainDialog.java @@ -0,0 +1,199 @@ + +package flintstones.domain.fuzzyset.ui.dialog; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +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 flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart; +import flintstones.domain.fuzzyset.ui.messages.Messages; +import flintstones.entity.domain.ui.dialog.DomainDialog; +import flintstones.helper.ui.components.WCollector; +import flintstones.helper.ui.components.WLabel; +import flintstones.helper.ui.components.listeners.WEvent; +import flintstones.helper.ui.components.listeners.WItemBeforeOperation; +import flintstones.helper.ui.components.listeners.WItemChanged; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.ui.service.UiService; + +@SuppressWarnings("javadoc") +public class AutoGenerateLinguisticDomainDialog extends DomainDialog implements WItemChanged, WItemBeforeOperation { + + private static final String NUMBER_LABELS = "labels"; + + private Composite base; + private Composite chartRow; + + private LinguisticDomainChart domainChart; + + // NEW + WCollector collector; + + // ERROR + private final HashMap errorLabels = new HashMap<>(); + + @Inject + @Translation + private Messages messages; + + @Inject + IDomainUIService uiDomainService; + + public AutoGenerateLinguisticDomainDialog() { + super(); + } + + protected void beforeUI() { + + // LOCAL + FuzzySet domain = (FuzzySet) getMyDomain(); + domain.setName(domain.getName() == null ? "" : domain.getName()); //$NON-NLS-1$ + + // CHART + this.domainChart = (LinguisticDomainChart) this.uiDomainService.createChart(domain.getType()); + this.domainChart.initialize(domain, this.chartRow, 470, 150, SWT.BORDER); + this.redraw(); + } + + private FuzzySet getMyDomain() { + return (FuzzySet) getDomain(); + } + + private void addErrorLabel(Composite base, String asociatedItemId) { + Composite subBase = new Composite(base, SWT.NONE); + UiService.setGridLayout(subBase, 1); + UiService.setGridDataAuto(subBase); + WLabel nameLabelError = new WLabel(subBase, SWT.NONE); + UiService.setGridData(nameLabelError, -1, 0, true, false); + UiService.setFont(nameLabelError, UiService.FONT_TEXT_ERROR); + this.errorLabels.put(asociatedItemId, nameLabelError); + } + + @Override + protected Control createDialogArea(Composite base) { + super.createDialogArea(base); + + for (Control c : base.getChildren()) + c.dispose(); +// + UiService.setGridLayout(base, 1); + UiService.setGridData(base, 9, 9, true, true); + + this.drawBlock1DomainName(base); + this.drawBlock2CollectorLabels(base); + this.drawBlock3Chart(base); + + return this.base; + } + + private void drawBlock1DomainName(Composite base) { + this.addNameField(base); + } + + + private void drawBlock2CollectorLabels(Composite base) { + // TITLE BLOCK 2 + Composite row2 = new Composite(base, SWT.NONE); + UiService.setGridData(row2, 9, -1, true, false); + UiService.setGridLayout(row2, 2); + + Label collectorTitle = new Label(row2, 0); + collectorTitle.setText(messages.Labels_name); + UiService.setGridData(collectorTitle, -1, 0, false, false); + UiService.setFont(collectorTitle, UiService.FONT_SECTION_TITLE); + + // ERROR BLOCK 1: name + this.addErrorLabel(row2, AutoGenerateLinguisticDomainDialog.NUMBER_LABELS); + + collector = new WCollector(base); + collector.setBeforeOperationListener(this); + collector.setChangeListener(this); + } + + private void drawBlock3Chart(Composite base) { + + // LABEL + Composite row1 = new Composite(base, SWT.NONE); + UiService.setGridLayout(row1, 1); + UiService.setGridData(row1, 9, 9, true, true); + + Label nameLabel = new Label(row1, SWT.NONE); + nameLabel.setText(this.messages.Preview); + UiService.setGridData(nameLabel, -1, 0, true, false); + UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE); + + // CHART + this.chartRow = new Composite(row1, SWT.NONE); + UiService.setGridData(this.chartRow, 9, 9, true, true); + UiService.setGridLayout(this.chartRow, 1); + } + + private void redraw() { + // ROW 3 + FuzzySet domain = getMyDomain(); + this.domainChart.setDomain(domain); + + boolean ok = checkLabelsName(); + setSaveEnabled(ok); + + + } + + private boolean checkLabelsName() { + boolean checkLabelsAreValid = true; + + String[] labels = collector.getData(); + if(labels.length < FuzzySet.MINIMUM_NUMBER_LABELS) { + String msg = MessageFormat.format(messages.Labels_empty, FuzzySet.MINIMUM_NUMBER_LABELS); + errorLabels.get(AutoGenerateLinguisticDomainDialog.NUMBER_LABELS).setText(msg); + checkLabelsAreValid = false; + } + + if(checkLabelsAreValid) + errorLabels.get(AutoGenerateLinguisticDomainDialog.NUMBER_LABELS).clear(); + + return checkLabelsAreValid; + } + + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + String[] labels = collector.getData(); + + if (operationType.equals(WEvent.ADD)) + return !Arrays.asList(labels).contains(before); + + return true; + } + + @Override + protected Point getInitialSize() { + return new Point(510, 700); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(this.messages.Auto_generated_domain); + } + + @Override + public void onWidgetChange() { + FuzzySet domain = getMyDomain(); + String[] labels = collector.getData(); + domain.createTrapezoidalFunction(labels); + domainChart.setDomain(domain); + checkLabelsName(); + redraw(); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/ManualLinguisticDomainDialog.java b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/ManualLinguisticDomainDialog.java new file mode 100644 index 0000000..5e08380 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/ManualLinguisticDomainDialog.java @@ -0,0 +1,519 @@ + +package flintstones.domain.fuzzyset.ui.dialog; + +import java.util.ArrayList; +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.jface.viewers.ISelectionChangedListener; +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.nebula.widgets.opal.commons.SWTGraphicUtil; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +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.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Text; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart; +import flintstones.domain.fuzzyset.ui.dialog.provider.FuzzyNameColumnLabelProvider; +import flintstones.domain.fuzzyset.ui.dialog.provider.FuzzySemanticColumnLabelProvider; +import flintstones.domain.fuzzyset.ui.dialog.provider.FuzzyTableContentProvider; +import flintstones.domain.fuzzyset.ui.messages.Messages; +import flintstones.entity.domain.ui.dialog.DomainDialog; +import flintstones.helper.DoubleHelper; +import flintstones.helper.ui.components.ValidatedField; +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.model.domain.ui.service.IDomainUIService; +import flintstones.model.ui.service.UiService; + +@SuppressWarnings("javadoc") +public class ManualLinguisticDomainDialog extends DomainDialog implements WItemChanged, WItemBeforeOperation { + + private int selectionIndex = -1; + private boolean isCreating; // If not creating then modify. + + // STATIC/PARENT + private Composite container; + private Composite chartRow; + private Composite collectorComposite; + boolean isCollectorEnabled = true; + + private LabelLinguisticDomain label = new LabelLinguisticDomain(); + + private TableViewer tableViewer; + + private LinguisticDomainChart domainChart; + + private Button addButton; + private Button modifyButton; + private Button removeButton; + private Button deselectButton; + + // NEW + WCollector collector; + ValidatedField tagField; + + @Inject + @Translation + private Messages messages; + + @Inject + IDomainUIService uiDomainService; + + @Inject + IEclipseContext context; + + public ManualLinguisticDomainDialog() { + super(); + } + + private FuzzySet getMyDomain() { + return (FuzzySet) getDomain(); + } + + protected void beforeUI() { + + // LOCAL + FuzzySet domain = getMyDomain(); + domain.setName(domain.getName() == null ? "" : domain.getName()); //$NON-NLS-1$ + this.tableViewer.setInput(domain); + + // CHART + this.domainChart = (LinguisticDomainChart) this.uiDomainService.createChart(domain.getType()); + this.domainChart.initialize(domain, this.chartRow, 600, 150, SWT.BORDER); + this.redraw(); + + } + + @Override + protected Control createDialogArea(Composite parent) { + + this.container = (Composite) super.createDialogArea(parent); + + this.drawBlock1DomainName(); + this.drawBlock2CollectorLabels(); + this.drawBlock3Chart(); + + return this.container; + } + + private void drawBlock1DomainName() { + this.addNameField(container); + } + + private boolean checkLabelName() { + + // 1. label name should not be not empty + if (this.label.getName().equals("")) { //$NON-NLS-1$ + tagField.setError(messages.Empty_value); + return false; + } + + // 2. label name should be new except if we are modifying a created label + if (getMyDomain().getLabelSet().getLabel(this.label.getName()) != null) { + if(this.selectionIndex != -1) { // label selected + + if(getMyDomain().getLabelSet().getPos(this.label.getName()) != this.selectionIndex) { // name repeated with other label + tagField.setError(messages.Duplicated_name); + return false; + } + + } else { + tagField.setError(messages.Duplicated_name); + return false; + } + } + + // 3. No problems in label + tagField.setError(""); + + return true; + } + + private boolean checkNumLabels() { + return getMyDomain().getLabelSet().getCardinality() >= 3; + } + + private void drawBlock2CollectorLabels() { + + UiService.setMargin(container, 0); + + tagField = new ValidatedField(container, messages.Labels, ""); + tagField.getInput().addModifyListener(this.nameLabelsInputOnChange()); + + Composite tableViewerComposite = new Composite(this.container, SWT.NONE); + UiService.setGridLayout(tableViewerComposite, 2); + UiService.setGridData(tableViewerComposite, 9, 9, true, false); + + createCollectorLabels(tableViewerComposite); + createTableViewer(tableViewerComposite); + + Composite globalButtonsComposite = new Composite(container, SWT.NONE); + UiService.setGridLayout(globalButtonsComposite, 2); + UiService.setGridData(globalButtonsComposite, 9, 9, true, false); + + createButtons(globalButtonsComposite); + } + + private ModifyListener nameLabelsInputOnChange() { + return e -> { + String name = ((Text) e.getSource()).getText().trim(); + label.setName(name); + + redraw(); + }; + } + + private void createButtons(Composite globalButtonsComposite) { + Composite buttonsComposite = new Composite(globalButtonsComposite, SWT.NONE); + UiService.setGridLayout(buttonsComposite, 3); + UiService.setGridData(buttonsComposite, 9, 9, true, false); + + addButton = new Button(buttonsComposite, SWT.NONE); + addButton.setText(this.messages.Add); + addButton.setImage(UiService.getIcon(UiService.IMAGE_CONTROLS_ADD).createImage()); + addButton.setEnabled(false); + addButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + addTag(); + } + }); + + modifyButton = new Button(buttonsComposite, SWT.NONE); + modifyButton.setText(messages.Modify); + modifyButton.setImage(UiService.getIcon(UiService.IMAGE_CONTROLS_EDIT).createImage()); + modifyButton.setEnabled(false); + modifyButton.addSelectionListener(modifySelectionListener()); + + removeButton = new Button(buttonsComposite, SWT.NONE); + removeButton.setText(messages.Remove); + removeButton.setImage(UiService.getIcon(UiService.IMAGE_CONTROLS_REMOVE).createImage()); + removeButton.setEnabled(false); + removeButton.addSelectionListener(removeSelectionListener()); + + Composite deselectButtonComposite = new Composite(globalButtonsComposite, SWT.NONE); + UiService.setGridLayout(deselectButtonComposite, 1); + UiService.setGridData(deselectButtonComposite, 9, 9, true, false); + + deselectButton = new Button(deselectButtonComposite, SWT.NONE); + deselectButton.setText(messages.Deselect); + deselectButton.setImage(UiService.getIcon(UiService.IMAGE_CONTROLS_DESELECT).createImage()); + deselectButton.setEnabled(false); + UiService.setGridData(deselectButton, 1, 0, true, false); + deselectButton.addSelectionListener(deselectSelectionListener()); + } + + private void createTableViewer(Composite tableViewerComposite) { + this.tableViewer = new TableViewer(tableViewerComposite, SWT.BORDER | SWT.FULL_SELECTION); + this.tableViewer.setContentProvider(new FuzzyTableContentProvider()); + + Table table = this.tableViewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + GridData gd_table = UiService.setGridData(table, -1, 1, false, false); + gd_table.heightHint = 160; + this.tableViewer.setInput(getMyDomain()); + + TableViewerColumn tableViewerNameCol = new TableViewerColumn(this.tableViewer, SWT.NONE); + tableViewerNameCol.getColumn().setWidth(140); + tableViewerNameCol.getColumn().setText(this.messages.Name); + tableViewerNameCol.setLabelProvider(new FuzzyNameColumnLabelProvider()); + + TableViewerColumn tableViewerSemanticCol = new TableViewerColumn(this.tableViewer, SWT.NONE); + tableViewerSemanticCol.getColumn().setWidth(140); + tableViewerSemanticCol.getColumn().setText(this.messages.Semantic); + tableViewerSemanticCol.setLabelProvider(new FuzzySemanticColumnLabelProvider()); + + this.tableViewer.addSelectionChangedListener(tableSelectionListener()); + } + + private ISelectionChangedListener tableSelectionListener() { + return new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + + int posSelectedLabel = tableViewer.getTable().getSelectionIndex(); + + if(selectionIndex != posSelectedLabel && posSelectedLabel != -1) + loadLabelInfo(posSelectedLabel); + + addButton.setEnabled(checkAddButton()); + modifyButton.setEnabled(checkModifyButton()); + removeButton.setEnabled(checkRemoveButton()); + deselectButton.setEnabled(true); + } + }; + } + + private void loadLabelInfo(int posSelectedLabel) { + LabelLinguisticDomain selectedLabel = getMyDomain().getLabelSet().getLabel(posSelectedLabel); + + TrapezoidalFunction semantic = (TrapezoidalFunction) selectedLabel.getSemantic(); + ArrayList values = new ArrayList(Arrays.asList( + Double.toString(semantic.getA()), + Double.toString(semantic.getB()), + Double.toString(semantic.getC()), + Double.toString(semantic.getD()))); + + collector.setValues(values); + + selectionIndex = posSelectedLabel; + + tagField.setText(selectedLabel.getName()); + } + + private void createCollectorLabels(Composite tableViewerComposite) { + + collectorComposite = new Composite(tableViewerComposite, 0); + UiService.setGridLayout(collectorComposite, 1); + UiService.setGridDataAuto(collectorComposite); + UiService.setMargin(collectorComposite, 0); + + collector = new WCollector(collectorComposite); + collector.setBeforeOperationListener(this); + collector.setChangeListener(this); + collector.setOperationListener(new WItemOperation() { + + @Override + public String getModifiedValue(WEvent operationType, String before, String after) { + + if (operationType.equals(WEvent.ADD)) { + return DoubleHelper.NormalizeZeroToOne(before) + ""; //$NON-NLS-1$ + } + return after; + + } + }); + } + + private void addTag() { + setSemanticToLabel(label); + getMyDomain().addLabel(label); + domainChart.refreshChart(); + tableViewer.setInput(getMyDomain()); + + addButton.setEnabled(false); + + clearLabelInfo(); + } + + private void clearLabelInfo() { + collector.clear(); + label = new LabelLinguisticDomain(); + tagField.setText(""); + + addButton.setEnabled(false); + removeButton.setEnabled(false); + modifyButton.setEnabled(false); + deselectButton.setEnabled(false); + } + + private void setSemanticToLabel(LabelLinguisticDomain selectedLabel) { + String[] labels = collector.getData(); + TrapezoidalFunction semantic = new TrapezoidalFunction(Double.parseDouble(labels[0]), + Double.parseDouble(labels[1]), Double.parseDouble(labels[2]), Double.parseDouble(labels[3])); + selectedLabel.setSemantic(semantic); + } + + private SelectionListener modifySelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + LabelLinguisticDomain selectedLabel = getMyDomain().getLabelSet().getLabel(selectionIndex); + selectedLabel.setName(tagField.getText()); + setSemanticToLabel(selectedLabel); + + getMyDomain().getLabelSet().removeLabel(selectedLabel); + getMyDomain().getLabelSet().addLabel(selectedLabel); + + domainChart.refreshChart(); + tableViewer.setInput(getMyDomain()); + + redraw(); + } + }; + } + + private SelectionListener removeSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + getMyDomain().removeLabel(ManualLinguisticDomainDialog.this.selectionIndex); + domainChart.refreshChart(); + tableViewer.setInput(getMyDomain()); + selectionIndex = -1; + + clearLabelInfo(); + } + }; + } + + private SelectionListener deselectSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + tableViewer.setSelection(StructuredSelection.EMPTY); + tableViewer.getTable().deselectAll(); + selectionIndex = -1; + + clearLabelInfo(); + } + }; + } + + private void drawBlock3Chart() { + + // LABEL + Composite row1 = new Composite(container, SWT.NONE); + UiService.setGridLayout(row1, 1); + UiService.setGridData(row1, 9, 9, true, true); + + Label nameLabel = new Label(row1, SWT.NONE); + nameLabel.setText(this.messages.Preview); + UiService.setGridData(nameLabel, -1, 0, true, false); + UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE); + + // CHART + this.chartRow = new Composite(row1, SWT.NONE); + UiService.setGridData(this.chartRow, 9, 9, true, true); + UiService.setGridLayout(this.chartRow, 1); + } + + @Override + protected Point getInitialSize() { + return new Point(670, 720); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + String title = this.isCreating ? this.messages.Manually_create_domain : this.messages.Manually_create_domain; + + newShell.setText(title); + } + + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + + if (operationType.equals(WEvent.ADD)) { + String[] labels = collector.getData(); + + if (labels.length == 4) { + return false; + } + + try { + Double num = Double.parseDouble(before); + if (num < 0.0) + return false; + } catch (NumberFormatException e) { + return false; + } + } + + return true; + } + + @Override + public void onWidgetChange() { + ArrayList semanticPoints = orderSemanticPoints(); + collector.setValues(semanticPoints); + addButton.setEnabled(checkAddButton()); + } + + private void redraw() { + + // ROW 2 + String labelName = this.label.getName(); + tagField.setText(labelName); + + if (tagField.getText().equals("")) { + if (isCollectorEnabled) { + SWTGraphicUtil.disableAllChildrenWidgets(collectorComposite); + isCollectorEnabled = false; + } + } else { + if (!isCollectorEnabled) { + SWTGraphicUtil.enableAllChildrenWidgets(collectorComposite); + isCollectorEnabled = true; + } + } + + // ROW 3 + this.domainChart.setDomain(getMyDomain()); + boolean ok = checkNumLabels(); + setSaveEnabled(ok); + } + + private ArrayList orderSemanticPoints() { + Double[] orderedSemanticPoints = parseSemanticPoints(); + Arrays.sort(orderedSemanticPoints); + + ArrayList semanticPoints = new ArrayList<>(); + for (Double point : orderedSemanticPoints) + semanticPoints.add(Double.toString(point)); + + return semanticPoints; + } + + private Double[] parseSemanticPoints() { + String[] semanticStringPoints = collector.getData(); + Double[] semanticDoublePoints = new Double[semanticStringPoints.length]; + + int cont = 0; + for (String point : semanticStringPoints) { + semanticDoublePoints[cont] = Double.parseDouble(point); + cont++; + } + + return semanticDoublePoints; + } + + private boolean checkAddButton() { + String[] labels = collector.getData(); + + boolean checkLabelName = checkLabelName(); + boolean checkNumLabels = labels.length != 4 ? false : true; + + + return checkLabelName && checkNumLabels && selectionIndex == -1; + } + + private boolean checkModifyButton() { + if(this.selectionIndex != -1) { + int pos = getMyDomain().getLabelSet().getPos(this.label.getName()); + if(pos == this.selectionIndex || pos == -1)// name repeated with the selected label or name not repeated + return true; + } + + return false; + } + + private boolean checkRemoveButton() { + return (selectionIndex != -1) ? true : false; + } + +} diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzyNameColumnLabelProvider.java b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzyNameColumnLabelProvider.java new file mode 100644 index 0000000..d8cef76 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzyNameColumnLabelProvider.java @@ -0,0 +1,16 @@ +package flintstones.domain.fuzzyset.ui.dialog.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; + +@SuppressWarnings("javadoc") +public class FuzzyNameColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + LabelLinguisticDomain label = (LabelLinguisticDomain) element; + return label.getName(); + } + +} diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzySemanticColumnLabelProvider.java b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzySemanticColumnLabelProvider.java new file mode 100644 index 0000000..7f3a55b --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzySemanticColumnLabelProvider.java @@ -0,0 +1,16 @@ +package flintstones.domain.fuzzyset.ui.dialog.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; + +@SuppressWarnings("javadoc") +public class FuzzySemanticColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + LabelLinguisticDomain label = (LabelLinguisticDomain) element; + return label.getSemantic().toString(); + } + +} diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzyTableContentProvider.java b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzyTableContentProvider.java new file mode 100644 index 0000000..d3c00d4 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/dialog/provider/FuzzyTableContentProvider.java @@ -0,0 +1,26 @@ +package flintstones.domain.fuzzyset.ui.dialog.provider; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import flintstones.domain.fuzzyset.FuzzySet; + +@SuppressWarnings("javadoc") +public class FuzzyTableContentProvider implements IStructuredContentProvider { + + @Override + public void dispose() { + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + @Override + public Object[] getElements(Object inputElement) { + return ((FuzzySet) inputElement).getLabelSet() + .getLabels() + .toArray(); + } + +} diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/Messages.java b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/Messages.java new file mode 100644 index 0000000..80f7f1c --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/Messages.java @@ -0,0 +1,39 @@ +// This file has been auto-generated +package flintstones.domain.fuzzyset.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String PlainFuzzySetChart_template_left; + public String PlainFuzzySetChart_template_right; + public String Domain_name; + public String Insert_label_names_with_separator_colon; + public String Preview; + public String Auto_generated_domain; + public String Empty_domain; + public String Duplicated_id; + public String Empty_value; + public String Labels; + public String Name; + public String Semantic; + public String Manually_create_domain; + public String Add; + public String Add_label; + public String Modify; + public String Modify_label; + public String Remove; + public String Remove_label; + public String Label_name; + public String Labels_name; + public String Labels_empty; + public String Trapezoidal; + public String Values; + public String Duplicated_name; + public String Invalid_value; + public String Value_lower_than_the_previous; + public String Deselect; + +} diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/messages.properties b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/messages.properties new file mode 100644 index 0000000..310f2c6 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/messages.properties @@ -0,0 +1,28 @@ +Auto_generated_domain=Auto-generated domain +Empty_domain=Empty domain +Insert_label_names_with_separator_colon=Insert label names with separator ':' +PlainFuzzySetChart_template_left={0}_left +PlainFuzzySetChart_template_right={0}_right +Duplicated_name=Duplicated name +Invalid_value=Invalid value +Label_name=Label name +Labels_name=Labels name +Trapezoidal=Trapezoidal +Value_lower_than_the_previous=Value lower than the previous +Labels_empty=Introduce at least {0} labels +Values=Values +Add=Add +Add_label=Add label +Domain_name=Domain name +Duplicated_id=Duplicated name +Empty_value=Empty value +Labels=Labels +Manually_create_domain= Create domain manually +Modify=Modify +Modify_label=Modify label +Name=Name +Preview=Preview +Remove=Remove +Remove_label=Remove label +Semantic=Semantic +Deselect=Deselect \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/messages_es.properties b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/messages_es.properties new file mode 100644 index 0000000..db0494f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.ui.dialog/src/flintstones/domain/fuzzyset/ui/messages/messages_es.properties @@ -0,0 +1,28 @@ +Auto_generated_domain=Dominio auto generado +Domain_name=Nombre de dominio +Duplicated_id=Id duplicado +Empty_domain=Dominio vacio +Empty_value=Valor vacio +Insert_label_names_with_separator_colon=Inserta las etiquetas separadas por ':' +PlainFuzzySetChart_template_left={0}_left +PlainFuzzySetCharttemplate_right={0}_right +Duplicated_name=Nombre duplicado +Invalid_value=Valor no valido +Label_name=Nombre de la etiqueta +Labels_name=Nombre de las etiquetas +Preview=Previsualizacin +Semantic=Semantica +Trapezoidal=Trapezoidal +Value_lower_than_the_previous=Valor inferior que el previo +Labels_empty=Introduce al menos {0} etiquetas +Values=Valores +Add=Aadir +Add_label=Aadir etiqueta +Labels=Etiquetas +Manually_create_domain=Crear dominio manualmente +Modify=Modificar +Modify_label=Modificar etiqueta +Name=Nombre +Remove=Eliminar +Remove_label=Eliminar etiqueta +Deselect=Deseleccionar \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.classpath b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.polyglot.META-INF b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.polyglot.META-INF new file mode 100644 index 0000000..69c3e69 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.fuzzyset.unbalanced.ui.chart + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Chart + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.project b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.project new file mode 100644 index 0000000..9f4116f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.fuzzyset.unbalanced.ui.chart + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362542 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/META-INF/MANIFEST.MF b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4861af4 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Chart +Bundle-SymbolicName: flintstones.domain.fuzzyset.unbalanced.ui.chart +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.domain.fuzzyset.unbalanced.ui.chart +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.domain.fuzzyset.ui.chart, + org.eclipse.swt, + flintstones.domain.fuzzyset.unbalanced, + flintstones.model.domain.ui.service, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.entity.domain, + flintstones.domain.numeric.real, + org.jfree.chart.jfreechart +Export-Package: flintstones.domain.fuzzyset.unbalanced.ui.chart diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/build.properties b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/src/flintstones/domain/fuzzyset/unbalanced/ui/chart/LHChart.java b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/src/flintstones/domain/fuzzyset/unbalanced/ui/chart/LHChart.java new file mode 100644 index 0000000..7319e20 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.chart/src/flintstones/domain/fuzzyset/unbalanced/ui/chart/LHChart.java @@ -0,0 +1,262 @@ +package flintstones.domain.fuzzyset.unbalanced.ui.chart; + +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.ui.chart.PlainFuzzySetChart; +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.model.domain.ui.service.IDomainUIService; + +@SuppressWarnings("javadoc") +public class LHChart { + + public PlainFuzzySetChart[] _charts; + + private int[] _lh; + + private Composite _composite; + + private Unbalanced _domain; + + @Inject + IDomainUIService uiDomainService; + + @Inject + IEclipseContext context; + + /* + private LHChart() { + this._charts = null; + this._domain = null; + } + */ + + public LHChart() { + this._charts = null; + this._domain = null; + } + + public void initLHChart(int[] lh, Composite composite, int width, int height) { +// this(); + + this._lh = lh; + this._charts = new PlainFuzzySetChart[this._lh.length]; + + this._composite = composite; + for (Control control : this._composite.getChildren()) + control.dispose(); + RowLayout layout = new RowLayout(SWT.VERTICAL); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginBottom = 0; + layout.marginTop = 0; + layout.marginRight = 0; + layout.marginLeft = 0; + layout.spacing = 0; + this._composite.setLayout(layout); + Composite auxComposite; + int sumHeight = 0; + int auxHeight = (height / this._lh.length) + 1; + for (int i = 0; i < this._lh.length; i++) { + sumHeight += auxHeight; + while (sumHeight > height) { + sumHeight--; + auxHeight--; + } + auxComposite = new Composite(composite, SWT.NONE); + + PlainFuzzySetChart chart = ContextInjectionFactory.make(PlainFuzzySetChart.class, this.context); +// PlainFuzzySetChart chart = new PlainFuzzySetChart(); + chart.initialize(this.createDomain(this._lh[i]), auxComposite, width, auxHeight, SWT.NONE, 0, 0, 125, false); + this._charts[i] = chart; + } + + } + + public void initLHChart(int[] lh, Composite composite, int width, int height, Unbalanced domain) { +// this(); + + this._lh = lh; + int size = this._lh.length; + this._charts = new PlainFuzzySetChart[size + 1]; + this._domain = domain; + + this._composite = composite; + for (Control control : this._composite.getChildren()) + control.dispose(); + RowLayout layout = new RowLayout(SWT.VERTICAL); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginBottom = 0; + layout.marginTop = 0; + layout.marginRight = 0; + layout.marginLeft = 0; + layout.spacing = 0; + this._composite.setLayout(layout); + Composite auxComposite; + + int sumHeight = 0; + int auxHeight = (height / (size + 1)) + 1; + + for (int i = 0; i < size; i++) { + sumHeight += auxHeight; + auxComposite = new Composite(composite, SWT.NONE); + + PlainFuzzySetChart chart = ContextInjectionFactory.make(PlainFuzzySetChart.class, context); + chart.initialize(this.createDomain(this._lh[i]), auxComposite, width, auxHeight, SWT.NONE, 0, 0, 125, true); + this._charts[i] = chart; + } + + sumHeight += auxHeight; + while (sumHeight > height) { + sumHeight--; + auxHeight--; + } + auxComposite = new Composite(composite, SWT.NONE); + PlainFuzzySetChart chart = ContextInjectionFactory.make(PlainFuzzySetChart.class, context); + chart.initialize(domain, auxComposite, width, auxHeight, SWT.NONE, false); + this._charts[size] = chart; + + this.clearCharts(); + } + + private void clearCharts() { + + for (PlainFuzzySetChart chart : this._charts) + chart.refreshChart(); + + boolean find; + int j; + NumericRealDomain center; + NumericRealDomain coverage; + double left; + double right; + int other; + int otherPos; + Map> labels = this._domain.getLabels(); + for (Integer pos : labels.keySet()) { + Map values = labels.get(pos); + other = -1; + otherPos = -1; + for (Integer lhDomain : values.keySet()) { + find = false; + j = 0; + do + if (this._lh[j] == lhDomain) + find = true; + else + j++; + while (!find); + + if (values.size() == 1) + this._charts[j].setPosColor(values.get(lhDomain), PlainFuzzySetChart.getColor(pos)); + else if (other != -1) { + center = ((FuzzySet) this._domain).getLabelSet() + .getLabel(pos) + .getSemantic() + .getCenter(); + coverage = ((FuzzySet) this._domain).getLabelSet() + .getLabel(pos) + .getSemantic() + .getCoverage(); + + left = center.getMin() - coverage.getMin(); + right = coverage.getMax() - center.getMax(); + + if (((left > right) && (other < lhDomain)) || ((left < right) && (other > lhDomain))) { + this._charts[otherPos].setPosLeftColor(values.get(other), PlainFuzzySetChart.getColor(pos)); + this._charts[j].setPosRightColor(values.get(lhDomain), PlainFuzzySetChart.getColor(pos)); + } else { + this._charts[j].setPosLeftColor(values.get(lhDomain), PlainFuzzySetChart.getColor(pos)); + this._charts[otherPos].setPosRightColor(values.get(other), PlainFuzzySetChart.getColor(pos)); + } + } + + if (other == -1) { + other = lhDomain; + otherPos = j; + } + } + } + } + + private Unbalanced createDomain(int cardinality) { + Unbalanced domain = ContextInjectionFactory.make(Unbalanced.class, this.context); + String[] labels = new String[cardinality]; + for (int i = 0; i < cardinality; i++) + labels[i] = Integer.toString(i); + + domain.createTrapezoidalFunction(labels); + + return domain; + } + + public void dispose() { + if (this._charts != null) + for (PlainFuzzySetChart chart : this._charts) + chart.getChartComposite() + .dispose(); + } + + public void select(int pos) { + this.clearCharts(); + this._charts[this._lh.length].select(pos); + + Map values = this._domain.getLabels() + .get(pos); + int other = -1; + int otherPos = -1; + boolean find; + int j; + NumericRealDomain center; + NumericRealDomain coverage; + for (Integer lhDomain : values.keySet()) { + find = false; + j = 0; + do + if (this._lh[j] == lhDomain) + find = true; + else + j++; + while (!find); + + if (values.size() == 1) + this._charts[j].select(values.get(lhDomain)); + else if (other != -1) { + center = ((FuzzySet) this._domain).getLabelSet() + .getLabel(pos) + .getSemantic() + .getCenter(); + coverage = ((FuzzySet) this._domain).getLabelSet() + .getLabel(pos) + .getSemantic() + .getCoverage(); + + double left = center.getMin() - coverage.getMin(); + double right = coverage.getMax() - center.getMax(); + + if (((left > right) && (other < lhDomain)) || ((left < right) && (other > lhDomain))) { + this._charts[otherPos].selectLeft(values.get(other)); + this._charts[j].selectRight(values.get(lhDomain)); + } else { + this._charts[j].selectLeft(values.get(lhDomain)); + this._charts[otherPos].selectRight(values.get(other)); + } + } + + if (other == -1) { + other = lhDomain; + otherPos = j; + } + } + } +} diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.classpath b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.polyglot.META-INF b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.polyglot.META-INF new file mode 100644 index 0000000..751e55e --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.fuzzyset.unbalanced.ui.dialog + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.project b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.project new file mode 100644 index 0000000..f9574e8 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.fuzzyset.unbalanced.ui.dialog + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362543 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/META-INF/MANIFEST.MF b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/META-INF/MANIFEST.MF new file mode 100644 index 0000000..69071e3 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.fuzzyset.unbalanced.ui.dialog;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.domain.fuzzyset.unbalanced, + flintstones.domain.fuzzyset.ui.dialog, + flintstones.domain.numeric.real, + org.eclipse.wb.swt, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.entity.domain, + flintstones.entity.domain.ui.chart, + flintstones.entity.domain.ui.dialog, + flintstones.model.domain.ui.service, + flintstones.domain.fuzzyset.ui.chart, + flintstones.model.ui.service, + flintstones.helper.ui, + flintstones.model.domain.service +Automatic-Module-Name: flintstones.domain.fuzzyset.unbalanced.ui diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..abf09af --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,5 @@ +#Properties file for flintstones.domain.fuzzyset.unbalanced.ui +Bundle-Name = Ui +chart_ui.icon = domain-L.png +new_dialog.description = [RELLENAR INFO FUZZYSET] +modify_dialog.description = [UNUSED] \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..abf09af --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,5 @@ +#Properties file for flintstones.domain.fuzzyset.unbalanced.ui +Bundle-Name = Ui +chart_ui.icon = domain-L.png +new_dialog.description = [RELLENAR INFO FUZZYSET] +modify_dialog.description = [UNUSED] \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/build.properties b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/plugin.xml b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/plugin.xml new file mode 100644 index 0000000..d48adcb --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/plugin.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/dialog/LHModifyDomainDialog.java b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/dialog/LHModifyDomainDialog.java new file mode 100644 index 0000000..0318dcd --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/dialog/LHModifyDomainDialog.java @@ -0,0 +1,518 @@ + +package flintstones.domain.fuzzyset.unbalanced.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.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +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.widgets.Button; +import org.eclipse.swt.widgets.Combo; +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.Spinner; +import org.eclipse.wb.swt.SWTResourceManager; + +import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart; +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.domain.fuzzyset.unbalanced.ui.dialog.subdialog.SemanticDialog; +import flintstones.domain.fuzzyset.unbalanced.ui.messages.Messages; +import flintstones.entity.domain.ui.dialog.DomainDialog; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.ui.service.UiService; + +@SuppressWarnings("javadoc") +public class LHModifyDomainDialog extends DomainDialog { + + private Composite container; + private Composite chartRow; + + private String[] labels = new String[] { "s0", "s1", "s2" }; + + // STATIC/PARENT + private LinguisticDomainChart domainChart; + + private Spinner numberOfLabelsSpinner; + private Spinner slSpinner; + private Spinner srSpinner; + + private int cardinality; + private int sl; + private int sr; + private int minimumLabels; + private int maximumLabels; + + private ModifyListener _numberOfLabelsModifyListener; + private ModifyListener _slModifyListener; + private ModifyListener _srModifyListener; + private ModifyListener _slDensityComboModifyListener; + private ModifyListener _srDensityComboModifyListener; + private ModifyListener _lhInitialDomainModifyListener; + + private Combo srDensityCombo; + private Combo slDensityCombo; + private Combo lhInitialDomainCombo; + + private Button setSemanticButton; + + @Inject + @Translation + private Messages messages; + + @Inject + IDomainUIService uiDomainService; + + @Inject + IEclipseContext context; + + public LHModifyDomainDialog() { + super(); + } + + protected void beforeUI() { + Unbalanced domain = (Unbalanced) getMyDomain(); + this.labels = domain.getLabelSet().getLabelsName().toArray(new String[0]); + + // CHART + this.domainChart = (LinguisticDomainChart) this.uiDomainService.createChart(domain.getType()); + this.domainChart.initialize(getMyDomain(), this.chartRow, 600, 185, SWT.BORDER); + + this.redraw(); + } + + private Unbalanced getMyDomain() { + return (Unbalanced) getDomain(); + } + + private void modifyDomain() { + int initialDomain = 0; + if (this.lhInitialDomainCombo.getSelectionIndex() == 0) + initialDomain = 3; + else + initialDomain = 7; + + this.labels = new String[this.cardinality]; + + for (int i = 0; i < this.cardinality; i++) + this.labels[i] = "s" + i; //$NON-NLS-1$ + + (getMyDomain()).createUnbalancedDomain(this.labels, this.sr, this.sl, + this.slDensityCombo.getSelectionIndex(), this.srDensityCombo.getSelectionIndex(), initialDomain); + this.domainChart.setDomain(getMyDomain()); + } + + + @Override + public Control createDialogArea(Composite parent) { + + this.container = (Composite) super.createDialogArea(parent); + + this.drawBlock1DomainName(); + this.drawBlock2LH(); + this.drawBlock3Labels(); + this.drawBlock4Chart(); + + this.hookSelection(); + this.hookModifyListeners(); + + return this.container; + + } + + private void drawBlock1DomainName() { + this.addNameField(container); + } + + + private void redraw() { + + // ROW 3 + this.domainChart.setDomain(getMyDomain()); + + setSaveEnabled(true); + } + + private void drawBlock2LH() { + Label lhFeaturesLabel = new Label(this.container, SWT.NONE); + UiService.setFont(lhFeaturesLabel, UiService.FONT_SECTION_TITLE); + lhFeaturesLabel.setText(this.messages.LH_features); + GridData gridData = UiService.setGridData(lhFeaturesLabel, -1, 0, false, false); + gridData.verticalIndent = 10; + + Composite genericDomainComposite = new Composite(this.container, SWT.BORDER); + UiService.setGridLayout(genericDomainComposite, 2, false); + UiService.setGridData(genericDomainComposite, 9, 9, true, false); + + Label lhInitialGranularityLabel = new Label(genericDomainComposite, SWT.NULL); + lhInitialGranularityLabel.setFont(SWTResourceManager.getFont("Cantarell", 8, SWT.NONE)); //$NON-NLS-1$ + lhInitialGranularityLabel.setText(this.messages.Initial_granularity_of_LH); + lhInitialGranularityLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + + this.lhInitialDomainCombo = new Combo(genericDomainComposite, SWT.BORDER | SWT.READ_ONLY); + gridData = UiService.setGridData(lhInitialDomainCombo, 9, 9, false, false); + gridData.widthHint = 15; + this.lhInitialDomainCombo.setItems(new String[] { "3", "7" }); //$NON-NLS-1$ //$NON-NLS-2$ + this.lhInitialDomainCombo.select(0); + this.minimumLabels = 3; + this.maximumLabels = 17; + } + + private void drawBlock3Labels() { + Label domainLabelsLabel = new Label(this.container, SWT.NONE); + GridData gridData = UiService.setGridData(domainLabelsLabel, -1, 0, false, false); + gridData.verticalIndent = 15; + UiService.setFont(domainLabelsLabel, UiService.FONT_SECTION_TITLE); + domainLabelsLabel.setText(this.messages.Labels_of_unbalanced_scale); + + Composite labelsInfoComposite = new Composite(this.container, SWT.BORDER); + UiService.setGridLayout(labelsInfoComposite, 1); + UiService.setGridData(labelsInfoComposite, 9, 9, true, false); + + Composite numberOfLabelsComposite = new Composite(labelsInfoComposite, SWT.NONE); + UiService.setGridLayout(numberOfLabelsComposite, 2); + UiService.setGridData(numberOfLabelsComposite, 0, 0, true, false); + + Label numberOfLabelsLabel = new Label(numberOfLabelsComposite, SWT.NULL); + numberOfLabelsLabel.setFont(SWTResourceManager.getFont("Cantarell", 8, SWT.NONE)); //$NON-NLS-1$ + numberOfLabelsLabel.setText(this.messages.Number_of_labels_of_unbalanced_scale); + UiService.setGridData(numberOfLabelsLabel, 0, 0, false, false); + + this.cardinality = getMyDomain().getLabelSet().getCardinality(); + + this.numberOfLabelsSpinner = new Spinner(numberOfLabelsComposite, SWT.BORDER); + gridData = UiService.setGridData(numberOfLabelsSpinner, 0, 0, false, false); + gridData.widthHint = 15; + this.numberOfLabelsSpinner.setMinimum(this.minimumLabels); + this.numberOfLabelsSpinner.setMaximum(this.maximumLabels); + this.numberOfLabelsSpinner.setIncrement(2); + this.numberOfLabelsSpinner.setSelection(this.cardinality); + + Composite labelsComposite = new Composite(labelsInfoComposite, SWT.NONE); + UiService.setGridLayout(labelsComposite, 4, true); + UiService.setGridData(labelsComposite, 0, 0, true, false); + + Label slLabel = new Label(labelsComposite, SWT.NULL); + slLabel.setFont(SWTResourceManager.getFont("Cantarell", 8, SWT.NONE)); //$NON-NLS-1$ + slLabel.setText(this.messages.Left_side_SL); + UiService.setGridData(slLabel, 1, 0, false, false); + + this.sl = (getMyDomain()).getSl(); + this.slSpinner = new Spinner(labelsComposite, SWT.BORDER); + gridData = UiService.setGridData(slSpinner, -1, 0, false, false); + gridData.widthHint = 15; + + Label slDensity = new Label(labelsComposite, SWT.NULL); + slDensity.setFont(SWTResourceManager.getFont("Cantarell", 8, SWT.NONE)); //$NON-NLS-1$ + slDensity.setText(this.messages.Density_SL); + UiService.setGridData(slDensity, 1, 0, true, false); + + this.slDensityCombo = new Combo(labelsComposite, SWT.BORDER | SWT.READ_ONLY); + gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); + gridData.widthHint = 70; + this.slDensityCombo.setLayoutData(gridData); + this.slDensityCombo.setItems(new String[] { this.messages.LHDomainDialog_Extreme, this.messages.LHDomainDialog_Center }); + this.slDensityCombo.setEnabled(false); + + Label srLabel = new Label(labelsComposite, SWT.NULL); + srLabel.setFont(SWTResourceManager.getFont("Cantarell", 8, SWT.NONE)); //$NON-NLS-1$ + srLabel.setText(this.messages.Right_side_SR); + srLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + + this.sr = (getMyDomain()).getSr(); + this.srSpinner = new Spinner(labelsComposite, SWT.BORDER); + gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gridData.widthHint = 15; + this.srSpinner.setLayoutData(gridData); + + Label srDensity = new Label(labelsComposite, SWT.NULL); + srDensity.setFont(SWTResourceManager.getFont("Cantarell", 8, SWT.NONE)); //$NON-NLS-1$ + srDensity.setText(this.messages.Density_SR); + srDensity.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); + + this.srDensityCombo = new Combo(labelsComposite, SWT.BORDER | SWT.READ_ONLY); + gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gridData.widthHint = 70; + this.srDensityCombo.setLayoutData(gridData); + this.srDensityCombo.setItems(new String[] { this.messages.LHDomainDialog_Extreme, this.messages.LHDomainDialog_Center }); + this.srDensityCombo.setEnabled(false); + } + + private void hookSelection() { + this.slSpinner.setSelection(this.sl); + this.slDensityCombo.select(((getMyDomain()).getSlDensity())); + this.srSpinner.setSelection(this.sr); + this.srDensityCombo.select(((getMyDomain()).getSrDensity())); + } + + private void drawBlock4Chart() { + Composite row1 = new Composite(container, SWT.NONE); + UiService.setGridLayout(row1, 1); + UiService.setGridData(row1, 9, 9, true, true); + + // LABEL + Label nameLabel = new Label(row1, SWT.NONE); + nameLabel.setText(this.messages.Preview); + UiService.setGridData(nameLabel, -1, 0, true, false); + UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE); + + // CHART + this.chartRow = new Composite(row1, SWT.NONE); + UiService.setGridLayout(this.chartRow, 1); + UiService.setGridData(this.chartRow, 9, 9, true, true); + + this.setSemanticButton = new Button(row1, SWT.NONE); + GridData gridData = new GridData(SWT.RIGHT, SWT.FILL, false, false); + this.setSemanticButton.setLayoutData(gridData); + this.setSemanticButton.setText(this.messages.Set_semantic); + + this.hookSemanticButtonListener(); + } + + private void hookSemanticButtonListener() { + this.setSemanticButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + SemanticDialog dialog = ContextInjectionFactory.make(SemanticDialog.class, LHModifyDomainDialog.this.context); + dialog.setValues(LHModifyDomainDialog.this.labels); + if (dialog.open() == Window.OK) { + List auxLabels = dialog.getValues(); + for (int i = 0; i < auxLabels.size(); i++) + LHModifyDomainDialog.this.labels[i] = auxLabels.get(i); + + LHModifyDomainDialog.this.modifyDomain(); + } + + } + }); + } + + private void hookModifyListeners() { + + this._lhInitialDomainModifyListener = e -> { + + boolean modify = false; + if (LHModifyDomainDialog.this.lhInitialDomainCombo.getSelectionIndex() == 1) { + if (LHModifyDomainDialog.this.minimumLabels == 3) { + modify = true; + LHModifyDomainDialog.this.sl = 3; + LHModifyDomainDialog.this.sr = 3; + LHModifyDomainDialog.this.minimumLabels = 7; + LHModifyDomainDialog.this.maximumLabels = 25; + LHModifyDomainDialog.this.cardinality = LHModifyDomainDialog.this.minimumLabels; + } + } else if (LHModifyDomainDialog.this.minimumLabels == 7) { + modify = true; + LHModifyDomainDialog.this.sl = 1; + LHModifyDomainDialog.this.sr = 1; + LHModifyDomainDialog.this.minimumLabels = 3; + LHModifyDomainDialog.this.maximumLabels = 17; + LHModifyDomainDialog.this.cardinality = LHModifyDomainDialog.this.minimumLabels; + } + + if (modify) { + LHModifyDomainDialog.this.numberOfLabelsSpinner + .removeModifyListener(LHModifyDomainDialog.this._numberOfLabelsModifyListener); + LHModifyDomainDialog.this.slSpinner.removeModifyListener(LHModifyDomainDialog.this._slModifyListener); + LHModifyDomainDialog.this.srSpinner.removeModifyListener(LHModifyDomainDialog.this._srModifyListener); + LHModifyDomainDialog.this.slDensityCombo + .removeModifyListener(LHModifyDomainDialog.this._slDensityComboModifyListener); + LHModifyDomainDialog.this.srDensityCombo + .removeModifyListener(LHModifyDomainDialog.this._srDensityComboModifyListener); + + LHModifyDomainDialog.this.numberOfLabelsSpinner.setValues(LHModifyDomainDialog.this.cardinality, + LHModifyDomainDialog.this.minimumLabels, LHModifyDomainDialog.this.maximumLabels, 0, 2, 2); + LHModifyDomainDialog.this.slSpinner.setValues(LHModifyDomainDialog.this.sl, LHModifyDomainDialog.this.sl, + LHModifyDomainDialog.this.sl, 0, 1, 1); + LHModifyDomainDialog.this.srSpinner.setValues(LHModifyDomainDialog.this.sr, LHModifyDomainDialog.this.sr, + LHModifyDomainDialog.this.sr, 0, 1, 1); + LHModifyDomainDialog.this.slDensityCombo.setEnabled(false); + LHModifyDomainDialog.this.slDensityCombo.select(0); + LHModifyDomainDialog.this.srDensityCombo.setEnabled(false); + LHModifyDomainDialog.this.srDensityCombo.select(0); + + LHModifyDomainDialog.this.numberOfLabelsSpinner + .addModifyListener(LHModifyDomainDialog.this._numberOfLabelsModifyListener); + LHModifyDomainDialog.this.slSpinner.addModifyListener(LHModifyDomainDialog.this._slModifyListener); + LHModifyDomainDialog.this.srSpinner.addModifyListener(LHModifyDomainDialog.this._srModifyListener); + LHModifyDomainDialog.this.slDensityCombo.addModifyListener(LHModifyDomainDialog.this._slDensityComboModifyListener); + LHModifyDomainDialog.this.srDensityCombo.addModifyListener(LHModifyDomainDialog.this._srDensityComboModifyListener); + + LHModifyDomainDialog.this.modifyDomain(); + } + + }; + + this._numberOfLabelsModifyListener = e -> { + int cardinality = LHModifyDomainDialog.this.numberOfLabelsSpinner.getSelection(); + if (cardinality < LHModifyDomainDialog.this.minimumLabels) + LHModifyDomainDialog.this.numberOfLabelsSpinner.setSelection(LHModifyDomainDialog.this.minimumLabels); + if (cardinality > LHModifyDomainDialog.this.maximumLabels) + LHModifyDomainDialog.this.numberOfLabelsSpinner.setSelection(LHModifyDomainDialog.this.maximumLabels); + if ((cardinality % 2) == 0) { + if (cardinality > LHModifyDomainDialog.this.cardinality) + cardinality++; + else + cardinality--; + LHModifyDomainDialog.this.numberOfLabelsSpinner.setSelection(cardinality); + } else { + int difference; + LHModifyDomainDialog.this.srSpinner.removeModifyListener(LHModifyDomainDialog.this._srModifyListener); + LHModifyDomainDialog.this.slSpinner.removeModifyListener(LHModifyDomainDialog.this._slModifyListener); + int maximum = cardinality - ((LHModifyDomainDialog.this.minimumLabels - 1) / 2) - 1; + if (maximum > ((LHModifyDomainDialog.this.maximumLabels - 1) / 2)) + maximum = ((LHModifyDomainDialog.this.maximumLabels - 1) / 2); + int minimum = cardinality - ((LHModifyDomainDialog.this.maximumLabels - 1) / 2) - 1; + if (minimum < ((LHModifyDomainDialog.this.minimumLabels - 1) / 2)) + minimum = ((LHModifyDomainDialog.this.minimumLabels - 1) / 2); + LHModifyDomainDialog.this.slSpinner.setMinimum(minimum); + LHModifyDomainDialog.this.srSpinner.setMinimum(minimum); + LHModifyDomainDialog.this.slSpinner.setMaximum(maximum); + LHModifyDomainDialog.this.srSpinner.setMaximum(maximum); + if (cardinality > LHModifyDomainDialog.this.cardinality) { + difference = cardinality - LHModifyDomainDialog.this.cardinality; + if (LHModifyDomainDialog.this.sl == ((LHModifyDomainDialog.this.maximumLabels - 1) / 2)) { + LHModifyDomainDialog.this.sr += difference; + LHModifyDomainDialog.this.srSpinner.setSelection(LHModifyDomainDialog.this.sr); + } else if (LHModifyDomainDialog.this.sr == ((LHModifyDomainDialog.this.maximumLabels - 1) / 2)) { + LHModifyDomainDialog.this.sl += difference; + LHModifyDomainDialog.this.slSpinner.setSelection(LHModifyDomainDialog.this.sl); + } else { + difference /= 2; + LHModifyDomainDialog.this.sl += difference; + LHModifyDomainDialog.this.sr += difference; + LHModifyDomainDialog.this.slSpinner.setSelection(LHModifyDomainDialog.this.sl); + LHModifyDomainDialog.this.srSpinner.setSelection(LHModifyDomainDialog.this.sr); + } + + } else if (cardinality < LHModifyDomainDialog.this.cardinality) { + difference = LHModifyDomainDialog.this.cardinality - cardinality; + if (LHModifyDomainDialog.this.sl == ((LHModifyDomainDialog.this.minimumLabels - 1) / 2)) { + LHModifyDomainDialog.this.sr -= difference; + LHModifyDomainDialog.this.srSpinner.setSelection(LHModifyDomainDialog.this.sr); + } else if (LHModifyDomainDialog.this.sr == ((LHModifyDomainDialog.this.minimumLabels - 1) / 2)) { + LHModifyDomainDialog.this.sl -= difference; + LHModifyDomainDialog.this.slSpinner.setSelection(LHModifyDomainDialog.this.sl); + } else { + difference /= 2; + LHModifyDomainDialog.this.sl -= difference; + LHModifyDomainDialog.this.sr -= difference; + LHModifyDomainDialog.this.slSpinner.setSelection(LHModifyDomainDialog.this.sl); + LHModifyDomainDialog.this.srSpinner.setSelection(LHModifyDomainDialog.this.sr); + } + } + + LHModifyDomainDialog.this.cardinality = cardinality; + + LHModifyDomainDialog.this.modifyDensityCombos(); + LHModifyDomainDialog.this.srSpinner.addModifyListener(LHModifyDomainDialog.this._srModifyListener); + LHModifyDomainDialog.this.slSpinner.addModifyListener(LHModifyDomainDialog.this._slModifyListener); + + LHModifyDomainDialog.this.modifyDomain(); + } + }; + + this._slModifyListener = e -> { + int sl = LHModifyDomainDialog.this.slSpinner.getSelection(); + + LHModifyDomainDialog.this.srSpinner.removeModifyListener(LHModifyDomainDialog.this._srModifyListener); + if (sl > LHModifyDomainDialog.this.sl) { + LHModifyDomainDialog.this.sr--; + LHModifyDomainDialog.this.srSpinner.setSelection(LHModifyDomainDialog.this.sr); + } else { + LHModifyDomainDialog.this.sr++; + LHModifyDomainDialog.this.srSpinner.setSelection(LHModifyDomainDialog.this.sr); + } + LHModifyDomainDialog.this.sl = sl; + + LHModifyDomainDialog.this.modifyDensityCombos(); + LHModifyDomainDialog.this.srSpinner.addModifyListener(LHModifyDomainDialog.this._srModifyListener); + + LHModifyDomainDialog.this.modifyDomain(); + }; + + this._srModifyListener = e -> { + int sr = LHModifyDomainDialog.this.srSpinner.getSelection(); + + LHModifyDomainDialog.this.slSpinner.removeModifyListener(LHModifyDomainDialog.this._slModifyListener); + if (sr > LHModifyDomainDialog.this.sr) { + LHModifyDomainDialog.this.sl--; + LHModifyDomainDialog.this.slSpinner.setSelection(LHModifyDomainDialog.this.sl); + } else { + LHModifyDomainDialog.this.sl++; + LHModifyDomainDialog.this.slSpinner.setSelection(LHModifyDomainDialog.this.sl); + } + LHModifyDomainDialog.this.sr = sr; + + LHModifyDomainDialog.this.modifyDensityCombos(); + LHModifyDomainDialog.this.slSpinner.addModifyListener(LHModifyDomainDialog.this._slModifyListener); + + LHModifyDomainDialog.this.modifyDomain(); + }; + + this._slDensityComboModifyListener = e -> LHModifyDomainDialog.this.modifyDomain(); + this._srDensityComboModifyListener = e -> LHModifyDomainDialog.this.modifyDomain(); + + this.lhInitialDomainCombo.addModifyListener(this._lhInitialDomainModifyListener); + this.numberOfLabelsSpinner.addModifyListener(this._numberOfLabelsModifyListener); + + this.slSpinner.addModifyListener(this._slModifyListener); + this.srSpinner.addModifyListener(this._srModifyListener); + + this.slDensityCombo.addModifyListener(this._slDensityComboModifyListener); + this.srDensityCombo.addModifyListener(this._srDensityComboModifyListener); + } + + private void modifyDensityCombos() { + + this.slDensityCombo.removeModifyListener(this._slDensityComboModifyListener); + this.srDensityCombo.removeModifyListener(this._srDensityComboModifyListener); + + if (!this.direct(this.sl)) { + if (!this.slDensityCombo.isEnabled()) + this.slDensityCombo.setEnabled(true); + } else if (this.slDensityCombo.isEnabled()) + this.slDensityCombo.setEnabled(false); + + if (!this.direct(this.sr)) { + if (!this.srDensityCombo.isEnabled()) + this.srDensityCombo.setEnabled(true); + } else if (this.srDensityCombo.isEnabled()) + this.srDensityCombo.setEnabled(false); + + this.slDensityCombo.addModifyListener(this._slDensityComboModifyListener); + this.srDensityCombo.addModifyListener(this._srDensityComboModifyListener); + } + + private boolean direct(int value) { + + int minimum = (this.minimumLabels - 1) / 2; + + while (value > minimum) + minimum *= 2; + + return (value == minimum); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(this.messages.Modify_unbalanced_domain); + } + + @Override + protected Point getInitialSize() { + return new Point(650, 750); + } +} \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/dialog/subdialog/SemanticDialog.java b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/dialog/subdialog/SemanticDialog.java new file mode 100644 index 0000000..738c91a --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/dialog/subdialog/SemanticDialog.java @@ -0,0 +1,236 @@ +package flintstones.domain.fuzzyset.unbalanced.ui.dialog.subdialog; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.jface.dialogs.Dialog; +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.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.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.wb.swt.SWTResourceManager; + +import flintstones.domain.fuzzyset.unbalanced.ui.messages.Messages; + +@SuppressWarnings("javadoc") +public class SemanticDialog extends Dialog { + + @Inject + @Translation + private Messages messages; + + private List _values; + private List _textValues; + private List _controlDecorations; + private Button _okButton; + + public SemanticDialog() { + super(Display.getCurrent().getActiveShell()); + } + + public List getValues() { + return this._values; + } + + @Override + protected Control createDialogArea(Composite parent) { + + Composite container = (Composite) super.createDialogArea(parent); + GridLayout gridLayout = (GridLayout) container.getLayout(); + gridLayout.verticalSpacing = 15; + gridLayout.numColumns = 1; + + Label titleLabel = new Label(container, SWT.CENTER); + 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(this.messages.Semantic_for_domain); + + ScrolledComposite scrolledComposite = new ScrolledComposite(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.CENTER); + 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.CENTER); + labelsComposite.setLayout(gridLayout); + + Label fieldLabel; + GridData gridData; + this._textValues = new LinkedList<>(); + this._controlDecorations = new LinkedList<>(); + Text value; + ControlDecoration controlDecoration; + + for (int i = 0; i < this._values.size(); i++) { + fieldLabel = new Label(labelsComposite, SWT.CENTER); + fieldLabel.setFont(SWTResourceManager.getFont("Cantarell", 9, SWT.BOLD)); //$NON-NLS-1$ + String labelTemplate = this.messages.SemanticDialog_labelTemplate; + String text = MessageFormat.format(labelTemplate, i + 1) + .toString(); + fieldLabel.setText(text); + + value = new Text(labelsComposite, SWT.BORDER); + gridData = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1); + gridData.widthHint = 105; + value.setLayoutData(gridData); + value.setText(this._values.get(i)); + this._textValues.add(value); + + controlDecoration = this.createNotificationDecorator(value); + this._controlDecorations.add(controlDecoration); + } + + scrolledComposite.setContent(labelsComposite); + scrolledComposite.setExpandVertical(true); + scrolledComposite.setExpandHorizontal(true); + scrolledComposite.setMinSize(labelsComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + scrolledComposite.setSize(200, 300); + + this.hookValuesModifyListener(); + this.validateFields(); + + return container; + + } + + private void hookValuesModifyListener() { + ModifyListener modifyListener = e -> { + Text semanticText = (Text) e.getSource(), text; + String semanticValueText = semanticText.getText(); + + for (int i = 0; i < SemanticDialog.this._textValues.size(); ++i) { + text = SemanticDialog.this._textValues.get(i); + if (semanticText == text) + SemanticDialog.this._values.set(i, semanticValueText); + } + + SemanticDialog.this.validateFields(); + }; + + for (Text text : this._textValues) + text.addModifyListener(modifyListener); + + } + + + // Este metodo debe morir + protected boolean validateBase(ControlDecoration controlDecoration, String text) { + controlDecoration.setDescriptionText(text); + if (text.isEmpty()) { + controlDecoration.hide(); + return true; + } + controlDecoration.show(); + return false; + } + + private boolean validateEmptyText(Text text, ControlDecoration controlDecoration) { + + if (text.getText() + .isEmpty()) + return this.validateBase(controlDecoration, this.messages.Empty_value); + return this.validateBase(controlDecoration, ""); //$NON-NLS-1$ + } + + private boolean validateInvalidText(Text text, ControlDecoration controlDecoration) { + String textValue = text.getText(); + + if (textValue.contains(":")) + return this.validateBase(controlDecoration, this.messages.Illegal_value); + return this.validateBase(controlDecoration, ""); //$NON-NLS-1$ + } + + private boolean validateDuplicateText(Text text, int index, ControlDecoration controlDecoration) { + String textValue = text.getText(); + + for (int i = 0; i < this._textValues.size(); ++i) + if (i != index) + if (textValue.equals(this._textValues.get(i) + .getText())) + return this.validateBase(controlDecoration, this.messages.Duplicated_value); + + return this.validateBase(controlDecoration, ""); //$NON-NLS-1$ + } + + private void validateFields() { + Boolean values[] = new Boolean[this._values.size()]; + Text text; + ControlDecoration controlDecoration; + + for (int i = 0; i < this._textValues.size(); ++i) { + text = this._textValues.get(i); + controlDecoration = this._controlDecorations.get(i); + values[i] = this.validateEmptyText(text, controlDecoration); + if (values[i]) { + values[i] = this.validateInvalidText(text, controlDecoration); + if (values[i]) + values[i] = this.validateDuplicateText(text, i, controlDecoration); + } + } + + boolean validFields; + int i = 0; + + do + validFields = values[i++]; + while ((validFields) && i < values.length); + + if (this._okButton != null) + this._okButton.setEnabled(validFields); + } + + public void setValues(String[] values) { + + this._values = new LinkedList<>(); + for (String value : values) + this._values.add(value); + } + + protected ControlDecoration createNotificationDecorator(Text text) { + ControlDecoration controlDecoration = new ControlDecoration(text, SWT.LEFT | SWT.TOP); + FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); + controlDecoration.setImage(fieldDecoration.getImage()); + validate(controlDecoration, ""); //$NON-NLS-1$ + + return controlDecoration; + } + + protected ControlDecoration createNotificationDecorator(Button button) { + ControlDecoration controlDecoration = new ControlDecoration(button, SWT.LEFT | SWT.TOP); + FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_WARNING); + controlDecoration.setImage(fieldDecoration.getImage()); + validate(controlDecoration, ""); //$NON-NLS-1$ + + return controlDecoration; + } + + + protected boolean validate(ControlDecoration controlDecoration, String text) { + controlDecoration.setDescriptionText(text); + if(text.isEmpty()) { + controlDecoration.hide(); + return true; + } else { + controlDecoration.show(); + return false; + + } + } + + + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/Messages.java b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/Messages.java new file mode 100644 index 0000000..1e6c6b5 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/Messages.java @@ -0,0 +1,33 @@ +// This file has been auto-generated +package flintstones.domain.fuzzyset.unbalanced.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String SemanticDialog_labelTemplate; + public String Domain_name; + public String LH_features; + public String Initial_granularity_of_LH; + public String Labels_of_unbalanced_scale; + public String Number_of_labels_of_unbalanced_scale; + public String Left_side_SL; + public String Density_SL; + public String Right_side_SR; + public String Density_SR; + public String Set_semantic; + public String Preview; + public String Create_unbalanced_domain; + public String Duplicated_name; + public String Empty_value; + public String Empty_domain; + public String Modify_unbalanced_domain; + public String Semantic_for_domain; + public String Illegal_value; + public String Duplicated_value; + public String LHDomainDialog_Extreme; + public String LHDomainDialog_Center; + +} diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/messages.properties b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/messages.properties new file mode 100644 index 0000000..b01cb88 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/messages.properties @@ -0,0 +1,22 @@ +Create_unbalanced_domain=Create unbalanced domain +Density_SL=Density SL +Density_SR=Density SR +Domain_name=Domain name +Duplicated_name=Duplicated name +Empty_value=Empty value +Empty_domain=Empty domain +Initial_granularity_of_LH=Initial granularity of LH +Labels_of_unbalanced_scale=Labels of unbalanced scale +Left_side_SL=Left side SL +LH_features=LH Features +LHDomainDialog_Center=Center +LHDomainDialog_Extreme=Extreme +Number_of_labels_of_unbalanced_scale=Number of labels of unbalanced scale +Preview=Preview +Right_side_SR=Right side SR +Set_semantic=Set semantic +Modify_unbalanced_domain=Modify unbalanced domain +Duplicated_value=Duplicated value +Illegal_value=Illegal value +Semantic_for_domain=Semantic for domain +SemanticDialog_labelTemplate=Label {0} diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/messages_es.properties b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/messages_es.properties new file mode 100644 index 0000000..76887cb --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced.ui.dialog/src/flintstones/domain/fuzzyset/unbalanced/ui/messages/messages_es.properties @@ -0,0 +1,22 @@ +Create_unbalanced_domain=Crear dominio no balanceado +Density_SL=Densidad SL +Density_SR=Densidad SR +Domain_name=Nombre de dominio +Duplicated_name=Nombre duplicado +Empty_value=Valor vacio +Empty_domain=Dominio vacio +Initial_granularity_of_LH=Granularidad inicial de LH +Labels_of_unbalanced_scale=Etiquetas de escala no balanceada +Left_side_SL=Lado izquierdo SL +LH_features=Caracteristicas LH +Number_of_labels_of_unbalanced_scale=Nmero de etiquetas de escala no balanceada +Preview=Previsualizacin +Right_side_SR=Lado derecho de SR +Set_semantic=Establecer semantica +Modify_unbalanced_domain=Modificar dominio no balanceado +Duplicated_value=Valor duplicado +Illegal_value=Valor ilegal +Semantic_for_domain=Semantica del dominio +SemanticDialog_labelTemplate=Etiqueta {0} +LHDomainDialog_Center=Centrado +LHDomainDialog_Extreme=Extremo diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/.classpath b/bundles/flintstones.domain.fuzzyset.unbalanced/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/.polyglot.META-INF b/bundles/flintstones.domain.fuzzyset.unbalanced/.polyglot.META-INF new file mode 100644 index 0000000..9012200 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.fuzzyset.unbalanced + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Unbalanced + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/.project b/bundles/flintstones.domain.fuzzyset.unbalanced/.project new file mode 100644 index 0000000..28ededb --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.fuzzyset.unbalanced + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362541 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/META-INF/MANIFEST.MF b/bundles/flintstones.domain.fuzzyset.unbalanced/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1bb007c --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.fuzzyset.unbalanced;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.domain, + flintstones.domain.fuzzyset;visibility:=reexport, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.linguistic, + flintstones.operator, + flintstones.helper.data.wxml, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di +Export-Package: flintstones.domain.fuzzyset.unbalanced, + flintstones.domain.fuzzyset.unbalanced.utils +Automatic-Module-Name: flintstones.domain.fuzzyset.unbalanced +Import-Package: flintstones.valuation.twoTuple diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.fuzzyset.unbalanced/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..969cd79 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,4 @@ +#Properties file for flintstones.domain.fuzzyset.unbalanced +Bundle-Name = Unbalanced +domain.name = Unbalanced +domain.type = Unbalanced \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.fuzzyset.unbalanced/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..557bee9 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,4 @@ +#Properties file for flintstones.domain.fuzzyset.unbalanced +Bundle-Name = No balanceado +domain.name = No balanceado +domain.type = No balanceados \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/build.properties b/bundles/flintstones.domain.fuzzyset.unbalanced/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/plugin.xml b/bundles/flintstones.domain.fuzzyset.unbalanced/plugin.xml new file mode 100644 index 0000000..1a6c688 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/plugin.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/Unbalanced.java b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/Unbalanced.java new file mode 100644 index 0000000..532e270 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/Unbalanced.java @@ -0,0 +1,902 @@ + package flintstones.domain.fuzzyset.unbalanced; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.unbalanced.messages.Messages; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.validator.Validator; + +@SuppressWarnings("javadoc") +public class Unbalanced extends FuzzySet { + + @Inject + IEclipseContext context; + + @Inject + @Translation + private Messages messages; + + public static enum FieldsFS3 implements ExtensionEnum { + // left_lateral_set + sl, + // right_lateral_set + sr, + // left_lateral_set_density + slDensity, + // right_lateral_set_density + srDensity, + // cardinality, _labels.size(). NO ESCRIBIR + cardinality, + // muere + labelU, + // muere + labelsU, + // ? + domainLabelMALMALMAL, + // position - NO ESCRIBIR + pos, + // label + la, + // domain + d, + // + l, + // linguistic hierarchy + lh, + // + labelSet, + // + values, + // muere + data + }; + + public static enum Fields implements ExtensionEnum { + // left_lateral_set + leftLateralSet, + // right_lateral_set + rightLateralSet, + // left_lateral_set_density + leftLateralSetDensity, + // right_lateral_set_density + rightLateralSetDensity, + // cardinality, _labels.size(). NO ESCRIBIR + cardinality, + // muere + unbalancedLabel, + // muere + unbalancedLabels, + // ? + domainLabel, + // position - NO ESCRIBIR + position, + // label + label, + // domain + domain, + // + l, + // linguistic hierarchy + linguisticHierarchy, + // + linguisticTerm, + // + granularity, + // + labelSet, + // + value, + // muere + values, + // muere + data, domainGranularity + }; + + public static final String ID = "flintstones.domain.linguistic.unbalanced"; //$NON-NLS-1$ + + private int[] _lh; + private int _sl; + private int _sr; + private int _slDensity; + private int _srDensity; + private int _cardinality; + private Map> _labels = new HashMap>();; + + public Unbalanced() { + super(); + } + + public void initUnbalanced() { + setType(ID); + } + + public int[] getLh() { + return _lh; + } + + public void setLh(int[] lh) { + _lh = lh; + } + + public int getSl() { + return _sl; + } + + public void setSl(int sl) { + _sl = sl; + } + + public int getSr() { + return _sr; + } + + public void setSr(int sr) { + _sr = sr; + } + + public int getSlDensity() { + return _slDensity; + } + + public void setSlDensity(int slDensity) { + _slDensity = slDensity; + } + + public int getSrDensity() { + return _srDensity; + } + + public void setSrDensity(int srDensity) { + _srDensity = srDensity; + } + + public int getCardinality() { + return _cardinality; + } + + public void setCardinality(int cardinality) { + _cardinality = cardinality; + } + + public Map> getLabels() { + return _labels; + } + + public void setLabels(Map> labels) { + _labels = labels; + } + + public boolean isBrid(int pos) { + return (_labels.get(pos).size() > 1); + } + + public void setLabel(int pos, Map label) { + _labels.put(pos, label); + } + + public Map getLabel(int pos) { + return _labels.get(pos); + } + + public void setLabelInDomain(int pos, int domain, int label) { + + if(!_labels.containsKey(pos)) { + _labels.put(pos, new HashMap()); + } + + _labels.get(pos).put(domain, label); + + } + + public Integer labelPos(int domain, int label) { + Integer aux; + for(int pos: _labels.keySet()) { + aux = getLabelInDomain(pos, domain); + if(aux != null) { + if(aux == label) { + return pos; + } + } + } + + return null; + } + + public Integer getLabelInDomain(int pos, int domain) { + + if(_labels.containsKey(pos)) { + return _labels.get(pos).get(domain); + } + return null; + } + + @Override + public String toString() { + //return this.formatDescriptionDomain(); + + String result = ""; //$NON-NLS-1$ + + for(int label: _labels.keySet()) { + result += "Label " + label + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + for(int domain: _labels.get(label).keySet()) { + result += "\tDomain: " + domain + ":" + _labels.get(label).get(domain) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + } + + return result; + + } + + public String getInfo() { + String result = ""; //$NON-NLS-1$ + + result = loadStringLh(result); + result = loadStringFormat(result); + return loadStringLabels(result); + } + + public void createUnbalancedDomain(String[] labels, int sr, int sl, int sldensity, int srdensity, int initialDomain) { + Validator.notNull(labels); + Validator.notEmpty(labels); + + if(Validator.isNegative(sr)) { + throw new IllegalArgumentException(messages.Unbalanced_Invalid_sr); + } + + if(Validator.isNegative(sl)) { + throw new IllegalArgumentException(messages.Unbalanced_Invalid_sl); + } + + if(!Validator.isSameElement(sl + sr + 1, labels.length)) { + throw new IllegalArgumentException(messages.Unbalanced_Invalid_cardinality); + } + + if((labels.length % 2) == 0) { + throw new IllegalArgumentException(messages.Unbalanced_Pair_cardinality); + } + + if(!Validator.inRange(sldensity, 0, 1)) { + throw new IllegalArgumentException(messages.Unbalanced_Invalid_sl_density); + } + + if(!Validator.inRange(srdensity, 0, 1)) { + throw new IllegalArgumentException(messages.Unbalanced_Invalid_sr_density); + } + + if((initialDomain % 2) == 0) { + throw new IllegalArgumentException(messages.Unbalanced_Pair_initial_domain); + } + + if(initialDomain < 3) { + throw new IllegalArgumentException(messages.Unbalanced_Invalid_initial_domain); + } + + int aux = (initialDomain - 1) / 2; + if((aux > sl) || (aux > sr)) { + throw new IllegalArgumentException(messages.Unbalanced_Invalid_initial_domain); + } + + LabelLinguisticDomain leftCenterLabel, rightCenterLabel, centerLabel; + + setSl(sl); + setSr(sr); + setSlDensity(sldensity); + setSrDensity(srdensity); + setCardinality(labels.length); + + _labels = new HashMap>(); + + clearFuzzySet(); + + List lh = new LinkedList(); + lh.add(initialDomain); + + int Lab_t; + int Lab_t1; + boolean directly; + int sideCardinality = ((initialDomain - 1) / 2); + + directly = false; + aux = sideCardinality; + while(aux < sl) { + aux *= 2; + lh.add((aux * 2) + 1); + } + + if (aux == sl) { + directly = true; + } + + if(directly) { + int leftCardinality = (sl * 2) + 1; + String leftLabels[] = new String[leftCardinality]; + + for(int i = 0; i < leftCardinality; i++) { + if(i < sl) { + leftLabels[i] = labels[i]; + } else { + leftLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + FuzzySet left = ContextInjectionFactory.make(FuzzySet.class, context); + left.createTrapezoidalFunction(leftLabels); + for(int i = 0; i < sl; i++) { + setLabelInDomain(i, leftCardinality, i); + addLabel(left.getLabelSet().getLabel(i)); + } + + setLabelInDomain(sl, leftCardinality, sl); + leftCenterLabel = left.getLabelSet().getLabel(sl); + } else { + LabelLinguisticDomain leftBrid, rightBrid, brid; + Lab_t = aux - sl; + Lab_t1 = sl - Lab_t; + int sleCardinality, slcCardinality; + String sleLabels[], slcLabels[]; + FuzzySet sleFuzzySet, slcFuzzySet; + + if(sldensity == 0) { + sleCardinality = (aux * 2) + 1; + sleLabels = new String[sleCardinality]; + + for(int i = 0; i < sleCardinality; i++) { + if(i < Lab_t1) { + sleLabels[i] = labels[i]; + } else { + sleLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + sleFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context); + sleFuzzySet.createTrapezoidalFunction(sleLabels); + for(int i = 0; i < Lab_t1; i++) { + setLabelInDomain(i, sleCardinality, i); + addLabel(sleFuzzySet.getLabelSet().getLabel(i)); + } + + setLabelInDomain(Lab_t1, sleCardinality, Lab_t1); + leftBrid = sleFuzzySet.getLabelSet().getLabel(Lab_t1); + + slcCardinality = aux + 1; + slcLabels = new String[slcCardinality]; + + int alreadyUsed = Lab_t1 / 2; + int j = 0; + for(int i = 0; i < slcCardinality; i++) { + if((i >= alreadyUsed) && (i < (Lab_t + alreadyUsed))) { + slcLabels[i] = labels[Lab_t1 + j++]; + } else { + slcLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + slcFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context); + slcFuzzySet.createTrapezoidalFunction(slcLabels); + for(int i = (alreadyUsed + 1); i < (Lab_t + alreadyUsed); i++) { + setLabelInDomain(getLabelSet().getCardinality() + 1, slcCardinality, i); + addLabel(slcFuzzySet.getLabelSet().getLabel(i)); + } + + setLabelInDomain(Lab_t1, slcCardinality, alreadyUsed); + rightBrid = slcFuzzySet.getLabelSet().getLabel(alreadyUsed); + + double a = leftBrid.getSemantic().getCoverage().getMin(); + double b = rightBrid.getSemantic().getCenter().getMin(); + double d = rightBrid.getSemantic().getCoverage().getMax(); + double limits[] = {a, b, b, d}; + + TrapezoidalFunction semantic = new TrapezoidalFunction(limits); + +// brid = new LabelLinguisticDomain(rightBrid.getName(), semantic); + brid = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + brid.initLabelLinguisticDomain(rightBrid.getName(), semantic); + + addLabel(Lab_t1, brid); + + setLabelInDomain(sl, slcCardinality, Lab_t + alreadyUsed); + leftCenterLabel = slcFuzzySet.getLabelSet().getLabel(Lab_t + alreadyUsed); + + } else { + sleCardinality = aux + 1; + sleLabels = new String[sleCardinality]; + + for(int i = 0; i < sleCardinality; i++) { + if(i < Lab_t) { + sleLabels[i] = labels[i]; + } else { + sleLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + + sleFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context); + sleFuzzySet.createTrapezoidalFunction(sleLabels); + for(int i = 0; i < Lab_t; i++) { + setLabelInDomain(i, sleCardinality, i); + addLabel(sleFuzzySet.getLabelSet().getLabel(i)); + } + + setLabelInDomain(Lab_t, sleCardinality, Lab_t); + leftBrid = sleFuzzySet.getLabelSet().getLabel(Lab_t); + + slcCardinality = (aux * 2) + 1; + slcLabels = new String[slcCardinality]; + + int alreadyUsed = Lab_t * 2; + int j = 0; + for(int i = 0; i < slcCardinality; i++) { + if((i >= alreadyUsed) && (i < (Lab_t1 + alreadyUsed))) { + slcLabels[i] = labels[Lab_t + j++]; + } else { + slcLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + slcFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context); + slcFuzzySet.createTrapezoidalFunction(slcLabels); + for(int i = (alreadyUsed + 1); i < (Lab_t1 + alreadyUsed); i++) { + setLabelInDomain(getLabelSet().getCardinality() + 1, slcCardinality, i); + addLabel(slcFuzzySet.getLabelSet().getLabel(i)); + } + + setLabelInDomain(Lab_t, slcCardinality, alreadyUsed); + rightBrid = slcFuzzySet.getLabelSet().getLabel(alreadyUsed); + + double a = leftBrid.getSemantic().getCoverage().getMin(); + double b = rightBrid.getSemantic().getCenter().getMin(); + double d = rightBrid.getSemantic().getCoverage().getMax(); + double limits[] = {a, b, b, d}; + TrapezoidalFunction semantic = new TrapezoidalFunction(limits); + +// brid = new LabelLinguisticDomain(rightBrid.getName(), semantic); + brid = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + brid.initLabelLinguisticDomain(rightBrid.getName(), semantic); + + addLabel(Lab_t, brid); + + setLabelInDomain(sl, slcCardinality, Lab_t1 + alreadyUsed); + leftCenterLabel = slcFuzzySet.getLabelSet().getLabel(Lab_t1 + alreadyUsed); + } + } + + directly = false; + aux = sideCardinality; + int bigger = lh.get(lh.size() - 1); + while(aux < sr) { + aux *= 2; + if (((aux * 2) + 1) > bigger) { + lh.add((aux * 2) + 1); + } + } + + if(aux == sr) { + directly = true; + } + + if(directly) { + int rightCardinality = (sr * 2) + 1; + String rightLabels[] = new String[rightCardinality]; + + for(int i = 0; i < rightCardinality; i++) { + if(i >= (rightCardinality - sr)) { + rightLabels[i] = labels[labels.length - (rightCardinality - i)]; + } else { + rightLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + FuzzySet right = ContextInjectionFactory.make(FuzzySet.class, context); + right.createTrapezoidalFunction(rightLabels); + for(int i = (rightCardinality - sr); i < rightCardinality; i++) { + setLabelInDomain(getLabelSet().getCardinality() + 1, rightCardinality, i); + addLabel(right.getLabelSet().getLabel(i)); + } + + rightCenterLabel = right.getLabelSet().getLabel(rightCardinality - sr - 1); + + double a = leftCenterLabel.getSemantic().getCoverage().getMin(); + double b = rightCenterLabel.getSemantic().getCenter().getMin(); + double d = rightCenterLabel.getSemantic().getCoverage().getMax(); + double limits[] = { a, b, b, d }; + TrapezoidalFunction semantic = new TrapezoidalFunction(limits); + +// centerLabel = new LabelLinguisticDomain(labels[sl], semantic); + centerLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + centerLabel.initLabelLinguisticDomain(labels[sl], semantic); + + + setLabelInDomain(sl, rightCardinality, rightCardinality - sr - 1); + addLabel(sl, centerLabel); + + } else { + LabelLinguisticDomain leftBrid, rightBrid, brid; + Lab_t = aux - sr; + Lab_t1 = sr - Lab_t; + int sreCardinality, srcCardinality; + String sreLabels[], srcLabels[]; + FuzzySet sreFuzzySet, srcFuzzySet; + + if(srdensity == 0) { + srcCardinality = aux + 1; + srcLabels = new String[srcCardinality]; + + int j = 0; + for(int i = 0; i < srcCardinality; i++) { + if((i > (aux / 2)) && (i <= ((aux / 2) + Lab_t))) { + srcLabels[i] = labels[sl + 1 + j++]; + } else { + srcLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + + srcFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context); + srcFuzzySet.createTrapezoidalFunction(srcLabels); + for(int i = ((aux / 2) + 1); i < ((aux / 2) + Lab_t); i++) { + setLabelInDomain(getLabelSet().getCardinality() + 1, srcCardinality, i); + addLabel(srcFuzzySet.getLabelSet().getLabel(i)); + } + setLabelInDomain(getLabelSet().getCardinality() + 1, srcCardinality, (aux / 2) + Lab_t); + leftBrid = srcFuzzySet.getLabelSet().getLabel((aux / 2) + Lab_t); + + rightCenterLabel = srcFuzzySet.getLabelSet().getLabel(aux / 2); + + double a = leftCenterLabel.getSemantic().getCoverage().getMin(); + double b = rightCenterLabel.getSemantic().getCenter().getMin(); + double d = rightCenterLabel.getSemantic().getCoverage().getMax(); + double limits[] = { a, b, b, d }; + TrapezoidalFunction semantic = new TrapezoidalFunction(limits); + +// centerLabel = new LabelLinguisticDomain(labels[sl], semantic); + centerLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + centerLabel.initLabelLinguisticDomain(labels[sl], semantic); + + + + setLabelInDomain(sl, srcCardinality, aux / 2); + addLabel(sl, centerLabel); + + sreCardinality = (aux * 2) + 1; + sreLabels = new String[sreCardinality]; + + for(int i = 0; i < sreCardinality; i++) { + if(i >= (sreCardinality - Lab_t1)) { + sreLabels[i] = labels[labels.length - (sreCardinality - i)]; + } else { + sreLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + + sreFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context); + sreFuzzySet.createTrapezoidalFunction(sreLabels); + for(int i = (sreCardinality - Lab_t1); i < sreCardinality; i++) { + setLabelInDomain(getLabelSet().getCardinality() + 1, sreCardinality, i); + addLabel(sreFuzzySet.getLabelSet().getLabel(i)); + } + + setLabelInDomain(sl + Lab_t, sreCardinality, sreCardinality - Lab_t1 - 1); + rightBrid = sreFuzzySet.getLabelSet().getLabel(sreCardinality - Lab_t1 - 1); + + a = leftBrid.getSemantic().getCoverage().getMin(); + b = rightBrid.getSemantic().getCenter().getMin(); + d = rightBrid.getSemantic().getCoverage().getMax(); + double limits1[] = { a, b, b, d }; + TrapezoidalFunction semantic1 = new TrapezoidalFunction(limits1); + +// brid = new LabelLinguisticDomain(leftBrid.getName(), semantic1); + brid = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + brid.initLabelLinguisticDomain(leftBrid.getName(), semantic1); + + + + addLabel(sl + Lab_t, brid); + + } else { + srcCardinality = (aux * 2) + 1; + srcLabels = new String[srcCardinality]; + + int j = 0; + for(int i = 0; i < srcCardinality; i++) { + if((i > aux) && i < (aux + Lab_t1)) { + srcLabels[i] = labels[sl + 1 + j++]; + } else { + srcLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + + srcFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context); + srcFuzzySet.createTrapezoidalFunction(srcLabels); + for(int i = (aux + 1); i < (aux + Lab_t1); i++) { + setLabelInDomain(getLabelSet().getCardinality() + 1, srcCardinality, i); + addLabel(srcFuzzySet.getLabelSet().getLabel(i)); + } + + leftBrid = srcFuzzySet.getLabelSet().getLabel(aux + Lab_t1); + + rightCenterLabel = srcFuzzySet.getLabelSet().getLabel(aux); + + double a = leftCenterLabel.getSemantic().getCoverage().getMin(); + double b = rightCenterLabel.getSemantic().getCenter().getMin(); + double d = rightCenterLabel.getSemantic().getCoverage().getMax(); + double limits[] = { a, b, b, d }; + TrapezoidalFunction semantic = new TrapezoidalFunction(limits); + +// centerLabel = new LabelLinguisticDomain(labels[sl], semantic); + centerLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + centerLabel.initLabelLinguisticDomain(labels[sl], semantic); + + + setLabelInDomain(sl, srcCardinality, aux); + addLabel(sl, centerLabel); + + sreCardinality = aux + 1; + sreLabels = new String[sreCardinality]; + + for(int i = 0; i < sreCardinality; i++) { + if(i >= (sreCardinality - Lab_t - 1)) { + sreLabels[i] = labels[labels.length - (sreCardinality - i)]; + } else { + sreLabels[i] = "dirty label " + i; //$NON-NLS-1$ + } + } + + sreFuzzySet = ContextInjectionFactory.make(FuzzySet.class, context); + sreFuzzySet.createTrapezoidalFunction(sreLabels); + + for(int i = (sreCardinality - Lab_t); i < sreCardinality; i++) { + setLabelInDomain(getLabelSet().getCardinality() + 1, sreCardinality, i); + addLabel(sreFuzzySet.getLabelSet().getLabel(i)); + } + + setLabelInDomain(sl + Lab_t1, srcCardinality, aux + Lab_t1); + setLabelInDomain(sl + Lab_t1, sreCardinality, sreCardinality - Lab_t - 1); + rightBrid = sreFuzzySet.getLabelSet().getLabel(sreCardinality - Lab_t - 1); + a = leftBrid.getSemantic().getCoverage().getMin(); + b = rightBrid.getSemantic().getCenter().getMin(); + d = rightBrid.getSemantic().getCoverage().getMax(); + + double limits1[] = { a, b, b, d }; + TrapezoidalFunction semantic1 = new TrapezoidalFunction(limits1); + +// brid = new LabelLinguisticDomain(rightBrid.getName(), semantic1); + brid = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + brid.initLabelLinguisticDomain(rightBrid.getName(), semantic1); + + addLabel(sl + Lab_t1, brid); + } + } + + _lh = new int[lh.size()]; + for(int i = 0; i < _lh.length; i++) { + _lh[i] = lh.get(i); + } + } + + private String loadStringLh(String result) { + StringBuilder lh = new StringBuilder("lh = "); //$NON-NLS-1$ + + for(int l: _lh) { + lh.append(l + ","); //$NON-NLS-1$ + } + lh.replace(lh.length() - 1, lh.length(), ""); //$NON-NLS-1$ + result += lh.toString(); + + return result; + } + + private String loadStringFormat(String result) { + String format = ";sl = " + _sl + ";" + "slDensity = " + _slDensity + ";" + "sr = " + _sr + ";" + "srDensity = " + _srDensity; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + result += format; + + return result; + } + + private String loadStringLabels(String result) { + int numLabels; + StringBuilder labels = new StringBuilder(";labels ="); //$NON-NLS-1$ + for(int label: _labels.keySet()) { + labels.append(label + "={"); + numLabels = 0; + for(int domain: _labels.get(label).keySet()) { + if(numLabels != (_labels.get(label).size() - 1)) { + labels.append(domain + "=" + _labels.get(label).get(domain) + ","); //$NON-NLS-1$ //$NON-NLS-2$ + } else { + labels.append(domain + "=" + _labels.get(label).get(domain)); //$NON-NLS-1$ + } + numLabels++; + } + labels.append("}&"); //$NON-NLS-1$ + } + labels.deleteCharAt(labels.lastIndexOf("&")); + + result += labels.toString(); + + return result; + } + + ///////////// + + @Override + public void write(XMLStreamWriter writer) throws XMLStreamException { + + writer.writeAttribute(Fields.leftLateralSet.toString(), Integer.toString(this._sl)); + writer.writeAttribute(Fields.rightLateralSet.toString(), Integer.toString(this._sr)); + writer.writeAttribute(Fields.leftLateralSetDensity.toString(), Integer.toString(this._slDensity)); + writer.writeAttribute(Fields.rightLateralSetDensity.toString(), Integer.toString(this._srDensity)); + writer.writeAttribute(Fields.cardinality.toString(), Integer.toString(this._cardinality)); + + // Write Linguistic Hierarchy + writer.writeStartElement(Fields.linguisticHierarchy.toString()); + for (int element : this._lh) { + writer.writeStartElement(Fields.linguisticTerm.toString()); + writer.writeAttribute(Fields.granularity.toString(), Integer.toString(element)); + writer.writeEndElement(); + } + writer.writeEndElement(); + + // Labels + writer.writeStartElement(Fields.unbalancedLabels.toString()); + for (Integer pos : this._labels.keySet()) { + Map labels = this._labels.get(pos); + + writer.writeStartElement(Fields.unbalancedLabel.toString()); + // TODO: Se debería poder quitar, es autoincremental desde 0 + writer.writeAttribute(Fields.position.toString(), Integer.toString(pos)); + + for (Integer domain : labels.keySet()) { + writer.writeStartElement(Fields.domainLabel.toString()); + writer.writeAttribute(Fields.domainGranularity.toString(), Integer.toString(domain)); + writer.writeAttribute(Fields.label.toString(), Integer.toString(labels.get(domain))); + writer.writeEndElement(); + } + + writer.writeEndElement(); + + } + writer.writeEndElement(); + + super.write(writer); + } + + @Override + public void read(WNode node) { + if (node.getVersion() + .equals("3.0")) //$NON-NLS-1$ + this.readFS3(node); + else + this.readFS4(node); + super.read(node); + + } + + private void readFS3(WNode node) { + + List nodes = node.getChildren(); + for (WNode item : nodes) { + String pseudoType = item.getName(); + + if (pseudoType.equals(FieldsFS3.lh.toString())) + this.readLH(item); + else if (pseudoType.equals(FieldsFS3.labelsU.toString())) + this.readLabelsU(item); + else if (pseudoType.equals(FieldsFS3.data.toString())) + this.readDataFS3(item); + else if (pseudoType.equals(FieldsFS3.values.toString()) || pseudoType.equals(FieldsFS3.labelSet.toString())) { + // Do nothing, se hace arriba. + } else + throw new Error("Implementar para pseudoType " + pseudoType); //$NON-NLS-1$ + + } + + // Read values & labelset + super.read(node); + + } + + private void readFS4(WNode node) { + this.readDataFS4(node); + this.readLinguisticHierarchyFS4(node.getFirst(Fields.linguisticHierarchy)); + this.readUnbalancedLabelsFS4(node.getFirst(Fields.unbalancedLabels)); + super.read(node); + } + + private void readLH(WNode node) { + + List values = new ArrayList<>(); + List nodes = node.getChildren(); + for (WNode item : nodes) { + String valueS = item.getAttribute(FieldsFS3.l); + Integer value = Integer.valueOf(valueS); + values.add(value); + } + + this._lh = new int[values.size()]; + for (int i = 0; i < values.size(); i++) + this._lh[i] = values.get(i); + + } + + private void readLinguisticHierarchyFS4(WNode node) { + List values = new ArrayList<>(); + + for (WNode item : node.getChildren()) { + int granularity = item.getAttributeInt(Fields.granularity); + values.add(granularity); + } + this._lh = values.stream() + .mapToInt(i -> i) + .toArray(); + } + + private void readUnbalancedLabelsFS4(WNode node) { + + for (WNode unbalancedLabelNode : node.getChildren()) { + int position = unbalancedLabelNode.getAttributeInt(Fields.position); + + Map domainLabels = new HashMap<>(); + for (WNode domainLabel : unbalancedLabelNode.getChildren()) { + int domainGranularity = domainLabel.getAttributeInt(Fields.domainGranularity); + int label = domainLabel.getAttributeInt(Fields.label); + domainLabels.put(domainGranularity, label); + } + this._labels.put(position, domainLabels); + } + } + + private void readLabelsU(WNode node) { + + List nodes = node.getChildren(); + this._labels = new HashMap<>(); + + Map data = new HashMap<>(); + + int pos = 0; + for (WNode item : nodes) { + + if(item.getName().equals("labelU")) { + + this._labels.put(pos, new HashMap<>(data)); + data.clear(); + + pos++; + continue; + } + + String domainS = item.getAttribute(FieldsFS3.d); + String labelS = item.getAttribute(FieldsFS3.la); + int domain = Integer.parseInt(domainS); + int label = Integer.parseInt(labelS); + data.put(domain, label); + + } + + } + + private void readDataFS3(WNode node) { + this._sl = Integer.parseInt(node.getAttribute(FieldsFS3.sl)); + this._sr = Integer.parseInt(node.getAttribute(FieldsFS3.sr)); + this._slDensity = Integer.parseInt(node.getAttribute(FieldsFS3.slDensity)); + this._srDensity = Integer.parseInt(node.getAttribute(FieldsFS3.srDensity)); + this._cardinality = Integer.parseInt(node.getAttribute(FieldsFS3.cardinality)); + } + + private void readDataFS4(WNode node) { + this._sl = Integer.parseInt(node.getAttribute(Fields.leftLateralSet)); + this._sr = Integer.parseInt(node.getAttribute(Fields.rightLateralSet)); + this._slDensity = Integer.parseInt(node.getAttribute(Fields.leftLateralSetDensity)); + this._srDensity = Integer.parseInt(node.getAttribute(Fields.rightLateralSetDensity)); + this._cardinality = Integer.parseInt(node.getAttribute(Fields.cardinality)); + } + +} diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/instance/Unbalanced3C5EIntance.java b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/instance/Unbalanced3C5EIntance.java new file mode 100644 index 0000000..ed5af5e --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/instance/Unbalanced3C5EIntance.java @@ -0,0 +1,24 @@ +package flintstones.domain.fuzzyset.unbalanced.instance; + +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class Unbalanced3C5EIntance extends DomainInstance { + + @Override + public Domain getInstance() { + Unbalanced domain = (Unbalanced) getDomain(); + + String[] labels = new String[9]; + for(int i = 0; i < 9; i++) + labels[i] = "s"+(i+1); + + String name = getLabel(); + + domain.createUnbalancedDomain(labels, 5, 3, 1, 0,5); + domain.setName(name); + return domain; + } + +} diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/instance/Unbalanced5E3CIntance.java b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/instance/Unbalanced5E3CIntance.java new file mode 100644 index 0000000..93d8081 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/instance/Unbalanced5E3CIntance.java @@ -0,0 +1,24 @@ +package flintstones.domain.fuzzyset.unbalanced.instance; + +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class Unbalanced5E3CIntance extends DomainInstance { + + @Override + public Domain getInstance() { + Unbalanced domain = (Unbalanced) getDomain(); + + String[] labels = new String[9]; + for(int i = 0; i < 9; i++) + labels[i] = "s"+(i+1); + + String name = getLabel(); + + domain.createUnbalancedDomain(labels, 3, 5, 0, 1,5); + domain.setName(name); + return domain; + } + +} diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/Messages.java b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/Messages.java new file mode 100644 index 0000000..5b4b7b2 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/Messages.java @@ -0,0 +1,22 @@ +// This file has been auto-generated +package flintstones.domain.fuzzyset.unbalanced.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public static String Unbalanced_id; + public String Unbalanced_Invalid_cardinality; + public String Unbalanced_Invalid_initial_domain; + public String Unbalanced_Invalid_sl; + public String Unbalanced_Invalid_sl_density; + public String Unbalanced_Invalid_sr; + public String Unbalanced_Invalid_sr_density; + public String Unbalanced_Pair_cardinality; + public String Unbalanced_Pair_initial_domain; + public String category; + public String name; + +} diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/messages.properties b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/messages.properties new file mode 100644 index 0000000..5418375 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/messages.properties @@ -0,0 +1,11 @@ +Unbalanced_id=flintstones.domain.linguistic.unbalanced +Unbalanced_Invalid_cardinality=Invalid cardinality +Unbalanced_Invalid_initial_domain=Invalid initial domain +Unbalanced_Invalid_sl=Invalid sl +Unbalanced_Invalid_sl_density=Invalid sl density +Unbalanced_Invalid_sr=Invalid sr +Unbalanced_Invalid_sr_density=Invalid sr density +Unbalanced_Pair_cardinality=Pair cardinality +Unbalanced_Pair_initial_domain=Pair initial domain +category=Unbalanced +name=Unbalanced \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/messages_es.properties b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/messages_es.properties new file mode 100644 index 0000000..5e309af --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/messages/messages_es.properties @@ -0,0 +1,11 @@ +Unbalanced_id=flintstones.domain.linguistic.unbalanced +Unbalanced_Invalid_cardinality=Cardinalidad invlida +Unbalanced_Invalid_initial_domain=Dominio inicial invlido +Unbalanced_Invalid_sl=Sl invlida +Unbalanced_Invalid_sl_density=Densidad sl invlida +Unbalanced_Invalid_sr=Sr invlido +Unbalanced_Invalid_sr_density=Densidad sr invlida +Unbalanced_Pair_cardinality=Cardinalidad par +Unbalanced_Pair_initial_domain=Dominio inicial par +category=No balanceados +name=No balanceado \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/utils/UnbalancedUtils.java b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/utils/UnbalancedUtils.java new file mode 100644 index 0000000..aa99873 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset.unbalanced/src/flintstones/domain/fuzzyset/unbalanced/utils/UnbalancedUtils.java @@ -0,0 +1,183 @@ +package flintstones.domain.fuzzyset.unbalanced.utils; + +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +@SuppressWarnings("javadoc") +// PATCH class from FS3 to allow unbalanced work with unification/aggregation +public class UnbalancedUtils { + + @Inject + IEclipseContext context; + + private Unbalanced _unbalancedDomain; + + private final int UNBALANCED_LEFT = 0; + private final int UNBALANCED_RIGHT = 1; + + public Map transformUnbalanced(Map problemResult, Unbalanced resultsDomain) { + + _unbalancedDomain = resultsDomain; + Map results = null; + + if(resultsDomain != null) { + + results = new HashMap(); + + Valuation valuation; + Unbalanced hgls = null; + LabelLinguisticDomain label, labelTest = null; + double alpha; + Map domains = null; + int testPos; + boolean find; + Integer labelPos; + Unbalanced domainTest; + int domainPos; + int domainSize; + + int size; + Unbalanced[] auxDomains = null; + LabelLinguisticDomain[] labels = null; + double[] alphas = null; + int[] sizes = null; + + int[] lh = resultsDomain.getLh(); + Map lhDomains = new HashMap(); + + for(int i = 0; i < lh.length; i++) { + lhDomains.put(lh[i], createDomain(lh[i])); + } + + for(ProblemElement alternative : problemResult.keySet()) { + valuation = problemResult.get(alternative); + if(valuation != null) { + if(hgls == null) { + hgls = (Unbalanced) valuation.getDomain(); + } + label = ((TwoTupleValuation) valuation).getLabel(); + alpha = ((TwoTupleValuation) valuation).getAlpha(); + + find = false; + + domainPos = lh.length - 1; + do { + domainSize = lh[domainPos]; + domainTest = lhDomains.get(domainSize); + testPos = domainTest.getLabelSet().getPos(label); + labelPos = resultsDomain.labelPos(domainSize, testPos); + if(labelPos != null) { + find = true; + labelTest = _unbalancedDomain.getLabelSet().getLabel(labelPos); + domains = resultsDomain.getLabel(labelPos); + size = domains.size(); + auxDomains = new Unbalanced[size]; + labels = new LabelLinguisticDomain[size]; + sizes = new int[size]; + alphas = new double[size]; + int i = 0; + for(Integer auxSize : domains.keySet()) { + auxDomains[i] = lhDomains.get(auxSize); + labels[i] = auxDomains[i].getLabelSet().getLabel(domains.get(auxSize)); + sizes[i] = auxSize; + if (labels[i] == label) { + alphas[i] = alpha; + } else { + alphas[i] = ((TwoTupleValuation) valuation).transform(auxDomains[i]).getAlpha(); + } + i++; + } + } else { + domainPos--; + valuation = ((TwoTupleValuation) valuation).transform(lhDomains.get(lh[domainPos])); + label = ((TwoTupleValuation) valuation).getLabel(); + alpha = ((TwoTupleValuation) valuation).getAlpha(); + } + } while (!find); + + if((domains.size() == 1) || (alpha == 0)) { + valuation = transformToResultsDomain(labelTest, alphas[0]); + } else { + if(alpha > 0) { + if(smallSide(labelTest) == UNBALANCED_RIGHT) { + if (sizes[0] > sizes[1]) { + valuation = transformToResultsDomain(labelTest, alphas[0]); + } else { + valuation = transformToResultsDomain(labelTest, alphas[1]); + } + } else { + if(sizes[0] > sizes[1]) { + valuation = transformToResultsDomain(labelTest, alphas[1]); + } else { + valuation = transformToResultsDomain(labelTest, alphas[0]); + } + } + } else { + if (smallSide(label) == UNBALANCED_RIGHT) { + if (sizes[0] > sizes[1]) { + valuation = transformToResultsDomain(labelTest, alphas[1]); + } else { + valuation = transformToResultsDomain(labelTest, alphas[0]); + } + } else { + if (sizes[0] > sizes[1]) { + valuation = transformToResultsDomain(labelTest, alphas[0]); + } else { + valuation = transformToResultsDomain(labelTest, alphas[1]); + } + } + } + } + } + + results.put(alternative, valuation); + } + } + + return results; + } + + private Unbalanced createDomain(int cardinality) { + String[] labels = new String[cardinality]; + for(int i = 0; i < cardinality; i++) { + labels[i] = Integer.toString(i); + } + + Unbalanced domain = ContextInjectionFactory.make(Unbalanced.class, context); + domain.createTrapezoidalFunction(labels); + + return domain; + } + + private int smallSide(LabelLinguisticDomain l) { + NumericRealDomain center = l.getSemantic().getCenter(); + NumericRealDomain coverage = l.getSemantic().getCoverage(); + + double left = center.getMin() - coverage.getMin(); + double right = coverage.getMax() - center.getMax(); + + if(left > right) { + return UNBALANCED_RIGHT; + } else { + return UNBALANCED_LEFT; + } + } + + private Valuation transformToResultsDomain(LabelLinguisticDomain label, double alpha) { + TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context); + result.build(_unbalancedDomain, label, alpha); + return result; + } +} diff --git a/bundles/flintstones.domain.fuzzyset/.classpath b/bundles/flintstones.domain.fuzzyset/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset/.polyglot.META-INF b/bundles/flintstones.domain.fuzzyset/.polyglot.META-INF new file mode 100644 index 0000000..3104650 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.fuzzyset + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Fuzzyset + diff --git a/bundles/flintstones.domain.fuzzyset/.project b/bundles/flintstones.domain.fuzzyset/.project new file mode 100644 index 0000000..f398841 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.fuzzyset + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362537 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.fuzzyset/META-INF/MANIFEST.MF b/bundles/flintstones.domain.fuzzyset/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b1699d4 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.fuzzyset;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.domain.numeric.real;visibility:=reexport, + flintstones.helper.data.wxml, + flintstones.entity.domain, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.apache.commons.lang, + javax.annotation +Export-Package: flintstones.domain.fuzzyset, + flintstones.domain.fuzzyset.function.types, + flintstones.domain.fuzzyset.label, + flintstones.domain.fuzzyset.semantic +Automatic-Module-Name: flintstones.domain.fuzzyset diff --git a/bundles/flintstones.domain.fuzzyset/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.fuzzyset/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..9b35b84 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,6 @@ +#Properties file for flintstones.domain.fuzzyset +Bundle-Name = Fuzzyset +domain.name.linguistic = Linguistic +domain.name.hesitant = Hesitant +domain.type.linguistic = Linguistic +domain.type.hesitant = Linguistic \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.fuzzyset/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..eaafc69 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,6 @@ +#Properties file for flintstones.domain.fuzzyset +Bundle-Name = Conjunto difuso +domain.name.linguistic = Lingstico +domain.name.hesitant = Hesitant +domain.type.linguistic = Lingsticos +domain.type.hesitant = Lingsticos \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset/build.properties b/bundles/flintstones.domain.fuzzyset/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.domain.fuzzyset/plugin.xml b/bundles/flintstones.domain.fuzzyset/plugin.xml new file mode 100644 index 0000000..7ac03bd --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/plugin.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/FuzzySet.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/FuzzySet.java new file mode 100644 index 0000000..19190ec --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/FuzzySet.java @@ -0,0 +1,595 @@ +package flintstones.domain.fuzzyset; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.function.FragmentFunction; +import flintstones.domain.fuzzyset.function.IFragmentFunction; +import flintstones.domain.fuzzyset.function.types.LinearPieceFunction; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.label.LabelSetLinguisticDomain; +import flintstones.domain.fuzzyset.messages.Messages; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.validator.Validator; + +@SuppressWarnings("javadoc") +public class FuzzySet extends Domain { + + @Inject + @Translation + private Messages messages; + + @Inject + IEclipseContext context; + + public static final String ID = "flintstones.domain.linguistic"; //$NON-NLS-1$ + public static final int MINIMUM_NUMBER_LABELS = 3; // $NON-NLS-1$ + + protected LabelSetLinguisticDomain _labelSet; + protected List _values; + + public static enum Fields implements ExtensionEnum { + value, values, v, labelSet + }; + + public FuzzySet() { + super(); + this._labelSet = new LabelSetLinguisticDomain(); + this._values = new LinkedList<>(); + } + + @PostConstruct + private void init() { + this._labelSet = ContextInjectionFactory.make(LabelSetLinguisticDomain.class, this.context); + this._values = new LinkedList<>(); + } + + public void clearFuzzySet() { + this._labelSet = ContextInjectionFactory.make(LabelSetLinguisticDomain.class, this.context); + this._values = new LinkedList<>(); + } + + public void setValues(List values) { + Validator.notNull(values); + int cardinality = this._labelSet.getCardinality(); + Validator.notInvalidSize(values.size(), cardinality, cardinality); + for (Double value : values) { + Validator.notNull(value); + Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$ + } + + this._values = values; + } + + public void setValue(int pos, Double value) { + Validator.notEmpty(this._labelSet.getLabels().toArray()); + Validator.notInvalidSize(pos, 0, this._labelSet.getCardinality() - 1); + + Validator.notNull(value); + Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$ + + this._values.set(pos, value); + } + + public void setValue(String name, Double value) { + Validator.notNull(name); + Validator.notNull(value); + Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$ + + int pos = this._labelSet.getPos(name); + + if (pos != -1) + this.setValue(pos, value); + else + throw new IllegalArgumentException(this.messages.FuzzySet_Inexistent_element); + } + + public void setValue(LabelLinguisticDomain label, Double value) { + Validator.notNull(label); + Validator.notNegative(value); + Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$ + + int pos = this._labelSet.getPos(label); + + if (pos != -1) + this.setValue(pos, value); + else + throw new IllegalArgumentException(this.messages.FuzzySet_Inexistent_element); + } + + public Double getValue(int pos) { + Validator.notEmpty(this._labelSet.getLabels().toArray()); + Validator.notInvalidSize(pos, 0, this._labelSet.getCardinality() - 1); + + return this._values.get(pos); + } + + public Double getValue(String name) { + + int pos = this._labelSet.getPos(name); + + if (pos != -1) + return this.getValue(pos); + return null; + } + + public Double getValue(LabelLinguisticDomain label) { + + int pos = this._labelSet.getPos(label); + + if (pos != -1) + return this.getValue(pos); + return null; + + } + + public List getValues() { + return this._values; + } + + public void setLabelSet(LabelSetLinguisticDomain labelSet) { + this._labelSet = labelSet; + } + + public LabelSetLinguisticDomain getLabelSet() { + return this._labelSet; + } + + public void addLabel(LabelLinguisticDomain label) { + + int labels = this._labelSet.getCardinality(); + + if (labels == 0) + this.addLabel(labels, label); + else { + boolean lower = false; + int counter = 0; + do + if (label.compareTo(this._labelSet.getLabels().get(counter)) <= 0) + lower = true; + else + counter++; + while ((!lower) && (counter < labels)); + + if (lower) + this.addLabel(counter, label); + else + this.addLabel(labels, label); + } + } + + public void addLabel(LabelLinguisticDomain label, Double value) { + this.addLabel(this._labelSet.getCardinality(), label, value); + } + + public void addLabel(int pos, LabelLinguisticDomain label) { + this._labelSet.addLabel(pos, label); + this._values.add(pos, 0d); + } + + public void addLabel(int pos, LabelLinguisticDomain label, Double value) { + this._labelSet.addLabel(pos, label); + + Validator.notNull(value); + Validator.notInvalidSize(value, 0.0, 1.0, "value"); //$NON-NLS-1$ + + this._values.add(pos, value); + } + + public void removeLabel(int pos) { + Validator.notEmpty(this._labelSet.getLabels().toArray()); + Validator.notInvalidSize(pos, 0, this._labelSet.getCardinality() - 1); + + this._labelSet.getLabels().remove(pos); + this._values.remove(pos); + } + + public void removeLabel(String name) { + + if (name == null) + return; + + int pos = this._labelSet.getPos(name); + + if (pos != -1) + this.removeLabel(pos); + } + + public void removeLabel(LabelLinguisticDomain label) { + + if (label == null) + return; + + int pos = this._labelSet.getPos(label); + + if (pos != -1) + this.removeLabel(pos); + } + + public void addValues(List labels) { + List values = new LinkedList<>(); + for (int element = 0; element < labels.size(); ++element) + values.add(0d); + + this._values = values; + } + + public void createTrapezoidalFunction(String[] labels) { + LabelLinguisticDomain currentLabel; + IMembershipFunction semantic; + + this.clearFuzzySet(); + + if (labels.length == 1) { + semantic = new TrapezoidalFunction(); + semantic.setLimits(new double[] { 0, 0, 1, 1 }); + + currentLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + currentLabel.initLabelLinguisticDomain(labels[0], semantic); + + this.addLabel(currentLabel); + } else { + int numLabels = labels.length; + double lower, central, upper, increment = 1d / (numLabels - 1), factor = 1e5; + + for (int i = 0; i < numLabels; ++i) { + lower = (i == 0) ? 0 : increment * (i - 1); + central = increment * i; + upper = (i == (numLabels - 1)) ? 1 : increment * (i + 1); + + lower = Math.round(lower * factor) / factor; + central = Math.round(central * factor) / factor; + upper = Math.round(upper * factor) / factor; + + semantic = new TrapezoidalFunction(); + semantic.setLimits(new double[] { lower, central, upper }); + + currentLabel = ContextInjectionFactory.make(LabelLinguisticDomain.class, context); + currentLabel.initLabelLinguisticDomain(labels[i], semantic); + + ContextInjectionFactory.inject(currentLabel, this.context); + + this.addLabel(currentLabel); + } + } + } + + public double chi() { + double result, valuesSum, sum; + int pos; + + if (this._labelSet.getCardinality() == 0) + return 0; + + sum = valuesSum = pos = 0; + + for (Double value : this._values) { + sum += value * pos++; + valuesSum += value; + } + + result = sum / valuesSum; + + return result; + } + + public boolean isFuzzy() { + int cardinality = this._labelSet.getCardinality(); + + if (cardinality == 0) + return false; + + FragmentFunction fragmentFunction = new FragmentFunction(); + FragmentFunction semantic; + Map pieces; + for (LabelLinguisticDomain label : this._labelSet.getLabels()) { + semantic = label.getSemantic().toFragmentFunction(); + pieces = semantic.getPieces(); + for (NumericRealDomain domain : pieces.keySet()) { + fragmentFunction.addPiece(domain, pieces.get(domain)); + fragmentFunction.simplify(); + } + } + + pieces = fragmentFunction.getPieces(); + if (pieces.size() == 1) { + Object[] values = pieces.values().toArray(); + LinearPieceFunction piece = (LinearPieceFunction) values[0]; + if (piece != null) + if ((Math.round(piece.getSlope() * 100d) / 100d == 0) + && (Math.round(piece.getCutOffY() * 100d) / 100d == 1)) + return true; + } + + return false; + } + + public boolean isOdd() { + return (this._labelSet.getCardinality() % 2 != 0); + } + + public boolean isTriangular() { + + if (this._labelSet.getCardinality() == 0) + return false; + + IMembershipFunction semantic; + for (LabelLinguisticDomain label : this._labelSet.getLabels()) { + semantic = label.getSemantic(); + if (semantic instanceof TrapezoidalFunction) { + if (!((TrapezoidalFunction) semantic).isTriangular()) + return false; + } else + return false; + } + + return true; + } + + public boolean isTOR() { + if (this.isFuzzy()) + if (this.isOdd()) + return this.isTriangular(); + + return false; + } + + public boolean isSymmetrical() { + + if (this._labelSet.getCardinality() == 0) + return false; + + double midPoint = this.midpoint(); + + if (midPoint != -1) { + LabelLinguisticDomain label1, label2; + int centralPos = this._labelSet.getCardinality() / 2; + + for (int i = 0; i < centralPos; ++i) { + label1 = this._labelSet.getLabels().get(i); + label2 = this._labelSet.getLabels().get((this._labelSet.getCardinality() - 1) - i); + if (!(label1.getSemantic().isSymmetrical(label2.getSemantic(), midPoint))) + return false; + } + return true; + } else + return false; + } + + @Override + public double midpoint() { + LabelLinguisticDomain label1, label2; + int centralPos = this._labelSet.getCardinality() / 2; + double midPoint; + + if (this.isOdd()) { + label1 = this._labelSet.getLabels().get(centralPos); + IMembershipFunction semantic = label1.getSemantic(); + if (!semantic.isSymmetrical()) + return -1; + else + midPoint = semantic.centroid(); + } else { + label1 = this._labelSet.getLabels().get(centralPos - 1); + label2 = this._labelSet.getLabels().get(centralPos); + + midPoint = (label2.getSemantic().centroid() + label1.getSemantic().centroid()) / 2d; + } + + return midPoint; + } + + public boolean isUniform() { + + int cardinality = this._labelSet.getCardinality(); + + if (cardinality <= 1) + return true; + + LabelLinguisticDomain label1 = this._labelSet.getLabels().get(0); + LabelLinguisticDomain label2 = this._labelSet.getLabels().get(1); + + double center1 = label1.getSemantic().getCenter().midpoint(); + double center2 = label2.getSemantic().getCenter().midpoint(); + double distance = center2 - center1; + double error = (1 / Math.pow(10, Double.toString(distance).length() - 2)) * 1.5; + double distanceLower = distance - error; + double distanceUpper = distance + error; + + for (int i = 2; i < cardinality; ++i) { + label1 = (LabelLinguisticDomain) label2.clone(); + label2 = this._labelSet.getLabels().get(i); + center1 = center2; + center2 = label2.getSemantic().getCenter().midpoint(); + distance = center2 - center1; + if (!((distanceLower <= distance) && (distance <= distanceUpper))) + return false; + } + + return true; + } + + public boolean belongtoFuzzySet(TrapezoidalFunction function) { + for (LabelLinguisticDomain l : this._labelSet.getLabels()) { + if (l.getSemantic().compareTo(function) == 0) { + return true; + } + } + + return false; + } + + public boolean isBLTS() { + if (this.isTOR()) + if (this.isSymmetrical()) + return this.isUniform(); + + return false; + } + + @Override + public String formatDescriptionDomain() { + String result = ""; //$NON-NLS-1$ + int cardinality; + + if ((cardinality = this._labelSet.getCardinality()) != 0) { + result += "("; //$NON-NLS-1$ + for (int i = 0; i < cardinality - 1; ++i) + result += this._labelSet.getLabels().get(i).getName() + ", "; //$NON-NLS-1$ + result += this._labelSet.getLabels().get(cardinality - 1).getName() + ")"; //$NON-NLS-1$ + } + + return result.toString(); + } + + @Override + public String toString() { + String result = ""; //$NON-NLS-1$ + int cardinality = this._labelSet.getCardinality(); + + if (cardinality > 0) + for (int i = 0; i < cardinality; ++i) { + if (i > 0) + result += ", "; //$NON-NLS-1$ + result += "[" + this._labelSet.getLabels() //$NON-NLS-1$ + .get(i) + ";" + this._values.get(i) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + return "{" + result + "}"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public String toStringExport() { + + StringBuilder result = new StringBuilder(); + + int cardinality = this._labelSet.getCardinality(); + if (cardinality > 0) + for (int pos = 0; pos < cardinality; pos++) { + if (pos > 0) + result.append(", "); //$NON-NLS-1$ + result.append("["); //$NON-NLS-1$ + result.append(this._labelSet.getLabel(pos)); + result.append("::"); //$NON-NLS-1$ + result.append(((TrapezoidalFunction) this._labelSet.getLabel(pos).getSemantic()).toStringExport()); + result.append(";"); //$NON-NLS-1$ + result.append(this._values.get(pos)); + result.append("]"); //$NON-NLS-1$ + } + + return "{" + result + "}"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(17, 31); + hcb.append(super.hashCode()); + return hcb.toHashCode(); + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) + return true; + + if (obj == null) + return false; + + if (this.getName() == null) + return false; + + if (this.getClass() != obj.getClass()) + return false; + + final FuzzySet other = (FuzzySet) obj; + + EqualsBuilder eb = new EqualsBuilder(); + eb.append(this._values, other._values); + + return eb.isEquals(); + } + + @Override + public Object clone() { + Object result; + + result = super.clone(); + + List values = new LinkedList<>(); + for (Double value : this._values) + values.add(Double.valueOf(value)); + + ((FuzzySet) result)._values = values; + ((FuzzySet) result)._labelSet = (LabelSetLinguisticDomain) this._labelSet.clone(); + + return result; + } + + @Override + public void write(XMLStreamWriter writer) throws XMLStreamException { + writer.writeStartElement(FuzzySet.Fields.values.toString()); + for (Double value : _values) { + writer.writeStartElement(FuzzySet.Fields.value.toString()); + writer.writeAttribute(FuzzySet.Fields.v.toString(), value.toString()); + writer.writeEndElement(); + } + writer.writeEndElement(); + this._labelSet.write(writer); + + } + + @Override + public void read(WNode node) { + + if (node.getVersion().equals("3.0")) //$NON-NLS-1$ + this.readFS3(node); + else + this.readFS4(node); + } + + private void readFS3(WNode node) { + WNode vNode = node.getFirst(FuzzySet.Fields.values); + this.readValues(vNode); + + WNode lNode = node.getFirst(FuzzySet.Fields.labelSet); + this.readLabelSet(lNode); + } + + private void readFS4(WNode node) { + this.readValues(node.getFirst(FuzzySet.Fields.values)); + + this.readLabelSet(node.getFirst(Fields.labelSet)); + } + + private void readValues(WNode node) { + List values = node.getChildren(); + for (WNode item : values) { + String valueS = item.getAttribute(FuzzySet.Fields.v); + Double value = Double.valueOf(valueS); + this._values.add(value); + } + } + + private void readLabelSet(WNode node) { + this._labelSet = ContextInjectionFactory.make(LabelSetLinguisticDomain.class, this.context); + this._labelSet.read(node); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/FragmentFunction.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/FragmentFunction.java new file mode 100644 index 0000000..8ccbc28 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/FragmentFunction.java @@ -0,0 +1,216 @@ +package flintstones.domain.fuzzyset.function; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import flintstones.domain.fuzzyset.function.types.LinearPieceFunction; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.helper.validator.Validator; + +@SuppressWarnings("javadoc") +public class FragmentFunction { + + Map _pieces; + + public FragmentFunction() { + this._pieces = new HashMap<>(); + } + + public Map getPieces() { + return this._pieces; + } + + public void addPiece(NumericRealDomain domain, IFragmentFunction piece) { + Validator.notNull(domain); + Validator.notNull(piece); + + double otherMin = domain.getMin(); + double otherMax = domain.getMax(); + + if (otherMin == otherMax) + return; + + double currentMin, currentMax; + NumericRealDomain lower, central, upper; + IFragmentFunction currentPiece; + + Set domains = this._pieces.keySet(); + + for (NumericRealDomain currentDomain : domains) { + currentMin = currentDomain.getMin(); + currentMax = currentDomain.getMax(); + currentPiece = this._pieces.get(currentDomain); + + switch (Double.compare(currentMin, otherMin)) { + case -1: + if (currentMax > otherMin) { + switch (Double.compare(currentMax, otherMax)) { + case -1: + lower = new NumericRealDomain(); + lower.setMinMax(currentMin, otherMin); + central = new NumericRealDomain(); + central.setMinMax(otherMin, currentMax); + upper = new NumericRealDomain(); + upper.setMinMax(currentMax, otherMax); + + this._pieces.remove(currentDomain); + this._pieces.put(lower, currentPiece); + this._pieces.put(central, piece.sumFunctions(currentPiece)); + this.addPiece(upper, piece); + break; + case 0: + lower = new NumericRealDomain(); + lower.setMinMax(currentMin, otherMin); + upper = new NumericRealDomain(); + upper.setMinMax(otherMin, otherMax); + + this._pieces.remove(currentDomain); + this._pieces.put(lower, currentPiece); + this._pieces.put(upper, piece.sumFunctions(currentPiece)); + break; + case 1: + lower = new NumericRealDomain(); + lower.setMinMax(currentMin, otherMin); + central = new NumericRealDomain(); + central.setMinMax(otherMin, otherMax); + upper = new NumericRealDomain(); + upper.setMinMax(otherMax, currentMax); + + this._pieces.remove(currentDomain); + this._pieces.put(lower, currentPiece); + this._pieces.put(central, piece.sumFunctions(currentPiece)); + this._pieces.put(upper, currentPiece); + break; + } + + return; + } + + break; + + case 0: + + switch (Double.compare(currentMax, otherMax)) { + case -1: + lower = new NumericRealDomain(); + lower.setMinMax(otherMin, currentMax); + upper = new NumericRealDomain(); + upper.setMinMax(currentMax, otherMax); + + this._pieces.remove(currentDomain); + this._pieces.put(lower, piece.sumFunctions(currentPiece)); + this.addPiece(upper, piece); + break; + case 0: + this._pieces.remove(currentDomain); + this._pieces.put(domain, piece.sumFunctions(currentPiece)); + break; + case 1: + lower = new NumericRealDomain(); + lower.setMinMax(currentMin, otherMax); + upper = new NumericRealDomain(); + upper.setMinMax(otherMax, currentMax); + + this._pieces.remove(currentDomain); + this._pieces.put(lower, piece.sumFunctions(currentPiece)); + this._pieces.put(upper, currentPiece); + break; + } + + return; + + case 1: + + if (otherMax > currentMin) { + + switch (Double.compare(otherMax, currentMax)) { + case -1: + lower = new NumericRealDomain(); + lower.setMinMax(otherMin, currentMin); + central = new NumericRealDomain(); + central.setMinMax(currentMin, otherMax); + upper = new NumericRealDomain(); + upper.setMinMax(otherMax, currentMax); + + this._pieces.remove(currentDomain); + this._pieces.put(central, piece.sumFunctions(currentPiece)); + this._pieces.put(upper, currentPiece); + this.addPiece(lower, piece); + break; + + case 0: + lower = new NumericRealDomain(); + lower.setMinMax(otherMin, currentMin); + upper = new NumericRealDomain(); + upper.setMinMax(currentMin, otherMax); + + this._pieces.remove(currentDomain); + this._pieces.put(upper, piece.sumFunctions(currentPiece)); + this.addPiece(lower, piece); + break; + case 1: + lower = new NumericRealDomain(); + lower.setMinMax(otherMin, currentMin); + central = new NumericRealDomain(); + central.setMinMax(currentMin, currentMax); + upper = new NumericRealDomain(); + upper.setMinMax(currentMax, otherMax); + + this._pieces.remove(currentDomain); + this._pieces.put(central, piece.sumFunctions(currentPiece)); + this.addPiece(lower, piece); + this.addPiece(upper, piece); + break; + } + + return; + + } + + break; + } + } + this._pieces.put(domain, piece); + } + + public void simplify() { + Map simplifyPieces = new HashMap<>(); + LinearPieceFunction piece1, piece2; + NumericRealDomain domain; + + for (NumericRealDomain domain1 : this._pieces.keySet()) { + piece1 = (LinearPieceFunction) this._pieces.get(domain1); + + for (NumericRealDomain domain2 : simplifyPieces.keySet()) { + piece2 = (LinearPieceFunction) simplifyPieces.get(domain2); + + if (domain1.getMin() == domain2.getMax()) { + if (piece1.equals(piece2)) { + domain = new NumericRealDomain(); + domain.setMinMax(domain2.getMin(), domain1.getMax()); + this._pieces.remove(domain1); + this._pieces.remove(domain2); + this._pieces.put(domain, piece1); + this.simplify(); + return; + } + } else if (domain1.getMax() == domain2.getMin()) + if (piece1.equals(piece2)) { + domain = new NumericRealDomain(); + domain.setMinMax(domain1.getMin(), domain2.getMax()); + this._pieces.remove(domain1); + this._pieces.remove(domain2); + this._pieces.put(domain, piece1); + this.simplify(); + return; + } + } + + simplifyPieces.put(domain1, piece1); + } + + this._pieces = simplifyPieces; + + } +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/IFragmentFunction.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/IFragmentFunction.java new file mode 100644 index 0000000..9291152 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/IFragmentFunction.java @@ -0,0 +1,8 @@ +package flintstones.domain.fuzzyset.function; + +@SuppressWarnings("javadoc") +public interface IFragmentFunction { + + public IFragmentFunction sumFunctions(IFragmentFunction other); + +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/types/LinearPieceFunction.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/types/LinearPieceFunction.java new file mode 100644 index 0000000..59b4660 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/types/LinearPieceFunction.java @@ -0,0 +1,72 @@ +package flintstones.domain.fuzzyset.function.types; + +import org.apache.commons.lang.builder.HashCodeBuilder; + +import flintstones.domain.fuzzyset.function.IFragmentFunction; +import flintstones.helper.validator.Validator; + +@SuppressWarnings("javadoc") +public class LinearPieceFunction implements IFragmentFunction { + + private final static double EPSILON = 0.00001; + + private final double _slope; + private final double _cutOffY; + + public LinearPieceFunction(Double slope, Double cutOff) { + this._slope = slope; + this._cutOffY = cutOff; + } + + public double getSlope() { + return this._slope; + } + + public double getCutOffY() { + return this._cutOffY; + } + + @Override + public IFragmentFunction sumFunctions(IFragmentFunction other) { + Validator.notNull(other); + Validator.notIllegalElementType(other, new String[] { this.getClass() + .toString() }); + + return new LinearPieceFunction(this._slope + ((LinearPieceFunction) other)._slope, this._cutOffY + ((LinearPieceFunction) other)._cutOffY); + } + + @Override + public String toString() { + return (this._cutOffY < 0) ? (this._slope + "x " + this._cutOffY) : (this._slope + "x + " + this._cutOffY); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) + return true; + + if (obj == null) + return false; + + if (obj.getClass() != this.getClass()) + return false; + + final LinearPieceFunction other = (LinearPieceFunction) obj; + + if (Math.abs(this._slope - other._slope) < LinearPieceFunction.EPSILON) + if (Math.abs(this._cutOffY - other._cutOffY) < LinearPieceFunction.EPSILON) + return true; + return false; + } + + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(17, 31); + hcb.append(this._cutOffY); + hcb.append(this._slope); + return hcb.hashCode(); + + } + +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/types/TrapezoidalFunction.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/types/TrapezoidalFunction.java new file mode 100644 index 0000000..ff51526 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/function/types/TrapezoidalFunction.java @@ -0,0 +1,549 @@ +package flintstones.domain.fuzzyset.function.types; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.DecimalFormat; +import java.text.MessageFormat; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.commons.lang.builder.HashCodeBuilder; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.FragmentFunction; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.validator.Validator; + +@SuppressWarnings("javadoc") +public class TrapezoidalFunction extends IMembershipFunction { + + private final static double EPSILON = 0.000001; + private final static double ALPHA = 1; + + protected double _a; + protected double _b; + protected double _c; + protected double _d; + + public static enum Fields implements ExtensionEnum { + a, b, c, d + }; + + public TrapezoidalFunction() { + super(); + this._a = this._b = this._c = this._d = 0d; + } + + public TrapezoidalFunction(double a, double b, double c, double d) { + this._a = a; + this._b = b; + this._c = c; + this._d = d; + } + + public TrapezoidalFunction(double[] limits) { + this(); + + Validator.notNull(limits); + Validator.notInvalidSize(limits.length, 3, 4); + + // Commented for usage in FuzzyVikor method +// for(double limit: limits) { +// Validator.notNegative(limit); +// } + + if (limits.length == 3) { + _a = limits[0]; + _b = _c = limits[1]; + _d = limits[2]; + } else if (limits.length == 4) { + _a = limits[0]; + _b = limits[1]; + _c = limits[2]; + _d = limits[3]; + } + } + + public double getA() { + return _a; + } + + public double setA(double a) { + return this._a = a; + } + + public double getB() { + return _b; + } + + public double setB(double b) { + return this._b = b; + } + + public double getC() { + return _c; + } + + public double setC(double c) { + return this._c = c; + } + + public double getD() { + return _d; + } + + public double setD(double d) { + return this._d = d; + } + + public double[] getLimits() { + double limits[] = new double[4]; + limits[0] = this._a; + limits[1] = this._b; + limits[2] = this._c; + limits[3] = this._d; + + return limits; + } + + @Override + public void setLimits(double[] limits) { + Validator.notNull(limits); + Validator.notInvalidSize(limits.length, 3, 4); + + // Commented for usage in FuzzyVikor method +// for (double limit : limits) +// Validator.notNegative(limit); + + if (limits.length == 3) { + this._a = limits[0]; + this._b = this._c = limits[1]; + this._d = limits[2]; + } else if (limits.length == 4) { + this._a = limits[0]; + this._b = limits[1]; + this._c = limits[2]; + this._d = limits[3]; + } + } + + @Override + public FragmentFunction toFragmentFunction() { + FragmentFunction result = new FragmentFunction(); + LinearPieceFunction piece; + NumericRealDomain domain; + double slope, cutoffY; + + if (this._a != this._b) { + slope = 1d / (this._b - this._a); + cutoffY = -(slope * this._a); + piece = new LinearPieceFunction(slope, cutoffY); + domain = new NumericRealDomain(); + domain.setMinMax(this._a, this._b); + result.addPiece(domain, piece); + } + + if (this._b != this._c) { + slope = 0; + cutoffY = 1; + piece = new LinearPieceFunction(slope, cutoffY); + domain = new NumericRealDomain(); + domain.setMinMax(this._b, this._c); + result.addPiece(domain, piece); + } + + if (this._c != this._d) { + slope = 1d / (this._c - this._d); + cutoffY = -(slope * this._d); + piece = new LinearPieceFunction(slope, cutoffY); + domain = new NumericRealDomain(); + domain.setMinMax(this._c, this._d); + result.addPiece(domain, piece); + } + + return result; + } + + @Override + public boolean isSymmetrical() { + return (Math.abs((this._b - this._a) - (this._d - this._c)) < TrapezoidalFunction.EPSILON); + } + + @Override + public boolean isSymmetrical(IMembershipFunction other, double center) { + double displacement = (center - this._d) * 2; + + TrapezoidalFunction clone = (TrapezoidalFunction) this.clone(); + + clone._a = this._d; + clone._b = clone._a + (this._d - this._c); + clone._c = clone._b + (this._c - this._b); + clone._d = clone._c + (this._b - this._a); + + clone._a += displacement; + clone._b += displacement; + clone._c += displacement; + clone._d += displacement; + + return clone.equals(other); + } + + @Override + public NumericRealDomain getCenter() { + NumericRealDomain result = new NumericRealDomain(); + result.setMinMax(this._b, this._c); + + return result; + } + + @Override + public NumericRealDomain getCoverage() { + NumericRealDomain result = new NumericRealDomain(); + result.setMinMax(this._a, this._d); + + return result; + } + + @Override + public double getMembershipValue(double x) { + double result; + + if (x >= this._b && x <= this._c) + result = 1d; + else if (x <= this._a || x >= this._d) + result = 0d; + else if (x < this._b) + result = (x - this._a) / (this._b - this._a); + else + result = (x - this._d) / (this._c - this._d); + + return result; + } + + public boolean isTriangular() { + return (this._b == this._c); + } + + @Override + public double centroid() { + double centroidLeft, centroidCenter, centroidRight, areaLeft, areaCenter, areaRight, areaSum, result; + + centroidLeft = (this._a + (2 * this._b)) / 3.; + centroidCenter = (this._b + this._c) / 2.; + centroidRight = ((2 * this._c) + this._d) / 3.; + + areaLeft = (this._b - this._a) / 2.; + areaCenter = (this._c - this._b); + areaRight = (this._d - this._c) / 2.; + areaSum = areaLeft + areaCenter + areaRight; + + result = ((centroidLeft * areaLeft) + (centroidCenter * areaCenter) + (centroidRight * areaRight)) / areaSum; + + return result; + } + + @Override + public double maxMin(double max, double min) { + Validator.notDisorder(new double[] { min, max }, false); + + if ((min >= this._b) && (max <= this._c)) + return 1d; + if (min <= this._b && max >= this._c) + return 1d; + else if (max < this._b) + return this.getMembershipValue(max); + else + return this.getMembershipValue(min); + } + + @Override + public double maxMin(IMembershipFunction function, FuzzySet blts, FuzzySet domainValuation) { + TrapezoidalFunction tmf; + + Validator.notNull(function); + if (function instanceof TrapezoidalFunction) + tmf = (TrapezoidalFunction) function; + else + throw new IllegalArgumentException("TrapezoidalFunction_Invalid_element_type"); //$NON-NLS-1$ + + // PATCH for only 1 domain + if (blts.equals(domainValuation)) { + if (tmf.equals(this)) { + return 1; + } else if (blts.belongtoFuzzySet(tmf)) { + return 0; + } + } + + double values[] = new double[5]; + double result; + double slopeThisAB, slopeFunctionAB, slopeThisCD, slopeFunctionCD; + + values[0] = this.maxMin(tmf._c, tmf._b); + + if (values[0] == 1) + return 1d; + + if (this._b == this._a) + values[1] = values[2] = tmf.getMembershipValue(this._a); + else { + slopeThisAB = 1d / (this._b - this._a); + + if (tmf._a == tmf._b) + values[1] = this.getMembershipValue(tmf._a); + else { + slopeFunctionAB = 1d / (tmf._b - tmf._a); + + if (slopeThisAB == slopeFunctionAB) + values[1] = 0d; + else + values[1] = slopeFunctionAB * slopeThisAB * (this._a - tmf._a) / (slopeThisAB - slopeFunctionAB); + } + + if (tmf._c == tmf._d) + values[2] = this.getMembershipValue(tmf._c); + else { + slopeFunctionCD = 1d / (tmf._c - tmf._d); + values[2] = slopeFunctionCD * slopeThisAB * (this._a - tmf._d) / (slopeThisAB - slopeFunctionCD); + } + } + + if (this._c == this._d) + values[3] = values[4] = tmf.getMembershipValue(this._c); + else { + slopeThisCD = 1d / (this._c - this._d); + + if (tmf._a == tmf._b) + values[3] = this.getMembershipValue(tmf._a); + else { + slopeFunctionAB = 1d / (tmf._b - tmf._a); + values[3] = slopeFunctionAB * slopeThisCD * (this._d - tmf._a) / (slopeThisCD - slopeFunctionAB); + } + + if (tmf._c == tmf._d) + values[4] = this.getMembershipValue(tmf._c); + else { + slopeFunctionCD = 1d / (tmf._c - tmf._d); + + if (slopeThisCD == slopeFunctionCD) + values[4] = 0d; + else + values[4] = slopeFunctionCD * slopeThisCD * (this._d - tmf._d) / (slopeThisCD - slopeFunctionCD); + } + } + + for (int i = 1; i < values.length; i++) + if (values[i] > 1) + values[i] = 0d; + + result = Math.max(values[0], Math.max(values[1], Math.max(values[2], Math.max(values[3], values[4])))); + + return result; + } + + public TrapezoidalFunction addition(TrapezoidalFunction tpf) { + + double[] limits = new double[] { this._a + tpf._a, this._b + tpf._b, this._c + tpf._c, this._d + tpf._d }; + TrapezoidalFunction tp = new TrapezoidalFunction(limits); + return tp; + } + + public TrapezoidalFunction subtraction(TrapezoidalFunction tpf) { + + double[] limits = new double[] { this._a - tpf._d, this._b - tpf._c, this._c - tpf._b, this._d - tpf._a }; + TrapezoidalFunction tp = new TrapezoidalFunction(limits); + return tp; + } + + public TrapezoidalFunction multiplication(TrapezoidalFunction tpf) { + + double[] limits = new double[] { this._a * tpf._a, this._b * tpf._b, this._c * tpf._c, this._d * tpf._d }; + TrapezoidalFunction tp = new TrapezoidalFunction(limits); + return tp; + } + + public TrapezoidalFunction division(TrapezoidalFunction tpf) { + + double[] limits = new double[] { this._a / tpf._d, this._b / tpf._c, this._c / tpf._b, this._d / tpf._a }; + TrapezoidalFunction tp = new TrapezoidalFunction(limits); + return tp; + } + + public TrapezoidalFunction multiplicationScalar(double scalar) { + double[] limits; + + if (scalar >= 0) + limits = new double[] { this._a * scalar, this._b * scalar, this._c * scalar, this._d * scalar }; + else + limits = new double[] { this._d * scalar, this._c * scalar, this._b * scalar, this._a * scalar }; + + TrapezoidalFunction tp = new TrapezoidalFunction(limits); + return tp; + } + + public TrapezoidalFunction divisionScalar(double scalar) { + double[] limits = new double[] { _a / scalar, _b / scalar, _c / scalar, _d / scalar }; + TrapezoidalFunction tp = new TrapezoidalFunction(limits); + return tp; + } + + public TrapezoidalFunction potence(double scalar) { + double[] limits = new double[] { Math.pow(this._a, scalar), Math.pow(this._b, scalar), + Math.pow(this._c, scalar), Math.pow(this._d, scalar) }; + TrapezoidalFunction tp = new TrapezoidalFunction(limits); + return tp; + } + + public Double[] computeAlphaCut() { + Double[] result = new Double[2]; + result[0] = _a + ALPHA * (_b - _a); + result[1] = _d - ALPHA * (_d - _c); + return result; + } + + public TrapezoidalFunction additionAlphaCuts(TrapezoidalFunction fuzzyNumber) { + TrapezoidalFunction tp = new TrapezoidalFunction(); + tp.setLimits(new double[] { this._a + fuzzyNumber._a, this._b + fuzzyNumber._b, this._c + fuzzyNumber._c, + this._d + fuzzyNumber._d }); + return tp; + } + + public TrapezoidalFunction subtractionAlphaCuts(TrapezoidalFunction fuzzyNumber) { + TrapezoidalFunction tp = new TrapezoidalFunction(); + tp.setLimits(new double[] { this._a - fuzzyNumber._d, this._b - fuzzyNumber._c, this._c - fuzzyNumber._b, + this._d - fuzzyNumber._a }); + return tp; + } + + public TrapezoidalFunction multiplicationAlphaCuts(TrapezoidalFunction fuzzyNumber) { + TrapezoidalFunction tp = new TrapezoidalFunction(); + tp.setLimits(new double[] { this._a * fuzzyNumber._a, this._b * fuzzyNumber._b, this._c * fuzzyNumber._c, + this._d * fuzzyNumber._d }); + return tp; + } + + public TrapezoidalFunction divisionAlphaCuts(TrapezoidalFunction fuzzyNumber) { + TrapezoidalFunction tp = new TrapezoidalFunction(); + tp.setLimits(new double[] { this._a / fuzzyNumber._d, this._b / fuzzyNumber._c, this._c / fuzzyNumber._b, + this._d / fuzzyNumber._a }); + return tp; + } + + public double getSimpleDefuzzifiedValue() { + return (this._a + (2d * this._b) + (2d * this._c) + this._d) / 6d; + } + + public double distance(TrapezoidalFunction tpf, double P) { + double acum = 0; + double limits1[] = this.getLimits(), limits2[] = tpf.getLimits(); + + for (int i = 0; i < 4; ++i) + acum += Math.pow(Math.abs(limits1[i] - limits2[i]), P); + + return Math.pow(acum, 1 / P); + } + + @Override + public String toString() { + DecimalFormat df = new DecimalFormat("#.########"); + df.setRoundingMode(RoundingMode.CEILING); + + if (this._b == this._c) { + String template = "T({0}, {1}, {2})"; + return MessageFormat.format(template, df.format(this._a), df.format(this._b), df.format(this._d)) + .toString(); + } + String template = "T({0}, {1}, {2}, {3})"; + return MessageFormat + .format(template, df.format(this._a), df.format(this._b), df.format(this._c), df.format(this._d)) + .toString(); + } + + public String toStringExport() { + + if (this._b == this._c) { + String template = "Trapezoidal({0}, {1}, {2})"; + return MessageFormat.format(template, this._a, this._b, this._d).toString(); + } + String template = "Trapezoidal({0}, {1}, {2}, {3})"; + return MessageFormat.format(template, this._a, this._b, this._c, this._d).toString(); + + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) + return true; + + if (obj == null) + return false; + + if (this.getClass() != obj.getClass()) + return false; + + final TrapezoidalFunction other = (TrapezoidalFunction) obj; + + double aRound = Math.abs(new BigDecimal(this._a).setScale(3, RoundingMode.HALF_UP).doubleValue()); + double bRound = Math.abs(new BigDecimal(this._b).setScale(3, RoundingMode.HALF_UP).doubleValue()); + double cRound = Math.abs(new BigDecimal(this._c).setScale(3, RoundingMode.HALF_UP).doubleValue()); + double dRound = Math.abs(new BigDecimal(this._d).setScale(3, RoundingMode.HALF_UP).doubleValue()); + double aOtherRound = Math.abs(new BigDecimal(other._a).setScale(3, RoundingMode.HALF_UP).doubleValue()); + double bOtherRound = Math.abs(new BigDecimal(other._b).setScale(3, RoundingMode.HALF_UP).doubleValue()); + double cOtherRound = Math.abs(new BigDecimal(other._c).setScale(3, RoundingMode.HALF_UP).doubleValue()); + double dOtherRound = Math.abs(new BigDecimal(other._d).setScale(3, RoundingMode.HALF_UP).doubleValue()); + + if (aRound == aOtherRound) + if (bRound == bOtherRound) + if (cRound == cOtherRound) + if (dRound == dOtherRound) + return true; + + return false; + } + + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(17, 31); + hcb.append(this._a); + hcb.append(this._b); + hcb.append(this._c); + hcb.append(this._d); + return hcb.hashCode(); + } + + @Override + public Object clone() { + TrapezoidalFunction tp = new TrapezoidalFunction(); + tp.setLimits(this.getLimits()); + return tp; + } + + @Override + public int compareTo(IMembershipFunction other) { + Validator.notNull(other); + + return Double.compare(this.centroid(), other.centroid()); + } + + @Override + public void write(XMLStreamWriter writer) throws XMLStreamException { + writer.writeAttribute(Fields.a.toString(), Double.toString(this._a)); + writer.writeAttribute(Fields.b.toString(), Double.toString(this._b)); + writer.writeAttribute(Fields.c.toString(), Double.toString(this._c)); + writer.writeAttribute(Fields.d.toString(), Double.toString(this._d)); + } + + @Override + public void read(WNode node) { + this._a = Double.parseDouble(node.getAttribute(Fields.a)); + this._b = Double.parseDouble(node.getAttribute(Fields.b)); + this._c = Double.parseDouble(node.getAttribute(Fields.c)); + this._d = Double.parseDouble(node.getAttribute(Fields.d)); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticQualityInstance.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticQualityInstance.java new file mode 100644 index 0000000..bd26a3d --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticQualityInstance.java @@ -0,0 +1,29 @@ +package flintstones.domain.fuzzyset.instance; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class LinguisticQualityInstance extends DomainInstance { + + @Override + public Domain getInstance() { + FuzzySet domain = (FuzzySet) getDomain(); + + String[] labels = new String[] { + "Muy Malo", + "Malo", + "Normal", + "Bueno", + "Muy bueno" + }; + + String name = getLabel(); + + domain.createTrapezoidalFunction(labels); + domain.setName(name); + return domain; + + } + +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticRandomInstance.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticRandomInstance.java new file mode 100644 index 0000000..d912194 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticRandomInstance.java @@ -0,0 +1,36 @@ +package flintstones.domain.fuzzyset.instance; + +import java.util.Random; + +import org.apache.commons.lang.RandomStringUtils; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class LinguisticRandomInstance extends DomainInstance { + + @Override + public Domain getInstance() { + + FuzzySet domain = (FuzzySet) getDomain(); + + Random rand = new Random(); + int size = rand.nextInt( 9 - 3 + 1 ) + 3; + + + String[] labels = new String[size]; + String base = RandomStringUtils.randomAlphabetic(3); + for( int i = 0; i < size; i++ ) { + labels[i] = "s_"+ i; + } + + String name = getLabel() + "_" + base; + + domain.createTrapezoidalFunction(labels); + domain.setName(name); + return domain; + + } + +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS3Instance.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS3Instance.java new file mode 100644 index 0000000..1bfb203 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS3Instance.java @@ -0,0 +1,26 @@ +package flintstones.domain.fuzzyset.instance; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class LinguisticS3Instance extends DomainInstance { + + @Override + public Domain getInstance() { + FuzzySet domain = (FuzzySet) getDomain(); + + String[] labels = new String[] { + "Low", + "Medium", + "High" + }; + + String name = getLabel(); + + domain.createTrapezoidalFunction(labels); + domain.setName(name); + return domain; + + } +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS5Instance.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS5Instance.java new file mode 100644 index 0000000..9023d0d --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS5Instance.java @@ -0,0 +1,28 @@ +package flintstones.domain.fuzzyset.instance; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class LinguisticS5Instance extends DomainInstance { + + @Override + public Domain getInstance() { + FuzzySet domain = (FuzzySet) getDomain(); + + String[] labels = new String[] { + "Very Low", + "Low", + "Medium", + "High", + "Very High" + }; + + String name = getLabel(); + + domain.createTrapezoidalFunction(labels); + domain.setName(name); + return domain; + + } +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS7Instance.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS7Instance.java new file mode 100644 index 0000000..7e34407 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS7Instance.java @@ -0,0 +1,30 @@ +package flintstones.domain.fuzzyset.instance; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class LinguisticS7Instance extends DomainInstance { + + @Override + public Domain getInstance() { + FuzzySet domain = (FuzzySet) getDomain(); + + String[] labels = new String[] { + "Nothing", + "Very Low", + "Low", + "Medium", + "High", + "Very High", + "Perfect" + }; + + String name = getLabel(); + + domain.createTrapezoidalFunction(labels); + domain.setName(name); + return domain; + + } +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS9Instance.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS9Instance.java new file mode 100644 index 0000000..6880e8f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/instance/LinguisticS9Instance.java @@ -0,0 +1,32 @@ +package flintstones.domain.fuzzyset.instance; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class LinguisticS9Instance extends DomainInstance { + + @Override + public Domain getInstance() { + FuzzySet domain = (FuzzySet) getDomain(); + + String[] labels = new String[] { + "Nothing", + "Very Low", + "Low", + "Slightly Low", + "Medium", + "Slightly High", + "High", + "Very High", + "Perfect" + }; + + String name = getLabel(); + + domain.createTrapezoidalFunction(labels); + domain.setName(name); + return domain; + + } +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/label/LabelLinguisticDomain.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/label/LabelLinguisticDomain.java new file mode 100644 index 0000000..dec08bc --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/label/LabelLinguisticDomain.java @@ -0,0 +1,154 @@ +package flintstones.domain.fuzzyset.label; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.validator.Validator; + +@SuppressWarnings("javadoc") +public class LabelLinguisticDomain implements Cloneable, Comparable { + + @Inject + IEclipseContext context; + + private String _name; + private IMembershipFunction _semantic; + + public static enum Fields implements ExtensionEnum { + semantic, type + }; + + public LabelLinguisticDomain() { + _name = ""; + _semantic = null; + } + + public void initLabelLinguisticDomain(String name, IMembershipFunction semantic) { + Validator.notEmpty(name); + Validator.notNull(semantic); + + this._name = name; + this._semantic = semantic; + } + + @PostConstruct + private void init() { + if (this.context == null) + throw new Error(); + } + + public String getName() { + return this._name; + } + + public void setName(String name) { + this._name = name; + } + + public IMembershipFunction getSemantic() { + return this._semantic; + } + + public void setSemantic(IMembershipFunction semantic) { + this._semantic = semantic; + } + + @Override + public String toString() { + return this._name; + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) + return true; + + if (obj == null) + return false; + + if (this.getClass() != obj.getClass()) + return false; + + final LabelLinguisticDomain other = (LabelLinguisticDomain) obj; + + EqualsBuilder eb = new EqualsBuilder(); + eb.append(this._name, other._name); + eb.append(this._semantic, other._semantic); + + return eb.isEquals(); + + } + + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(17, 31); + hcb.append(this._name); + hcb.append(this._semantic); + return hcb.hashCode(); + } + + @Override + public Object clone() { + Object result = null; + + try { + result = super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + + ((LabelLinguisticDomain) result)._name = new String(this._name); + ((LabelLinguisticDomain) result)._semantic = (IMembershipFunction) this._semantic.clone(); + + return result; + + } + + @Override + public int compareTo(LabelLinguisticDomain other) { + Validator.notNull(other); + + return this._semantic.compareTo(other._semantic); + } + + public void write(XMLStreamWriter writer) throws XMLStreamException { + writer.writeStartElement(Fields.semantic.toString()); + writer.writeAttribute(Fields.type.toString(), this._semantic.getClass() + .getName()); + this._semantic.write(writer); + writer.writeEndElement(); + } + + public void read(WNode node) { + WNode nnode = node.getFirst(Fields.semantic); + + // Compatibilidad FS3-FS4 + String type = nnode.getAttribute(Fields.type); + if (type.equals("sinbad2.domain.linguistic.fuzzy.function.types.TrapezoidalFunction")) //$NON-NLS-1$ + type = "flintstones.domain.fuzzyset.function.types.TrapezoidalFunction"; //$NON-NLS-1$ + + Class function = null; + try { + function = Class.forName(type); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + + this._semantic = (IMembershipFunction) ContextInjectionFactory.make(function, this.context); + + this._semantic.read(nnode); + + } + +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/label/LabelSetLinguisticDomain.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/label/LabelSetLinguisticDomain.java new file mode 100644 index 0000000..1038636 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/label/LabelSetLinguisticDomain.java @@ -0,0 +1,263 @@ +package flintstones.domain.fuzzyset.label; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.messages.Messages; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.validator.Validator; + +@SuppressWarnings("javadoc") +public class LabelSetLinguisticDomain implements Cloneable { + + @Inject + @Translation + private Messages messages; + + @Inject + IEclipseContext context; + + protected List _labels = new LinkedList<>(); + + public static enum Fields implements ExtensionEnum { + label, labels, labelSet, position, name + }; + + public LabelSetLinguisticDomain() { + } + + public void setLabels(List labels) { + Validator.notNull(labels); + + for (LabelLinguisticDomain label : labels) + this.addLabel(label); + + this._labels = labels; + } + + public List getLabels() { + return this._labels; + } + + public ArrayList getLabelsName() { + ArrayList labelsName = new ArrayList<>(); + + for(int i = 0; i < _labels.size(); ++i) { + labelsName.add(_labels.get(i).getName()); + } + + return labelsName; + } + + public void addLabel(LabelLinguisticDomain label) { + this.addLabel(this.getCardinality(), label); + } + + public void addLabel(int pos, LabelLinguisticDomain label) { + Validator.notNull(label); + Validator.notInvalidSize(pos, 0, this.getCardinality()); + + if (this.containsLabel(label.getName())) + throw new IllegalArgumentException(this.messages.LabelSetLinguisticDomain_duplicated_label); + + this._labels.add(pos, label); + } + + public void removeLabel(int pos) { + Validator.notEmpty(this._labels.toArray()); + Validator.notInvalidSize(pos, 0, this.getCardinality() - 1); + + this._labels.remove(pos); + } + + public void removeLabel(LabelLinguisticDomain label) { + + if (label == null) + return; + + int pos = this.getPos(label); + + if (pos != -1) + this.removeLabel(pos); + } + + public boolean containsLabel(String name) { + return (this.getPos(name) != -1); + } + + public boolean containsLabel(LabelLinguisticDomain label) { + return this._labels.contains(label); + } + + public int getCardinality() { + return this._labels.size(); + } + + public LabelLinguisticDomain getLabel(int pos) { + Validator.notEmpty(this._labels.toArray()); + Validator.notInvalidSize(pos, 0, this.getCardinality() - 1); + + return this._labels.get(pos); + } + + public LabelLinguisticDomain getLabel(String name) { + int pos = this.getPos(name); + + if (pos != -1) + return this.getLabel(pos); + return null; + } + + public int getPos(String name) { + + if (name == null) + return -1; + + if (Validator.isEmpty(name)) + return -1; + + for (LabelLinguisticDomain auxLabel : this._labels) + if (auxLabel.getName() + .equals(name)) + return this._labels.indexOf(auxLabel); + + return -1; + + } + + public int getPos(LabelLinguisticDomain label) { + int pos = this._labels.indexOf(label); + return pos; + } + + @Override + public String toString() { + String result = ""; //$NON-NLS-1$ + int cardinality = this.getCardinality(); + + if (cardinality > 0) + for (int pos = 0; pos < cardinality; ++pos) { + if (pos > 0) + result += ", "; //$NON-NLS-1$ + result += this._labels.get(pos); + } + + String template = this.messages.LabelSetLinguisticDomain_toStringTemplate; + return MessageFormat.format(template, result); + } + + @Override + public boolean equals(Object obj) { + + if (obj == null) + return false; + + if (this.getClass() != obj.getClass()) + return false; + + final LabelSetLinguisticDomain other = (LabelSetLinguisticDomain) obj; + + EqualsBuilder eb = new EqualsBuilder(); + eb.append(this._labels, other._labels); + + return eb.isEquals(); + } + + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(17, 31); + hcb.append(this._labels); + return hcb.hashCode(); + } + + @Override + public Object clone() { + Object result = null; + + try { + result = super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + + List resultLabels = new LinkedList<>(); + for (LabelLinguisticDomain label : this._labels) + resultLabels.add((LabelLinguisticDomain) label.clone()); + + ((LabelSetLinguisticDomain) result)._labels = resultLabels; + + return result; + } + + public void write(XMLStreamWriter writer) throws XMLStreamException { + writer.writeStartElement(Fields.labelSet.toString()); + + for (LabelLinguisticDomain label : this._labels) + this.writeLabel(writer, label); + + writer.writeEndElement(); + + } + + private void writeLabel(XMLStreamWriter writer, LabelLinguisticDomain label) throws XMLStreamException { + writer.writeStartElement(Fields.label.toString()); + writer.writeAttribute(Fields.name.toString(), label.getName()); + label.write(writer); + writer.writeEndElement(); + } + + public void read(WNode node) { + if (node.getVersion() + .equals("3.0")) + this.readFS3(node); + else + this.readFS4(node); + } + + private void readFS3(WNode node) { + + WNode labelset = node.getFirst(Fields.labels.toString()); + List nodes = labelset.getChildren(); + for (WNode item : nodes) { + + LabelLinguisticDomain label = ContextInjectionFactory.make(LabelLinguisticDomain.class, this.context); + + String name = item.getAttribute(Fields.label); + label.setName(name); + label.read(item); + this.addLabel(label); + + } + } + + private void readFS4(WNode node) { + + // WNode labelset = node.getFirst(Fields.labelSet.toString()); + List nodes = node.getChildren(); + for (WNode item : nodes) { + + LabelLinguisticDomain label = ContextInjectionFactory.make(LabelLinguisticDomain.class, this.context); + + String name = item.getAttribute(Fields.name); + label.setName(name); + label.read(item); + this.addLabel(label); + + } + + } + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/Messages.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/Messages.java new file mode 100644 index 0000000..64fdf10 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/Messages.java @@ -0,0 +1,20 @@ +// This file has been auto-generated +package flintstones.domain.fuzzyset.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String TrapezoidalFunction_decimal_format; + public String TrapezoidalFunction_template_tostring_short; + public String TrapezoidalFunction_template_tostring_long; + public String LabelSetLinguisticDomain_duplicated_label; + public String LabelSetLinguisticDomain_toStringTemplate; + public String FuzzySet_Inexistent_element; + public String category; + public String name_fuzzyset; + public String name_hesitant; + +} diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/messages.properties b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/messages.properties new file mode 100644 index 0000000..552eaff --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/messages.properties @@ -0,0 +1,6 @@ +FuzzySet_Inexistent_element=El elemento no exste +LabelSetLinguisticDomain_duplicated_label=Duplicated label name +LabelSetLinguisticDomain_toStringTemplate=({0}) +category=Linguistic +name_fuzzyset=Fuzzyset +name_hesitant=Hesitant \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/messages_es.properties b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/messages_es.properties new file mode 100644 index 0000000..d669a1f --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/messages/messages_es.properties @@ -0,0 +1,6 @@ +FuzzySet_Inexistent_element=El elemento no exste +LabelSetLinguisticDomain_duplicated_label=Duplicated label name +LabelSetLinguisticDomain_toStringTemplate=({0}) +category=Lingsticos +name_fuzzyset=Fuzzyset +name_hesitant=Hesitant \ No newline at end of file diff --git a/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/semantic/IMembershipFunction.java b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/semantic/IMembershipFunction.java new file mode 100644 index 0000000..a3c6637 --- /dev/null +++ b/bundles/flintstones.domain.fuzzyset/src/flintstones/domain/fuzzyset/semantic/IMembershipFunction.java @@ -0,0 +1,44 @@ +package flintstones.domain.fuzzyset.semantic; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.FragmentFunction; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.helper.data.wxml.WNode; + +@SuppressWarnings("javadoc") +public abstract class IMembershipFunction implements Cloneable, Comparable { + + public IMembershipFunction() { + } + + public abstract FragmentFunction toFragmentFunction(); + + public abstract boolean isSymmetrical(); + + public abstract boolean isSymmetrical(IMembershipFunction other, double center); + + public abstract NumericRealDomain getCenter(); + + public abstract NumericRealDomain getCoverage(); + + public abstract double getMembershipValue(double x); + + public abstract double centroid(); + + public abstract double maxMin(double max, double min); + + public abstract double maxMin(IMembershipFunction function, FuzzySet bltsDomain, FuzzySet valuationDomain); + + @Override + public abstract Object clone(); + + public abstract void write(XMLStreamWriter writer) throws XMLStreamException; + + public abstract void read(WNode node); + + public abstract void setLimits(double[] limits); + +} diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/.classpath b/bundles/flintstones.domain.numeric.integer.ui.chart/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/.polyglot.META-INF b/bundles/flintstones.domain.numeric.integer.ui.chart/.polyglot.META-INF new file mode 100644 index 0000000..66cdb44 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric.integer.ui.chart + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Chart + diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/.project b/bundles/flintstones.domain.numeric.integer.ui.chart/.project new file mode 100644 index 0000000..39a9619 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric.integer.ui.chart + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362545 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric.integer.ui.chart/META-INF/MANIFEST.MF new file mode 100644 index 0000000..634c1d6 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Chart +Bundle-SymbolicName: flintstones.domain.numeric.integer.ui.chart;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.domain.numeric.integer.ui.chart +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.domain.numeric.ui.chart, + org.eclipse.swt, + flintstones.entity.domain diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/build.properties b/bundles/flintstones.domain.numeric.integer.ui.chart/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/plugin.xml b/bundles/flintstones.domain.numeric.integer.ui.chart/plugin.xml new file mode 100644 index 0000000..898bdaa --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/plugin.xml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/bundles/flintstones.domain.numeric.integer.ui.chart/src/flintstones/domain/numeric/integer/ui/chart/NumericRealDomainChart.java b/bundles/flintstones.domain.numeric.integer.ui.chart/src/flintstones/domain/numeric/integer/ui/chart/NumericRealDomainChart.java new file mode 100644 index 0000000..0073194 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.chart/src/flintstones/domain/numeric/integer/ui/chart/NumericRealDomainChart.java @@ -0,0 +1,7 @@ +package flintstones.domain.numeric.integer.ui.chart; + +import flintstones.domain.numeric.ui.chart.NumericDomainChart; + +public class NumericRealDomainChart extends NumericDomainChart { + +} diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/.classpath b/bundles/flintstones.domain.numeric.integer.ui.dialog/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/.polyglot.META-INF b/bundles/flintstones.domain.numeric.integer.ui.dialog/.polyglot.META-INF new file mode 100644 index 0000000..90d2c31 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric.integer.ui.dialog + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Integer UI + diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/.project b/bundles/flintstones.domain.numeric.integer.ui.dialog/.project new file mode 100644 index 0000000..7928e57 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric.integer.ui.dialog + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362545 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric.integer.ui.dialog/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7282295 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.numeric.integer.ui.dialog;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.jface, + flintstones.entity.domain, + flintstones.domain.numeric.ui.dialog +Automatic-Module-Name: flintstones.domain.numeric.integer.ui diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.numeric.integer.ui.dialog/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..76e4bff --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,8 @@ +#Properties file for flintstones.domain.numeric.integer.ui +Bundle-Name = Integer UI +chart_ui.icon.integer = domain-N.png +chart_ui.icon.integer.intervalar = domain-N.png +modify_dialog.description.integer = [Descripcin INTEGER UI] +modify_dialog.description.integer.intervalar = [Descripcin INTEGER UI] +new_dialog.description.integer = [Descripcin INTEGER UI] +new_dialog.description.integer.intervalar = [Descripcin INTEGER UI] \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.numeric.integer.ui.dialog/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..76e4bff --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,8 @@ +#Properties file for flintstones.domain.numeric.integer.ui +Bundle-Name = Integer UI +chart_ui.icon.integer = domain-N.png +chart_ui.icon.integer.intervalar = domain-N.png +modify_dialog.description.integer = [Descripcin INTEGER UI] +modify_dialog.description.integer.intervalar = [Descripcin INTEGER UI] +new_dialog.description.integer = [Descripcin INTEGER UI] +new_dialog.description.integer.intervalar = [Descripcin INTEGER UI] \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/build.properties b/bundles/flintstones.domain.numeric.integer.ui.dialog/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/plugin.xml b/bundles/flintstones.domain.numeric.integer.ui.dialog/plugin.xml new file mode 100644 index 0000000..440fc36 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/plugin.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.numeric.integer.ui.dialog/src/flintstones/domain/numeric/integer/ui/dialog/UpsertIntegerDomainDialog.java b/bundles/flintstones.domain.numeric.integer.ui.dialog/src/flintstones/domain/numeric/integer/ui/dialog/UpsertIntegerDomainDialog.java new file mode 100644 index 0000000..22ffcdf --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer.ui.dialog/src/flintstones/domain/numeric/integer/ui/dialog/UpsertIntegerDomainDialog.java @@ -0,0 +1,16 @@ +package flintstones.domain.numeric.integer.ui.dialog; + +import flintstones.domain.numeric.ui.dialog.UpsertNumericDomainDialog; + +/** + * The Class UpsertIntegerDomainDialog. + */ +public class UpsertIntegerDomainDialog extends UpsertNumericDomainDialog { + + /** + * Instantiates a new upsert integer domain dialog. + */ + public UpsertIntegerDomainDialog() { + super(true); + } +} diff --git a/bundles/flintstones.domain.numeric.integer/.classpath b/bundles/flintstones.domain.numeric.integer/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric.integer/.polyglot.META-INF b/bundles/flintstones.domain.numeric.integer/.polyglot.META-INF new file mode 100644 index 0000000..6c7d772 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric.integer + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.domain.numeric.integer/.project b/bundles/flintstones.domain.numeric.integer/.project new file mode 100644 index 0000000..e29ba04 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric.integer + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362544 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric.integer/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric.integer/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8d0f5cf --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.numeric.integer;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.domain, + flintstones.domain.numeric;visibility:=reexport, + flintstones.helper.data.wxml, + flintstones.entity.domain, + javax.inject +Export-Package: flintstones.domain.numeric.integer +Automatic-Module-Name: flintstones.domain.numeric.integer diff --git a/bundles/flintstones.domain.numeric.integer/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.numeric.integer/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..618968b --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,3 @@ +#Properties file for flintstones.domain.numeric.integer +domain.label = Integer +domain.label.integer = Integer Intervalar \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.integer/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.numeric.integer/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..786b46e --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,3 @@ +#Properties file for flintstones.domain.numeric.integer +domain.label = Entero +domain.label.integer = Entero Intervalar \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.integer/build.properties b/bundles/flintstones.domain.numeric.integer/build.properties new file mode 100644 index 0000000..04fa2ee --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + OSGI-INF/l10n/bundle.properties diff --git a/bundles/flintstones.domain.numeric.integer/plugin.xml b/bundles/flintstones.domain.numeric.integer/plugin.xml new file mode 100644 index 0000000..0b350e7 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/NumericIntegerDomain.java b/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/NumericIntegerDomain.java new file mode 100644 index 0000000..9138795 --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/NumericIntegerDomain.java @@ -0,0 +1,45 @@ +package flintstones.domain.numeric.integer; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.numeric.NumericDomain; +import flintstones.domain.numeric.integer.messages.Messages; +import flintstones.helper.data.wxml.WNode; + +/** + * The Class NumericIntegerDomain. + */ +public class NumericIntegerDomain extends NumericDomain { + + @Inject + @Translation + private Messages messages; + + /** The Constant ID. */ + public static final String ID = "flintstones.domain.numeric.integer"; //$NON-NLS-1$ + + /** + * Instantiates a new numeric integer domain. + */ + public NumericIntegerDomain() { + super(); + } + + /* (non-Javadoc) + * + * @see flintstones.domain.Domain#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + this.inRange = Boolean.parseBoolean(node.getAttribute(NumericDomain.Fields.inRange)); + if (!this.inRange) { + this.min = 0; + this.max = 0; + } else { + this.min = node.getAttributeInt(NumericDomain.Fields.min); + this.max = node.getAttributeInt(NumericDomain.Fields.max); + } + } + +} diff --git a/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/Messages.java b/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/Messages.java new file mode 100644 index 0000000..86c567f --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/Messages.java @@ -0,0 +1,13 @@ +package flintstones.domain.numeric.integer.messages; + +//This file has been auto-generated + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + public String category; + public String name_intervalar; + public String name; +} diff --git a/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/messages.properties b/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/messages.properties new file mode 100644 index 0000000..abf1eac --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/messages.properties @@ -0,0 +1,3 @@ +category=Numeric integer +name_intervalar=Numeric integer intervalar +name=Numeric integer \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/messages_es.properties b/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/messages_es.properties new file mode 100644 index 0000000..25a6bed --- /dev/null +++ b/bundles/flintstones.domain.numeric.integer/src/flintstones/domain/numeric/integer/messages/messages_es.properties @@ -0,0 +1,3 @@ +category=Numrico entero +name_intervalar=Numrico entero intervalar +name=Numrico entero \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/.classpath b/bundles/flintstones.domain.numeric.real.ui.chart/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/.polyglot.META-INF b/bundles/flintstones.domain.numeric.real.ui.chart/.polyglot.META-INF new file mode 100644 index 0000000..5788e11 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric.real.ui.chart + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Chart + diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/.project b/bundles/flintstones.domain.numeric.real.ui.chart/.project new file mode 100644 index 0000000..65cef9a --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric.real.ui.chart + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362546 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric.real.ui.chart/META-INF/MANIFEST.MF new file mode 100644 index 0000000..39277a5 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Chart +Bundle-SymbolicName: flintstones.domain.numeric.real.ui.chart;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.domain.numeric.real.ui.chart +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.domain.numeric.ui.chart, + org.eclipse.swt, + flintstones.entity.domain diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/build.properties b/bundles/flintstones.domain.numeric.real.ui.chart/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/plugin.xml b/bundles/flintstones.domain.numeric.real.ui.chart/plugin.xml new file mode 100644 index 0000000..dcbacff --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/plugin.xml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/bundles/flintstones.domain.numeric.real.ui.chart/src/flintstones/domain/numeric/real/ui/chart/NumericIntegerDomainChart.java b/bundles/flintstones.domain.numeric.real.ui.chart/src/flintstones/domain/numeric/real/ui/chart/NumericIntegerDomainChart.java new file mode 100644 index 0000000..ded3a4d --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.chart/src/flintstones/domain/numeric/real/ui/chart/NumericIntegerDomainChart.java @@ -0,0 +1,7 @@ +package flintstones.domain.numeric.real.ui.chart; + +import flintstones.domain.numeric.ui.chart.NumericDomainChart; + +public class NumericIntegerDomainChart extends NumericDomainChart { + +} diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/.classpath b/bundles/flintstones.domain.numeric.real.ui.dialog/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/.polyglot.META-INF b/bundles/flintstones.domain.numeric.real.ui.dialog/.polyglot.META-INF new file mode 100644 index 0000000..3c80939 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric.real.ui.dialog + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/.project b/bundles/flintstones.domain.numeric.real.ui.dialog/.project new file mode 100644 index 0000000..90cb606 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric.real.ui.dialog + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362547 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric.real.ui.dialog/META-INF/MANIFEST.MF new file mode 100644 index 0000000..595fb0c --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.numeric.real.ui.dialog;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.jface, + flintstones.entity.domain, + flintstones.domain.numeric.ui.dialog +Automatic-Module-Name: flintstones.domain.numeric.real.ui +Export-Package: flintstones.domain.numeric.real.ui.dialog diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.numeric.real.ui.dialog/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..0d4c4ed --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,8 @@ +#Properties file for flintstones.domain.numeric.real.ui +Bundle-Name = Ui +chart_ui.icon = domain-N.png +chart_ui.icon.0 = domain-N.png +modify_dialog.description = real desc +modify_dialog.description.0 = real intervalar +new_dialog.description = description +new_dialog.description.0 = description \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.numeric.real.ui.dialog/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..138a59e --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,8 @@ +#Properties file for flintstones.domain.numeric.real.ui +Bundle-Name = Ui +chart_ui.icon = domain-N.png +chart_ui.icon.0 = domain-N.png +modify_dialog.description.real = real desc +modify_dialog.description.real.intervalar = real intervalar +new_dialog.description.real = description +new_dialog.description.real.intervalar = description \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/build.properties b/bundles/flintstones.domain.numeric.real.ui.dialog/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/plugin.xml b/bundles/flintstones.domain.numeric.real.ui.dialog/plugin.xml new file mode 100644 index 0000000..56707f3 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/plugin.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.numeric.real.ui.dialog/src/flintstones/domain/numeric/real/ui/dialog/UpsertRealDomainDialog.java b/bundles/flintstones.domain.numeric.real.ui.dialog/src/flintstones/domain/numeric/real/ui/dialog/UpsertRealDomainDialog.java new file mode 100644 index 0000000..91207f7 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real.ui.dialog/src/flintstones/domain/numeric/real/ui/dialog/UpsertRealDomainDialog.java @@ -0,0 +1,16 @@ +package flintstones.domain.numeric.real.ui.dialog; + +import flintstones.domain.numeric.ui.dialog.UpsertNumericDomainDialog; + +/** + * The Class UpsertRealDomainDialog. + */ +public class UpsertRealDomainDialog extends UpsertNumericDomainDialog { + + /** + * Instantiates a new upsert real domain dialog. + */ + public UpsertRealDomainDialog() { + super(false); + } +} diff --git a/bundles/flintstones.domain.numeric.real/.classpath b/bundles/flintstones.domain.numeric.real/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric.real/.polyglot.META-INF b/bundles/flintstones.domain.numeric.real/.polyglot.META-INF new file mode 100644 index 0000000..16c9da0 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric.real + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Real + diff --git a/bundles/flintstones.domain.numeric.real/.project b/bundles/flintstones.domain.numeric.real/.project new file mode 100644 index 0000000..6b694dd --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric.real + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362546 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric.real/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric.real/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c6aae3a --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.numeric.real;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.domain.numeric.real +Require-Bundle: flintstones.domain.numeric;visibility:=reexport, + flintstones.helper.data.wxml, + javax.inject, + flintstones.entity.domain, + org.apache.commons.lang, + flintstones.helper.data +Automatic-Module-Name: flintstones.domain.numeric.real diff --git a/bundles/flintstones.domain.numeric.real/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.numeric.real/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..65b9266 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,4 @@ +#Properties file for flintstones.domain.numeric.real +Bundle-Name = Real +domain.name.real = Real +domain.name.real.intervalar = Real intervalar \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.real/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.numeric.real/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..65b9266 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,4 @@ +#Properties file for flintstones.domain.numeric.real +Bundle-Name = Real +domain.name.real = Real +domain.name.real.intervalar = Real intervalar \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.real/build.properties b/bundles/flintstones.domain.numeric.real/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.domain.numeric.real/plugin.xml b/bundles/flintstones.domain.numeric.real/plugin.xml new file mode 100644 index 0000000..8cd6dfa --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/plugin.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/NumericRealDomain.java b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/NumericRealDomain.java new file mode 100644 index 0000000..c78e342 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/NumericRealDomain.java @@ -0,0 +1,32 @@ +package flintstones.domain.numeric.real; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.numeric.NumericDomain; +import flintstones.domain.numeric.real.messages.Messages; +import flintstones.helper.data.wxml.WNode; + +@SuppressWarnings("javadoc") +public class NumericRealDomain extends NumericDomain { + + @Inject + @Translation + private Messages messages; + + public static final String ID = "flintstones.domain.numeric.real"; //$NON-NLS-1$ + + @Override + public void read(WNode node) { + this.inRange = Boolean.parseBoolean(node.getAttribute(NumericDomain.Fields.inRange)); + if (!this.inRange) { + this.min = 0.0d; + this.max = 0.0d; + } else { + this.min = Double.parseDouble(node.getAttribute(NumericDomain.Fields.min)); + this.max = Double.parseDouble(node.getAttribute(NumericDomain.Fields.max)); + } + } + +} diff --git a/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealBetween0100Instance.java b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealBetween0100Instance.java new file mode 100644 index 0000000..93202ac --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealBetween0100Instance.java @@ -0,0 +1,26 @@ +package flintstones.domain.numeric.real.instance; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class RealBetween0100Instance extends DomainInstance { + + @Override + public Domain getInstance() { + + NumericRealDomain domain = (NumericRealDomain) getDomain(); + domain.setInRange(true); + + double max = 100; + double min = 0; + + String name = getLabel();; + + domain.setMax(max); + domain.setMin(min); + domain.setName(name); + return domain; + } + +} diff --git a/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealBetween010Instance.java b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealBetween010Instance.java new file mode 100644 index 0000000..b8b6a32 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealBetween010Instance.java @@ -0,0 +1,26 @@ +package flintstones.domain.numeric.real.instance; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class RealBetween010Instance extends DomainInstance { + + @Override + public Domain getInstance() { + + NumericRealDomain domain = (NumericRealDomain) getDomain(); + domain.setInRange(true); + + double max = 10; + double min = 0; + + String name = getLabel();; + + domain.setMax(max); + domain.setMin(min); + domain.setName(name); + return domain; + } + +} diff --git a/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealNoRangeInstance.java b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealNoRangeInstance.java new file mode 100644 index 0000000..fb1ac48 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealNoRangeInstance.java @@ -0,0 +1,21 @@ +package flintstones.domain.numeric.real.instance; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; + +public class RealNoRangeInstance extends DomainInstance { + + @Override + public Domain getInstance() { + + NumericRealDomain domain = (NumericRealDomain) getDomain(); + + domain.setInRange(false); + String name = getLabel(); + + domain.setName(name); + return domain; + } + +} diff --git a/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealRandomRangedInstance.java b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealRandomRangedInstance.java new file mode 100644 index 0000000..7b78d84 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/instance/RealRandomRangedInstance.java @@ -0,0 +1,35 @@ +package flintstones.domain.numeric.real.instance; + +import java.util.Random; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainInstance; +import flintstones.helper.DoubleHelper; + +public class RealRandomRangedInstance extends DomainInstance { + + @Override + public Domain getInstance() { + + NumericRealDomain domain = (NumericRealDomain) getDomain(); + domain.setInRange(true); + + Random rand = new Random(); + double n = (rand.nextDouble()*rand.nextInt()%10000); + double m = (rand.nextDouble()*rand.nextInt()%10000); + + if(m > n) { + double x = n; + n = m; + m = x; + } + String name = getLabel() + " ["+DoubleHelper.Draw(m)+","+DoubleHelper.Draw(n)+"]_"; + + domain.setMax(n); + domain.setMin(m); + domain.setName(name); + return domain; + } + +} diff --git a/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/Messages.java b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/Messages.java new file mode 100644 index 0000000..df3f7ee --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/Messages.java @@ -0,0 +1,13 @@ +package flintstones.domain.numeric.real.messages; + +//This file has been auto-generated + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + public String category; + public String name_intervalar; + public String name; +} diff --git a/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/messages.properties b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/messages.properties new file mode 100644 index 0000000..ac8309e --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/messages.properties @@ -0,0 +1,3 @@ +category=Numeric real +name_intervalar=Numeric real intervalar +name=Numeric real \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/messages_es.properties b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/messages_es.properties new file mode 100644 index 0000000..74950b1 --- /dev/null +++ b/bundles/flintstones.domain.numeric.real/src/flintstones/domain/numeric/real/messages/messages_es.properties @@ -0,0 +1,3 @@ +category=Numrico real +name_intervalar=Numrico real intervalar +name=Numrico real \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.ui.chart/.classpath b/bundles/flintstones.domain.numeric.ui.chart/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric.ui.chart/.polyglot.META-INF b/bundles/flintstones.domain.numeric.ui.chart/.polyglot.META-INF new file mode 100644 index 0000000..291ca33 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric.ui.chart + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Chart + diff --git a/bundles/flintstones.domain.numeric.ui.chart/.project b/bundles/flintstones.domain.numeric.ui.chart/.project new file mode 100644 index 0000000..36dd93b --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric.ui.chart + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362549 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric.ui.chart/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric.ui.chart/META-INF/MANIFEST.MF new file mode 100644 index 0000000..bf76d53 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Chart +Bundle-SymbolicName: flintstones.domain.numeric.ui.chart +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.domain.numeric.ui.chart +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.domain.numeric, + javax.inject, + flintstones.entity.domain.ui.chart;visibility:=reexport, + org.eclipse.swt, + flintstones.entity.domain, + org.jfree.chart.jfreechart +Export-Package: flintstones.domain.numeric.ui.chart diff --git a/bundles/flintstones.domain.numeric.ui.chart/build.properties b/bundles/flintstones.domain.numeric.ui.chart/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/NumericDomainChart.java b/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/NumericDomainChart.java new file mode 100644 index 0000000..34566d3 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/NumericDomainChart.java @@ -0,0 +1,275 @@ +package flintstones.domain.numeric.ui.chart; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.IntervalMarker; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.ValueMarker; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.StandardXYBarPainter; +import org.jfree.chart.renderer.xy.XYBarRenderer; +import org.jfree.data.xy.DefaultIntervalXYDataset; +import org.jfree.data.xy.IntervalXYDataset; +import org.jfree.chart.swt.ChartComposite; +import org.jfree.chart.ui.Layer; +import org.jfree.chart.ui.RectangleInsets; + +import flintstones.domain.numeric.NumericDomain; +import flintstones.domain.numeric.ui.chart.messages.Messages; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.chart.DomainChart; +import flintstones.helper.validator.Validator; + +@SuppressWarnings("javadoc") +public class NumericDomainChart extends DomainChart { + + @Inject + @Translation + private Messages messages; + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + private NumericDomain _domain; + + public static final Color[] colors = { Color.RED, Color.CYAN, Color.GREEN, Color.MAGENTA, Color.LIGHT_GRAY, Color.ORANGE, Color.ORANGE, Color.MAGENTA, Color.PINK, Color.WHITE, Color.YELLOW }; + + private ValueMarker _numMarker; + private IntervalMarker _intervalMarker; + + private ValueMarker[] _alternativesMarkers; + + public NumericDomainChart() { + super(); + this._domain = null; + this._chart = null; + this._chartComposite = null; + this._numMarker = null; + this._intervalMarker = null; + } + + @Override + public void refreshChart() { + + if (this._chart == null) + this._chart = this.createChart(this.createIntervalDataset()); + else + this._chart.getXYPlot() + .setDataset(this.createIntervalDataset()); + + double upperLimit = this._domain.getMax(), lowerLimit = this._domain.getMin(); + boolean inRange = this._domain.getInRange(); + + double rangeSize = upperLimit - lowerLimit; + double margin = (rangeSize > 0) ? rangeSize / 4d : 1; + + this._chart.getXYPlot() + .getRangeAxis() + .setRange(lowerLimit - margin, upperLimit + margin); + this._chart.getXYPlot() + .getRangeAxis() + .setTickLabelsVisible(inRange); + + if (inRange) { + if (this._domain.getName() + .equals("")) //$NON-NLS-1$ + this._chart.getXYPlot() + .getRangeAxis() + .setLabel(this.domainMessages.Domain_entity); + else + this._chart.getXYPlot() + .getRangeAxis() + .setLabel(this._domain.getName()); // $NON-NLS-1$ + } else + this._chart.getXYPlot() + .getRangeAxis() + .setLabel(this.messages.lessInfinity + this.messages.noInfinity + this.messages.plusInfinity); + + } + + @Override + public void setDomain(Domain domain) { + + Validator.notNull(domain); + // Validator.notIllegalElementType(domain, new String[] { + // NumericDomain.class.toString() }); + + this._domain = (NumericDomain) domain; + this.refreshChart(); + } + + @Override + public void setSelection(Object selection) { + + if (this._numMarker != null) + this._chart.getXYPlot() + .removeRangeMarker(this._numMarker); + + if (this._intervalMarker != null) + this._chart.getXYPlot() + .removeRangeMarker(this._intervalMarker); + + if (selection instanceof LinkedList) { + LinkedList selectionL = (LinkedList) selection; + if (selectionL.getFirst() instanceof Integer) { + Integer mark1 = (int) (selectionL).getFirst(); + Integer mark2 = (int) (selectionL).getLast(); + this._intervalMarker = new IntervalMarker(mark1, mark2); + } else if (selectionL.getFirst() instanceof Double) { + Double mark1 = (double) (selectionL).getFirst(); + Double mark2 = (double) (selectionL).getLast(); + this._intervalMarker = new IntervalMarker(mark1, mark2); + } else + throw new Error("Tipo no esperado " + selectionL.getFirst() //$NON-NLS-1$ + .getClass()); + + this._intervalMarker.setAlpha(0.5f); + this._intervalMarker.setPaint(Color.RED); + this._chart.getXYPlot() + .addRangeMarker(this._intervalMarker); + } else { + if (selection instanceof Integer) + this._numMarker = new ValueMarker((Integer) selection); + else if (selection instanceof Double) + this._numMarker = new ValueMarker((Double) selection); + else + throw new Error("Tipo no esperado " + selection.getClass()); //$NON-NLS-1$ + + this._numMarker.setPaint(Color.RED); + this._numMarker.setStroke(new BasicStroke(4)); + this._chart.getXYPlot() + .addRangeMarker(this._numMarker); + } + + } + + @Override + public void initialize(Domain domain, Composite container, int width, int height, int style) { + this.setDomain(domain); + this._chartComposite = new ChartComposite(container, style, this._chart, true); + this._chartComposite.setSize(width, height); + } + + private JFreeChart createChart(IntervalXYDataset intervalXYDataset) { + JFreeChart result = ChartFactory.createXYBarChart("", "X", false, "", intervalXYDataset, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + PlotOrientation.HORIZONTAL, false, false, false); + + result.setBackgroundPaint(Color.WHITE); + XYPlot xyplot = (XYPlot) result.getPlot(); + + XYBarRenderer xyBarRenderer = (XYBarRenderer) xyplot.getRenderer(); + xyBarRenderer.setSeriesPaint(0, Color.BLUE); + xyBarRenderer.setUseYInterval(true); + xyBarRenderer.setBarPainter(new StandardXYBarPainter()); + + xyplot.setBackgroundPaint(Color.WHITE); + xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); + xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); + xyplot.getDomainAxis() + .setVisible(false); + + return result; + } + + private IntervalXYDataset createIntervalDataset() { + DefaultIntervalXYDataset result = new DefaultIntervalXYDataset(); + + double upperLimit = this._domain.getMax(), lowerLimit = this._domain.getMin(); + + double[] x = new double[] { 1 }; + double[] xStart = new double[] { 0.1 }; + double[] xEnd = new double[] { 0.9 }; + double[] y = new double[] { upperLimit - lowerLimit }; + double[] yStart = new double[] { lowerLimit }; + double[] yEnd = new double[] { upperLimit }; + double[][] data = new double[][] { x, xStart, xEnd, y, yStart, yEnd }; + result.addSeries(this.messages.NumericDomainChart_range, data); + + return result; + } + + @Override + public void displayRanking(Object ranking) { + + if (ranking != null) { + String[] alternatives = (String[]) ((Object[]) ranking)[0]; + double[] pos = (double[]) ((Object[]) ranking)[1]; + this.displayAlternatives(alternatives, pos, NumericDomainChart.colors); + } + } + + public void displayAlternatives(String[] alternatives, double[] pos, Color[] colors) { + + if (this._numMarker != null) + this._chart.getXYPlot() + .removeRangeMarker(this._numMarker); + if (this._alternativesMarkers != null) + for (ValueMarker marker : this._alternativesMarkers) + this._chart.getXYPlot() + .removeRangeMarker(marker); + + this._alternativesMarkers = null; + + class MyItem implements Comparable { + private final String alternative; + private final Double pos; + private final Color color; + + public MyItem(String alternative, double pos, Color color) { + this.alternative = alternative; + this.pos = pos; + this.color = color; + } + + @Override + public int compareTo(MyItem other) { + return Double.compare(this.pos, other.pos); + } + } + + List items = null; + if ((alternatives != null) && (pos != null) && (colors != null)) { + items = new LinkedList<>(); + for (int i = 0; i < pos.length; i++) + if (alternatives[i] != null) + items.add(new MyItem(alternatives[i], pos[i], colors[i])); + + Collections.sort(items); + } + + if (items != null) { + int size = items.size(); + if (size > 0) { + int height = (int) (this._chartComposite.getSize().y * 0.75f); + int offset = height / size; + this._alternativesMarkers = new ValueMarker[size]; + MyItem item; + for (int i = 0; i < size; i++) { + item = items.get(i); + this._alternativesMarkers[i] = new ValueMarker(item.pos); + this._alternativesMarkers[i].setPaint(item.color); + this._alternativesMarkers[i].setStroke(new BasicStroke(3)); + this._alternativesMarkers[i].setLabel(item.alternative); + this._alternativesMarkers[i].setLabelFont(new Font("TimesRoman", Font.BOLD, 20)); //$NON-NLS-1$ + this._alternativesMarkers[i].setLabelPaint(item.color); + this._alternativesMarkers[i].setLabelOffset(new RectangleInsets(offset / 2 + (offset * i), 15, 0, 0)); + this._chart.getXYPlot() + .addRangeMarker(0, this._alternativesMarkers[i], Layer.FOREGROUND); + } + } + } + } + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/Messages.java b/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/Messages.java new file mode 100644 index 0000000..489b763 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/Messages.java @@ -0,0 +1,38 @@ +// This file has been auto-generated +package flintstones.domain.numeric.ui.chart.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String NumericDomain_formatTemplate; + public String NumericDomain_toStringTemplate; + public String NumericDomainChart_range; + public String plusInfinity; + public String noInfinity; + public String Without_range; + public String lessInfinity; + public String label_domain_name; + public String error_domain_name; + public String limits; + public String rangeless; + public String limitless; + public String error_limits; + public String error_limits1; + public String to; + public String error_limits2; + public String preview; + public String dialogTitleTemplate; + public String crating; + public String integer; + public String intervalar; + public String error_empty_domain; + public String error_alredy_used_name; + public String error_out_of_limits; + public String modifying; + public String real; + public String blank; + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/messages.properties b/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/messages.properties new file mode 100644 index 0000000..a78a34a --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/messages.properties @@ -0,0 +1,28 @@ +Without_range=Without range +error_limits1=limits1 +error_limits2=limits2 +error_domain_name=name +error_limits=limits +chart=chart +crating=Creating +dialogTitleTemplate=%s domain of type %s %s +label_domain_name=Domain name +error_alredy_used_name=The chosen name is alredy used by another domain +error_empty_domain=Domain name can not be empty +error_out_of_limits=The first limit must be smaller than the second one +integer=Integer +intervalar=intervalar +lessInfinity=-Infinity +limitless=(-\u221E to \u221E) +limits=Limits +modifying=Editing +noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +NumericDomainChart_range=Range +plusInfinity=+Infinity +preview=Preview +rangeless=No range +real=Real +to=to +NumericDomain_formatTemplate={0} {1} +NumericDomain_toStringTemplate=[ {0} - {1} ] +blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/messages_es.properties b/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/messages_es.properties new file mode 100644 index 0000000..bd9a835 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.chart/src/flintstones/domain/numeric/ui/chart/messages/messages_es.properties @@ -0,0 +1,28 @@ +Without_range=Sin rango +error_limits1=limits1 +error_limits2=limits2 +error_domain_name=name +error_limits=limits +chart=chart +crating=Creando +dialogTitleTemplate=%s dominio de tipo %s %s +label_domain_name=Nombre del dominio +error_alredy_used_name=El nombre ya esta siendo usado por otro dominio +error_empty_domain=El nombre de dominio no puede estar vacio +error_out_of_limits=El limite inferior debe ser menor que el limite superior +integer=Entero +intervalar=intervalar +limitless=(-\u221E to \u221E) +limits=Limites +modifying=Modificando +preview=Previsualizacin +rangeless=Sin rango +real=Real +to=a +NumericDomainChart_range=Rango +plusInfinity=+Infinito +lessInfinity=-Infinito +noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +NumericDomain_formatTemplate={0} {1} +NumericDomain_toStringTemplate=[ {0} - {1} ] +blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.ui.dialog/.classpath b/bundles/flintstones.domain.numeric.ui.dialog/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric.ui.dialog/.polyglot.META-INF b/bundles/flintstones.domain.numeric.ui.dialog/.polyglot.META-INF new file mode 100644 index 0000000..291cff3 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric.ui.dialog + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Dialog + diff --git a/bundles/flintstones.domain.numeric.ui.dialog/.project b/bundles/flintstones.domain.numeric.ui.dialog/.project new file mode 100644 index 0000000..03833cc --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric.ui.dialog + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362550 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..465d9ee --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/flintstones/domain/numeric/ui/dialog/UpsertNumericDomainDialog.java=UTF-8 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric.ui.dialog/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric.ui.dialog/META-INF/MANIFEST.MF new file mode 100644 index 0000000..00fad37 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Dialog +Bundle-SymbolicName: flintstones.domain.numeric.ui.dialog +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.domain.numeric.ui.dialog +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.domain.ui.dialog;visibility:=reexport, + flintstones.helper.ui, + flintstones.entity.domain.ui.chart, + flintstones.entity.domain, + flintstones.domain.numeric, + flintstones.model.domain.service, + flintstones.model.domain.ui.service, + javax.inject, + flintstones.entity.domain.ui, + flintstones.model.ui.service +Export-Package: flintstones.domain.numeric.ui.dialog diff --git a/bundles/flintstones.domain.numeric.ui.dialog/build.properties b/bundles/flintstones.domain.numeric.ui.dialog/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/UpsertNumericDomainDialog.java b/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/UpsertNumericDomainDialog.java new file mode 100644 index 0000000..9d6ddc8 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/UpsertNumericDomainDialog.java @@ -0,0 +1,347 @@ +package flintstones.domain.numeric.ui.dialog; + +import java.util.ArrayList; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Point; +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.Spinner; +import flintstones.domain.numeric.NumericDomain; +import flintstones.domain.numeric.ui.dialog.messages.Messages; +import flintstones.entity.domain.ui.chart.DomainChart; +import flintstones.entity.domain.ui.dialog.DomainDialog; +import flintstones.helper.ui.components.WLabel; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.ui.service.UiService; + +public class UpsertNumericDomainDialog extends DomainDialog { + + @Inject + IDomainUIService uiDomainService; + + @Inject + @Translation + private Messages messages; + + // UI STATE + private Composite spinnersRow; + private Button hasLimitsCB; + private Composite chartRow; + private DomainChart domainChart; + private Spinner lower; + private Spinner upper; + + // ERROR + private final HashMap errorLabels = new HashMap<>(); + private final HashMap errorControls = new HashMap<>(); + + // Variants + private boolean isInteger; // If it is not integer, is real + private boolean isCreating; // If not creating then modify. + private boolean isIntervalar; + + /** + * Necesary builder? + */ + public UpsertNumericDomainDialog() { + + } + + /** + * @param isInteger if true is integer, if not, is real + */ + public UpsertNumericDomainDialog(boolean isInteger) { + this.isInteger = isInteger; + } + + public NumericDomain getMyDomain() { + return (NumericDomain) this.getDomain(); + } + + private void addErrorLabel(Composite base, String asociatedItemId) { + Composite subBase = new Composite(base, SWT.NONE); + UiService.setGridLayout(subBase, 1); + UiService.setGridDataAuto(subBase); + WLabel nameLabelError = new WLabel(subBase, SWT.NONE); + UiService.setGridData(nameLabelError, -1, 0, true, false); + UiService.setFont(nameLabelError, UiService.FONT_TEXT_ERROR); + this.errorLabels.put(asociatedItemId, nameLabelError); + } + + @Override + protected Control createDialogArea(Composite base) { + super.createDialogArea(base); + + for (Control c : base.getChildren()) + c.dispose(); + + UiService.setGridLayout(base, 1); + UiService.setGridData(base, 9, 9, true, true); + + this.drawBlock1DomainName(base); + this.drawBlock2Limits(base); + this.drawBlock3Chart(base); + + return base; + } + + private void drawBlock1DomainName(Composite base) { + this.addNameField(base); + } + + private void drawBlock2Limits(Composite base) { + + Composite row1 = new Composite(base, SWT.NONE); + UiService.setGridLayout(row1, 3); + UiService.setGridData(row1, 9, 1, true, false); + + // LABEL + WLabel nameLabel = new WLabel(row1, SWT.NULL); + nameLabel.setText(this.messages.limits); + UiService.setGridData(nameLabel, -1, 0, false, false); + UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE); + + // CHECKBOX + this.hasLimitsCB = new Button(row1, SWT.CHECK); + UiService.setGridData(this.hasLimitsCB, -1, 0, false, false); + this.hasLimitsCB.setText(this.messages.rangeless); + this.hasLimitsCB.addSelectionListener(this.hasLimitsOnClick()); + + // ERROR: Limits + this.addErrorLabel(row1, this.messages.error_limits); + + // SPINNER - LABEL - SPINNER + this.spinnersRow = new Composite(base, SWT.NONE); + UiService.setGridData(this.spinnersRow, 9, 9, true, false); + UiService.setGridLayout(this.spinnersRow, 3); + + this.lower = new Spinner(this.spinnersRow, SWT.BORDER); + UiService.setGridData(this.lower, 9, 0, true, false); + this.errorControls.put(this.messages.error_limits1, this.lower); + + Label toLabel = new Label(this.spinnersRow, SWT.NONE); + toLabel.setText(this.messages.to); + + this.upper = new Spinner(this.spinnersRow, SWT.BORDER); + UiService.setGridData(this.upper, 9, 0, true, false); + this.errorControls.put(this.messages.error_limits2, this.upper); + + if (this.isInteger) { + // Nothing? Default set up seems to work just fine with integers + } else { + + this.lower.setDigits(2); + this.lower.setIncrement(10); + this.lower.setSelection((int) (0 * 100d)); + + this.upper.setDigits(2); + this.upper.setIncrement(10); + this.upper.setSelection((int) (0 * 100d)); + + } + + // Same for integer and real + this.lower.setMinimum(Integer.MIN_VALUE); + this.lower.setMaximum(Integer.MAX_VALUE); + + this.upper.setMinimum(Integer.MIN_VALUE); + this.upper.setMaximum(Integer.MAX_VALUE); + + this.lower.addModifyListener(this.lowerLimitModifyListener()); + this.upper.addModifyListener(this.upperLimitModifyListener()); + + } + + private ModifyListener lowerLimitModifyListener() { + return e -> { + Spinner c = (Spinner) e.widget; + if (UpsertNumericDomainDialog.this.isInteger) + getMyDomain().setMin(c.getSelection()); + else + getMyDomain().setMin(c.getSelection() / 100d); + UpsertNumericDomainDialog.this.upper.setMinimum(UpsertNumericDomainDialog.this.lower.getSelection()); + + UpsertNumericDomainDialog.this.redraw(); + + }; + } + + private ModifyListener upperLimitModifyListener() { + return e -> { + Spinner c = (Spinner) e.widget; + + if (UpsertNumericDomainDialog.this.isInteger) + getMyDomain().setMax(c.getSelection()); + else + getMyDomain().setMax(c.getSelection() / 100d); + + UpsertNumericDomainDialog.this.lower.setMaximum(UpsertNumericDomainDialog.this.upper.getSelection()); + + UpsertNumericDomainDialog.this.redraw(); + }; + } + + private void updateRow2(boolean status) { + this.spinnersRow.setEnabled(!status); + this.recolorSpinners(status); + } + + private void recolorSpinners(boolean status) { + + Color c = (!status) ? UiService.COLOR_BG_DISABLED : UiService.COLOR_BG_NORMAL; + for (Control spinner : this.spinnersRow.getChildren()) + if (spinner instanceof Spinner) + spinner.setBackground(c); + } + + private SelectionAdapter hasLimitsOnClick() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean status = ((Button) e.getSource()).getSelection(); + getMyDomain().setInRange(!status); + UpsertNumericDomainDialog.this.updateRow2(!status); + UpsertNumericDomainDialog.this.redraw(); + + } + + }; + } + + private void drawBlock3Chart(Composite base) { + + // LABEL + Composite row1 = new Composite(base, SWT.NONE); + UiService.setGridLayout(row1, 1); + UiService.setGridData(row1, 9, 9, true, true); + + Label nameLabel = new Label(row1, SWT.NONE); + nameLabel.setText(this.messages.preview); + UiService.setGridData(nameLabel, -1, 0, true, false); + UiService.setFont(nameLabel, UiService.FONT_SECTION_TITLE); + + // CHART + this.chartRow = new Composite(row1, SWT.NONE); + UiService.setGridData(this.chartRow, 9, 9, true, true); + UiService.setGridLayout(this.chartRow, 1); + + } + + @Override + protected Point getInitialSize() { + return new Point(510, 600); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + String title = String.format(this.messages.dialogTitleTemplate, + this.isCreating ? this.messages.crating : this.messages.modifying, + this.isInteger ? this.messages.integer : this.messages.real, + this.isIntervalar ? this.messages.intervalar : "" //$NON-NLS-1$ + ); + + newShell.setText(title); + } + + protected void beforeUI() { + + NumericDomain domain = getMyDomain(); + + // SHELL + this.isIntervalar = domain.getType().contains(this.messages.intervalar); + + // LOCAL + domain.setName(domain.getName() == null ? "" : domain.getName()); //$NON-NLS-1$ + + if (!domain.isInRange()) { + domain.setMin(0.0d); + domain.setMax(0.0d); + } + + // CHART + this.domainChart = this.uiDomainService.createChart(domain.getType()); + this.domainChart.initialize(domain, this.chartRow, 470, 300, SWT.BORDER); + this.redraw(); + } + + private void redraw() { + + // ROW 2 + boolean hasLimitsStatus = getMyDomain().getInRange(); + this.hasLimitsCB.setSelection(!hasLimitsStatus); + this.updateRow2(!hasLimitsStatus); + + // ROW 2 SPINNERS + NumericDomain cDomain = getMyDomain(); + + double maxD = cDomain.getMax(); + double minD = cDomain.getMin(); + int max = (int) maxD; + int min = (int) minD; + + if (!this.isInteger) { + max = (int) (maxD * 100d); + min = (int) (minD * 100d); + } + + if (this.upper.getSelection() != max) + this.upper.setSelection(max); + + if (this.lower.getSelection() != min) + this.lower.setSelection(min); + + // ROW 3 + this.domainChart.setDomain(getMyDomain()); + + // BUTTON BAR + ArrayList errors = this.checkAndDrawErrors(); + boolean ok = errors.size() == 0; + setSaveEnabled(ok); + + } + + private ArrayList checkAndDrawErrors() { + + ArrayList errors = new ArrayList<>(); + + // 4. Check limits + NumericDomain cDomain = (NumericDomain) getMyDomain(); + double max = cDomain.getMax(); + double min = cDomain.getMin(); + boolean inRange = cDomain.getInRange(); + + if (inRange && max <= min) { + String msg = this.messages.error_out_of_limits; + errors.add(msg); + this.errorLabels.get(this.messages.error_limits).setText(msg); + this.errorControls.get(this.messages.error_limits1).setBackground(UiService.COLOR_BG_WRONG); + this.errorControls.get(this.messages.error_limits2).setBackground(UiService.COLOR_BG_WRONG); + } else { + this.errorLabels.get(this.messages.error_limits).setText(""); //$NON-NLS-1$ + if (inRange) { + this.errorControls.get(this.messages.error_limits1).setBackground(UiService.COLOR_BG_NORMAL); + this.errorControls.get(this.messages.error_limits2).setBackground(UiService.COLOR_BG_NORMAL); + } else { + this.errorControls.get(this.messages.error_limits1).setBackground(UiService.COLOR_BG_DISABLED); + this.errorControls.get(this.messages.error_limits2).setBackground(UiService.COLOR_BG_DISABLED); + } + } + + return errors; + + } + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/Messages.java b/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/Messages.java new file mode 100644 index 0000000..a7e73fa --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/Messages.java @@ -0,0 +1,38 @@ +// This file has been auto-generated +package flintstones.domain.numeric.ui.dialog.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String NumericDomain_formatTemplate; + public String NumericDomain_toStringTemplate; + public String NumericDomainChart_range; + public String plusInfinity; + public String noInfinity; + public String Without_range; + public String lessInfinity; + public String label_domain_name; + public String error_domain_name; + public String limits; + public String rangeless; + public String limitless; + public String error_limits; + public String error_limits1; + public String to; + public String error_limits2; + public String preview; + public String dialogTitleTemplate; + public String crating; + public String integer; + public String intervalar; + public String error_empty_domain; + public String error_alredy_used_name; + public String error_out_of_limits; + public String modifying; + public String real; + public String blank; + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/messages.properties b/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/messages.properties new file mode 100644 index 0000000..a78a34a --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/messages.properties @@ -0,0 +1,28 @@ +Without_range=Without range +error_limits1=limits1 +error_limits2=limits2 +error_domain_name=name +error_limits=limits +chart=chart +crating=Creating +dialogTitleTemplate=%s domain of type %s %s +label_domain_name=Domain name +error_alredy_used_name=The chosen name is alredy used by another domain +error_empty_domain=Domain name can not be empty +error_out_of_limits=The first limit must be smaller than the second one +integer=Integer +intervalar=intervalar +lessInfinity=-Infinity +limitless=(-\u221E to \u221E) +limits=Limits +modifying=Editing +noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +NumericDomainChart_range=Range +plusInfinity=+Infinity +preview=Preview +rangeless=No range +real=Real +to=to +NumericDomain_formatTemplate={0} {1} +NumericDomain_toStringTemplate=[ {0} - {1} ] +blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/messages_es.properties b/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/messages_es.properties new file mode 100644 index 0000000..bd9a835 --- /dev/null +++ b/bundles/flintstones.domain.numeric.ui.dialog/src/flintstones/domain/numeric/ui/dialog/messages/messages_es.properties @@ -0,0 +1,28 @@ +Without_range=Sin rango +error_limits1=limits1 +error_limits2=limits2 +error_domain_name=name +error_limits=limits +chart=chart +crating=Creando +dialogTitleTemplate=%s dominio de tipo %s %s +label_domain_name=Nombre del dominio +error_alredy_used_name=El nombre ya esta siendo usado por otro dominio +error_empty_domain=El nombre de dominio no puede estar vacio +error_out_of_limits=El limite inferior debe ser menor que el limite superior +integer=Entero +intervalar=intervalar +limitless=(-\u221E to \u221E) +limits=Limites +modifying=Modificando +preview=Previsualizacin +rangeless=Sin rango +real=Real +to=a +NumericDomainChart_range=Rango +plusInfinity=+Infinito +lessInfinity=-Infinito +noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +NumericDomain_formatTemplate={0} {1} +NumericDomain_toStringTemplate=[ {0} - {1} ] +blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric/.classpath b/bundles/flintstones.domain.numeric/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.domain.numeric/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.domain.numeric/.polyglot.META-INF b/bundles/flintstones.domain.numeric/.polyglot.META-INF new file mode 100644 index 0000000..31044ae --- /dev/null +++ b/bundles/flintstones.domain.numeric/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.domain.numeric + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Numeric + diff --git a/bundles/flintstones.domain.numeric/.project b/bundles/flintstones.domain.numeric/.project new file mode 100644 index 0000000..4abcdd6 --- /dev/null +++ b/bundles/flintstones.domain.numeric/.project @@ -0,0 +1,45 @@ + + + flintstones.domain.numeric + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362543 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.domain.numeric/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.domain.numeric/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.domain.numeric/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.domain.numeric/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.domain.numeric/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.domain.numeric/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.domain.numeric/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.domain.numeric/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.domain.numeric/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.domain.numeric/META-INF/MANIFEST.MF b/bundles/flintstones.domain.numeric/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e2c1830 --- /dev/null +++ b/bundles/flintstones.domain.numeric/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.domain.numeric;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.domain.numeric +Require-Bundle: flintstones.helper.validator;visibility:=reexport, + org.eclipse.jface, + javax.inject, + flintstones.entity.extensionenum, + flintstones.entity.domain, + org.apache.commons.lang +Automatic-Module-Name: flintstones.domain.numeric diff --git a/bundles/flintstones.domain.numeric/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.domain.numeric/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..55d2e17 --- /dev/null +++ b/bundles/flintstones.domain.numeric/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,4 @@ +#Properties file for flintstones.domain.numeric +Bundle-Name = Numeric +domain.category.numeric = Numeric +domain.category.numeric.intervalar = Numeric Intervalar \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.domain.numeric/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..24bde43 --- /dev/null +++ b/bundles/flintstones.domain.numeric/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,4 @@ +#Properties file for flintstones.domain.numeric +Bundle-Name = Numrico +domain.category.numeric = Numrico +domain.category.numeric.intervalar = Numrico Intervalar \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric/build.properties b/bundles/flintstones.domain.numeric/build.properties new file mode 100644 index 0000000..da1e9aa --- /dev/null +++ b/bundles/flintstones.domain.numeric/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/,\ + plugin.xml diff --git a/bundles/flintstones.domain.numeric/plugin.xml b/bundles/flintstones.domain.numeric/plugin.xml new file mode 100644 index 0000000..09cabfc --- /dev/null +++ b/bundles/flintstones.domain.numeric/plugin.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/NumericDomain.java b/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/NumericDomain.java new file mode 100644 index 0000000..aa50588 --- /dev/null +++ b/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/NumericDomain.java @@ -0,0 +1,238 @@ +package flintstones.domain.numeric; + +import java.text.MessageFormat; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +import flintstones.entity.domain.Domain; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.validator.Validator; + +/** + * The Class NumericDomain. + */ +public abstract class NumericDomain extends Domain { + + /** The in range. */ + protected boolean inRange; + + /** The min. */ + protected double min; + + /** The max. */ + protected double max; + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + + /** The min. */ + min, + /** The max. */ + max, + /** The in range. */ + inRange + }; + + /** + * Instantiates a new numeric domain. + */ + public NumericDomain() { + super(); + this.min = 0.0d; + this.max = 0.0d; + this.inRange = true; + } + + /** + * Sets the in range. + * + * @param inRange the new in range + */ + public void setInRange(Boolean inRange) { + this.inRange = inRange; + } + + /** + * Checks if is in range. + * + * @return true, if is in range + */ + public boolean isInRange() { + return this.inRange; + } + + /** + * Gets the in range. + * + * @return the in range + */ + public boolean getInRange() { + return this.inRange; + } + + /** + * Sets the min. + * + * @param min the new min + */ + public void setMin(double min) { + this.min = min; + } + + /** + * Gets the min. + * + * @return the min + */ + public double getMin() { + + if(!inRange) + return -100000; + + return this.min; + } + + /** + * Sets the max. + * + * @param max the new max + */ + public void setMax(double max) { + this.max = max; + } + + /** + * Gets the max. + * + * @return the max + */ + public double getMax() { + + if(!inRange) + return 100000; + + return this.max; + } + + /** + * Sets the min max. + * + * @param min the min + * @param max the max + */ + public void setMinMax(double min, double max) { + Validator.notDisorder(new double[] { min, max }, false); + this.min = min; + this.max = max; + } + + /* + * (non-Javadoc) + * + * @see flintstones.entity.domain.Domain#midpoint() + */ + @Override + public double midpoint() { + if (this.inRange) + return (this.max + this.min) / 2d; + return 0; + } + + /* + * (non-Javadoc) + * + * @see flintstones.entity.domain.Domain#formatDescriptionDomain() + */ + @Override + public String formatDescriptionDomain() { + String template = "{0}"; + String param = this.inRange ? this.toString() : "Sin rango"; + String msg = MessageFormat.format(template, param).toString(); + return msg; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + String template = "[ {0}, {1} ]"; + return MessageFormat.format(template, this.min, this.max).toString(); + } + + /* + * (non-Javadoc) + * + * @see flintstones.entity.domain.Domain#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) + return true; + + if (obj == null) + return false; + + if ((obj.getClass() != this.getClass()) || !super.equals(obj)) + return false; + + final NumericDomain other = (NumericDomain) obj; + + EqualsBuilder eb = new EqualsBuilder(); + eb.append(this.inRange, other.inRange); + eb.append(this.max, other.max); + eb.append(this.min, other.min); + + return eb.isEquals(); + } + + /* + * (non-Javadoc) + * + * @see flintstones.entity.domain.Domain#hashCode() + */ + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(17, 31); + hcb.append(super.hashCode()); + hcb.append(this.inRange); + hcb.append(this.max); + hcb.append(this.min); + return hcb.toHashCode(); + } + + /* + * (non-Javadoc) + * + * @see flintstones.entity.domain.Domain#write(javax.xml.stream.XMLStreamWriter) + */ + @Override + public void write(XMLStreamWriter writer) throws XMLStreamException { + writer.writeAttribute("inRange", Boolean.toString(this.inRange)); //$NON-NLS-1$ + writer.writeAttribute("min", Double.toString(this.min)); //$NON-NLS-1$ + writer.writeAttribute("max", Double.toString(this.max)); //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see flintstones.entity.domain.Domain#clone() + */ + @Override + public Object clone() { + NumericDomain result = null; + result = (NumericDomain) super.clone(); + + return result; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/Messages.java b/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/Messages.java new file mode 100644 index 0000000..3834314 --- /dev/null +++ b/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/Messages.java @@ -0,0 +1,38 @@ +// This file has been auto-generated +package flintstones.domain.numeric.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String NumericDomain_formatTemplate; + public String NumericDomain_toStringTemplate; + public String NumericDomainChart_range; + public String plusInfinity; + public String noInfinity; + public String Without_range; + public String lessInfinity; + public String label_domain_name; + public String error_domain_name; + public String limits; + public String rangeless; + public String limitless; + public String error_limits; + public String error_limits1; + public String to; + public String error_limits2; + public String preview; + public String dialogTitleTemplate; + public String crating; + public String integer; + public String intervalar; + public String error_empty_domain; + public String error_alredy_used_name; + public String error_out_of_limits; + public String modifying; + public String real; + public String blank; + +} \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/messages.properties b/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/messages.properties new file mode 100644 index 0000000..a78a34a --- /dev/null +++ b/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/messages.properties @@ -0,0 +1,28 @@ +Without_range=Without range +error_limits1=limits1 +error_limits2=limits2 +error_domain_name=name +error_limits=limits +chart=chart +crating=Creating +dialogTitleTemplate=%s domain of type %s %s +label_domain_name=Domain name +error_alredy_used_name=The chosen name is alredy used by another domain +error_empty_domain=Domain name can not be empty +error_out_of_limits=The first limit must be smaller than the second one +integer=Integer +intervalar=intervalar +lessInfinity=-Infinity +limitless=(-\u221E to \u221E) +limits=Limits +modifying=Editing +noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +NumericDomainChart_range=Range +plusInfinity=+Infinity +preview=Preview +rangeless=No range +real=Real +to=to +NumericDomain_formatTemplate={0} {1} +NumericDomain_toStringTemplate=[ {0} - {1} ] +blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ No newline at end of file diff --git a/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/messages_es.properties b/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/messages_es.properties new file mode 100644 index 0000000..bd9a835 --- /dev/null +++ b/bundles/flintstones.domain.numeric/src/flintstones/domain/numeric/messages/messages_es.properties @@ -0,0 +1,28 @@ +Without_range=Sin rango +error_limits1=limits1 +error_limits2=limits2 +error_domain_name=name +error_limits=limits +chart=chart +crating=Creando +dialogTitleTemplate=%s dominio de tipo %s %s +label_domain_name=Nombre del dominio +error_alredy_used_name=El nombre ya esta siendo usado por otro dominio +error_empty_domain=El nombre de dominio no puede estar vacio +error_out_of_limits=El limite inferior debe ser menor que el limite superior +integer=Entero +intervalar=intervalar +limitless=(-\u221E to \u221E) +limits=Limites +modifying=Modificando +preview=Previsualizacin +rangeless=Sin rango +real=Real +to=a +NumericDomainChart_range=Rango +plusInfinity=+Infinito +lessInfinity=-Infinito +noInfinity=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ +NumericDomain_formatTemplate={0} {1} +NumericDomain_toStringTemplate=[ {0} - {1} ] +blank=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ No newline at end of file diff --git a/bundles/flintstones.element.common.ui/.classpath b/bundles/flintstones.element.common.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.element.common.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.element.common.ui/.polyglot.META-INF b/bundles/flintstones.element.common.ui/.polyglot.META-INF new file mode 100644 index 0000000..9b20927 --- /dev/null +++ b/bundles/flintstones.element.common.ui/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.element.common.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Views common + + Sinbad2 + + diff --git a/bundles/flintstones.element.common.ui/.project b/bundles/flintstones.element.common.ui/.project new file mode 100644 index 0000000..28c71f3 --- /dev/null +++ b/bundles/flintstones.element.common.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.element.common.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362551 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.element.common.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.element.common.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.element.common.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.element.common.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.element.common.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.element.common.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.element.common.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.element.common.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.element.common.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.element.common.ui/META-INF/MANIFEST.MF b/bundles/flintstones.element.common.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a604aa4 --- /dev/null +++ b/bundles/flintstones.element.common.ui/META-INF/MANIFEST.MF @@ -0,0 +1,37 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Views common +Bundle-SymbolicName: flintstones.element.common.ui +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.view.common +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.valuation.ui;visibility:=reexport, + flintstones.application.constants;visibility:=reexport, + flintstones.helper.wtable;visibility:=reexport, + org.eclipse.e4.ui.di;visibility:=reexport, + org.eclipse.e4.ui.workbench;visibility:=reexport, + org.eclipse.e4.ui.model.workbench;visibility:=reexport, + flintstones.entity.problemelement, + flintstones.model.problemelement.service, + org.eclipse.e4.core.services, + javax.inject, + org.eclipse.jface, + flintstones.helper.ui, + flintstones.model.domain.service, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.entity.domain, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.model.domain.ui.service, + javax.annotation, + flintstones.model.ui.service, + flintstones.entity.problemelement.ui, + flintstones.helper.faq, + flintstones.model.application.service, + org.eclipse.nebula.widgets.opal.notifier, + flintstones.helper.debug +Export-Package: flintstones.element.common.ui.parts, + flintstones.element.common.ui.providers, + flintstones.element.common.ui.views diff --git a/bundles/flintstones.element.common.ui/build.properties b/bundles/flintstones.element.common.ui/build.properties new file mode 100644 index 0000000..0b1b0c4 --- /dev/null +++ b/bundles/flintstones.element.common.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + faq/ diff --git a/bundles/flintstones.element.common.ui/faq/SelectorPart.en.md b/bundles/flintstones.element.common.ui/faq/SelectorPart.en.md new file mode 100644 index 0000000..4338816 --- /dev/null +++ b/bundles/flintstones.element.common.ui/faq/SelectorPart.en.md @@ -0,0 +1,70 @@ +# Selector de elemento de problema + +## Contexto + +Cuando se define un problema, se añaden 4 tipos de elementos: + - Expertos + - Alternativas + - Criterios + - Dominios + +Los 3 primeros son los elementos del problema. Para cada combinación de Experto + Alternative + Criterio se podrá asignar un dominio, el cual define como debe puntuar el **Experto** seleccionado el **Criterio** para esa **Alternativa**. + +En el panel de la izquierda se puede cambiar la visualización, para mostrar el problema desde el punto de vista de un Experto/Alternativa/Criterio concreto. + +En este panel es posible selecciona una casilla de la tabla que se este mostrando para introducir la valoración, dados los elementos de problema seleccionados. + +## Exísten controles adicionales: +- Con el botón azul es posible transponer la matriz. +- Con la X es posible eliminar todas las valoraciones de la tabla actual +- Si copias desde Excel una tabla con valoraciones, es posible pegarlas. Para que esto funcione, la tabla que se pegue debe tener una cabecera para las columnas (la primera fila) y una cabecera para las filas (el primer valor de cada fila). Estas cabeceras tendrán que coincidir con los elementos de problema introducidos previamente. El programa se encargará de mapear las cabeceras con los elementos de problema. + +### Dominios soportados: +- Real: El valor de la celda debe ser el valor númerico separado con un solo punto o coma (1.234 o 1 o 0.123 o 1,123). +- Entero: El valor de la celda será el valor númerico: ( 1 o 2 o -1) +- Linguistica: El valor será el indice de la etiquea empezando en 0 o el nombre de la etiqueta. 0 => Mala, 1 => Buena ( 0 o Mala, 1 o Buena ). +- No balanceado: Similar a Linguistico. + +Para pegar indices es necesario que las celdas en Excel no estén formateadas como numeros. [Más información](https://support.office.com/es-es/article/convertir-en-n%C3%BAmero-los-n%C3%BAmeros-guardados-como-texto-40105f2a-fe79-4477-a171-c5bad0f0a885). + +### Ejemplo: + +Queremos introducir los valores de este excel: +![faq/excel.png](faq/excel.png) + +Añadimos los elementos de problema. Como solo hay un experto pulsamos el botón de añadir rápido: + +![faq/elements.png](faq/elements.png) + +Para añadir las alternativas, las seleccionamos en Excel y copiamos con Ctrl+C. + +![fastPasteAlternatives.png](faq/fastPasteAlternatives.png) + +Seleccionamos el panel de alternativas (la pestaña se activará en blanco) y pulsamos Ctrl+V. Las alternativas se añadirán. + +![fastPasteAlternatives2.png](faq/fastPasteAlternatives2.png) + +Hacemos lo mísmo con los criterios, en este caso serían la cabecera de la tabla: +![fastPasteCriterion.png](faq/fastPasteCriterion.png) + +Creamos un dominio teniendo en cuenta los datos. En este caso será un dominio numerico real entre 0 y 100. + +Realizamos la asignación del dominio. + +Desde la pantalla Gathering, usamos el filtro de elementos de problema para obtener un listado de los expertos + +![filter.png](faq/filter.png) + +Seleccionamos el único experto que tenemos, de tal forma que nos quede una visualización igual a la del Excel. + +![expert.png](faq/expert.png) + +Seleccionamos los datos en Excel y pulsamos Ctrl+C: + +![data.png](faq/data.png) + +Pulsamos sobre el panel con la tabla y pulsamos Ctrl+V: + +![result.png](faq/result.png) + +El resultado aparecerá en una notificación. diff --git a/bundles/flintstones.element.common.ui/faq/SelectorPart.es.md b/bundles/flintstones.element.common.ui/faq/SelectorPart.es.md new file mode 100644 index 0000000..70f72bc --- /dev/null +++ b/bundles/flintstones.element.common.ui/faq/SelectorPart.es.md @@ -0,0 +1,63 @@ +# Selector de elemento de problema + +## Contexto + +Cuando se define un problema, se añaden 4 tipos de elementos: + - Expertos + - Alternativas + - Criterios + - Dominios + +Los 3 primeros son los elementos del problema. Para cada combinación de Experto + Alternative + Criterio se podrá asignar un dominio, el cual define como debe puntuar el **Experto** seleccionado el **Criterio** para esa **Alternativa**. + +En el panel de la izquierda se puede cambiar la visualización, para mostrar el problema desde el punto de vista de un Experto/Alternativa/Criterio concreto. + +En este panel es posible selecciona una casilla de la tabla que se este mostrando para introducir la valoración, dados los elementos de problema seleccionados. + +## Exísten controles adicionales: +- Con el botón azul es posible transponer la matriz. +- Con la X es posible eliminar todas las valoraciones de la tabla actual +- Si copias desde Excel una tabla con valoraciones, es posible pegarlas. Para que esto funcione, la tabla que se pegue debe tener una cabecera para las columnas (la primera fila) y una cabecera para las filas (el primer valor de cada fila). Estas cabeceras tendrán que coincidir con los elementos de problema introducidos previamente. El programa se encargará de mapear las cabeceras con los elementos de problema. + + +### Ejemplo: + +Queremos introducir los valores de este excel: +![faq/excel.png](faq/excel.png) + +Añadimos los elementos de problema. Como solo hay un experto pulsamos el botón de añadir rápido: + +![faq/elements.png](faq/elements.png) + +Para añadir las alternativas, las seleccionamos en Excel y copiamos con Ctrl+C. + +![fastPasteAlternatives.png](faq/fastPasteAlternatives.png) + +Seleccionamos el panel de alternativas (la pestaña se activará en blanco) y pulsamos Ctrl+V. Las alternativas se añadirán. + +![fastPasteAlternatives2.png](faq/fastPasteAlternatives2.png) + +Hacemos lo mísmo con los criterios, en este caso serían la cabecera de la tabla: +![fastPasteCriterion.png](faq/fastPasteCriterion.png) + +Creamos un dominio teniendo en cuenta los datos. En este caso será un dominio numerico real entre 0 y 100. + +Realizamos la asignación del dominio. + +Desde la pantalla Gathering, usamos el filtro de elementos de problema para obtener un listado de los expertos + +![filter.png](faq/filter.png) + +Seleccionamos el único experto que tenemos, de tal forma que nos quede una visualización igual a la del Excel. + +![expert.png](faq/expert.png) + +Seleccionamos los datos en Excel y pulsamos Ctrl+C: + +![data.png](faq/data.png) + +Pulsamos sobre el panel con la tabla y pulsamos Ctrl+V: + +![result.png](faq/result.png) + +El resultado aparecerá en una notificación. diff --git a/bundles/flintstones.element.common.ui/faq/data.png b/bundles/flintstones.element.common.ui/faq/data.png new file mode 100644 index 0000000..4b75a89 Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/data.png differ diff --git a/bundles/flintstones.element.common.ui/faq/elements.png b/bundles/flintstones.element.common.ui/faq/elements.png new file mode 100644 index 0000000..dabe5a0 Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/elements.png differ diff --git a/bundles/flintstones.element.common.ui/faq/excel.png b/bundles/flintstones.element.common.ui/faq/excel.png new file mode 100644 index 0000000..dd93ae2 Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/excel.png differ diff --git a/bundles/flintstones.element.common.ui/faq/expert.png b/bundles/flintstones.element.common.ui/faq/expert.png new file mode 100644 index 0000000..87da7da Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/expert.png differ diff --git a/bundles/flintstones.element.common.ui/faq/fastAddPE.png b/bundles/flintstones.element.common.ui/faq/fastAddPE.png new file mode 100644 index 0000000..d1ff902 Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/fastAddPE.png differ diff --git a/bundles/flintstones.element.common.ui/faq/fastPasteAlternatives.png b/bundles/flintstones.element.common.ui/faq/fastPasteAlternatives.png new file mode 100644 index 0000000..5d55c4f Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/fastPasteAlternatives.png differ diff --git a/bundles/flintstones.element.common.ui/faq/fastPasteAlternatives2.png b/bundles/flintstones.element.common.ui/faq/fastPasteAlternatives2.png new file mode 100644 index 0000000..fdde9c5 Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/fastPasteAlternatives2.png differ diff --git a/bundles/flintstones.element.common.ui/faq/fastPasteCriterion.png b/bundles/flintstones.element.common.ui/faq/fastPasteCriterion.png new file mode 100644 index 0000000..c302f9a Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/fastPasteCriterion.png differ diff --git a/bundles/flintstones.element.common.ui/faq/filter.png b/bundles/flintstones.element.common.ui/faq/filter.png new file mode 100644 index 0000000..6e19a27 Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/filter.png differ diff --git a/bundles/flintstones.element.common.ui/faq/result.png b/bundles/flintstones.element.common.ui/faq/result.png new file mode 100644 index 0000000..511258f Binary files /dev/null and b/bundles/flintstones.element.common.ui/faq/result.png differ diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/Messages.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/Messages.java new file mode 100644 index 0000000..9e436c3 --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/Messages.java @@ -0,0 +1,16 @@ +// This file has been auto-generated +package flintstones.element.common.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String label_domain_description; + public String label_domain_name; + public String label_domain_valuation; + public String SelectorPart_title_template; + public String SelectorPart_valuation_missing; + +} diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/messages.properties b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/messages.properties new file mode 100644 index 0000000..416af3a --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/messages.properties @@ -0,0 +1,5 @@ +label_domain_description=Description +label_domain_name=Domains +label_domain_valuation=Valuation +SelectorPart_title_template={0} | {1} +SelectorPart_valuation_missing=No valuation diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/messages_es.properties b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/messages_es.properties new file mode 100644 index 0000000..8b46a63 --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/messages/messages_es.properties @@ -0,0 +1,5 @@ +label_domain_description=Descripciones +label_domain_name=Dominios +label_domain_valuation=Evaluaciones +SelectorPart_title_template={0} | {1} +SelectorPart_valuation_missing=Sin valoracin \ No newline at end of file diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/parts/FilterPart.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/parts/FilterPart.java new file mode 100644 index 0000000..afeb819 --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/parts/FilterPart.java @@ -0,0 +1,328 @@ +package flintstones.element.common.ui.parts; + +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.element.common.ui.providers.ProblemElementFilterContentProvider; +import flintstones.element.common.ui.providers.ProblemElementFilterLabelProvider; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.problemelement.provider.ProblemElementTitleProvider; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class FilterPart. + * + * @author Sinbad2 Gathering UI part that makes posible to filter out the + * expert/criteria/domain + */ +public class FilterPart { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The part. */ + @Inject + MPart part; + + @Inject + @Translation + private flintstones.entity.problemelement.messages.Messages problemMessages; + + /** The treeviewer. */ + private TreeViewer tv; + + /** The combo to chose the type. */ + private Combo combo; + + /** The tree selection listener. */ + private ISelectionChangedListener treeSelectionListener; + + /** The combo selection adapter. */ + private SelectionAdapter comboSelectionAdapter; + + /** The current problem element. */ + private ProblemElement currentProblemElement; + + /** The current selection. */ + private ISelection currentSelection; + + /** The Constant SUB_ID. */ + private static final String SUB_ID = FrameworkConstants.TOPIC_FRAMEWORK_ALLTOPICS; + + /** + * Adds the combo. + * + * @param parent the parent + */ + private void addCombo(Composite parent) { + this.combo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY); + + this.combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + this.drawComboItems(); + + } + + private void drawComboItems() { + String items[] = { this.problemMessages.ALTERNATIVE_ENTITY_NAME, this.problemMessages.EXPERT_ENTITY_NAME, + this.problemMessages.CRITERION_ENTITY_NAME }; + this.combo.removeAll(); + this.combo.setItems(items); + this.combo.select(0); + } + + /** + * Inits the. + * + * @param parent Called after construct to build the controls + */ + @PostConstruct + public void init(Composite parent) { + this.createControls(parent); + } + + /** + * Creates the controls. + * + * @param parent the parent + * @return the composite + */ + public Composite createControls(Composite parent) { + + this.setLayout(parent); + this.addTreeViewer(parent); + this.addCombo(parent); + + this.addListeners(); + return parent; + + } + + /** + * Sets the layout. + * + * @param parent the new layout + */ + private void setLayout(Composite parent) { + GridLayout layout = new GridLayout(1, false); + + layout.verticalSpacing = 2; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.horizontalSpacing = 0; + parent.setLayout(layout); + } + + /** + * Adds the tree viewer. + * + * @param parent the parent + */ + private void addTreeViewer(Composite parent) { + this.tv = new TreeViewer(parent); + this.tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); + + ProblemElementFilterContentProvider pefcp = ContextInjectionFactory + .make(ProblemElementFilterContentProvider.class, this.context); + ProblemElementFilterLabelProvider peflp = ContextInjectionFactory.make(ProblemElementFilterLabelProvider.class, + this.context); + + this.tv.setContentProvider(pefcp); + this.tv.setLabelProvider(peflp); + this.tv.setInput(this.problemService.getMainElements(Alternative.Type)); + + } + + /** + * Refresh. + */ + public void refresh() { + this.tv.setInput(this.problemService.getMainElements(Alternative.Type)); + this.setCurrentItem(null); + } + + /** + * Try to recover the selected items after a change in the combo. + * https://stackoverflow.com/questions/17453515/get-all-treeitems-in-an-swt-tree + */ + private void tryRecoverSelection() { + + if (this.currentSelection == null) + return; + this.getTreeviewer().setSelection(this.currentSelection); + } + + /** + * Adds the listeners. + */ + private void addListeners() { + this.treeSelectionListener = this.selectionListener(); + this.comboSelectionAdapter = this.selectionAdapter(); + + this.tv.addSelectionChangedListener(this.treeSelectionListener); + this.combo.addSelectionListener(this.comboSelectionAdapter); + } + + /** + * Selection adapter. + * + * @return the selection adapter + */ + private SelectionAdapter selectionAdapter() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + + int index = FilterPart.this.combo.getSelectionIndex(); + boolean next = index > 0; + boolean nextnext = index > 1; + + String type = ProblemElementHelper.getNextType(Alternative.Type, next, nextnext); + + ProblemElement[] l = FilterPart.this.problemService.getMainElements(type); + FilterPart.this.tv.setInput(l); + FilterPart.this.tryRecoverSelection(); + + } + }; + } + + /** + * Selection listener. + * + * @return the selection changed listener + */ + private ISelectionChangedListener selectionListener() { + return event -> { + ISelection selection = event.getSelection(); + Iterator selectedElements = ((IStructuredSelection) selection).iterator(); + + if (!selectedElements.hasNext()) + return; + + ProblemElement pe = (ProblemElement) selectedElements.next(); + if (!pe.hasChildren()) { + FilterPart.this.setCurrentProblemElement(pe); + FilterPart.this.setCurrentItem(selection); + ((SelectorPart) FilterPart.this.context.getParent().get(SelectorPart.ID)).initTable(pe); + + String titleLabel = ContextInjectionFactory + .make(ProblemElementTitleProvider.class, FilterPart.this.context).getTitle(pe); + FilterPart.this.part.setLabel(titleLabel); + + } + + }; + } + + /** + * Gets the treeviewer. + * + * @return the treeviewer + */ + public TreeViewer getTreeviewer() { + return this.tv; + } + + /** + * Sets the treeviewer. + * + * @param tv the new treeviewer + */ + public void setTreeviewer(TreeViewer tv) { + this.tv = tv; + } + + /** + * Removes the listeners. + */ + public void removeListeners() { + this.tv.removeSelectionChangedListener(this.treeSelectionListener); + } + + /** + * Subscribe. + * + * @param event the event + */ + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribe(@UIEventTopic(FilterPart.SUB_ID) Map event) { + this.refresh(); + } + + /** + * Gets the current problem element. + * + * @return the currentProblemElement + */ + ProblemElement getCurrentProblemElement() { + return this.currentProblemElement; + } + + /** + * Sets the current problem element. + * + * @param currentProblemElement the currentProblemElement to set + */ + public void setCurrentProblemElement(ProblemElement currentProblemElement) { + this.currentProblemElement = currentProblemElement; + } + + /** + * Gets the current item. + * + * @return the currentSelection + */ + public ISelection getCurrentItem() { + return this.currentSelection; + } + + /** + * Sets the current item. + * + * @param currentItem the new current item + */ + public void setCurrentItem(ISelection currentItem) { + this.currentSelection = currentItem; + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + this.drawComboItems(); + } +} \ No newline at end of file diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/parts/SelectorPart.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/parts/SelectorPart.java new file mode 100644 index 0000000..82ed0f8 --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/parts/SelectorPart.java @@ -0,0 +1,371 @@ +package flintstones.element.common.ui.parts; + +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.nebula.widgets.opal.notifier.NotifierColorsFactory.NotifierTheme; +import org.eclipse.nebula.widgets.opal.notifier.WNotifier; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; + +import de.kupzog.ktable.KTable; +import flintstones.application.constants.FrameworkConstants; +import flintstones.element.common.ui.messages.Messages; +import flintstones.element.common.ui.providers.AssignmentsTableProvider; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.debug.DH; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.helper.wtable.WTable; +import flintstones.helper.wtable.WTableModel; +import flintstones.helper.wtable.event.WTableCellClickListener; +import flintstones.helper.wtable.event.WTableCellModifiedListener; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.cell.ValuationTableCell; +import flintstones.valuation.ui.service.IValuationUIService; + +/** + * The Class SelectorPart. + * + * @author Sinbad 2 Gathering UI Part to select the item to rate. Confidential + * Announcement: This is some confidential text that you really + * shouldn't be sharing anywhere else. + */ +public class SelectorPart implements WTableCellClickListener, WTableCellModifiedListener, IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The valuation UI service. */ + @Inject + IValuationUIService valuationUIService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** The part. */ + @Inject + MPart part; + + /** The Constant ID. */ + public static final String ID = SelectorPart.class.getName(); + /** The Constant BUS_ID. */ + private static final String BUS_ID = FrameworkConstants.TOPIC_SELECTION_VALUATION; + + /** The Constant SUB_ID_TRANSPOSE. */ + private static final String SUB_ID_TRANSPOSE = "TOPIC/COMMAND/TRANSPOSE"; //$NON-NLS-1$ + + /** The is transposed. */ + private boolean isTransposed = false; + + /** The ktable. */ + private KTable ktable; + + /** The table model. */ + private WTableModel tableModel; + + /** The provider. */ + private AssignmentsTableProvider provider; + + /** The base composite. */ + private Composite baseComposite; + + /** The current problem element. */ + private ProblemElement currentProblemElement = null; + + @Inject + @Translation + private flintstones.entity.problemelement.messages.Messages problemMessages; + + /** + * Inits the part. + * + * @param parent Creates the ui + */ + @PostConstruct + public void init(Composite parent) { + this.baseComposite = parent; + this.context.getParent().set(SelectorPart.ID, this); + parent.getParent().setLayout(new FillLayout()); + + // Tablas + ProblemElement[] items = problemService.getAll(Alternative.Type); + if (items.length > 0) { + this.drawTable(parent); + this.initTable(items[0]); + } + + } + + public void refreshTable() { + if (this.currentProblemElement != null) + this.initTable(this.currentProblemElement); + baseComposite.layout(); + } + + /** + * Draw table. + * + * @param parent the parent + */ + private void drawTable(Composite parent) { + Composite cc = new Composite(parent, SWT.NONE); + + cc.setLayout(new FillLayout()); + this.ktable = new WTable(cc, SWT.V_SCROLL); + + } + + /** + * Inits the table. + * + * @param pe Problem Element Draw a table for the given Problem Element + */ + void initTable(ProblemElement pe) { + + if (this.ktable == null) + this.drawTable(this.baseComposite); + + // Part title +// String partTitleTemplate = this.messages.SelectorPart_title_template; +// String title = MessageFormat.format(partTitleTemplate, pe.getType(), pe.getCanonicalName()); +// this.part.setLabel(title); + // + this.currentProblemElement = pe; + + drawPartTitle(); + + // Table + this.provider = ContextInjectionFactory.make(AssignmentsTableProvider.class, this.context); + this.provider.show(Valuation.Fields.Valuation.toString()); + this.provider.prepareTableContent(this.currentProblemElement); + if (this.isTransposed) + this.provider.transpose(); + + this.setTable(); + } + + /** + * Sets the table. + */ + private void setTable() { + + // Clear last table listener if it exists + if (this.tableModel != null) + this.tableModel.clearListeners(); + + this.tableModel = new WTableModel(this.ktable); + + // Cabeceras + this.tableModel.setHorizontalHeaders(this.provider.getTableHeaderH()); + this.tableModel.setVerticalHeaders(this.provider.getTableHeaderV()); + + // Contenido, PH, Abbr + this.tableModel.addContent(this.provider.getTableValuations()); + this.tableModel.setEmptyCellPlaceholder(this.messages.SelectorPart_valuation_missing); + this.tableModel.setEmptyIsWrong(true); + + this.ktable.setModel(this.tableModel); + this.tableModel.addListener((WTableCellClickListener) this); + this.tableModel.addListener((WTableCellModifiedListener) this); + this.tableModel.init(); + } + + /* + * (non-Javadoc) + * + * @see + * flintstones.helper.wtable.event.WTableCellModifiedListener#cellModified(int, + * int, java.lang.Object, java.lang.Object) + */ + @Override + public void cellModified(int col, int row, Object oldValue, Object newValue) { + // System.out.println("[Gathering/cellModified] ModificadaCelda " + col + "," + + // row + " " + oldValue + " -> " + newValue); + } + + /* + * (non-Javadoc) + * + * @see flintstones.helper.wtable.event.WTableCellClickListener#cellClicked(int, + * int, java.lang.Object) + */ + @Override + public void cellClicked(int col, int row, Object cell) { + ValuationTableCell vtc; + + try { + vtc = (ValuationTableCell) cell; + } catch (Exception e) { + + new WNotifier("Aún no", // + "Debes asignar un dominio a esta celda antes de continuar.", // + NotifierTheme.YELLOW_THEME // + ).withCloseOnClick(true).withTimeout(15).send(); + return; + + } + + if (this.isTransposed) { + int x = col; + col = row; + row = x; + } + + ProblemElementKey pek = this.provider.getPek(col, row); + if (pek != null) { + HashMap map = new HashMap<>(); + map.put("cell", vtc); //$NON-NLS-1$ + map.put("pek", pek); //$NON-NLS-1$ + this.broker.post(SelectorPart.BUS_ID, map); + } + + } + + /** + * Subscribe transpose. + * + * @param event the event + */ + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribeTranspose(@UIEventTopic(SelectorPart.SUB_ID_TRANSPOSE) Map event) { + if (this.currentProblemElement != null) { + this.provider.transpose(); + this.setTable(); + this.isTransposed = !this.isTransposed; + } + } + + public ProblemElement getCurrentProblemElement() { + return currentProblemElement; + } + + @Override + public String getFAQFile() { + return "faq/SelectorPart"; + } + + /** + * Subscribe selection. + * + * @param event the event + */ + @Inject + @Optional + private void subscribeSelectionAlt( + @UIEventTopic(FrameworkConstants.TOPIC_SELECTION_FRAMEWORK_PROBLEMELEMENT) ProblemElement pe) { + + if (pe != null && !(pe instanceof FakeProblemElement)) { + this.initTable(pe); + this.refreshTable(); + } + DH.out("refresh", "gt subscribeSelectionAlt"); + + } + + // NEW + /** + * Subscribe valuation. + * + * @param event the event + */ + @SuppressWarnings("unused") + @Inject + @Optional + private void subscribeValuation(@UIEventTopic(FrameworkConstants.TOPIC_VALUATION_ALLTOPICS) Map event) { + + if (this.currentProblemElement != null) + this.initTable(this.currentProblemElement); + + DH.out("refresh", "gt subscribeValuation"); + + } + + @SuppressWarnings("unused") + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + DH.out("refresh", "getNotified"); + + this.drawPartTitle(); + } + + private void drawPartTitle() { + ProblemElement pe = this.currentProblemElement; + String template = "{0} | {1}"; + + String type = pe.getType(); + String label = ""; //$NON-NLS-1$ + + if (type.equals(Alternative.Type)) + label = this.problemMessages.ALTERNATIVE_ENTITY_NAME; + else if (type.equals(Criterion.Type)) + label = this.problemMessages.CRITERION_ENTITY_NAME; + else if (type.equals(Expert.Type)) + label = this.problemMessages.EXPERT_ENTITY_NAME; + + String message = MessageFormat.format(template, label, pe.getCanonicalName()); + this.part.setLabel(message); + } + + @Inject + @Optional + private void subscribeFramework(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_CREATED) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + + if (items.length > 0) + this.initTable(items[0]); + DH.out("refresh", "subscribeFramework"); + } + + @Inject + @Optional + private void subscribeFramework2(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_ALLTOPICS) Object o) { + ProblemElement[] items = this.problemService.getAll(Expert.Type); + + if (items.length > 0) + this.initTable(items[0]); + DH.out("refresh", "subscribeFramework"); + } +} \ No newline at end of file diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/AssignmentsTableProvider.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/AssignmentsTableProvider.java new file mode 100644 index 0000000..e5731ee --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/AssignmentsTableProvider.java @@ -0,0 +1,243 @@ + +package flintstones.element.common.ui.providers; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.stream.Collectors; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.wtable.cell.WTableCell; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.cell.DomainValuationTableCell; +import flintstones.valuation.cell.ValuationTableCell; + +/** + * The Class AssignmentsTableProvider. + * + * @author Sinbad2 + * Prepares table data for a given element + */ +public class AssignmentsTableProvider { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The context. */ + @Inject + IEclipseContext context; + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + /** The item. */ + ProblemElement currentProblemElement; + + /** The show. */ + private String show = Domain.Fields.Domain.toString(); + + /** The table header H. */ + private ArrayList tableHeaderH = new ArrayList<>(); + + /** The table header V. */ + private ArrayList tableHeaderV = new ArrayList<>(); + + /** The table placeholder. */ + private final ArrayList> tablePlaceholder = new ArrayList<>(); + + /** The table PEK. */ + private final ArrayList> tablePEK = new ArrayList<>(); + + /** The table valuations. */ + private ArrayList> tableValuations = new ArrayList<>(); + + /** + * Prepares table data for a given element. + */ + public AssignmentsTableProvider() { + + } + + /** + * Prepare table content. + * + * @param pe Problem Element Item + * For the "item", it prepares a table full of valuations. + * Cols are the next type of PE and + * rows are the next next type of PE. + * ALT -> EXP -> CRIT -> ALT + */ + public void prepareTableContent(ProblemElement pe) { + + this.currentProblemElement = pe; + ProblemElement currentPE = pe; + String currentType = this.currentProblemElement.getType(); + + // Rows and Cols header elements sorted by name + String nextType = ProblemElementHelper.getNextType(currentType, true, false); + String nextNextType = ProblemElementHelper.getNextType(currentType, true, true); + + ProblemElement[] l1 = ProblemElementHelper.getAsUserOrdered(problemService.getSubElements(nextType)); + ProblemElement[] l2 = ProblemElementHelper.getAsUserOrdered(problemService.getSubElements(nextNextType)); + + // Headers to String. Already ordered. + this.setTableHeaderH(Arrays.stream(l1) + .map(ProblemElement::getName) + .collect(Collectors.toCollection(ArrayList::new))); + this.setTableHeaderV(Arrays.stream(l2) + .map(ProblemElement::getName) + .collect(Collectors.toCollection(ArrayList::new))); + + for (ProblemElement pe1 : l1) { + ArrayList peks = new ArrayList<>(); + for (ProblemElement pe2 : l2) { + ProblemElementKey pek = new ProblemElementKey(currentPE, pe1, pe2); + peks.add(pek); + } + this.tablePEK.add(peks); + } + + for (ArrayList kList : this.tablePEK) { + + ArrayList placeholders = new ArrayList<>(); + ArrayList cells = new ArrayList<>(); + + for (ProblemElementKey k : kList) { + Valuation v = this.valuationService.getValuationFor(k); + + WTableCell cell; + if (v == null) { + cell = new WTableCell(); + } else if (this.show.equals(Valuation.Fields.Valuation.toString())) + cell = new ValuationTableCell(v); + else if (this.show.equals(Domain.Fields.Domain.toString())) + cell = new DomainValuationTableCell(v); + else + throw new Error("Invalid show value valuation/domain " + this.show); //$NON-NLS-1$ + + String name = (v != null) ? v.getDomain() + .getName() : ""; //$NON-NLS-1$ + + cells.add(cell); + placeholders.add(name); + } + + this.getTableValuations() + .add(cells); + this.tablePlaceholder.add(placeholders); + } + + } + + /** + * Gets the pek. + * + * @param col col + * @param row row + * @return ProblemElementKey at the requested position + */ + public ProblemElementKey getPek(int col, int row) { + if (this.tablePEK.size() > col) + if (this.tablePEK.get(col) + .size() > row) + return this.tablePEK.get(col) + .get(row); // Table headers + return null; + } + + + /** + * Gets the table header H. + * + * @return The horizontal table header + */ + public String[] getTableHeaderH() { + return this.tableHeaderH.toArray(new String[this.tableHeaderH.size()]); + } + + /** + * Sets the table header H. + * + * @param tableHeaderH the new table header H + */ + private void setTableHeaderH(ArrayList tableHeaderH) { + this.tableHeaderH = tableHeaderH; + } + + /** + * Gets the table header V. + * + * @return The vertical table header + */ + public String[] getTableHeaderV() { + return this.tableHeaderV.toArray(new String[this.tableHeaderV.size()]); + } + + /** + * Sets the table header V. + * + * @param tableHeaderV the new table header V + */ + private void setTableHeaderV(ArrayList tableHeaderV) { + this.tableHeaderV = tableHeaderV; + } + + /** + * Gets the table valuations. + * + * @return The table valuations + */ + public ArrayList> getTableValuations() { + return this.tableValuations; + } + + /** + * Transpose the table. + */ + public void transpose() { + + ArrayList> transposedList = new ArrayList<>(); + + if (this.tableValuations.size() == 0) + return; + + final int firstListSize = this.tableValuations.get(0) + .size(); + for (int i = 0; i < firstListSize; i++) { + ArrayList tempList = new ArrayList<>(); + + for (ArrayList row : this.tableValuations) + tempList.add(row.get(i)); + + transposedList.add(tempList); + } + + this.tableValuations = transposedList; + ArrayList temp = this.tableHeaderH; + this.tableHeaderH = this.tableHeaderV; + this.tableHeaderV = temp; + } + + /** + * Shows either domains or valuations + * @param show the key word domain or valuation + */ + public void show(String show) { + this.show = show; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainDescriptionLabelProvider.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainDescriptionLabelProvider.java new file mode 100644 index 0000000..116be39 --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainDescriptionLabelProvider.java @@ -0,0 +1,54 @@ + + +package flintstones.element.common.ui.providers; + +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.domain.Domain; + + + + +/** + * The Class DomainDescriptionLabelProvider. + */ +public class DomainDescriptionLabelProvider extends LabelProvider implements IStyledLabelProvider { + + /** + * Instantiates a new domain description label provider. + */ + public DomainDescriptionLabelProvider() { + + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider. + * IStyledLabelProvider#getStyledText(java.lang.Object) */ + @Override + public StyledString getStyledText(Object element) { + Domain d = (Domain) element; + StyledString styledString = new StyledString(d.formatDescriptionDomain()); + return styledString; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + return null; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose() */ + @Override + public void dispose() { + + } + +} diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainNameLabelProvider.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainNameLabelProvider.java new file mode 100644 index 0000000..133d79b --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainNameLabelProvider.java @@ -0,0 +1,72 @@ + +/* + * + */ +package flintstones.element.common.ui.providers; + +import javax.inject.Inject; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.domain.Domain; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.ui.service.UiService; + +/** + * The Class DomainNameLabelProvider. + */ +public class DomainNameLabelProvider extends LabelProvider implements IStyledLabelProvider { + + /** The domain ui service. */ + @Inject + IDomainUIService uiDomainService; + + /** The resource service. */ + + /** + * Instantiates a new domain name label provider. + */ + public DomainNameLabelProvider() { + + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider. + * IStyledLabelProvider#getStyledText(java.lang.Object) */ + @Override + public StyledString getStyledText(Object element) { + Domain d = (Domain) element; + StyledString styledString = new StyledString(d.getName()); + return styledString; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + Domain d = (Domain) element; + ImageDescriptor img = null; + + String iconName = "domain/" + d.getType() + ".png"; + img = UiService.getIcon(iconName); + + if (img != null) + return img.createImage(); + + return super.getImage(element); + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose() */ + @Override + public void dispose() { + } + +} diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainValuationLabelProvider.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainValuationLabelProvider.java new file mode 100644 index 0000000..d4f5a52 --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/DomainValuationLabelProvider.java @@ -0,0 +1,64 @@ + + +package flintstones.element.common.ui.providers; + +import javax.inject.Inject; + +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.domain.Domain; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class DomainValuationLabelProvider. + */ +public class DomainValuationLabelProvider extends LabelProvider implements IStyledLabelProvider { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** + * Instantiates a new domain valuation label provider. + */ + public DomainValuationLabelProvider() { + + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider. + * IStyledLabelProvider#getStyledText(java.lang.Object) */ + @Override + public StyledString getStyledText(Object element) { + Domain d = (Domain) element; + String valuationName = this.valuationService.getExtensionNameFor(d.getType()); + + if(valuationName == null) { + valuationName = "[Valuation sin definir para " + d.getType() + "]"; + } + + StyledString styledString = new StyledString(valuationName); + return styledString; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + return null; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose() */ + @Override + public void dispose() { + + } + +} diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/ProblemElementFilterContentProvider.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/ProblemElementFilterContentProvider.java new file mode 100644 index 0000000..3068c4e --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/ProblemElementFilterContentProvider.java @@ -0,0 +1,84 @@ +package flintstones.element.common.ui.providers; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * @author Sinbad2 + * Data to fill the table of tabs 2 and 3 + */ +public class ProblemElementFilterContentProvider implements ITreeContentProvider { + /** + * Gets the children of the specified object + * + * @param arg0 + * the parent object + * @return Object[] + */ + @Override + public Object[] getChildren(Object arg0) { + return ((ProblemElement) arg0).getChildren(); + } + + /** + * Gets the parent of the specified object + * + * @param arg0 + * the object + * @return Object + */ + @Override + public Object getParent(Object arg0) { + return ((ProblemElement) arg0).getParent(); + } + + /** + * Returns whether the passed object has children + * + * @param arg0 + * the parent object + * @return boolean + */ + @Override + public boolean hasChildren(Object arg0) { + Object[] obj = this.getChildren(arg0); + return obj == null ? false : obj.length > 0; + } + + /** + * Gets the root element(s) of the tree + * + * @param arg0 + * the input data + * @return Object[] + */ + @Override + public Object[] getElements(Object arg0) { + return ((ProblemElement[]) arg0); + } + + /** + * Disposes any created resources + */ + @Override + public void dispose() { + // Nothing to dispose + } + + /** + * Called when the input changes + * + * @param arg0 + * the viewer + * @param arg1 + * the old input + * @param arg2 + * the new input + */ + @Override + public void inputChanged(Viewer arg0, Object arg1, Object arg2) { + // Nothing to change + } +} diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/ProblemElementFilterLabelProvider.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/ProblemElementFilterLabelProvider.java new file mode 100644 index 0000000..561b782 --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/providers/ProblemElementFilterLabelProvider.java @@ -0,0 +1,160 @@ +package flintstones.element.common.ui.providers; + +import java.util.ArrayList; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.ui.service.UiService; + +/** + * The Class ProblemElementFilterLabelProvider. + */ +public class ProblemElementFilterLabelProvider implements ILabelProvider { + + /** The resource service. */ + + @Inject + @Translation + private flintstones.entity.problemelement.messages.Messages problemMessages; + + /** The listeners. */ + private ArrayList listeners; + + /** The alt image */ + private Image alt; + + /** The criterion image */ + private Image crit; + + /** The expert image */ + private Image exp; + + /** The criterion group image. */ + private Image critG; + + /** The expert group image */ + private Image expG; + + /** + * Constructs a FileTreeLabelProvider. + */ + public ProblemElementFilterLabelProvider() { + } + + /** + * Inits the. + */ + @PostConstruct + private void init() { + this.listeners = new ArrayList<>(); + + this.alt = UiService.getIcon(this.problemMessages.ALTERNATIVE_IMAGE_CHILD) + .createImage(); + this.crit = UiService.getIcon(this.problemMessages.CRITERION_IMAGE_CHILD) + .createImage(); + this.exp = UiService.getIcon(this.problemMessages.EXPERT_IMAGE_CHILD) + .createImage(); + this.critG = UiService.getIcon(this.problemMessages.CRITERION_IMAGE_PARENT) + .createImage(); + this.expG = UiService.getIcon(this.problemMessages.EXPERT_IMAGE_PARENT) + .createImage(); + + } + + /** + * Gets the image to display for a node in the tree. + * + * @param element the element + * @return Image + */ + @Override + public Image getImage(Object element) { + String type = ((ProblemElement) element).getType(); + + if (element instanceof ProblemElement) { + if (((ProblemElement) element).hasChildren()) + switch (type) { + case "Expert": //$NON-NLS-1$ + return this.expG; + case "Criterion": //$NON-NLS-1$ + return this.critG; + } + + switch (type) { + case "Alternative": //$NON-NLS-1$ + return this.alt; + case "Expert": //$NON-NLS-1$ + return this.exp; + case "Criterion": //$NON-NLS-1$ + return this.crit; + } + } + return null; + } + + /** + * Gets the text to display for a node in the tree. + * + * @param arg0 the node + * @return String + */ + @Override + public String getText(Object arg0) { + return ((ProblemElement) arg0).getName(); + } + + /** + * Adds a listener to this label provider. + * + * @param arg0 the listener + */ + @Override + public void addListener(ILabelProviderListener arg0) { + this.listeners.add(arg0); + } + + /** + * Called when this LabelProvider is being disposed. + */ + @Override + public void dispose() { + // Dispose the images + + if (this.alt != null) + this.alt.dispose(); + if (this.crit != null) + this.crit.dispose(); + if (this.exp != null) + this.exp.dispose(); + } + + /** + * Returns whether changes to the specified property on the specified element + * would affect the label for the element. + * + * @param arg0 the element + * @param arg1 the property + * @return boolean + */ + @Override + public boolean isLabelProperty(Object arg0, String arg1) { + return false; + } + + /** + * Removes the listener. + * + * @param arg0 the listener to remove + */ + @Override + public void removeListener(ILabelProviderListener arg0) { + this.listeners.remove(arg0); + } +} \ No newline at end of file diff --git a/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/views/DomainViewer.java b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/views/DomainViewer.java new file mode 100644 index 0000000..c847a8b --- /dev/null +++ b/bundles/flintstones.element.common.ui/src/flintstones/element/common/ui/views/DomainViewer.java @@ -0,0 +1,229 @@ + +package flintstones.element.common.ui.views; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.ILocaleChangeService; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.workbench.modeling.EPartService; +import org.eclipse.e4.ui.workbench.modeling.ESelectionService; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TableColumn; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.application.model.IApplicationService; +import flintstones.application.model.ProblemType; +import flintstones.element.common.ui.messages.Messages; +import flintstones.element.common.ui.providers.DomainDescriptionLabelProvider; +import flintstones.element.common.ui.providers.DomainNameLabelProvider; +import flintstones.element.common.ui.providers.DomainValuationLabelProvider; +import flintstones.entity.domain.Domain; +import flintstones.model.domain.service.IDomainService; + +/** + * The Class DomainViewer. + */ +public class DomainViewer { + + @Inject + IApplicationService appService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The selection service. */ + @Inject + ESelectionService selectionService; + + /** The current part. */ + @Inject + MPart currentPart; + + /** The part service. */ + @Inject + EPartService partService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The broker. */ + @Inject + IEventBroker broker; + + @Inject + @Translation + private Messages messages; + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + /** The viewer. */ + private TableViewer viewer; + + /** The Constant BUS_ID. */ + private final static String BUS_ID = FrameworkConstants.TOPIC_SELECTION_FRAMEWORK_DOMAIN; + + // Translatable + TableViewerColumn nameColumn; + TableViewerColumn descriptionColumn; + TableViewerColumn valuationColumn; + + /** + * Instantiates a new domain viewer. + */ + public DomainViewer() { + } + + /** + * Creates the controls. + * + * @param parent the parent + */ + public void createControls(Composite parent, boolean showSecondColumn, boolean showThirdColumn) { + + this.createTableViewer(parent); + this.createNameColumn(); + if (showSecondColumn) + this.createDescriptionColumn(); + if (showThirdColumn) + this.createValuationColumn(); + this.addListeners(); + this.updateViewer(); + + } + + /** + * Adds the listeners. + */ + private void addListeners() { + + this.viewer.addSelectionChangedListener(e -> { + ProblemType type = appService.getProblemType(); + + IStructuredSelection selection = (IStructuredSelection) DomainViewer.this.viewer.getSelection(); + this.selectionService.setSelection(selection.getFirstElement()); + Map m = new HashMap<>(); + Domain d = (Domain) selection.getFirstElement(); + m.put(DomainViewer.this.domainMessages.Domain_entity, d); + + if(type.equals(ProblemType.Ranking)) { + DomainViewer.this.broker.post(DomainViewer.BUS_ID, m); + } + }); + + } + + private void createNameColumn() { + this.nameColumn = new TableViewerColumn(this.viewer, SWT.NONE); + this.nameColumn.getColumn().setWidth(200); + DomainNameLabelProvider provider = ContextInjectionFactory.make(DomainNameLabelProvider.class, this.context); + this.nameColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(provider)); + + this.drawNameColumn(); + } + + /** + * Creates the name column. + */ + private void drawNameColumn() { + this.nameColumn.getColumn() + .setText(this.messages.label_domain_name); + } + + /** + * Creates the description column. + */ + private void createDescriptionColumn() { + this.descriptionColumn = new TableViewerColumn(this.viewer, SWT.NONE); + this.descriptionColumn.getColumn().setWidth(200); + DomainDescriptionLabelProvider provider = ContextInjectionFactory.make(DomainDescriptionLabelProvider.class, this.context); + this.descriptionColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(provider)); + + this.drawDescriptionColumn(); + } + + private void drawDescriptionColumn() { + if (descriptionColumn != null) + this.descriptionColumn.getColumn() + .setText(this.messages.label_domain_description); + } + + /** + * Creates the valuation column. + */ + private void createValuationColumn() { + this.valuationColumn = new TableViewerColumn(this.viewer, SWT.NONE); + this.valuationColumn.getColumn() + .setWidth(200); + DomainValuationLabelProvider provider = ContextInjectionFactory.make(DomainValuationLabelProvider.class, this.context); + this.valuationColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(provider)); + + this.drawValuationColumn(); + } + + private void drawValuationColumn() { + if (valuationColumn != null) + this.valuationColumn.getColumn() + .setText(this.messages.label_domain_valuation); + } + + /** + * Creates the table viewer. + * + * @param parent the parent + */ + private void createTableViewer(Composite parent) { + this.viewer = new TableViewer(parent, SWT.FULL_SELECTION); + this.viewer.setContentProvider(new ArrayContentProvider()); + this.viewer.getTable() + .setHeaderVisible(true); + } + + /** + * Update viewer. + */ + public void updateViewer() { + + if (this.viewer != null) { + Domain[] items = this.domainService.getAll(); + Arrays.sort(items); + this.viewer.setInput(items); + packColumnsViewer(); + } + } + + private void packColumnsViewer() { + for(TableColumn tc: this.viewer.getTable().getColumns()) + tc.pack(); + } + + @Inject + @Optional + private void getNotified(@UIEventTopic(ILocaleChangeService.LOCALE_CHANGE) Locale s) { + this.drawNameColumn(); + this.drawDescriptionColumn(); + this.drawValuationColumn(); + this.updateViewer(); + } + +} diff --git a/bundles/flintstones.engine.R/.classpath b/bundles/flintstones.engine.R/.classpath new file mode 100644 index 0000000..47d45ef --- /dev/null +++ b/bundles/flintstones.engine.R/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/flintstones.engine.R/.polyglot.META-INF b/bundles/flintstones.engine.R/.polyglot.META-INF new file mode 100644 index 0000000..f06bf0b --- /dev/null +++ b/bundles/flintstones.engine.R/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.engine.R + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] R + diff --git a/bundles/flintstones.engine.R/.project b/bundles/flintstones.engine.R/.project new file mode 100644 index 0000000..8d614a3 --- /dev/null +++ b/bundles/flintstones.engine.R/.project @@ -0,0 +1,50 @@ + + + flintstones.engine.R + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362552 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.engine.R/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.engine.R/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.engine.R/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.engine.R/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.engine.R/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.engine.R/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.engine.R/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.engine.R/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.engine.R/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.engine.R/META-INF/MANIFEST.MF b/bundles/flintstones.engine.R/META-INF/MANIFEST.MF new file mode 100644 index 0000000..da19c99 --- /dev/null +++ b/bundles/flintstones.engine.R/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: R +Bundle-SymbolicName: flintstones.engine.R +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flinstones.engine.R +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.di, + org.eclipse.e4.core.contexts, + org.eclipse.e4.ui.model.workbench, + javax.inject, + org.eclipse.core.jobs, + org.eclipse.e4.core.services, + org.eclipse.equinox.registry, + org.eclipse.swt, + javax.annotation +Import-Package: flintstones.entity.domain.messages, + flintstones.entity.problemelement.messages +Bundle-ClassPath: lib/JRI.jar, + . +Export-Package: flintstones.engine.R, + flintstones.engine.R.provider, + flintstones.engine.R.provider.internal, + org.rosuda.JRI +Service-Component: component.xml +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.engine.R/build.properties b/bundles/flintstones.engine.R/build.properties new file mode 100644 index 0000000..2ef8f9f --- /dev/null +++ b/bundles/flintstones.engine.R/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + lib/,\ + lib/JRI.jar,\ + component.xml +jars.compile.order = . diff --git a/bundles/flintstones.engine.R/component.xml b/bundles/flintstones.engine.R/component.xml new file mode 100644 index 0000000..5930251 --- /dev/null +++ b/bundles/flintstones.engine.R/component.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/bundles/flintstones.engine.R/lib/JRI.jar b/bundles/flintstones.engine.R/lib/JRI.jar new file mode 100644 index 0000000..dcc6dda Binary files /dev/null and b/bundles/flintstones.engine.R/lib/JRI.jar differ diff --git a/bundles/flintstones.engine.R/src/flintstones/engine/R/R.java b/bundles/flintstones.engine.R/src/flintstones/engine/R/R.java new file mode 100644 index 0000000..c6e0745 --- /dev/null +++ b/bundles/flintstones.engine.R/src/flintstones/engine/R/R.java @@ -0,0 +1,60 @@ +package flintstones.engine.R; + +import javax.script.ScriptException; + +import org.rosuda.JRI.Rengine; + +import flintstones.engine.R.engine.IEngine; + +/** + * R engine for ASE + * + * @author Sinbad² + * @version 3.0 + */ +public class R implements IEngine { + + public static final String ID = "R"; //$NON-NLS-1$ + + private Rengine rengine; + private String name; + + private R() { + super(); + name = ID; + rengine = null; + } + + /** + * Build R engine + * + * @param rengine + * JRI Rengine + */ + public R(Rengine rengine) { + this(); + assert rengine != null; + this.rengine = rengine; + } + + @Override + public String getName() { + return name; + } + + @Override + public Object getEngine() { + return rengine; + } + + @Override + public Object eval(String script) throws ScriptException { + return rengine.eval(script); + } + + @Override + public void end() { + rengine.end(); + } + +} diff --git a/bundles/flintstones.engine.R/src/flintstones/engine/R/engine/IEngine.java b/bundles/flintstones.engine.R/src/flintstones/engine/R/engine/IEngine.java new file mode 100644 index 0000000..2ada26e --- /dev/null +++ b/bundles/flintstones.engine.R/src/flintstones/engine/R/engine/IEngine.java @@ -0,0 +1,37 @@ +package flintstones.engine.R.engine; + +import javax.script.ScriptException; + + +public interface IEngine { + + /** + * Return engine name + * + * @return Engine name + */ + String getName(); + + /** + * Return engine + * + * @return Engine + */ + Object getEngine(); + + /** + * Evaluate script + * + * @param script + * Script to eval + * @return Evaluation result + * @throws ScriptException + */ + Object eval(String script) throws ScriptException; + + /** + * End engine + */ + void end(); + +} diff --git a/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/IREngineProvider.java b/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/IREngineProvider.java new file mode 100644 index 0000000..bfb84ef --- /dev/null +++ b/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/IREngineProvider.java @@ -0,0 +1,20 @@ +package flintstones.engine.R.provider; + +import flintstones.engine.R.engine.IEngine; + + +public interface IREngineProvider { + + public static final String R = "R"; //$NON-NLS-1$ + public static final String R_STATUS = "R_STATUS"; //$NON-NLS-1$ + public static final String R_MANUAL = "R_MANUAL"; //$NON-NLS-1$ + public static final String R_VERSION = "R_VERSION"; + public static final String R_PATHS = "R_PATHS"; //$NON-NLS-1$ + + /** + * Return R engine instance + * + * @return R engine instance + */ + IEngine getEngine(); +} diff --git a/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/internal/REngineDefaultProvider.java b/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/internal/REngineDefaultProvider.java new file mode 100644 index 0000000..12ca241 --- /dev/null +++ b/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/internal/REngineDefaultProvider.java @@ -0,0 +1,173 @@ +package flintstones.engine.R.provider.internal; + +import java.io.File; +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; +import org.rosuda.JRI.Rengine; + +import flintstones.engine.R.engine.IEngine; +import flintstones.engine.R.R; +import flintstones.engine.R.provider.IREngineProvider; + +public class REngineDefaultProvider implements IREngineProvider { + + private static final String VERSION = "--vanilla"; //$NON-NLS-1$ + + private static final String JRI_IGNORE_FLAG = "jri.ignore.ule"; //$NON-NLS-1$ + private static final String JRI_IGNORE_FLAG_VALUE = "yes"; //$NON-NLS-1$ + + private static final String R_HOME = "R_HOME"; //$NON-NLS-1$ + private static final String BINARIES_DIRECTORY = "bin"; //$NON-NLS-1$ + private static final String LIBRARIES_DIRECTORY = "library"; //$NON-NLS-1$ + + private static final String R_VERSION_CMD = "R.version.string"; //$NON-NLS-1$ + private static final String R_JRI_CMD = "system.file(\"jri\",package=\"rJava\")"; //$NON-NLS-1$ + + + @Inject + private IEclipseContext context; + + private IEclipseContext topContext; + + private R engine; + + private Job job; + + @PostConstruct + private void initialize() { + System.out.println("initialize"); + getTopContext(); + //saveRConfigurationInstructions(); + saveRStatus(); + createEngineJob(R); + } + + private void getTopContext() { + + /*IEclipseContext parent = context; + do { + topContext = parent; + parent = topContext.getParent(); + } while (parent != null);*/ + + MApplication application = context.get(MApplication.class); + topContext = application.getContext(); + + } + + + @Override + public IEngine getEngine() { + try { + job.join(); + } catch (InterruptedException e) { + // Nothing to do + } + return (flintstones.engine.R.engine.IEngine) topContext.get(R); + } + + private void saveRStatus() { + String status = checkDependenciesStatus(); + topContext.set(R_STATUS, status); + } + + private String checkDependenciesStatus() { + System.setProperty(JRI_IGNORE_FLAG, JRI_IGNORE_FLAG_VALUE); + try { + if (!Rengine.jriLoaded) { + return "Invalid jri"; + } + if (!Rengine.versionCheck()) { + return "Invalid jri version"; + } + if (System.getenv(R_HOME) == null) { + return "R_HOME not detected"; + } + if (!validateR_HOME()) { + return "Invalid R_HOME"; + } + } catch (UnsatisfiedLinkError error) { + return "Invalid jri"; + } + return null; + } + + private boolean validateR_HOME() { + String home = System.getenv(R_HOME); + File dir = new File(home); + if (!dir.exists()) { + return false; + } + if (!dir.canRead()) { + return false; + } + if (!dir.isDirectory()) { + return false; + } + List files = Arrays.asList(dir.list()); + if (!files.contains(BINARIES_DIRECTORY) || !files.contains(LIBRARIES_DIRECTORY)) { + return false; + } + return true; + } + + private void createEngineJob(String scriptName) { + job = new Job(scriptName) { + @Override + protected IStatus run(IProgressMonitor monitor) { + createEngine(); + return (topContext.get(scriptName) != null) + ? Status.OK_STATUS + : Status.CANCEL_STATUS; + } + }; + job.schedule(); + } + + private void createEngine() { + Rengine rengine = getRengine(); + topContext.set(R, (rengine != null) + ? new R(rengine) + : null); + } + + private Rengine getRengine() { + Rengine result = null; + if (topContext.get(R_STATUS) == null) { + result = new Rengine(new String[] { VERSION }, false, null); + if (!result.waitForR()) { + result = null; + } else { + String rVersion = result.eval(R_VERSION_CMD).asString(); + String rJRI = result.eval(R_JRI_CMD).asString(); + String rHome = System.getenv(R_HOME); + topContext.set(R_VERSION, rVersion); + topContext.set( + R_PATHS, + MessageFormat.format( + "{0}\n\nJRI:\n{1}\n\nR_HOME:\n{2}", //$NON-NLS-1$ + rVersion, + rJRI, + rHome)); + } + } + return result; + } + + public void end() { + if (engine != null) { + engine.end(); + } + } +} diff --git a/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/internal/REngineProviderContextFunction.java b/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/internal/REngineProviderContextFunction.java new file mode 100644 index 0000000..e826162 --- /dev/null +++ b/bundles/flintstones.engine.R/src/flintstones/engine/R/provider/internal/REngineProviderContextFunction.java @@ -0,0 +1,25 @@ +package flintstones.engine.R.provider.internal; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.engine.R.provider.IREngineProvider; + + +public class REngineProviderContextFunction extends ContextFunction { + + @Override + public Object compute (IEclipseContext context, String contextKey) { + + IREngineProvider rEngineProvider = ContextInjectionFactory.make(REngineDefaultProvider.class, context); + + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IREngineProvider.class, rEngineProvider); + + return rEngineProvider; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.entity.aggregation/.classpath b/bundles/flintstones.entity.aggregation/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.aggregation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.aggregation/.polyglot.META-INF b/bundles/flintstones.entity.aggregation/.polyglot.META-INF new file mode 100644 index 0000000..148e877 --- /dev/null +++ b/bundles/flintstones.entity.aggregation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.aggregation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Aggregation + diff --git a/bundles/flintstones.entity.aggregation/.project b/bundles/flintstones.entity.aggregation/.project new file mode 100644 index 0000000..0e7d7b2 --- /dev/null +++ b/bundles/flintstones.entity.aggregation/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.aggregation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362552 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.aggregation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.aggregation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.aggregation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.aggregation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.aggregation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.aggregation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.aggregation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.aggregation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.aggregation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.aggregation/META-INF/MANIFEST.MF b/bundles/flintstones.entity.aggregation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6d1ca0c --- /dev/null +++ b/bundles/flintstones.entity.aggregation/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Aggregation +Bundle-SymbolicName: flintstones.entity.aggregation +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.aggregation +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.problemelement, + flintstones.helper.data +Export-Package: flintstones.entity.aggregation diff --git a/bundles/flintstones.entity.aggregation/build.properties b/bundles/flintstones.entity.aggregation/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.aggregation/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.aggregation/src/flintstones/entity/aggregation/AggregationItem.java b/bundles/flintstones.entity.aggregation/src/flintstones/entity/aggregation/AggregationItem.java new file mode 100644 index 0000000..9023eeb --- /dev/null +++ b/bundles/flintstones.entity.aggregation/src/flintstones/entity/aggregation/AggregationItem.java @@ -0,0 +1,232 @@ +package flintstones.entity.aggregation; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; + +public class AggregationItem implements Cloneable { + + // Current item + Alternative element1; + ProblemElement element2 = null; + ProblemElement element3 = null; + + // Relatives + AggregationItem parent = null; + List children = new LinkedList<>(); + + // Data + Double weight = 0.0d; + String aggregationOperatorId = ""; + boolean isEnabled = true; + + public AggregationItem(Alternative alternative) { + + element1 = alternative; + setWeight(0.0); + + } + + public AggregationItem(Alternative cElement1, ProblemElement[] elements2, ProblemElement[] elements3) { + + element1 = cElement1; + + setWeight(1.0); + + for (ProblemElement expert : elements2) { + AggregationItem agg = new AggregationItem(cElement1, expert, elements3); + agg.setParent(this); + children.add(agg); + } + + + } + + public AggregationItem(Alternative cElement1, ProblemElement cElement2, ProblemElement[] elements3) { + + element1 = cElement1; + element2 = cElement2; + + if (cElement2.hasChildren()) { + ProblemElement[] experts = element2.getChildren(); + for (ProblemElement expert : experts) { + AggregationItem agg = new AggregationItem(cElement1, expert, elements3); + agg.setParent(this); + children.add(agg); + } + } else { + for (ProblemElement criterion : elements3) { + AggregationItem agg = new AggregationItem(cElement1, cElement2, criterion); + agg.setParent(this); + children.add(agg); + } + + } + + } + + private AggregationItem(Alternative cElement1, ProblemElement cElement2, ProblemElement cElement3) { + + element1 = cElement1; + element2 = cElement2; + element3 = cElement3; + + if (element3.hasChildren()) { + ProblemElement[] criterions = cElement3.getChildren(); + for (ProblemElement c : criterions) { + AggregationItem agg = new AggregationItem(cElement1, cElement2, c); + agg.setParent(this); + children.add(agg); + } + } + + } + + public double getWeight() { + return weight; + } + + public void setWeight(double w) { + weight = w; + } + + public boolean validateParentWeights() { + if( getParent() == null) + return true; + return parent.validateWeights(); + } + + public boolean validateWeights() { + double sum = 0.0d; + for (AggregationItem item : children) { + if(item.isEnabled()) + sum += item.getWeight(); + } + return DoubleHelper.Equals(sum, 1.0d, 3); + + } + + public void setWeights(double[] weights) { + + for (int i = 0; i < children.size(); i++) { + children.get(i).setWeight(weights[i]); + } + + } + + public void shareWeight() { + + int total = children.size() != 0 ? children.size() : 1; + double partedWeight = 1.0d / total; + + double[] arr = new double[total]; + Arrays.fill(arr, partedWeight); + + setWeights(arr); + + // Cascade + for (AggregationItem item : children) + item.shareWeight(); + + } + + @Override + public String toString() { + + String a = element1.getName(); + String e = element2 != null ? element2.getName() : "EX"; + String c = element3 != null ? element3.getName() : "CX"; + + return a + " : " + e + " : " + c + " => " + weight; + } + + public ProblemElement getFinalItem() { + if (element3 != null) + return element3; + if (element2 != null) + return element2; + return element1; + } + + public void setParent(AggregationItem item) { + parent = item; + } + + public AggregationItem getParent() { + return parent; + } + + public boolean hasChildren() { + return children.size() != 0; + } + + public AggregationItem[] getChildren() { + return children.toArray(new AggregationItem[0]); + } + + public void setChildren(List children) { + this.children = children; + } + + public Alternative getAlternative() { + return element1; + } + + public void setAlternative(Alternative item, boolean cascade) { + this.element1 = item; + if(cascade) + children.stream().forEach(k -> k.setAlternative(item, cascade)); + } + + public ProblemElement getElement2() { + return element2; + } + + public ProblemElement getElement3() { + return element3; + } + + public void setEnabled(boolean x) { + isEnabled = x; + } + + public boolean isEnabled() { + return isEnabled; + } + + public String getOperatorId() { + return aggregationOperatorId; + } + + public void setOperatorId(String op) { + this.aggregationOperatorId = op; + } + + public void setOperatorId(String op, boolean cascade) { + + // If the aggregation item is leaf, do not assign operator + if(children.size() == 0) + return ; + + this.aggregationOperatorId = op; + if(cascade) + children.stream().forEach(k -> k.setOperatorId(op, true)); + } + + @Override + public Object clone() throws CloneNotSupportedException { + AggregationItem other = new AggregationItem(element1); + other.element2 = this.element2; + other.element3 = this.element3; + other.setParent(this.parent); + other.setChildren(this.children); + other.setWeight(this.weight); + other.setOperatorId(aggregationOperatorId, false); + other.setEnabled(this.isEnabled); + return other; + } +} diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/.classpath b/bundles/flintstones.entity.ahp.decisionmatrix/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/.polyglot.META-INF b/bundles/flintstones.entity.ahp.decisionmatrix/.polyglot.META-INF new file mode 100644 index 0000000..9f15fcb --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.ahp.decisionmatrix + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Decision Matrix + diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/.project b/bundles/flintstones.entity.ahp.decisionmatrix/.project new file mode 100644 index 0000000..91155d1 --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.ahp.decisionmatrix + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362554 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/META-INF/MANIFEST.MF b/bundles/flintstones.entity.ahp.decisionmatrix/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7070bc5 --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Decision Matrix +Bundle-SymbolicName: flintstones.entity.ahp.decisionmatrix +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.decisionmatrix +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.valuation, + flintstones.entity.problemelement, + flintstones.valuation.numeric, + flintstones.helper.data, + flintstones.entity.wvaluation +Export-Package: flintstones.entity.ahp.decisionmatrix diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/build.properties b/bundles/flintstones.entity.ahp.decisionmatrix/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.ahp.decisionmatrix/src/flintstones/entity/ahp/decisionmatrix/DecisionMatrix.java b/bundles/flintstones.entity.ahp.decisionmatrix/src/flintstones/entity/ahp/decisionmatrix/DecisionMatrix.java new file mode 100644 index 0000000..23bd09c --- /dev/null +++ b/bundles/flintstones.entity.ahp.decisionmatrix/src/flintstones/entity/ahp/decisionmatrix/DecisionMatrix.java @@ -0,0 +1,263 @@ +package flintstones.entity.ahp.decisionmatrix; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; +import java.util.TreeMap; +import java.util.stream.Collectors; + +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.entity.wvaluation.WValuation; +import flintstones.helper.MatrixHelper; +import flintstones.valuation.numeric.NumericValuation; + +/** + * The Class DecisionMatrix. + */ +public class DecisionMatrix implements Cloneable { + + /* Decision Matrix + * ____| C_1 | C_2 | C_3 | + * A1 | V | V | V | + * A2 | V | V | V | + * A3 | V | V | V | */ + + /** + * Instantiates a new decision matrix. + */ + public DecisionMatrix() { + } + + /** The criterion headers. */ + ArrayList criterionHeaders; + + /** The alternative headers. */ + ArrayList alternativeHeaders; + + /** The content. */ + TreeMap> content = new TreeMap<>(); + + /** The cached values. */ + ArrayList> cachedValues = null; // Poner a null para que se regenere + + /** The expert. */ + Expert expert; + + /** + * Adds the content. + * + * @param entries the entries + */ + public void addContent(HashMap entries) { + + expert = entries.keySet().iterator().next().getExpert(); + for (Entry entry : entries.entrySet()) { + + ProblemElementKey pek = entry.getKey(); + Criterion c = pek.getCriterion(); + Alternative a = pek.getAlternative(); + + WValuation w = new WValuation(entry); + + // Get the criterion column + TreeMap col = content.get(c); + if (col == null) + col = new TreeMap<>(); + + // Add the valuation + col.put(a, w); + content.put(c, col); + + } + + updateHeaders(); + } + + /** + * Update headers. + */ + public void updateHeaders() { + criterionHeaders = new ArrayList<>(content.keySet()); + alternativeHeaders = new ArrayList<>(content.values() + .iterator() + .next() + .keySet()); + } + + /** + * Gets the content. + * + * @return the content + */ + public TreeMap> getContent() { + return content; + } + + /** + * Gets the criterion header. + * + * @return the criterion header + */ + public ArrayList getCriterionHeader() { + return (ArrayList) criterionHeaders.stream() + .map(k -> k.getCanonicalName()) + .collect(Collectors.toList()); + } + + /** + * Gets the alternative header. + * + * @return the alternative header + */ + public ArrayList getAlternativeHeader() { + return (ArrayList) alternativeHeaders.stream() + .map(k -> k.getCanonicalName()) + .collect(Collectors.toList()); + } + + /** + * Gets the values. + * + * @return the values + */ + public ArrayList> getValues() { + + if (cachedValues != null) + return cachedValues; + + cachedValues = new ArrayList<>(); + for (Entry> critEntry : content.entrySet()) { + ArrayList columnValues = new ArrayList<>(); + for (Entry altEntry : critEntry.getValue() + .entrySet()) { + NumericValuation value = (NumericValuation) altEntry.getValue().getValuation(); + columnValues.add(value.getValue()); + } + cachedValues.add(columnValues); + } + return cachedValues; + + } + + /* (non-Javadoc) + * @see java.lang.Object#clone() + */ + @Override + public Object clone() { + DecisionMatrix dm = new DecisionMatrix(); + + for( Entry> entry1 : this.getContent().entrySet() ) { + ProblemElement criterion = entry1.getKey(); + for( Entry entry2 : entry1.getValue().entrySet() ) { + + ProblemElement alternative = entry2.getKey(); + Valuation v = (Valuation) entry2.getValue().getValuation().clone(); + + dm.set(criterion, alternative, v); + } + } + + dm.updateHeaders(); + + return dm; + } + + /** + * Gets the criterions. + * + * @return the criterions + */ + public Criterion[] getCriterions() { + return this.criterionHeaders.stream() + .map(k -> (Criterion) k) + .toArray(Criterion[]::new); + } + + /** + * Gets the alternatives. + * + * @return the alternatives + */ + public Alternative[] getAlternatives() { + return this.alternativeHeaders.stream() + .map(k -> (Alternative) k) + .toArray(Alternative[]::new); + } + + /** + * Gets the column. + * + * @param crit the crit + * @return the column + */ + public TreeMap getColumn(ProblemElement crit) { + TreeMap column = content.get(crit); + return column; + } + + /** + * Gets the row. + * + * @param alternative the alternative + * @return the row + */ + public ArrayList getRow(Alternative alternative){ + // o(n) -> o(1) + return (ArrayList) content.values().stream().map( k -> k.get( alternative )).collect(Collectors.toList()); + } + + /** + * Sets the content. + * + * @param content the content + */ + public void setContent(TreeMap> content) { + this.content = content; + updateHeaders(); + } + + /** + * Sets the. + * + * @param crit the crit + * @param alt the alt + * @param value the value + */ + public void set(ProblemElement crit, ProblemElement alt, Valuation value) { + WValuation waluation = new WValuation(this.expert, (Alternative)alt, (Criterion)crit, value); + + TreeMap col = content.get(crit); + if (col == null) + col = new TreeMap<>(); + + col.put(alt, waluation); + content.put(crit, col); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + List> values = MatrixHelper.transpose(this.getValues()); + + StringBuilder sb = new StringBuilder(""); + + for (List arr : values) { + for (Double val : arr) { + sb.append(val); + sb.append(" "); + } + sb.append("\n"); + } + return sb.toString(); + + } + +} diff --git a/bundles/flintstones.entity.ahp.ui/.classpath b/bundles/flintstones.entity.ahp.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.ahp.ui/.polyglot.META-INF b/bundles/flintstones.entity.ahp.ui/.polyglot.META-INF new file mode 100644 index 0000000..9e2c7a2 --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.ahp.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.entity.ahp.ui/.project b/bundles/flintstones.entity.ahp.ui/.project new file mode 100644 index 0000000..7caebd0 --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.ahp.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362554 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.ahp.ui/META-INF/MANIFEST.MF b/bundles/flintstones.entity.ahp.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1b183b7 --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.entity.ahp.ui +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.ahp.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.contexts, + javax.inject, + flintstones.model.problemelement.service, + flintstones.valuation.ahp.ui, + org.eclipse.swt, + flintstones.entity.problemelement.ui, + flintstones.entity.ahppreferences, + flintstones.entity.preferences.preferencecollection, + flintstones.entity.problemelement, + flintstones.entity.ahp, + flintstones.helper.debug, + flintstones.model.ui.service, + org.eclipse.jface, + flintstones.model.ahppreferences.service, + org.eclipse.e4.core.di, + flintstones.helper.data, + flintstones.helper.html +Export-Package: flintstones.entity.ahp.ui diff --git a/bundles/flintstones.entity.ahp.ui/build.properties b/bundles/flintstones.entity.ahp.ui/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.ahp.ui/src/flintstones/entity/ahp/ui/AHPMatrixDialog.java b/bundles/flintstones.entity.ahp.ui/src/flintstones/entity/ahp/ui/AHPMatrixDialog.java new file mode 100644 index 0000000..2171a46 --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/src/flintstones/entity/ahp/ui/AHPMatrixDialog.java @@ -0,0 +1,50 @@ +package flintstones.entity.ahp.ui; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.html.HtmlMatrix; +import flintstones.model.ui.service.UiService; + +public class AHPMatrixDialog extends Dialog { + + AHPMatrix matrix; + public AHPMatrixDialog(Shell parentShell, AHPMatrix m) { + super(parentShell); + this.matrix = m; + } + + @Override + protected Control createDialogArea(Composite parent) { + + Composite base = new Composite(parent,0); + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + ProblemElement[] items = matrix.getRows(); + int l = items.length; + String[][] data = new String[l][l]; + + for(int i = 0; i < l; i++ ) { + for(int j = 0; j < l; j++ ) { + data[i][j] = matrix.getLabel(items[i],items[j]); + } + } + + HtmlMatrix hMatrix = new HtmlMatrix(base, data); + hMatrix.render(); + + return parent; + + } + + @Override + protected Point getInitialSize() { + return new Point(450, 300); + } +} diff --git a/bundles/flintstones.entity.ahp.ui/src/flintstones/entity/ahp/ui/PreferencesRatingPart.java b/bundles/flintstones.entity.ahp.ui/src/flintstones/entity/ahp/ui/PreferencesRatingPart.java new file mode 100644 index 0000000..49bc54a --- /dev/null +++ b/bundles/flintstones.entity.ahp.ui/src/flintstones/entity/ahp/ui/PreferencesRatingPart.java @@ -0,0 +1,484 @@ +package flintstones.entity.ahp.ui; + +import java.util.HashSet; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; + +import flintstones.entity.ahp.AHPConsistency; +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.problemelement.ui.widget.ProblemElementSelector; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.helper.DoubleHelper; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; +import flintstones.valuation.ahp.ui.AHPValuationPanel; +import flintstones.valuation.ahp.ui.IAHPValuationPanelClickListener; + +/** + * The Class PreferencesRatingPart. + */ +public class PreferencesRatingPart implements IAHPValuationPanelClickListener { + + @Inject + IEclipseContext context; + + @Inject + IProblemPreferencesService ppreferencesService; + + @Inject + IProblemElementService problemService; + + AHPValuationPanel panel; + + Label consistencyLabel; + + ProblemElementSelector mainCombo; + + ProblemElementSelector otherCombo; + + /** The size check. */ + CLabel sizeCheck; + CLabel showAHP; + + /** The max ratio. */ + Double MAX_RATIO = 0.100001; + + /** + * Instantiates a new preferences rating part. + */ + public PreferencesRatingPart() { + } + + /** The current build. */ + // Changing parts + private PreferenceBuild currentBuild; + + /** The manager. */ + // Fixed parts + PreferenceCollection manager; + + /** + * Inits the preferences rating part. + * + * @param parent the parent + * @param domain the domain + * @param builds the builds + */ + public void initPreferencesRatingPart(Composite parent, PreferenceBuild[] builds) { + + manager = null; + if (builds != null && builds.length > 0) { + PreferenceBuild any = builds[0]; + manager = ppreferencesService.get( + any.getMainType(), // + any.getOtherType(), // + any.getLeftType(), // + any.getRightType()); + } + + if (manager == null) + manager = new PreferenceCollection(builds); + + currentBuild = builds[0]; + + createRow1(parent, getAllMainElements(builds), getAllOtherElements(builds)); + createRow2(parent); + + if (currentBuild.isAHP()) { + drawSizeCheck(currentBuild.getLeftElements().toArray(new ProblemElement[0])); + drawShowAHP(); + } + refresh(); + + } + + private void drawShowAHP() { + showAHP.setImage(UiService.getImage("ahpmatrix.png").createImage()); + showAHP.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e) { + + PreferenceBuild build = manager.getBuild(getComboMainElement(), getComboOtherElement()); + AHPMatrix m = build.getAHPMatrix(); + new AHPMatrixDialog(Display.getCurrent().getActiveShell(), m).open(); + } + }); + + showAHP.addListener(SWT.MouseMove, new Listener() { + public void handleEvent(Event event) { + final Cursor cursor = new Cursor(Display.getDefault(), SWT.CURSOR_HAND); + showAHP.setCursor(cursor); + } + }); + + } + + /** + * Gets the all main elements. + * + * @param builds the builds + * @return the all main elements + */ + public ProblemElement[] getAllMainElements(PreferenceBuild[] builds) { + HashSet arr = new HashSet<>(); + for (int i = 0; i < builds.length; i++) + arr.add(builds[i].getMain()); + return arr.stream().toArray(ProblemElement[]::new); + } + + /** + * Gets the all other elements. + * + * @param builds the builds + * @return the all other elements + */ + public ProblemElement[] getAllOtherElements(PreferenceBuild[] builds) { + HashSet arr = new HashSet<>(); + for (int i = 0; i < builds.length; i++) + arr.add(builds[i].getOther()); + return arr.stream().toArray(ProblemElement[]::new); + } + + /** + * Creates the row 1. + * + * @param parent the parent + * @param experts the experts + * @param criterions the criterions + */ + private void createRow1(Composite parent, ProblemElement[] experts, ProblemElement[] criterions) { + + experts = ProblemElementHelper.getAsUserOrdered(experts); + criterions = ProblemElementHelper.getAsUserOrdered(criterions); + + Composite row1 = new Composite(parent, 0); + UiService.setGridLayout(row1, 3, false); + UiService.setGridData(row1, 9, 0, true, false); + + Group g = new Group(row1, 0); + g.setText("Controls"); + UiService.setGridLayout(g, 9, false); + UiService.setGridData(g, 9, 0, true, false); + + if (!currentBuild.isMainGeneric()) { + Label expertLabel = new Label(g, 0); + mainCombo = new ProblemElementSelector(g, experts); + mainCombo.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + refresh(); + } + }); + expertLabel.setText(currentBuild.getMainType()); + + UiService.setFont(expertLabel, UiService.FONT_SECTION_TITLE); + } + + if (!currentBuild.isOtherGeneric()) { + Label criterionLabel = new Label(g, 0); + otherCombo = new ProblemElementSelector(g, criterions); + otherCombo.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) {refresh();} + }); + criterionLabel.setText(currentBuild.getOtherType()); + + UiService.setFont(criterionLabel, UiService.FONT_SECTION_TITLE); + } + + Label consistencyTitle = new Label(g, 0); + consistencyTitle.setText("CR: "); + + consistencyLabel = new Label(g, 0); + consistencyLabel.setText("0.0 "); + UiService.setFont(consistencyTitle, UiService.FONT_SECTION_TITLE); + + showAHP = new CLabel(row1, 0); + UiService.setGridData(showAHP, 1, 0, false, false); + + sizeCheck = new CLabel(row1, 0); + UiService.setGridData(sizeCheck, 1, 0, false, false); + + if (currentBuild.getLeftType().equals(currentBuild.getRightType())) { + Button hideSame = new Button(g,SWT.CHECK); + hideSame.setText("Hide same"); + hideSame.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.show(!hideSame.getSelection()); + refresh(); + } + + }); + } + + } + + /** + * Draw size check. + * + * @param alternatives the alternatives + */ + private void drawSizeCheck(ProblemElement[] alternatives) { + + int num = alternatives.length; + boolean isValid = num >= 2 && num <= 10; + + Image labelImage = isValid ? UiService.getIcon("status_right").createImage() + : UiService.getIcon("status_wrong").createImage(); + String sizeCheckText = num + " alternatives"; + + if (num < 2) + sizeCheckText += " (at least 2)"; + if (num > 10) + sizeCheckText += " (at most 10)"; + + sizeCheck.setText(sizeCheckText); + sizeCheck.setImage(labelImage); + + } + + /** + * Creates the row 2. + * + * @param parent the parent + * @param domain the domain + */ + private void createRow2(Composite parent) { + + ScrolledComposite c1 = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + UiService.setGridLayout(c1, 1); + UiService.setGridData(c1, 9, 9, true, true); + + c1.setExpandHorizontal(true); + c1.setExpandVertical(true); + c1.addListener(SWT.Resize, event -> { + int width = c1.getClientArea().width; + c1.setMinSize(parent.computeSize(width, SWT.DEFAULT)); + }); + + Composite row2 = new Composite(c1, 0); + UiService.setGridLayout(row2, 1); + UiService.setGridData(row2, 9, 0, true, false); + + c1.setContent(row2); + + panel = new AHPValuationPanel(row2); + ContextInjectionFactory.inject(panel, context); + + setButtonListener(panel); + } + + /** + * Sets the button listener. + * + * @param panel the new button listener + */ + protected void setButtonListener(AHPValuationPanel panel) { + panel.setButtonOnClickListener(this); + } + + /** + * Refresh. + */ + protected void refresh() { + + currentBuild = manager.getBuild(getComboMainElement(), getComboOtherElement()); + int[][] mat = currentBuild.get(); + + panel.clear(); + panel.setButtonOnClickListener(this); + panel.base1(currentBuild.getLeftElements().toArray(new ProblemElement[0]), currentBuild.getRightElements().toArray(new ProblemElement[0]), mat); + + refreshCriterionCombo(); + refreshExpertCombo(); + + if (mat != null) + refreshConsistencyLabel(); + + } + + /** + * Gets the combo main element. + * + * @return the combo main element + */ + private ProblemElement getComboMainElement() { + if(currentBuild != null) { + if (currentBuild.isMainGeneric()) + return currentBuild.getMain(); + } + + return mainCombo.getSelectedElement(); + } + + /** + * Gets the combo other element. + * + * @return the combo other element + */ + private ProblemElement getComboOtherElement() { + + if(currentBuild != null) { + if (currentBuild.isOtherGeneric()) + return currentBuild.getOther(); + } + + return otherCombo.getSelectedElement(); + } + + /** + * Gets the current other element. + * + * @return the current other element + */ + protected ProblemElement getCurrentOtherElement() { + return currentBuild.getOther(); + } + + /** + * Gets the current main element. + * + * @return the current main element + */ + protected ProblemElement getCurrentMainElement() { + + return currentBuild.getMain(); + } + + /** + * Refresh consistency label. + */ + protected void refreshConsistencyLabel() { + + if (!currentBuild.isAHP()) { + consistencyLabel.setText("0,0"); + return; + } + + if(currentBuild.getLeftElements().size() * currentBuild.getRightElements().size() < 5) { + consistencyLabel.setText("0,0"); + return ; + } + + AHPMatrix mat = currentBuild.getAHPMatrix(); + AHPConsistency consistencyChecker = new AHPConsistency(); + double ratio = consistencyChecker.getConsistencyRatio(mat); + consistencyLabel.setText(DoubleHelper.Draw(ratio)); + + refreshCriterionCombo(); + refreshExpertCombo(); + + } + + /** + * Refresh expert combo. + */ + protected void refreshExpertCombo() { + + if (currentBuild.isMainGeneric()) + return; + + boolean everyCriterionOk = otherCombo.getStatus(); + mainCombo.getSelectedElement(); + mainCombo.setStatus(mainCombo.getSelectedElement(), everyCriterionOk); + } + + /** + * Refresh criterion combo. + */ + protected void refreshCriterionCombo() { + + if (currentBuild.isOtherGeneric()) { + return; + } + + if (!currentBuild.isMainGeneric()) { + ProblemElement[] otherElements = manager.getAllOtherElements(); + for (int i = 0; i < otherElements.length; i++) { + + ProblemElement main = getComboMainElement(); + ProblemElement other = otherElements[i]; + + boolean status = getStatusFor(main, other); + otherCombo.setStatus(other, status); + + } + + } + + } + + /** + * Gets the status for. + * + * @param main the main + * @param other the other + * @return the status for + */ + private boolean getStatusFor(ProblemElement main, ProblemElement other) { + + PreferenceBuild build = manager.getBuild(main, other); + if (build.isAHP()) { + AHPMatrix mat = build.getAHPMatrix(); + + if (mat == null) + return false; + + AHPConsistency consistencyChecker = new AHPConsistency(); + double ratio = consistencyChecker.getConsistencyRatio(mat); + + return ratio > MAX_RATIO ? false : true; + + } + + return true; + + } + + /* + * (non-Javadoc) + * + * @see flintstones.valuation.ahp.ui.IAHPValuationPanelClickListener#onClick( + * flintstones.entity.problemelement.entities.ProblemElement, + * flintstones.entity.problemelement.entities.ProblemElement, + * flintstones.domain.ahp.AHPDomain, int) + */ + @Override + public void onClick(ProblemElement left, ProblemElement right, int position) { + + if (left.getType().equals(right.getType())) + currentBuild.setDiagonal(left, right, position); + else + currentBuild.set(left, right, position); + + ppreferencesService.addOrUpdate(manager); + + panel.select(left, right, position); + refreshConsistencyLabel(); + } + +} diff --git a/bundles/flintstones.entity.ahp/.classpath b/bundles/flintstones.entity.ahp/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.ahp/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.ahp/.polyglot.META-INF b/bundles/flintstones.entity.ahp/.polyglot.META-INF new file mode 100644 index 0000000..80d74b2 --- /dev/null +++ b/bundles/flintstones.entity.ahp/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.ahp + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ahp + diff --git a/bundles/flintstones.entity.ahp/.project b/bundles/flintstones.entity.ahp/.project new file mode 100644 index 0000000..24baf16 --- /dev/null +++ b/bundles/flintstones.entity.ahp/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.ahp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362553 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.ahp/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.ahp/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.ahp/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.ahp/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.ahp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.ahp/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.ahp/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.ahp/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.ahp/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.ahp/META-INF/MANIFEST.MF b/bundles/flintstones.entity.ahp/META-INF/MANIFEST.MF new file mode 100644 index 0000000..77565be --- /dev/null +++ b/bundles/flintstones.entity.ahp/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ahp +Bundle-SymbolicName: flintstones.entity.ahp +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.ahp +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.valuation.ahp, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.model.valuation.service, + javax.inject, + flintstones.operator, + flintstones.valuation.numeric.real, + flintstones.operator.aggregation.geometricMean, + org.apache.commons.math3, + flintstones.helper.data, + flintstones.entity.valuation, + flintstones.model.domain.service, + flintstones.domain.numeric.real, + flintstones.entity.domain, + flintstones.helper.ahp, + flintstones.entity.operator +Export-Package: flintstones.entity.ahp diff --git a/bundles/flintstones.entity.ahp/build.properties b/bundles/flintstones.entity.ahp/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.ahp/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPAggregatedMatrix.java b/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPAggregatedMatrix.java new file mode 100644 index 0000000..e775afc --- /dev/null +++ b/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPAggregatedMatrix.java @@ -0,0 +1,107 @@ +package flintstones.entity.ahp; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.aggregation.geometricMean.GeometricMean; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.numeric.real.RealValuation; + +/** + * The Class AHPAggregatedMatrix. + */ +public class AHPAggregatedMatrix { + + /** The rows of the matrox. */ + private ProblemElement[] rows; + + /** The cols of the matrix. */ + private ProblemElement[] cols; + + /** The result matrix. */ + private double[][] resultMatrix; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + @Inject + IDomainService domainService; + + /** The operator service. */ + @Inject + IOperatorService operatorService; + + /** + * Instantiates a new AHP aggregated matrix. + */ + public AHPAggregatedMatrix() { + + + } + + /** + * Aggregate the given preferences using GeometricMean. + * + * @param preferences the preferences + */ + public void aggregate(AHPMatrix[] preferences) { + + cols = preferences[0].getCols(); + rows = preferences[0].getRows(); + + resultMatrix = new double[cols.length][rows.length]; + + // Aggregate the values of every of each matrix to retrive a single matrix. C1,A1,A2,E1 + C1,A1,A2,E2 + + C1,A1,A2,E3... -> C1,A1,A2 + for (int i = 0; i < cols.length; i++) { + ProblemElement a = cols[i]; + + for (int j = 0; j < rows.length; j++) { + ProblemElement b = rows[j]; + + List valuations = new ArrayList<>(); + for (AHPMatrix mat : preferences) { + double x = mat.getValue(a, b); + + NumericRealDomain newDomain = (NumericRealDomain) domainService.create(NumericRealDomain.ID); + newDomain.setInRange(false); + RealValuation realValuation = (RealValuation) valuationService.create(newDomain); + realValuation.setValue(x); + valuations.add(realValuation); + } + + AggregationOperator operator = operatorService.getAggregationOperator(GeometricMean.class.getPackage().getName().toString(), valuations.get(0).getId()); + RealValuation result = (RealValuation) operator.computeAggregation(valuations, null); + resultMatrix[i][j] = result.getValue(); + } + } + + } + + /** + * Gets the result matrix. + * + * @return the result matrix + */ + public double[][] getResultMatrix() { + return resultMatrix; + } + + /** + * Gets the row. + * + * @return the row + */ + public ProblemElement[] getRow() { + return rows; + } + + +} diff --git a/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPConsistency.java b/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPConsistency.java new file mode 100644 index 0000000..62e611a --- /dev/null +++ b/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPConsistency.java @@ -0,0 +1,99 @@ +package flintstones.entity.ahp; + +import java.util.stream.DoubleStream; + +import org.apache.commons.math3.linear.EigenDecomposition; +import org.apache.commons.math3.linear.MatrixUtils; +import org.apache.commons.math3.linear.RealMatrix; + +import flintstones.entity.ahp.exception.UncheckableConsistencyException; +import flintstones.helper.DoubleHelper; + +/** + * The Class AHPConsistency. + */ +public class AHPConsistency { + + /** The consistency random indexes. */ + double[] consistencyRandomIndexes = {-1.0,-1.0,-1.0,0.58,0.9,1.12,1.24,1.32,1.41,1.45,1.49}; + + /** + * Instantiates a new AHP consistency checker. + */ + public AHPConsistency() { + + } + + /** + * Gets the consistency ratio. + * + * @param maxEigenValue the max eigen value + * @param numberOfItems the number of items + * @return the consistency ratio + */ + private double getConsistencyRatio(double maxEigenValue, int numberOfItems) { + if(numberOfItems == 2) + return 0; + else + return getConsistencyIndex(maxEigenValue, numberOfItems) / getRandomIndex(numberOfItems); + } + + /** + * Gets the consistency index. + * + * @param maxEigenValue the max eigen value + * @param numberOfItems the number of items + * @return the consistency index + */ + private double getConsistencyIndex( double maxEigenValue, int numberOfItems ) { + return (maxEigenValue - numberOfItems)/(numberOfItems-1); + } + + /** + * Gets the random index. + * + * @param numberOfItems the number of items + * @return the random index + */ + private double getRandomIndex(int numberOfItems) { + double val = consistencyRandomIndexes[numberOfItems]; + + if(numberOfItems > 10 || val == -1.0 ) + throw new UncheckableConsistencyException(numberOfItems); + + return val; + } + + /** + * Gets the consistency ratio. + * + * @param mat the mat + * @return the consistency ratio + */ + public double getConsistencyRatio(AHPMatrix mat) { + + double[][] values = mat.getValues(); + + RealMatrix realMatrix = MatrixUtils.createRealMatrix(values); + EigenDecomposition descomposition = null; + try { + descomposition = new EigenDecomposition(realMatrix); + + } catch( org.apache.commons.math3.exception.MaxCountExceededException e ) { + System.err.println(e.getMessage()); + } + + if(descomposition == null) + return 1.0; + + double[] eigenValues = descomposition.getRealEigenvalues(); + double max = DoubleStream.of(eigenValues).max().getAsDouble(); + max = DoubleHelper.Round(max,2); + + double result = this.getConsistencyRatio(max,eigenValues.length); + return result; + + } + + +} diff --git a/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPMatrix.java b/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPMatrix.java new file mode 100644 index 0000000..a174b35 --- /dev/null +++ b/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/AHPMatrix.java @@ -0,0 +1,255 @@ +package flintstones.entity.ahp; + +import java.util.LinkedHashMap; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; +import flintstones.helper.MatrixHelper; +import flintstones.helper.StringHelper; +import flintstones.helper.ahp.AHPHelper; +import flintstones.valuation.ahp.AHPValuation; + +/** + * The Class AHPMatrix. + */ +public class AHPMatrix { + + /** The content. */ + private LinkedHashMap> content = new LinkedHashMap<>(); + + /* + * El cuestionario: + * + * A2 -> 8 <- A1 A2 -> 1/6 <- A3 A1 -> 1/8 <- A2 (Repe) A1 -> 1 <- A3 A3 -> 6 <- + * A2 (Repe) A3 -> 1 <- A1 (Repe) + * + * Genera la matrix: A2 A1 A3 A2 1 8 1/6 A1 1/8 1 1 A3 6 1 1 + * + * Genera la matrix de índices: A2 A1 A3 A2 8 15 3 A1 1 8 8 A3 13 8 8 + * + * + */ + + /** + * Instantiates a new AHP matrix. + * + * @param domain the domain + * @param alternatives the alternatives + */ + public AHPMatrix(ProblemElement[] alternatives) { + + for (int i = 0; i < alternatives.length; i++) { + ProblemElement alternative = alternatives[i]; + LinkedHashMap map = new LinkedHashMap<>(); + for (int j = i + 1; j < alternatives.length; j++) { + ProblemElement b = alternatives[j]; + AHPValuation v = new AHPValuation().buildAHPValuation(alternative, b); + map.put(b, v); + } + content.put(alternative, map); + } + + } + + /** + * Sets the cell to a value by it index. + * + * @param a the first PE + * @param b the second PE + * @param index the index of the value in the domain + */ + public void set(ProblemElement a, ProblemElement b, int index) { + + if (a.equals(b)) + return; + + LinkedHashMap map = content.get(a); + AHPValuation val = map.get(b); + + if (val == null) { + map = content.get(b); + val = map.get(a); + int reverseIndex = AHPHelper.getInverseIndex(index); + val.setIndex(reverseIndex); + } else { + val.setIndex(index); + } + + } + + // API for debbugging only + public void setValue(ProblemElement a, ProblemElement b, String valueLabel) { + String[] labels = AHPHelper.getLabels(); + int index = StringHelper.IndexOf(labels, valueLabel); + set(a, b, index); + } + + /** + * Gets the index. + * + * @param a the first PE + * @param b the second PE + * @return the index of the value in the domain + */ + public int getIndex(ProblemElement a, ProblemElement b) { + + if (a.equals(b)) + return (int) AHPHelper.getMidPoint(); + + LinkedHashMap map = content.get(a); + + AHPValuation val = map.get(b); + + int index; + + if (val == null) { + map = content.get(b); + val = map.get(a); + index = AHPHelper.getInverseIndex(val.getIndex()); + } else { + index = val.getIndex(); + } + + return index; + + } + + /** + * Gets the label. + * + * @param a the first PE + * @param b the second PE + * @return the human readable label + */ + public String getLabel(ProblemElement a, ProblemElement b) { + int index = this.getIndex(a, b); + return AHPHelper.getLabels()[index]; + } + + /** + * Gets the value. + * + * @param a the first PE + * @param b the second PE + * @return the value + */ + public Double getValue(ProblemElement a, ProblemElement b) { + int index = this.getIndex(a, b); + Double val = DoubleHelper.ParseFraction(AHPHelper.getLabels()[index]); + return val; + } + + /** + * Gets the values. + * + * @return the values + */ + public double[][] getValues() { + + int size = content.size(); + double[][] result = new double[size][size]; + + ProblemElement[] arr = content.keySet().stream().toArray(ProblemElement[]::new); + + for (int i = 0; i < size; i++) + for (int j = 0; j < size; j++) + result[i][j] = this.getValue(arr[i], arr[j]); + + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + boolean toStringIndex = true; + String[] indexValueMapping = AHPHelper.getLabels(); + StringBuilder sb = new StringBuilder(); + String[] headers = content.keySet().stream().map(k -> k.getName()).toArray(String[]::new); + + String[][] m = new String[headers.length][headers.length]; + + ProblemElement[] pes = content.keySet().toArray(new ProblemElement[0]); + + int i = 0; + for (ProblemElement pe1 : pes) { + int j = 0; + + for (ProblemElement pe2 : pes) { + m[i][j] = toStringIndex ? indexValueMapping[getIndex(pe1, pe2)] : this.getIndex(pe1, pe2) + ""; + j++; + + } + + i++; + } + +// for(Entry> entry1 : content.entrySet()) { +// int j = 0; +// for( Entry entry2 : entry1.getValue().entrySet()) { +// m[i][j] = entry2.getValue().getIndex()+""; +// j++; +// } +// i++; +// } + + String[][] m2 = MatrixHelper.addHeaders(m, headers, headers); + sb.append(StringHelper.PrintTable(m2)); + sb.append("\n"); + sb.append("RAW: \n"); + sb.append(content.toString()); + sb.append("\n"); + return sb.toString(); + + } + + /** + * Gets the cols. + * + * @return the cols + */ + public ProblemElement[] getCols() { + return this.content.keySet().toArray(new ProblemElement[0]); + } + + /** + * Gets the rows. + * + * @return the rows + */ + public ProblemElement[] getRows() { + return this.content.keySet().toArray(new ProblemElement[0]); + } + + /** + * Write. + * + * @param writer the writer + * @throws XMLStreamException the XML stream exception + */ + public void write(XMLStreamWriter writer) throws XMLStreamException { + ProblemElement[] arr = content.keySet().toArray(new ProblemElement[0]); + + for (int i = 0; i < arr.length; i++) { + ProblemElement pe1 = arr[i]; + for (int j = i; j < arr.length; j++) { + ProblemElement pe2 = arr[j]; + if (!pe1.equals(pe2)) { + writer.writeStartElement("AHPValuation"); + content.get(pe1).get(pe2).write(writer); + writer.writeEndElement(); + } + + } + } + + } + +} diff --git a/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/exception/UncheckableConsistencyException.java b/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/exception/UncheckableConsistencyException.java new file mode 100644 index 0000000..3a52174 --- /dev/null +++ b/bundles/flintstones.entity.ahp/src/flintstones/entity/ahp/exception/UncheckableConsistencyException.java @@ -0,0 +1,21 @@ +package flintstones.entity.ahp.exception; + +/** + * @author igmunoz + * + */ +public class UncheckableConsistencyException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = -1452084500458108325L; + + /** + * @param numberOfItems the number of recibed items (n items -> matrix n*n) + */ + public UncheckableConsistencyException(int numberOfItems) { + super("Consistency can be checked between 3 and 10 only. ( numberOfItems: " + numberOfItems + ")"); + } + +} diff --git a/bundles/flintstones.entity.ahppreferences/.classpath b/bundles/flintstones.entity.ahppreferences/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.ahppreferences/.polyglot.META-INF b/bundles/flintstones.entity.ahppreferences/.polyglot.META-INF new file mode 100644 index 0000000..cbb741a --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.ahppreferences + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ahppreferences + diff --git a/bundles/flintstones.entity.ahppreferences/.project b/bundles/flintstones.entity.ahppreferences/.project new file mode 100644 index 0000000..ad3022b --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.ahppreferences + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362555 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.ahppreferences/META-INF/MANIFEST.MF b/bundles/flintstones.entity.ahppreferences/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c8e717c --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ahppreferences +Bundle-SymbolicName: flintstones.entity.ahppreferences +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.ahppreferences +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.apache.commons.lang, + flintstones.entity.ahp, + flintstones.entity.problemelement, + flintstones.model.problemelement.service, + flintstones.entity.extensionenum, + javax.inject, + flintstones.entity.domain, + javax.annotation, + flintstones.helper.data, + flintstones.valuation.ahp, + flintstones.helper.ahp +Export-Package: flintstones.entity.ahppreferences diff --git a/bundles/flintstones.entity.ahppreferences/build.properties b/bundles/flintstones.entity.ahppreferences/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceBuild.java b/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceBuild.java new file mode 100644 index 0000000..e82fa81 --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceBuild.java @@ -0,0 +1,309 @@ +package flintstones.entity.ahppreferences; + +import java.util.LinkedList; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class PreferenceBuild. + * Almacena una instancia completa de una comparación. + * Para el Experto e1 con el Criterio c1, tenemos 2 listas de elementos (leftArr y rightArr) y sus comparaciones en "matrix". + */ +public class PreferenceBuild { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The main. */ + ProblemElement main; + + /** The other. */ + ProblemElement other; + + /** The main type. */ + String mainType; + + /** The other type. */ + String otherType; + + /** The left type. */ + String leftType; + + /** The right type. */ + String rightType; + + /** The matrix. */ + // Preferences + PreferenceMatrix matrix; + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + + /** The Preference build. */ + PreferenceBuild, + /** The main problem element. */ + mainProblemElement, + /** The other problem element. */ + otherProblemElement, + /** The left elements. */ + leftElements, + /** The right elements. */ + rightElements, + /** The type. */ + type, + /** The right problem element. */ + rightProblemElement, + /** The left problem element. */ + leftProblemElement, + /** The Preference. */ + Preference + }; + + /** + * Instantiates a new preference build. + * + * @param domain the domain + * @param main the main + * @param other the other + * @param leftArr the left arr + * @param rightArr the right arr + */ + public PreferenceBuild(ProblemElement main, ProblemElement other, ProblemElement[] leftArr, + ProblemElement[] rightArr) { + + this.main = main; + this.other = other; + + mainType = main != null ? main.getType() : FakeProblemElement.Type; + otherType = other != null ? other.getType() : FakeProblemElement.Type; + + leftType = leftArr[0].getType(); + rightType = rightArr[0].getType(); + + matrix = new PreferenceMatrix(leftArr, rightArr); + } + + /** + * Post construct. + */ + @PostConstruct + private void postConstruct() { + if (main == null) + main = getFakeElementArr(); + + if (other == null) + other = getFakeElementArr(); + + } + + /** + * Gets the main type. + * + * @return the main type + */ + public String getMainType() { + return mainType; + } + + /** + * Gets the other type. + * + * @return the other type + */ + public String getOtherType() { + return otherType; + } + + /** + * Gets the left type. + * + * @return the left type + */ + public String getLeftType() { + return leftType; + } + + /** + * Gets the right type. + * + * @return the right type + */ + public String getRightType() { + return rightType; + } + + /** + * Gets the main. + * + * @return the main + */ + public ProblemElement getMain() { + return main; + } + + /** + * Gets the other. + * + * @return the other + */ + public ProblemElement getOther() { + return other; + } + + /** + * Gets the left elements. + * + * @return the left elements + */ + public LinkedList getLeftElements() { + return matrix.getRowHeaders(); + } + + /** + * Gets the right elements. + * + * @return the right elements + */ + public LinkedList getRightElements() { + return matrix.getColumnHeaders(); + } + + /** + * Gets the fake element arr. + * + * @return the fake element arr + */ + private ProblemElement getFakeElementArr() { + return problemService.getGeneric(); + } + + /** + * Checks if is main generic. + * + * @return true, if is main generic + */ + public boolean isMainGeneric() { + return main.getType().equals(FakeProblemElement.Type); + } + + /** + * Checks if is other generic. + * + * @return true, if is other generic + */ + public boolean isOtherGeneric() { + return other.getType().equals(FakeProblemElement.Type); + } + + /** + * Gets the matrix. + * + * @return the matrix + */ + public PreferenceMatrix getMatrix() { + return this.matrix; + } + + /** + * Gets the key. + * + * @return the key + */ + public PreferenceCollectionKey getKey() { + return new PreferenceCollectionKey(mainType, otherType, leftType, rightType); + } + + /** + * Gets the AHP matrix. + * + * @return the AHP matrix + */ + // Matrix operations + public AHPMatrix getAHPMatrix() { + + if (!isAHP()) + throw new RuntimeException( + "AHPMatrix can not be generated if you are not comparing element with the same type "); + + return matrix.getAHPMatrix(/*main, other*/); + + } + + /** + * Sets the. + * + * @param left the left + * @param right the right + * @param index the index + */ + public void set(ProblemElement left, ProblemElement right, int index) { + matrix.set(left, right, index); + } + + /** + * Sets the diagonal. + * + * @param left the left + * @param right the right + * @param index the index + */ + public void setDiagonal(ProblemElement left, ProblemElement right, int index) { + matrix.setDiagonal(left, right, index); + } + + /** + * Gets the. + * + * @return the int[][] + */ + public int[][] get() { + return matrix.getMatrix(); + } + + /** + * Gets the. + * + * @param left the left + * @param right the right + * @return the int + */ + public int get(ProblemElement left, ProblemElement right) { + return matrix.get(left, right); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + + + StringBuilder sb = new StringBuilder(); + sb.append(matrix.toString()); + return sb.toString(); + + } + + /** + * Checks if is ahp. + * + * @return true, if is ahp + */ + public boolean isAHP() { + return leftType.equals(rightType); + } + +} diff --git a/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceCollectionKey.java b/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceCollectionKey.java new file mode 100644 index 0000000..8c58ae7 --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceCollectionKey.java @@ -0,0 +1,133 @@ +package flintstones.entity.ahppreferences; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +import flintstones.entity.problemelement.entities.FakeProblemElement; + +/** + * The Class PreferenceCollectionKey. + */ +public class PreferenceCollectionKey { + + /** The main type. */ + private String mainType; + + /** The other type. */ + private String otherType; + + /** The left type. */ + private String leftType; + + /** The right type. */ + private String rightType; + + /** + * Instantiates a new preference collection key. + * + * @param mainType the main type + * @param otherType the other type + * @param leftType the left type + * @param rightType the right type + */ + public PreferenceCollectionKey(String mainType, String otherType, String leftType, String rightType) { + this.mainType = mainType != null ? mainType : FakeProblemElement.Type; + this.otherType = otherType != null ? otherType : FakeProblemElement.Type; + this.leftType = leftType; + this.rightType = rightType; + } + + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + HashCodeBuilder builder = new HashCodeBuilder(); + builder.append(mainType); + builder.append(otherType); + builder.append(leftType); + builder.append(rightType); + + return builder.toHashCode(); + + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + + if(obj == null) + return false; + + PreferenceCollectionKey pc = (PreferenceCollectionKey)obj; + + EqualsBuilder builder = new EqualsBuilder(); + builder.append(mainType, pc.mainType); + builder.append(otherType, pc.otherType); + builder.append(leftType, pc.leftType); + builder.append(rightType, pc.rightType); + + return builder.isEquals(); + + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append(mainType); + builder.append(", "); + builder.append(otherType); + builder.append(", "); + builder.append(leftType); + builder.append(", "); + builder.append(rightType); + builder.append("\n "); + + return builder.toString(); + + } + + /** + * Gets the main type. + * + * @return the main type + */ + public String getMainType() { + return mainType; + } + + /** + * Gets the other type. + * + * @return the other type + */ + public String getOtherType() { + return otherType; + } + + /** + * Gets the left type. + * + * @return the left type + */ + public String getLeftType() { + return leftType; + } + + /** + * Gets the right type. + * + * @return the right type + */ + public String getRightType() { + return rightType; + } +} + diff --git a/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceMatrix.java b/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceMatrix.java new file mode 100644 index 0000000..2e8c2ac --- /dev/null +++ b/bundles/flintstones.entity.ahppreferences/src/flintstones/entity/ahppreferences/PreferenceMatrix.java @@ -0,0 +1,157 @@ +package flintstones.entity.ahppreferences; + +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.Map.Entry; + +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.ahp.AHPHelper; +import flintstones.helper.data.LinkedHashMatrix; + +/** + * The Class PreferenceMatrix store the preferences of two lists of elements and + * provide tools to convert it to an AHP Matrix or to múltiple AHP Matrix. + * + * It also respect the properties of an AHP matrix if it used with the right + * API. + * + * Almacena preferencias. + */ +public class PreferenceMatrix { + + /** The matrix. */ + LinkedHashMatrix matrix = new LinkedHashMatrix<>(); + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + + /** The Preference matrix. */ + PreferenceMatrix, + /** The preference index. */ + preferenceIndex + } + + /** + * Instantiates a new preference matrix. + * + * @param ahpDomain the ahp domain + * @param leftItems the left items + * @param rightItems the right items + */ + public PreferenceMatrix(ProblemElement[] leftItems, ProblemElement[] rightItems) { + + for (ProblemElement left : leftItems) + for (ProblemElement right : rightItems) + matrix.put(left, right, (int) AHPHelper.getMidPoint() ); + + + } + + /** + * Gets the matrix. + * + * @return the matrix + */ + public int[][] getMatrix() { + + int[][] basicMatrix = new int[matrix.size()][matrix.innerSize()]; + + int i = 0; + for (Entry> entry1 : matrix.entrySet()) { + int j = 0; + for (Entry entry2 : entry1.getValue().entrySet()) { + basicMatrix[i][j] = get(entry1.getKey(), entry2.getKey()); + j++; + } + i++; + } + + return basicMatrix; + } + + /** + * Sets the. + * + * @param left the left + * @param right the right + * @param index the index + */ + public void set(ProblemElement left, ProblemElement right, int index) { + + matrix.put(left, right, index); + + } + + /** + * Sets the diagonal. + * + * @param left the left + * @param right the right + * @param index the index + */ + public void setDiagonal(ProblemElement left, ProblemElement right, int index) { + + if (left.equals(right) || matrix.size() != matrix.innerSize()) + throw new RuntimeException("Use set(...) instead of setDiagonal(...)"); + + matrix.put(left, right, index); + matrix.put(right, left, AHPHelper.getInverseIndex(index)); + } + + /** + * Gets the. + * + * @param left the left + * @param right the right + * @return the int + */ + public Integer get(ProblemElement left, ProblemElement right) { + + return matrix.get(left, right); + } + + /** + * Gets the AHP matrix. + * + * @param main the main + * @param other the other + * @return the AHP matrix + */ + public AHPMatrix getAHPMatrix() { + LinkedList leftItems = getRowHeaders(); + AHPMatrix ahpmatrix = new AHPMatrix(leftItems.toArray(new ProblemElement[0])); + + for (ProblemElement pe1 : leftItems) { + for (ProblemElement pe2 : leftItems) { + int index = get(pe1, pe2); + ahpmatrix.set(pe1, pe2, index); + } + + } + + return ahpmatrix; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return matrix.toString(); + } + + public LinkedList getRowHeaders() { + return new LinkedList<>(matrix.keySet()); + } + + public LinkedList getColumnHeaders() { + return new LinkedList<>(matrix.iterator().next().getValue().keySet()); + } + +} diff --git a/bundles/flintstones.entity.ahpsort.priority/.classpath b/bundles/flintstones.entity.ahpsort.priority/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.ahpsort.priority/.polyglot.META-INF b/bundles/flintstones.entity.ahpsort.priority/.polyglot.META-INF new file mode 100644 index 0000000..e616cc7 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.ahpsort.priority + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Priority + diff --git a/bundles/flintstones.entity.ahpsort.priority/.project b/bundles/flintstones.entity.ahpsort.priority/.project new file mode 100644 index 0000000..54564be --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.ahpsort.priority + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362555 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.ahpsort.priority/META-INF/MANIFEST.MF b/bundles/flintstones.entity.ahpsort.priority/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7726b5e --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Priority +Bundle-SymbolicName: flintstones.entity.ahpsort.priority +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.ahpsort.priority +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.data, + flintstones.entity.problemelement, + flintstones.entity.ahpsort.referencepoint +Export-Package: flintstones.entity.ahpsort.priority diff --git a/bundles/flintstones.entity.ahpsort.priority/build.properties b/bundles/flintstones.entity.ahpsort.priority/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.ahpsort.priority/src/flintstones/entity/ahpsort/priority/AHPSortPriority.java b/bundles/flintstones.entity.ahpsort.priority/src/flintstones/entity/ahpsort/priority/AHPSortPriority.java new file mode 100644 index 0000000..cc4031a --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/src/flintstones/entity/ahpsort/priority/AHPSortPriority.java @@ -0,0 +1,117 @@ +package flintstones.entity.ahpsort.priority; + +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.DoubleHelper; + +/** + * The Class AHPSortPriority. + */ +public class AHPSortPriority { + + /** The alternative. */ + ProblemElement leftElement; + + /** The profile. */ + ProblemElement[] rightElement; + + /** The alternative priority. */ + double leftPriority; + + /** The profile priority. */ + double[] rightPriority; + + /** + * Instantiates a new AHP sort priority. + * + * @param profile the profile + * @param alternative the alternative + * @param leftValue the left value + * @param rightValue the right value + */ + public AHPSortPriority(SortingProfile[] profile, Alternative alternative, double leftValue, double[] rightValue) { + this.rightElement = profile; + this.leftElement = alternative; + this.leftPriority = leftValue; + this.rightPriority = rightValue; + } + + public AHPSortPriority(SortingProfile[] profile, AHPSortReferencencePoint refPoint, double leftValue, + double[] rightValue) { + this.rightElement = profile; + this.leftElement = refPoint; + this.leftPriority = leftValue; + this.rightPriority = rightValue; + } + +// /** +// * Instantiates a new AHP sort priority. +// * +// * @param profile the profile +// * @param alternative the alternative +// * @param values the values +// */ +// public AHPSortPriority(SortingProfile[] profile, Alternative alternative, double[] values) { +// this(profile, alternative, values[0], valores); +// if (values.length != 2) +// throw new RuntimeException("No"); +// } +// +// public AHPSortPriority(SortingProfile[] profile, AHPSortReferencencePoint refPoint, double[] values) { +// this(profile, refPoint, values[0], values[1]); +// if (values.length != 2) +// throw new RuntimeException("No"); +// } + + /** + * Gets the alternative. + * + * @return the alternative + */ + public ProblemElement getLeftElement() { + return leftElement; + } + + /** + * Gets the profile. + * + * @return the profile + */ + public SortingProfile[] getProfile() { + return (SortingProfile[]) rightElement; + } + + /** + * Gets the alternative priority. + * + * @return the alternative priority + */ + public double getAlternativePriority() { + return leftPriority; + } + + public double getReferencePointPriority() { + return leftPriority; + } + + /** + * Gets the profile priority. + * + * @return the profile priority + */ + public double[] getProfilePriority() { + return rightPriority; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "( " + DoubleHelper.Draw(leftPriority) + ", " + rightPriority.toString() + " )"; + } +} diff --git a/bundles/flintstones.entity.ahpsort.priority/src/flintstones/entity/ahpsort/priority/AHPSortPriorityManager.java b/bundles/flintstones.entity.ahpsort.priority/src/flintstones/entity/ahpsort/priority/AHPSortPriorityManager.java new file mode 100644 index 0000000..a168200 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.priority/src/flintstones/entity/ahpsort/priority/AHPSortPriorityManager.java @@ -0,0 +1,93 @@ +package flintstones.entity.ahpsort.priority; + +import java.util.Arrays; +import java.util.LinkedHashSet; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.data.HashMapList; +import flintstones.helper.data.HashMatrix; + +/** + * The Class AHPSortPriorityManager. + */ +public class AHPSortPriorityManager { + + /** The data. */ + private HashMapList data = new HashMapList<>(); + private LinkedHashSet profiles = new LinkedHashSet(); + + /** + * Instantiates a new AHP sort priority manager. + */ + public AHPSortPriorityManager() { + } + + /** + * Adds the. + * + * @param prior the prior + */ + public void add(AHPSortPriority prior) { + data.add(prior.getLeftElement(), prior); + SortingProfile[] perfil = prior.getProfile(); + for (SortingProfile sortingProfile : perfil) { + if (!profiles.contains(sortingProfile)) + profiles.add(sortingProfile); + } + + } + + /** + * Gets the alternatives. + * + * @return the alternatives + */ + public ProblemElement[] getLeftElements() { + return data.keySet().stream().toArray(ProblemElement[]::new); + } + + /** + * Gets the profiles. + * + * @return the profiles // + */ + public SortingProfile[] getProfiles() { + return profiles.stream().toArray(SortingProfile[]::new); + } + + /** + * Gets the. + * + * @param a the a + * @param p the p + * @return the AHP sort priority + */ + + public AHPSortPriority get(ProblemElement a, int profileIndex) { + return data.get(a).get(profileIndex); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + ProblemElement[] outer = data.keySet().stream().map(k -> k).toArray(ProblemElement[]::new); + ProblemElement[] inner = profiles.stream().map(k -> (ProblemElement) k).toArray(ProblemElement[]::new); + + Arrays.sort(outer, (a, b) -> a.getOrder() > b.getOrder() ? 1 : -1); + Arrays.sort(inner, (a, b) -> a.getOrder() > b.getOrder() ? 1 : -1); + + HashMatrix matrix = new HashMatrix<>(); + + for (ProblemElement o : outer) + for (int i = 0; i < inner.length; i++) + matrix.put(o, getProfiles()[i], get(o, i)); + + return matrix.toString(); + } +} diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/.classpath b/bundles/flintstones.entity.ahpsort.profileassignment/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/.polyglot.META-INF b/bundles/flintstones.entity.ahpsort.profileassignment/.polyglot.META-INF new file mode 100644 index 0000000..4c4dcb9 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.ahpsort.profileassignment + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Profileassignment + diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/.project b/bundles/flintstones.entity.ahpsort.profileassignment/.project new file mode 100644 index 0000000..a2db2fa --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.ahpsort.profileassignment + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362556 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/META-INF/MANIFEST.MF b/bundles/flintstones.entity.ahpsort.profileassignment/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6b13249 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Profileassignment +Bundle-SymbolicName: flintstones.entity.ahpsort.profileassignment +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.profileassignment +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.extensionenum +Export-Package: flintstones.entity.ahpsort.profileassignment diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/build.properties b/bundles/flintstones.entity.ahpsort.profileassignment/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.ahpsort.profileassignment/src/flintstones/entity/ahpsort/profileassignment/ProfileAssignment.java b/bundles/flintstones.entity.ahpsort.profileassignment/src/flintstones/entity/ahpsort/profileassignment/ProfileAssignment.java new file mode 100644 index 0000000..ba2ff82 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.profileassignment/src/flintstones/entity/ahpsort/profileassignment/ProfileAssignment.java @@ -0,0 +1,108 @@ +package flintstones.entity.ahpsort.profileassignment; + +import java.util.LinkedList; + +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; + +/** + * The Class ProfileAssignment. + */ +public class ProfileAssignment { + + /** The expert. */ + Expert expert; + + /** The criterion. */ + Criterion criterion; + + /** The profiles. */ + LinkedList profiles = new LinkedList<>(); + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + + /** The Profile assignment. */ + ProfileAssignment, + /** The Profile assignments. */ + ProfileAssignments + } + + /** + * Instantiates a new profile assignment. + * + * @param e the e + * @param c the c + */ + public ProfileAssignment(Expert e, Criterion c) { + this.expert = e; + this.criterion = c; + } + + /** + * Adds the profile. + * + * @param p the p + */ + public void addProfile(SortingProfile p) { + profiles.add(p); + } + + /** + * Gets the all profiles. + * + * @return the all profiles + */ + public LinkedList getAllProfiles() { + return new LinkedList<>(profiles); + } + + /** + * Gets the values. + * + * @return the values + */ + public Double[] getValues() { + return profiles.stream().map(k -> k.getValue()).toArray(Double[]::new); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (SortingProfile profile : profiles) { + sb.append(profile.getValue()); + sb.append(", "); + } + + return sb.toString(); + } + + + /** + * Gets the expert. + * + * @return the expert + */ + public Expert getExpert() { + return expert; + } + + /** + * Gets the criterion. + * + * @return the criterion + */ + public Criterion getCriterion() { + return criterion; + } + +} diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/.classpath b/bundles/flintstones.entity.ahpsort.referencepoint/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/.polyglot.META-INF b/bundles/flintstones.entity.ahpsort.referencepoint/.polyglot.META-INF new file mode 100644 index 0000000..de15076 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.ahpsort.referencepoint + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Referencepoint + diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/.project b/bundles/flintstones.entity.ahpsort.referencepoint/.project new file mode 100644 index 0000000..7481f20 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.ahpsort.referencepoint + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362559 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/META-INF/MANIFEST.MF b/bundles/flintstones.entity.ahpsort.referencepoint/META-INF/MANIFEST.MF new file mode 100644 index 0000000..03e0c86 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Referencepoint +Bundle-SymbolicName: flintstones.entity.ahpsort.referencepoint +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.ahpsort.referencepoint +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.problemelement, + org.apache.commons.lang, + flintstones.helper.data +Export-Package: flintstones.entity.ahpsort.referencepoint diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/build.properties b/bundles/flintstones.entity.ahpsort.referencepoint/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.ahpsort.referencepoint/src/flintstones/entity/ahpsort/referencepoint/AHPSortReferencencePoint.java b/bundles/flintstones.entity.ahpsort.referencepoint/src/flintstones/entity/ahpsort/referencepoint/AHPSortReferencencePoint.java new file mode 100644 index 0000000..39b97c6 --- /dev/null +++ b/bundles/flintstones.entity.ahpsort.referencepoint/src/flintstones/entity/ahpsort/referencepoint/AHPSortReferencencePoint.java @@ -0,0 +1,63 @@ +package flintstones.entity.ahpsort.referencepoint; + +import java.util.ArrayList; + +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; + +public class AHPSortReferencencePoint extends ProblemElement { + + public static String Type = AHPSortReferencencePoint.class.getSimpleName(); + + private double value; + private Criterion c; + + private ArrayList profiles = new ArrayList<>(); + + public void addProfile(SortingProfile prof) { + profiles.add(prof); + } + + public AHPSortReferencencePoint(Criterion c, double value) { + + this.value = value; + this.c = c; + + setType(AHPSortReferencencePoint.Type); + setName("RP_" + c.getName() + " " + DoubleHelper.Draw(value)); + updateId(); + + } + + public double getValue() { + return value; + } + + @Override + public Object clone() { + throw new UnsupportedOperationException(); + } + + @Override + public String toString() { + return value + ""; + } + + @Override + public String calculateId() { + return c.getName() + " " + value; + } + + @Override + public int compareTo(ProblemElement pe) { + return Double.compare(this.value, ((AHPSortReferencencePoint) pe).getValue()); + } + + @Override + public String getShortName() { + return "RP " + value; + } + +} diff --git a/bundles/flintstones.entity.common/.classpath b/bundles/flintstones.entity.common/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.common/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.common/.polyglot.META-INF b/bundles/flintstones.entity.common/.polyglot.META-INF new file mode 100644 index 0000000..6374029 --- /dev/null +++ b/bundles/flintstones.entity.common/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.common + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Common + diff --git a/bundles/flintstones.entity.common/.project b/bundles/flintstones.entity.common/.project new file mode 100644 index 0000000..10740a8 --- /dev/null +++ b/bundles/flintstones.entity.common/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.common + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362560 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.common/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.common/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.common/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.common/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.common/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.common/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.common/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.common/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.common/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.common/META-INF/MANIFEST.MF b/bundles/flintstones.entity.common/META-INF/MANIFEST.MF new file mode 100644 index 0000000..93b03f2 --- /dev/null +++ b/bundles/flintstones.entity.common/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Common +Bundle-SymbolicName: flintstones.entity.common +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.common +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.common.interfaces diff --git a/bundles/flintstones.entity.common/build.properties b/bundles/flintstones.entity.common/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.common/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IChangedEntity.java b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IChangedEntity.java new file mode 100644 index 0000000..7b53d56 --- /dev/null +++ b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IChangedEntity.java @@ -0,0 +1,6 @@ +package flintstones.entity.common.interfaces; + +public interface IChangedEntity { + + void onEntityChange(Object data); +} diff --git a/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IRefreshEntity.java b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IRefreshEntity.java new file mode 100644 index 0000000..24452c9 --- /dev/null +++ b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IRefreshEntity.java @@ -0,0 +1,7 @@ +package flintstones.entity.common.interfaces; + +public interface IRefreshEntity { + + void refreshEntity(Object data); + +} diff --git a/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IdentifiedEntity.java b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IdentifiedEntity.java new file mode 100644 index 0000000..096a391 --- /dev/null +++ b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/IdentifiedEntity.java @@ -0,0 +1,11 @@ +package flintstones.entity.common.interfaces; + +public interface IdentifiedEntity { + + abstract String calculateId(); + + public abstract String getId(); + + public abstract void updateId(); + +} diff --git a/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/Iuuid.java b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/Iuuid.java new file mode 100644 index 0000000..d92aad2 --- /dev/null +++ b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/Iuuid.java @@ -0,0 +1,5 @@ +package flintstones.entity.common.interfaces; + +public interface Iuuid { + public int getUUID(); +} diff --git a/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/TypedEntity.java b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/TypedEntity.java new file mode 100644 index 0000000..55f0e1d --- /dev/null +++ b/bundles/flintstones.entity.common/src/flintstones/entity/common/interfaces/TypedEntity.java @@ -0,0 +1,8 @@ +package flintstones.entity.common.interfaces; + +public interface TypedEntity { + + abstract String getType(); + + abstract void setType(String type); +} diff --git a/bundles/flintstones.entity.domain.ui.chart/.classpath b/bundles/flintstones.entity.domain.ui.chart/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.domain.ui.chart/.polyglot.META-INF b/bundles/flintstones.entity.domain.ui.chart/.polyglot.META-INF new file mode 100644 index 0000000..c27c1c6 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.domain.ui.chart + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Chart + diff --git a/bundles/flintstones.entity.domain.ui.chart/.project b/bundles/flintstones.entity.domain.ui.chart/.project new file mode 100644 index 0000000..4cb26e8 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.domain.ui.chart + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362563 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.domain.ui.chart/META-INF/MANIFEST.MF b/bundles/flintstones.entity.domain.ui.chart/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b10db69 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Chart +Bundle-SymbolicName: flintstones.entity.domain.ui.chart +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.domain.ui.chart +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.domain.ui.chart +Require-Bundle: flintstones.entity.domain, + org.eclipse.swt, + org.jfree.chart.jfreechart diff --git a/bundles/flintstones.entity.domain.ui.chart/build.properties b/bundles/flintstones.entity.domain.ui.chart/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.domain.ui.chart/src/flintstones/entity/domain/ui/chart/DomainChart.java b/bundles/flintstones.entity.domain.ui.chart/src/flintstones/entity/domain/ui/chart/DomainChart.java new file mode 100644 index 0000000..15db408 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.chart/src/flintstones/entity/domain/ui/chart/DomainChart.java @@ -0,0 +1,50 @@ +package flintstones.entity.domain.ui.chart; + + +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.swt.ChartComposite; + +import flintstones.entity.domain.Domain; + + +@SuppressWarnings("javadoc") +public abstract class DomainChart { + + protected Domain _domain; + protected JFreeChart _chart; + protected ChartComposite _chartComposite; + + public ChartComposite getChartComposite() { + return this._chartComposite; + } + + public void setCharComposite(ChartComposite chartComposite) { + this._chartComposite = chartComposite; + } + + public Domain getDomain() { + return this._domain; + } + + public void setDomain(Domain domain) { + this._domain = domain; + this.refreshChart(); + } + + public void updateSize(int width, int height) { + _chartComposite.setSize(width, height); + } + + public abstract void refreshChart(); + + public abstract void setSelection(Object selection); + + public abstract void initialize(Domain domain, Composite container, int width, int height, int style); + + public abstract void displayRanking(Object ranking); + + public void displayAlternatives(String[] alternatives, int[] pos, double[] alpha) { + throw new RuntimeException("No implementado"); + } +} diff --git a/bundles/flintstones.entity.domain.ui.dialog/.classpath b/bundles/flintstones.entity.domain.ui.dialog/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.domain.ui.dialog/.polyglot.META-INF b/bundles/flintstones.entity.domain.ui.dialog/.polyglot.META-INF new file mode 100644 index 0000000..550ae49 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.domain.ui.dialog + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Dialog + diff --git a/bundles/flintstones.entity.domain.ui.dialog/.project b/bundles/flintstones.entity.domain.ui.dialog/.project new file mode 100644 index 0000000..ba36ac9 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.domain.ui.dialog + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362564 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.domain.ui.dialog/META-INF/MANIFEST.MF b/bundles/flintstones.entity.domain.ui.dialog/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2f6eb62 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Dialog +Bundle-SymbolicName: flintstones.entity.domain.ui.dialog +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.domain.ui.dialog +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.domain.ui.dialog +Require-Bundle: flintstones.entity.domain, + flintstones.model.domain.service, + javax.inject, + org.eclipse.swt, + org.eclipse.jface, + flintstones.helper.ui, + org.eclipse.e4.core.services, + org.eclipse.e4.core.contexts, + flintstones.entity.domain.ui.provider, + org.eclipse.e4.core.di, + javax.annotation, + flintstones.model.ui.service diff --git a/bundles/flintstones.entity.domain.ui.dialog/build.properties b/bundles/flintstones.entity.domain.ui.dialog/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/AddDomainDialog.java b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/AddDomainDialog.java new file mode 100644 index 0000000..18d3755 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/AddDomainDialog.java @@ -0,0 +1,171 @@ +package flintstones.entity.domain.ui.dialog; + +import java.util.Iterator; + +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.viewers.AbstractTreeViewer; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.swt.SWT; +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 org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import flintstones.entity.domain.DomainMockup; +import flintstones.entity.domain.ui.dialog.messages.Messages; +import flintstones.entity.domain.ui.provider.DomainDomainMockupContentProvider; +import flintstones.entity.domain.ui.provider.DomainMockupLabelProvider; +import flintstones.model.domain.service.IDomainService; + +/** + * @author Sinbad2 + * + */ +public class AddDomainDialog extends Dialog { + + @Inject + @Translation + private Messages messages; + + private static final int DIALOG_SIZE_Y = 400; + + private static final int DIALOG_SIZE_X = 450; + + @Inject + IDomainService domainService; + + @Inject + IEclipseContext context; + + + private Button okButton; + + private String selectedDomainExtension; + + /** + * @param parentShell The parent shell + */ + @Inject + public AddDomainDialog(Shell parentShell) { + super(parentShell); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + + GridLayout layout = new GridLayout(1, false); + + layout.verticalSpacing = 2; + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.horizontalSpacing = 0; + parent.setLayout(layout); + + this.addTreeView(container); + + return container; + } + + private void addTreeView(Composite container) { + + DomainMockupLabelProvider delp = ContextInjectionFactory.make(DomainMockupLabelProvider.class, this.context); + DomainDomainMockupContentProvider dccp = ContextInjectionFactory.make(DomainDomainMockupContentProvider.class, context); + + final TreeViewer tv = new TreeViewer(container); + tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); + tv.setContentProvider(dccp); + + TreeViewerColumn mainColumn = new TreeViewerColumn(tv, SWT.NONE); + mainColumn.getColumn().setText("Domains"); + mainColumn.getColumn().setWidth(300); + mainColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(delp)); + + tv.getTree().setHeaderVisible(true); + tv.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); + + DomainMockup[] domains = domainService.getMockupDomains(); + + tv.setInput(domains); + tv.addSelectionChangedListener(this.treeviewOnclick()); + } + + private ISelectionChangedListener treeviewOnclick() { + return event -> { + ISelection selection = event.getSelection(); + Iterator selectedElements = ((IStructuredSelection) selection).iterator(); + + if (!selectedElements.hasNext()) + return; + + Object next = selectedElements.next(); + + DomainMockup de = (DomainMockup) next; + boolean isDomain = de.getId() != null; + + AddDomainDialog.this.okButton.setEnabled(isDomain); + + if(isDomain) + AddDomainDialog.this.setSelectedDomainExtension(de.getId()); + + }; + } + + // overriding this methods allows you to set the + // title of the custom dialog + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(this.messages.title_add_domain_dialog); + + } + + @Override + protected Point getInitialSize() { + return new Point(AddDomainDialog.DIALOG_SIZE_X, AddDomainDialog.DIALOG_SIZE_Y); + } + + @Override + protected void okPressed() { + super.okPressed(); + } + + @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); + + this.okButton = this.getButton(IDialogConstants.OK_ID); + this.okButton.setEnabled(false); + // UiService.reLayoutShell(this.getShell()); + } + + /** + * @return the selectedDomainExtension + */ + public String getSelectedDomainExtension() { + return this.selectedDomainExtension; + } + + /** + * @param selectedDomainExtension the selectedDomainExtension to set + */ + public void setSelectedDomainExtension(String selectedDomainExtension) { + this.selectedDomainExtension = selectedDomainExtension; + } + +} diff --git a/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/DomainDialog.java b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/DomainDialog.java new file mode 100644 index 0000000..03b678e --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/DomainDialog.java @@ -0,0 +1,136 @@ +package flintstones.entity.domain.ui.dialog; + +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.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.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.dialog.messages.Messages; +import flintstones.helper.ui.components.ValidatedField; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.ui.service.UiService; + +public abstract class DomainDialog extends Dialog { + + private Domain domain; + private Button okButton; + + private String oldName = ""; + private String newName = ""; + + private ValidatedField nameField; + private boolean lastCheck = false; + + @Inject + IDomainService domainService; + + @Inject + @Translation + private Messages messages; + + protected DomainDialog() { + super(Display.getCurrent().getActiveShell()); + } + + public Domain getDomain() { + return domain; + } + + public String getName() { + return newName; + } + + public void setDomainTop(Domain base) { + + domain = base; + oldName = base.getName(); + newName = base.getName(); + + this.create(); + beforeUI(); + } + + public void setSaveEnabled(boolean enabled) { + lastCheck = enabled; + refresheEnabled(); + } + + protected void addNameField(Composite container) { + + UiService.setMargin(container, 0); + + nameField = new ValidatedField(container, messages.Domain_name_label, getDomain().getName()); + nameField.getInput().addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + newName = nameField.getText(); + checkDomainName(); + refresheEnabled(); + } + }); + + } + + protected abstract void beforeUI(); + + private void refresheEnabled() { + if (okButton != null) + okButton.setEnabled(lastCheck && checkDomainName()); + + } + + private boolean checkDomainName() { + + boolean isValid = isValidName(newName); + + // 1. Domain name should not be not empty + if (!isValid && (newName == null || newName.equals(""))) { //$NON-NLS-1$ + nameField.setError(messages.Empty_domain); + } else if(!isValid) { + nameField.setError(messages.Duplicated_name); + } else { + nameField.setError(""); + } + + return isValid; + + } + + private boolean isValidName(String name) { + + if(name == null) + return false; + + if(name.equals("")) + return false; + + if(name.equals(oldName)) + return true; + + return domainService.getByName(name) == null; + } + + + @Override + protected void createButtonsForButtonBar(Composite parent) { + this.okButton = this.createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false); + this.okButton.setEnabled(false); + this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + this.okButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + domain.setName(newName); + } + }); + } + +} diff --git a/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/SelectBetweenMultipleDomainsDialog.java b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/SelectBetweenMultipleDomainsDialog.java new file mode 100644 index 0000000..6d95652 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/SelectBetweenMultipleDomainsDialog.java @@ -0,0 +1,94 @@ +package flintstones.entity.domain.ui.dialog; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +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.Shell; + +import flintstones.entity.domain.ui.dialog.messages.Messages; +import flintstones.helper.ui.components.WLabel; +import flintstones.model.ui.service.UiService; + +/** + * The Class SelectNewDomainDialog. + */ +public class SelectBetweenMultipleDomainsDialog extends Dialog { + + + @Inject + @Translation + private Messages messages; + + /** The selected id. */ + private String selected; + + String[] descriptions; + + /** + * Instantiates a new select new domain dialog. + */ + public SelectBetweenMultipleDomainsDialog() { + super(Display.getCurrent().getActiveShell()); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets. + * Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + + WLabel label = new WLabel(container); + UiService.setFont(label, UiService.FONT_SECTION_TITLE); + label.setText(this.messages.title_select_new_domain_dialog); + + for (String description : descriptions) { + Button button = new Button(container, SWT.RADIO); + button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); + + button.setText(description); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String selectedDescription = ((Button) e.getSource()).getText(); + selected = selectedDescription; + }; + }); + + } + + return container; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(this.messages.title_select_new_domain_dialog); + } + + public void setDescriptions(String[] descriptions) { + this.descriptions = descriptions; + } + + public String getSelected() { return selected; } + +} diff --git a/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/Messages.java b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/Messages.java new file mode 100644 index 0000000..3f2d7b2 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/Messages.java @@ -0,0 +1,17 @@ +// This file has been auto-generated +package flintstones.entity.domain.ui.dialog.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String title_add_domain_dialog; + public String title_select_new_domain_dialog; + + public String Domain_name_label; + public String Empty_domain; + public String Duplicated_name; + +} diff --git a/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/messages.properties b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/messages.properties new file mode 100644 index 0000000..211a218 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/messages.properties @@ -0,0 +1,5 @@ +title_add_domain_dialog=Choose domain type +title_select_new_domain_dialog=Choose the domain +Domain_name_label=Domain name +Empty_domain=The domain name should not be empty +Duplicated_name=The selected name is being used by another domain \ No newline at end of file diff --git a/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/messages_es.properties b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/messages_es.properties new file mode 100644 index 0000000..cd6f479 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.dialog/src/flintstones/entity/domain/ui/dialog/messages/messages_es.properties @@ -0,0 +1,5 @@ +title_add_domain_dialog=Elija el tipo de dominio +title_select_new_domain_dialog=Elija el dominio +Domain_name_label=Nombre del dominio +Empty_domain=El nombre del dominio no debe estar vaco +Duplicated_name=El nombre del dominio ya existe \ No newline at end of file diff --git a/bundles/flintstones.entity.domain.ui.provider/.classpath b/bundles/flintstones.entity.domain.ui.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.domain.ui.provider/.polyglot.META-INF b/bundles/flintstones.entity.domain.ui.provider/.polyglot.META-INF new file mode 100644 index 0000000..4429ff0 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.domain.ui.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.entity.domain.ui.provider/.project b/bundles/flintstones.entity.domain.ui.provider/.project new file mode 100644 index 0000000..e45d1e5 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.domain.ui.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362565 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.domain.ui.provider/META-INF/MANIFEST.MF b/bundles/flintstones.entity.domain.ui.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e129c71 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.entity.domain.ui.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.domain.ui.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.domain.ui.provider +Require-Bundle: flintstones.helper.ui, + javax.inject, + flintstones.entity.domain, + flintstones.model.ui.service, + flintstones.model.domain.service diff --git a/bundles/flintstones.entity.domain.ui.provider/build.properties b/bundles/flintstones.entity.domain.ui.provider/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.domain.ui.provider/src/flintstones/entity/domain/ui/provider/DomainDomainMockupContentProvider.java b/bundles/flintstones.entity.domain.ui.provider/src/flintstones/entity/domain/ui/provider/DomainDomainMockupContentProvider.java new file mode 100644 index 0000000..8e74ffa --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/src/flintstones/entity/domain/ui/provider/DomainDomainMockupContentProvider.java @@ -0,0 +1,38 @@ +package flintstones.entity.domain.ui.provider; + +import javax.inject.Inject; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; + +import flintstones.entity.domain.DomainMockup; +import flintstones.model.domain.service.IDomainService; + +public class DomainDomainMockupContentProvider implements ITreeContentProvider { + + @Inject + IDomainService domainService; + + @Override + public Object[] getElements(Object inputElement) { + return ArrayContentProvider.getInstance().getElements(inputElement); + } + + @Override + public Object[] getChildren(Object parentElement) { + DomainMockup mockup = (DomainMockup) parentElement; + return mockup.getChildren(); + } + + @Override + public Object getParent(Object element) { + return null; + } + + @Override + public boolean hasChildren(Object element) { + DomainMockup mockup = (DomainMockup) element; + return mockup.getChildren().length > 0; + } + +} diff --git a/bundles/flintstones.entity.domain.ui.provider/src/flintstones/entity/domain/ui/provider/DomainMockupLabelProvider.java b/bundles/flintstones.entity.domain.ui.provider/src/flintstones/entity/domain/ui/provider/DomainMockupLabelProvider.java new file mode 100644 index 0000000..174f81b --- /dev/null +++ b/bundles/flintstones.entity.domain.ui.provider/src/flintstones/entity/domain/ui/provider/DomainMockupLabelProvider.java @@ -0,0 +1,51 @@ +package flintstones.entity.domain.ui.provider; + +import javax.inject.Inject; + +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.domain.DomainMockup; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.ui.service.UiService; + +/** + * @author Sinbad2 + * + */ +public class DomainMockupLabelProvider extends LabelProvider implements IStyledLabelProvider { + + + @Inject + IDomainService domainService; + + /** + * Constructs a FileTreeLabelProvider + */ + public DomainMockupLabelProvider() { + } + + @Override + public StyledString getStyledText(Object element) { + + if (element instanceof DomainMockup) { + DomainMockup e = (DomainMockup) element; + return new StyledString(e.getName()); + } + + return new StyledString(element.toString()); + } + + @Override + public Image getImage(Object element) { + + DomainMockup e = (DomainMockup) element; + String path = e.getImage(); + return UiService.getIcon(path).createImage(); + } + + + +} diff --git a/bundles/flintstones.entity.domain.ui/.classpath b/bundles/flintstones.entity.domain.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.domain.ui/.polyglot.META-INF b/bundles/flintstones.entity.domain.ui/.polyglot.META-INF new file mode 100644 index 0000000..26ae5dd --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.domain.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.entity.domain.ui/.project b/bundles/flintstones.entity.domain.ui/.project new file mode 100644 index 0000000..721a499 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.domain.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362562 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.domain.ui/META-INF/MANIFEST.MF b/bundles/flintstones.entity.domain.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2b433e6 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.entity.domain.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.domain.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.extensionenum, + flintstones.helper.extensionpoint, + flintstones.model.domain.ui.service, + org.eclipse.e4.core.services, + org.eclipse.jface, + flintstones.helper.ui, + flintstones.entity.domain +Export-Package: flintstones.entity.domain.ui +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.entity.domain.ui/build.properties b/bundles/flintstones.entity.domain.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.domain.ui/plugin.xml b/bundles/flintstones.entity.domain.ui/plugin.xml new file mode 100644 index 0000000..46932da --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.entity.domain.ui/schema/chart.exsd b/bundles/flintstones.entity.domain.ui/schema/chart.exsd new file mode 100644 index 0000000..7211cb4 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/schema/chart.exsd @@ -0,0 +1,127 @@ + + + + + + + + + Este punto de agregación permite definir los gráficos que se usarán con los dominios definidos en el punto de extensión de dominio. + +Por herencia de FS3 también hay que definir un icono que representará al dominio en las interfaces gráficas. + +============================================================================================================================================== + +This aggregation point allows you to define the graphics to be used with the domains defined in the domain extension point. + +By inheritance of FS3 you must also define an icon that will represent the domain in the graphical interfaces. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.domain.ui/schema/modifydialog.exsd b/bundles/flintstones.entity.domain.ui/schema/modifydialog.exsd new file mode 100644 index 0000000..8692749 --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/schema/modifydialog.exsd @@ -0,0 +1,133 @@ + + + + + + + + + Este punto de extensión permite definir el dialogo que se muestra al modificar un dominio del tipo que se concrete. + +============================================================================================================================================== + +This extension point allows you to define the dialog shown when modifying a domain of the type to be specified. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.domain.ui/schema/newdialog.exsd b/bundles/flintstones.entity.domain.ui/schema/newdialog.exsd new file mode 100644 index 0000000..6d8084c --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/schema/newdialog.exsd @@ -0,0 +1,141 @@ + + + + + + + + + Este punto de extensión permite definir el dialogo que se muestra al crear un nuevo dominio del tipo que se concrete. + +Es posible asignar varios dialogo a un mismo tipo de dominio, cuando se seleccione el dominio para crearlo se preguntará al usuario mediante un dialogo intermedio, cual de los diálogos debe lanzarse. En el dialogo el usuario seleccionará entre las distintas interfaces, para distinguirlas se mostrará al usuario el campo descripción de las mismas. + +De esta forma se puede crear un dominio usando diferentes interfaces gráficas. + +============================================================================================================================================== + +This extension point allows you to define the dialog shown when creating a new domain of the type to be specified. + +It is possible to assign several dialogs to the same type of domain, when the domain is selected to create it, the user will be asked by means of an intermediate dialog, which of the dialogs should be launched. In the dialog the user will select between the different interfaces, to distinguish them the user will be shown the description of them. + +This way you can create a domain using different graphical interfaces. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.domain.ui/src/flintstones/entity/domain/ui/DomainUI.java b/bundles/flintstones.entity.domain.ui/src/flintstones/entity/domain/ui/DomainUI.java new file mode 100644 index 0000000..cd9269f --- /dev/null +++ b/bundles/flintstones.entity.domain.ui/src/flintstones/entity/domain/ui/DomainUI.java @@ -0,0 +1,38 @@ +package flintstones.entity.domain.ui; + +import flintstones.entity.extensionenum.ExtensionEnum; + +/** + * The Class DomainUI. + */ +public class DomainUI { + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + /** The id. */ + uid, + /** The domain description. */ + description, + /** The associated domain. */ + domain, + /** The icon. */ // TODO: Igual debería estar en la definición de dominio + icon, + /** The associated chart. */ + chart + }; + + /** + * The Enum Types. + */ + public static enum Types implements ExtensionEnum { + + /** The chart. */ + chart, + /** The newdialog. */ + newdialog, + /** The modifydialog. */ + modifydialog + }; +} diff --git a/bundles/flintstones.entity.domain/.classpath b/bundles/flintstones.entity.domain/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.domain/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.domain/.polyglot.META-INF b/bundles/flintstones.entity.domain/.polyglot.META-INF new file mode 100644 index 0000000..5397002 --- /dev/null +++ b/bundles/flintstones.entity.domain/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.domain + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Domain + diff --git a/bundles/flintstones.entity.domain/.project b/bundles/flintstones.entity.domain/.project new file mode 100644 index 0000000..0265701 --- /dev/null +++ b/bundles/flintstones.entity.domain/.project @@ -0,0 +1,50 @@ + + + flintstones.entity.domain + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362561 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.domain/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.domain/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.domain/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.domain/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.domain/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.domain/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.domain/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.domain/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.domain/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.domain/META-INF/MANIFEST.MF b/bundles/flintstones.entity.domain/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b486efb --- /dev/null +++ b/bundles/flintstones.entity.domain/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Domain +Bundle-SymbolicName: flintstones.entity.domain;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.domain +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.helper.data.wxml, + org.apache.commons.lang, + flintstones.entity.common;visibility:=reexport, + flintstones.entity.extensionenum, + flintstones.model.ui.service +Export-Package: flintstones.entity.domain, + flintstones.entity.domain.messages diff --git a/bundles/flintstones.entity.domain/build.properties b/bundles/flintstones.entity.domain/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.entity.domain/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.domain/plugin.xml b/bundles/flintstones.entity.domain/plugin.xml new file mode 100644 index 0000000..38fe622 --- /dev/null +++ b/bundles/flintstones.entity.domain/plugin.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.domain_category.exsd b/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.domain_category.exsd new file mode 100644 index 0000000..68cc6d8 --- /dev/null +++ b/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.domain_category.exsd @@ -0,0 +1,109 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.exsd b/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.exsd new file mode 100644 index 0000000..561a10b --- /dev/null +++ b/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.exsd @@ -0,0 +1,131 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.fastadd.exsd b/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.fastadd.exsd new file mode 100644 index 0000000..64a6244 --- /dev/null +++ b/bundles/flintstones.entity.domain/schema/flintstones.entity.domain.fastadd.exsd @@ -0,0 +1,129 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.domain/src/flintstones/entity/domain/Domain.java b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/Domain.java new file mode 100644 index 0000000..560a4a5 --- /dev/null +++ b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/Domain.java @@ -0,0 +1,208 @@ +/* + * + */ +package flintstones.entity.domain; + +import flintstones.entity.common.interfaces.IdentifiedEntity; +import flintstones.entity.common.interfaces.TypedEntity; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.data.wxml.WNode; + +import java.util.UUID; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +/** + * The Domain Class. + */ +public abstract class Domain implements Cloneable, Comparable, IdentifiedEntity, TypedEntity { + + /** The domain name. */ + private String name = null; // Must be null + + /** The Constant EXTENSION_POINT. */ + public static final String EXTENSION_POINT = "flintstones.entity.domain"; //$NON-NLS-1$ + public static final String EXTENSION_POINT_CATEGORY="flintstones.entity.domain.domain_category"; + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + /** The Domain. */ + Domain, + /** The id. */ + uid, + /** The name. */ + name, + /** The type. */ + category, + + label, + + /** The implementation. */ + implementation, + /** The type. */ + type // is now label? + }; + + /** + * Instantiates a new domain. + */ + public Domain() { + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(final String name) { + this.name = name; + } + + /** + * Midpoint. + * + * @return the midpoint + */ + public abstract double midpoint(); + + /** + * Format description domain. + * + * @return the string + */ + public abstract String formatDescriptionDomain(); + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final HashCodeBuilder hcb = new HashCodeBuilder(17, 31); + hcb.append(this.name); + hcb.append(this.type); + return hcb.toHashCode(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) + return true; + + if (obj == null) + return false; + + if (obj.getClass() != this.getClass()) + return false; + + final Domain other = (Domain) obj; + + final EqualsBuilder eb = new EqualsBuilder(); + eb.append(this.name, other.name); + eb.append(this.type, other.type); + + return eb.isEquals(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#clone() + */ + @Override + public Object clone() { + Domain result = null; + + try { + result = (Domain) super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(Domain domain) { + + if (this.name == null) + return -1; + + return this.name.compareTo(domain.getName()); + } + + /** + * Write. + * + * @param writer the writer + * @throws XMLStreamException the XML stream exception + */ + public abstract void write(XMLStreamWriter writer) throws XMLStreamException; + + /** + * Read. + * + * @param node the node + */ + public abstract void read(WNode node); + + + /* IdentifiedEntity implementation */ + private String serviceId = null; + + @Override + public final String getId() { + return serviceId; + }; + + @Override + public final void updateId() { + serviceId = calculateId(); + } + + @Override + public final String calculateId() { + return UUID.randomUUID().toString(); + } + + /* TypedEntity implementation */ + private String type; + + @Override + public String getType() { + return this.type; + } + + @Override + public void setType(String type) { + this.type = type; + } + +} diff --git a/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainInstance.java b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainInstance.java new file mode 100644 index 0000000..6f81a78 --- /dev/null +++ b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainInstance.java @@ -0,0 +1,22 @@ +package flintstones.entity.domain; + +public abstract class DomainInstance { + + private String type; + private String label; + private Domain domain; + + public String getType() {return type; } + + public void setType(String type) {this.type = type;} + + public String getLabel() {return label; } + + public void setLabel(String label) {this.label = label;} + + public void setCleanDomain(Domain d) {domain = d;} + + protected Domain getDomain() { return domain;} + + public abstract Domain getInstance(); +} diff --git a/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainInstanceMockup.java b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainInstanceMockup.java new file mode 100644 index 0000000..961a733 --- /dev/null +++ b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainInstanceMockup.java @@ -0,0 +1,35 @@ +package flintstones.entity.domain; + +public class DomainInstanceMockup extends DomainMockup { + + private String fastId; + + public DomainInstanceMockup(String category) { + super(category); + } + + public DomainInstanceMockup(String fastId, String id, String label, String category) { + super(id, label, category); + this.fastId = fastId; + } + + @Override + public String getImage() { + if(id == null) + return domains.get(0).getImage(); + + return "domain/" + id + ".png"; + } + + @Override + public String getId() { + return category; + } + + @Override + public String getCategory() { + return id; + } + + public String getFastId() {return fastId; } +} diff --git a/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainMockup.java b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainMockup.java new file mode 100644 index 0000000..95b00e1 --- /dev/null +++ b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/DomainMockup.java @@ -0,0 +1,61 @@ +package flintstones.entity.domain; + +import java.text.MessageFormat; +import java.util.ArrayList; + +public class DomainMockup { + + protected String id; + protected String label; + protected String category; + + ArrayList domains = new ArrayList<>(); + + public DomainMockup(String category) { + this.category = category; + } + + public void addDomain(DomainMockup domain) { + domains.add(domain); + } + + public DomainMockup[] getChildren() { + + if(label != null || id != null) + return new DomainMockup[0]; + + return domains.toArray(new DomainMockup[0]); + } + + public DomainMockup(String id, String label, String category) { + this.id = id; + this.label = label; + this.category = category; + } + + public String getName() { + return id != null ? label : category; + } + + public String getId() { + return id; + } + + public String getCategory() { + return category; + } + + + public String getImage() { + if(id == null) + return domains.get(0).getImage(); + + return "domain/" + id + ".png"; + } + + @Override + public String toString() { + String template = "[{0}] {1} {2}"; + return MessageFormat.format(template, category, label, id); + } +} diff --git a/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/Messages.java b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/Messages.java new file mode 100644 index 0000000..e7f232f --- /dev/null +++ b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/Messages.java @@ -0,0 +1,15 @@ +// This file has been auto-generated +package flintstones.entity.domain.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Domain_entity; + public String Domain_entities; + public String Domain_count; + public String Domain_type_entities; + +} diff --git a/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/messages.properties b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/messages.properties new file mode 100644 index 0000000..2d3e353 --- /dev/null +++ b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/messages.properties @@ -0,0 +1,5 @@ +Domain_entity=Domain +Domain_entities=Domains +Domain_count=The number of domains +Domain_type_entities=The domains of type +Domain_type=The type of domain \ No newline at end of file diff --git a/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/messages_es.properties b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/messages_es.properties new file mode 100644 index 0000000..39cca99 --- /dev/null +++ b/bundles/flintstones.entity.domain/src/flintstones/entity/domain/messages/messages_es.properties @@ -0,0 +1,5 @@ +Domain_entity=Dominio +Domain_entities=Dominios +Domain_count=El nmero de dominios +Domain_type_entities=Los dominios de tipo +Domain_type=El tipo de dominio \ No newline at end of file diff --git a/bundles/flintstones.entity.extensionenum/.classpath b/bundles/flintstones.entity.extensionenum/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.extensionenum/.polyglot.META-INF b/bundles/flintstones.entity.extensionenum/.polyglot.META-INF new file mode 100644 index 0000000..f3d4d92 --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.extensionenum + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Extensionenum + diff --git a/bundles/flintstones.entity.extensionenum/.project b/bundles/flintstones.entity.extensionenum/.project new file mode 100644 index 0000000..b41b818 --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.extensionenum + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362565 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.extensionenum/META-INF/MANIFEST.MF b/bundles/flintstones.entity.extensionenum/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8bb31e2 --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Extensionenum +Bundle-SymbolicName: flintstones.entity.extensionenum +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.extensionenum +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.extensionenum diff --git a/bundles/flintstones.entity.extensionenum/build.properties b/bundles/flintstones.entity.extensionenum/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.extensionenum/src/flintstones/entity/extensionenum/ExtensionEnum.java b/bundles/flintstones.entity.extensionenum/src/flintstones/entity/extensionenum/ExtensionEnum.java new file mode 100644 index 0000000..130c68c --- /dev/null +++ b/bundles/flintstones.entity.extensionenum/src/flintstones/entity/extensionenum/ExtensionEnum.java @@ -0,0 +1,12 @@ +package flintstones.entity.extensionenum; + +/** + * @author UJA + * Used in Fields enum attribute like: + * public static enum Fields implements ExtensionEnum + * Let the attributes of Field to be passed to functions as ExtensionEnum objects + */ +// +public interface ExtensionEnum { + +} diff --git a/bundles/flintstones.entity.method.phase.ui/.classpath b/bundles/flintstones.entity.method.phase.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.method.phase.ui/.polyglot.META-INF b/bundles/flintstones.entity.method.phase.ui/.polyglot.META-INF new file mode 100644 index 0000000..16fb913 --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.method.phase.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.entity.method.phase.ui/.project b/bundles/flintstones.entity.method.phase.ui/.project new file mode 100644 index 0000000..166551f --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.method.phase.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362567 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.method.phase.ui/META-INF/MANIFEST.MF b/bundles/flintstones.entity.method.phase.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9ee8b8f --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.entity.method.phase.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.method.phase.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase;visibility:=reexport, + flintstones.entity.extensionenum, + flintstones.application.constants, + flintstones.helper.debug, + org.eclipse.e4.core.services, + javax.inject, + org.eclipse.swt;visibility:=reexport +Export-Package: flintstones.entity.method.phase.ui diff --git a/bundles/flintstones.entity.method.phase.ui/build.properties b/bundles/flintstones.entity.method.phase.ui/build.properties new file mode 100644 index 0000000..3595411 --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + schema/ diff --git a/bundles/flintstones.entity.method.phase.ui/plugin.xml b/bundles/flintstones.entity.method.phase.ui/plugin.xml new file mode 100644 index 0000000..add7369 --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/plugin.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/bundles/flintstones.entity.method.phase.ui/schema/methodphaseui.exsd b/bundles/flintstones.entity.method.phase.ui/schema/methodphaseui.exsd new file mode 100644 index 0000000..94450ae --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/schema/methodphaseui.exsd @@ -0,0 +1,123 @@ + + + + + + + + + Este punto de extensión nos permite definir la interfaz gráfica asociadas a una fase de metodo. + +============================================================================================================================================== + +This extension point allows us to define the graphical interface associated with a method phase. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.method.phase.ui/src/flintstones/entity/method/phase/ui/PhaseMethodUI.java b/bundles/flintstones.entity.method.phase.ui/src/flintstones/entity/method/phase/ui/PhaseMethodUI.java new file mode 100644 index 0000000..3bcedfc --- /dev/null +++ b/bundles/flintstones.entity.method.phase.ui/src/flintstones/entity/method/phase/ui/PhaseMethodUI.java @@ -0,0 +1,206 @@ +package flintstones.entity.method.phase.ui; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.swt.widgets.Composite; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.helper.debug.DH; + +/** + * The Class PhaseMethodUI. + */ +public abstract class PhaseMethodUI { + + @Inject + IEventBroker broker; + + /** The model. */ + private PhaseMethod model; + + /** The base composite. */ + protected Composite baseComposite; + + /** The Constant EXTENSION_POINT. */ + public final static String EXTENSION_POINT = "flintstones.phasemethod.ui"; //$NON-NLS-1$ + + /** The Constant REFRESH_BUS_ID. */ + protected final static String REFRESH_BUS_ID = "TOPIC_RATING/CONTAINER/REFRESH"; //$NON-NLS-1$ + + /* Debug refresh -> Changes on model then refresh the ui suscribing to this sub */ + public final static String REFRESH_SUB_ID = "TOPIC_RATING/PHASEMETHODUI/REFRESH"; //$NON-NLS-1$ + + // DEBUG + long lastTime = 0; + + /** + * The Enum Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The id. */ + uid, + /** The name. */ + name, + /** The ui. */ + ui, + /** The phasemethod. */ + phasemethod, + /** The view. */ + view, + /** The step. */ + step; + } + + + // NEW + public static enum Status implements ExtensionEnum { + Unloaded, Loaded, ActiveReloaded, Active + } + + private Status status = Status.Unloaded; + + public Status getStatus() { + return status; + } + + // 1.INIT + /** + * This will be called on every phase when drawing it before calling concrete init. + * @param base Composite to draw + */ + public void preInit(Composite base) { + this.baseComposite = base; + lastTime = System.currentTimeMillis(); + } + + public void postInit() { + status = Status.Active; + long currentTime = System.currentTimeMillis(); + DH.out("router","Fase " + model.getName() + " cargada en " + (currentTime - lastTime) + " ms. "); + lastTime = 0; + } + + /** + * Common refresh. + * + * @param parent the parent + */ + public void preRefresh() { + + lastTime = System.currentTimeMillis(); + } + + public void postRefresh() { + status = Status.ActiveReloaded; + + long currentTime = System.currentTimeMillis(); + DH.out("router", "Fase " + model.getName() + " refrescada en " + (currentTime - lastTime) + " ms. "); + lastTime = 0; + } + + public void exit() { + status = Status.Loaded; + } + + /** + * Entrypoint when drawing. + */ + public abstract void init(); + + // Iniciar y cargar los datos de fases anteriores y de la fase actual desde + // phasemethodui? + /** + * Refresh. + */ + // Redibujar usando model. llamar a model.refresh? + public abstract void refresh(); + + /** + * Can the user open the next phase?. + * + * @return true if the user can go to the next phase + */ + // 2. CONTROL + protected abstract boolean isForwardEnabled(); + + /** + * Can the user open the previous phase?. + * + * @return true if the user can go to the previous phase + */ + public boolean isBackwardEnabled() { + return true; + }; + + public boolean isSkippable() { + return false; + } + + public void beforeSkip() { + } + + /** + * Gets the phase name. + * + * @return the phase name + */ + // 3. UI TEXT + public String getPhaseName() { + return this.model.getName(); + } + + /** + * Gets the position. + * + * @return The number of the phase + */ + public int getPosition() { + return this.model.getPosition(); + } + + /** + * Gets the model. + * + * @return The phase model + */ + public PhaseMethod getModel() { + return this.model; + } + + /** + * Sets the model. + * + * @param model The data model + */ + public void setModel(PhaseMethod model) { + this.model = model; + } + + /** + * Gets the base composite. + * + * @return the base composite + */ + // 4.Debug + public Composite getBaseComposite() { + return this.baseComposite; + } + + protected void sendRefresh() { + this.broker.send(PhaseMethodUI.REFRESH_BUS_ID, null); + this.broker.send(FrameworkConstants.TOPIC_METHOD_PHASE_REFRESH, null); + } + + public boolean isPhaseCompleted() { + if(status == Status.Unloaded) + return false; + return this.isForwardEnabled(); + } + + + +} \ No newline at end of file diff --git a/bundles/flintstones.entity.method.phase/.classpath b/bundles/flintstones.entity.method.phase/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.method.phase/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.method.phase/.polyglot.META-INF b/bundles/flintstones.entity.method.phase/.polyglot.META-INF new file mode 100644 index 0000000..a011ef8 --- /dev/null +++ b/bundles/flintstones.entity.method.phase/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.method.phase + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Phase + diff --git a/bundles/flintstones.entity.method.phase/.project b/bundles/flintstones.entity.method.phase/.project new file mode 100644 index 0000000..5267756 --- /dev/null +++ b/bundles/flintstones.entity.method.phase/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.method.phase + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362566 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.method.phase/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.method.phase/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.method.phase/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.method.phase/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.method.phase/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.method.phase/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.method.phase/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.method.phase/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.method.phase/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.method.phase/META-INF/MANIFEST.MF b/bundles/flintstones.entity.method.phase/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1fd2b0b --- /dev/null +++ b/bundles/flintstones.entity.method.phase/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Phase +Bundle-SymbolicName: flintstones.entity.method.phase;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.method.phase +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.nebula.widgets.opal.breadcrumb, + flintstones.helper.data, + flintstones.entity.extensionenum +Export-Package: flintstones.entity.method.phase diff --git a/bundles/flintstones.entity.method.phase/build.properties b/bundles/flintstones.entity.method.phase/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.entity.method.phase/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.method.phase/plugin.xml b/bundles/flintstones.entity.method.phase/plugin.xml new file mode 100644 index 0000000..e5c9417 --- /dev/null +++ b/bundles/flintstones.entity.method.phase/plugin.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/bundles/flintstones.entity.method.phase/schema/flintstones.phasemethod.exsd b/bundles/flintstones.entity.method.phase/schema/flintstones.phasemethod.exsd new file mode 100644 index 0000000..2818290 --- /dev/null +++ b/bundles/flintstones.entity.method.phase/schema/flintstones.phasemethod.exsd @@ -0,0 +1,113 @@ + + + + + + + + + Este punto de extensión nos permite definir los modelos de fase de un método. + +============================================================================================================================================== + +This extension point allows us to define the phase models of a method. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/ImportedDataNotFoundException.java b/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/ImportedDataNotFoundException.java new file mode 100644 index 0000000..82bc1b0 --- /dev/null +++ b/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/ImportedDataNotFoundException.java @@ -0,0 +1,13 @@ +package flintstones.entity.method.phase; + +public class ImportedDataNotFoundException extends Error { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public ImportedDataNotFoundException(String phase, String[] arr) { + super("Ninguna de las claves encontradas en la fase " + phase + "=> " + String.join(", ", arr)); + } +} diff --git a/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/PhaseMethod.java b/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/PhaseMethod.java new file mode 100644 index 0000000..8273cfb --- /dev/null +++ b/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/PhaseMethod.java @@ -0,0 +1,192 @@ +package flintstones.entity.method.phase; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.data.text.ClassToString; + +/** + * The Class PhaseMethod. + */ +public abstract class PhaseMethod { + + /** The id. */ + private String id; + + /** The position. */ + private int position; + + private PhaseMethod previousPhase; + + private HashMap methodData = new HashMap<>(); + private HashMap exportedData = new HashMap<>(); + private HashMap carryOverData = new HashMap<>(); + + /** + * The Enum Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The id. */ + uid, + /** The name. */ + name, + /** The implementation. */ + implementation, + /** The description. */ + description; + } + + /** The Constant EXTENSION_POINT. */ + public static final String EXTENSION_POINT = "flintstones.phasemethod.extensionpoint"; //$NON-NLS-1$ + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the id. + * + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the name. + * + * @return the name + */ + public abstract String getName(); + + public String getInfo() { + return ""; + } + + /** + * Gets the position. + * + * @return the position + */ + public int getPosition() { + return this.position; + } + + /** + * Sets the position. + * + * @param position the new position + */ + public void setPosition(int position) { + this.position = position; + } + + protected void exportData(String key, Object value, boolean carryOver ) { + exportedData.put(key, value); + if(carryOver) + carryOverData.put(key, value); + } + + protected void exportData(String key, Object value) { + exportData(key, value, false); + } + + + protected void deleteData(String key) { + exportedData.remove(key); + } + + public Object getExportedData(String key) { + return exportedData.get(key); + } + + public String getExportedSummary() { + + ArrayList lines = new ArrayList<>(); + for(Entry entry : exportedData.entrySet()) { + String key = entry.getKey(); + String value = ClassToString.getClassAsString(entry.getValue()); + String line = key + " => " + value; + lines.add(line); + + } + + return lines.stream().collect(Collectors.joining("\n")); + + } + + public String[] getExportedKeys( boolean onlyCarried ) { + if(onlyCarried) + return carryOverData.keySet().toArray(new String[0]); + return exportedData.keySet().toArray(new String[0]); + } + + public Object importData(String... keys) { + + if(previousPhase == null) + return null; + + for(String key : keys) { + Object item = previousPhase.getExportedData(key); + if(item != null) + return item; + } + + throw new ImportedDataNotFoundException(previousPhase.getName(), keys); + + } + + public Object importDataFromMethod(String ...keys) { + + for(String key : keys) { + Object item = methodData.get(key); + if(item != null) + return item; + } + + return null; + + } + + public void carryData() { + + if(previousPhase == null) + return ; + + String[] keys = previousPhase.getExportedKeys(true); + + for(String key : keys) { + Object item = previousPhase.getExportedData(key); + exportData(key, item, true); + } + + } + + public void setPreviousPhase(PhaseMethod phase) { + this.previousPhase = phase; + this.carryData(); + } + + public void setMethodData(HashMap methodData) { + this.methodData = methodData; + } + + public PhaseMethod getPreviousPhase() { + return previousPhase; + } + + public boolean canBeExecuted() { + return true; + } + + +} \ No newline at end of file diff --git a/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/PhaseNotFoundException.java b/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/PhaseNotFoundException.java new file mode 100644 index 0000000..c5c866e --- /dev/null +++ b/bundles/flintstones.entity.method.phase/src/flintstones/entity/method/phase/PhaseNotFoundException.java @@ -0,0 +1,19 @@ +package flintstones.entity.method.phase; + +/** + * The Class PhaseNotFoundException. + */ +public class PhaseNotFoundException extends RuntimeException { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 1L; + + /** + * Instantiates a new phase not found exception. + * + * @param phaseNumber the phase number + */ + public PhaseNotFoundException(int phaseNumber) { + super("\n Fase no encontrada en la posición " + phaseNumber + " durante la llamada a import(...)"); + } +} diff --git a/bundles/flintstones.entity.method.phasepage/.classpath b/bundles/flintstones.entity.method.phasepage/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.method.phasepage/.polyglot.META-INF b/bundles/flintstones.entity.method.phasepage/.polyglot.META-INF new file mode 100644 index 0000000..c483e6e --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.method.phasepage + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Phasepage + diff --git a/bundles/flintstones.entity.method.phasepage/.project b/bundles/flintstones.entity.method.phasepage/.project new file mode 100644 index 0000000..c2f6fa7 --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.method.phasepage + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362568 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.method.phasepage/META-INF/MANIFEST.MF b/bundles/flintstones.entity.method.phasepage/META-INF/MANIFEST.MF new file mode 100644 index 0000000..08e1758 --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Phasepage +Bundle-SymbolicName: flintstones.entity.method.phasepage +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.method.phasepage +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.nebula.widgets.opal.breadcrumb, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui +Export-Package: flintstones.entity.method.phasepage diff --git a/bundles/flintstones.entity.method.phasepage/build.properties b/bundles/flintstones.entity.method.phasepage/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.method.phasepage/src/flintstones/entity/method/phasepage/PhasePage.java b/bundles/flintstones.entity.method.phasepage/src/flintstones/entity/method/phasepage/PhasePage.java new file mode 100644 index 0000000..5c4141f --- /dev/null +++ b/bundles/flintstones.entity.method.phasepage/src/flintstones/entity/method/phasepage/PhasePage.java @@ -0,0 +1,191 @@ +package flintstones.entity.method.phasepage; + +import org.eclipse.nebula.widgets.opal.breadcrumb.BreadcrumbItem; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.method.phase.ui.PhaseMethodUI.Status; + +/** + * The Class PhasePage. + */ +public class PhasePage { + + /** The base. */ + private Composite base; + + /** The menu item. */ + private BreadcrumbItem menuItem; + + /** The ui. */ + private PhaseMethodUI ui; + + /** The breadcrumb listener. */ + SelectionAdapter breadcrumbListener; + + /** + * Instantiates a new phase page. + * + * @param base the base + * @param ui the ui + * @param menuItem the menu item + */ + public PhasePage(Composite base, PhaseMethodUI ui, BreadcrumbItem menuItem) { + this.base = base; + this.menuItem = menuItem; + this.ui = ui; + } + + /** + * Gets the ui. + * + * @return the ui + */ + public PhaseMethodUI getUI() { + return ui; + } + + /** + * Gets the container. + * + * @return the container + */ + public Composite getContainer() { + return base; + } + + /** + * Gets the breadcrumb item. + * + * @return the item + */ + public BreadcrumbItem getItem() { + return menuItem; + } + + /** + * Selected the page. + */ + public void selected() { + this.menuItem.setSelection(true); + } + + /** + * Unselected the page. + */ + public void unselected() { + this.menuItem.setSelection(false); + } + + /** + * Enable the page. + */ + public void enable() { + this.menuItem.setEnabled(true); + } + + /** + * Disable the page. + */ + public void disable() { + this.menuItem.setEnabled(false); + } + + /** + * Load the page. + * + * @return true, if successful + */ + public boolean load() { + + importData(); + + if( ui.getStatus() == Status.Unloaded) { +// System.err.println("Unloaded, init"); + init(); + } else if(ui.getStatus() == Status.Active) { +// System.err.println("Active, do nothing"); + } else if (ui.getStatus() == Status.Loaded) { +// System.err.println("Loaded, do refresh"); + refresh(); + } + + // old compat + return ui.getStatus() == Status.Unloaded; + } + + /** + * Import data from previous phase. + */ + private void importData() { + ui.getModel().carryData(); + } + + /** + * Inits the page. + */ + private void init() { + ui.preInit(base); + ui.init(); + ui.postInit(); + } + + /** + * Refresh the page. + */ + private void refresh() { + ui.preRefresh(); + ui.refresh(); + ui.postRefresh(); + } + + public void exit() { + ui.exit(); + } + + /** + * Checks if is alredy it loaded. + * + * @return true, if is it loaded + */ + public boolean isItLoaded() { + return ui.getStatus() != Status.Unloaded; + } + + public boolean isItSkippable() { + if( ui.getStatus() == Status.ActiveReloaded ) + return false; + return ui.isSkippable(); + } + + public void skip() { + ui.beforeSkip(); + } + + /** + * Dispose the page. + */ + public void dispose() { + this.menuItem.dispose(); + this.base.dispose(); + } + + /** + * Update listener. + * + * @param newListener the new listener + */ + public void updateListener(SelectionAdapter newListener) { + if(this.breadcrumbListener != null) + this.menuItem.removeSelectionListener( this.breadcrumbListener ); + + this.breadcrumbListener = newListener; + this.menuItem.addSelectionListener(newListener); + } + + public void update(boolean isSelected, boolean isEnabled) { + this.menuItem.setEnabled( isEnabled ); + this.menuItem.setSelection( isSelected ); + } +} diff --git a/bundles/flintstones.entity.method/.classpath b/bundles/flintstones.entity.method/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.method/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.method/.polyglot.META-INF b/bundles/flintstones.entity.method/.polyglot.META-INF new file mode 100644 index 0000000..8a25bcb --- /dev/null +++ b/bundles/flintstones.entity.method/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.method + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Method + diff --git a/bundles/flintstones.entity.method/.project b/bundles/flintstones.entity.method/.project new file mode 100644 index 0000000..7a450f8 --- /dev/null +++ b/bundles/flintstones.entity.method/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.method + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362566 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.method/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.method/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.method/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.method/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.method/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.method/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.method/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.method/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.method/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.method/META-INF/MANIFEST.MF b/bundles/flintstones.entity.method/META-INF/MANIFEST.MF new file mode 100644 index 0000000..90b69b6 --- /dev/null +++ b/bundles/flintstones.entity.method/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.entity.method;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.method +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.extensionenum, + flintstones.helper.chainvalidator;visibility:=reexport, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui, + javax.inject;visibility:=reexport, + org.eclipse.e4.core.services;visibility:=reexport, + org.eclipse.e4.core.di;visibility:=reexport +Export-Package: flintstones.entity.method diff --git a/bundles/flintstones.entity.method/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.entity.method/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..6e49a5b --- /dev/null +++ b/bundles/flintstones.entity.method/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,11 @@ +#Properties file for flintstones.entity.method +extension-point.name = Method +extension-point.name.0 = Method category extension point +Bundle-Name = Method +flintstones.entity.method.twotuple.category = 2-tuple linguistic framework +flintstones.entity.method.hesitant.category = Hesitant fuzzy linguistic framework +flintstones.entity.method.multigranular.category = Multi-granular framework +flintstones.entity.method.multicriteria.category = Multi-criteria decision analysis framework +flintstones.entity.method.heterogeneous.category = Heterogeneous framework +flintstones.entity.method.unbalanced.category = Unbalanced linguistic framework +flintstones.entity.method.sorting.category = Multi-criteria sorting framework \ No newline at end of file diff --git a/bundles/flintstones.entity.method/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.entity.method/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..5792530 --- /dev/null +++ b/bundles/flintstones.entity.method/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,11 @@ +#Properties file for flintstones.entity.method +extension-point.name = Method +extension-point.name.0 = Method category extension point +Bundle-Name = Method +flintstones.entity.method.twotuple.category = Marco lingstico 2-tuplas +flintstones.entity.method.hesitant.category = Marco lingstico difuso dudoso +flintstones.entity.method.multigranular.category = Marco lingstico multigranular +flintstones.entity.method.multicriteria.category = Marco multicriterio de anlisis de decisin +flintstones.entity.method.heterogeneous.category = Marco heterogneo +flintstones.entity.method.unbalanced.category = Marco lingstico no balanceado +flintstones.entity.method.sorting.category = Marco multicriterio de clasificacin \ No newline at end of file diff --git a/bundles/flintstones.entity.method/build.properties b/bundles/flintstones.entity.method/build.properties new file mode 100644 index 0000000..19ce185 --- /dev/null +++ b/bundles/flintstones.entity.method/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + schema/,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.entity.method/plugin.xml b/bundles/flintstones.entity.method/plugin.xml new file mode 100644 index 0000000..5043b5d --- /dev/null +++ b/bundles/flintstones.entity.method/plugin.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.method/schema/flintstones.method.category.exsd b/bundles/flintstones.entity.method/schema/flintstones.method.category.exsd new file mode 100644 index 0000000..8f46c8e --- /dev/null +++ b/bundles/flintstones.entity.method/schema/flintstones.method.category.exsd @@ -0,0 +1,109 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.method/schema/flintstones.method.exsd b/bundles/flintstones.entity.method/schema/flintstones.method.exsd new file mode 100644 index 0000000..7aca277 --- /dev/null +++ b/bundles/flintstones.entity.method/schema/flintstones.method.exsd @@ -0,0 +1,138 @@ + + + + + + + + + Este punto de extensión nos permitirá definir nuevos métodos, indicando los dominios soportados por el método, las fases del método y las pre-condiciones que se indicarán para que el método pueda ejecutarse o no con la información del proyecto, indicadas en la implementación que se da. + +============================================================================================================================================== + +This extension point will allow us to define new methods, indicating the domains supported by the method, the phases of the method and the preconditions that will be indicated so that the method can be executed or not with the project information, indicated in the implementation that is given. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.method/src/flintstones/entity/method/Method.java b/bundles/flintstones.entity.method/src/flintstones/entity/method/Method.java new file mode 100644 index 0000000..c7276c6 --- /dev/null +++ b/bundles/flintstones.entity.method/src/flintstones/entity/method/Method.java @@ -0,0 +1,186 @@ +package flintstones.entity.method; + +import java.util.ArrayList; +import java.util.HashMap; + +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.chainvalidator.Statement; + +/** + * The Class Method. + */ +public abstract class Method { + + /** The id. */ + private String id; + + /** The name. */ + private String name; + + /** The category. */ + private String category; + + /** The phaseModels. */ + private ArrayList phaseModels = new ArrayList<>(); + private PhaseMethodUI[] phases; + + public final static String TYPE_OF_VALUATION = "finalValuationId"; + + /** The Constant EXTENSION_POINT. */ + public final static String EXTENSION_POINT = "flintstones.method.extension"; //$NON-NLS-1$ + + /** The Constant CATEGORY EXTENSION_POINT. */ + public final static String EXTENSION_POINT_CATEGORY = "flintstones.method.category.extension"; //$NON-NLS-1$ + + /** + * The Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The id. */ + uid, + /** The name. */ + name, + /** The phase. */ + phase, + /** The phasemethod. */ + phasemethod, + /** The implementation. */ + implementation, + /** The category. */ + category, + /** The description. */ + description, + /** The aggregation supported. */ + aggregation_supported, + /** The type. */ + type + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the id. + * + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Sets the name + * + * @param the name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets the category. + * + * @return the category + */ + public String getCategory() { + return this.category; + } + + /** + * Sets the category. + * + * @return the category + */ + public void setCategory(String category) { + this.category = category; + } + + /** + * Gets the phaseModels. + * + * @return the phaseModels + */ + public ArrayList getPhaseModels() { + return this.phaseModels; + } + + /** + * Sets the phaseModels. + * + * @param phaseModels the new phaseModels + */ + public void setPhaseModels(ArrayList phases) { + this.phaseModels = phases; + } + + /** + * Can be executed. + * + * @return true, if successful + */ + public abstract boolean canBeExecuted(); + + /** + * Gets the passed execute conditions. + * + * @return the passed execute conditions + */ + public abstract String[] getPassedExecuteConditions(); + + /** + * Gets the failed execute conditions. + * + * @return the failed execute conditions + */ + public abstract String[] getFailedExecuteConditions(); + + /** + * Gets the execution statement. + * + * @return the execution statement + */ + public abstract Statement getExecutionStatement(); + + + /** + * Inits the method. + */ + public abstract void init(); + + public void setPhases(PhaseMethodUI[] phases) { + this.phases = phases; + } + + public PhaseMethodUI[] getPhases() { + return phases; + } + + public HashMap getExportedData(){ + + HashMap data = exportData(); + data.put("methodId", this.getId()); + + return data; + } + + protected abstract HashMap exportData(); +} + diff --git a/bundles/flintstones.entity.operator/.classpath b/bundles/flintstones.entity.operator/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.operator/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.operator/.polyglot.META-INF b/bundles/flintstones.entity.operator/.polyglot.META-INF new file mode 100644 index 0000000..f6d0871 --- /dev/null +++ b/bundles/flintstones.entity.operator/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.operator + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Operator + diff --git a/bundles/flintstones.entity.operator/.project b/bundles/flintstones.entity.operator/.project new file mode 100644 index 0000000..422853a --- /dev/null +++ b/bundles/flintstones.entity.operator/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.operator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362571 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.operator/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.operator/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.operator/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.operator/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.operator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.operator/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.operator/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.operator/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.operator/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.operator/META-INF/MANIFEST.MF b/bundles/flintstones.entity.operator/META-INF/MANIFEST.MF new file mode 100644 index 0000000..14205ef --- /dev/null +++ b/bundles/flintstones.entity.operator/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Operator +Bundle-SymbolicName: flintstones.entity.operator +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.operator +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.operator, + flintstones.entity.operator.interfaces +Require-Bundle: flintstones.entity.extensionenum, + flintstones.entity.valuation, + flintstones.entity.wvaluation, + flintstones.domain.fuzzyset, + flintstones.entity.problemelement, + org.eclipse.jface diff --git a/bundles/flintstones.entity.operator/build.properties b/bundles/flintstones.entity.operator/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.operator/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.operator/src/flintstones/entity/operator/AggregationOperator.java b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/AggregationOperator.java new file mode 100644 index 0000000..db07e78 --- /dev/null +++ b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/AggregationOperator.java @@ -0,0 +1,54 @@ +package flintstones.entity.operator; + +import java.util.List; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.operator.interfaces.IFuzzyWeightedAggregationOperator; +import flintstones.entity.operator.interfaces.IParameterizedOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; +import flintstones.entity.operator.interfaces.IWeightedAggregationOperator; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; + +/** + * The Class AggregationOperator. + */ +public abstract class AggregationOperator extends Operator { + + /** The type. */ + protected String type = "Aggregation"; + + + public Valuation computeAggregation(List valuations, List weights) { + return aggregate(valuations, weights); + } + + public Valuation computeParameterizedAggregation(ProblemElement[] items, List valuations, List weights) { + + ((IParameterizedOperator) this).openDialog(items); + + return aggregate(valuations, weights); + } + + @SuppressWarnings("unchecked") + private Valuation aggregate(List valuations, List weights) { + String valuationId = valuations.get(0).getId(); + Valuation result; + + if ((this instanceof IWeightedAggregationOperator || this instanceof IFuzzyWeightedAggregationOperator) && weights != null) { + + if(weights.get(0) instanceof Double) + result = ((IWeightedAggregationOperator) this).aggregate(valuations, (List) weights); + else + result = ((IFuzzyWeightedAggregationOperator) this).aggregateF(valuations, (List) weights); + + } else + result = ((IUnweightedAggregationOperator) this).aggregate(valuations); + + result.setId(valuationId); + + return result; + + } + +} diff --git a/bundles/flintstones.entity.operator/src/flintstones/entity/operator/NormalizationOperator.java b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/NormalizationOperator.java new file mode 100644 index 0000000..a49b2a6 --- /dev/null +++ b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/NormalizationOperator.java @@ -0,0 +1,12 @@ +package flintstones.entity.operator; + +import java.util.List; + +import flintstones.entity.wvaluation.WValuation; + +public abstract class NormalizationOperator extends Operator { + + protected String type = "Normalization"; + + public abstract WValuation[] normalize(List valuations); +} diff --git a/bundles/flintstones.entity.operator/src/flintstones/entity/operator/Operator.java b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/Operator.java new file mode 100644 index 0000000..a6641af --- /dev/null +++ b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/Operator.java @@ -0,0 +1,86 @@ +package flintstones.entity.operator; + +import flintstones.entity.extensionenum.ExtensionEnum; + +/** + * The Operator Class. + */ +public abstract class Operator { + + /** The id. */ + protected String id; + + /** The name. */ + protected String name; + + /** + * The Class Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The id. */ + uid, + /** The name. */ + name, + /** The parameters. */ + parameters, + /** The implementation. */ + implementation, + /** The weighted. */ + weighted, + /** The unweighted. */ + unweighted, + /** The supported types. */ + supported_types, + /** The type. */ + type, + /** The has attributes. */ + hasAttributes, + /** The aggregation operator. */ + aggregation_operator, + /** The valuation id. */ + valuationId; + } + + /** + * Instantiates a new aggregation operator. + */ + public Operator() { + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the id. + * + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the name. + * + * @return the name + */ + public abstract String getName(); + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + +} diff --git a/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IFuzzyWeightedAggregationOperator.java b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IFuzzyWeightedAggregationOperator.java new file mode 100644 index 0000000..5a8e763 --- /dev/null +++ b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IFuzzyWeightedAggregationOperator.java @@ -0,0 +1,17 @@ +package flintstones.entity.operator.interfaces; + +import java.util.List; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.valuation.Valuation; + +public interface IFuzzyWeightedAggregationOperator { + + /** + * Aggregate a set of valuations into one valuation using weights. + * + * @param valuations the valuations + * @param weights the fuzzy weights + * @return the valuation + */ + public abstract Valuation aggregateF(List valuations, List weights); +} diff --git a/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IParameterizedOperator.java b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IParameterizedOperator.java new file mode 100644 index 0000000..3f0a741 --- /dev/null +++ b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IParameterizedOperator.java @@ -0,0 +1,17 @@ +package flintstones.entity.operator.interfaces; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Interface IParameterizedOperator let you provide a wizard to configure a AggregationOperator. + */ +public interface IParameterizedOperator { + + /** + * Open the dialog. + * @param parentItem The elements to be aggregated and that must be represented in the dialog + * + */ + public abstract void openDialog(ProblemElement[] items); + +} diff --git a/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IUnweightedAggregationOperator.java b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IUnweightedAggregationOperator.java new file mode 100644 index 0000000..94aa638 --- /dev/null +++ b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IUnweightedAggregationOperator.java @@ -0,0 +1,19 @@ +package flintstones.entity.operator.interfaces; + +import java.util.List; + +import flintstones.entity.valuation.Valuation; + +/** + * The Interface IUnweightedOperator is used to define operators that wi. + */ +public interface IUnweightedAggregationOperator { + + /** + * Aggregate a set of valuations into one valuation. + * + * @param valuations the valuations + * @return the valuation + */ + public abstract Valuation aggregate(List valuations); +} diff --git a/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IWeightedAggregationOperator.java b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IWeightedAggregationOperator.java new file mode 100644 index 0000000..e6e8908 --- /dev/null +++ b/bundles/flintstones.entity.operator/src/flintstones/entity/operator/interfaces/IWeightedAggregationOperator.java @@ -0,0 +1,17 @@ +package flintstones.entity.operator.interfaces; + +import java.util.List; + +import flintstones.entity.valuation.Valuation; + +public interface IWeightedAggregationOperator { + + /** + * Aggregate a set of valuations into one valuation using weights. + * + * @param valuations the valuations + * @param weights the weights + * @return the valuation + */ + public abstract Valuation aggregate(List valuations, List weights); +} diff --git a/bundles/flintstones.entity.preferences.preferencecollection/.classpath b/bundles/flintstones.entity.preferences.preferencecollection/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.preferences.preferencecollection/.polyglot.META-INF b/bundles/flintstones.entity.preferences.preferencecollection/.polyglot.META-INF new file mode 100644 index 0000000..7bbe592 --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.preferences.preferencecollection + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Preferencecollection + diff --git a/bundles/flintstones.entity.preferences.preferencecollection/.project b/bundles/flintstones.entity.preferences.preferencecollection/.project new file mode 100644 index 0000000..3a6fa8c --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.preferences.preferencecollection + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362571 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.preferences.preferencecollection/META-INF/MANIFEST.MF b/bundles/flintstones.entity.preferences.preferencecollection/META-INF/MANIFEST.MF new file mode 100644 index 0000000..72c400e --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Preferencecollection +Bundle-SymbolicName: flintstones.entity.preferences.preferencecollection +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.preferences.preferencecollection +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Export-Package: flintstones.entity.preferences.preferencecollection +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.ahppreferences, + flintstones.entity.ahp, + flintstones.entity.extensionenum, + flintstones.entity.domain, + flintstones.helper.data diff --git a/bundles/flintstones.entity.preferences.preferencecollection/build.properties b/bundles/flintstones.entity.preferences.preferencecollection/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.preferences.preferencecollection/src/flintstones/entity/preferences/preferencecollection/PreferenceCollection.java b/bundles/flintstones.entity.preferences.preferencecollection/src/flintstones/entity/preferences/preferencecollection/PreferenceCollection.java new file mode 100644 index 0000000..ad66ec9 --- /dev/null +++ b/bundles/flintstones.entity.preferences.preferencecollection/src/flintstones/entity/preferences/preferencecollection/PreferenceCollection.java @@ -0,0 +1,360 @@ +package flintstones.entity.preferences.preferencecollection; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map.Entry; + +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.ahppreferences.PreferenceCollectionKey; +import flintstones.entity.ahppreferences.PreferenceMatrix; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.HashMatrix; + +/** + * The Class PreferenceCollection. + */ +public class PreferenceCollection { + + /** + * Instantiates a new preference collection. Esta clase almacena conjuntos de + * comparaciones dados 4 tipos. Los 2 primeros tipos, normalmente experto y + * criterio están en los combos. El tercer tipo es el elemento de la izquierda + * de la comparación. El cuarto tipo es el elemento de la derecha de la + * comparación. Los tipos 1,2 no pueden cambiar, aunque pueden ser "genericos". + * Los tipos 3,4 pueden cambiar cuando se cambien el tipo 1 o 2. No pueden ser + * genericos. + * + * Esta clase no almacena matrices AHP, almacena las comparaciones y a partir de + * las comparaciones se sacan AHP o no. + * + * El orden de tipo1, tipo2 en principio no importa y viene determinado por el + * orden los propios elementos de problema. + */ + public PreferenceCollection() { + } + + /** The content. */ + private HashMatrix content = new HashMatrix<>(); + + /** The any build. */ + private PreferenceBuild anyBuild; + + /** The main elements. */ + private HashMap mainElements = new HashMap<>(); + + /** The other elements. */ + private HashMap otherElements = new HashMap<>(); + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + + /** The Preference collections. */ + PreferenceCollections, + /** The Preference collection. */ + PreferenceCollection, + /** The main type. */ + mainType, + /** The other type. */ + otherType, + /** The left type. */ + leftType, + /** The right type. */ + rightType + }; + + /** + * Instantiates a new preference collection. + * + * @param builds the builds + */ + public PreferenceCollection(PreferenceBuild[] builds) { + + anyBuild = builds[0]; + + for (PreferenceBuild build : builds) { + + content.put(build.getMain(), build.getOther(), build); + + mainElements.put(build.getMain().getName(), build.getMain()); + otherElements.put(build.getOther().getName(), build.getOther()); + + } + + } + + /** + * Sets the value. + * + * @param main the main PE (first dropwdown) + * @param other the other PE (second dropdown) + * @param left the left PE (left column) + * @param right the right PE (right column) + * @param index the index + */ + public void set(ProblemElement main, ProblemElement other, ProblemElement left, ProblemElement right, int index) { + + PreferenceMatrix matrix = content.get(main, other).getMatrix(); + matrix.set(left, right, index); + + } + + /** + * Gets the builds the. + * + * @param main the main + * @param other the other + * @return the builds the + */ + public PreferenceBuild getBuild(ProblemElement main, ProblemElement other) { + + return content.get(main, other); + + } + + /** + * Gets the. + * + * @param main the main + * @param other the other + * @return the int[][] + */ + public int[][] get(ProblemElement main, ProblemElement other) { + PreferenceBuild build = getBuild(main, other); + if (build == null) + return null; + + return build.getMatrix().getMatrix(); + } + + /** + * Gets the. + * + * @param main the main + * @param other the other + * @param left the left + * @param right the right + * @return the int + */ + public int get(ProblemElement main, ProblemElement other, ProblemElement left, ProblemElement right) { + PreferenceMatrix matrix = content.get(main, other).getMatrix(); + return matrix.get(left, right); + } + + /** + * Gets the main element. + * + * @param name the name + * @return the main element + */ + public ProblemElement getMainElement(String name) { + return mainElements.get(name); + } + + /** + * Gets the other element. + * + * @param name the name + * @return the other element + */ + public ProblemElement getOtherElement(String name) { + return otherElements.get(name); + } + + /** + * Gets the all main elements. + * + * @return the all main elements + */ + public ProblemElement[] getAllMainElements() { + return mainElements.values().toArray(new ProblemElement[0]); + } + + /** + * Gets the all other elements. + * + * @return the all other elements + */ + public ProblemElement[] getAllOtherElements() { + return otherElements.values().toArray(new ProblemElement[0]); + } + + /** + * Gets the every AHP matrix. + * + * @return the every AHP matrix + */ + // AHP + public AHPMatrix[] getEveryAHPMatrix() { + return getEveryAHPMatrix(anyBuild.getMain()); + } + + /** + * Gets the every AHP matrix. + * + * @param main the main + * @return the every AHP matrix + */ + public AHPMatrix[] getEveryAHPMatrix(ProblemElement main) { + + ProblemElement[] others = getAllOtherElements(); + AHPMatrix[] matrixes = new AHPMatrix[others.length]; + for (int i = 0; i < others.length; i++) { + ProblemElement other = others[i]; + AHPMatrix matrix = getAHPMatrix(main, other); + matrixes[i] = matrix; + } + return matrixes; + + } + + /** + * Gets the every AHP matrix other. + * + * @param other the other + * @return the every AHP matrix other + */ + public AHPMatrix[] getEveryAHPMatrixOther(ProblemElement other) { + + ProblemElement[] mains = getAllMainElements(); + AHPMatrix[] matrixes = new AHPMatrix[mains.length]; + for (int i = 0; i < mains.length; i++) { + ProblemElement main = mains[i]; + AHPMatrix matrix = getAHPMatrix(main, other); + matrixes[i] = matrix; + } + return matrixes; + + } + + /** + * Gets the AHP matrix. + * + * @return the AHP matrix + */ + public AHPMatrix getAHPMatrix() { + + if (mainElements.size() != 1) + throw new RuntimeException( + "mainArr should have exactly one element to use this API. (The generic ProblemElement) "); + + if (otherElements.size() != 1) + throw new RuntimeException( + "otherArr should have exactly one element to use this API. (The generic ProblemElement) "); + + return getAHPMatrix(mainElements.values().iterator().next(), otherElements.values().iterator().next()); + } + + /** + * Gets the AHP matrix. + * + * @param main the main + * @param other the other + * @return the AHP matrix + */ + public AHPMatrix getAHPMatrix(ProblemElement main, ProblemElement other) { + + if (main == null && other == null) + throw new RuntimeException("API abuse"); + + if (main == null) + main = mainElements.values().iterator().next(); + + if (other == null) + other = otherElements.values().iterator().next(); + + PreferenceBuild build = content.get(main, other); + PreferenceMatrix matrix = build.getMatrix(); + if (!build.isAHP()) + throw new RuntimeException( + "AHPMatrix can not be generated if you are not comparing element with the same type "); + + return matrix.getAHPMatrix(); + + } + + /** + * Gets the AHP content for. + * + * @param main the main + * @param other the other + * @return the AHP content for + */ + public AHPMatrix[] getAHPMatrixesFor(ProblemElement main, ProblemElement other) { + + PreferenceBuild build = content.get(main, other); + + LinkedList leftArr = build.getLeftElements(); + LinkedList rightArr = build.getRightElements(); + + ArrayList matrixArr = new ArrayList<>(); + + for (ProblemElement left : leftArr) { + ProblemElement[] all = new ProblemElement[1 + rightArr.size()]; + int i = 0; + + all[i++] = left; + for (ProblemElement right : rightArr) + all[i++] = right; + + AHPMatrix matrix = new AHPMatrix(all); + for (int j = 1; j < all.length; j++) { + matrix.set(left, all[j], build.get(left, all[j])); + } + + matrixArr.add(matrix); + } + + return matrixArr.toArray(new AHPMatrix[0]); + + } + + /** + * Gets the key. + * + * @return the key + */ + public PreferenceCollectionKey getKey() { + return anyBuild.getKey(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + for (Entry> entry1 : content.entrySet()) { + sb.append("P1 " + entry1.getKey().toString()); + for (Entry entry2 : entry1.getValue().entrySet()) { + sb.append("\n"); + sb.append("P2 " + entry2.getKey().toString()); + sb.append("\n"); + sb.append(entry2.getValue().toString()); + } + sb.append("\n"); + } + return sb.toString(); + } + + /** + * Gets the builds. + * + * @return the builds + */ + public ArrayList getBuilds() { + ArrayList builds = new ArrayList<>(); + for (HashMap entry : content.values()) + for (PreferenceBuild build : entry.values()) + builds.add(build); + return builds; + } + +} diff --git a/bundles/flintstones.entity.problemelement.ui/.classpath b/bundles/flintstones.entity.problemelement.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.problemelement.ui/.polyglot.META-INF b/bundles/flintstones.entity.problemelement.ui/.polyglot.META-INF new file mode 100644 index 0000000..7a36f20 --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.problemelement.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.entity.problemelement.ui/.project b/bundles/flintstones.entity.problemelement.ui/.project new file mode 100644 index 0000000..1489ca1 --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.problemelement.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362573 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.problemelement.ui/META-INF/MANIFEST.MF b/bundles/flintstones.entity.problemelement.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8fec3b8 --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.entity.problemelement.ui +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.problemelement.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.ui, + flintstones.entity.problemelement;visibility:=reexport, + org.eclipse.nebula.widgets.tablecombo, + org.eclipse.e4.core.contexts, + flintstones.helper.data +Export-Package: flintstones.entity.problemelement.ui.widget, + flintstones.entity.problemelement.ui.widget.listener diff --git a/bundles/flintstones.entity.problemelement.ui/build.properties b/bundles/flintstones.entity.problemelement.ui/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/ProblemElementPairSelector.java b/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/ProblemElementPairSelector.java new file mode 100644 index 0000000..d53c914 --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/ProblemElementPairSelector.java @@ -0,0 +1,140 @@ +package flintstones.entity.problemelement.ui.widget; + + +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementPairChangedListener; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.ui.components.TableComboStatus.Status; +import flintstones.helper.ui.components.listeners.IStatusProvider; + +public class ProblemElementPairSelector { + + // Component + ProblemElementSelector mainSelector; + ProblemElementSelector otherSelector; + + // Data + HashMatrix statusMatrix = new HashMatrix<>(); + ProblemElement[] mainPes; + ProblemElement[] otherPes; + + // Control + IProblemElementPairChangedListener listener; + + public ProblemElementPairSelector(Composite base, ProblemElement[] mainElements, ProblemElement[] otherElements) { + + mainSelector = new ProblemElementSelector(base, mainElements); + otherSelector = new ProblemElementSelector(base, otherElements); + + mainPes = mainElements; + otherPes = otherElements; + + for(ProblemElement main : mainPes) { + for(ProblemElement other : otherPes) { + statusMatrix.put(main, other, false); + } + } + + setStatusProvider(); + + } + + private void setStatusProvider() { + otherSelector.setStatusProvider(new IStatusProvider() { + + @Override + public Status getStatusFor(String name) { + + ProblemElement main = mainSelector.getSelectedElement(); + ProblemElement other = otherSelector.getByName(name); + + return statusMatrix.get(main, other) ? Status.Right : Status.Wrong; + + } + }); + + mainSelector.setStatusProvider(new IStatusProvider() { + + @Override + public Status getStatusFor(String name) { + + ProblemElement main = mainSelector.getByName(name); + boolean ok = true; + for(ProblemElement other : otherPes) { + Boolean status = statusMatrix.get(main, other); + ok = ok && status; + } + + return ok ? Status.Right : Status.Wrong; + + } + }); + + refresh(); + } + + public void setListener(IProblemElementPairChangedListener lis) { + listener = lis; + + mainSelector.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + listener.mainProblemElementChanged(pe); + } + }); + + otherSelector.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + listener.otherProblemElementChanged(pe); + } + }); + } + + public void setText(String main, String other) { + mainSelector.setText(main); + otherSelector.setText(other); + } + + public void setStatus(ProblemElement main, ProblemElement other, Boolean status, Boolean refresh) { + statusMatrix.put(main, other, status); + if(refresh) + refresh(); + } + + public void setStatus(ProblemElement main, ProblemElement other, Boolean status) { + setStatus(main, other, status,true); + } + + public ProblemElement getSelectedMain() { + return mainSelector.getSelectedElement(); + } + + public ProblemElement getSelectedOther() { + return otherSelector.getSelectedElement(); + } + + public void refresh() { + otherSelector.refresh(); + mainSelector.refresh(); + } +// public void refresh() { +// +// ProblemElement mainPe = mainSelector.getSelectedElement(); +// +// boolean ok = true; +// for(ProblemElement other : otherPes) { +// boolean status = statusMatrix.get(mainPe, other); +// otherSelector.setStatus(other, status); +// ok = ok && status; +// +// } +// +// mainSelector.setStatus(mainPe, ok); +// +// } + +} diff --git a/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/ProblemElementSelector.java b/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/ProblemElementSelector.java new file mode 100644 index 0000000..e00ed85 --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/ProblemElementSelector.java @@ -0,0 +1,109 @@ +package flintstones.entity.problemelement.ui.widget; + +import java.util.Arrays; +import java.util.LinkedHashMap; + +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.ProblemElement; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.helper.ui.components.TableComboStatus; +import flintstones.helper.ui.components.TableComboStatus.Status; +import flintstones.helper.ui.components.listeners.IStatusProvider; + +public class ProblemElementSelector { + + // Component + TableComboStatus combo; + Label titleLabel; + + // Data + LinkedHashMap elements = new LinkedHashMap(); + ProblemElement lastProblemElementSelected = null; + + // Control + IProblemElementChangedListener changeListener; + IStatusProvider statusProvider; + + public ProblemElementSelector(Composite base, ProblemElement[] problemElements) { + + titleLabel = new Label(base, 0); + + combo = new TableComboStatus(base, SWT.BORDER | SWT.READ_ONLY ); + Arrays.stream(problemElements).forEach(k -> elements.put(k.getName(), k)); + + combo.setItems(elements.keySet().toArray(new String[elements.size()])); + combo.select(0); + combo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + + ProblemElement pe = getSelectedElement(); + if(!pe.equals(lastProblemElementSelected)) { + // The element has changed + lastProblemElementSelected = pe; + // Elevate the change + changeListener.problemElementChanged(pe); + } + } + }); + + lastProblemElementSelected = problemElements[0]; + } + + public void setListener(IProblemElementChangedListener lis) { + changeListener = lis; + } + + public void setStatusProvider(IStatusProvider sta) { + statusProvider = sta; + } + + public void setText(String text) { + titleLabel.setText(text); + titleLabel.getParent().layout(); + } + + public void setStatus(ProblemElement pe, boolean status) { + combo.setStatus(pe.getName(), status ? TableComboStatus.Status.Right : TableComboStatus.Status.Wrong); + } + + public boolean getStatus() { + return combo.getStatus(); + } + + public boolean getStatus(ProblemElement pe) { + return combo.getStatus(pe.getName()); + } + + public ProblemElement getSelectedElement() { + String peS = combo.getText(); + ProblemElement pe = elements.get(peS); + return pe; + } + + public ProblemElement getByName(String name) { + return elements.get(name); + } + + public void refresh() { + + if(statusProvider == null) + return ; + + if(statusProvider == null) + throw new RuntimeException("Provider de status sin definir"); + + for(String element : elements.keySet()) { + Status status = statusProvider.getStatusFor(element); + combo.setStatus(element, status); + } + + } + +} + diff --git a/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/listener/IProblemElementChangedListener.java b/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/listener/IProblemElementChangedListener.java new file mode 100644 index 0000000..1e8926a --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/listener/IProblemElementChangedListener.java @@ -0,0 +1,9 @@ +package flintstones.entity.problemelement.ui.widget.listener; + +import flintstones.entity.problemelement.entities.ProblemElement; + +public interface IProblemElementChangedListener { + + void problemElementChanged(ProblemElement pe); + +} diff --git a/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/listener/IProblemElementPairChangedListener.java b/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/listener/IProblemElementPairChangedListener.java new file mode 100644 index 0000000..b9ed4c1 --- /dev/null +++ b/bundles/flintstones.entity.problemelement.ui/src/flintstones/entity/problemelement/ui/widget/listener/IProblemElementPairChangedListener.java @@ -0,0 +1,11 @@ +package flintstones.entity.problemelement.ui.widget.listener; + +import flintstones.entity.problemelement.entities.ProblemElement; + +public interface IProblemElementPairChangedListener { + + void mainProblemElementChanged(ProblemElement pe); + + void otherProblemElementChanged(ProblemElement pe); + +} diff --git a/bundles/flintstones.entity.problemelement/.classpath b/bundles/flintstones.entity.problemelement/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.problemelement/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.problemelement/.polyglot.META-INF b/bundles/flintstones.entity.problemelement/.polyglot.META-INF new file mode 100644 index 0000000..bb84451 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.problemelement + 1.0.0.qualfier + eclipse-plugin + [bundle] Problemelements + + Sinbad2 + + diff --git a/bundles/flintstones.entity.problemelement/.project b/bundles/flintstones.entity.problemelement/.project new file mode 100644 index 0000000..e1048e7 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/.project @@ -0,0 +1,50 @@ + + + flintstones.entity.problemelement + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362572 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.problemelement/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.problemelement/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.problemelement/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.problemelement/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.problemelement/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.problemelement/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.problemelement/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.problemelement/META-INF/MANIFEST.MF b/bundles/flintstones.entity.problemelement/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b5c5b0b --- /dev/null +++ b/bundles/flintstones.entity.problemelement/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Problemelements +Bundle-SymbolicName: flintstones.entity.problemelement;singleton:=true +Bundle-Version: 1.0.0.qualfier +Bundle-Vendor: Sinbad2 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Export-Package: flintstones.entity.problemelement;uses:="flintstones.entity.problemelement.entities", + flintstones.entity.problemelement.entities;uses:="flintstones.helper.extensionpoint,flintstones.entity.problemelement.service", + flintstones.entity.problemelement.messages, + flintstones.entity.problemelement.provider;uses:="flintstones.entity.problemelement.entities" +Automatic-Module-Name: flintstones.problemelements +Require-Bundle: org.eclipse.e4.core.contexts, + org.eclipse.e4.core.services, + javax.inject, + org.apache.commons.lang, + flintstones.entity.extensionenum, + flintstones.entity.common;visibility:=reexport diff --git a/bundles/flintstones.entity.problemelement/build.properties b/bundles/flintstones.entity.problemelement/build.properties new file mode 100644 index 0000000..f250f99 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/build.properties @@ -0,0 +1,4 @@ +output.. = bin/ +bin.includes = META-INF/,\ + . +source.. = src/ diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/ProblemElementKey.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/ProblemElementKey.java new file mode 100644 index 0000000..9e0e9dd --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/ProblemElementKey.java @@ -0,0 +1,230 @@ +package flintstones.entity.problemelement; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Class ProblemElementKey. + * + * @author Sinbad2 + * Unify expert, alternative and criterion into a class to be used in Maps. + */ +public class ProblemElementKey implements Cloneable, Comparable { + + /** The expert. */ + private Expert expert; + + /** The alternative. */ + private Alternative alternative; + + /** The criterion. */ + private Criterion criterion; + + /** + * Instantiates a new problem element key. + * + * @param currentPE the current PE + * @param pe1 the pe 1 + * @param pe2 the pe 2 + * @param b the b + */ + public ProblemElementKey(ProblemElement currentPE, ProblemElement pe1, ProblemElement pe2) { + + if (currentPE instanceof Expert) { + this.expert = (Expert) currentPE; + this.criterion = (Criterion) pe1; + this.alternative = (Alternative) pe2; + } else if (currentPE instanceof Criterion) { + this.criterion = (Criterion) currentPE; + this.alternative = (Alternative) pe1; + this.expert = (Expert) pe2; + } else { + this.alternative = (Alternative) currentPE; + this.expert = (Expert) pe1; + this.criterion = (Criterion) pe2; + } + } + + public ProblemElementKey assign(ProblemElement pe) { + if(pe.getType().equals(Expert.Type)) + expert = (Expert) pe; + else if(pe.getType().equals(Criterion.Type)) + criterion = (Criterion) pe; + else + alternative = (Alternative) pe; + return this; + } + + public ProblemElementKey() { + + } + + /** + * Instantiates a new problem element key. + * + * @param expert expert + * @param alternative alternative + * @param criterion criterion + */ + public ProblemElementKey(Expert expert, Alternative alternative, Criterion criterion) { + this.expert = expert; + this.alternative = alternative; + this.criterion = criterion; + } + + /** + * Gets the expert. + * + * @return the expert + */ + public Expert getExpert() { + return this.expert; + } + + /** + * Gets the alternative. + * + * @return the alternative + */ + public Alternative getAlternative() { + return this.alternative; + } + + /** + * Gets the criterion. + * + * @return the criterion + */ + public Criterion getCriterion() { + return this.criterion; + } + + /** + * Gets one of the 3 problem elements depending on the type. + * + * @param type the type of the problem element + * @return the item + */ + public ProblemElement get(String type) { + return this.get(type, false, false); + } + + /** + * Gets one of the 3 problem elements depending on the type. + * + * @param type the type of the problem element + * @param next Get the next problem item. If type is ALT, get CRIT + * @return the item + */ + public ProblemElement get(String type, boolean next) { + return this.get(type, next, false); + } + + /** + * Gets one of the 3 problem elements depending on the type. + * + * @param type the type of the problem element + * @param next Get the next problem item. If type is ALT, get CRIT + * @param nextnext Get the next next problem item. If type is ALT, EXPERT + * @return the item + */ + public ProblemElement get(String type, boolean next, boolean nextnext) { + int x = -1; + + if (Alternative.Type + .equals(type)) + x = 0; + else if (Expert.Type + .equals(type)) + x = 1; + else if (Criterion.Type + .equals(type)) + x = 2; + + if (next) + x++; + if (nextnext) + x++; + + x = x % 3; + + if (x == 0) + return this.getAlternative(); + if (x == 1) + return this.getExpert(); + if (x == 2) + return this.getCriterion(); + + return null; + } + + /* (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) */ + @Override + public boolean equals(Object object) { + + if (this == object) + return true; + + if (object == null) + return false; + + if (object.getClass() != this.getClass()) + return false; + + final ProblemElementKey other = (ProblemElementKey) object; + + EqualsBuilder eb = new EqualsBuilder(); + eb.append(this.expert, other.expert); + eb.append(this.alternative, other.alternative); + eb.append(this.criterion, other.criterion); + return eb.isEquals(); + } + + /* (non-Javadoc) + * + * @see java.lang.Object#hashCode() */ + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(); + hcb.append(this.expert); + hcb.append(this.alternative); + hcb.append(this.criterion); + return hcb.toHashCode(); + } + + /* (non-Javadoc) + * + * @see java.lang.Object#toString() */ + @Override + public String toString() { + String result = ""; //$NON-NLS-1$ + + result += (this.expert != null) ? this.expert.getCanonicalName() : "null"; //$NON-NLS-1$ + result += ":"; //$NON-NLS-1$ + result += (this.alternative != null) ? this.alternative.getCanonicalName() : "null"; //$NON-NLS-1$ + result += ":"; //$NON-NLS-1$ + result += (this.criterion != null) ? this.criterion.getCanonicalName() : "null"; //$NON-NLS-1$ + + return result; + } + + /* (non-Javadoc) + * + * @see java.lang.Comparable#compareTo(java.lang.Object) */ + @Override + public int compareTo(ProblemElementKey other) {/* if(!this.alternative.getName().equals(other.getAlternative().getName())) + * return -1; + * if(!this.criterion.getName().equals(other.getCriterion().getName())) return + * -1; if(!this.expert.getName().equals(other.getExpert().getName())) return -1; + * return 1; */ + return this.toString() + .compareTo(other.toString()); + } +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Alternative.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Alternative.java new file mode 100644 index 0000000..1fa88e4 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Alternative.java @@ -0,0 +1,91 @@ +package flintstones.entity.problemelement.entities; + +import java.util.UUID; + +import flintstones.entity.extensionenum.ExtensionEnum; + +/** + * The Class Alternative. Alternatives can't have parents or children. + */ +public class Alternative extends ProblemElement { + + /** The Type. */ + public static String Type = Alternative.class.getSimpleName(); + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + /** The Alternative. */ + Alternative, + /** The Alternatives. */ + Alternatives + }; + + /** + * Instantiates a new alternative. + */ + public Alternative(String name) { +// super(); + setName(name); + setType(Alternative.Type); + updateId(); + } + + /* + * (non-Javadoc) + * º + * @see flintstones.problemelements.ProblemElement#clone() + */ + @Override + public Object clone() { + Alternative result = new Alternative(this.getName()); + return result; + } + + /* + * (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#getChildren() + */ + @Override + public Alternative[] getChildren() { + return new Alternative[0]; + } + + /* + * (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#getParent() + */ + @Override + public Alternative getParent() { + return null; + } + + /* + * (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#hasChildren() + */ + @Override + public boolean hasChildren() { + return false; + } + + /* + * (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#hasParent() + */ + @Override + public boolean hasParent() { + return false; + } + + @Override + public String calculateId() { + return UUID.randomUUID().toString(); + } + +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Criterion.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Criterion.java new file mode 100644 index 0000000..341c462 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Criterion.java @@ -0,0 +1,79 @@ +package flintstones.entity.problemelement.entities; + +import java.util.UUID; + +import flintstones.entity.extensionenum.ExtensionEnum; + +/** + * The Class Criterion. + */ +public class Criterion extends ProblemElement { + + /** The cost. */ + private boolean cost; + + /** The Type. */ + public static String Type = Criterion.class.getSimpleName(); + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + /** n elements. */ + Criteria, + /** 1 element. */ + Criterion, + /** The cost. */ + cost + } + + /** + * Instantiates a new criterion. + */ + public Criterion(String name) { + setName(name); + this.setType(Criterion.Type); + updateId(); + } + + /** + * Checks if is cost is cost or benefit. + * + * @return true, if is cost + */ + public boolean isCost() { + return this.cost; + } + + /** + * Sets the cost. + * + * @param cost the new cost + */ + public void setCost(boolean cost) { + this.cost = cost; + } + + /* (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#clone() */ + @Override + public Object clone() { + Criterion result = new Criterion(this.getName()); + result.cost = cost; + + ProblemElement[] children = this.getChildren(); + for (ProblemElement item : children) + result.addChildren(item); + + if(this.hasParent()) + result.setParent(this.parent); + + return result; + } + + @Override + public String calculateId() { + return UUID.randomUUID().toString(); + } +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Expert.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Expert.java new file mode 100644 index 0000000..171673d --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/Expert.java @@ -0,0 +1,84 @@ +package flintstones.entity.problemelement.entities; + +import java.util.UUID; + +import flintstones.entity.extensionenum.ExtensionEnum; + +/** + * The Class Expert. + */ +public class Expert extends ProblemElement { + + /** The Type. */ + public static String Type = Expert.class.getSimpleName(); + + /** The mail. */ + private String mail = ""; + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + /** The Expert. */ + Expert, + /** The Experts. */ + Experts, + + /** The mail. */ + mail + } + + /** + * Instantiates a new expert. + */ + public Expert(String name) { + setName(name); + setType(Expert.Type); + updateId(); + } + + /* + * (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#clone() + */ + @Override + public Object clone() { + + Expert result = new Expert(this.getName()); + result.mail = mail; + + ProblemElement[] children = this.getChildren(); + for (ProblemElement item : children) + result.addChildren(item); + + if (this.hasParent()) + result.setParent(this.parent); + + return result; + } + + /** + * Sets the mail. + * + * @param newMail the new mail + */ + public void setMail(String newMail) { + this.mail = newMail; + } + + /** + * Gets the mail. + * + * @return the mail + */ + public String getMail() { + return mail; + } + + @Override + public String calculateId() { + return UUID.randomUUID().toString(); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/FakeProblemElement.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/FakeProblemElement.java new file mode 100644 index 0000000..fd55cd3 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/FakeProblemElement.java @@ -0,0 +1,74 @@ +package flintstones.entity.problemelement.entities; + +import org.apache.commons.lang.NotImplementedException; + +/** + * The Class FakeProblemElement makes posible to use a dummy ProblemElement with some components. + */ +public class FakeProblemElement extends ProblemElement { + + /** The Type. */ + public static String Type = FakeProblemElement.class.getSimpleName(); + + /** + * Instantiates a new fake problem element. + */ + public FakeProblemElement(String name) { + setName(name); + setType(FakeProblemElement.Type); + updateId(); + } + + /* (non-Javadoc) + * @see flintstones.entity.problemelement.entities.ProblemElement#clone() + */ + @Override + public Object clone() { + throw new NotImplementedException(); + } + + /** + * As alternative. + * + * @return the problem element + */ + public ProblemElement asAlternative() { + this.setType(Alternative.Type); + return this; + } + + /** + * As criterion. + * + * @return the problem element + */ + public ProblemElement asCriterion() { + this.setType(Criterion.Type); + return this; + } + + /** + * As expert. + * + * @return the problem element + */ + public ProblemElement asExpert() { + this.setType(Expert.Type); + return this; + } + + /** + * As. + * + * @param type the type + */ + public ProblemElement as(String type) { + this.setType(type); + return this; + } + + @Override + public String calculateId() { + return getName(); + } +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/ProblemElement.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/ProblemElement.java new file mode 100644 index 0000000..854c657 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/ProblemElement.java @@ -0,0 +1,404 @@ +package flintstones.entity.problemelement.entities; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.LinkedList; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +import flintstones.entity.common.interfaces.IdentifiedEntity; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.problemelement.exception.DifferentProblemElementTypeException; + +/** + * The Class ProblemElement. + */ +public abstract class ProblemElement implements Comparable, IdentifiedEntity { + + /** The children list. */ + protected LinkedList children = new LinkedList<>(); + + /** The item unique name. */ + private String name; + + /** The parent. */ + protected ProblemElement parent = null; + + /** The Type. */ + public static String Type; // Should be null in parent class + + /* IdentifiedEntity implementation */ + private String serviceId = null; + + private int order = -1; + private int childrenOrder = 0; + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + /** The Problems. */ + Problems, + /** The Problem. */ + Problem, + /** The id. */ + id, + /** The name. */ + name, + /** The children. */ + children, + + /** The Problem element. */ + // + ProblemElement + }; + + protected ProblemElement() { + } + + // Children modify methods + /** + * Adds the children. + * + * @param item the item + */ + public void addChildren(ProblemElement item) { + + if (item.equals(this)) + return; + + if (item.hasParent()) + item.getParent().removeChildren(item); + + item.setParent(this); + item.setOrder(childrenOrder++); + children.add(item); + } + + public void addChildrenAfter(ProblemElement previousItem, ProblemElement item) { + + ProblemElement[] childrenItems = getChildren(); + children.clear(); + childrenOrder = 0; + + if (previousItem == null) { + addChildren(item); + for (ProblemElement child : childrenItems) + addChildren(child); + + } else { + + for (ProblemElement child : childrenItems) { + addChildren(child); + if (previousItem.equals(child)) + addChildren(item); + + } + + } + + } + + public void addChildrenBefore(ProblemElement nextItem, ProblemElement item) { + + ProblemElement[] childrenItems = getChildren(); + children.clear(); + childrenOrder = 0; + + for (ProblemElement child : childrenItems) { + if (nextItem.equals(child)) + addChildren(item); + addChildren(child); + + } + + } + + /** + * Removes the children. + * + * @param itemUniqueId the item unique id + */ + public void removeChildren(ProblemElement removedChild) { + + ProblemElement[] childrenItems = getChildren(); + children.clear(); + childrenOrder = 0; + + for (ProblemElement child : childrenItems) { + if (child.equals(removedChild)) { + child.setOrder(-1); + child.setParent(null); + continue; + } + addChildren(child); + } +// +// for (ProblemElement child : children) +// if (child.equals(removedChild)) { +// children.remove(child); +// return; +// } + } + + /** + * Sets the parent. + * + * @param pe the new parent + */ + protected void setParent(ProblemElement pe) { + this.parent = pe; + } + + /** + * Change parent. + * + * @param newParent the new parent + * @return true, if successful + */ + public boolean changeParent(ProblemElement newParent) { + + ProblemElement item = this; + ProblemElement oldParent = item.getParent(); + + // Basic check + if (item.getType().equals(Alternative.Type)) { + return false; + } +// throw new AlternativeCantHaveParentException(item); + + // Unlink from old parent + if (oldParent != null) + oldParent.removeChildren(item); + + // Link with new parent + item.setParent(newParent); + + // Add as a child of the item + if (newParent != null) { + + // Basic check + if (!item.getType().equals(newParent.getType())) + throw new DifferentProblemElementTypeException(item, newParent); + + newParent.addChildren(item); + + } + + return true; + } + + public void setOrder(int pos) { + order = pos; + } + + public int getOrder() { + return order; + } + + // END Children modify methods + + /* + * (non-Javadoc) + * + * @see java.lang.Object#clone() + */ + @Override + public abstract Object clone(); + + /* + * (non-Javadoc) + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(ProblemElement pe) { + return Comparator.comparing(ProblemElement::getName).thenComparing(ProblemElement::getType).compare(this, pe); + } + + /** + * Gets the canonical name. Parent_name > Next_parent > ... > Item_Name + * + * @return the canonical name + */ + public String getCanonicalName() { + + if (this.parent != null) { + if(!this.parent.getName().isEmpty()) { + String canonicalTemplate = "{0}>{1}"; + return MessageFormat.format(canonicalTemplate, this.parent.getCanonicalName(), this.getName()).toString(); + } + } + return this.getName(); + } + + /** + * Gets shorter item name. + * + * @return the name + */ + public String getShortName() { + return this.name; + } + + + /** + * Gets the children. + * + * @return the children + */ + public ProblemElement[] getChildren() { + return this.children.toArray(new ProblemElement[this.children.size()]); + } + + /** + * Gets the final elements (leaf elements) from this item. + * + * @return the final elements + */ + public ProblemElement[] getFinalElements() { + ArrayList items = new ArrayList<>(); + + // leaf + if (this.children.isEmpty()) + items.add(this); + else + for (ProblemElement child : this.children) { + ProblemElement[] arr = child.getFinalElements(); + for (ProblemElement pe : arr) + items.add(pe); + } + + return items.toArray(new ProblemElement[items.size()]); + + } + + /** + * Gets the item name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Gets the parent. + * + * @return the parent + */ + public ProblemElement getParent() { + return this.parent; + } + + /** + * Checks for children. + * + * @return true, if successful + */ + public boolean hasChildren() { + return this.children.size() > 0; + } + + /** + * Checks for parent. + * + * @return true, if successful + */ + public boolean hasParent() { + return this.parent != null; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; +// updateId(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return this.getName(); + } + + /** + * Checks if is parent. + * + * @return true, if is parent + */ + public boolean isParent() { + return this.hasChildren(); + } + + /** + * Checks if is leaf. + * + * @return true, if is leaf + */ + public boolean isLeaf() { + return !isParent(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(); + hcb.append(this.getId()); + hcb.append(this.getType()); + + return hcb.toHashCode(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object o) { + if (!(o instanceof ProblemElement)) { + return false; + } + ProblemElement other = (ProblemElement) o; + EqualsBuilder builder = new EqualsBuilder(); + builder.append(this.getId(), other.getId()); + builder.append(this.getType(), other.getType()); + + return builder.isEquals(); + } + + @Override + public final String getId() { + return serviceId; + }; + + @Override + public final void updateId() { + serviceId = calculateId(); + } + + /* TypedEntity implementation */ + private String type; + + public String getType() { + return this.type; + } + + protected void setType(String type) { + this.type = type; + } + +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/ProblemElementHelper.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/ProblemElementHelper.java new file mode 100644 index 0000000..a472363 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/ProblemElementHelper.java @@ -0,0 +1,145 @@ +package flintstones.entity.problemelement.entities; + +import java.io.File; +import java.util.Arrays; +import java.util.Comparator; + +import flintstones.entity.problemelement.exception.InvalidProblemElementTypeException; + +public class ProblemElementHelper { + + public static ProblemElement create(String name, String type) { + if(type.equals(Alternative.Type)) + return new Alternative(name); + + if(type.equals(Expert.Type)) + return new Expert(name); + + if(type.equals(Criterion.Type)) + return new Criterion(name); + + if(type.equals(SortingClass.Type)) + return new SortingClass(name); + + if(type.equals(FakeProblemElement.Type)) + return new FakeProblemElement(name); + + throw new InvalidProblemElementTypeException(type); + } + + public static Alternative[] asAlternatives(ProblemElement[] pes) { + return Arrays.stream(pes).map(k -> (Alternative)k).toArray(Alternative[]::new); + } + + public static Criterion[] asCriterions(ProblemElement[] pes) { + return Arrays.stream(pes).map(k -> (Criterion)k).toArray(Criterion[]::new); + } + + public static Expert[] asExperts(ProblemElement[] pes) { + return Arrays.stream(pes).map(k -> (Expert)k).toArray(Expert[]::new); + } + + public static SortingClass[] asSortingClasses(ProblemElement[] pes) { + return Arrays.stream(pes).map(k -> (SortingClass)k).toArray(SortingClass[]::new); + } + + + public static String getNextType(String type, boolean next, boolean nextnext) { + + int x = 0; + + if (Alternative.Type.equals(type)) + x = 0; + else if (Expert.Type.equals(type)) + x = 1; + else if (Criterion.Type.equals(type)) + x = 2; + + if (next) + x++; + if (nextnext) + x++; + + x = x % 3; + + if (x == 0) + return Alternative.Type; + else if (x == 1) + return Expert.Type; + else if (x == 2) + return Criterion.Type; + return null; + + } + + public static String getImage(ProblemElement pe) { + String type = pe.getType(); + boolean isParent = pe.hasChildren(); + boolean cost = false; + if(pe.getType().equals(Criterion.Type) && !(pe instanceof FakeProblemElement) ) { + cost = ((Criterion)pe).isCost(); + } + return getImage(type, isParent, cost); + } + + public static String getImage(String type) { + return getImage(type, false, false); + } + + public static String getImage(String type, boolean parent) { + return getImage(type, parent, false); + } + + public static String getImage(String type, boolean parent, boolean isCost) { + String f = "problemelement" + File.separator; + if(FakeProblemElement.Type.equals(type)) + return f+"fake.png"; + if (Alternative.Type.equals(type)) + return parent ? f+"alternatives.png" : f+"alternative.png"; + if (Expert.Type.equals(type)) + return parent ? f+"experts.png": f+"expert.png"; + if(SortingClass.Type.equals(type)) + return f+"sortclass.png"; + if (Criterion.Type.equals(type)) + if(parent) + return f+"criterions.png"; + else + return isCost ? f+"criterion_cost.png" : f+"criterion.png"; + return null; + } + + public static ProblemElement[] getAsUserOrdered(ProblemElement[] pes) { + Arrays.sort(pes, getAsUserOrderedComparator()); + return pes; + } + + public static ProblemElement[] getAsAlphabeticalOrdered(ProblemElement[] pes) { + Arrays.sort(pes, getAlphabeticalComparator()); + return pes; + } + + // Private + public static Comparator getAsUserOrderedComparator(){ + Comparator c = new Comparator() { + public int compare(ProblemElement a, ProblemElement b) { + return a.getOrder() > b.getOrder() ? 1 : -1; + } + + }; + return c; + } + + public static Comparator getAlphabeticalComparator(){ + Comparator c = new Comparator() { + public int compare(ProblemElement o1, ProblemElement o2) { + return transformToSInteger(o1.getName()) - transformToSInteger(o2.getName()); + } + + int transformToSInteger(String str) { + String number = str.replaceAll("\\D", ""); + return number.isEmpty() ? 0 : Integer.parseInt(number); + } + }; + return c; + } +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/SortingClass.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/SortingClass.java new file mode 100644 index 0000000..c4458d4 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/SortingClass.java @@ -0,0 +1,80 @@ +package flintstones.entity.problemelement.entities; + +import java.util.UUID; + +import flintstones.entity.extensionenum.ExtensionEnum; + +/** + * The Class AHPSortClass. + */ +public class SortingClass extends ProblemElement{ + + /** The Type. */ + public static String Type = SortingClass.class.getSimpleName(); + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + + /** The name. */ + name, AHPSortClass + } + + /** + * Instantiates a new AHP sort class. + * + * @param className the class name + */ + public SortingClass(String className) { + setName(className); + setType(SortingClass.Type); + updateId(); + } + + /* (non-Javadoc) + * @see flintstones.entity.problemelement.entities.ProblemElement#clone() + */ + @Override + public Object clone() { + throw new UnsupportedOperationException(); + } + + @Override + public String calculateId() { + return UUID.randomUUID().toString(); + } + + + /* + * (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#getParent() + */ + @Override + public Alternative getParent() { + return null; + } + + /* + * (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#hasChildren() + */ + @Override + public boolean hasChildren() { + return false; + } + + /* + * (non-Javadoc) + * + * @see flintstones.problemelements.ProblemElement#hasParent() + */ + @Override + public boolean hasParent() { + return false; + } + + +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/SortingProfile.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/SortingProfile.java new file mode 100644 index 0000000..18c536b --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/entities/SortingProfile.java @@ -0,0 +1,163 @@ +package flintstones.entity.problemelement.entities; + +import java.text.MessageFormat; +import java.util.UUID; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +import flintstones.entity.extensionenum.ExtensionEnum; + +/** + * The Class AHPSortProfile. + */ +public class SortingProfile extends ProblemElement { + + /** The Type. */ + public static String Type = SortingProfile.class.getSimpleName(); + + /** + * The Enum Fields. + */ + public static enum Fields implements ExtensionEnum { + + /** The value. */ + value, + /** The AHP sort profile. */ + SortingProfile, + /** The AHP sort profiles. */ + SortingProfiles + }; + + public static enum SortingProfileType { + Central, Limiting + } + + /** The value. */ + private double value; + + Expert expert; + Criterion criterion; + + /** + * Instantiates a new AHP sort profile. + * + * @param limit the limit + * @param position the position + */ + public SortingProfile(Expert e, Criterion c, Double limit) { +// super(); + setType(SortingProfile.Type); + expert = e; + criterion = c; + + setValue(limit); + setName("P_" + c.getName() + "_" + e.getName() + " " + value + ""); + + updateId(); + + } + + /* + * (non-Javadoc) + * + * @see flintstones.entity.problemelement.entities.ProblemElement#clone() + */ + @Override + public Object clone() { + throw new UnsupportedOperationException(); + } + + /** + * Gets the value. + * + * @return the value + */ + public double getValue() { + return value; + } + + /** + * Sets the value. + * + * @param val the new value + */ + public void setValue(double val) { + this.value = val; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + HashCodeBuilder hcb = new HashCodeBuilder(); + hcb.append(this.getName()); + hcb.append(this.getType()); + hcb.append(this.getValue()); + hcb.append(this.expert.getName()); + hcb.append(this.criterion.getName()); + + return hcb.toHashCode(); + } + + /* + * (non-Javadoc) + * + * @see + * flintstones.entity.problemelement.entities.ProblemElement#equals(java.lang. + * Object) + */ + @Override + public boolean equals(Object o) { + + if (!(o instanceof SortingProfile)) { + return false; + } + + SortingProfile other = (SortingProfile) o; + EqualsBuilder builder = new EqualsBuilder(); + builder.append(this.getName(), other.getName()); + builder.append(this.getType(), other.getType()); + builder.append(this.getValue(), other.getValue()); + builder.append(this.expert.getName(), other.expert.getName()); + builder.append(this.criterion.getName(), other.criterion.getName()); + + return builder.isEquals(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + String template = "{1}"; +// String template = "[{0}] {1} -> {2}"; + String x = MessageFormat.format(template, Type, getName(), this.value).toString(); + + return x; + } + + @Override + public String calculateId() { + return UUID.randomUUID().toString(); + } + + public ProblemElement getExpert() { + return expert; + } + + public ProblemElement getCriterion() { + return criterion; + } + + @Override + public String getShortName() { + return "P " + value; + } +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/AlternativeCantHaveParentException.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/AlternativeCantHaveParentException.java new file mode 100644 index 0000000..d8ec28b --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/AlternativeCantHaveParentException.java @@ -0,0 +1,21 @@ +package flintstones.entity.problemelement.exception; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Class AlternativeCantHaveParentException. + */ +public class AlternativeCantHaveParentException extends RuntimeException { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 1950044469539431139L; + + /** + * Instantiates a new alternative cant have parent exception. + * + * @param pe the ProblemElement + */ + public AlternativeCantHaveParentException(ProblemElement pe) { + super("Alternatives can't have parent/children " + pe.getName()); + } +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/DifferentProblemElementTypeException.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/DifferentProblemElementTypeException.java new file mode 100644 index 0000000..434dbdb --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/DifferentProblemElementTypeException.java @@ -0,0 +1,23 @@ +package flintstones.entity.problemelement.exception; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Class DifferentProblemElementTypeException. + */ +public class DifferentProblemElementTypeException extends RuntimeException { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = -8758298521716570202L; + + /** + * Instantiates a new different problem element type exception. + * + * @param a the a + * @param b the b + */ + public DifferentProblemElementTypeException(ProblemElement a, ProblemElement b) { + super( a.getName() + " can not be parent of " + b.getName() + ", types do not match " + a.getType() + " != " + b.getType()); + } + +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/InvalidProblemElementTypeException.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/InvalidProblemElementTypeException.java new file mode 100644 index 0000000..e43b5df --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/exception/InvalidProblemElementTypeException.java @@ -0,0 +1,19 @@ +package flintstones.entity.problemelement.exception; + +/** + * The Class InvalidProblemElementTypeException. + */ +public class InvalidProblemElementTypeException extends RuntimeException { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = -1618577755296656641L; + + /** + * Instantiates a new invalid problem element type exception. + * + * @param type the type + */ + public InvalidProblemElementTypeException(String type){ + super( type + " is not a valid type for ProblemElement"); + } +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/Messages.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/Messages.java new file mode 100644 index 0000000..0e5886a --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/Messages.java @@ -0,0 +1,30 @@ +// This file has been auto-generated +package flintstones.entity.problemelement.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings({ "javadoc", "nls" }) +public class Messages { + + public String ALTERNATIVE_IMAGE_CHILD; + public String ALTERNATIVE_ENTITY_NAME; + public String ALTERNATIVE_GROUP_NAME; + public String CRITERION_IMAGE_CHILD; + public String CRITERION_IMAGE_COST_NEGATIVE; + public String CRITERION_IMAGE_COST_POSITIVE; + public String CRITERION_ENTITY_NAME; + public String CRITERION_GROUP_NAME; + public String CRITERION_IMAGE_PARENT; + public String CRITERION_IMAGE_COST; + public String EXPERT_IMAGE_CHILD; + public String EXPERT_ENTITY_NAME; + public String EXPERT_GROUP_NAME; + public String EXPERT_IMAGE_PARENT; + public String ProblemElement_canonical_template; + public String ProblemElement_template; + public String title_template; + public String Profile_count; + public String SortingClass_count; + +} diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/messages.properties b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/messages.properties new file mode 100644 index 0000000..a68baf2 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/messages.properties @@ -0,0 +1,21 @@ +ALTERNATIVE_IMAGE_CHILD=alternative.png +ALTERNATIVE_ENTITY_NAME=Alternative +ALTERNATIVE_GROUP_NAME=Alternatives +CRITERION_IMAGE_CHILD=criterion.png +CRITERION_IMAGE_COST_NEGATIVE=cost.png +CRITERION_IMAGE_COST_POSITIVE=benefit.png +CRITERION_GROUP_NAME=Criterion +CRITERION_ENTITY_NAME=Criteria +CRITERION_IMAGE_PARENT=criteria.png +CRITERION_IMAGE_COST=type-of-criterion.png +EXPERT_IMAGE_CHILD=expert.png +EXPERT_ENTITY_NAME=Expert +EXPERT_GROUP_NAME=Experts +EXPERT_IMAGE_PARENT=group-of-experts.png +ProblemElement_canonical_template={0}>{1} +ProblemElement_entity=ProblemElement +ProblemElement_template=[{0}] {1} +ProblemElement_group=Problems +title_template {0} | {1} +Profile_count=The number of profiles +SortingClass_count=The number of sorting classes \ No newline at end of file diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/messages_es.properties b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/messages_es.properties new file mode 100644 index 0000000..01dfb70 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/messages/messages_es.properties @@ -0,0 +1,21 @@ +ALTERNATIVE_IMAGE_CHILD=alternative.png +ALTERNATIVE_ENTITY_NAME=Alternativa +ALTERNATIVE_GROUP_NAME=Alternativas +CRITERION_IMAGE_CHILD=criterion.png +CRITERION_IMAGE_COST_NEGATIVE=cost.png +CRITERION_IMAGE_COST_POSITIVE=benefit.png +CRITERION_GROUP_NAME=Criterios +CRITERION_ENTITY_NAME=Criterio +CRITERION_IMAGE_PARENT=criteria.png +CRITERION_IMAGE_COST=type-of-criterion.png +EXPERT_IMAGE_CHILD=expert.png +EXPERT_ENTITY_NAME=Experto +EXPERT_GROUP_NAME=Expertos +EXPERT_IMAGE_PARENT=group-of-experts.png +ProblemElement_canonical_template={0}>{1} +ProblemElement_entity=Problema +ProblemElement_template=[{0}] {1} +ProblemElement_group=Problemas +title_template {0} | {1} +Profile_count=El nmero de perfiles +SortingClass_count=El nmero de clases \ No newline at end of file diff --git a/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/provider/ProblemElementTitleProvider.java b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/provider/ProblemElementTitleProvider.java new file mode 100644 index 0000000..34a4930 --- /dev/null +++ b/bundles/flintstones.entity.problemelement/src/flintstones/entity/problemelement/provider/ProblemElementTitleProvider.java @@ -0,0 +1,53 @@ +package flintstones.entity.problemelement.provider; + +import java.text.MessageFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.messages.Messages; + +/** + * The Class ProblemElementTitleProvider. + */ +public class ProblemElementTitleProvider { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** + * Instantiates a new problem element title provider. + */ + public ProblemElementTitleProvider() { + } + + /** + * Gets the title. + * + * @param pe the pe + * @return the title + */ + public String getTitle(ProblemElement pe) { + String template = this.messages.title_template; + + String type = pe.getType(); + String label = ""; //$NON-NLS-1$ + + if (type.equals(Alternative.Type)) + label = this.messages.ALTERNATIVE_ENTITY_NAME; + else if (type.equals(Criterion.Type)) + label = this.messages.CRITERION_ENTITY_NAME; + else if (type.equals(Expert.Type)) + label = this.messages.EXPERT_ENTITY_NAME; + + String message = MessageFormat.format(template, label, pe.getCanonicalName()); + return message; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.polyglot.META-INF new file mode 100644 index 0000000..bd0093b --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ahp.mcc + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] AHP + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.project new file mode 100644 index 0000000..4711d67 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ahp.mcc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362574 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a31d96d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: AHP +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ahp.mcc;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.sensitiveanalysis.mcc.ahp +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + flintstones.valuation.twoTuple, + flintstones.valuation.numeric, + javax.inject, + org.eclipse.e4.core.di.annotations, + flintstones.valuation.fuzzy +Export-Package: flintstones.entity.sensitiveanalysismodel.ahp.mcc diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/plugin.xml new file mode 100644 index 0000000..e234ed5 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCC.java b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCC.java new file mode 100644 index 0000000..1a54bb9 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCC.java @@ -0,0 +1,314 @@ +package flintstones.entity.sensitiveanalysismodel.ahp.mcc; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public abstract class AnalyticHierarchyProcessMCC extends SensitiveAnalysisModel { + + @Inject + @Optional + IProblemElementService problemService; + + protected Double[] alternativesFinalPreferences; + + protected Double[][][] minimumAbsoluteChangeInCriteriaWeights; + protected Double[][][] minimumRelativeChangeInCriteriaWeights; + + protected List absoluteTop; + protected List absoluteAny; + protected List relativeTop; + protected List relativeAny; + + protected int numAlternatives; + protected int numCriteria; + + public AnalyticHierarchyProcessMCC() {} + + public Map getCriteriaWeights() { + return criteriaWeights; + } + + public void setCriteriaWeights(Map criteriaWeights) { + this.criteriaWeights = criteriaWeights; + } + + public Double[] getAlternativesFinalPreferences() { + return alternativesFinalPreferences; + } + + public void setAlternativesFinalPreferences(Double[] alternativesFinalPreferences) { + this.alternativesFinalPreferences = alternativesFinalPreferences; + } + + public Double[][][] getMinimumAbsoluteChangeInCriteriaWeights() { + return minimumAbsoluteChangeInCriteriaWeights; + } + + public void setMinimumAbsoluteChangeInCriteriaWeights(Double[][][] minimumAbsoluteChangeInCriteriaWeights) { + this.minimumAbsoluteChangeInCriteriaWeights = minimumAbsoluteChangeInCriteriaWeights; + } + + public Double[][][] getMinimumRelativeChangeInCriteriaWeights() { + return minimumRelativeChangeInCriteriaWeights; + } + + public void setMinimumRelativeChangeInCriteriaWeights(Double[][][] minimumRelativeChangeInCriteriaWeights) { + this.minimumRelativeChangeInCriteriaWeights = minimumRelativeChangeInCriteriaWeights; + } + + public List getAbsoluteTop() { + return absoluteTop; + } + + public void setAbsoluteTop(List absoluteTop) { + this.absoluteTop = absoluteTop; + } + + public List getAbsoluteAny() { + return absoluteAny; + } + + public void setAbsoluteAny(List absoluteAny) { + this.absoluteAny = absoluteAny; + } + + public List getRelativeTop() { + return relativeTop; + } + + public void setRelativeTop(List relativeTop) { + this.relativeTop = relativeTop; + } + + public List getRelativeAny() { + return relativeAny; + } + + public void setRelativeAny(List relativeAny) { + this.relativeAny = relativeAny; + } + + @Override + public void execute(HashMatrix decisionMatrix, Map criteriaWeights) { + numAlternatives = problemService.getAll(Alternative.Type).length; + numCriteria = problemService.getMainElements(Criterion.Type).length; + + this.setCriteriaWeights(criteriaWeights); + this.normalizeDecisionMatrix(decisionMatrix); + this.computeFinalPreferences(); + this.computeRanking(); + this.computeMinimumAbsoluteChangeInCriteriaWeights(); + this.computeMinimumRelativeChangeInCriteriaWeights(); + this.computeAbsoluteTopCriticalCriterion(); + this.computeAbsoluteAnyCriticalCriterion(); + this.computeRelativeTopCriticalCriterion(); + this.computeRelativeAnyCriticalCriterion(); + } + + protected abstract void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation); + + private void computeFinalPreferences() { + alternativesFinalPreferences = new Double[numAlternatives]; + for (int alternative = 0; alternative < numAlternatives; alternative++) { + alternativesFinalPreferences[alternative] = 0d; + for (int criterion = 0; criterion < numCriteria; criterion++) { + alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion] * + criteriaWeights.get(problemService.getMainElements(Criterion.Type)[criterion]); + } + } + } + + private void computeRanking() { + ranking = IntStream.range(0, alternativesFinalPreferences.length) + .boxed().sorted((j, i) -> alternativesFinalPreferences[i].compareTo(alternativesFinalPreferences[j])) + .mapToInt(ele -> ele).toArray(); + } + + /** + * Compute the minimum change in absolute terms to apply in criteria weights so that there is an exchange among any pair of alternatives + */ + private void computeMinimumAbsoluteChangeInCriteriaWeights() { + minimumAbsoluteChangeInCriteriaWeights = new Double[numAlternatives][numAlternatives][numCriteria]; + + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + if ((Double) decisionMatrix[j][k] - (Double) decisionMatrix[i][k] == 0) + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + else { + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = (alternativesFinalPreferences[j] - alternativesFinalPreferences[i]) + / ((Double) decisionMatrix[j][k] - (Double) decisionMatrix[i][k]); + + if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] > criteriaWeights.get(problemService.getMainElements(Criterion.Type)[k])) + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } + } + } + } + } + + /** + * Compute the minimum change in relative terms to apply in criteria weights so that there is an exchange among any pair of alternatives + */ + private void computeMinimumRelativeChangeInCriteriaWeights() { + minimumRelativeChangeInCriteriaWeights = new Double[numAlternatives][numAlternatives][numCriteria]; + + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] != NON_FEASIBLE) + minimumRelativeChangeInCriteriaWeights[i][j][k] = minimumAbsoluteChangeInCriteriaWeights[i][j][k] * (100d / criteriaWeights.get( + problemService.getMainElements(Criterion.Type)[k])); + else + minimumRelativeChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } + } + } + } + + /** + * Look for the minimal change in absolute terms among the best alternative/s and the rest of them + */ + private void computeAbsoluteTopCriticalCriterion() { + List bestAlternatives = getBestAlternatives(); + + absoluteTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumAbsoluteChangeInCriteriaWeights[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteTop.clear(); + absoluteTop.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Get the indexes of the best alternatives + * @return indexes of the best alternatives + */ + private List getBestAlternatives() { + List bestAlternatives = new LinkedList(); + for (int i = 0; i < numAlternatives; i++) { + if (ranking[i] == 0) + bestAlternatives.add(Integer.valueOf(i)); + } + return bestAlternatives; + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeAbsoluteAnyCriticalCriterion() { + + absoluteAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumAbsoluteChangeInCriteriaWeights[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteAny.clear(); + absoluteAny.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteAny.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in relative terms among the best alternative/s and the rest of them + */ + private void computeRelativeTopCriticalCriterion() { + List bestAlternatives = getBestAlternatives(); + + relativeTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumRelativeChangeInCriteriaWeights[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeTop.clear(); + relativeTop.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeRelativeAnyCriticalCriterion() { + + relativeAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumRelativeChangeInCriteriaWeights[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeAny.clear(); + relativeAny.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeAny.add(Integer.valueOf(k)); + } + } + } + } + } + + @Override + public Double[][][] getChanges(FieldsChanges typeOfChange) { + switch(typeOfChange) { + case absolute: + return minimumAbsoluteChangeInCriteriaWeights; + case relative: + return minimumRelativeChangeInCriteriaWeights; + default: + return null; + } + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCFuzzy.java b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCFuzzy.java new file mode 100644 index 0000000..ee37387 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCFuzzy.java @@ -0,0 +1,50 @@ +package flintstones.entity.sensitiveanalysismodel.ahp.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class AnalyticHierarchyProcessMCCFuzzy extends AnalyticHierarchyProcessMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((FuzzyValuation) decisionMatrixAggregation.get(alt, crit)).getFuzzyNumber().getB(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCNumeric.java b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCNumeric.java new file mode 100644 index 0000000..bfb01ae --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCNumeric.java @@ -0,0 +1,49 @@ +package flintstones.entity.sensitiveanalysismodel.ahp.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.numeric.NumericValuation; + +public class AnalyticHierarchyProcessMCCNumeric extends AnalyticHierarchyProcessMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getSubElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getSubElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((NumericValuation) decisionMatrixAggregation.get(alt, crit)).getValue(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCTwoTuple.java b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCTwoTuple.java new file mode 100644 index 0000000..ef90736 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ahp/mcc/AnalyticHierarchyProcessMCCTwoTuple.java @@ -0,0 +1,50 @@ +package flintstones.entity.sensitiveanalysismodel.ahp.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class AnalyticHierarchyProcessMCCTwoTuple extends AnalyticHierarchyProcessMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getSubElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getSubElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((TwoTupleValuation) decisionMatrixAggregation.get(alt, crit)).calculateInverseDelta(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.polyglot.META-INF new file mode 100644 index 0000000..d810da2 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ahp.mcm + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Most critical measure performance model + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.project new file mode 100644 index 0000000..cbb8072 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ahp.mcm + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362575 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c3303fe --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Most critical measure performance model +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ahp.mcm;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.mcm.ahp +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + flintstones.valuation.twoTuple, + flintstones.valuation.numeric, + javax.inject, + org.eclipse.e4.core.di.annotations, + flintstones.valuation.fuzzy +Export-Package: flintstones.entity.sensitiveanalysismodel.ahp.mcm diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/plugin.xml new file mode 100644 index 0000000..6624050 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCM.java b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCM.java new file mode 100644 index 0000000..85a5636 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCM.java @@ -0,0 +1,360 @@ +package flintstones.entity.sensitiveanalysismodel.ahp.mcm; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public abstract class AnalyticHierarchyProcessMCM extends SensitiveAnalysisModel { + + @Inject + @Optional + IProblemElementService problemService; + + protected Double[] alternativesFinalPreferences; + + protected Double[][][] absoluteThresholdValues; + protected Double[][][] relativeThresholdValues; + + protected List absoluteTop; + protected List absoluteAny; + protected List relativeTop; + protected List relativeAny; + + protected int numAlternatives; + protected int numCriteria; + + public AnalyticHierarchyProcessMCM() {} + + public Map getCriteriaWeights() { + return criteriaWeights; + } + + public void setCriteriaWeights(Map criteriaWeights) { + this.criteriaWeights = criteriaWeights; + } + + public Double[] getAlternativesFinalPreferences() { + return alternativesFinalPreferences; + } + + public void setAlternativesFinalPreferences(Double[] alternativesFinalPreferences) { + this.alternativesFinalPreferences = alternativesFinalPreferences; + } + + public Double[][][] getAbsoluteThresholdValues() { + return absoluteThresholdValues; + } + + public void setAbsoluteThresholdValues(Double[][][] absoluteThresholdValues) { + this.absoluteThresholdValues = absoluteThresholdValues; + } + + public Double[][][] getRelativeThresholdValues() { + return relativeThresholdValues; + } + + public void setRelativeThresholdValues(Double[][][] relativeThresholdValues) { + this.relativeThresholdValues = relativeThresholdValues; + } + + public List getAbsoluteTop() { + return absoluteTop; + } + + public void setAbsoluteTop(List absoluteTop) { + this.absoluteTop = absoluteTop; + } + + public List getAbsoluteAny() { + return absoluteAny; + } + + public void setAbsoluteAny(List absoluteAny) { + this.absoluteAny = absoluteAny; + } + + public List getRelativeTop() { + return relativeTop; + } + + public void setRelativeTop(List relativeTop) { + this.relativeTop = relativeTop; + } + + public List getRelativeAny() { + return relativeAny; + } + + public void setRelativeAny(List relativeAny) { + this.relativeAny = relativeAny; + } + + /** + * The most sensitive alternative is computed from the threshold values. + */ + @Override + public void execute(HashMatrix decisionMatrix, + Map criteriaWeights) { + numAlternatives = problemService.getAll(Alternative.Type).length; + numCriteria = problemService.getMainElements(Criterion.Type).length; + + //this.createExampleDecisionMatrix(); + //this.createExampleCriteriaWeights(); + + this.setCriteriaWeights(criteriaWeights); + this.normalizeDecisionMatrix(decisionMatrix); + this.computeFinalPreferences(); + this.computeRanking(); + this.computeAbsoluteThresholdValues(); + this.computeRelativeThresholdValues(); + this.computeAbsoluteTopCriticalAlternative(); + this.computeAbsoluteAnyCriticalAlternative(); + this.computeRelativeTopCriticalAlternative(); + this.computeRelativeAnyCriticalAlternative(); + } + + public void createExampleDecisionMatrix() { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService + .getMainElements(Criterion.Type).length]; + decisionMatrix[0][0] = 0.3088; + decisionMatrix[0][1] = 0.2897; + decisionMatrix[0][2] = 0.3867; + decisionMatrix[0][3] = 0.1922; + + decisionMatrix[1][0] = 0.2163; + decisionMatrix[1][1] = 0.3458; + decisionMatrix[1][2] = 0.1755; + decisionMatrix[1][3] = 0.6288; + + decisionMatrix[2][0] = 0.4509; + decisionMatrix[2][1] = 0.2473; + decisionMatrix[2][2] = 0.1194; + decisionMatrix[2][3] = 0.0575; + + decisionMatrix[3][0] = 0.0240; + decisionMatrix[3][1] = 0.1172; + decisionMatrix[3][2] = 0.3184; + decisionMatrix[3][3] = 0.1215; + } + + public void createExampleCriteriaWeights() { + criteriaWeights = new HashMap<>(); + Criterion c1 = (Criterion) problemService.getById(Criterion.Type, "Criterion 1"); + criteriaWeights.put(c1, 0.3277); + Criterion c2 = (Criterion) problemService.getById(Criterion.Type, "Criterion 2"); + criteriaWeights.put(c2, 0.3058); + Criterion c3 = (Criterion) problemService.getById(Criterion.Type, "Criterion 3"); + criteriaWeights.put(c3, 0.2876); + Criterion c4 = (Criterion) problemService.getById(Criterion.Type, "Criterion 4"); + criteriaWeights.put(c4, 0.0790); + } + + protected abstract void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation); + + private void computeFinalPreferences() { + alternativesFinalPreferences = new Double[numAlternatives]; + for (int alternative = 0; alternative < numAlternatives; alternative++) { + alternativesFinalPreferences[alternative] = 0d; + for (int criterion = 0; criterion < numCriteria; criterion++) { + alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion] * + criteriaWeights.get(problemService.getMainElements(Criterion.Type)[criterion]); + } + } + } + + private void computeRanking() { + ranking = IntStream.range(0, alternativesFinalPreferences.length) + .boxed().sorted((j, i) -> alternativesFinalPreferences[i].compareTo(alternativesFinalPreferences[j])) + .mapToInt(ele -> ele).toArray(); + } + + /** + * Get the indexes of the best alternatives + * @return indexes of the best alternatives + */ + private List getBestAlternatives() { + List bestAlternatives = new LinkedList(); + for (int i = 0; i < numAlternatives; i++) { + if (ranking[i] == 0) + bestAlternatives.add(Integer.valueOf(i)); + } + return bestAlternatives; + } + + private void computeAbsoluteThresholdValues() { + absoluteThresholdValues = new Double[numAlternatives][numAlternatives][numCriteria]; + + double denominator; + Criterion cr; + for (int i = 0; i < numAlternatives; i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + cr = (Criterion) problemService.getMainElements(Criterion.Type)[k]; + if (i != j) { + denominator = alternativesFinalPreferences[i] - alternativesFinalPreferences[j] + criteriaWeights.get(cr) * + ((Double) decisionMatrix[j][k] - (Double) decisionMatrix[i][k] + 1); + if (denominator == 0) + absoluteThresholdValues[i][j][k] = NON_FEASIBLE; + else { + absoluteThresholdValues[i][j][k] = (alternativesFinalPreferences[i] - alternativesFinalPreferences[j]) / denominator; + if (absoluteThresholdValues[i][j][k] > criteriaWeights.get(cr)) + absoluteThresholdValues[i][j][k] = NON_FEASIBLE; + } + } + } + } + } + } + + private void computeRelativeThresholdValues() { + relativeThresholdValues = new Double[numAlternatives][numAlternatives][numCriteria]; + + for (int i = 0; i < numAlternatives; i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + if (absoluteThresholdValues[i][j][k] != NON_FEASIBLE) { + if ((Double) decisionMatrix[i][k] == 0) + relativeThresholdValues[i][j][k] = NON_FEASIBLE; + else + relativeThresholdValues[i][j][k] = absoluteThresholdValues[i][j][k] * (100d / (Double) decisionMatrix[i][k]); + } else + relativeThresholdValues[i][j][k] = NON_FEASIBLE; + } + } + } + } + + /** + * Look for the minimal change in absolute terms among the best alternative/s + * and the rest of them + */ + private void computeAbsoluteTopCriticalAlternative() { + List bestAlternatives = getBestAlternatives(); + + absoluteTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = absoluteThresholdValues[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteTop.clear(); + absoluteTop.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeAbsoluteAnyCriticalAlternative() { + + absoluteAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = absoluteThresholdValues[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteAny.clear(); + absoluteAny.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteAny.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in relative terms among the best alternative/s + * and the rest of them + */ + private void computeRelativeTopCriticalAlternative() { + List bestAlternatives = getBestAlternatives(); + + relativeTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = relativeThresholdValues[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeTop.clear(); + relativeTop.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeRelativeAnyCriticalAlternative() { + + relativeAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = relativeThresholdValues[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeAny.clear(); + relativeAny.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeAny.add(Integer.valueOf(k)); + } + } + } + } + } + + @Override + public Double[][][] getChanges(FieldsChanges typeOfChange) { + switch(typeOfChange) { + case absolute: + return absoluteThresholdValues; + case relative: + return relativeThresholdValues; + default: + return null; + } + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMFuzzy.java b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMFuzzy.java new file mode 100644 index 0000000..d13d72b --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMFuzzy.java @@ -0,0 +1,50 @@ +package flintstones.entity.sensitiveanalysismodel.ahp.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class AnalyticHierarchyProcessMCMFuzzy extends AnalyticHierarchyProcessMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((FuzzyValuation) decisionMatrixAggregation.get(alt, crit)).getFuzzyNumber().getB(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMNumeric.java b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMNumeric.java new file mode 100644 index 0000000..1f28ef1 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMNumeric.java @@ -0,0 +1,49 @@ +package flintstones.entity.sensitiveanalysismodel.ahp.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.numeric.NumericValuation; + +public class AnalyticHierarchyProcessMCMNumeric extends AnalyticHierarchyProcessMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getSubElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getSubElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((NumericValuation) decisionMatrixAggregation.get(alt, crit)).getValue(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMTwoTuple.java b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMTwoTuple.java new file mode 100644 index 0000000..36789ba --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ahp/mcm/AnalyticHierarchyProcessMCMTwoTuple.java @@ -0,0 +1,50 @@ +package flintstones.entity.sensitiveanalysismodel.ahp.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class AnalyticHierarchyProcessMCMTwoTuple extends AnalyticHierarchyProcessMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getSubElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getSubElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((TwoTupleValuation) decisionMatrixAggregation.get(alt, crit)).calculateInverseDelta(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.polyglot.META-INF new file mode 100644 index 0000000..f291aa1 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] AHP sensitive analysis model ui + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.project new file mode 100644 index 0000000..1592db0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362576 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c703a97 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: AHP sensitive analysis model ui +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel.ui, + flintstones.entity.sensitiveanalysismodel.ahp.mcc;bundle-version="1.0.0", + flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + flintstones.helper.html, + org.eclipse.swt, + javax.inject, + org.jfree.chart.jfreechart, + org.eclipse.e4.core.services diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/plugin.xml new file mode 100644 index 0000000..e4ee7b3 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/AnalyticHierarchyProcessUI.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/AnalyticHierarchyProcessUI.java new file mode 100644 index 0000000..c8167dc --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/AnalyticHierarchyProcessUI.java @@ -0,0 +1,111 @@ +package flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc; + +import javax.inject.Inject; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel.FieldsChanges; +import flintstones.entity.sensitiveanalysismodel.ahp.mcc.AnalyticHierarchyProcessMCC; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; +import flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc.chart.AHPRankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc.messages.Messages; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; +import flintstones.helper.html.table.HtmlTextTable; + +public class AnalyticHierarchyProcessUI extends SensitiveAnalysisModelUi { + + @Inject + @Translation + Messages messages; + + public AnalyticHierarchyProcessUI() {} + + @Override + public HtmlTextTable createRankingTable(Composite rankingSection) { + String[] rowHeader = getOrderedAlternatives(model.getRanking()); + String[] colHeader = new String[] {messages.Preference, "Ranking"}; //$NON-NLS-1$ + + rankingTable = new HtmlTextTable(rankingSection, loadRanking(model.getRanking(), + ((AnalyticHierarchyProcessMCC) model).getAlternativesFinalPreferences(), + rowHeader.length, colHeader.length), colHeader, rowHeader); + return rankingTable; + } + + private String[] getOrderedAlternatives(int[] ranking) { + String[] orderedAlternatives = new String[ranking.length]; + String[] shorterAlternatives = getShortenedAlternativesNames(); + + for(int i = 0; i < orderedAlternatives.length; ++i) + orderedAlternatives[i] = shorterAlternatives[ranking[i]]; + + return orderedAlternatives; + } + + private String[][] loadRanking(int[] ranking, Double[] preferences, int numRows, int numCols) { + String[][] valuesSTR = new String [numRows][numCols]; + + int rank = 1; + for(int i = 0; i < valuesSTR.length; i++) { + valuesSTR[i][0] = "" + Math.round(preferences[ranking[i]] * 100000d) / 100000d; //$NON-NLS-1$ + for(int j = 1; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = "" + (rank++); //$NON-NLS-1$ + } + return valuesSTR; + } + + @Override + public HtmlTextTable createChangesTable(Composite changesSection, FieldsChanges typeChange) { + String[] rowHeader = getShortenedPairAlternativesNames(); + String[] colHeader = getShortenedCriteriaNames(); + + changesTable = new HtmlTextTable(changesSection, loadChanges(model.getChanges(typeChange), rowHeader.length, colHeader.length), + colHeader, rowHeader); + return changesTable; + } + + @SuppressWarnings("static-access") + private String[][] loadChanges(Double[][][] changes, int numRows, int numCols) { + String[][] valuesSTR = new String[numRows][numCols]; + + Double change; + int cont = 0; + for(int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for(int j = i + 1; j < model.getDecisionMatrix().length; ++j) { + for(int k = 0; k < valuesSTR[i].length; k++) { + change = changes[i][j][k]; + if(change == model.NON_FEASIBLE) + valuesSTR[cont][k] = "N/F"; //$NON-NLS-1$ + else + valuesSTR[cont][k] = "" + Math.round(change * 10000d) / 10000d; //$NON-NLS-1$ + } + cont++; + } + } + return valuesSTR; + } + + @Override + public void refreshChangesTable(FieldsChanges typeChange) { + changesTable.refresh(loadChanges(model.getChanges(typeChange), changesTable.getNumberOfRows(), + changesTable.getNumberOfColumns())); + changesTable.render(); + + } + + @Override + public void refreshRankingTable() { + rankingTable.refresh(loadRanking(model.getRanking(), + ((AnalyticHierarchyProcessMCC) model).getAlternativesFinalPreferences(), + rankingTable.getNumberOfRows(), rankingTable.getNumberOfColumns())); + rankingTable.render(); + } + + @Override + public RankingEvolutionChart createRankingEvolutionChart(Composite container, ProblemElement[] criteria, Criterion criterion, int width, int height, int style) { + chart = new AHPRankingEvolutionChart(); + chart.initialize(model, criteria, criterion, container, width, height, style); + return chart; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/chart/AHPRankingEvolutionChart.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/chart/AHPRankingEvolutionChart.java new file mode 100644 index 0000000..7b6727f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/chart/AHPRankingEvolutionChart.java @@ -0,0 +1,88 @@ +package flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc.chart; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; + +public class AHPRankingEvolutionChart extends RankingEvolutionChart { + + @Override + public XYDataset createDataset() { + dataset = new XYSeriesCollection(); + + List alternativesSeries = computeEvolutionChart(); + for (XYSeries xySerie : alternativesSeries) { + dataset.addSeries(xySerie); + } + + return dataset; + } + + private List computeEvolutionChart() { + + List alternativesSeries = generateXYSeries(); + + Double[] preferences; + for (double j = 0.01; j <= 1.0; j += 0.01) { + preferences = computeFinalPreferences(computeInferredWeights(j)); + for (int s = 0; s < alternativesSeries.size(); ++s) { + XYSeries serie = alternativesSeries.get(s); + serie.add(Math.round(j * 100d) / 100d, preferences[s]); + } + } + + return alternativesSeries; + } + + private List generateXYSeries() { + List alternativesSeries = new LinkedList(); + for (int i = 0; i < model.getDecisionMatrix().length; ++i) { + XYSeries serie = new XYSeries("A"+ (i + 1)); + serie.add(0, 0); + alternativesSeries.add(serie); + } + + return alternativesSeries; + } + + private Double[] computeFinalPreferences(Double[] inferredWeights) { + Double[][] decisionMatrix = model.getDecisionMatrix(); + + Double[] alternativesFinalPreferences = new Double[decisionMatrix.length]; + for (int alternative = 0; alternative < alternativesFinalPreferences.length; alternative++) { + alternativesFinalPreferences[alternative] = 0d; + for (int criterion = 0; criterion < this.criteria.length; criterion++) { + alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion] * + inferredWeights[criterion]; + } + } + return alternativesFinalPreferences; + } + + private Double[] computeInferredWeights(double evolutionWeight) { + Map criteriaWeights = model.getCriteriaWeights(); + Double[] inferWeights = new Double[criteriaWeights.size()]; + + List criteria = Arrays.asList(this.criteria); + + int indexSelectedCriterion = criteria.indexOf(criterion); + inferWeights[indexSelectedCriterion] = evolutionWeight; + + for (ProblemElement cr: criteria) { + if (!cr.equals(criterion)) + inferWeights[criteria.indexOf(cr)] = ((1d - evolutionWeight) / + (1d - criteriaWeights.get(criterion))) * criteriaWeights.get(cr); + } + + return inferWeights; + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/Messages.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/Messages.java new file mode 100644 index 0000000..25eafc1 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/Messages.java @@ -0,0 +1,7 @@ +package flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc.messages; + +public class Messages { + + public String Preference; + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/messages.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/messages.properties new file mode 100644 index 0000000..d3b8871 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/messages.properties @@ -0,0 +1 @@ +Preference=Preference diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/messages_es.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/messages_es.properties new file mode 100644 index 0000000..9238aed --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcc/messages/messages_es.properties @@ -0,0 +1 @@ +Preference=Preferencia diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.polyglot.META-INF new file mode 100644 index 0000000..89ffe32 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Analytic hierarchy process sensitive analysis model ui + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.project new file mode 100644 index 0000000..d53b2bb --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362577 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f31ac2c --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Analytic hierarchy process sensitive analysis model ui +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel.ahp.mcm, + flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + flintstones.entity.sensitiveanalysismodel.ui, + flintstones.helper.html, + org.eclipse.swt, + javax.inject, + org.jfree.chart.jfreechart, + org.eclipse.e4.core.services diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/plugin.xml new file mode 100644 index 0000000..507e121 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/AnalyticHierarchyProcessUI.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/AnalyticHierarchyProcessUI.java new file mode 100644 index 0000000..e2bc147 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/AnalyticHierarchyProcessUI.java @@ -0,0 +1,112 @@ +package flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm; + +import javax.inject.Inject; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel.FieldsChanges; +import flintstones.entity.sensitiveanalysismodel.ahp.mcm.AnalyticHierarchyProcessMCM; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; +import flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm.chart.AHPRankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm.messages.Messages; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; +import flintstones.helper.html.table.HtmlTextTable;; + +public class AnalyticHierarchyProcessUI extends SensitiveAnalysisModelUi { + + @Inject + @Translation + Messages messages; + + public AnalyticHierarchyProcessUI() {} + + @Override + public HtmlTextTable createRankingTable(Composite rankingSection) { + String[] rowHeader = getOrderedAlternatives(model.getRanking()); + String[] colHeader = new String[] {messages.Preference, "Ranking"};//$NON-NLS-1$ + + rankingTable = new HtmlTextTable(rankingSection, loadRanking(model.getRanking(), + ((AnalyticHierarchyProcessMCM) model).getAlternativesFinalPreferences(), + rowHeader.length, colHeader.length), colHeader, rowHeader); + return rankingTable; + } + + private String[] getOrderedAlternatives(int[] ranking) { + String[] orderedAlternatives = new String[ranking.length]; + String[] shorterAlternatives = getShortenedAlternativesNames(); + + for(int i = 0; i < orderedAlternatives.length; ++i) + orderedAlternatives[i] = shorterAlternatives[ranking[i]]; + + return orderedAlternatives; + } + + private String[][] loadRanking(int[] ranking, Double[] preferences, int numRows, int numCols) { + String[][] valuesSTR = new String [numRows][numCols]; + + int rank = 1; + for(int i = 0; i < valuesSTR.length; i++) { + valuesSTR[i][0] = "" + Math.round(preferences[ranking[i]] * 100000d) / 100000d;; + for(int j = 1; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = "" + (rank++); + } + return valuesSTR; + } + + @Override + public HtmlTextTable createChangesTable(Composite changesSection, FieldsChanges typeChange) { + String[] rowHeader = getShortenedAllPairAlternativesNames(); + String[] colHeader = getShortenedCriteriaNames(); + + changesTable = new HtmlTextTable(changesSection, loadChanges(model.getChanges(typeChange), rowHeader.length, colHeader.length), + colHeader, rowHeader); + return changesTable; + } + + @SuppressWarnings("static-access") + private String[][] loadChanges(Double[][][] changes, int numRows, int numCols) { + String[][] valuesSTR = new String [numRows][numCols]; + + Double change; + int cont = 0; + for(int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for(int j = 0; j < model.getDecisionMatrix().length; ++j) { + if(i != j) { + for(int k = 0; k < valuesSTR[i].length; k++) { + change = changes[i][j][k]; + if(change == model.NON_FEASIBLE) + valuesSTR[cont][k] = "N/F"; + else + valuesSTR[cont][k] = "" + Math.round(change * 10000d) / 10000d; + } + cont++; + } + } + } + return valuesSTR; + } + + @Override + public void refreshChangesTable(FieldsChanges typeChange) { + changesTable.refresh(loadChanges(model.getChanges(typeChange), changesTable.getNumberOfRows(), + changesTable.getNumberOfColumns())); + changesTable.render(); + } + + @Override + public void refreshRankingTable() { + rankingTable.refresh(loadRanking(model.getRanking(), + ((AnalyticHierarchyProcessMCM) model).getAlternativesFinalPreferences(), + rankingTable.getNumberOfRows(), rankingTable.getNumberOfColumns())); + rankingTable.render(); + } + + @Override + public RankingEvolutionChart createRankingEvolutionChart(Composite container, ProblemElement[] criteria, Criterion criterion, int width, int height, int style) { + chart = new AHPRankingEvolutionChart(); + chart.initialize(model, criteria, criterion, container, width, height, style); + return chart; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/chart/AHPRankingEvolutionChart.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/chart/AHPRankingEvolutionChart.java new file mode 100644 index 0000000..45b612c --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/chart/AHPRankingEvolutionChart.java @@ -0,0 +1,88 @@ +package flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm.chart; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; + +public class AHPRankingEvolutionChart extends RankingEvolutionChart { + + @Override + public XYDataset createDataset() { + dataset = new XYSeriesCollection(); + + List alternativesSeries = computeEvolutionChart(); + for (XYSeries xySerie : alternativesSeries) { + dataset.addSeries(xySerie); + } + + return dataset; + } + + private List computeEvolutionChart() { + + List alternativesSeries = generateXYSeries(); + + Double[] preferences; + for (double j = 0.01; j <= 1.0; j += 0.01) { + preferences = computeFinalPreferences(computeInferredWeights(j)); + for (int s = 0; s < alternativesSeries.size(); ++s) { + XYSeries serie = alternativesSeries.get(s); + serie.add(Math.round(j * 100d) / 100d, preferences[s]); + } + } + + return alternativesSeries; + } + + private List generateXYSeries() { + List alternativesSeries = new LinkedList(); + for (int i = 0; i < model.getDecisionMatrix().length; ++i) { + XYSeries serie = new XYSeries("A"+ (i + 1)); + serie.add(0, 0); + alternativesSeries.add(serie); + } + + return alternativesSeries; + } + + private Double[] computeInferredWeights(double evolutionWeight) { + Map criteriaWeights = model.getCriteriaWeights(); + Double[] inferWeights = new Double[criteriaWeights.size()]; + + List criteria = Arrays.asList(this.criteria); + + int indexSelectedCriterion = criteria.indexOf(criterion); + inferWeights[indexSelectedCriterion] = evolutionWeight; + + for (ProblemElement cr: criteria) { + if (!cr.equals(criterion)) + inferWeights[criteria.indexOf(cr)] = ((1d - evolutionWeight) / + (1d - criteriaWeights.get(criterion))) * criteriaWeights.get(cr); + } + + return inferWeights; + } + + private Double[] computeFinalPreferences(Double[] inferredWeights) { + Double[][] decisionMatrix = model.getDecisionMatrix(); + + Double[] alternativesFinalPreferences = new Double[decisionMatrix.length]; + for (int alternative = 0; alternative < alternativesFinalPreferences.length; alternative++) { + alternativesFinalPreferences[alternative] = 0d; + for (int criterion = 0; criterion < this.criteria.length; criterion++) { + alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion] * + inferredWeights[criterion]; + } + } + return alternativesFinalPreferences; + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/Messages.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/Messages.java new file mode 100644 index 0000000..d707474 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/Messages.java @@ -0,0 +1,7 @@ +package flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm.messages; + +public class Messages { + + public String Preference; + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/messages.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/messages.properties new file mode 100644 index 0000000..d3b8871 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/messages.properties @@ -0,0 +1 @@ +Preference=Preference diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/messages_es.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/messages_es.properties new file mode 100644 index 0000000..9238aed --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.ahp.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/ahp/mcm/messages/messages_es.properties @@ -0,0 +1 @@ +Preference=Preferencia diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.polyglot.META-INF new file mode 100644 index 0000000..8c4d22c --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] WPM sensitive analysis model ui + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.project new file mode 100644 index 0000000..ca904c8 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362578 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d37947d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: WPM sensitive analysis model ui +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel.wpm.mcc, + flintstones.entity.sensitiveanalysismodel.ui, + flintstones.helper.html, + flintstones.entity.sensitiveanalysismodel, + org.eclipse.swt, + flintstones.model.problemelement.service, + javax.inject, + org.jfree.chart.jfreechart diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/plugin.xml new file mode 100644 index 0000000..0fc3fe3 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcc/WeightedProductModelUI.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcc/WeightedProductModelUI.java new file mode 100644 index 0000000..bd5292f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcc/WeightedProductModelUI.java @@ -0,0 +1,113 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc; + +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel.FieldsChanges; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc.chart.WPMRankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.wpm.mcc.WeightedProductModelMCC; +import flintstones.helper.html.table.HtmlTextTable; + +public class WeightedProductModelUI extends SensitiveAnalysisModelUi { + + public WeightedProductModelUI() {} + + @Override + public HtmlTextTable createRankingTable(Composite rankingSection) { + String[] rowHeader = getShortenedPairAlternativesNames(); + String[] colHeader = new String[] {"Ratio", "Ranking"};//$NON-NLS-1$ $NON-NLS-2$ + + rankingTable = new HtmlTextTable(rankingSection, loadRanking(model.getRanking(), + ((WeightedProductModelMCC) model).getAlternativesRatioFinalPreferences(), + rowHeader.length, colHeader.length), colHeader, rowHeader); + return rankingTable; + } + + private String[][] loadRanking(int[] ranking, Double[][] preferences, int numRows, int numCols) { + String[][] valuesSTR = initialize(numRows, numCols); + + //Preferences + int cont = 0; + double preference; + for(int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for(int j = i + 1; j < model.getDecisionMatrix().length; ++j) { + preference = Math.round(preferences[i][j] * 100000d) / 100000d; + valuesSTR[cont][0] = "" + preference; + cont++; + } + } + + //Ranking + for(int i = 0; i < model.getDecisionMatrix().length; ++i) + valuesSTR[i][1] = "A" + (i + 1) + "->" + ranking[i]; + + return valuesSTR; + } + + private String[][] initialize(int numRows, int numCols) { + String[][] valueSTR = new String[numRows][numCols]; + + for(int i = 0; i < valueSTR.length; ++i) { + for(int j = 0; j < valueSTR[i].length; ++j) { + valueSTR[i][j] = ""; + } + } + return valueSTR; + } + + @Override + public HtmlTextTable createChangesTable(Composite changesSection, FieldsChanges typeChange) { + String[] rowHeader = getShortenedPairAlternativesNames(); + String[] colHeader = getShortenedCriteriaNames(); + + changesTable = new HtmlTextTable(changesSection, loadChanges(model.getChanges(typeChange), rowHeader.length, colHeader.length), + colHeader, rowHeader); + return changesTable; + } + + @SuppressWarnings("static-access") + private String[][] loadChanges(Double[][][] changes, int numRows, int numCols) { + String[][] valuesSTR = new String[numRows][numCols]; + + Double change; + int cont = 0; + for(int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for(int j = i + 1; j < model.getDecisionMatrix().length; ++j) { + for(int k = 0; k < valuesSTR[i].length; k++) { + change = changes[i][j][k]; + if(change == model.NON_FEASIBLE) + valuesSTR[cont][k] = "N/F"; + else + valuesSTR[cont][k] = "" + Math.round(change * 10000d) / 10000d; + } + cont++; + } + } + return valuesSTR; + } + + @Override + public void refreshChangesTable(FieldsChanges typeChange) { + changesTable.refresh(loadChanges(model.getChanges(typeChange), changesTable.getNumberOfRows(), + changesTable.getNumberOfColumns())); + changesTable.render(); + } + + @Override + public void refreshRankingTable() { + rankingTable.refresh(loadRanking(model.getRanking(), + ((WeightedProductModelMCC) model).getAlternativesRatioFinalPreferences(), + rankingTable.getNumberOfRows(), rankingTable.getNumberOfColumns())); + rankingTable.render(); + } + + @Override + public RankingEvolutionChart createRankingEvolutionChart(Composite container, ProblemElement[] criteria, Criterion criterion, int width, int height, int style) { + chart = new WPMRankingEvolutionChart(); + chart.initialize(model, criteria, criterion, container, width, height, style); + return chart; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcc/chart/WPMRankingEvolutionChart.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcc/chart/WPMRankingEvolutionChart.java new file mode 100644 index 0000000..8612aea --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcc/chart/WPMRankingEvolutionChart.java @@ -0,0 +1,76 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wpm.mcc.chart; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; + +public class WPMRankingEvolutionChart extends RankingEvolutionChart { + + @Override + public XYDataset createDataset() { + dataset = new XYSeriesCollection(); + + List alternativesSeries = computeEvolutionChart(); + for (XYSeries xySerie : alternativesSeries) { + dataset.addSeries(xySerie); + } + + return dataset; + } + + private List computeEvolutionChart() { + List alternativeSeries = new LinkedList<>(); + + Double preference; + for (int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for (int j = (i + 1); j < model.getDecisionMatrix().length; ++j) { + XYSeries serie = new XYSeries("A" + (i + 1) + " - " + "A" + (j + 1)); //$NON-NLS-1$ + for (double k = 0.01; k <= 1.01; k += 0.01) { + preference = computeAlternativeRatioFinalPreferenceInferWeights(i, j, computeInferredWeights(j)); + serie.add(Math.round(k * 100d) / 100d, preference); + } + alternativeSeries.add(serie); + } + } + + return alternativeSeries; + } + + private Double computeAlternativeRatioFinalPreferenceInferWeights(int a1, int a2, Double[] w) { + Double[][] decisionMatrix = model.getDecisionMatrix(); + + double alternativeRatioFinalPreference = 1; + for (int criterion = 0; criterion < this.criteria.length; criterion++) { + alternativeRatioFinalPreference *= Math.pow(((Double) decisionMatrix[a1][criterion] / (Double) decisionMatrix[a2][criterion]), + w[criterion]); + } + + return alternativeRatioFinalPreference; + } + + private Double[] computeInferredWeights(double evolutionWeight) { + Map criteriaWeights = model.getCriteriaWeights(); + Double[] inferWeights = new Double[criteriaWeights.size()]; + + List criteria = Arrays.asList(this.criteria); + + int indexSelectedCriterion = criteria.indexOf(criterion); + inferWeights[indexSelectedCriterion] = evolutionWeight; + + for (ProblemElement cr: criteria) { + if (!cr.equals(criterion)) + inferWeights[criteria.indexOf(cr)] = ((1d - evolutionWeight) / + (1d - criteriaWeights.get(criterion))) * criteriaWeights.get(cr); + } + + return inferWeights; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.polyglot.META-INF new file mode 100644 index 0000000..07aca98 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] WPM sensitive analysis model ui + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.project new file mode 100644 index 0000000..fa0ca43 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362579 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0587eb4 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: WPM sensitive analysis model ui +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel.wpm.mcm, + flintstones.entity.sensitiveanalysismodel.ui, + javax.inject, + flintstones.model.problemelement.service, + flintstones.helper.html, + org.eclipse.swt, + flintstones.entity.sensitiveanalysismodel, + org.jfree.chart.jfreechart diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/plugin.xml new file mode 100644 index 0000000..b18236d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcm/WeightedProductModelUI.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcm/WeightedProductModelUI.java new file mode 100644 index 0000000..cf53887 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcm/WeightedProductModelUI.java @@ -0,0 +1,115 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm; + +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel.FieldsChanges; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm.chart.WPMRankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.wpm.mcm.WeightedProductModelMCMTwoTuple; +import flintstones.helper.html.table.HtmlTextTable; + +public class WeightedProductModelUI extends SensitiveAnalysisModelUi { + + public WeightedProductModelUI() {} + + @Override + public HtmlTextTable createRankingTable(Composite rankingSection) { + String[] rowHeader = getShortenedPairAlternativesNames(); + String[] colHeader = new String[] {"Ratio", "Ranking"};//$NON-NLS-1$ $NON-NLS-2$ + + rankingTable = new HtmlTextTable(rankingSection, loadRanking(model.getRanking(), + ((WeightedProductModelMCMTwoTuple) model).getAlternativesRatioFinalPreferences(), + rowHeader.length, colHeader.length), colHeader, rowHeader); + return rankingTable; + } + + private String[][] loadRanking(int[] ranking, Double[][] preferences, int numRows, int numCols) { + String[][] valuesSTR = initialize(numRows, numCols); + + //Preferences + int cont = 0; + double preference; + for(int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for(int j = i + 1; j < model.getDecisionMatrix().length; ++j) { + preference = Math.round(preferences[i][j] * 100000d) / 100000d; + valuesSTR[cont][0] = "" + preference; + cont++; + } + } + + //Ranking + for(int i = 0; i < model.getDecisionMatrix().length; ++i) + valuesSTR[i][1] = "A" + (i + 1) + "->" + ranking[i]; + + return valuesSTR; + } + + private String[][] initialize(int numRows, int numCols) { + String[][] valueSTR = new String[numRows][numCols]; + + for(int i = 0; i < valueSTR.length; ++i) { + for(int j = 0; j < valueSTR[i].length; ++j) { + valueSTR[i][j] = ""; + } + } + return valueSTR; + } + + @Override + public HtmlTextTable createChangesTable(Composite changesSection, FieldsChanges typeChange) { + String[] rowHeader = getShortenedAllPairAlternativesNames(); + String[] colHeader = getShortenedCriteriaNames(); + + changesTable = new HtmlTextTable(changesSection, loadChanges(model.getChanges(typeChange), rowHeader.length, colHeader.length), + colHeader, rowHeader); + return changesTable; + } + + @SuppressWarnings("static-access") + private String[][] loadChanges(Double[][][] changes, int numRows, int numCols) { + String[][] valuesSTR = new String[numRows][numCols]; + + Double change; + int cont = 0; + for(int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for(int j = 0; j < model.getDecisionMatrix().length; ++j) { + if(i != j) { + for(int k = 0; k < valuesSTR[i].length; k++) { + change = changes[i][j][k]; + if(change == model.NON_FEASIBLE) + valuesSTR[cont][k] = "N/F"; + else + valuesSTR[cont][k] = "" + Math.round(change * 10000d) / 10000d; + } + cont++; + } + } + } + return valuesSTR; + } + + @Override + public void refreshChangesTable(FieldsChanges typeChange) { + changesTable.refresh(loadChanges(model.getChanges(typeChange), changesTable.getNumberOfRows(), + changesTable.getNumberOfColumns())); + changesTable.render(); + } + + @Override + public void refreshRankingTable() { + rankingTable.refresh(loadRanking(model.getRanking(), + ((WeightedProductModelMCMTwoTuple) model).getAlternativesRatioFinalPreferences(), + rankingTable.getNumberOfRows(), rankingTable.getNumberOfColumns())); + rankingTable.render(); + } + + @Override + public RankingEvolutionChart createRankingEvolutionChart(Composite container, ProblemElement[] criteria, Criterion criterion, int width, int height, int style) { + chart = new WPMRankingEvolutionChart(); + chart.initialize(model, criteria, criterion, container, width, height, style); + return chart; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcm/chart/WPMRankingEvolutionChart.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcm/chart/WPMRankingEvolutionChart.java new file mode 100644 index 0000000..54b4d8e --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wpm/mcm/chart/WPMRankingEvolutionChart.java @@ -0,0 +1,75 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wpm.mcm.chart; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; + +public class WPMRankingEvolutionChart extends RankingEvolutionChart { + + @Override + public XYDataset createDataset() { + dataset = new XYSeriesCollection(); + + List alternativesSeries = computeEvolutionChart(); + for (XYSeries xySerie : alternativesSeries) { + dataset.addSeries(xySerie); + } + + return dataset; + } + + private List computeEvolutionChart() { + List alternativeSeries = new LinkedList<>(); + + Double preference; + for (int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for (int j = (i + 1); j < model.getDecisionMatrix().length; ++j) { + XYSeries serie = new XYSeries("A" + (i + 1) + " - " + "A" + (j + 1)); //$NON-NLS-1$ + for (double k = 0.01; k <= 1.01; k += 0.01) { + preference = computeAlternativeRatioFinalPreferenceInferWeights(i, j, computeInferredWeights(j)); + serie.add(Math.round(k * 100d) / 100d, preference); + } + alternativeSeries.add(serie); + } + } + return alternativeSeries; + } + + private Double computeAlternativeRatioFinalPreferenceInferWeights(int a1, int a2, Double[] w) { + Double[][] decisionMatrix = model.getDecisionMatrix(); + + double alternativeRatioFinalPreference = 1; + for (int criterion = 0; criterion < this.criteria.length; criterion++) { + alternativeRatioFinalPreference *= Math.pow(((Double) decisionMatrix[a1][criterion] / (Double) decisionMatrix[a2][criterion]), + w[criterion]); + } + + return alternativeRatioFinalPreference; + } + + private Double[] computeInferredWeights(double evolutionWeight) { + Map criteriaWeights = model.getCriteriaWeights(); + Double[] inferWeights = new Double[criteriaWeights.size()]; + + List criteria = Arrays.asList(this.criteria); + + int indexSelectedCriterion = criteria.indexOf(criterion); + inferWeights[indexSelectedCriterion] = evolutionWeight; + + for (ProblemElement cr: criteria) { + if (!cr.equals(criterion)) + inferWeights[criteria.indexOf(cr)] = ((1d - evolutionWeight) / + (1d - criteriaWeights.get(criterion))) * criteriaWeights.get(cr); + } + + return inferWeights; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.polyglot.META-INF new file mode 100644 index 0000000..effb0ed --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] WSM sensitive analysis model ui + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.project new file mode 100644 index 0000000..985d72a --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362579 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/META-INF/MANIFEST.MF new file mode 100644 index 0000000..14ed8fb --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: WSM sensitive analysis model ui +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel.wsm.mcc, + flintstones.entity.sensitiveanalysismodel.ui, + flintstones.helper.html, + flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + javax.inject, + org.eclipse.swt, + org.jfree.chart.jfreechart, + org.eclipse.e4.core.services diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/plugin.xml new file mode 100644 index 0000000..c438c5c --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/WeightedSumModelUI.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/WeightedSumModelUI.java new file mode 100644 index 0000000..9bda005 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/WeightedSumModelUI.java @@ -0,0 +1,108 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc; + +import javax.inject.Inject; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel.FieldsChanges; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc.chart.WSMRankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc.messages.Messages; +import flintstones.entity.sensitiveanalysismodel.wsm.mcc.WeightedSumModelMCC; +import flintstones.helper.html.table.HtmlTextTable; + +public class WeightedSumModelUI extends SensitiveAnalysisModelUi { + + @Inject + @Translation + Messages messages; + + @Override + public HtmlTextTable createRankingTable(Composite rankingSection) { + String[] rowHeader = getOrderedAlternatives(model.getRanking()); + String[] colHeader = new String[] {messages.Preference, "Ranking"};//$NON-NLS-1$ + + rankingTable = new HtmlTextTable(rankingSection, loadRanking(model.getRanking(), + ((WeightedSumModelMCC) model).getAlternativesFinalPreferences(), rowHeader.length, colHeader.length), colHeader, rowHeader); + return rankingTable; + } + + private String[] getOrderedAlternatives(int[] ranking) { + String[] orderedAlternatives = new String[ranking.length]; + String[] shorterAlternatives = getShortenedAlternativesNames(); + + for(int i = 0; i < orderedAlternatives.length; ++i) + orderedAlternatives[i] = shorterAlternatives[ranking[i]]; + + return orderedAlternatives; + } + + private String[][] loadRanking(int[] ranking, Double[] preferences, int numRows, int numCols) { + String[][] valuesSTR = new String [numRows][numCols]; + + int rank = 1; + for(int i = 0; i < valuesSTR.length; i++) { + valuesSTR[i][0] = "" + Math.round(preferences[ranking[i]] * 100000d) / 100000d; + for(int j = 1; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = "" + (rank++); + } + return valuesSTR; + } + + @Override + public HtmlTextTable createChangesTable(Composite changesSection, FieldsChanges typeChange) { + String[] rowHeader = getShortenedPairAlternativesNames(); + String[] colHeader = getShortenedCriteriaNames(); + + changesTable = new HtmlTextTable(changesSection, loadChanges(model.getChanges(typeChange), rowHeader.length, colHeader.length), + colHeader, rowHeader); + return changesTable; + } + + @SuppressWarnings("static-access") + private String[][] loadChanges(Double[][][] changes, int numRows, int numCols) { + String[][] valuesSTR = new String[numRows][numCols]; + + Double change; + int cont = 0; + for(int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for(int j = i + 1; j < model.getDecisionMatrix().length; ++j) { + for(int k = 0; k < valuesSTR[i].length; k++) { + change = changes[i][j][k]; + if(change == model.NON_FEASIBLE) + valuesSTR[cont][k] = "N/F"; + else + valuesSTR[cont][k] = "" + Math.round(change * 10000d) / 10000d; + } + cont++; + } + } + return valuesSTR; + } + + @Override + public void refreshChangesTable(FieldsChanges typeChange) { + changesTable.refresh(loadChanges(model.getChanges(typeChange), changesTable.getNumberOfRows(), + changesTable.getNumberOfColumns())); + changesTable.render(); + + } + + @Override + public void refreshRankingTable() { + rankingTable.refresh(loadRanking(model.getRanking(), + ((WeightedSumModelMCC) model).getAlternativesFinalPreferences(), + rankingTable.getNumberOfRows(), rankingTable.getNumberOfColumns())); + rankingTable.render(); + } + + @Override + public RankingEvolutionChart createRankingEvolutionChart(Composite container, ProblemElement[] criteria, Criterion criterion, int width, int height, int style) { + chart = new WSMRankingEvolutionChart(); + chart.initialize(model, criteria, criterion, container, width, height, style); + return chart; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/chart/WSMRankingEvolutionChart.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/chart/WSMRankingEvolutionChart.java new file mode 100644 index 0000000..27b87ed --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/chart/WSMRankingEvolutionChart.java @@ -0,0 +1,88 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc.chart; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; + +public class WSMRankingEvolutionChart extends RankingEvolutionChart { + + @Override + public XYDataset createDataset() { + dataset = new XYSeriesCollection(); + + List alternativesSeries = computeEvolutionChart(); + for (XYSeries xySerie : alternativesSeries) { + dataset.addSeries(xySerie); + } + + return dataset; + } + + private List computeEvolutionChart() { + + List alternativesSeries = generateXYSeries(); + + Double[] preferences; + for (double j = 0.01; j <= 1.0; j += 0.01) { + preferences = computeFinalPreferences(computeInferredWeights(j)); + for (int s = 0; s < alternativesSeries.size(); ++s) { + XYSeries serie = alternativesSeries.get(s); + serie.add(Math.round(j * 100d) / 100d, preferences[s]); + } + } + + return alternativesSeries; + } + + private List generateXYSeries() { + List alternativesSeries = new LinkedList(); + for (int i = 0; i < model.getDecisionMatrix().length; ++i) { + XYSeries serie = new XYSeries("A"+ (i + 1)); + serie.add(0, 0); + alternativesSeries.add(serie); + } + + return alternativesSeries; + } + + private Double[] computeInferredWeights(double evolutionWeight) { + Map criteriaWeights = model.getCriteriaWeights(); + Double[] inferWeights = new Double[criteriaWeights.size()]; + + List criteria = Arrays.asList(this.criteria); + + int indexSelectedCriterion = criteria.indexOf(criterion); + inferWeights[indexSelectedCriterion] = evolutionWeight; + + for (ProblemElement cr: criteria) { + if (!cr.equals(criterion)) + inferWeights[criteria.indexOf(cr)] = ((1d - evolutionWeight) / + (1d - criteriaWeights.get(criterion))) * criteriaWeights.get(cr); + } + + return inferWeights; + } + + private Double[] computeFinalPreferences(Double[] inferredWeights) { + Double[][] decisionMatrix = model.getDecisionMatrix(); + + Double[] alternativesFinalPreferences = new Double[decisionMatrix.length]; + for (int alternative = 0; alternative < alternativesFinalPreferences.length; alternative++) { + alternativesFinalPreferences[alternative] = 0d; + for (int criterion = 0; criterion < this.criteria.length; criterion++) { + alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion] * + inferredWeights[criterion]; + } + } + return alternativesFinalPreferences; + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/Messages.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/Messages.java new file mode 100644 index 0000000..1c4645e --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/Messages.java @@ -0,0 +1,7 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc.messages; + +public class Messages { + + public String Preference; + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/messages.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/messages.properties new file mode 100644 index 0000000..d3b8871 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/messages.properties @@ -0,0 +1 @@ +Preference=Preference diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/messages_es.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/messages_es.properties new file mode 100644 index 0000000..9238aed --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcc/messages/messages_es.properties @@ -0,0 +1 @@ +Preference=Preferencia diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.polyglot.META-INF new file mode 100644 index 0000000..aecea79 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] WSM sensitive analysis model ui + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.project new file mode 100644 index 0000000..596694a --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362580 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c9790ab --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: WSM sensitive analysis model ui +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel.wsm.mcm, + flintstones.entity.sensitiveanalysismodel.ui, + flintstones.helper.html, + flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + javax.inject, + org.eclipse.swt, + org.jfree.chart.jfreechart, + org.eclipse.e4.core.services diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/plugin.xml new file mode 100644 index 0000000..418d3ba --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/WeightedSumModelUI.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/WeightedSumModelUI.java new file mode 100644 index 0000000..49cb481 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/WeightedSumModelUI.java @@ -0,0 +1,113 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm; + +import javax.inject.Inject; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel.FieldsChanges; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm.chart.WSMRankingEvolutionChart; +import flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm.messages.Messages; +import flintstones.entity.sensitiveanalysismodel.wsm.mcm.WeightedSumModelMCM; +import flintstones.entity.sensitiveanalysismodel.wsm.mcm.WeightedSumModelMCMTwoTuple; +import flintstones.helper.html.table.HtmlTextTable; + +public class WeightedSumModelUI extends SensitiveAnalysisModelUi { + + @Inject + @Translation + Messages messages; + + public WeightedSumModelUI() {} + + @Override + public HtmlTextTable createRankingTable(Composite rankingSection) { + String[] rowHeader = getOrderedAlternatives(model.getRanking()); + String[] colHeader = new String[] {messages.Preference, "Ranking"};//$NON-NLS-1$ + + rankingTable = new HtmlTextTable(rankingSection, loadRanking(model.getRanking(), + ((WeightedSumModelMCM) model).getAlternativesFinalPreferences(), + rowHeader.length, colHeader.length), colHeader, rowHeader); + return rankingTable; + } + + private String[] getOrderedAlternatives(int[] ranking) { + String[] orderedAlternatives = new String[ranking.length]; + String[] shorterAlternatives = getShortenedAlternativesNames(); + + for(int i = 0; i < orderedAlternatives.length; ++i) + orderedAlternatives[i] = shorterAlternatives[ranking[i]]; + + return orderedAlternatives; + } + + private String[][] loadRanking(int[] ranking, Double[] preferences, int numRows, int numCols) { + String[][] valuesSTR = new String [numRows][numCols]; + + int rank = 1; + for(int i = 0; i < valuesSTR.length; i++) { + valuesSTR[i][0] = "" + Math.round(preferences[ranking[i]] * 100000d) / 100000d;; + for(int j = 1; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = "" + (rank++); + } + return valuesSTR; + } + + @Override + public HtmlTextTable createChangesTable(Composite changesSection, FieldsChanges typeChange) { + String[] rowHeader = getShortenedAllPairAlternativesNames(); + String[] colHeader = getShortenedCriteriaNames(); + + changesTable = new HtmlTextTable(changesSection, loadChanges(model.getChanges(typeChange), rowHeader.length, colHeader.length), + colHeader, rowHeader); + return changesTable; + } + + @SuppressWarnings("static-access") + private String[][] loadChanges(Double[][][] changes, int numRows, int numCols) { + String[][] valuesSTR = new String [numRows][numCols]; + + Double change; + int cont = 0; + for(int i = 0; i < model.getDecisionMatrix().length - 1; ++i) { + for(int j = 0; j < model.getDecisionMatrix().length; ++j) { + if(i != j) { + for(int k = 0; k < valuesSTR[i].length; k++) { + change = changes[i][j][k]; + if(change == model.NON_FEASIBLE) + valuesSTR[cont][k] = "N/F"; + else + valuesSTR[cont][k] = "" + Math.round(change * 10000d) / 10000d; + } + cont++; + } + } + } + return valuesSTR; + } + + @Override + public void refreshChangesTable(FieldsChanges typeChange) { + changesTable.refresh(loadChanges(model.getChanges(typeChange), changesTable.getNumberOfRows(), + changesTable.getNumberOfColumns())); + changesTable.render(); + } + + @Override + public void refreshRankingTable() { + rankingTable.refresh(loadRanking(model.getRanking(), + ((WeightedSumModelMCMTwoTuple) model).getAlternativesFinalPreferences(), + rankingTable.getNumberOfRows(), rankingTable.getNumberOfColumns())); + rankingTable.render(); + } + + @Override + public RankingEvolutionChart createRankingEvolutionChart(Composite container, ProblemElement[] criteria, Criterion criterion, int width, int height, int style) { + chart = new WSMRankingEvolutionChart(); + chart.initialize(model, criteria, criterion, container, width, height, style); + return chart; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/chart/WSMRankingEvolutionChart.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/chart/WSMRankingEvolutionChart.java new file mode 100644 index 0000000..eafed6f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/chart/WSMRankingEvolutionChart.java @@ -0,0 +1,88 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm.chart; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; + +public class WSMRankingEvolutionChart extends RankingEvolutionChart { + + @Override + public XYDataset createDataset() { + dataset = new XYSeriesCollection(); + + List alternativesSeries = computeEvolutionChart(); + for (XYSeries xySerie : alternativesSeries) { + dataset.addSeries(xySerie); + } + + return dataset; + } + + private List computeEvolutionChart() { + + List alternativesSeries = generateXYSeries(); + + Double[] preferences; + for (double j = 0.01; j <= 1.0; j += 0.01) { + preferences = computeFinalPreferences(computeInferredWeights(j)); + for (int s = 0; s < alternativesSeries.size(); ++s) { + XYSeries serie = alternativesSeries.get(s); + serie.add(Math.round(j * 100d) / 100d, preferences[s]); + } + } + + return alternativesSeries; + } + + private List generateXYSeries() { + List alternativesSeries = new LinkedList(); + for (int i = 0; i < model.getDecisionMatrix().length; ++i) { + XYSeries serie = new XYSeries("A"+ (i + 1)); + serie.add(0, 0); + alternativesSeries.add(serie); + } + + return alternativesSeries; + } + + private Double[] computeInferredWeights(double evolutionWeight) { + Map criteriaWeights = model.getCriteriaWeights(); + Double[] inferWeights = new Double[criteriaWeights.size()]; + + List criteria = Arrays.asList(this.criteria); + + int indexSelectedCriterion = criteria.indexOf(criterion); + inferWeights[indexSelectedCriterion] = evolutionWeight; + + for (ProblemElement cr: criteria) { + if (!cr.equals(criterion)) + inferWeights[criteria.indexOf(cr)] = ((1d - evolutionWeight) / + (1d - criteriaWeights.get(criterion))) * criteriaWeights.get(cr); + } + + return inferWeights; + } + + private Double[] computeFinalPreferences(Double[] inferredWeights) { + Double[][] decisionMatrix = model.getDecisionMatrix(); + + Double[] alternativesFinalPreferences = new Double[decisionMatrix.length]; + for (int alternative = 0; alternative < alternativesFinalPreferences.length; alternative++) { + alternativesFinalPreferences[alternative] = 0d; + for (int criterion = 0; criterion < this.criteria.length; criterion++) { + alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion] * + inferredWeights[criterion]; + } + } + return alternativesFinalPreferences; + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/Messages.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/Messages.java new file mode 100644 index 0000000..f23b45a --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/Messages.java @@ -0,0 +1,7 @@ +package flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm.messages; + +public class Messages { + + public String Preference; + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/messages.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/messages.properties new file mode 100644 index 0000000..d3b8871 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/messages.properties @@ -0,0 +1 @@ +Preference=Preference diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/messages_es.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/messages_es.properties new file mode 100644 index 0000000..9238aed --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/ui/wsm/mcm/messages/messages_es.properties @@ -0,0 +1 @@ +Preference=Preferencia diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.polyglot.META-INF new file mode 100644 index 0000000..d0a9623 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Sensitve analysis model ui + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/.project b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.project new file mode 100644 index 0000000..c571d73 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362576 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c665fa4 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Sensitve analysis model ui +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.html, + flintstones.model.ui.service, + flintstones.entity.extensionenum, + org.eclipse.swt, + javax.inject, + org.eclipse.e4.core.di.annotations, + flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + org.jfree.chart.jfreechart +Export-Package: flintstones.entity.sensitiveanalysismodel.ui, + flintstones.entity.sensitiveanalysismodel.ui.chart diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.ui/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.ui/plugin.xml new file mode 100644 index 0000000..76a4c8c --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/plugin.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/schema/flintstones.entity.sensitiveanalysismodel.ui.extension.exsd b/bundles/flintstones.entity.sensitiveanalysismodel.ui/schema/flintstones.entity.sensitiveanalysismodel.ui.extension.exsd new file mode 100644 index 0000000..83b1aa7 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/schema/flintstones.entity.sensitiveanalysismodel.ui.extension.exsd @@ -0,0 +1,119 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/src/flintstones/entity/sensitiveanalysismodel/ui/SensitiveAnalysisModelUi.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui/src/flintstones/entity/sensitiveanalysismodel/ui/SensitiveAnalysisModelUi.java new file mode 100644 index 0000000..8fbfc8c --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/src/flintstones/entity/sensitiveanalysismodel/ui/SensitiveAnalysisModelUi.java @@ -0,0 +1,153 @@ +package flintstones.entity.sensitiveanalysismodel.ui; + +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel.FieldsChanges; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.model.problemelement.service.IProblemElementService; + +public abstract class SensitiveAnalysisModelUi { + + public static final String EXTENSION_POINT = "flintstones.entity.sensitiveanalysismodel.ui.extension"; + + protected HtmlTextTable dmTable; + protected HtmlTextTable rankingTable; + protected HtmlTextTable changesTable; + + protected RankingEvolutionChart chart; + + protected SensitiveAnalysisModel model; + + @Inject + IProblemElementService problemService; + + + /** + * The Class Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The id. */ + uid, + /** The model. */ + sensitivemodel, + /** The implementation. */ + implementation + } + + public SensitiveAnalysisModel getModel() { + return model; + } + + public void setModel(SensitiveAnalysisModel model) { + this.model = model; + } + + public HtmlTextTable createDecisionMatrixTable(Composite decisionMatrixSection) { + String[] rowHeader = getShortenedAlternativesNames(); + String[] colHeader = getShortenedCriteriaNames(); + String[][] valuesSTR = new String [rowHeader.length][colHeader.length]; + + Double[][] values = model.getDecisionMatrix(); + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = "" + values[i][j]; + } + + dmTable = new HtmlTextTable(decisionMatrixSection, valuesSTR, colHeader, rowHeader); + return dmTable; + } + + public abstract HtmlTextTable createRankingTable(Composite rankingSection); + + public abstract HtmlTextTable createChangesTable(Composite changesSection, FieldsChanges typeChange); + + public void refreshDecisionMatrixTable() { + Double[][] newValues = model.getDecisionMatrix(); + String[][] valuesSTR = new String[dmTable.getNumberOfRows()][dmTable.getNumberOfColumns()]; + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) { + valuesSTR[i][j] = "" + newValues[i][j]; + } + } + + dmTable.refresh(valuesSTR); + dmTable.render(); + } + + public abstract void refreshRankingTable(); + + public abstract void refreshChangesTable(FieldsChanges typeChange); + + public String[] getShortenedCriteriaNames() { + Criterion[] allCriteria = ProblemElementHelper.asCriterions(problemService.getMainElements(Criterion.Type)); + String[] str = new String[allCriteria.length]; + + for(int i = 0; i < allCriteria.length; i++) + str[i] = "C" + (i + 1); + + return str; + } + + public String[] getShortenedAlternativesNames() { + Alternative[] allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + String[] str = new String[allAlternatives.length]; + + for(int i = 0; i < allAlternatives.length; i++) + str[i] = "A" + (i + 1); + + return str; + } + + public String[] getShortenedPairAlternativesNames() { + Alternative[] allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + + List str = new LinkedList<>(); + for(int i = 0; i < allAlternatives.length - 1; i++) { + for(int j = i + 1; j < allAlternatives.length; ++j) { + str.add("A" + (i + 1) + "-" + "A" + (j + 1)); + } + } + + return str.toArray(new String[0]); + } + + public String[] getShortenedAllPairAlternativesNames() { + Alternative[] allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + + List str = new LinkedList<>(); + for(int i = 0; i < allAlternatives.length - 1; i++) { + for(int j = 0; j < allAlternatives.length; ++j) { + if(i != j) + str.add("A" + (i + 1) + "-" + "A" + (j + 1)); + } + } + + return str.toArray(new String[0]); + } + + public abstract RankingEvolutionChart createRankingEvolutionChart(Composite container, ProblemElement[] criteria, Criterion criterion, int width, int height, int style); + + public String[] getCriteriaIds() { + String[] ids = new String[problemService.getMainElements(Criterion.Type).length]; + + int cont = 0; + for(ProblemElement pe: problemService.getMainElements(Criterion.Type)) { + ids[cont] = pe.getName(); + cont++; + } + return ids; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.ui/src/flintstones/entity/sensitiveanalysismodel/ui/chart/RankingEvolutionChart.java b/bundles/flintstones.entity.sensitiveanalysismodel.ui/src/flintstones/entity/sensitiveanalysismodel/ui/chart/RankingEvolutionChart.java new file mode 100644 index 0000000..36e257d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.ui/src/flintstones/entity/sensitiveanalysismodel/ui/chart/RankingEvolutionChart.java @@ -0,0 +1,173 @@ +package flintstones.entity.sensitiveanalysismodel.ui.chart; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; +import java.awt.Stroke; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.NumberTickUnit; +import org.jfree.chart.labels.XYToolTipGenerator; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.ValueMarker; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.chart.swt.ChartComposite; +import org.jfree.chart.ui.RectangleAnchor; +import org.jfree.chart.ui.RectangleInsets; +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; + +public abstract class RankingEvolutionChart { + + protected SensitiveAnalysisModel model; + + protected Criterion criterion; + protected ProblemElement[] criteria; + + protected JFreeChart chart; + protected ChartComposite chartComposite; + protected XYSeriesCollection dataset; + protected ValueMarker currentWeightMarker; + + public void refreshChart(Criterion criterion) { + this.criterion = criterion; + if (this.chart == null) + this.chart = this.createChart(this.createDataset()); + else + this.chart.getXYPlot() + .setDataset(this.createDataset()); + + currentWeightMarker.setValue(model.getCriteriaWeights().get(criterion)); + + updateRange(); + } + + private JFreeChart createChart(XYDataset dataset) { + JFreeChart chart = ChartFactory.createXYLineChart("Ranking exchanges among alternatives", null, null, dataset, + PlotOrientation.VERTICAL, true, true, false); + + chart.setBackgroundPaint(Color.white); + + XYPlot plot = chart.getXYPlot(); + plot.setBackgroundPaint(Color.white); + plot.setDomainGridlinesVisible(true); + plot.setRangeGridlinesVisible(true); + + setDefaultRanges(plot); + setRenderer(plot); + setMarker(plot); + + chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12)); + + return chart; + } + + private void setDefaultRanges(XYPlot plot) { + NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); + rangeAxis.setRange(0, 1); + rangeAxis.setTickUnit(new NumberTickUnit(0.1)); + + NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); + domainAxis.setRange(0.01, 1); + domainAxis.setTickUnit(new NumberTickUnit(0.05)); + } + + private void setRenderer(XYPlot plot) { + @SuppressWarnings("serial") + XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() { + Stroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 7.0f, + new float[] { 7.0f }, 0.0f); + + @Override + public Stroke getItemStroke(int row, int column) { + return dashed; + } + }; + renderer.setDefaultShapesVisible(true); + renderer.setDefaultShapesFilled(true); + renderer.setDefaultStroke(new BasicStroke(2)); + renderer.setDefaultLegendTextFont(new Font("sans-serif", Font.BOLD, 8)); + renderer.setDefaultToolTipGenerator(createToolTipGenerator()); + plot.setRenderer(renderer); + } + + private XYToolTipGenerator createToolTipGenerator() { + XYToolTipGenerator xyToolTipGenerator = new XYToolTipGenerator() { + public String generateToolTip(XYDataset dataset, int series, int item) { + StringBuffer sb = new StringBuffer(); + double x = dataset.getX(series, item).doubleValue(); + double y = dataset.getY(series, item).doubleValue(); + String coordX = Double.toString(Math.round(x * 10000d) / 10000d); + String coordY = Double.toString(Math.round(y * 10000d) / 10000d); + sb.append("(" + coordX + ", " + coordY + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + return sb.toString(); + } + }; + + return xyToolTipGenerator; + } + + private void setMarker(XYPlot plot) { + currentWeightMarker = new ValueMarker(0); + currentWeightMarker.setLabelFont(new java.awt.Font("SansSerif", Font.BOLD, 9)); //$NON-NLS-1$ + currentWeightMarker.setLabel("Current weight"); + currentWeightMarker.setPaint(Color.red); + currentWeightMarker.setStroke(new BasicStroke(2)); + currentWeightMarker.setLabelOffset(new RectangleInsets(10, 10, 10, 50)); + currentWeightMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); + currentWeightMarker.setLabelBackgroundColor(new Color(255, 255, 255)); + plot.addDomainMarker(currentWeightMarker); + } + + private void updateRange() { + XYPlot plot = chart.getXYPlot(); + + List preferences = new LinkedList<>(); + for(int i = 0; i < dataset.getSeries().size(); ++i) { + XYSeries serie = dataset.getSeries(i); + preferences.add(serie.getMaxY()); + } + + Collections.sort(preferences); + + double max = 1; + double tickUnit = 0.1; + if(preferences.get(preferences.size() - 1) > 1) { + max = preferences.get(preferences.size() - 1) + 1; + tickUnit = max / 10d; + } + + NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); + rangeAxis.setRange(0, 1); + rangeAxis.setTickUnit(new NumberTickUnit(tickUnit)); + } + + public abstract XYDataset createDataset(); + + public void initialize(SensitiveAnalysisModel model, ProblemElement[] criteria, Criterion criterion, + Composite container, int width, int height, int style) { + + this.model = model; + this.criteria = criteria; + this.criterion = criterion; + + refreshChart(this.criterion); + + this.chartComposite = new ChartComposite(container, style, this.chart, true); + this.chartComposite.setSize(width, height); + } + + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.polyglot.META-INF new file mode 100644 index 0000000..8c13de1 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.wpm.mcc + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Weighted product model + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.project b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.project new file mode 100644 index 0000000..6212125 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.wpm.mcc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362581 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4b4ea05 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Weighted product model +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.wpm.mcc;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.mcc.wpm +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel, + javax.inject, + flintstones.model.problemelement.service, + flintstones.valuation.twoTuple, + flintstones.valuation.numeric, + flintstones.valuation.fuzzy +Export-Package: flintstones.entity.sensitiveanalysismodel.wpm.mcc diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/plugin.xml new file mode 100644 index 0000000..2531df0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCC.java b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCC.java new file mode 100644 index 0000000..611ad95 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCC.java @@ -0,0 +1,357 @@ +package flintstones.entity.sensitiveanalysismodel.wpm.mcc; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import javax.inject.Inject; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public abstract class WeightedProductModelMCC extends SensitiveAnalysisModel { + + @Inject + IProblemElementService problemService; + + protected Double[][] alternativesRatioFinalPreferences; + + protected Double[][][] minimumAbsoluteChangeInCriteriaWeights; + protected Double[][][] minimumRelativeChangeInCriteriaWeights; + + protected List absoluteTop; + protected List absoluteAny; + protected List relativeTop; + protected List relativeAny; + + protected int numAlternatives; + protected int numCriteria; + + public Map getCriteriaWeights() { + return criteriaWeights; + } + + public void setCriteriaWeights(Map criteriaWeights) { + this.criteriaWeights = criteriaWeights; + } + + public Double[][] getAlternativesRatioFinalPreferences() { + return alternativesRatioFinalPreferences; + } + + public void setAlternativesRatioFinalPreferences(Double[][] alternativesRatioFinalPreferences) { + this.alternativesRatioFinalPreferences = alternativesRatioFinalPreferences; + } + + public Double[][][] getMinimumAbsoluteChangeInCriteriaWeights() { + return minimumAbsoluteChangeInCriteriaWeights; + } + + public void setMinimumAbsoluteChangeInCriteriaWeights(Double[][][] minimumAbsoluteChangeInCriteriaWeights) { + this.minimumAbsoluteChangeInCriteriaWeights = minimumAbsoluteChangeInCriteriaWeights; + } + + public Double[][][] getMinimumRelativeChangeInCriteriaWeights() { + return minimumRelativeChangeInCriteriaWeights; + } + + public void setMinimumRelativeChangeInCriteriaWeights(Double[][][] minimumRelativeChangeInCriteriaWeights) { + this.minimumRelativeChangeInCriteriaWeights = minimumRelativeChangeInCriteriaWeights; + } + + public List getAbsoluteTop() { + return absoluteTop; + } + + public void setAbsoluteTop(List absoluteTop) { + this.absoluteTop = absoluteTop; + } + + public List getAbsoluteAny() { + return absoluteAny; + } + + public void setAbsoluteAny(List absoluteAny) { + this.absoluteAny = absoluteAny; + } + + public List getRelativeTop() { + return relativeTop; + } + + public void setRelativeTop(List relativeTop) { + this.relativeTop = relativeTop; + } + + public List getRelativeAny() { + return relativeAny; + } + + public void setRelativeAny(List relativeAny) { + this.relativeAny = relativeAny; + } + + @Override + public void execute(HashMatrix decisionMatrix, + Map criteriaWeights) { + numAlternatives = problemService.getAll(Alternative.Type).length; + numCriteria = problemService.getMainElements(Criterion.Type).length; + + this.setCriteriaWeights(criteriaWeights); + this.normalizeDecisionMatrix(decisionMatrix); + this.computeFinalPreferences(); + this.computeRanking(); + this.computeMinimumAbsoluteChangeInCriteriaWeights(); + this.computeMinimumRelativeChangeInCriteriaWeights(); + this.computeAbsoluteTopCriticalCriterion(); + this.computeAbsoluteAnyCriticalCriterion(); + this.computeRelativeTopCriticalCriterion(); + this.computeRelativeAnyCriticalCriterion(); + } + + protected abstract void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation); + + private void computeFinalPreferences() { + + alternativesRatioFinalPreferences = new Double[numAlternatives][numAlternatives]; + + for (int alt1 = 0; alt1 < numAlternatives - 1; alt1++) { + for (int alt2 = alt1 + 1; alt2 < numAlternatives; alt2++) { + alternativesRatioFinalPreferences[alt1][alt2] = 1d; + for (int cr = 0; cr < numCriteria; cr++) { + alternativesRatioFinalPreferences[alt1][alt2] *= Math.pow( + ((Double) decisionMatrix[alt1][cr] / (Double) decisionMatrix[alt2][cr]), + criteriaWeights.get(problemService.getMainElements(Criterion.Type)[cr])); + } + } + } + } + + private void computeRanking() { + + ranking = new int[numAlternatives]; + + for (int i = 0; i < ranking.length; ++i) + ranking[i] = i + 1; + + double ratio = 0; + for (int alt1 = 0; alt1 < numAlternatives - 1; ++alt1) { + for (int alt2 = alt1 + 1; alt2 < numAlternatives; ++alt2) { + ratio = alternativesRatioFinalPreferences[alt1][alt2]; + if (ratio < 1) { + if (ranking[alt2] > ranking[alt1]) { + if (ranking[alt2] - 1 == ranking[alt1]) { + ranking[alt2] = ranking[alt1]; + ranking[alt1] += 1; + } else { + ranking[alt2] = ranking[alt1]; + incrementPosRanking(alt2); + } + } + } + } + } + } + + private void incrementPosRanking(int alt2) { + int rank = ranking[alt2]; + + for (int alt = 0; alt < ranking.length; ++alt) { + if (ranking[alt] >= rank && ranking[alt] < ranking.length) { + if (alt != alt2) + ranking[alt] += 1; + } + } + } + + /** + * Compute the minimum change in absolute terms to apply in criteria weights so that there is an exchange among any pair of alternatives + */ + private void computeMinimumAbsoluteChangeInCriteriaWeights() { + minimumAbsoluteChangeInCriteriaWeights = new Double[numAlternatives][numAlternatives][numCriteria]; + + double numerator, denominator, total; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + numerator = Math.log(alternativesRatioFinalPreferences[i][j]); + if ((Double) decisionMatrix[j][k] == 0) { + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } else { + denominator = Math.log((Double) decisionMatrix[i][k] / (Double) decisionMatrix[j][k]); + if (denominator != 0) { + total = numerator / denominator; + if (total > criteriaWeights.get(problemService.getMainElements(Criterion.Type)[k])) { + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } else { + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = total; + if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] > criteriaWeights.get(problemService.getMainElements(Criterion.Type)[k])) + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } + } else + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } + } + } + } + } + + /** + * Compute the minimum change in relative terms to apply in criteria weights so that there is an exchange among any pair of alternatives + */ + private void computeMinimumRelativeChangeInCriteriaWeights() { + minimumRelativeChangeInCriteriaWeights = new Double[numAlternatives][numAlternatives][numCriteria]; + + Criterion cr; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + cr = (Criterion) problemService.getMainElements(Criterion.Type)[k]; + if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] != NON_FEASIBLE) { + if (criteriaWeights.get(cr) == 0) { + minimumRelativeChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } else { + minimumRelativeChangeInCriteriaWeights[i][j][k] = minimumAbsoluteChangeInCriteriaWeights[i][j][k] * (100d / criteriaWeights.get(cr)); + } + } else + minimumRelativeChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } + } + } + } + + /** + * Look for the minimal change in absolute terms among the best alternative/s and the rest of them + */ + private void computeAbsoluteTopCriticalCriterion() { + List bestAlternatives = getBestAlternatives(); + + absoluteTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumAbsoluteChangeInCriteriaWeights[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteTop.clear(); + absoluteTop.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Get the indexes of the best alternatives + * @return indexes of the best alternatives + */ + private List getBestAlternatives() { + List bestAlternatives = new LinkedList(); + for (int i = 0; i < numAlternatives; i++) { + if (ranking[i] == 0) + bestAlternatives.add(Integer.valueOf(i)); + } + return bestAlternatives; + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeAbsoluteAnyCriticalCriterion() { + + absoluteAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumAbsoluteChangeInCriteriaWeights[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteAny.clear(); + absoluteAny.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteAny.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in relative terms among the best alternative/s and the rest of them + */ + private void computeRelativeTopCriticalCriterion() { + List bestAlternatives = getBestAlternatives(); + + relativeTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumRelativeChangeInCriteriaWeights[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeTop.clear(); + relativeTop.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeRelativeAnyCriticalCriterion() { + + relativeAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumRelativeChangeInCriteriaWeights[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeAny.clear(); + relativeAny.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeAny.add(Integer.valueOf(k)); + } + } + } + } + } + + @Override + public Double[][][] getChanges(FieldsChanges typeOfChange) { + switch(typeOfChange) { + case absolute: + return minimumAbsoluteChangeInCriteriaWeights; + case relative: + return minimumRelativeChangeInCriteriaWeights; + default: + return null; + } + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCFuzzy.java b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCFuzzy.java new file mode 100644 index 0000000..aec88fb --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCFuzzy.java @@ -0,0 +1,50 @@ +package flintstones.entity.sensitiveanalysismodel.wpm.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class WeightedProductModelMCCFuzzy extends WeightedProductModelMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((FuzzyValuation) decisionMatrixAggregation.get(alt, crit)).getFuzzyNumber().getB(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCNumeric.java b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCNumeric.java new file mode 100644 index 0000000..4b6b9b0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCNumeric.java @@ -0,0 +1,49 @@ +package flintstones.entity.sensitiveanalysismodel.wpm.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.numeric.NumericValuation; + +public class WeightedProductModelMCCNumeric extends WeightedProductModelMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((NumericValuation) decisionMatrixAggregation.get(alt, crit)).getValue(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCTwoTuple.java b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCTwoTuple.java new file mode 100644 index 0000000..b908714 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcc/src/flintstones/entity/sensitiveanalysismodel/wpm/mcc/WeightedProductModelMCCTwoTuple.java @@ -0,0 +1,50 @@ +package flintstones.entity.sensitiveanalysismodel.wpm.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class WeightedProductModelMCCTwoTuple extends WeightedProductModelMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((TwoTupleValuation) decisionMatrixAggregation.get(alt, crit)).calculateInverseDelta(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.polyglot.META-INF new file mode 100644 index 0000000..c33e0eb --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.wpm.mcm + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Most critical measure weighted product model + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.project b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.project new file mode 100644 index 0000000..51092c4 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.wpm.mcm + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362581 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3d63c21 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Most critical measure weighted product model +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.wpm.mcm;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.mcm.wpm +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.model.problemelement.service, + flintstones.entity.problemelement, + flintstones.helper.data, + flintstones.valuation.numeric, + flintstones.entity.valuation, + flintstones.valuation.twoTuple, + javax.inject, + flintstones.valuation.fuzzy +Import-Package: flintstones.entity.sensitiveanalysismodel +Export-Package: flintstones.entity.sensitiveanalysismodel.wpm.mcm diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/plugin.xml new file mode 100644 index 0000000..a2b8938 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCM.java b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCM.java new file mode 100644 index 0000000..2b03c12 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCM.java @@ -0,0 +1,348 @@ +package flintstones.entity.sensitiveanalysismodel.wpm.mcm; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public abstract class WeightedProductModelMCM extends SensitiveAnalysisModel { + + @Inject + IProblemElementService problemService; + + protected Double[][] alternativesRatioFinalPreferences; + + protected Double[][][] absoluteThresholdValues; + protected Double[][][] relativeThresholdValues; + + protected List absoluteTop; + protected List absoluteAny; + protected List relativeTop; + protected List relativeAny; + + protected int numAlternatives; + protected int numCriteria; + + public Map getCriteriaWeights() { + return criteriaWeights; + } + + public void setCriteriaWeights(Map criteriaWeights) { + this.criteriaWeights = criteriaWeights; + } + + public Double[][] getAlternativesRatioFinalPreferences() { + return alternativesRatioFinalPreferences; + } + + public void setAlternativesRatioFinalPreferences(Double[][] alternativesRatioFinalPreferences) { + this.alternativesRatioFinalPreferences = alternativesRatioFinalPreferences; + } + + public Double[][][] getAbsoluteThresholdValues() { + return absoluteThresholdValues; + } + + public void setAbsoluteThresholdValues(Double[][][] absoluteThresholdValues) { + this.absoluteThresholdValues = absoluteThresholdValues; + } + + public Double[][][] getRelativeThresholdValues() { + return relativeThresholdValues; + } + + + public void setRelativeThresholdValues(Double[][][] relativeThresholdValues) { + this.relativeThresholdValues = relativeThresholdValues; + } + + public List getAbsoluteTop() { + return absoluteTop; + } + + public void setAbsoluteTop(List absoluteTop) { + this.absoluteTop = absoluteTop; + } + + public List getAbsoluteAny() { + return absoluteAny; + } + + public void setAbsoluteAny(List absoluteAny) { + this.absoluteAny = absoluteAny; + } + + public List getRelativeTop() { + return relativeTop; + } + + public void setRelativeTop(List relativeTop) { + this.relativeTop = relativeTop; + } + + public List getRelativeAny() { + return relativeAny; + } + + public void setRelativeAny(List relativeAny) { + this.relativeAny = relativeAny; + } + + /** + * The most sensitive alternative is computed from the threshold values. + */ + @Override + public void execute(HashMatrix decisionMatrix, + Map criteriaWeights) { + numAlternatives = problemService.getAll(Alternative.Type).length; + numCriteria = problemService.getMainElements(Criterion.Type).length; + + this.setCriteriaWeights(criteriaWeights); + this.normalizeDecisionMatrix(decisionMatrix); + this.computeFinalPreferences(); + this.computeRanking(); + this.computeAbsoluteThresholdValues(); + this.computeRelativeThresholdValues(); + this.computeAbsoluteTopCriticalAlternative(); + this.computeAbsoluteAnyCriticalAlternative(); + this.computeRelativeTopCriticalAlternative(); + this.computeRelativeAnyCriticalAlternative(); + } + + protected abstract void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation); + + private void computeFinalPreferences() { + + alternativesRatioFinalPreferences = new Double[numAlternatives][numAlternatives]; + + for (int alt1 = 0; alt1 < numAlternatives; alt1++) { + for (int alt2 = 0; alt2 < numAlternatives; alt2++) { + if (alt1 != alt2) { + alternativesRatioFinalPreferences[alt1][alt2] = 1d; + for (int cr = 0; cr < numCriteria; cr++) { + alternativesRatioFinalPreferences[alt1][alt2] *= Math.pow( + ((Double) decisionMatrix[alt1][cr] / (Double) decisionMatrix[alt2][cr]), + criteriaWeights.get(problemService.getMainElements(Criterion.Type)[cr])); + } + } + } + } + } + + private void computeRanking() { + + ranking = new int[numAlternatives]; + + for (int i = 0; i < ranking.length; ++i) + ranking[i] = i + 1; + + double ratio = 0; + for (int alt1 = 0; alt1 < numAlternatives - 1; ++alt1) { + for (int alt2 = alt1 + 1; alt2 < numAlternatives; ++alt2) { + ratio = alternativesRatioFinalPreferences[alt1][alt2]; + if (ratio < 1) { + if (ranking[alt2] > ranking[alt1]) { + if (ranking[alt2] - 1 == ranking[alt1]) { + ranking[alt2] = ranking[alt1]; + ranking[alt1] += 1; + } else { + ranking[alt2] = ranking[alt1]; + incrementPosRanking(alt2); + } + } + } + } + } + } + + private void incrementPosRanking(int alt2) { + int rank = ranking[alt2]; + + for (int alt = 0; alt < ranking.length; ++alt) { + if (ranking[alt] >= rank && ranking[alt] < ranking.length) { + if (alt != alt2) + ranking[alt] += 1; + } + } + } + + /** + * Get the indexes of the best alternatives + * @return indexes of the best alternatives + */ + private List getBestAlternatives() { + List bestAlternatives = new LinkedList(); + for (int i = 0; i < numAlternatives; i++) { + if (ranking[i] == 0) + bestAlternatives.add(Integer.valueOf(i)); + } + return bestAlternatives; + } + + private void computeAbsoluteThresholdValues() { + + absoluteThresholdValues = new Double[numAlternatives][numAlternatives][numCriteria]; + + Criterion cr; + for (int i = 0; i < numAlternatives; i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + cr = (Criterion) problemService.getMainElements(Criterion.Type)[k]; + if (i != j) { + if (criteriaWeights.get(cr) == 0) { + absoluteThresholdValues[i][j][k] = NON_FEASIBLE; + } else { + absoluteThresholdValues[i][j][k] = 1 - Math.pow(alternativesRatioFinalPreferences[j][i], 1d / criteriaWeights.get(cr)); + if (absoluteThresholdValues[i][j][k] > criteriaWeights.get(cr)) + absoluteThresholdValues[i][j][k] = NON_FEASIBLE; + } + } + } + } + } + } + + private void computeRelativeThresholdValues() { + relativeThresholdValues = new Double[numAlternatives][numAlternatives][numCriteria]; + + for (int i = 0; i < numAlternatives; i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + if (absoluteThresholdValues[i][j][k] == NON_FEASIBLE) + relativeThresholdValues[i][j][k] = NON_FEASIBLE; + else + relativeThresholdValues[i][j][k] = absoluteThresholdValues[i][j][k] * 100d; + } + } + } + } + + /** + * Look for the minimal change in absolute terms among the best alternative/s + * and the rest of them + */ + private void computeAbsoluteTopCriticalAlternative() { + List bestAlternatives = getBestAlternatives(); + + absoluteTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = absoluteThresholdValues[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteTop.clear(); + absoluteTop.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeAbsoluteAnyCriticalAlternative() { + + absoluteAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = absoluteThresholdValues[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteAny.clear(); + absoluteAny.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteAny.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in relative terms among the best alternative/s + * and the rest of them + */ + private void computeRelativeTopCriticalAlternative() { + List bestAlternatives = getBestAlternatives(); + + relativeTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = relativeThresholdValues[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeTop.clear(); + relativeTop.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeRelativeAnyCriticalAlternative() { + + relativeAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = relativeThresholdValues[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeAny.clear(); + relativeAny.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeAny.add(Integer.valueOf(k)); + } + } + } + } + } + + @Override + public Double[][][] getChanges(FieldsChanges typeOfChange) { + switch(typeOfChange) { + case absolute: + return absoluteThresholdValues; + case relative: + return relativeThresholdValues; + default: + return null; + } + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMFuzzy.java b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMFuzzy.java new file mode 100644 index 0000000..f6d8cdc --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMFuzzy.java @@ -0,0 +1,50 @@ +package flintstones.entity.sensitiveanalysismodel.wpm.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class WeightedProductModelMCMFuzzy extends WeightedProductModelMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((FuzzyValuation) decisionMatrixAggregation.get(alt, crit)).getFuzzyNumber().getB(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMNumeric.java b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMNumeric.java new file mode 100644 index 0000000..a67330f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMNumeric.java @@ -0,0 +1,49 @@ +package flintstones.entity.sensitiveanalysismodel.wpm.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.numeric.NumericValuation; + +public class WeightedProductModelMCMNumeric extends WeightedProductModelMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((NumericValuation) decisionMatrixAggregation.get(alt, crit)).getValue(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMTwoTuple.java b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMTwoTuple.java new file mode 100644 index 0000000..c7fc6e0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wpm.mcm/src/flintstones/entity/sensitiveanalysismodel/wpm/mcm/WeightedProductModelMCMTwoTuple.java @@ -0,0 +1,50 @@ +package flintstones.entity.sensitiveanalysismodel.wpm.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class WeightedProductModelMCMTwoTuple extends WeightedProductModelMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((TwoTupleValuation) decisionMatrixAggregation.get(alt, crit)).calculateInverseDelta(); + altPos++; + } + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.polyglot.META-INF new file mode 100644 index 0000000..30b076f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.wsm.mcc + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Weighted Sum Model + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.project b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.project new file mode 100644 index 0000000..694b60d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.wsm.mcc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362582 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/META-INF/MANIFEST.MF new file mode 100644 index 0000000..bef9315 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Weighted Sum Model +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.wsm.mcc;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.sensitiveanalysis.mcc.wsm +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + flintstones.valuation.twoTuple, + flintstones.valuation.numeric.real, + javax.inject, + org.eclipse.e4.core.di.annotations, + flintstones.valuation.fuzzy +Export-Package: flintstones.entity.sensitiveanalysismodel.wsm.mcc diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/plugin.xml new file mode 100644 index 0000000..31d290c --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCC.java b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCC.java new file mode 100644 index 0000000..c8a9c22 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCC.java @@ -0,0 +1,325 @@ +package flintstones.entity.sensitiveanalysismodel.wsm.mcc; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public abstract class WeightedSumModelMCC extends SensitiveAnalysisModel { + + @Inject + @Optional + IProblemElementService problemService; + + protected Double[] alternativesFinalPreferences; + + protected Double[][][] minimumAbsoluteChangeInCriteriaWeights; + protected Double[][][] minimumRelativeChangeInCriteriaWeights; + + protected List absoluteTop; + protected List absoluteAny; + protected List relativeTop; + protected List relativeAny; + + protected int numAlternatives; + protected int numCriteria; + + public WeightedSumModelMCC() { + } + + public Map getCriteriaWeights() { + return criteriaWeights; + } + + public void setCriteriaWeights(Map criteriaWeights) { + this.criteriaWeights = criteriaWeights; + } + + public Double[] getAlternativesFinalPreferences() { + return alternativesFinalPreferences; + } + + public void setAlternativesFinalPreferences(Double[] alternativesFinalPreferences) { + this.alternativesFinalPreferences = alternativesFinalPreferences; + } + + public Double[][][] getMinimumAbsoluteChangeInCriteriaWeights() { + return minimumAbsoluteChangeInCriteriaWeights; + } + + public void setMinimumAbsoluteChangeInCriteriaWeights(Double[][][] minimumAbsoluteChangeInCriteriaWeights) { + this.minimumAbsoluteChangeInCriteriaWeights = minimumAbsoluteChangeInCriteriaWeights; + } + + public Double[][][] getMinimumRelativeChangeInCriteriaWeights() { + return minimumRelativeChangeInCriteriaWeights; + } + + public void setMinimumRelativeChangeInCriteriaWeights(Double[][][] minimumRelativeChangeInCriteriaWeights) { + this.minimumRelativeChangeInCriteriaWeights = minimumRelativeChangeInCriteriaWeights; + } + + public List getAbsoluteTop() { + return absoluteTop; + } + + public void setAbsoluteTop(List absoluteTop) { + this.absoluteTop = absoluteTop; + } + + public List getAbsoluteAny() { + return absoluteAny; + } + + public void setAbsoluteAny(List absoluteAny) { + this.absoluteAny = absoluteAny; + } + + public List getRelativeTop() { + return relativeTop; + } + + public void setRelativeTop(List relativeTop) { + this.relativeTop = relativeTop; + } + + public List getRelativeAny() { + return relativeAny; + } + + public void setRelativeAny(List relativeAny) { + this.relativeAny = relativeAny; + } + + /** + * The most sensitive criterion is computed from the minimum changes in criteria weights. + */ + @Override + public void execute(HashMatrix decisionMatrix, + Map criteriaWeights) { + numAlternatives = problemService.getAll(Alternative.Type).length; + numCriteria = problemService.getMainElements(Criterion.Type).length; + + this.setCriteriaWeights(criteriaWeights); + this.normalizeDecisionMatrix(decisionMatrix); + this.computeFinalPreferences(); + this.computeRanking(); + this.computeMinimumAbsoluteChangeInCriteriaWeights(); + this.computeMinimumRelativeChangeInCriteriaWeights(); + this.computeAbsoluteTopCriticalCriterion(); + this.computeAbsoluteAnyCriticalCriterion(); + this.computeRelativeTopCriticalCriterion(); + this.computeRelativeAnyCriticalCriterion(); + } + + protected abstract void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation); + + private void computeFinalPreferences() { + alternativesFinalPreferences = new Double[numAlternatives]; + for (int alternative = 0; alternative < numAlternatives; alternative++) { + alternativesFinalPreferences[alternative] = 0d; + for (int criterion = 0; criterion < numCriteria; criterion++) { + alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion] + * criteriaWeights.get(problemService.getMainElements(Criterion.Type)[criterion]); + } + } + } + + private void computeRanking() { + ranking = IntStream.range(0, alternativesFinalPreferences.length).boxed() + .sorted((j, i) -> alternativesFinalPreferences[i].compareTo(alternativesFinalPreferences[j])) + .mapToInt(ele -> ele).toArray(); + } + + /** + * Compute the minimum change in absolute terms to apply in criteria weights so + * that there is an exchange among any pair of alternatives + */ + private void computeMinimumAbsoluteChangeInCriteriaWeights() { + minimumAbsoluteChangeInCriteriaWeights = new Double[numAlternatives][numAlternatives][numCriteria]; + + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + if ((Double) decisionMatrix[j][k] - (Double) decisionMatrix[i][k] == 0) + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + else { + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = (alternativesFinalPreferences[j] + - alternativesFinalPreferences[i]) + / ((Double) decisionMatrix[j][k] - (Double) decisionMatrix[i][k]); + + if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] > criteriaWeights + .get(problemService.getMainElements(Criterion.Type)[k])) + minimumAbsoluteChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } + } + } + } + } + + /** + * Compute the minimum change in relative terms to apply in criteria weights so + * that there is an exchange among any pair of alternatives + */ + private void computeMinimumRelativeChangeInCriteriaWeights() { + minimumRelativeChangeInCriteriaWeights = new Double[numAlternatives][numAlternatives][numCriteria]; + + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + if (minimumAbsoluteChangeInCriteriaWeights[i][j][k] != NON_FEASIBLE) + minimumRelativeChangeInCriteriaWeights[i][j][k] = minimumAbsoluteChangeInCriteriaWeights[i][j][k] + * (100d / criteriaWeights.get(problemService.getMainElements(Criterion.Type)[k])); + else + minimumRelativeChangeInCriteriaWeights[i][j][k] = NON_FEASIBLE; + } + } + } + } + + /** + * Look for the minimal change in absolute terms among the best alternative/s + * and the rest of them + */ + private void computeAbsoluteTopCriticalCriterion() { + List bestAlternatives = getBestAlternatives(); + + absoluteTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumAbsoluteChangeInCriteriaWeights[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteTop.clear(); + absoluteTop.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Get the indexes of the best alternatives + * + * @return indexes of the best alternatives + */ + private List getBestAlternatives() { + List bestAlternatives = new LinkedList(); + for (int i = 0; i < numAlternatives; i++) { + if (ranking[i] == 0) + bestAlternatives.add(Integer.valueOf(i)); + } + return bestAlternatives; + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeAbsoluteAnyCriticalCriterion() { + + absoluteAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumAbsoluteChangeInCriteriaWeights[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteAny.clear(); + absoluteAny.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteAny.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in relative terms among the best alternative/s + * and the rest of them + */ + private void computeRelativeTopCriticalCriterion() { + List bestAlternatives = getBestAlternatives(); + + relativeTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumRelativeChangeInCriteriaWeights[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeTop.clear(); + relativeTop.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeRelativeAnyCriticalCriterion() { + + relativeAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = minimumRelativeChangeInCriteriaWeights[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeAny.clear(); + relativeAny.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeAny.add(Integer.valueOf(k)); + } + } + } + } + } + + @Override + public Double[][][] getChanges(FieldsChanges typeOfChange) { + switch(typeOfChange) { + case absolute: + return minimumAbsoluteChangeInCriteriaWeights; + case relative: + return minimumRelativeChangeInCriteriaWeights; + default: + return null; + } + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCFuzzy.java b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCFuzzy.java new file mode 100644 index 0000000..7ad85e2 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCFuzzy.java @@ -0,0 +1,51 @@ +package flintstones.entity.sensitiveanalysismodel.wsm.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class WeightedSumModelMCCFuzzy extends WeightedSumModelMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((FuzzyValuation) decisionMatrixAggregation.get(alt, crit)).getFuzzyNumber().getB(); + altPos++; + } + + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCNumeric.java b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCNumeric.java new file mode 100644 index 0000000..911da44 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCNumeric.java @@ -0,0 +1,51 @@ +package flintstones.entity.sensitiveanalysismodel.wsm.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.numeric.NumericValuation; + +public class WeightedSumModelMCCNumeric extends WeightedSumModelMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((NumericValuation) decisionMatrixAggregation.get(alt, crit)).getValue(); + altPos++; + } + + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCTwoTuple.java b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCTwoTuple.java new file mode 100644 index 0000000..4ddd854 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcc/src/flintstones/entity/sensitiveanalysismodel/wsm/mcc/WeightedSumModelMCCTwoTuple.java @@ -0,0 +1,51 @@ +package flintstones.entity.sensitiveanalysismodel.wsm.mcc; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class WeightedSumModelMCCTwoTuple extends WeightedSumModelMCC { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((TwoTupleValuation) decisionMatrixAggregation.get(alt, crit)).calculateInverseDelta(); + altPos++; + } + + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.polyglot.META-INF new file mode 100644 index 0000000..2e8dc4f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel.wsm.mcm + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Most critical measure weighted sum model + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.project b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.project new file mode 100644 index 0000000..eff46f4 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysismodel.wsm.mcm + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362583 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/META-INF/MANIFEST.MF new file mode 100644 index 0000000..89b3f43 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Most critical measure weighted sum model +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel.wsm.mcm;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysismodel.mcm.wsm +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.sensitiveanalysismodel, + flintstones.model.problemelement.service, + flintstones.valuation.twoTuple, + flintstones.valuation.numeric.real, + javax.inject, + org.eclipse.e4.core.di.annotations, + flintstones.valuation.fuzzy +Export-Package: flintstones.entity.sensitiveanalysismodel.wsm.mcm diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/plugin.xml new file mode 100644 index 0000000..f5ddd28 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCM.java b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCM.java new file mode 100644 index 0000000..2c073f2 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCM.java @@ -0,0 +1,321 @@ +package flintstones.entity.sensitiveanalysismodel.wsm.mcm; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.stream.IntStream; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public abstract class WeightedSumModelMCM extends SensitiveAnalysisModel { + + @Inject + @Optional + IProblemElementService problemService; + + protected Double[] alternativesFinalPreferences; + + protected Double[][][] absoluteThresholdValues; + protected Double[][][] relativeThresholdValues; + + protected List absoluteTop; + protected List absoluteAny; + protected List relativeTop; + protected List relativeAny; + + protected int numAlternatives; + protected int numCriteria; + + public WeightedSumModelMCM() { + } + + public Map getCriteriaWeights() { + return criteriaWeights; + } + + public void setCriteriaWeights(Map criteriaWeights) { + this.criteriaWeights = criteriaWeights; + } + + public Double[] getAlternativesFinalPreferences() { + return alternativesFinalPreferences; + } + + public void setAlternativesFinalPreferences(Double[] alternativesFinalPreferences) { + this.alternativesFinalPreferences = alternativesFinalPreferences; + } + + public Double[][][] getAbsoluteThresholdValues() { + return absoluteThresholdValues; + } + + public void setAbsoluteThresholdValues(Double[][][] absoluteThresholdValues) { + this.absoluteThresholdValues = absoluteThresholdValues; + } + + public Double[][][] getRelativeThresholdValues() { + return relativeThresholdValues; + } + + public void setRelativeThresholdValues(Double[][][] relativeThresholdValues) { + this.relativeThresholdValues = relativeThresholdValues; + } + + public List getAbsoluteTop() { + return absoluteTop; + } + + public void setAbsoluteTop(List absoluteTop) { + this.absoluteTop = absoluteTop; + } + + public List getAbsoluteAny() { + return absoluteAny; + } + + public void setAbsoluteAny(List absoluteAny) { + this.absoluteAny = absoluteAny; + } + + public List getRelativeTop() { + return relativeTop; + } + + public void setRelativeTop(List relativeTop) { + this.relativeTop = relativeTop; + } + + public List getRelativeAny() { + return relativeAny; + } + + public void setRelativeAny(List relativeAny) { + this.relativeAny = relativeAny; + } + + /** + * The most sensitive alternative is computed from the threshold values. + */ + @Override + public void execute(HashMatrix decisionMatrix, + Map criteriaWeights) { + numAlternatives = problemService.getAll(Alternative.Type).length; + numCriteria = problemService.getMainElements(Criterion.Type).length; + + this.setCriteriaWeights(criteriaWeights); + this.normalizeDecisionMatrix(decisionMatrix); + this.computeFinalPreferences(); + this.computeRanking(); + this.computeAbsoluteThresholdValues(); + this.computeRelativeThresholdValues(); + this.computeAbsoluteTopCriticalAlternative(); + this.computeAbsoluteAnyCriticalAlternative(); + this.computeRelativeTopCriticalAlternative(); + this.computeRelativeAnyCriticalAlternative(); + } + + protected abstract void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation); + + private void computeFinalPreferences() { + alternativesFinalPreferences = new Double[numAlternatives]; + for (int alternative = 0; alternative < numAlternatives; alternative++) { + alternativesFinalPreferences[alternative] = 0d; + for (int criterion = 0; criterion < numCriteria; criterion++) { + alternativesFinalPreferences[alternative] += decisionMatrix[alternative][criterion] + * criteriaWeights.get(problemService.getMainElements(Criterion.Type)[criterion]); + } + } + } + + private void computeRanking() { + ranking = IntStream.range(0, alternativesFinalPreferences.length).boxed() + .sorted((j, i) -> alternativesFinalPreferences[i].compareTo(alternativesFinalPreferences[j])) + .mapToInt(ele -> ele).toArray(); + } + + /** + * Get the indexes of the best alternatives + * + * @return indexes of the best alternatives + */ + private List getBestAlternatives() { + List bestAlternatives = new LinkedList(); + for (int i = 0; i < numAlternatives; i++) { + if (ranking[i] == 0) + bestAlternatives.add(Integer.valueOf(i)); + } + return bestAlternatives; + } + + private void computeAbsoluteThresholdValues() { + absoluteThresholdValues = new Double[numAlternatives][numAlternatives][numCriteria]; + + Criterion cr; + for (int i = 0; i < numAlternatives; i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + cr = (Criterion) problemService.getMainElements(Criterion.Type)[k]; + if (i != j) { + if (criteriaWeights.get(cr) == 0) { + absoluteThresholdValues[i][j][k] = NON_FEASIBLE; + } else { + absoluteThresholdValues[i][j][k] = (alternativesFinalPreferences[i] + - alternativesFinalPreferences[j]) / criteriaWeights.get(cr); + if (absoluteThresholdValues[i][j][k] > criteriaWeights.get(cr)) + absoluteThresholdValues[i][j][k] = NON_FEASIBLE; + } + } + } + } + } + } + + private void computeRelativeThresholdValues() { + relativeThresholdValues = new Double[numAlternatives][numAlternatives][numCriteria]; + + for (int i = 0; i < numAlternatives; i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + if (absoluteThresholdValues[i][j][k] != NON_FEASIBLE) { + if ((Double) decisionMatrix[i][k] == 0) + relativeThresholdValues[i][j][k] = NON_FEASIBLE; + else + relativeThresholdValues[i][j][k] = absoluteThresholdValues[i][j][k] + * (100d / (Double) decisionMatrix[i][k]); + } else + relativeThresholdValues[i][j][k] = NON_FEASIBLE; + } + } + } + } + + /** + * Look for the minimal change in absolute terms among the best alternative/s + * and the rest of them + */ + private void computeAbsoluteTopCriticalAlternative() { + List bestAlternatives = getBestAlternatives(); + + absoluteTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = absoluteThresholdValues[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteTop.clear(); + absoluteTop.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeAbsoluteAnyCriticalAlternative() { + + absoluteAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = absoluteThresholdValues[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + absoluteAny.clear(); + absoluteAny.add(Integer.valueOf(k)); + } else if (change == minimum) + absoluteAny.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in relative terms among the best alternative/s + * and the rest of them + */ + private void computeRelativeTopCriticalAlternative() { + List bestAlternatives = getBestAlternatives(); + + relativeTop = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < bestAlternatives.size(); i++) { + for (int j = 0; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = relativeThresholdValues[bestAlternatives.get(i)][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeTop.clear(); + relativeTop.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeTop.add(Integer.valueOf(k)); + } + } + } + } + } + + /** + * Look for the minimal change in absolute terms among all the alternatives + */ + private void computeRelativeAnyCriticalAlternative() { + + relativeAny = new LinkedList(); + + Double minimum = Double.MAX_VALUE, change; + for (int i = 0; i < numAlternatives - 1; i++) { + for (int j = i + 1; j < numAlternatives; j++) { + for (int k = 0; k < numCriteria; k++) { + change = relativeThresholdValues[i][j][k]; + if (change != NON_FEASIBLE) { + change = Math.abs(change); + if (change < minimum) { + minimum = change; + relativeAny.clear(); + relativeAny.add(Integer.valueOf(k)); + } else if (change == minimum) + relativeAny.add(Integer.valueOf(k)); + } + } + } + } + } + + @Override + public Double[][][] getChanges(FieldsChanges typeOfChange) { + switch(typeOfChange) { + case absolute: + return absoluteThresholdValues; + case relative: + return relativeThresholdValues; + default: + return null; + } + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMFuzzy.java b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMFuzzy.java new file mode 100644 index 0000000..9f8f808 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMFuzzy.java @@ -0,0 +1,51 @@ +package flintstones.entity.sensitiveanalysismodel.wsm.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class WeightedSumModelMCMFuzzy extends WeightedSumModelMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((FuzzyValuation) decisionMatrixAggregation.get(alt, crit)).getFuzzyNumber().getB(); + altPos++; + } + + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMNumeric.java b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMNumeric.java new file mode 100644 index 0000000..f955a0e --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMNumeric.java @@ -0,0 +1,51 @@ +package flintstones.entity.sensitiveanalysismodel.wsm.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.numeric.NumericValuation; + +public class WeightedSumModelMCMNumeric extends WeightedSumModelMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((NumericValuation) decisionMatrixAggregation.get(alt, crit)).getValue(); + altPos++; + } + + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMTwoTuple.java b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMTwoTuple.java new file mode 100644 index 0000000..08f7839 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel.wsm.mcm/src/flintstones/entity/sensitiveanalysismodel/wsm/mcm/WeightedSumModelMCMTwoTuple.java @@ -0,0 +1,51 @@ +package flintstones.entity.sensitiveanalysismodel.wsm.mcm; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class WeightedSumModelMCMTwoTuple extends WeightedSumModelMCM { + + @Override + protected void normalizeDecisionMatrix(HashMatrix decisionMatrixAggregation) { + decisionMatrix = new Double[problemService.getAll(Alternative.Type).length][problemService.getMainElements(Criterion.Type).length]; + + int critPos = 0, altPos; + for(ProblemElement crit: problemService.getMainElements(Criterion.Type)) { + altPos = 0; + for(ProblemElement alt: problemService.getAll(Alternative.Type)) { + decisionMatrix[altPos][critPos] = ((TwoTupleValuation) decisionMatrixAggregation.get(alt, crit)).calculateInverseDelta(); + altPos++; + } + + critPos++; + } + normalize(); + } + + private Double[][] normalize() { + double acum, noStandarizedValue; + + for (int i = 0; i < numCriteria; ++i) { + acum = sumCriteria(i); + for (int j = 0; j < numAlternatives; ++j) { + noStandarizedValue = (Double) decisionMatrix[j][i]; + decisionMatrix[j][i] = (double) Math.round((noStandarizedValue / acum) * 10000d) / 10000d; + } + } + + return decisionMatrix; + } + + private double sumCriteria(int numCriterion) { + double value = 0; + for (int j = 0; j < numAlternatives; ++j) { + value += Math.pow((Double) decisionMatrix[j][numCriterion], 2); + } + return Math.sqrt(value); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/.classpath b/bundles/flintstones.entity.sensitiveanalysismodel/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysismodel/.polyglot.META-INF new file mode 100644 index 0000000..aec4cfd --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysismodel + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Most critical criterion + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/.project b/bundles/flintstones.entity.sensitiveanalysismodel/.project new file mode 100644 index 0000000..f0326bc --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/.project @@ -0,0 +1,50 @@ + + + flintstones.entity.sensitiveanalysismodel + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362573 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysismodel/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1ebc11e --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Most critical criterion +Bundle-SymbolicName: flintstones.entity.sensitiveanalysismodel;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.sensitiveanalysis.mcc +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.sensitiveanalysismodel +Require-Bundle: flintstones.entity.problemelement;visibility:=reexport, + flintstones.entity.valuation;visibility:=reexport, + flintstones.helper.data;visibility:=reexport, + org.eclipse.e4.core.contexts, + javax.inject, + flintstones.helper.extensionpoint, + org.eclipse.e4.ui.model.workbench +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/build.properties b/bundles/flintstones.entity.sensitiveanalysismodel/build.properties new file mode 100644 index 0000000..3ea470d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/build.properties @@ -0,0 +1,5 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml +source.. = src/ diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/plugin.xml b/bundles/flintstones.entity.sensitiveanalysismodel/plugin.xml new file mode 100644 index 0000000..acbc925 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/plugin.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/schema/flintstones.entity.sensitiveanalysismodel.extension.exsd b/bundles/flintstones.entity.sensitiveanalysismodel/schema/flintstones.entity.sensitiveanalysismodel.extension.exsd new file mode 100644 index 0000000..74122ee --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/schema/flintstones.entity.sensitiveanalysismodel.extension.exsd @@ -0,0 +1,116 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysismodel/src/flintstones/entity/sensitiveanalysismodel/SensitiveAnalysisModel.java b/bundles/flintstones.entity.sensitiveanalysismodel/src/flintstones/entity/sensitiveanalysismodel/SensitiveAnalysisModel.java new file mode 100644 index 0000000..54bdbde --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysismodel/src/flintstones/entity/sensitiveanalysismodel/SensitiveAnalysisModel.java @@ -0,0 +1,95 @@ +package flintstones.entity.sensitiveanalysismodel; + +import java.util.Map; + +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; + +public abstract class SensitiveAnalysisModel { + + public static final String EXTENSION_POINT = "flintstones.entity.sensitiveanalysismodel.extension"; + + public static final Double NON_FEASIBLE = null; + + protected String id; + protected String name; + + protected Double[][] decisionMatrix; + protected Map criteriaWeights; + protected int[] ranking; + + /** + * The Class Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The id. */ + id, + /** The name. */ + name, + /** The implementation. */ + implementation + } + + /** + * The Class Fields. + */ + public enum FieldsChanges implements ExtensionEnum { + + /** The id. */ + relative, + /** The name. */ + absolute, + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double[][] getDecisionMatrix() { + return decisionMatrix; + } + + public void setDecisionMatrix(Double[][] decisionMatrix) { + this.decisionMatrix = decisionMatrix; + } + + public Map getCriteriaWeights() { + return criteriaWeights; + } + + public void setCriteriaWeights(Map criteriaWeights) { + this.criteriaWeights = criteriaWeights; + } + + public int[] getRanking() { + return ranking; + } + + public void setRanking(int[] ranking) { + this.ranking = ranking; + } + + public abstract void execute(HashMatrix decisionMatrix, Map criteriaWeights); + + public abstract Double[][][] getChanges(FieldsChanges typeOfChange); + + @Override + public String toString() { + return this.id; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.classpath b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.polyglot.META-INF new file mode 100644 index 0000000..c2a5a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysisproblem.mcc + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Most critical criterion problem + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.project b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.project new file mode 100644 index 0000000..131bc70 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysisproblem.mcc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362587 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/META-INF/MANIFEST.MF new file mode 100644 index 0000000..418da01 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Most critical criterion problem +Bundle-SymbolicName: flintstones.entity.sensitiveanalysisproblem.mcc;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysisproblem.mcc +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.sensitiveanalysisproblem diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/build.properties b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/plugin.xml b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/plugin.xml new file mode 100644 index 0000000..325d750 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/plugin.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/src/NO_BORRAR b/bundles/flintstones.entity.sensitiveanalysisproblem.mcc/src/NO_BORRAR new file mode 100644 index 0000000..e69de29 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.classpath b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.polyglot.META-INF new file mode 100644 index 0000000..83d8cbc --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysisproblem.mcm + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Most critical measure problem + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.project b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.project new file mode 100644 index 0000000..3459615 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sensitiveanalysisproblem.mcm + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362588 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0e9b15e --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Most critical measure problem +Bundle-SymbolicName: flintstones.entity.sensitiveanalysisproblem.mcm;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysisproblem.mcm +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.sensitiveanalysisproblem diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/build.properties b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/plugin.xml b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/plugin.xml new file mode 100644 index 0000000..0623f2a --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/plugin.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/src/NO_BORRAR b/bundles/flintstones.entity.sensitiveanalysisproblem.mcm/src/NO_BORRAR new file mode 100644 index 0000000..e69de29 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/.classpath b/bundles/flintstones.entity.sensitiveanalysisproblem/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/.polyglot.META-INF b/bundles/flintstones.entity.sensitiveanalysisproblem/.polyglot.META-INF new file mode 100644 index 0000000..0726b6b --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sensitiveanalysisproblem + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Sensitive analysis problem + + Sinbad2 + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/.project b/bundles/flintstones.entity.sensitiveanalysisproblem/.project new file mode 100644 index 0000000..c31c751 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/.project @@ -0,0 +1,50 @@ + + + flintstones.entity.sensitiveanalysisproblem + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362583 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sensitiveanalysisproblem/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6a69e48 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Sensitive analysis problem +Bundle-SymbolicName: flintstones.entity.sensitiveanalysisproblem;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.entity.sensitiveanalysisproblem +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.sensitiveanalysismodel, + flintstones.model.sensitiveanalysismodel.service, + flintstones.helper.extensionpoint, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.ui.model.workbench, + javax.annotation +Service-Component: component.xml +Bundle-ActivationPolicy: lazy +Export-Package: flintstones.entity.sensitiveanalysisproblem.service diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/build.properties b/bundles/flintstones.entity.sensitiveanalysisproblem/build.properties new file mode 100644 index 0000000..ffaa565 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/build.properties @@ -0,0 +1,6 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml,\ + plugin.xml +source.. = src/ diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/component.xml b/bundles/flintstones.entity.sensitiveanalysisproblem/component.xml new file mode 100644 index 0000000..94851a3 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/component.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/plugin.xml b/bundles/flintstones.entity.sensitiveanalysisproblem/plugin.xml new file mode 100644 index 0000000..8161aea --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/plugin.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/schema/flintstones.entity.sensitiveanalysisproblem.extension.exsd b/bundles/flintstones.entity.sensitiveanalysisproblem/schema/flintstones.entity.sensitiveanalysisproblem.extension.exsd new file mode 100644 index 0000000..9e8bafd --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/schema/flintstones.entity.sensitiveanalysisproblem.extension.exsd @@ -0,0 +1,127 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/SensitiveAnalysisProblem.java b/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/SensitiveAnalysisProblem.java new file mode 100644 index 0000000..9f5dbfb --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/SensitiveAnalysisProblem.java @@ -0,0 +1,73 @@ +package flintstones.entity.sensitiveanalysisproblem; + +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; + +public class SensitiveAnalysisProblem { + + protected String id; + protected String valuationId; + protected SensitiveAnalysisModel[] models; + + /** + * The Class Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The id. */ + uid, + /** The valuation. */ + valuation, + /** The model. */ + model, + /** The implementation. */ + implementation + } + + public SensitiveAnalysisProblem() { + } + + public SensitiveAnalysisProblem(String id) { + this.setId(id); + } + + public SensitiveAnalysisProblem(String id, String valuationId) { + this.setId(id); + this.setValuationId(valuationId); + } + + public SensitiveAnalysisProblem(String id, String valuationId, SensitiveAnalysisModel[] models) { + this.setId(id); + this.setValuationId(valuationId); + this.setModels(models); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getValuationId() { + return valuationId; + } + + public void setValuationId(String valuationId) { + this.valuationId = valuationId; + } + + public SensitiveAnalysisModel[] getModels() { + return models; + } + + public void setModels(SensitiveAnalysisModel[] models) { + this.models = models; + } + + @Override + public String toString() { + return this.id; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/provider/SensitiveAnalysisProblemProvider.java b/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/provider/SensitiveAnalysisProblemProvider.java new file mode 100644 index 0000000..3c68527 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/provider/SensitiveAnalysisProblemProvider.java @@ -0,0 +1,117 @@ +package flintstones.entity.sensitiveanalysisproblem.provider; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.sensitiveanalysisproblem.SensitiveAnalysisProblem; +import flintstones.entity.sensitiveanalysisproblem.service.ISensitiveAnalysisProblemService; +import flintstones.helper.data.Pair; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.model.sensitiveanalysismodel.service.ISensitiveAnalysisModelService; + +public class SensitiveAnalysisProblemProvider implements ISensitiveAnalysisProblemService { + + /** The Constant EXTENSION_POINT. */ + public final static String EXTENSION_POINT = "flintstones.entity.sensitiveanalysisproblem.extension"; //$NON-NLS-1$ + + @Inject + IEclipseContext context; + + @Inject + ISensitiveAnalysisModelService saModelService; + + private BaseRegistry reg; + + private HashMap, SensitiveAnalysisProblem> problems = new HashMap<>(); + + public SensitiveAnalysisProblemProvider() {} + + @PostConstruct + public void init() { + this.reg = new BaseRegistry(EXTENSION_POINT); + this.cacheAllProblems(); + } + + public void cacheAllProblems() { + + problems.clear(); + + ExtensionRegistry[] regProblems = reg.getAllRegistries(); + + for (ExtensionRegistry regProblem : regProblems) { + SensitiveAnalysisProblem saProblem = new SensitiveAnalysisProblem(); + saProblem.setId(regProblem.getAttribute(SensitiveAnalysisProblem.Fields.uid)); + saProblem.setValuationId(regProblem.getAttribute(SensitiveAnalysisProblem.Fields.valuation)); + saProblem.setModels(loadModels(regProblem)); + problems.put(new Pair(saProblem.getId(), saProblem.getValuationId()), saProblem); + } + } + + private SensitiveAnalysisModel[] loadModels(ExtensionRegistry regProblem) { + SensitiveAnalysisModel[] models = new SensitiveAnalysisModel[regProblem.getAttributeReferences(SensitiveAnalysisProblem.Fields.model).length]; + + int cont = 0; + for (ExtensionRegistry regModel : regProblem.getAttributeReferences(SensitiveAnalysisProblem.Fields.model)) { + String saModelId = regModel.getAttribute(SensitiveAnalysisProblem.Fields.uid); + models[cont] = saModelService.getSensitiveAnalysisModel(saModelId); + cont++; + } + return models; + } + + @Override + public SensitiveAnalysisProblem getSensitiveAnalysisProblem(String problemId, String valuationId) { + return problems.get(new Pair(problemId, valuationId)); + } + + @Override + public String[] getSensitiveAnalysisProblemsIdsFor(String valuationId) { + List ids = new LinkedList(); + for(Pair pair: problems.keySet()) { + if(pair.getRight().equals(valuationId)) + ids.add(pair.getLeft()); + } + return ids.toArray(new String[0]); + } + + @Override + public String[] getSensitiveAnalysisModelsNamesFor(String problemId, String valuationId) { + SensitiveAnalysisProblem saProblem = problems.get(new Pair(problemId, valuationId)); + return getSensitiveAnalysisModelsNames(saProblem); + } + + @Override + public String[] getSensitiveAnalysisModelsNames(SensitiveAnalysisProblem sap) { + String[] ids = new String[sap.getModels().length]; + int cont = 0; + for(SensitiveAnalysisModel saModel: sap.getModels()) { + ids[cont] = saModel.getName(); + cont++; + } + return ids; + } + + @Override + public SensitiveAnalysisModel getSensitiveAnalysisModel(SensitiveAnalysisProblem sap, String modelName) { + for(SensitiveAnalysisModel saModel: sap.getModels()) { + if(saModel.getName().equals(modelName)) + return saModel; + } + return null; + } + + @Override + public SensitiveAnalysisModel getSensitiveAnalysisModel(String problemId, String modelName, String valuationId) { + SensitiveAnalysisProblem saProblem = getSensitiveAnalysisProblem(problemId, valuationId); + return getSensitiveAnalysisModel(saProblem, modelName); + } + +} diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/provider/SensitiveAnalysisProblemServiceContextFunction.java b/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/provider/SensitiveAnalysisProblemServiceContextFunction.java new file mode 100644 index 0000000..9599254 --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/provider/SensitiveAnalysisProblemServiceContextFunction.java @@ -0,0 +1,28 @@ +package flintstones.entity.sensitiveanalysisproblem.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.entity.sensitiveanalysisproblem.service.ISensitiveAnalysisProblemService; + +/** + * The Class MostCriticalCriterionServiceContextFunction add the MostCriticalCriterion Service instance to global context. + */ +public class SensitiveAnalysisProblemServiceContextFunction extends ContextFunction { + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core. + * contexts.IEclipseContext, java.lang.String) */ + @Override + public Object compute(IEclipseContext context, String contextKey) { + ISensitiveAnalysisProblemService service = ContextInjectionFactory.make(SensitiveAnalysisProblemProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(ISensitiveAnalysisProblemService.class, service); + return service; + } +} diff --git a/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/service/ISensitiveAnalysisProblemService.java b/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/service/ISensitiveAnalysisProblemService.java new file mode 100644 index 0000000..ea0582f --- /dev/null +++ b/bundles/flintstones.entity.sensitiveanalysisproblem/src/flintstones/entity/sensitiveanalysisproblem/service/ISensitiveAnalysisProblemService.java @@ -0,0 +1,56 @@ +package flintstones.entity.sensitiveanalysisproblem.service; + +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.sensitiveanalysisproblem.SensitiveAnalysisProblem; + +public interface ISensitiveAnalysisProblemService { + + /** + * Gets a sensitive analysis problem by its id and the supported valuation id. + * + * @param problemId the problem id + * @param valuationId the valuation id + * @return Instanced SensitiveAnalysisProblem + */ + SensitiveAnalysisProblem getSensitiveAnalysisProblem(String problemId, String valuationId); + + /** + * Get all the sensitive analysis models names for a specific sensitive analysis problem and valuation + * @param problemId the sensitive analysis problem id + * @param valuationId the valuation id + * @return Array with all the names + */ + String[] getSensitiveAnalysisModelsNamesFor(String problemId, String valuationId); + + /** + * Get all the sensitive analysis models ids for a specific sensitive analysis problem + * @param sap the SensitiveAnalysisProblem + * @return Array with all the ids + */ + String[] getSensitiveAnalysisModelsNames(SensitiveAnalysisProblem sap); + + /** + * Get all the sensitive analysis problems for a specific valuation + * @param valuationId the valuation id + * @return Array with all the ids + */ + String[] getSensitiveAnalysisProblemsIdsFor(String valuationId); + + /** + * Get a sensitive analysis model for a specific sensitive analysis problem + * @param sap the SensitiveAnalysisProblem + * @param model the SensitiveAnalysisModel id + * @return SensitiveAnalysisModel + */ + SensitiveAnalysisModel getSensitiveAnalysisModel(SensitiveAnalysisProblem sap, String modelId); + + /** + * Get a sensitive analysis model for a specific sensitive analysis problem + * @param problemId the SensitiveAnalysisProblem id + * @param modelId the SensitiveAnalysisModel id + * @param valuationId the supported valuation id + * @return SensitiveAnalysisModel + */ + SensitiveAnalysisModel getSensitiveAnalysisModel(String problemId, String modelId, String valuationId); + +} diff --git a/bundles/flintstones.entity.sorting.ui/.classpath b/bundles/flintstones.entity.sorting.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.sorting.ui/.polyglot.META-INF b/bundles/flintstones.entity.sorting.ui/.polyglot.META-INF new file mode 100644 index 0000000..221c5d5 --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.sorting.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.entity.sorting.ui/.project b/bundles/flintstones.entity.sorting.ui/.project new file mode 100644 index 0000000..2f6859e --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.sorting.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362589 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.sorting.ui/META-INF/MANIFEST.MF b/bundles/flintstones.entity.sorting.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1d4d7e8 --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.entity.sorting.ui +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.sorting.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.html, + flintstones.entity.problemelement +Export-Package: flintstones.entity.sorting.ui diff --git a/bundles/flintstones.entity.sorting.ui/build.properties b/bundles/flintstones.entity.sorting.ui/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.sorting.ui/src/flintstones/entity/sorting/ui/SortingDiagram.java b/bundles/flintstones.entity.sorting.ui/src/flintstones/entity/sorting/ui/SortingDiagram.java new file mode 100644 index 0000000..faf98ea --- /dev/null +++ b/bundles/flintstones.entity.sorting.ui/src/flintstones/entity/sorting/ui/SortingDiagram.java @@ -0,0 +1,113 @@ +package flintstones.entity.sorting.ui; + +import java.util.ArrayList; +import java.util.List; + +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.html.svg.Svg; +import flintstones.helper.html.svg.SvgCanvas; +import flintstones.helper.html.svg.Tag; + +public class SortingDiagram extends SvgCanvas { + + Tag svg; + + int tWidth; + int tHeight; + + int hspace; + int vspace; + + int width = 500; + int height = 1000; + + int ts; + + List classes = new ArrayList<>(); + List profiles = new ArrayList<>(); + + public SortingDiagram() { + + vspace = height / 10; + hspace = width / 10; + ts = height / 25; + + tHeight = height + vspace*2; + tWidth = width + hspace*2; + + + + +// Tag upLine = Svg.getHorizontalLine(hspace, vspace, width); +// svg.add(upLine); +// + +// Tag bottomLine = Svg.getHorizontalLine(hspace, tHeight - vspace, width); +// svg.add(bottomLine); + + } + + public void setProfiles(List list) { + profiles = list; + } + + private int realocateY(double first, double last, double y) { + + boolean isAscending = first < last; + + double ny = isAscending ? y - first : first - y; + double max = isAscending ? last : first; + double min = isAscending ? first : last; + + double down = max - min; + + double r = ny / down; + int val = (int) (r * height); + + return val; + + } + + @Override + public String toString() { + + svg = (Tag) new Tag("svg") + .attr("xmlns","http://www.w3.org/2000/svg") + .attr("viewbox", "0 0 " + tWidth + " " + tHeight) + .attr("width", "100%") + .attr("height", "100%"); + + // Vertical Line + Tag vline = Svg.getVerticalLine(tWidth/2, vspace, height); + svg.add(vline); + + double[] values = profiles.stream().map(k -> k.getValue()).mapToDouble(Number::doubleValue).toArray(); + + Double up = null; + Double down = null; + if(values.length > 0) + up = values[0]; + + if(values.length > 1) + down = values[values.length-1]; + + if(values.length < 2) + return ""; + + + for(double value : values) { + int y = realocateY(up, down, value); + + Tag hLine = Svg.getHorizontalLine(hspace, vspace + y, width); + svg.add(hLine); + + Tag text = Svg.getText(hspace, vspace + y -vspace/4, ts, value+""); + svg.add(text); + } + + + return svg.toString(); + } + +} diff --git a/bundles/flintstones.entity.validatedmethod/.classpath b/bundles/flintstones.entity.validatedmethod/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.validatedmethod/.polyglot.META-INF b/bundles/flintstones.entity.validatedmethod/.polyglot.META-INF new file mode 100644 index 0000000..af59712 --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.validatedmethod + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Validatedmethod + diff --git a/bundles/flintstones.entity.validatedmethod/.project b/bundles/flintstones.entity.validatedmethod/.project new file mode 100644 index 0000000..325cab6 --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.validatedmethod + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362590 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.validatedmethod/META-INF/MANIFEST.MF b/bundles/flintstones.entity.validatedmethod/META-INF/MANIFEST.MF new file mode 100644 index 0000000..31b5a89 --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Validatedmethod +Bundle-SymbolicName: flintstones.entity.validatedmethod +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.validatedmethod +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.validatedmethod +Require-Bundle: flintstones.entity.method;visibility:=reexport, + flintstones.model.problemelement.service;visibility:=reexport, + flintstones.model.domain.service;visibility:=reexport, + flintstones.model.valuation.service;visibility:=reexport, + org.eclipse.e4.core.contexts;visibility:=reexport, + javax.annotation diff --git a/bundles/flintstones.entity.validatedmethod/build.properties b/bundles/flintstones.entity.validatedmethod/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.validatedmethod/src/flintstones/entity/validatedmethod/ValidatedMethod.java b/bundles/flintstones.entity.validatedmethod/src/flintstones/entity/validatedmethod/ValidatedMethod.java new file mode 100644 index 0000000..a2365f3 --- /dev/null +++ b/bundles/flintstones.entity.validatedmethod/src/flintstones/entity/validatedmethod/ValidatedMethod.java @@ -0,0 +1,77 @@ +package flintstones.entity.validatedmethod; + +import flintstones.entity.method.Method; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.Statement; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import java.util.HashMap; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; + +public abstract class ValidatedMethod extends Method { + + @Inject + protected IProblemElementService problemService; + + @Inject + protected IDomainService domainService; + + @Inject + protected IValuationService valuationService; + + @Inject + protected IEclipseContext context; + + @Inject + @Translation + protected flintstones.entity.problemelement.messages.Messages problemMessages; + + @Inject + @Translation + protected flintstones.entity.domain.messages.Messages domainMessages; + + @Inject + @Translation + protected flintstones.entity.valuation.messages.Messages valuationMessages; + + protected ChainValidator validator; + + @PostConstruct + public void init() { + reloadValidator(); + } + + @Override + public boolean canBeExecuted() { + reloadValidator(); + return validator.validate(); + } + + @Override + public String[] getPassedExecuteConditions() { + return validator.getChainMessages().stream().filter(k -> k.isSuccessful()).map( k2 -> k2.getMessage() ).toArray( String[]::new ); + } + + @Override + public String[] getFailedExecuteConditions() { + return validator.getChainMessages().stream().filter(k -> k.isWrong()).map( k2 -> k2.getMessage() ).toArray( String[]::new ); + } + + @Override + public Statement getExecutionStatement() { + return validator.getStatement(); + } + + protected abstract void reloadValidator(); + + @Override + protected HashMap exportData() { + return new HashMap<>(); + } + +} diff --git a/bundles/flintstones.entity.valuation/.classpath b/bundles/flintstones.entity.valuation/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.valuation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.valuation/.polyglot.META-INF b/bundles/flintstones.entity.valuation/.polyglot.META-INF new file mode 100644 index 0000000..a4c1e3d --- /dev/null +++ b/bundles/flintstones.entity.valuation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.valuation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Valuation + diff --git a/bundles/flintstones.entity.valuation/.project b/bundles/flintstones.entity.valuation/.project new file mode 100644 index 0000000..1b472be --- /dev/null +++ b/bundles/flintstones.entity.valuation/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.valuation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362591 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.valuation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.valuation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.valuation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.valuation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.valuation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.valuation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.valuation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.valuation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.valuation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.valuation/META-INF/MANIFEST.MF b/bundles/flintstones.entity.valuation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c5091af --- /dev/null +++ b/bundles/flintstones.entity.valuation/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Valuation +Bundle-SymbolicName: flintstones.entity.valuation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entity.valuation +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.entity.valuation, + flintstones.entity.valuation.exception, + flintstones.entity.valuation.messages +Require-Bundle: flintstones.entity.domain;visibility:=reexport, + flintstones.helper.data.wxml;visibility:=reexport, + flintstones.entity.extensionenum, + javax.inject, + org.eclipse.e4.core.services diff --git a/bundles/flintstones.entity.valuation/build.properties b/bundles/flintstones.entity.valuation/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.entity.valuation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.entity.valuation/plugin.xml b/bundles/flintstones.entity.valuation/plugin.xml new file mode 100644 index 0000000..62a8491 --- /dev/null +++ b/bundles/flintstones.entity.valuation/plugin.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/bundles/flintstones.entity.valuation/schema/flintstones.valuation.exsd b/bundles/flintstones.entity.valuation/schema/flintstones.valuation.exsd new file mode 100644 index 0000000..e5d327a --- /dev/null +++ b/bundles/flintstones.entity.valuation/schema/flintstones.valuation.exsd @@ -0,0 +1,148 @@ + + + + + + + + + Este punto de extensión permite definir nuevos tipos de evaluaciones, los cuales estarán enlazados con un dominio concreto. + +Si revisamos la definición del punto de extensión de dominio, vemos que es posible crear distintos dominios que compartan implementación. Esto nos permite definir distintos tipos de evaluaciones para cada uno de los distintos dominios definidos. Se compartiría la implementación del dominio pero no la implementación de la evaluación. + +Por ejemplo un dominio numérico entero se evalúa de forma distinta a uno numérico entero intervalar pero la definición de dominio es la misma. + +============================================================================================================================================== + +This extension point allows you to define new types of evaluations, which will be linked to a specific domain. + +If we review the definition of the domain extension point, we see that it is possible to create different domains that share implementation. This allows us to define different types of evaluations for each of the different domains defined. The implementation of the domain would be shared but not the implementation of the evaluation. + +For example, an integer domain is evaluated differently than an interval integer domain but the domain definition is the same. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/Valuation.java b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/Valuation.java new file mode 100644 index 0000000..534f29c --- /dev/null +++ b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/Valuation.java @@ -0,0 +1,220 @@ +package flintstones.entity.valuation; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.domain.Domain; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.valuation.exception.InvalidValueException; +import flintstones.entity.valuation.messages.Messages; +import flintstones.helper.data.wxml.WNode; + +/** + * The Class Valuation. + */ +public abstract class Valuation implements Cloneable, Comparable { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** The domain. */ + protected Domain domain; + + /** The id. */ + private String id; + + /** The name. */ + private String name; + + /** The evaluated. */ + private boolean evaluated = false; + + /** The Constant EXTENSION_POINT. */ + public static String EXTENSION_POINT = "flintstones.valuation"; //$NON-NLS-1$ + + /** The image. */ + public static String IMAGE = "valuation.png";; //$NON-NLS-1$ + + /** + * The Enum Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The Valuation. */ + Valuation, + /** The id. */ + uid, + /** The name. */ + name, + /** The implementation. */ + implementation, + /** The domain. */ + domain, + /** The type. */ + type, + /** The is intermediate. */ + is_intermediate, + /** The Valuations. */ + Valuations, + /** The alternative. */ + alternative, + /** The criterion. */ + criterion, + /** The expert. */ + expert; + } + + /** + * Instantiates a new valuation. + */ + public Valuation() { + this.domain = null; + this.id = null; + this.name = null; + } + + public void setValueFromString(String value) { + + if(value == null) + throw new InvalidValueException("Debes rellenar el valor. "); + + if(domain == null) + throw new InvalidValueException("Debes asignar un dominio antes de evaluar. "); + + initFromString(value); + } + + protected abstract void initFromString(String value); + + /** + * Sets the id. + * + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Sets the domain. + * + * @param domain the new domain + */ + public void setDomain(Domain domain) { + this.domain = domain; + } + + /** + * Gets the domain. + * + * @return the domain + */ + public Domain getDomain() { + return this.domain; + } + + /* (non-Javadoc) + * + * @see java.lang.Object#clone() */ + @Override + public Object clone() { +// throw new RuntimeException("No se puede clonar así"); + + Valuation result = null; + + try { + result = (Valuation) super.clone(); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + + if(domain != null) { + result.domain = (Domain) domain.clone(); + } + + return result; + + + } + + /** + * Negate valuation. + * + * @return the valuation + */ + public abstract Valuation negateValuation(); + + /** + * Change format valuation to string. + * + * @return the string + */ + public abstract String changeFormatValuationToString(); + + /** + * Checks if is evaluated. + * + * @return true, if is evaluated + */ + public boolean isEvaluated() { + return this.evaluated; + } + + /** + * Sets the evaluated. + * + * @param status the new evaluated + */ + public void setEvaluated(boolean status) { + this.evaluated = status; + } + + /** + * Write. + * + * @param writer the writer + * @throws XMLStreamException the XML stream exception + */ + public abstract void write(XMLStreamWriter writer) throws XMLStreamException; + + /** + * Read. + * + * @param node the node + */ + public abstract void read(WNode node); + +} \ No newline at end of file diff --git a/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/exception/InvalidValueException.java b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/exception/InvalidValueException.java new file mode 100644 index 0000000..90d4a53 --- /dev/null +++ b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/exception/InvalidValueException.java @@ -0,0 +1,14 @@ +package flintstones.entity.valuation.exception; + +public class InvalidValueException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = -2367035980186200517L; + + public InvalidValueException(String message) { + super(message); + } + +} diff --git a/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/Messages.java b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/Messages.java new file mode 100644 index 0000000..3b618c1 --- /dev/null +++ b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/Messages.java @@ -0,0 +1,13 @@ +// This file has been auto-generated +package flintstones.entity.valuation.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings({ "javadoc", "nls" }) +public class Messages { + + public String Valuation_entity = "Valuation"; + public String Valuation_image = "valuation.png"; + +} diff --git a/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/messages.properties b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/messages.properties new file mode 100644 index 0000000..fba2ffc --- /dev/null +++ b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/messages.properties @@ -0,0 +1,3 @@ +Valuation_entity=valuation +Valuation_extension=flintstones.valuation +Valuation_image=valuation.png diff --git a/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/messages_es.properties b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/messages_es.properties new file mode 100644 index 0000000..dd8c530 --- /dev/null +++ b/bundles/flintstones.entity.valuation/src/flintstones/entity/valuation/messages/messages_es.properties @@ -0,0 +1,3 @@ +Valuation_entity=Evaluación +Valuation_extension=flintstones.valuation +Valuation_image=valuation.png diff --git a/bundles/flintstones.entity.wvaluation/.classpath b/bundles/flintstones.entity.wvaluation/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.entity.wvaluation/.polyglot.META-INF b/bundles/flintstones.entity.wvaluation/.polyglot.META-INF new file mode 100644 index 0000000..32e5201 --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.entity.wvaluation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Wvaluation + diff --git a/bundles/flintstones.entity.wvaluation/.project b/bundles/flintstones.entity.wvaluation/.project new file mode 100644 index 0000000..6adb815 --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/.project @@ -0,0 +1,45 @@ + + + flintstones.entity.wvaluation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362592 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.entity.wvaluation/META-INF/MANIFEST.MF b/bundles/flintstones.entity.wvaluation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..533b0a9 --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Wvaluation +Bundle-SymbolicName: flintstones.entity.wvaluation +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.entitities.wvaluation +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.valuation +Export-Package: flintstones.entity.wvaluation diff --git a/bundles/flintstones.entity.wvaluation/build.properties b/bundles/flintstones.entity.wvaluation/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.entity.wvaluation/src/flintstones/entity/wvaluation/WValuation.java b/bundles/flintstones.entity.wvaluation/src/flintstones/entity/wvaluation/WValuation.java new file mode 100644 index 0000000..1cd8d7f --- /dev/null +++ b/bundles/flintstones.entity.wvaluation/src/flintstones/entity/wvaluation/WValuation.java @@ -0,0 +1,109 @@ +package flintstones.entity.wvaluation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.valuation.Valuation; + +/** + * The Class WValuation. + * Wrapper around Valuation to stick together a valuation and its ProblemElements + */ +public class WValuation { + + /** The pek. */ + ProblemElementKey pek; + + /** The v. */ + Valuation v; + + /** + * Instantiates a new w valuation. + * + * @param pek the pek + * @param v the v + */ + public WValuation(ProblemElementKey pek, Valuation v) { + this.pek = pek; + this.v = v; + } + + /** + * Instantiates a new w valuation. + * + * @param entry the entry + */ + public WValuation(Entry entry) { + this(entry.getKey(), entry.getValue()); + } + + /** + * Instantiates a new w valuation. + * + * @param expert the expert + * @param alternative the alternative + * @param criterion the criterion + * @param valuation the valuation + */ + public WValuation(Expert expert, Alternative alternative, Criterion criterion, Valuation valuation) { + this(new ProblemElementKey(expert, alternative, criterion), valuation); + } + + /** + * Gets the pek. + * + * @return the pek + */ + public ProblemElementKey getPEK() { + return pek; + } + + /** + * Gets the valuation. + * + * @return the valuation + */ + public Valuation getValuation() { + return this.v; + } + + + /** + * Gets the valuations as array. + * + * @param waluations the waluations + * @return the valuations as array + */ + public static Valuation[] getValuationsAsArray(ArrayList waluations) { + return waluations.stream().map( k -> k.getValuation()).toArray(Valuation[]::new); + } + + /** + * Gets the valuation as list. + * + * @param valuations the valuations + * @return the valuation as list + */ + public static ArrayList getValuationAsList(List valuations){ + return (ArrayList) valuations.stream().map( k -> k.getValuation()).collect(Collectors.toList()); + } + + /** + * Gets the valuation as list. + * + * @param the generic type + * @param valuations the valuations + * @param clazz the clazz + * @return the valuation as list + */ + public static ArrayList getValuationAsList(List valuations, Class clazz){ + return (ArrayList) valuations.stream().map( k -> clazz.cast(k.getValuation()) ).collect(Collectors.toList()); + } + +} diff --git a/bundles/flintstones.helper.ahp/.classpath b/bundles/flintstones.helper.ahp/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.helper.ahp/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.ahp/.polyglot.META-INF b/bundles/flintstones.helper.ahp/.polyglot.META-INF new file mode 100644 index 0000000..3043c65 --- /dev/null +++ b/bundles/flintstones.helper.ahp/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.ahp + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] AHP helper + + Sinbad2 + + diff --git a/bundles/flintstones.helper.ahp/.project b/bundles/flintstones.helper.ahp/.project new file mode 100644 index 0000000..3492657 --- /dev/null +++ b/bundles/flintstones.helper.ahp/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.ahp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362603 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.ahp/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.ahp/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.ahp/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.ahp/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.ahp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.helper.ahp/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.ahp/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.ahp/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.ahp/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.ahp/META-INF/MANIFEST.MF b/bundles/flintstones.helper.ahp/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f3cd49d --- /dev/null +++ b/bundles/flintstones.helper.ahp/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: AHP helper +Bundle-SymbolicName: flintstones.helper.ahp +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.helper.ahp +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.helper.ahp diff --git a/bundles/flintstones.helper.ahp/build.properties b/bundles/flintstones.helper.ahp/build.properties new file mode 100644 index 0000000..41eb6ad --- /dev/null +++ b/bundles/flintstones.helper.ahp/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.ahp/src/flintstones/helper/ahp/AHPHelper.java b/bundles/flintstones.helper.ahp/src/flintstones/helper/ahp/AHPHelper.java new file mode 100644 index 0000000..865a3cc --- /dev/null +++ b/bundles/flintstones.helper.ahp/src/flintstones/helper/ahp/AHPHelper.java @@ -0,0 +1,40 @@ +package flintstones.helper.ahp; + +public class AHPHelper { + + /** The numeric labels. */ + private static final String[] numericLabels = new String[]{ + "1/9", "1/8", "1/7", "1/6", "1/5", "1/4", "1/3", "1/2", + "1", + "2" , "3", "4", "5", "6", "7", "8", "9"}; + + + /* (non-Javadoc) + * @see flintstones.entity.domain.Domain#midpoint() + */ + public static double getMidPoint() { + return 8; + } + + /** + * Gets the labels. + * + * @return the labels + */ + public static String[] getLabels() { + return numericLabels; + } + + /** + * Gets the inverse index. + * + * @param index the index + * @return the inverse index + */ + public static int getInverseIndex( int index ) { + int lastIndex = numericLabels.length -1; // 16 -> 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 + int compIndex = lastIndex - index; // 16-5 = 11. 1/4 => 4. + return compIndex; + } + +} diff --git a/bundles/flintstones.helper.chainvalidator/.classpath b/bundles/flintstones.helper.chainvalidator/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.chainvalidator/.polyglot.META-INF b/bundles/flintstones.helper.chainvalidator/.polyglot.META-INF new file mode 100644 index 0000000..41c3685 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.chainvalidator + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Chainvalidator + diff --git a/bundles/flintstones.helper.chainvalidator/.project b/bundles/flintstones.helper.chainvalidator/.project new file mode 100644 index 0000000..a0dcb8b --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.chainvalidator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362604 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.chainvalidator/META-INF/MANIFEST.MF b/bundles/flintstones.helper.chainvalidator/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e88806d --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Chainvalidator +Bundle-SymbolicName: flintstones.helper.chainvalidator +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.chainvalidator +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.helper.chainvalidator, + flintstones.helper.chainvalidator.operation, + flintstones.helper.chainvalidator.operation.method, + flintstones.helper.chainvalidator.pseudocode +Require-Bundle: javax.inject, + org.eclipse.e4.core.di, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.services, + org.eclipse.swt, + flintstones.entity.domain, + flintstones.helper.ui, + flintstones.domain.fuzzyset, + flintstones.helper.data, + javax.annotation, + flintstones.model.ui.service, + flintstones.entity.valuation, + org.apache.commons.lang, + flintstones.engine.R diff --git a/bundles/flintstones.helper.chainvalidator/build.properties b/bundles/flintstones.helper.chainvalidator/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/ChainMessage.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/ChainMessage.java new file mode 100644 index 0000000..50ae05e --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/ChainMessage.java @@ -0,0 +1,93 @@ +package flintstones.helper.chainvalidator; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class ChainMessage. + */ +public class ChainMessage { + + @Inject + @Translation + private Messages messages; + + /** The type sucess/error/operator. */ + private String type = ""; //$NON-NLS-1$ + + /** The Constant type_success. */ + private static final String type_success = Messages.Success; + + /** The Constant type_error. */ + private static final String type_error = Messages.Error; + + /** The Constant type_operator. */ + public static final String type_operator = Messages.Operator; + + /** The message. */ + private String message = ""; //$NON-NLS-1$ + + /** + * Instantiates a new chain message. + * + * @param msg the message + * @param type the type + */ + public ChainMessage(String msg, String type) { + this.message = msg; + this.type = type; + } + + /** + * Instantiates a new chain message. + * + * @param msg the msg + * @param status the status (success/error) -> type + */ + public ChainMessage(String msg, boolean status) { + this.message = msg; + this.type = status ? ChainMessage.type_success : ChainMessage.type_error; + } + + /** + * Checks if is right. + * + * @return true, if is right + */ + public boolean isSuccessful() { + return this.type.equals(ChainMessage.type_success); + } + + /** + * Checks if the message is an error. + * + * @return true, if is wrong + */ + public boolean isWrong() { + return this.type.equals(ChainMessage.type_error); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + return this.message; + + } + + /** + * Gets the message text. + * + * @return the message + */ + public String getMessage() { + return this.toString(); + } +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/ChainValidator.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/ChainValidator.java new file mode 100644 index 0000000..b9e8527 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/ChainValidator.java @@ -0,0 +1,289 @@ +package flintstones.helper.chainvalidator; + +import java.util.ArrayList; +import java.util.stream.IntStream; + +import javax.annotation.PostConstruct; +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 flintstones.helper.chainvalidator.messages.Messages; +import flintstones.helper.chainvalidator.operation.And; +import flintstones.helper.chainvalidator.operation.BaseOperation; +import flintstones.helper.chainvalidator.operation.Or; +import flintstones.helper.chainvalidator.operation.binary.Equals; +import flintstones.helper.chainvalidator.operation.binary.GreaterOrEqualThan; +import flintstones.helper.chainvalidator.operation.binary.GreaterThan; +import flintstones.helper.chainvalidator.operation.binary.IsTrue; +import flintstones.helper.chainvalidator.operation.binary.LowerOrEqualThan; +import flintstones.helper.chainvalidator.operation.binary.LowerThan; +import flintstones.helper.chainvalidator.operation.binary.NotEquals; + +/** + * The Class ChainValidator. + */ +public class ChainValidator { + + @Inject + @Translation + private Messages messages; + + @Inject + IEclipseContext context; + + /** The messages. */ + private final ArrayList chainMessages = new ArrayList<>(); + + /** The statement. */ + private Statement statement; + + /** The last operation. */ + private BaseOperation lastOperation; + + /** The operator. */ + private String operator; + + /** + * Instantiates a new chain validator. + */ + public ChainValidator() { + }; + + @PostConstruct + private void init() { + this.operator = this.messages.And; + this.statement = ContextInjectionFactory.make(Statement.class, this.context); + + } + + /** + * Validate. + * + * @return true, if successful + */ + public boolean validate() { + return this.statement.evaluate(); + }; + + /** + * Named. + * + * @param args the args + * @return the chain validator + */ + public ChainValidator named(String... args) { + IntStream.range(0, args.length) + .forEach(i -> this.lastOperation.addVariableName(args[i])); + return this; + } + + /** + * Or. + * + * @return the chain validator + */ + public ChainValidator or() { + + this.operator = this.messages.Or; + ChainMessage cm = new ChainMessage(this.messages.Or_hr, ChainMessage.type_operator); + ContextInjectionFactory.inject(cm, this.context); + this.chainMessages.add(cm); + + return this; + } + + /** + * Update statement. + */ + private void updateStatement() { + if (this.operator.equals(this.messages.And)) { + And and = ContextInjectionFactory.make(And.class, this.context); + this.statement.add(and); + } else if (this.operator.equals(this.messages.Or)) { + Or or = ContextInjectionFactory.make(Or.class, this.context); + this.statement.add(or); + } + } + + /** + * Evaluate item. + * + * @param op the op + */ + private void evaluateItem(BaseOperation op) { + + // Get values + boolean lastResult = op.evaluate(); + String msg = op.getValidationMessage(); + + // Make a human readable message + ChainMessage message = new ChainMessage(msg, lastResult); + ContextInjectionFactory.inject(message, this.context); + + this.chainMessages.add(message); + + // Update the if-statement + this.statement.add(op); + this.statement.updateResult(this.operator, lastResult); + this.operator = this.messages.And; + + } + + /** + * Equals operator shortcut. + * + * @param entity the entity + * @param a the first operand + * @param b the second operand + * @return An instance of this class to allow chaining more validations + */ + public ChainValidator equals(String entity, Object a, Object b) { + this.updateStatement(); + this.lastOperation = new Equals(entity, a, b); + ContextInjectionFactory.inject(this.lastOperation, this.context); + this.evaluateItem(this.lastOperation); + return this; + } + + /** + * Greater than operator shortcut. + * + * @param entity the entity + * @param a the first operand + * @param b the second operand + * @return An instance of this class to allow chaining more validations + */ + public ChainValidator greaterThan(String entity, Object a, Object b) { + this.updateStatement(); + this.lastOperation = new GreaterThan(entity, Double.valueOf(a.toString()), Double.valueOf(b.toString())); + ContextInjectionFactory.inject(this.lastOperation, this.context); + this.evaluateItem(this.lastOperation); + return this; + } + + /** + * Greater or equals than operator shortcut. + * + * @param entity the entity + * @param a the first operand + * @param b the second operand + * @return An instance of this class to allow chaining more validations + */ + public ChainValidator greaterOrEqualsThan(String entity, Object a, Object b) { + this.updateStatement(); + this.lastOperation = new GreaterOrEqualThan(entity, Double.valueOf(a.toString()), Double.valueOf(b.toString())); + ContextInjectionFactory.inject(this.lastOperation, this.context); + this.evaluateItem(this.lastOperation); + return this; + } + + /** + * Lower than operator shortcut. + * + * @param entity the entity + * @param a the first operand + * @param b the second operand + * @return An instance of this class to allow chaining more validations + */ + public ChainValidator lowerThan(String entity, Object a, Object b) { + this.updateStatement(); + this.lastOperation = new LowerThan(entity, Double.valueOf(a.toString()), Double.valueOf(b.toString())); + ContextInjectionFactory.inject(this.lastOperation, this.context); + this.evaluateItem(this.lastOperation); + return this; + } + + /** + * Lower or equals than operator shortcut. + * + * @param entity the entity + * @param a the first operand + * @param b the second operand + * @return An instance of this class to allow chaining more validations + */ + public ChainValidator lowerOrEqualsThan(String entity, Object a, Object b) { + this.updateStatement(); + this.lastOperation = new LowerOrEqualThan(entity, Double.valueOf(a.toString()), Double.valueOf(b.toString())); + ContextInjectionFactory.inject(this.lastOperation, this.context); + this.evaluateItem(this.lastOperation); + return this; + } + + /** + * Checks if is true operator shortcut. + * + * @param entity the entity + * @param a the only operand + * @return An instance of this class to allow chaining more validations + */ + public ChainValidator isTrue(String entity, Object a) { + this.updateStatement(); + this.lastOperation = new IsTrue(entity, Boolean.valueOf(a.toString())); + ContextInjectionFactory.inject(this.lastOperation, this.context); + this.evaluateItem(this.lastOperation); + return this; + } + + /** + * Not Equals operator shortcut. + * + * @param entity the entity + * @param a the first operand + * @param b the second operand + * @return An instance of this class to allow chaining more validations + */ + public ChainValidator notEquals(String entity, Object a, Object b) { + this.updateStatement(); + this.lastOperation = new NotEquals(entity, a, b); + ContextInjectionFactory.inject(this.lastOperation, this.context); + this.evaluateItem(this.lastOperation); + return this; + } + + /** + * Entry-point for adding custom operators. + * + * @param operation the operation + * @return the chain validator + */ + public ChainValidator custom(BaseOperation operation) { + this.updateStatement(); + this.lastOperation = operation; + ContextInjectionFactory.inject(this.lastOperation, this.context); + this.evaluateItem(this.lastOperation); + return this; + } + + /** + * Gets the statement. + * + * @return the statement + */ + public Statement getStatement() { + return this.statement; + } + + /** + * Gets the messages. + * + * @return the messages + */ + public ArrayList getChainMessages() { + return this.chainMessages; + } + + /** + * Sets the return value of the statement. + * + * @param text the text + * @return the chain validator + */ + public ChainValidator setReturn(String text) { + this.statement.setReturnValue(text); + return this; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/Statement.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/Statement.java new file mode 100644 index 0000000..ce1c916 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/Statement.java @@ -0,0 +1,132 @@ +package flintstones.helper.chainvalidator; + +import java.util.ArrayList; + +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 flintstones.helper.chainvalidator.messages.Messages; +import flintstones.helper.chainvalidator.operation.BaseOperation; + +/** + * The Class Statement. + */ +public class Statement { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The operations. */ + private final ArrayList operations = new ArrayList<>(); + + /** The return value. */ + private String returnValue = ""; //$NON-NLS-1$ + + /** The result. */ + private boolean result = true; + + /** + * Instantiates a new statement. + */ + public Statement() { + } + + /** + * Gets the operations. + * + * @return the operations + */ + public ArrayList getOperations() { + return this.operations; + } + + /** + * Sets the operations. + * + * @param ops the new operations + */ + public void setOperations(ArrayList ops) { + for (BaseOperation op : ops) + this.operations.add(op); + } + + /** + * Adds the. + * + * @param op the op + */ + public void add(BaseOperation op) { + this.operations.add(op); + } + + /** + * Gets the return value. + * + * @return the return value + */ + public String getReturnValue() { + return this.returnValue; + } + + /** + * Sets the return value. + * + * @param returnValue the new return value + */ + public void setReturnValue(String returnValue) { + this.returnValue = returnValue; + } + + /** + * Evaluate. + * + * @return true, if successful + */ + public boolean evaluate() { + return this.result; + } + + /** + * Sets the result. + * + * @param lastResult the new result + */ + public void setResult(boolean lastResult) { + this.result = lastResult; + } + + /** + * Copy. + * + * @return the statement + */ + public Statement copy() { + Statement clone = ContextInjectionFactory.make(Statement.class, this.context); + clone.setOperations(this.operations); + clone.setReturnValue(this.returnValue); + clone.setResult(this.result); + return clone; + } + + /** + * Update result. + * + * @param operator the operator + * @param lastResult the last result + */ + public void updateResult(String operator, boolean lastResult) { + if (operator.equals(this.messages.And)) + this.result = this.result && lastResult; + else if (operator.equals(this.messages.Or)) + this.result = this.result || lastResult; + } +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/Messages.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/Messages.java new file mode 100644 index 0000000..a8ac511 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/Messages.java @@ -0,0 +1,87 @@ +// This file has been auto-generated +package flintstones.helper.chainvalidator.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public static String Success; + public static String Error; + public static String Operator; + public String MessageTemplate; + public String And; + public String Or_hr; + public String Or; + public String and_label; + public String and_pseudo; + public String or_label; + public String or_pseudo; + public String BaseBinaryOperation_pseudo; + public String Equals_label; + public String Equals_failed; + public String Equals_passed; + public String Equals_operator; + public String Not_Equals_label; + public String Not_Equals_failed; + public String Not_Equals_passed; + public String Not_Equals_operator; + public String GreaterOrEqualThan_label; + public String GreaterOrEqualThan_failedTemplate; + public String GreaterOrEqualThan_passedTemplate; + public String GreaterOrEqualThan_Operator; + public String GreaterThan_label; + public String GreaterThan_failed; + public String GreaterThan_passed; + public String GreaterThan_operator; + public String IsTrue_label; + public String IsTrue_failed; + public String IsTrue_passed; + public String IsTrue_value; + public String IsTrue_operator; + public String LowerOrEqualThan_label; + public String LowerOrEqualThan_failed; + public String LowerOrEqualThan_passed; + public String LowerOrEqualThan_operator; + public String LowerThan_label; + public String LowerThan_failed; + public String LowerThan_passed; + public String LowerThan_operator; + public String BaseMethodOperation_pseudo; + public String ValidFuzzysetDomainsOperations_methodLabel; + public String ValidFuzzysetDomainsOperations_operationLabel; + public String ValidFuzzysetDomainsOperations_failed; + public String ValidFuzzysetDomainsOperations_passed; + public String ValidFuzzysetDomainsOperations_invalidDomain; + public String ValidFuzzysetDomainsOperations_description; + public String Generator_headerVariables; + public String Generator_headerAlgorith; + public String All_domains_are; + public String Domain; + public String Domain_not_type; + public String Domains; + public String Domains_same_type; + public String Domains_type_are; + public String Domain_is_valid_BLTS; + public String All_domains_must_be_BLTS; + public String Not_BLTS_domain; + public String All_domains_are_BLTS; + public String Cardinalities_are_matched; + public String Domains_BLTS_with_match_cardinalities; + public String Domain_cardinality_repeated; + public String Possible_to_create_LH; + public String Domains_must_follow_sequence; + public String Domain_not_satisfy_sequence; + public String Sequence_valid; + + + // ValuationType + public String ValuationType_Description; + public String ValuationType_Invalid_Valuation_type; + public String ValuationType_Invalid_Valuation_type_Not_Assigned; + public String ValuationType_All_Valuations_Valid; + + // RLibTest + public String RLibTest_Description; +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/messages.properties b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/messages.properties new file mode 100644 index 0000000..2c368bf --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/messages.properties @@ -0,0 +1,74 @@ +And=AND +entity=entity +Error=Error +MessageTemplate={1} +Operator=Operator +Or=OR +Or_hr=o bien +Success=Success +and_label=and +and_pseudo=AND +or_label=or +or_pseudo=OR +BaseBinaryOperation_pseudo={0} {1} {2} +Equals_failed={0} is {1}, should be {2} +Equals_label=equals +Equals_operator== +Equals_passed={0} is {1}, is correct +Not_Equals_failed={0} is {1}, should not be {1} +Not_Equals_label=different +Not_Equals_operator=!= +Not_Equals_passed={0} is not {2}, is correct +GreaterOrEqualThan_failedTemplate={0} is {1}, should be greater or equals than {2} +GreaterOrEqualThan_label=greater or equal than +GreaterOrEqualThan_Operator=>= +GreaterOrEqualThan_passedTemplate={0} is {1}, is correct (Greater or equal than {2}) +GreaterThan_failed={0} is {1}, should be greater than {2} +GreaterThan_label=greater than +GreaterThan_operator=> +GreaterThan_passed={0} is {1}, is correct (Greater than {2}) +IsTrue_failed={0} is false, should be true +IsTrue_label=is true +IsTrue_operator=== +IsTrue_passed={0} is true, is correct +IsTrue_value=true +LowerOrEqualThan_failed={0} is {1}, should be less or equal than {2} +LowerOrEqualThan_label=lower or equal than +LowerOrEqualThan_operator=<= +LowerOrEqualThan_passed={0} is {1}, is correct (Less or equal than {2}) +LowerThan_failed={0} is {1}, should be less than {2} +LowerThan_label=lower than +LowerThan_operator=< +LowerThan_passed={0} is {1}, is correct_ (Less than {2}) +BaseMethodOperation_pseudo={0}({1}) +Domain_not_satisfy_sequence=The domain {0} not satisfy the sequence (card {1}) +Domains_must_follow_sequence=The domains must follow the cardinality sequence [XXXX] +Possible_to_create_LH=It is possible to create a LH +Sequence_valid=The domains follow a valid cardinality sequence +All_domains_are_BLTS=All domains are BLTS +All_domains_must_be_BLTS=All domains must be BLTS \n description of BLTS \n Pseudo Code \n xxxx +Domain_is_valid_BLTS=Domain is valid BLTS +Not_BLTS_domain=The domain {0} is not BLTS +ValidFuzzysetDomainsOperations_description=Check if all the available domains are FuzzySet and their cardinality is 2n-1 +ValidFuzzysetDomainsOperations_failed=The domains {0} do not correspond to a valid sequence +ValidFuzzysetDomainsOperations_invalidDomain=The domain {0} is not FuzzySet +ValidFuzzysetDomainsOperations_methodLabel=ValidFuzzysetDomains +ValidFuzzysetDomainsOperations_operationLabel=Domains are valid FuzzySet domains +ValidFuzzysetDomainsOperations_passed=Domains correspond to a valid sequence +Generator_headerAlgorith=\# Algorithm to select the suitable CWW methodology \#\n +Generator_headerVariables=\# Required values \#\n +All_domains_are= The domains are {0} +Cardinalities_are_matched=Compatible cardinals +Domain_cardinality_repeated=Domain cardinality repeated: {0} ({1} card) +Domains_BLTS_with_match_cardinalities=Domains must be BLTS FuzzySet with compatible cardinals +Domain=domain +Domain_not_type=The type of the domain {0} is not {1}, but {2} +Domains=domains +Domains_same_type=All the domains must have the same type +Domains_type_are=The type of the domains are {0} + +ValuationType_Description =Check if the valuation types are compatible +ValuationType_Invalid_Valuation_type=The valuation {0} type is not valid. (Valid types are {1}) +ValuationType_Invalid_Valuation_type_Not_Assigned=The valuation {0} has not been assigned (Valid types are {1}) +ValuationType_All_Valuations_Valid=All the valuations are valid +RLibTest_Description=Check R library installation diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/messages_es.properties b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/messages_es.properties new file mode 100644 index 0000000..fdfb7f6 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/messages/messages_es.properties @@ -0,0 +1,75 @@ +And=AND +And=AND +entity=entity +Error=Error +MessageTemplate=[{0}] {1} +Operator=Operator +Or=OR +Or=OR +Or_hr=o bien +Success=Success +and_label=y +and_pseudo=Y +or_label=o +or_pseudo=O +BaseBinaryOperation_pseudo={0} {1} {2} +Equals_failed={0} es {1}, debera ser {2}. +Equals_label=equals +Equals_operator=\== +Equals_passed={0} es {1}, debera ser {2}. Es correcto. +Not_Equals_failed={0} es {1}, no debera ser {2} +Not_Equals_label=diferente +Not_Equals_operator=!= +Not_Equals_passed={0} no es {2}, is correct +GreaterOrEqualThan_failedTemplate={0} es {1}, debera ser mayor o igual que {2}. +GreaterOrEqualThan_label=greater or equal than +GreaterOrEqualThan_Operator=>= +GreaterOrEqualThan_passedTemplate={0} es {1}, es correcto. (Mayor o igual que {2}) +GreaterThan_failed={0} es {1}, debera ser mayor que {2}. +GreaterThan_label=greater than +GreaterThan_operator=> +GreaterThan_passed={0} es {1}, es correcto. (Mayor que {2}) +IsTrue_failed={0} es falso, debera ser verdadero. +IsTrue_label=is true +IsTrue_operator= == +IsTrue_passed={0} es verdadero, es correcto. +IsTrue_value=true +LowerOrEqualThan_failed={0} es {1}, deber�a ser menor o igual que {2}. +LowerOrEqualThan_label=lower or equal than +LowerOrEqualThan_operator=<= +LowerOrEqualThan_passed={0} es {1}, es correcto. (Menor o igual que {2}) +LowerThan_failed={0} es {1}, deber�a ser menor que {2}. +LowerThan_label=lower than +LowerThan_operator=< +LowerThan_passed={0} es {1}, es correcto. (Menor que {2}) +BaseMethodOperation_pseudo={0}({1}) +Domain_not_satisfy_sequence=El dominio {0} no cumple con la secuencia (card {1}) +Domains_must_follow_sequence=Los dominios deben seguir la secuencia [XXXX] +Possible_to_create_LH=Es posible crear una LH con los dominios +Sequence_valid=Los dominios forman una secuencia valida +All_domains_are_BLTS=Todos los dominios son BLTS +All_domains_must_be_BLTS=Todos los dominios deben ser BLTS \n Descripcin de las condiciones de un dominio BLTS \n Pseudo Cdigo \n xxxx +Domain_is_valid_BLTS=El dominio es BLTS +Not_BLTS_domain=El dominio {0} no es BLTS +ValidFuzzysetDomainsOperations_description=Comprueba si todos los dominios disponibles son FuzzySet y si la cardinalidad de los m�smos es 2n-1 +ValidFuzzysetDomainsOperations_failed=Los dominios {0} no se corresponden con una secuencia valida +ValidFuzzysetDomainsOperations_invalidDomain=El dominio {0} no es FuzzySet +ValidFuzzysetDomainsOperations_methodLabel=ValidFuzzysetDomains +ValidFuzzysetDomainsOperations_operationLabel=Son dominios FuzzySet vlidos +ValidFuzzysetDomainsOperations_passed=Los dominios se corresponden con una secuencia valida +Generator_headerAlgorith=\# Algoritmo para seleccionar la metodolog�a CWW adecuada \#\n +Generator_headerVariables=\# Valores requeridos \#\n +All_domains_are=Todos los dominios son {0} +Cardinalities_are_matched=Las cardinalidades son compatibles +Domain_cardinality_repeated=La cardinalidad del dominio est repetida: {0} ({1} card) +Domains_BLTS_with_match_cardinalities=Los dominios deben ser FuzzySet, BLTS y con cardinalidades compatibles +Domain=dominio +Domain_not_type=El dominio {0} no es del tipo {1}, es del tipo {2} +Domains=dominios +Domains_same_type=Los dominios deben ser del tipo +Domains_type_are=Los dominios son del tipo {0} +ValuationType_Description =Comprueba si las valoraciones son compatibles +ValuationType_Invalid_Valuation_type=El tipo de la valoracin {0} no es valido. (Los tipos validos son {1}) +ValuationType_Invalid_Valuation_type_Not_Assigned=La valoracin {0} no ha sido asignada. (Los tipos vlidos son {1}) +ValuationType_All_Valuations_Valid=Todas las valoraciones son correctas +RLibTest_Description=Comprueba si se encuentra instalada la librera de R diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/And.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/And.java new file mode 100644 index 0000000..33c0a9c --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/And.java @@ -0,0 +1,97 @@ +package flintstones.helper.chainvalidator.operation; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class And. + */ +public class And extends BaseOperation { + + @Inject + @Translation + private Messages messages; + + /** + * Instantiates a new and. + */ + public And() { + super(); + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel( + * ) */ + @Override + public String getOperationHumanName() { + return this.messages.and_label; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getFailedValidationTemplate() */ + @Override + public String getFailedValidationTemplate() { + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPassedValidationTemplate() */ + @Override + public String getPassedValidationTemplate() { + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getValidationMessage() */ + @Override + public String getValidationMessage() { + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */ + @Override + public String getPseudoCode() { + return this.getPseudoCodeTemplate(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPseudoCodeTemplate() */ + @Override + protected String getPseudoCodeTemplate() { + return this.messages.and_pseudo; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */ + @Override + public boolean evaluate() { + return true; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getDescription() */ + @Override + public String getDescription() { + return ""; //$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/BaseOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/BaseOperation.java new file mode 100644 index 0000000..e0e0e45 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/BaseOperation.java @@ -0,0 +1,183 @@ +package flintstones.helper.chainvalidator.operation; + +import java.util.ArrayList; +import java.util.HashMap; + +import flintstones.helper.chainvalidator.operation.method.BaseMethodOperation; + +/** + * The Class BaseOperation. + */ +public abstract class BaseOperation { + + private String entity = ""; //$NON-NLS-1$ + + private Object[] args; + + private final ArrayList variableNames = new ArrayList<>(); + + protected BaseOperation() { + } + + /** + * + * @param entity the entity + * @param args the args + */ + protected BaseOperation(String entity, Object... args) { + this.entity = entity; + this.args = args; + } + + /** + * Gets the entity name. + * + * @return the entity + */ + protected String getEntity() { + return this.entity; + } + + protected void setEntity(String entity) { + this.entity = entity; + } + + protected void setArgs(Object... args) { + this.args = args; + } + + /** + * Adds the name. + * + * @param index the index + * @param value the value + */ + public void addVariableName(String value) { + this.variableNames.add(value); + } + + /** + * Gets the variable name. + * + * @param index the index + * @return the variable name + */ + protected String getVariableName(int index) { + return (this.variableNames.size() > index) ? this.variableNames.get(index) : "[Nombre de variable no definido para " + this.entity + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * Gets the variable names. + * + * @return the variable names + */ + public ArrayList getVariableNames() { + return this.variableNames; + }; + + /** + * Gets the variables. + * + * @return the variables + */ + public HashMap getVariables() { + + HashMap namesKV = new HashMap<>(); + + // ars[0] should be an Object[] but ars[] == Object[] + if( args != null && args.length > getVariableNames().size() && getVariableNames().size() == 1 && this instanceof BaseMethodOperation ) { + Object[] items = args; + args = new Object[1]; + args[0] = items; + } + + for (int index = 0; index < this.getVariableNames().size(); index++) { + String key = this.variableNames.get(index); + String value = ( args.length > index ) ? this.getVariableValue(this.args[index]) : ""; + + namesKV.put(key, value); + } + + return namesKV; + } + + /** + * Gets the readable name of the operationsss. + * + * @return the name + */ + protected abstract String getOperationHumanName(); + + /** + * Gets the pseudo code. + * + * @return the pseudo code + */ + public abstract String getPseudoCode(); + + /** + * Gets the readable message. + * + * @return the message + */ + public abstract String getValidationMessage(); + + /** + * Gets the human readable description. + * + * @return the description of the operation + */ + public abstract String getDescription(); + + /** + * Gets the template for the wrong message. + * + * @return the wrong template + */ + protected abstract String getFailedValidationTemplate(); + + /** + * Gets the template for the message when validation pass. + * + * @return the right template + */ + protected abstract String getPassedValidationTemplate(); + + /** + * Gets the pseudo code template. + * + * @return the pseudo code template + */ + protected abstract String getPseudoCodeTemplate(); + + /** + * Evaluate. + * + * @return true, if successful + */ + public abstract boolean evaluate(); + + /** + * Return how the variable will be displayed. Can be overrided. + * @param var variable + * @return + */ + protected String getVariableValue(Object var) { + + if(var == null) + return "NULL"; + else if( var.getClass().isArray() ) { + + Object[] items = (Object[]) var; + + ArrayList texts = new ArrayList<>(); + for( Object item : items ) { + texts.add(item.toString()); + } + return String.join(", ", texts); + } else { + return var.toString(); + } + } + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/Or.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/Or.java new file mode 100644 index 0000000..cfdfc0e --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/Or.java @@ -0,0 +1,90 @@ +package flintstones.helper.chainvalidator.operation; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class Or. + */ +public class Or extends BaseOperation { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** + * Instantiates a new or. + */ + public Or() { + super(); + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getOperationHumanName() + */ + @Override + public String getOperationHumanName() { + return this.messages.or_label; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getFailedValidationTemplate() + */ + @Override + public String getFailedValidationTemplate() { + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPassedValidationTemplate() + */ + @Override + public String getPassedValidationTemplate() { + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getValidationMessage() + */ + @Override + public String getValidationMessage() { + return ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() + */ + @Override + public String getPseudoCode() { + return this.getPseudoCodeTemplate(); + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCodeTemplate() + */ + @Override + protected String getPseudoCodeTemplate() { + return this.messages.or_pseudo; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() + */ + @Override + public boolean evaluate() { + return true; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getDescription() + */ + @Override + public String getDescription() { + return null; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/BaseBinaryOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/BaseBinaryOperation.java new file mode 100644 index 0000000..1d7f77b --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/BaseBinaryOperation.java @@ -0,0 +1,91 @@ +package flintstones.helper.chainvalidator.operation.binary; + +import java.text.MessageFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; +import flintstones.helper.chainvalidator.operation.BaseOperation; + +/** + * The Class BaseBinaryOperation. + */ +public abstract class BaseBinaryOperation extends BaseOperation { + + @Inject + @Translation + private Messages messages; + + private Object paramA; + private Object paramB; + + /** + * Instantiates a new base binary operation. + * + * @param entity the entity + * @param args the args + */ + public BaseBinaryOperation(String entity, Object... args) { + super(entity, args); + + this.paramA = args[0]; + this.paramB = args[1]; + + } + + /** + * Gets the key. + * + * @return the key + */ + public abstract String getKey(); + + /** + * Gets the value. + * + * @return the value + */ + public abstract String getValue(); + + /** + * Gets the operator. + * + * @return the operator + */ + public abstract String getOperator(); + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPseudoCodeTemplate() */ + @Override + public String getPseudoCodeTemplate() { + return this.messages.BaseBinaryOperation_pseudo; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getValidationMessage() */ + @Override + public String getValidationMessage() { + if (this.evaluate()) { + return MessageFormat.format(this.getPassedValidationTemplate(), this.getEntity(), paramA, paramB) + .toString(); + } + return MessageFormat.format(this.getFailedValidationTemplate(), this.getEntity(), paramA, paramB) + .toString(); + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getDescription() */ + @Override + public String getDescription() { + return null; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/Equals.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/Equals.java new file mode 100644 index 0000000..ad21cbd --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/Equals.java @@ -0,0 +1,116 @@ +package flintstones.helper.chainvalidator.operation.binary; + +import java.text.MessageFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class Equals. + */ +public class Equals extends BaseBinaryOperation { + + @Inject + @Translation + private Messages messages; + + /** The first operand. */ + private final Object a; + + /** The second operand. */ + private final Object b; + + /** + * Instantiates a new equals. + * + * @param entity the entity + * @param args the args + */ + public Equals(String entity, Object... args) { + + super(entity, args); + + this.a = args[0]; + this.b = args[1]; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel( + * ) */ + @Override + public String getOperationHumanName() { + return this.messages.Equals_label; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getFailedValidationTemplate() */ + @Override + public String getFailedValidationTemplate() { + return this.messages.Equals_failed; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPassedValidationTemplate() */ + @Override + public String getPassedValidationTemplate() { + return this.messages.Equals_passed; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), this.a, this.b) + .toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */ + @Override + public boolean evaluate() { + if (this.a.equals(this.b)) + return true; + return false; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey + * () */ + @Override + public String getKey() { + return this.getVariableName(0); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getValue() */ + @Override + public String getValue() { + return this.b.toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getOperator() */ + @Override + public String getOperator() { + return this.messages.Equals_operator; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/GreaterOrEqualThan.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/GreaterOrEqualThan.java new file mode 100644 index 0000000..462e070 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/GreaterOrEqualThan.java @@ -0,0 +1,127 @@ +package flintstones.helper.chainvalidator.operation.binary; + +import java.text.DecimalFormat; +import java.text.MessageFormat; +import java.text.NumberFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class GreaterOrEqualThan. + */ +public class GreaterOrEqualThan extends BaseBinaryOperation { + + /** The first operand. */ + private final Double a; + + /** The second operand. */ + private final Double b; + + private final String aS; + + private final String bS; + + @Inject + @Translation + private Messages messages; + + /** + * Instantiates a new greater or equal than. + * + * @param entity the entity + * @param args the args + */ + public GreaterOrEqualThan(String entity, Double... args) { + + super(entity, (Object[]) args); + + this.a = args[0]; + this.b = args[1]; + + NumberFormat nf = new DecimalFormat("##.##"); + + this.aS = nf.format(a); + this.bS = nf.format(b); + + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel( + * ) */ + @Override + protected String getOperationHumanName() { + return this.messages.GreaterOrEqualThan_label; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getFailedValidationTemplate() */ + @Override + protected String getFailedValidationTemplate() { + return this.messages.GreaterOrEqualThan_failedTemplate; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPassedValidationTemplate() */ + @Override + protected String getPassedValidationTemplate() { + return this.messages.GreaterOrEqualThan_passedTemplate; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), this.aS, this.bS) + .toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */ + @Override + public boolean evaluate() { + if (this.a.compareTo(this.b) >= 0) + return true; + return false; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey + * () */ + @Override + public String getKey() { + return this.getVariableName(0); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getValue() */ + @Override + public String getValue() { + return this.bS; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getOperator() */ + @Override + public String getOperator() { + return this.messages.GreaterOrEqualThan_Operator; + } +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/GreaterThan.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/GreaterThan.java new file mode 100644 index 0000000..8a5757b --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/GreaterThan.java @@ -0,0 +1,127 @@ +package flintstones.helper.chainvalidator.operation.binary; + +import java.text.DecimalFormat; +import java.text.MessageFormat; +import java.text.NumberFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class GreaterThan. + */ +public class GreaterThan extends BaseBinaryOperation { + + @Inject + @Translation + private Messages messages; + + /** The a. */ + private final Double a; + + /** The b. */ + private final Double b; + + private final String aS; + + private final String bS; + + /** + * Instantiates a new greater than operation. + * + * @param entity the entity + * @param args the args + */ + public GreaterThan(String entity, Double... args) { + + super(entity, (Object[]) args); + + this.a = args[0]; + this.b = args[1]; + + NumberFormat nf = new DecimalFormat("##.##"); + + this.aS = nf.format(a); + this.bS = nf.format(b); + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel( + * ) */ + @Override + public String getOperationHumanName() { + return this.messages.GreaterThan_label; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getFailedValidationTemplate() */ + @Override + public String getFailedValidationTemplate() { + return this.messages.GreaterThan_failed; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPassedValidationTemplate() */ + @Override + public String getPassedValidationTemplate() { + return this.messages.GreaterThan_passed; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), this.aS, this.bS) + .toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */ + @Override + public boolean evaluate() { + if (this.a.compareTo(this.b) > 0) + return true; + return false; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey + * () */ + @Override + public String getKey() { + return this.getVariableName(0); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getValue() */ + @Override + public String getValue() { + return this.bS; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getOperator() */ + @Override + public String getOperator() { + return this.messages.GreaterThan_operator; + } + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/IsTrue.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/IsTrue.java new file mode 100644 index 0000000..4233b17 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/IsTrue.java @@ -0,0 +1,112 @@ +package flintstones.helper.chainvalidator.operation.binary; + +import java.text.MessageFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class IsTrue. + */ +public class IsTrue extends BaseBinaryOperation { + + @Inject + @Translation + private Messages messages; + + /** The value. */ + private final Boolean a; + + /** + * Instantiates a new checks if is true. + * + * @param entity the entity + * @param args the args + */ + public IsTrue(String entity, Boolean... args) { + + super(entity, args, true); + + this.a = args[0]; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel( + * ) */ + @Override + public String getOperationHumanName() { + return this.messages.IsTrue_label; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getFailedValidationTemplate() */ + @Override + public String getFailedValidationTemplate() { + return this.messages.IsTrue_failed; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPassedValidationTemplate() */ + @Override + public String getPassedValidationTemplate() { + return this.messages.IsTrue_passed; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), this.a) + .toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */ + @Override + public boolean evaluate() { + if (this.a) + return true; + return false; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey + * () */ + @Override + public String getKey() { + return this.getVariableName(0); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getValue() */ + @Override + public String getValue() { + return this.messages.IsTrue_value; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getOperator() */ + @Override + public String getOperator() { + return this.messages.IsTrue_operator; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/LowerOrEqualThan.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/LowerOrEqualThan.java new file mode 100644 index 0000000..c5283d7 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/LowerOrEqualThan.java @@ -0,0 +1,129 @@ +package flintstones.helper.chainvalidator.operation.binary; + +import java.text.DecimalFormat; +import java.text.MessageFormat; +import java.text.NumberFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class LowerOrEqualThan Operation. + */ +public class LowerOrEqualThan extends BaseBinaryOperation { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** The a. */ + private final Double a; + + /** The b. */ + private final Double b; + + private final String aS; + + private final String bS; + + /** + * Instantiates a new lower or equal than operation. + * + * @param entity the entity + * @param args the args + */ + public LowerOrEqualThan(String entity, Double... args) { + + super(entity, (Object[]) args); + + this.a = args[0]; + this.b = args[1]; + + NumberFormat nf = new DecimalFormat("##.##"); + + this.aS = nf.format(a); + this.bS = nf.format(b); + + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel( + * ) */ + @Override + protected String getOperationHumanName() { + return this.messages.LowerOrEqualThan_label; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getFailedValidationTemplate() */ + @Override + protected String getFailedValidationTemplate() { + return this.messages.LowerOrEqualThan_failed; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPassedValidationTemplate() */ + @Override + protected String getPassedValidationTemplate() { + return this.messages.LowerOrEqualThan_passed; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), this.aS, this.bS) + .toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */ + @Override + public boolean evaluate() { + if (this.a.compareTo(this.b) < 0) + return true; + return false; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey + * () */ + @Override + public String getKey() { + return this.getVariableName(0); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getValue() */ + @Override + public String getValue() { + return this.bS; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getOperator() */ + @Override + public String getOperator() { + return this.messages.LowerOrEqualThan_operator; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/LowerThan.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/LowerThan.java new file mode 100644 index 0000000..e45044d --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/LowerThan.java @@ -0,0 +1,129 @@ +package flintstones.helper.chainvalidator.operation.binary; + +import java.text.DecimalFormat; +import java.text.MessageFormat; +import java.text.NumberFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class LowerThan. + */ +public class LowerThan extends BaseBinaryOperation { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** The a. */ + private final Double a; + + /** The b. */ + private final Double b; + + private final String aS; + + private final String bS; + + /** + * Instantiates a new lower than operation. + * + * @param entity the entity + * @param args the args + */ + public LowerThan(String entity, Double... args) { + + super(entity, (Object[]) args); + + this.a = args[0]; + this.b = args[1]; + + NumberFormat nf = new DecimalFormat("##.##"); + + this.aS = nf.format(a); + this.bS = nf.format(b); + + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel( + * ) */ + @Override + protected String getOperationHumanName() { + return this.messages.LowerThan_label; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getFailedValidationTemplate() */ + @Override + protected String getFailedValidationTemplate() { + return this.messages.LowerThan_failed; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPassedValidationTemplate() */ + @Override + protected String getPassedValidationTemplate() { + return this.messages.LowerThan_passed; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), this.aS, this.bS) + .toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */ + @Override + public boolean evaluate() { + if (this.a.compareTo(this.b) <= 0) + return true; + return false; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey + * () */ + @Override + public String getKey() { + return this.getVariableName(0); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getValue() */ + @Override + public String getValue() { + return this.bS; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getOperator() */ + @Override + public String getOperator() { + return this.messages.LowerThan_operator; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/NotEquals.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/NotEquals.java new file mode 100644 index 0000000..57e4851 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/binary/NotEquals.java @@ -0,0 +1,116 @@ +package flintstones.helper.chainvalidator.operation.binary; + +import java.text.MessageFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class Equals. + */ +public class NotEquals extends BaseBinaryOperation { + + @Inject + @Translation + private Messages messages; + + /** The first operand. */ + private final Object a; + + /** The second operand. */ + private final Object b; + + /** + * Instantiates a new equals. + * + * @param entity the entity + * @param args the args + */ + public NotEquals(String entity, Object... args) { + + super(entity, args); + + this.a = args[0]; + this.b = args[1]; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel( + * ) */ + @Override + public String getOperationHumanName() { + return this.messages.Not_Equals_label; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getFailedValidationTemplate() */ + @Override + public String getFailedValidationTemplate() { + return this.messages.Not_Equals_failed; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPassedValidationTemplate() */ + @Override + public String getPassedValidationTemplate() { + return this.messages.Not_Equals_passed; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), this.a, this.b) + .toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */ + @Override + public boolean evaluate() { + if (!this.a.equals(this.b)) + return true; + return false; + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey + * () */ + @Override + public String getKey() { + return this.getVariableName(0); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getValue() */ + @Override + public String getValue() { + return this.b.toString(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation# + * getOperator() */ + @Override + public String getOperator() { + return this.messages.Not_Equals_operator; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/BaseMethodOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/BaseMethodOperation.java new file mode 100644 index 0000000..704de5a --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/BaseMethodOperation.java @@ -0,0 +1,69 @@ +package flintstones.helper.chainvalidator.operation.method; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.chainvalidator.messages.Messages; +import flintstones.helper.chainvalidator.operation.BaseOperation; + +/** + * The Class BaseMethodOperation. + */ +public abstract class BaseMethodOperation extends BaseOperation { + + @Inject + @Translation + private Messages messages; + + /** The args. */ + private final Object[] args; + + /** + * Instantiates a new base method operation. + * + * @param entity the entity + * @param args the args + */ + public BaseMethodOperation(String entity, Object... args) { + super(entity, args); + this.args = args; + } + + /** + * Gets the method name. + * + * @return the method name + */ + public abstract String getOperationName(); + + /** + * Gets the args. + * + * @return the args + */ + public Object[] getArgs() { + return this.args; + } + + /** + * Gets the args textual. + * + * @return the args textual + */ + public String[] getArgsTextual() { + return this.getVariableNames() + .toArray(new String[this.getVariableNames() + .size()]); + }; + + /* (non-Javadoc) + * + * @see flintstones.helper.chainvalidator.operation.BaseOperation# + * getPseudoCodeTemplate() */ + @Override + public String getPseudoCodeTemplate() { + return this.messages.BaseMethodOperation_pseudo; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/BuildableLinguisticHierarchyOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/BuildableLinguisticHierarchyOperation.java new file mode 100644 index 0000000..80bd3e2 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/BuildableLinguisticHierarchyOperation.java @@ -0,0 +1,191 @@ + +package flintstones.helper.chainvalidator.operation.method; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class BuildableLinguisticHerarchyOperation. + */ +public class BuildableLinguisticHierarchyOperation extends BaseMethodOperation { + + + /** The params. */ + private final String params; + + /** The domains. */ + private final Domain[] domains; + + @Inject + @Translation + Messages messages; + + /** + * Instantiates a new buildable linguistic herarchy operation check. + * + * @param entity the entity + * @param args the args + */ + public BuildableLinguisticHierarchyOperation(String entity, Object[] args) { + super(entity, args); + + if( args.length == 1 ) { + domains = new Domain[1]; + domains[0] = (Domain)args[0]; + } else if( args.length > 1 ) { + ArrayList domainsL = new ArrayList<>(); + for(Object arg : args) { + domainsL.add((Domain)arg); + } + domains = domainsL.toArray(new Domain[domainsL.size()]); + } else { + domains = new Domain[0]; + } + + params = (domains.length > 1 ? "domains" : "domain"); //$NON-NLS-1$ //$NON-NLS-2$ + + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.method.BaseMethodOperation#getOperationName() + */ + @Override + public String getOperationName() { + return "BuildableLinguisticHerarchy"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getOperationHumanName() + */ + @Override + protected String getOperationHumanName() { + return messages.Possible_to_create_LH; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() + */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), params); + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getValidationMessage() + */ + @Override + public String getValidationMessage() { + if( evaluate() ) + return messages.Possible_to_create_LH; + + + Domain firstInvalidDomain = findFirstInvalid(); + if(firstInvalidDomain != null) + return MessageFormat.format(getFailedValidationTemplate(), firstInvalidDomain.getName(), ((FuzzySet)firstInvalidDomain).getLabelSet().getCardinality()); + return getDescription(); + + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getDescription() + */ + @Override + public String getDescription() { + return messages.Domains_must_follow_sequence; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getFailedValidationTemplate() + */ + @Override + protected String getFailedValidationTemplate() { + return messages.Domain_not_satisfy_sequence; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPassedValidationTemplate() + */ + @Override + protected String getPassedValidationTemplate() { + return messages.Sequence_valid; + } + + /** + * Find first invalid. + * + * @return the domain + */ + private Domain findFirstInvalid() { + + ArrayList cardinalities = new ArrayList<>(); + + for(Domain d : domains) { + if( !(d instanceof FuzzySet)) + return null; + + FuzzySet fuzzyDomain = (FuzzySet) d; + if(!fuzzyDomain.isBLTS()) + return null; + + cardinalities.add(((FuzzySet) d).getLabelSet().getCardinality()); + } + + Collections.sort(cardinalities); + + Domain[] orderedByCardinalityDomains = Arrays.stream(domains) + .map(k -> (FuzzySet)k) + .sorted( (d1,d2) -> d1.getLabelSet().getCardinality() > d2.getLabelSet().getCardinality() ? 1 : 0 ) + .toArray(Domain[]::new); + + for(int c = 0; c < cardinalities.size() - 1; c++) { + + int cardinality = cardinalities.get(c); + int nextCardinality = cardinalities.get(c + 1); + + // card(Actual) * 2 - 1 == card(Siguiente) + if( (cardinality * 2) - 1 != nextCardinality ) { + return orderedByCardinalityDomains[c]; + } + } + + return null; + + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() + */ + @Override + public boolean evaluate() { + + if( domains.length == 0 ) + return false; + + for(Domain d : domains) { + if( !(d instanceof FuzzySet)) + return false; + + FuzzySet fuzzyDomain = (FuzzySet) d; + if(!fuzzyDomain.isBLTS()) + return false; + } + + Domain invalidDomain = findFirstInvalid(); + if(invalidDomain != null) + return false; + + return true; + } + + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/CompatibleCardinalitiesOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/CompatibleCardinalitiesOperation.java new file mode 100644 index 0000000..2629047 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/CompatibleCardinalitiesOperation.java @@ -0,0 +1,133 @@ + +package flintstones.helper.chainvalidator.operation.method; + +import java.text.MessageFormat; +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.helper.chainvalidator.messages.Messages; + +public class CompatibleCardinalitiesOperation extends BaseMethodOperation { + + private final String params; + private final Domain[] domains; + + @Inject + @Translation + Messages messages; + + public CompatibleCardinalitiesOperation(String entity, Object[] args) { + super(entity, args); + + if( args.length == 1 ) { + domains = new Domain[1]; + domains[0] = (Domain)args[0]; + } else if( args.length > 1 ) { + ArrayList domainsL = new ArrayList<>(); + for(Object arg : args) { + domainsL.add((Domain)arg); + } + domains = domainsL.toArray(new Domain[domainsL.size()]); + } else { + domains = new Domain[0]; + } + + params = (domains.length > 1 ? "domains" : "domain"); //$NON-NLS-1$ //$NON-NLS-2$ + + } + + @Override + public String getOperationName() { + return "CompatibleCardinalities"; //$NON-NLS-1$ + } + + @Override + protected String getOperationHumanName() { + return messages.Cardinalities_are_matched; + } + + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), params); + } + + @Override + public String getValidationMessage() { + if( evaluate() ) { + return messages.Cardinalities_are_matched; + } + + Domain firstInvalidDomain = findFirstInvalid(); + if(firstInvalidDomain != null) + return MessageFormat.format(getFailedValidationTemplate(), firstInvalidDomain.getName(), ((FuzzySet)firstInvalidDomain).getLabelSet().getCardinality()); + return getDescription(); + + } + + @Override + public String getDescription() { + return messages.Domains_BLTS_with_match_cardinalities; + } + + @Override + protected String getFailedValidationTemplate() { + return messages.Domain_cardinality_repeated; + } + + @Override + protected String getPassedValidationTemplate() { + return messages.Cardinalities_are_matched; + } + + private Domain findFirstInvalid() { + + ArrayList cardinalities = new ArrayList<>(); + for(Domain d : domains) { + + if( !(d instanceof FuzzySet)) + return null; + + FuzzySet fuzzyDomain = (FuzzySet) d; + if(!fuzzyDomain.isBLTS()) + return null; + + int cardinality = fuzzyDomain.getLabelSet().getCardinality(); + if( cardinalities.contains(cardinality) ) + return d; + cardinalities.add(cardinality); + + } + + return null; + + } + + @Override + public boolean evaluate() { + + if( domains.length == 0 ) + return false; + + for(Domain d : domains) { + if( !(d instanceof FuzzySet)) + return false; + + FuzzySet fuzzyDomain = (FuzzySet) d; + if(!fuzzyDomain.isBLTS()) + return false; + } + + Domain invalidDomain = findFirstInvalid(); + if(invalidDomain != null) + return false; + + return true; + } + + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/DomainTypeOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/DomainTypeOperation.java new file mode 100644 index 0000000..07ea5b4 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/DomainTypeOperation.java @@ -0,0 +1,166 @@ +package flintstones.helper.chainvalidator.operation.method; + +import java.text.MessageFormat; +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.domain.Domain; +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class DomainTypeOperation checks the type of a given domain. + */ +public class DomainTypeOperation extends BaseMethodOperation { + + /** The domain type. */ + final String domainType; + + /** The domains. */ + final Domain[] domains; + + /** The params. */ + final String params; + + @Inject + @Translation + private Messages messages; + + /** + * Instantiates a new domain type operation. + * + * @param entity the entity + * @param type the type + * @param args the args + */ + public DomainTypeOperation(String entity, String type, Domain[] args) { + super(entity, type, args); + + domainType = type; + + ArrayList domainsL = new ArrayList<>(); + for (Object arg : args) + domainsL.add((Domain) arg); + + domains = domainsL.toArray(new Domain[domainsL.size()]); + + params = domainType + ", " + (domains.length > 1 ? "domains" : "domain"); + + } + + /** + * Instantiates a new domain type operation. + * + * @param entity the entity + * @param type the type + * @param args the args + */ + public DomainTypeOperation(String entity, String type, Domain args) { + super(entity, type, args); + + domainType = type; + + domains = new Domain[1]; + domains[0] = args; + + params = domainType + ", " + (domains.length > 1 ? "domains" : "domain"); + + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.method.BaseMethodOperation#getOperationName() + */ + @Override + public String getOperationName() { + return "DomainType"; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getOperationHumanName() + */ + @Override + protected String getOperationHumanName() { + return messages.Domains_type_are; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() + */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), params); + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getValidationMessage() + */ + @Override + public String getValidationMessage() { + if (evaluate()) + return MessageFormat.format(getPassedValidationTemplate(), domainType); + + Domain firstInvalidDomain = findFirstInvalid(); + if (firstInvalidDomain != null) + return MessageFormat.format(getFailedValidationTemplate(), firstInvalidDomain.getName(), domainType, firstInvalidDomain.getClass() + .getSimpleName()); + return getDescription(); + + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getDescription() + */ + @Override + public String getDescription() { + return messages.Domains_same_type; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getFailedValidationTemplate() + */ + @Override + protected String getFailedValidationTemplate() { + return messages.Domain_not_type; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPassedValidationTemplate() + */ + @Override + protected String getPassedValidationTemplate() { + return messages.All_domains_are; + } + + /** + * Find first invalid. + * + * @return the domain + */ + private Domain findFirstInvalid() { + for (Domain d : domains) { + if (!d.getClass().getSimpleName().equals(domainType) + && !d.getClass().getSuperclass().getSimpleName().equals(domainType)) + return d; + } + return null; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() + */ + @Override + public boolean evaluate() { + + if (domains.length == 0) + return false; + + Domain firstInvalidDomain = findFirstInvalid(); + if (firstInvalidDomain != null) + return false; + + return true; + } + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/RLibTestOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/RLibTestOperation.java new file mode 100644 index 0000000..88c0607 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/RLibTestOperation.java @@ -0,0 +1,125 @@ +package flintstones.helper.chainvalidator.operation.method; + +import java.text.MessageFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.rosuda.JRI.Rengine; +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * Method operation to test installed R libraries + * @author jcfer + * + */ +public class RLibTestOperation extends BaseMethodOperation{ + + @Inject + @Translation + Messages messages; + + /** + * Libraries names + */ + private String[] libs; + + /** + * Instantiates object + * @param entity Entity name + * @param reqLib Required libraries names to test + */ + public RLibTestOperation(String entity, String... reqLibs) { + super(entity, (Object[]) reqLibs); + + libs = reqLibs; + } + + /** + * @return operation name + */ + @Override + public String getOperationName() { + return "RLibTest"; + } + + /** + * @return Operation description + */ + @Override + protected String getOperationHumanName() { + return messages.RLibTest_Description; + } + + /** + * @return PseudoCode + */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), "RLibTest, " + libs); + } + + /** + * @return Validation results + */ + @Override + public String getValidationMessage() { + if(evaluate()) { + return MessageFormat.format(this.getPassedValidationTemplate(), "Rtesting", "passedTest"); + } + return MessageFormat.format(this.getFailedValidationTemplate(), "Rtesting", "failedTest"); + } + + /** + * @return Operation description + */ + @Override + public String getDescription() { + return messages.RLibTest_Description; + } + + /** + * @return Message template for failed evaluation + */ + @Override + protected String getFailedValidationTemplate() { + return messages.BaseMethodOperation_pseudo; + } + + /** + * @return Message template for passed evaluation + */ + @Override + protected String getPassedValidationTemplate() { + return messages.BaseMethodOperation_pseudo; + } + + /** + * Evaluates operation + */ + @Override + public boolean evaluate() { + // Set this property to true, so we can catch the exception + System.setProperty("jri.ignore.ule", "yes"); + try { + // Check if the JRI has been loaded and its version too + if (Rengine.jriLoaded && Rengine.versionCheck()) { + Rengine reng = Rengine.getMainEngine(); + // In case there's no engine, create a new one + if(reng == null) + reng = new Rengine(new String[] { "--no-save" }, false, null); + // Test all the R libraries. In case any fails, mark R as not functional. + for (String l : libs) { + if(reng.eval("library(" + l + ")") == null) { + return false; + } + } + } + else return false; + }catch(UnsatisfiedLinkError e) { + // R is not properly installed on the system, as Rengine couldn't load it. + return false; + } + return true; + } +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValidBLTSDomainOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValidBLTSDomainOperation.java new file mode 100644 index 0000000..9b4c078 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValidBLTSDomainOperation.java @@ -0,0 +1,166 @@ +package flintstones.helper.chainvalidator.operation.method; + +import java.text.MessageFormat; +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.helper.chainvalidator.messages.Messages; + +/** + * The Class ValidBLTSDomainOperation. + */ +public class ValidBLTSDomainOperation extends BaseMethodOperation { + + /** The domains. */ + final Domain[] domains; + + /** The params. */ + final String params; + + @Inject + @Translation + private Messages messages; + + /** + * Instantiates a new valid BLTS domain operation check. + * + * @param entity the entity + * @param d the d + */ + public ValidBLTSDomainOperation(String entity, Domain d) { + + super(entity, d); + + domains = new Domain[1]; + domains[0] = d; + + params = "domain"; //$NON-NLS-1$ + + } + + /** + * Instantiates a new valid BLTS domain operation check. + * + * @param entity the entity + * @param domains the domains + */ + public ValidBLTSDomainOperation(String entity, Domain[] domains) { + + super(entity, (Object[])domains); + + ArrayList domainsL = new ArrayList<>(); + for(Domain arg : domains) { + domainsL.add(arg); + } + this.domains = domainsL.toArray(new Domain[domainsL.size()]); + + params = "domains"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.method.BaseMethodOperation#getOperationName() + */ + @Override + public String getOperationName() { + return "ValidBLTSDomain"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getOperationHumanName() + */ + @Override + protected String getOperationHumanName() { + return messages.Domain_is_valid_BLTS; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() + */ + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), params); + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getValidationMessage() + */ + @Override + public String getValidationMessage() { + if( evaluate() ) { + return messages.All_domains_are_BLTS; + } + Domain firstInvalidDomain = findFirstInvalid(); + if(firstInvalidDomain != null) + return MessageFormat.format(getFailedValidationTemplate(), firstInvalidDomain.getName()); + return getDescription(); + + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getDescription() + */ + @Override + public String getDescription() { + return messages.All_domains_must_be_BLTS; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getFailedValidationTemplate() + */ + @Override + protected String getFailedValidationTemplate() { + return messages.Not_BLTS_domain; + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#getPassedValidationTemplate() + */ + @Override + protected String getPassedValidationTemplate() { + return messages.All_domains_are_BLTS; + } + + /** + * Find first invalid. + * + * @return the domain + */ + private Domain findFirstInvalid() { + + for(Domain d : domains) { + + if( !(d instanceof FuzzySet)) + return d; + + FuzzySet fuzzyDomain = (FuzzySet) d; + if(!fuzzyDomain.isBLTS()) + return d; + + } + + return null; + + } + + /* (non-Javadoc) + * @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() + */ + @Override + public boolean evaluate() { + + if( domains.length == 0 ) + return false; + + Domain invalidDomain = findFirstInvalid(); + if(invalidDomain != null) + return false; + + return true; + } + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValidFuzzysetDomainsOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValidFuzzysetDomainsOperation.java new file mode 100644 index 0000000..e1e3a62 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValidFuzzysetDomainsOperation.java @@ -0,0 +1,119 @@ + +package flintstones.helper.chainvalidator.operation.method; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.stream.Collectors; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.helper.chainvalidator.messages.Messages; + +@SuppressWarnings("javadoc") +public class ValidFuzzysetDomainsOperation extends BaseMethodOperation { + + @Inject + @Translation + private Messages messages; + + private final Domain[] domains; + private final String domainsText; + + public ValidFuzzysetDomainsOperation(String entity, Domain[] args) { + super(entity, args, true); + this.domains = Arrays.copyOf(args, args.length, Domain[].class); + this.domainsText = Arrays.stream(this.domains) + .map(k -> k.getName()) + .collect(Collectors.joining(",")) //$NON-NLS-1$ + .toString(); + + } + + @Override + public String getOperationName() { + return this.messages.ValidFuzzysetDomainsOperations_methodLabel; + } + + @Override + protected String getOperationHumanName() { + return this.messages.ValidFuzzysetDomainsOperations_operationLabel; + } + + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), this.getOperationName(), this.domainsText); + } + + @Override + protected String getFailedValidationTemplate() { + return this.messages.ValidFuzzysetDomainsOperations_failed; + } + + @Override + protected String getPassedValidationTemplate() { + return this.messages.ValidFuzzysetDomainsOperations_passed; + } + + private String invalidDomainTypeTemplate() { + return this.messages.ValidFuzzysetDomainsOperations_invalidDomain; + } + + @Override + public boolean evaluate() { + return this.getFirstErrorOrNull() == null; + } + + private String getFirstErrorOrNull() { + for (Domain domain : this.domains) + if (!(domain instanceof FuzzySet)) + return MessageFormat.format(this.invalidDomainTypeTemplate(), domain.getName()); + return null; + } + + @Override + protected String getVariableValue(Object var) { + + if (!(var instanceof Domain[])) + return var.toString(); + + Domain[] domains = (Domain[]) var; + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < domains.length; i++) { + Domain domain = domains[i]; + sb.append("{"); //$NON-NLS-1$ + sb.append(domain.getName()); + + if ((domain instanceof FuzzySet)) { + sb.append(","); //$NON-NLS-1$ + FuzzySet fuzzyDomain = (FuzzySet) domain; + sb.append(fuzzyDomain.getLabelSet() + .getCardinality()); + } + sb.append("}"); //$NON-NLS-1$ + + if (i < domains.length - 1) + sb.append(", "); //$NON-NLS-1$ + } + + return sb.toString(); + } + + @Override + public String getValidationMessage() { + if (this.evaluate()) + return this.getPassedValidationTemplate(); + return this.getFirstErrorOrNull(); + } + + @Override + public String getDescription() { + return this.messages.ValidFuzzysetDomainsOperations_description; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValuationTypeOperation.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValuationTypeOperation.java new file mode 100644 index 0000000..869362d --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/operation/method/ValuationTypeOperation.java @@ -0,0 +1,146 @@ +package flintstones.helper.chainvalidator.operation.method; + +import java.text.MessageFormat; + +import javax.inject.Inject; +import org.apache.commons.lang.StringUtils; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.messages.Messages; + +public class ValuationTypeOperation extends BaseMethodOperation { + + String[] validTypes; + + Valuation[] valuations; + + Valuation invalidValuation; + + String params; + + Boolean superClass = null; + + @Inject + @Translation + private Messages messages; + + public ValuationTypeOperation(String entity, String[] validTypes, Valuation[] valuations) { + super(entity, validTypes, valuations); + + this.validTypes = validTypes; + this.valuations = valuations; + + params = StringUtils.join(validTypes, ", ") + (validTypes.length > 1 ? "types" : "type"); + } + + public ValuationTypeOperation(String entity, String validType, Valuation[] valuations) { + super(entity, validType, valuations); + + this.validTypes = new String[1]; + validTypes[0] = validType; + this.valuations = valuations; + + params = validType + " type"; + } + + + public ValuationTypeOperation(String entity, String[] validTypes, Valuation[] valuations, boolean superClass) { + super(entity, validTypes, valuations); + + this.validTypes = validTypes; + this.valuations = valuations; + this.superClass = superClass; + + params = StringUtils.join(validTypes, ", ") + (validTypes.length > 1 ? "types" : "type"); + } + + @Override + public String getOperationName() { + return "ValuationType"; + } + + @Override + protected String getOperationHumanName() { + return messages.ValuationType_Description; + } + + @Override + public String getPseudoCode() { + return MessageFormat.format(this.getPseudoCodeTemplate(), params); + } + + @Override + public String getValidationMessage() { + String types = StringUtils.join(validTypes, ", "); + + if (evaluate()) + return MessageFormat.format(getPassedValidationTemplate(), types); + + if (invalidValuation != null) + return MessageFormat.format(getFailedValidationTemplate(), invalidValuation.getName(), types, + invalidValuation.getClass().getSimpleName()); + return getDescription(); + + } + + @Override + public String getDescription() { + return messages.ValuationType_Description; + } + + @Override + protected String getFailedValidationTemplate() { + if(invalidValuation.isEvaluated()) + return messages.ValuationType_Invalid_Valuation_type; + else + return messages.ValuationType_Invalid_Valuation_type_Not_Assigned; + } + + + @Override + protected String getPassedValidationTemplate() { + return messages.ValuationType_All_Valuations_Valid; + } + + private Valuation findFirstInvalid() { + + for (Valuation v : valuations) { + + if(!v.isEvaluated()) + return v; + + boolean found = false; + for (String type : validTypes) { + if(superClass != null) { + if (v.getClass().getSimpleName().equals(type)) { + found = true; + break; + } + } else if(v.getClass().getSimpleName().equals(type) || v.getClass().getSuperclass().getSimpleName().equals(type)) { + found = true; + break; + } + } + + if(!found) + return v; + } + + return null; + } + + @Override + public boolean evaluate() { + + if (valuations.length == 0) + return false; + + invalidValuation = findFirstInvalid(); + if (invalidValuation != null) + return false; + + return true; + } + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/pseudocode/Generator.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/pseudocode/Generator.java new file mode 100644 index 0000000..702cf34 --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/pseudocode/Generator.java @@ -0,0 +1,208 @@ +package flintstones.helper.chainvalidator.pseudocode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Point; + +import flintstones.helper.chainvalidator.Statement; +import flintstones.helper.chainvalidator.messages.Messages; +import flintstones.helper.chainvalidator.operation.And; +import flintstones.helper.chainvalidator.operation.BaseOperation; +import flintstones.helper.chainvalidator.operation.Or; +import flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation; +import flintstones.helper.chainvalidator.operation.method.BaseMethodOperation; +import flintstones.helper.data.Pair; + +/** + * The Class Generator. + */ +public class Generator { + + /** The statements. */ + private final ArrayList statements = new ArrayList<>(); + + /** The operations in text. */ + private final ArrayList> operationsInText = new ArrayList<>(); + + /** The context. */ + @Inject + IEclipseContext context; + + @Inject + @Translation + private Messages messages; + + /** + * Instantiates a new generator. + */ + public Generator() { + } + + /** + * Adds the statement. + * + * @param statement the statement + */ + public void addStatement(Statement statement) { + statement = this.cleanStatement(statement); + this.statements.add(statement); + } + + /** + * Clean statement. + * + * @param statement the statement + * @return the statement + */ + private Statement cleanStatement(Statement statement) { + + Statement clone = statement.copy(); + + if (clone.getOperations() + .size() == 0) + return clone; + + BaseOperation firstOp = clone.getOperations() + .get(0); + if (firstOp.getClass() + .getSimpleName() + .equals(And.class.getSimpleName())) + clone.getOperations() + .remove(firstOp); + if (firstOp.getClass() + .getSimpleName() + .equals(Or.class.getSimpleName())) + clone.getOperations() + .remove(firstOp); + return clone; + } + + /** + * Gets the styled pseudo code. + * + * @param input the input box + * @param drawEvaluation the draw evaluation + */ + public void drawStyledPseudoCode(StyledText input, boolean drawEvaluation) { + + StyleProvider styler = new StyleProvider(input); + styler.drawEvaluation(drawEvaluation); + + // Cabecera + styler.addBoldText(this.messages.Generator_headerVariables); + + // Variables + HashMap variables = this.getAllVariables(); + Map variablesSorted = new TreeMap<>(variables); // Variables sorted by key + for (Entry entry : variablesSorted.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + styler.addNewVariable(key, value); + styler.addNL(); + } + + // Cabecera + styler.addNL(); + styler.addBoldText(this.messages.Generator_headerAlgorith); + + // If Statement + for (Statement statement : this.statements) { + styler.addIfOpen(); + + statement.getOperations() + .stream() + .forEach(k -> { + + int paddingBegin = styler.getCurrentPadding(); + + if (k instanceof BaseBinaryOperation) { + styler.setEvaluation(k.evaluate()); + BaseBinaryOperation binaryOp = (BaseBinaryOperation) k; + styler.addVariableKOV(binaryOp.getKey(), binaryOp.getOperator(), binaryOp.getValue()); + styler.endEvaluation(); + + } else if (k instanceof BaseMethodOperation) { + styler.setEvaluation(k.evaluate()); + BaseMethodOperation methodOp = (BaseMethodOperation) k; + styler.addMethod(methodOp.getOperationName(), methodOp.getArgsTextual()); + styler.endEvaluation(); + } else { + styler.addWS(); + styler.addText(k.getPseudoCode()); + styler.addWS(); + } + + int paddingEnd = styler.getCurrentPadding(); + this.addOperatorPosition(k, paddingBegin, paddingEnd); + + }); + + styler.addIfClose(); + styler.addNL(); + + styler.addReturnLabel(); + styler.setEvaluation(statement.evaluate()); + styler.addReturnText(statement.getReturnValue()); + styler.endEvaluation(); + + styler.addNL(); + } + + input.pack(); + + } + + /** + * Adds the operator position. + * + * @param operation the operation + * @param paddingBegin the padding begin + * @param paddingEnd the padding end + */ + private void addOperatorPosition(BaseOperation operation, int paddingBegin, int paddingEnd) { + Point desp = new Point(paddingBegin, paddingEnd); + Pair pair = new Pair<>(desp, operation); + this.operationsInText.add(pair); + } + + /** + * Gets the operator at the given point in the styled text. + * + * @param p the p + * @return the operator + */ + public BaseOperation getOperator(Point p) { + int position = p.x; + for (Pair pair : this.operationsInText) { + int min = pair.getLeft().x; + int max = pair.getLeft().y; + if (position >= min && position <= max) + return pair.getRight(); + } + return null; + } + + /** + * Gets the all variables. + * + * @return the all variables + */ + private HashMap getAllVariables() { + HashMap variables = new HashMap<>(); + + for (Statement statement : this.statements) + for (BaseOperation operation : statement.getOperations()) + variables.putAll(operation.getVariables()); + return variables; + } + +} diff --git a/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/pseudocode/StyleProvider.java b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/pseudocode/StyleProvider.java new file mode 100644 index 0000000..8d65c2e --- /dev/null +++ b/bundles/flintstones.helper.chainvalidator/src/flintstones/helper/chainvalidator/pseudocode/StyleProvider.java @@ -0,0 +1,281 @@ +package flintstones.helper.chainvalidator.pseudocode; + +import java.text.MessageFormat; + +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; + +import flintstones.model.ui.service.UiService; + +/** + * The Class PseudoCodeStyler. + */ +@SuppressWarnings("nls") +public class StyleProvider { + + /** The styled text. */ + private final /** The styled text widget. */ + StyledText styledText; + + /** The evaluation. */ + private int evaluation = 0; // -1 incorrecto, 0 nada, 1 correcto + + /** The draw evaluation. */ + private boolean drawEvaluation = false; + + /** The ui service. */ + + /** + * Sets the background color of the widget. + * + * @param c the new background + */ + private void setBackground(Color c) { + this.styledText.setBackground(c); + } + + /** + * Instantiates a new pseudo code styler. + * + * @param text the text + */ + public StyleProvider(StyledText text) { + super(); + this.styledText = text; + Color blackBackground = UiService.getColor(28, 31, 34); + this.setBackground(blackBackground); + UiService.setFont(this.styledText, UiService.FONT_CODE); + + } + + /** + * Sets the evaluation. + * + * @param status the new evaluation + */ + public void setEvaluation(boolean status) { + if (this.drawEvaluation) + this.evaluation = status ? 1 : -1; + } + + /** + * End evaluation. + */ + public void endEvaluation() { + this.evaluation = 0; + } + + /** + * Dibujar. + * + * @param text the text + * @param itemType the item type + */ + private void paint(String text, String itemType) { + + if (this.evaluation == -1) + itemType = UiService.CODE_WRONG; + else if (this.evaluation == 1) + itemType = UiService.CODE_RIGHT; + + Color foregroundColor = UiService.getCodeForeground(itemType, true); + int fontStyle = UiService.getCodeStyle(itemType, true); + + int appendSize = text.length(); + int totalSize = this.styledText.getText() + .length() + appendSize; + int begin = totalSize - appendSize; + + this.styledText.append(text); + this.styledText.setStyleRange(new StyleRange(begin, appendSize, foregroundColor, null, fontStyle)); + } + + /** + * Adds a tabulation. + */ + public void addTab() { + this.styledText.append(" "); + } + + /** + * Adds a white space. + */ + public void addWS() { + this.styledText.append(" "); + } + + /** + * Adds a new line. + */ + public void addNL() { + this.styledText.append("\n"); + } + + /** + * Adds text. + * + * @param text the text + */ + public void addText(String text) { + this.paint(text, ""); + } + + /** + * Adds a Key Operator Value. + * + * @param key the key + * @param operator the operator + * @param value the value + */ + public void addVariableKOV(String key, String operator, String value) { + // addWS(); + this.addVariableK(key); + this.addWS(); + this.addOperator(operator); + this.addWS(); + this.addVariableV(value); + } + + /** + * Adds the a var Key = Value. + * + * @param key the key + * @param value the value + */ + public void addNewVariable(String key, String value) { + this.addText("var"); + this.addWS(); + this.addVariableKOV(key, "=", value); + } + + /** + * Adds a Key = Value. + * + * @param key the key + * @param value the value + */ + public void addVariableKV(String key, String value) { + this.addVariableKOV(key, "=", value); + } + + /** + * Adds the Key. + * + * @param key the key + */ + public void addVariableK(String key) { + this.paint(key, UiService.CODE_KEY); + } + + /** + * Adds the Value. + * + * @param value the value + */ + public void addVariableV(String value) { + this.paint(value, UiService.CODE_VALUE); + } + + /** + * Adds the operator. + * + * @param op the op + */ + public void addOperator(String op) { + this.paint(op, UiService.CODE_OPERATOR); + } + + /** + * Adds the bold text. AKA important + * + * @param text the text + */ + public void addBoldText(String text) { + this.paint(text, UiService.CODE_COMMENT); + } + + /** + * Adds the return label. + * + */ + public void addReturnLabel() { + this.addTab(); + this.paint("return", "return"); + this.addWS(); + } + + /** + * Adds the return text. + * + * @param returnText the return text + */ + public void addReturnText(String returnText) { + returnText = MessageFormat.format("\"{0}\"", returnText); + this.paint(returnText, UiService.CODE_STRING); + } + + /** + * Adds the if open. + */ + public void addIfOpen() { + this.addWS(); + this.paint("if (", UiService.CODE_CONDITION); + this.addWS(); + } + + /** + * Adds the if close. + */ + public void addIfClose() { + this.addWS(); + this.paint(") then", UiService.CODE_CONDITION); + } + + /** + * Adds the method. + * + * @param methodName the method name + * @param args the args + */ + public void addMethod(String methodName, String... args) { + this.paint(methodName + "(", UiService.CODE_METHOD); + this.addWS(); + + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + this.addVariableK(arg); + if (i < args.length - 1) + this.addSemicolon(); + this.addWS(); + } + this.paint(")", UiService.CODE_METHOD); + } + + /** + * Adds the semicolon. + */ + public void addSemicolon() { + this.paint(",", "semicolon"); + } + + /** + * Draw evaluation. + * + * @param state the state + */ + public void drawEvaluation(boolean state) { + this.drawEvaluation = state; + } + + /** + * Gets the current padding. + * + * @return the current padding + */ + public int getCurrentPadding() { + return this.styledText.getText() + .length(); + } + +} diff --git a/bundles/flintstones.helper.data.io/.classpath b/bundles/flintstones.helper.data.io/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.helper.data.io/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.data.io/.polyglot.META-INF b/bundles/flintstones.helper.data.io/.polyglot.META-INF new file mode 100644 index 0000000..e41fb3c --- /dev/null +++ b/bundles/flintstones.helper.data.io/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.data.io + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] flintstones.helper.data.io + diff --git a/bundles/flintstones.helper.data.io/.project b/bundles/flintstones.helper.data.io/.project new file mode 100644 index 0000000..203cf96 --- /dev/null +++ b/bundles/flintstones.helper.data.io/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.data.io + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362606 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.data.io/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.data.io/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.data.io/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.data.io/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.data.io/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.data.io/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.data.io/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.data.io/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.data.io/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.data.io/META-INF/MANIFEST.MF b/bundles/flintstones.helper.data.io/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2ace496 --- /dev/null +++ b/bundles/flintstones.helper.data.io/META-INF/MANIFEST.MF @@ -0,0 +1,33 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: flintstones.helper.data.io +Bundle-SymbolicName: flintstones.helper.data.io;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.data.io +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Export-Package: flintstones.helper.data.io +Require-Bundle: flintstones.application.constants, + javanet.staxutils, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.helper.data.wxml, + flintstones.model.ahppreferences.service, + javax.inject, + flintstones.entity.ahppreferences, + flintstones.model.problemelement.service, + org.eclipse.e4.core.services, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment, + flintstones.entity.preferences.preferencecollection, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.model.domain.service, + javax.annotation, + flintstones.model.method.service, + flintstones.helper.data, + flintstones.model.ahp.referencepoint.service, + flintstones.entity.ahpsort.referencepoint, + flintstones.helper.debug, + flintstones.model.application.service, + flintstones.helper.extensionpoint diff --git a/bundles/flintstones.helper.data.io/build.properties b/bundles/flintstones.helper.data.io/build.properties new file mode 100644 index 0000000..3595411 --- /dev/null +++ b/bundles/flintstones.helper.data.io/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + schema/ diff --git a/bundles/flintstones.helper.data.io/plugin.xml b/bundles/flintstones.helper.data.io/plugin.xml new file mode 100644 index 0000000..e3efa49 --- /dev/null +++ b/bundles/flintstones.helper.data.io/plugin.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.helper.data.io/schema/flintstones.helper.data.io.exsd b/bundles/flintstones.helper.data.io/schema/flintstones.helper.data.io.exsd new file mode 100644 index 0000000..e12daa1 --- /dev/null +++ b/bundles/flintstones.helper.data.io/schema/flintstones.helper.data.io.exsd @@ -0,0 +1,123 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/ClearData.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/ClearData.java new file mode 100644 index 0000000..1aaae8b --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/ClearData.java @@ -0,0 +1,83 @@ +package flintstones.helper.data.io; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.services.events.IEventBroker; +import flintstones.application.constants.FrameworkConstants; +import flintstones.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.method.service.IMethodService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class ClearData. + */ +public class ClearData { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + @Inject + IMethodService methodService; + + @Inject + IProblemPreferencesService prefService; + + @Inject + IProfileAssignmentService profileAssignmentService; + + @Inject + IReferencePointService referencePointService; + + /** The broker. */ + @Inject + IEventBroker broker; + + @PostConstruct + private void init() { + } + + /** + * Execute the handler. + */ + public void execute() { + this.clear(); + this.sendEvents(); + } + + /** + * Clear the data in the model. + */ + private void clear() { + this.problemService.deleteAll(); + this.domainService.clear(); + this.valuationService.clear(); + this.methodService.clear(); + this.prefService.clear(); + this.profileAssignmentService.clear(); + this.referencePointService.clear(); + } + + + /** + * Send events to refresh the UI. + */ + private void sendEvents() { + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, FrameworkConstants.empty()); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_DELETED, null); + this.broker.post(FrameworkConstants.TOPIC_VALUATION_CREATED, null); + } +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/FlintstonesIO.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/FlintstonesIO.java new file mode 100644 index 0000000..0417341 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/FlintstonesIO.java @@ -0,0 +1,187 @@ +package flintstones.helper.data.io; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.data.wxml.exception.WNodeNotFound; +import flintstones.helper.debug.DH; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import javanet.staxutils.IndentingXMLStreamWriter; + +/** + * The Class FlintstonesIO. + */ +@SuppressWarnings("nls") +public class FlintstonesIO { + + /** The broker. */ + @Inject + IEventBroker broker; + + /** The context. */ + @Inject + IEclipseContext context; + + /** + * Load a file. + * + * @param fileName the file name + */ + public void load(String fileName) { + + try { + this.loadFile(fileName); + this.sendEvents(); + } catch (ParserConfigurationException | IOException | SAXException e1) { + DH.out("No se ha podido cargar el fichero " + fileName); + e1.printStackTrace(); + } + + } + + /** + * Load file. + * + * @param fileName the file name + * @throws ParserConfigurationException the parser configuration exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws SAXException the SAX exception + */ + private void loadFile(String fileName) throws ParserConfigurationException, IOException, SAXException { + + DH.l(); + DH.out("I/O","!INFOFS Cargando el fichero " + fileName); + Element node = DocumentBuilderFactory.newInstance() + .newDocumentBuilder() + .parse(new File(fileName)) + .getDocumentElement(); + + WNode wnode = new WNode(node); + WNode nodex = wnode.getFirst("resolution.phase"); + String version = nodex.getAttribute("version") != null ? nodex.getAttribute("version") : "3.0"; + wnode.setVersion(version); + this.load(wnode); + } + + /** + * Load. + * + * @param node the nod + * @param version the version + */ + private void load(WNode node) { + DH.out("I/O","!INFOFS Leyendo la versión " + node.getVersion()); + + + List importModules = getIOModules(); + for (BaseIO io : importModules) { + + if (!io.getVersion().equals(node.getVersion())) { + continue; + } + + io.beforeRead(); + WNode ioNode = null; + try { + ioNode = node.getFirst("id", io.getPhase()); + WNode ioNode2 = ioNode.getFirst(io.getPart()); + io.read(ioNode2); + io.afterRead(); + + } catch (WNodeNotFound e) { + System.out.println(e.getMessage()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + private List getIOModules() { + List importModules = new ArrayList(); + + BaseRegistry basereg = new BaseRegistry("flintstones.helper.data.io"); + ExtensionRegistry[] regs = basereg.getAllRegistries(); + for(ExtensionRegistry reg : regs) { + BaseIO importModule = (BaseIO) basereg.instantiate(reg, context); + importModule.setVersion(reg.getAttribute("version_mayor"), reg.getAttribute("version_minor")); + importModules.add(importModule); + } + return importModules; + } + + /** + * Write file. + * + * @param fileName the file name + * @throws ParserConfigurationException the parser configuration exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws SAXException the SAX exception + * @throws XMLStreamException the XML stream exception + */ + public void writeFile(String fileName) throws IOException, XMLStreamException { + + XMLOutputFactory factory = XMLOutputFactory.newInstance(); + + XMLStreamWriter writer = new IndentingXMLStreamWriter(factory.createXMLStreamWriter(new FileOutputStream(fileName), "UTF-8")); + + List importModules = getIOModules(); + + DH.l(); + DH.out("!INFOFS Guardando en el fichero " + fileName); + + writer.writeStartDocument(); + writer.writeStartElement("resolution.scheme"); + + for (BaseIO io : importModules) { + + if (!io.getVersion() + .equals("4.0")) + continue; + + writer.writeStartElement("resolution.phase"); + writer.writeAttribute("id", io.getPhase()); + writer.writeAttribute("version", "4.0"); + writer.writeStartElement(io.getPart()); + io.beforeWrite(); + io.setWriter(writer); + io.write(); + io.afterWrite(); + writer.writeEndElement(); + writer.writeEndElement(); + } + writer.writeEndElement(); + writer.writeEndDocument(); + writer.flush(); + } + + /** + * Send events. + */ + private void sendEvents() { + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_PROBLEMELEMENT_CREATED, FrameworkConstants.empty() ); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_CREATED, null); + this.broker.post(FrameworkConstants.TOPIC_VALUATION_CREATED, null); + this.broker.post(FrameworkConstants.TOPIC_FRAMEWORK_SORTINGPROFILE_CREATED, null); + + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/interfaces/BaseIO.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/interfaces/BaseIO.java new file mode 100644 index 0000000..a1a1192 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/interfaces/BaseIO.java @@ -0,0 +1,116 @@ +package flintstones.helper.data.io.interfaces; + +import java.text.MessageFormat; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.debug.DH; + +/** + * The Class BaseIO. + */ +public abstract class BaseIO { + + /** The expected number of loadedItems. */ + protected int expected = 0; + + /** The valid number of loadedItems. */ + protected int valid = 0; + + /** The failed number of loadedItems. */ + protected int failed = 0; + + /** The writer. */ + protected XMLStreamWriter writer; + + /** The version id. */ + protected String version = "X.X"; //$NON-NLS-1$ + + /** + * Before write do this. + */ + public void beforeWrite() { + }; + + /** + * Before read do this. + */ + public abstract void beforeRead(); + + /** + * Read the XML node. + * + * @param node the node + */ + public abstract void read(WNode node); + + /** + * Write. + * + * @throws XMLStreamException the XML stream exception + */ + public abstract void write() throws XMLStreamException; + + /** + * Sets the writer. + * + * @param writer the new writer + * @throws XMLStreamException the XML stream exception + */ + public void setWriter(XMLStreamWriter writer) throws XMLStreamException { + this.writer = writer; + }; + + /** + * Gets the phase. + * + * @return the phase + */ + public abstract String getPhase(); + + /** + * Gets the part. + * + * @return the part + */ + public abstract String getPart(); + + public void afterRead() { + String msg = ""; //$NON-NLS-1$ + + if (this.expected > 0) + msg = "!INFOFS Cargados {0}/{1} en {3}"; //$NON-NLS-1$ + else + msg = "!INFOFS Cargados {0} en {3}"; //$NON-NLS-1$ + + if (this.failed == 1) + msg += " con un fallo"; //$NON-NLS-1$ + else if (this.failed > 1) + msg += ", con {2} fallos"; //$NON-NLS-1$ + + String loader = this.getClass() + .asSubclass(this.getClass()) + .getSimpleName(); + String msg2 = MessageFormat.format(msg, this.valid, this.expected, this.failed, loader); + DH.out("I/O",msg2); + } + + public void afterWrite() { + }; + + /** + * Gets the version. + * + * @return the version + */ + public String getVersion() { + return this.version; + } + + public void setVersion(String mayor, String minor) { + this.version = mayor + "." + minor; + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/interfaces/BaseIO30.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/interfaces/BaseIO30.java new file mode 100644 index 0000000..6cec669 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/interfaces/BaseIO30.java @@ -0,0 +1,18 @@ +package flintstones.helper.data.io.interfaces; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +public abstract class BaseIO30 extends BaseIO { + + + @Override + public void setWriter(XMLStreamWriter writer) { + } + + @Override + public void write() throws XMLStreamException { + + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOApplication40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOApplication40.java new file mode 100644 index 0000000..f159769 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOApplication40.java @@ -0,0 +1,53 @@ +package flintstones.helper.data.io.modules; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import flintstones.application.model.IApplicationService; +import flintstones.application.model.ProblemType; +import flintstones.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; + +public class IOApplication40 extends BaseIO { + + @Inject + IApplicationService appService; + + public IOApplication40() { + } + + @Override + public void beforeRead() { + + } + + @Override + public void read(WNode node) { + WNode wnode = node.getFirst("data"); + String problemType = wnode.getAttribute("problemType"); + + if (problemType != null) { + if (problemType.equals(ProblemType.Ranking.toString())) + appService.launchProblem(ProblemType.Ranking); + else if (problemType.equals(ProblemType.Sorting.toString())) + appService.launchProblem(ProblemType.Sorting); + } + } + + @Override + public void write() throws XMLStreamException { + writer.writeStartElement("data"); + writer.writeAttribute("problemType", appService.getProblemType().toString()); + writer.writeEndElement(); + } + + @Override + public String getPhase() { + return "flintstones.application"; + } + + @Override + public String getPart() { + return "application"; + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomain30.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomain30.java new file mode 100644 index 0000000..6040d8a --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomain30.java @@ -0,0 +1,80 @@ + +package flintstones.helper.data.io.modules; + +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.domain.Domain; +import flintstones.helper.data.io.interfaces.BaseIO30; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.domain.service.IDomainService; + +/** + * The Class IODomain30. + */ +public class IODomain30 extends BaseIO30 { + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO domain 30. + */ + public IODomain30() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + List nodes = node.getChildren(); + this.expected = nodes.size(); + + for (WNode item : nodes) { + String extensionPointId = item.getName(); + String domainName = item.getAttribute("id"); //$NON-NLS-1$ + Domain domain = this.domainService.create(extensionPointId); + domain.read(item); + domain.setName(domainName); + this.domainService.add(domain); + this.valid++; + + } + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.framework"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "domain-set"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + this.domainService.clear(); + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomain40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomain40.java new file mode 100644 index 0000000..0da0304 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomain40.java @@ -0,0 +1,105 @@ + +package flintstones.helper.data.io.modules; + +import java.util.List; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.domain.Domain; +import flintstones.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.domain.service.IDomainService; + +/** + * The Class IODomain40. + */ +public class IODomain40 extends BaseIO { + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO domain 40. + */ + public IODomain40() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + List nodes = node.getChildren(); + this.expected = nodes.size(); + + for (WNode item : nodes) { + String extensionPointId = item.getAttribute(Domain.Fields.type); + String itemName = item.getAttribute(Domain.Fields.name); + Domain domain = this.domainService.create(extensionPointId); + domain.read(item); + domain.setName(itemName); + this.domainService.add(domain); + this.valid++; + } + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#write() */ + @Override + public void write() throws XMLStreamException { + Domain[] arr = this.domainService.getAll(); + for (Domain d : arr) + this.writeDomain(d); + + } + + /** + * Write domain. + * + * @param d the d + * @throws XMLStreamException the XML stream exception + */ + private void writeDomain(Domain d) throws XMLStreamException { + this.writer.writeStartElement(Domain.class.getSimpleName().toLowerCase()); + this.writer.writeAttribute(Domain.Fields.type.toString(), d.getType()); + this.writer.writeAttribute(Domain.Fields.name.toString(), d.getName()); + d.write(this.writer); + this.writer.writeEndElement(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.framework.domains"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "domains"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + this.domainService.clear(); + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainAssignments30.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainAssignments30.java new file mode 100644 index 0000000..342b3f9 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainAssignments30.java @@ -0,0 +1,110 @@ + +package flintstones.helper.data.io.modules; + +import java.util.List; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.ProblemElementKey; +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.helper.data.io.interfaces.BaseIO30; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class IODomainAssignments30. + */ +public class IODomainAssignments30 extends BaseIO30 { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO domain assignments 30. + */ + public IODomainAssignments30() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + List nodes = node.getChildren(); + this.expected = nodes.size(); + + for (WNode item : nodes) { + + String domainName = item.getAttribute("domain"); //$NON-NLS-1$ + String expertCanonicalName = item.getAttribute("expert"); //$NON-NLS-1$ + String alternativeCanonicalName = item.getAttribute("alternative"); //$NON-NLS-1$ + String criterionCanonicalName = item.getAttribute("criterion"); //$NON-NLS-1$ + + Domain domain = this.domainService.getByName(domainName); + Expert expert = (Expert) this.problemService.getByCanonicalName(Expert.Type, expertCanonicalName); + Alternative alternative = (Alternative) this.problemService.getByCanonicalName(Alternative.Type, alternativeCanonicalName); + Criterion criterion = (Criterion) this.problemService.getByCanonicalName(Criterion.Type, criterionCanonicalName); + + ProblemElementKey pek = new ProblemElementKey(expert, alternative, criterion); + Valuation v = this.valuationService.create(domain); + this.valuationService.addOrUpdate(pek, v); + this.valid++; + } + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + // valuationService.clear(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.frameworkstructuring"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "domain-assignments"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */ + @Override + public void setWriter(XMLStreamWriter writer) { + } +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainAssignments40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainAssignments40.java new file mode 100644 index 0000000..a834b1b --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainAssignments40.java @@ -0,0 +1,144 @@ + +package flintstones.helper.data.io.modules; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map.Entry; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.ProblemElementKey; +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.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class IODomainAssignments40. + */ +public class IODomainAssignments40 extends BaseIO { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO domain assignments 40. + */ + public IODomainAssignments40() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + List nodes = node.getChildren(); + this.expected = nodes.size(); + + for (WNode item : nodes) { + + String domainName = item.getAttribute(Domain.Fields.Domain); + String expertCanonicalName = item.getAttribute(Expert.Fields.Expert); + String alternativeCanonicalName = item.getAttribute(Alternative.Fields.Alternative); + String criterionCanonicalName = item.getAttribute(Criterion.Fields.Criterion); + + Domain domain = this.domainService.getByName(domainName); + Expert expert = (Expert) this.problemService.getByName(Expert.Fields.Expert.toString(), expertCanonicalName); + Alternative alternative = (Alternative) this.problemService.getByName(Alternative.Fields.Alternative.toString(), alternativeCanonicalName); + Criterion criterion = (Criterion) this.problemService.getByName(Criterion.Fields.Criterion.toString(), criterionCanonicalName); + + ProblemElementKey pek = new ProblemElementKey(expert, alternative, criterion); + Valuation v = this.valuationService.create(domain); + + this.valuationService.addOrUpdate(pek, v); + this.valid++; + } + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#write() */ + @Override + public void write() throws XMLStreamException { + LinkedHashMap valuations = this.valuationService.getAllKV(); + + for (Entry entry : valuations.entrySet()) + this.writeAssignment(entry.getKey() + .getExpert(), + entry.getKey() + .getAlternative(), + entry.getKey() + .getCriterion(), + entry.getValue() + .getDomain(), + entry.getValue()); + } + + /** + * Write assignment. + * + * @param e the expert + * @param a the alternative + * @param c the criterion + * @param d the domain + * @throws XMLStreamException the XML stream exception + */ + private void writeAssignment(Expert e, Alternative a, Criterion c, Domain d, Valuation v) throws XMLStreamException { + this.writer.writeStartElement("assignment"); //$NON-NLS-1$ + this.writer.writeAttribute(Expert.Fields.Expert.toString(), e.getName()); + this.writer.writeAttribute(Alternative.Fields.Alternative.toString(), a.getName()); + this.writer.writeAttribute(Criterion.Fields.Criterion.toString(), c.getName()); + this.writer.writeAttribute(Domain.Fields.Domain.toString(), d.getName()); + this.writer.writeAttribute(Valuation.Fields.Valuation.toString(), v.getId()); + this.writer.writeEndElement(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + // valuationService.clear(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.frameworkstructuring"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "domain-assignments"; //$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainValuation30.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainValuation30.java new file mode 100644 index 0000000..6bdf844 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IODomainValuation30.java @@ -0,0 +1,120 @@ + +package flintstones.helper.data.io.modules; + +import java.util.List; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.domain.Domain; +import flintstones.helper.data.io.interfaces.BaseIO30; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.debug.DH; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class IODomainValuation30. + */ +public class IODomainValuation30 extends BaseIO30 { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO domain valuation 30. + */ + public IODomainValuation30() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + List nodes = node.getChildren(); + this.expected = nodes.size() / 2; + + for (int i = 0; i < nodes.size(); i += 2) { + WNode domainItem = nodes.get(i); + WNode valuationItem = nodes.get(i + 1); + + String domainName = domainItem.getAttribute("id"); //$NON-NLS-1$ + String valuationId = valuationItem.getAttribute("id"); //$NON-NLS-1$ + + this.fixDomainType(domainName, valuationId); + } + + } + + /** + * Fix domain type. The old flintstone won't save different domain type for some hesitant/fuzzy domains. + * This methods fix it. + * @param domainName the domain name + * @param valuationId the valuation id + */ + private void fixDomainType(String domainName, String valuationId) { + + String newType = this.valuationService.getDomainFor(valuationId); + Domain domain = this.domainService.getByName(domainName); + + // En FS3, si borras un dominio con valuation, el dominio se borra pero el par + // dominio-valuatio no. + if (domain != null) { + domain.setType(newType); + this.valid++; + } else { + DH.out("!ERRORFS Fallo al asignar el dominio " + domainName); //$NON-NLS-1$ + this.failed++; + } + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + this.valuationService.clear(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.framework"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "domain-valuation"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */ + @Override + public void setWriter(XMLStreamWriter writer) { + } +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOPreferences40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOPreferences40.java new file mode 100644 index 0000000..b2bb1fa --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOPreferences40.java @@ -0,0 +1,267 @@ + +package flintstones.helper.data.io.modules; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.ahppreferences.PreferenceCollectionKey; +import flintstones.entity.ahppreferences.PreferenceMatrix; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class IOValuation40. + */ +public class IOPreferences40 extends BaseIO { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The broker. */ + @Inject + IEventBroker broker; + + @Inject + IProblemPreferencesService preferencesService; + + /** + * Instantiates a new IO valuation 40. + */ + public IOPreferences40() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + if(node == null) + return ; + + List preferenceCollections = node.getFirst(PreferenceCollection.Fields.PreferenceCollections).getChildren(); + + for(WNode preferenceNode : preferenceCollections ) { + + String mainType = preferenceNode.getAttribute(PreferenceCollection.Fields.mainType); + String otherType = preferenceNode.getAttribute(PreferenceCollection.Fields.otherType); + String leftType = preferenceNode.getAttribute(PreferenceCollection.Fields.leftType); + String rightType = preferenceNode.getAttribute(PreferenceCollection.Fields.rightType); + + ArrayList builds = new ArrayList<>(); + + List buildNodes = preferenceNode.getChildren(); + for(WNode buildNode : buildNodes) { + + String mainName = buildNode.getAttribute(PreferenceBuild.Fields.mainProblemElement); + String otherName = buildNode.getAttribute(PreferenceBuild.Fields.otherProblemElement); + + ProblemElement mainPE = problemService.getByName(mainType, mainName); + ProblemElement otherPE = problemService.getByName(otherType, otherName); + + WNode leftNode = buildNode.getFirst(PreferenceBuild.Fields.leftElements); + ArrayList leftItems = new ArrayList<>(); + for(WNode lNode : leftNode.getChildren()) { + String leftId = lNode.getAttribute(ProblemElement.Fields.name); + ProblemElement pe = problemService.getByName(leftType, leftId); + if(pe == null) + throw new NullPointerException(); + + leftItems.add(pe); + } + + WNode rightNode = buildNode.getFirst(PreferenceBuild.Fields.rightElements); + ArrayList rightItems = new ArrayList<>(); + for(WNode rNode : rightNode.getChildren()) { + String name = rNode.getAttribute(ProblemElement.Fields.name); + ProblemElement pe = problemService.getByName(rightType, name); + if(pe == null) + throw new NullPointerException(); + rightItems.add(pe); + } + + PreferenceBuild build = new PreferenceBuild( + mainPE, + otherPE, + leftItems.toArray(new ProblemElement[0]), + rightItems.toArray(new ProblemElement[0]) + ); + + WNode matrixNode = buildNode.getFirst(PreferenceMatrix.Fields.PreferenceMatrix); + List preferenceNodes = matrixNode.getChildren(); + + for(WNode prefNode : preferenceNodes) { + int index = prefNode.getAttributeInt(PreferenceMatrix.Fields.preferenceIndex); + String lName = prefNode.getAttribute(PreferenceBuild.Fields.leftProblemElement); + String rName = prefNode.getAttribute(PreferenceBuild.Fields.rightProblemElement); + + ProblemElement leftPe = problemService.getByName(leftType, lName); + ProblemElement rightPe = problemService.getByName(rightType, rName); + + build.set(leftPe, rightPe, index); + + } + + builds.add(build); + + } + + PreferenceCollection pref = new PreferenceCollection(builds.toArray(new PreferenceBuild[0])); + preferencesService.addOrUpdate(pref); + + } + + + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#write() */ + @Override + public void write() throws XMLStreamException { + + HashMap preferences = preferencesService.getAllPreferences(); + + writer.writeStartElement(PreferenceCollection.Fields.PreferenceCollections.toString()); + for( Entry entry : preferences.entrySet() ) { + + PreferenceCollectionKey key = entry.getKey(); + PreferenceCollection col = entry.getValue(); + + writePreferenceCollection(key, col); + + } + writer.writeEndElement(); + + } + + private void writePreferenceCollection(PreferenceCollectionKey key, PreferenceCollection pref) throws XMLStreamException { + + writer.writeStartElement(PreferenceCollection.Fields.PreferenceCollection.toString()); + + writer.writeAttribute(PreferenceCollection.Fields.mainType.toString(), key.getMainType()); + writer.writeAttribute(PreferenceCollection.Fields.otherType.toString(), key.getOtherType()); + writer.writeAttribute(PreferenceCollection.Fields.leftType.toString(), key.getLeftType()); + writer.writeAttribute(PreferenceCollection.Fields.rightType.toString(), key.getRightType()); + + for(ProblemElement main : pref.getAllMainElements()) + for(ProblemElement other : pref.getAllOtherElements()) + writePreferenceBuild(pref, main, other); + + writer.writeEndElement(); + + } + + private void writePreferenceBuild(PreferenceCollection pref, ProblemElement pe1, ProblemElement pe2) throws XMLStreamException { + + writer.writeStartElement(PreferenceBuild.Fields.PreferenceBuild.toString()); + + PreferenceBuild build = pref.getBuild(pe1, pe2); + writer.writeAttribute(PreferenceBuild.Fields.mainProblemElement.toString(), pe1.getName()); + writer.writeAttribute(PreferenceBuild.Fields.otherProblemElement.toString(), pe2.getName()); + + writeBuildLeftelements(build); + writeBuildRightelements(build); + writeBuildMatrix(build); + + writer.writeEndElement(); + + } + + private void writeBuildMatrix(PreferenceBuild build) throws XMLStreamException { + + writer.writeStartElement(PreferenceMatrix.Fields.PreferenceMatrix.toString()); + + for(ProblemElement leftItem : build.getLeftElements()) + for(ProblemElement rightItem : build.getRightElements()) + writePreferences(build, leftItem, rightItem); + + writer.writeEndElement(); + } + + private void writeBuildLeftelements(PreferenceBuild build) throws XMLStreamException { + writer.writeStartElement(PreferenceBuild.Fields.leftElements.toString()); +// writer.writeAttribute(PreferenceBuild.Fields.type.toString(), build.getLeftType().toString()); + + for(ProblemElement element : build.getLeftElements()) { + writer.writeStartElement(ProblemElement.Fields.ProblemElement.toString()); + writer.writeAttribute(ProblemElement.Fields.name.toString(), element.getName()); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + private void writeBuildRightelements(PreferenceBuild build) throws XMLStreamException { + writer.writeStartElement(PreferenceBuild.Fields.rightElements.toString()); +// writer.writeAttribute(PreferenceBuild.Fields.type.toString(), build.getRightType().toString()); + + for(ProblemElement element : build.getRightElements()) { + writer.writeStartElement(ProblemElement.Fields.ProblemElement.toString()); + writer.writeAttribute(ProblemElement.Fields.name.toString(), element.getName()); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + private void writePreferences(PreferenceBuild pref, ProblemElement left, ProblemElement right) throws XMLStreamException { + + int index = pref.get(left, right); + writer.writeStartElement(PreferenceBuild.Fields.Preference.toString()); + writer.writeAttribute(PreferenceBuild.Fields.leftProblemElement.toString(), left.getName()); + writer.writeAttribute(PreferenceBuild.Fields.rightProblemElement.toString(), right.getName()); + writer.writeAttribute(PreferenceMatrix.Fields.preferenceIndex.toString(), index+""); + writer.writeEndElement(); + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.gathering.preferences"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "preferences"; //$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProblemElements30.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProblemElements30.java new file mode 100644 index 0000000..3f42734 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProblemElements30.java @@ -0,0 +1,182 @@ +package flintstones.helper.data.io.modules; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.helper.data.io.interfaces.BaseIO30; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class IOProblemElements30. + */ +public class IOProblemElements30 extends BaseIO30 { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO problem elements 30. + */ + public IOProblemElements30() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + WNode eNode = node.getFirst("experts"); //$NON-NLS-1$ + this.readExperts(eNode); + + WNode aNode = node.getFirst("alternatives"); //$NON-NLS-1$ + this.readAlternatives(aNode); + + WNode cNode = node.getFirst("criteria"); //$NON-NLS-1$ + this.readCriterions(cNode); + + } + + /** + * Read expert. + * + * @param node the node + * @param parent the parent + * @return the expert + */ + private Expert readExpert(WNode node) { + + String id = node.getAttribute("id"); //$NON-NLS-1$ + Expert mainPE = new Expert(id); + +// mainPE.setParent(null); + this.problemService.add(mainPE); + this.valid++; + + for (WNode item : node.getChildren()) { + Expert childPE = this.readExpert(item); + mainPE.addChildren(childPE); + } + + return mainPE; + + } + + /** + * Read experts. + * + * @param node the node + */ + private void readExperts(WNode node) { + for (WNode item : node.getChildren()) + this.readExpert(item); + } + + /** + * Read alternative. + * + * @param node the node + * @param parent the parent + * @return the alternative + */ + private Alternative readAlternative(WNode node) { + + String id = node.getAttribute("id"); //$NON-NLS-1$ + Alternative mainPE = new Alternative(id); + this.problemService.add(mainPE); + this.valid++; + + return mainPE; + } + + /** + * Read alternatives. + * + * @param node the node + */ + private void readAlternatives(WNode node) { + for (WNode item : node.getChildren()) + this.readAlternative(item); + } + + /** + * Read criterion. + * + * @param node the node + * @param parent the parent + * @return the criterion + */ + private Criterion readCriterion(WNode node) { + + String id = node.getAttribute("id"); //$NON-NLS-1$ + boolean cost = (node.getAttribute("cost") //$NON-NLS-1$ + .equals("true")) ? true : false; //$NON-NLS-1$ + Criterion mainPE = new Criterion(id); + mainPE.setCost(cost); + +// mainPE.setParent(null); + this.problemService.add(mainPE); + this.valid++; + + for (WNode item : node.getChildren()) { + Criterion childPE = this.readCriterion(item); + mainPE.addChildren(childPE); + } + + return mainPE; + + } + + /** + * Read criterion. + * + * @param node the node + */ + private void readCriterions(WNode node) { + for (WNode item : node.getChildren()) + this.readCriterion(item); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + this.problemService.deleteAll(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.framework"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "elements"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */ + @Override + public void setWriter(XMLStreamWriter writer) { + } +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProblemElements40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProblemElements40.java new file mode 100644 index 0000000..f0824e5 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProblemElements40.java @@ -0,0 +1,249 @@ +package flintstones.helper.data.io.modules; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class IOProblemElements40. + */ +public class IOProblemElements40 extends BaseIO { + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO problem elements 40. + */ + public IOProblemElements40() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + WNode eNode = node.getFirst(Expert.Fields.Experts); + this.readExperts(eNode); + + WNode aNode = node.getFirst(Alternative.Fields.Alternatives); + this.readAlternatives(aNode); + + WNode cNode = node.getFirst(Criterion.Fields.Criteria); + this.readCriterions(cNode); + + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */ + @Override + public void setWriter(XMLStreamWriter writer) { + this.writer = writer; + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#write() */ + @Override + public void write() throws XMLStreamException { + + ProblemElement[] items = ProblemElementHelper.getAsUserOrdered(problemService.getMainElements(Expert.Type)); + + this.writer.writeStartElement(Expert.Fields.Experts.toString()); + for (ProblemElement pe : items) + this.writePE(pe); + this.writer.writeEndElement(); + + this.writer.writeStartElement(Alternative.Fields.Alternatives.toString()); + items = ProblemElementHelper.getAsUserOrdered(problemService.getMainElements(Alternative.Type)); + for (ProblemElement pe : items) + this.writePE(pe); + this.writer.writeEndElement(); + + this.writer.writeStartElement(Criterion.Fields.Criteria.toString()); + items = ProblemElementHelper.getAsUserOrdered(problemService.getMainElements(Criterion.Type)); + for (ProblemElement pe : items) + this.writePE(pe); + this.writer.writeEndElement(); + + } + + /** + * Read expert. + * + * @param node the node + * @param parent the parent + * @return the expert + */ + private Expert readExpert(WNode node) { + + String name = node.getAttribute(ProblemElement.Fields.name); + String mail = node.getAttribute(Expert.Fields.mail); + + Expert mainPE = new Expert(name); +// mainPE.setParent(null); + mainPE.setMail(mail); + + this.problemService.add(mainPE); + this.valid++; + + WNode children = node.getFirst(ProblemElement.Fields.children); + if (children != null) + for (WNode item : children.getChildren()) { + Expert childPE = this.readExpert(item); + mainPE.addChildren(childPE); + } + + return mainPE; + + } + + /** + * Write PE. + * + * @param pe the pe + * @throws XMLStreamException the XML stream exception + */ + private void writePE(ProblemElement pe) throws XMLStreamException { + this.writer.writeStartElement(pe.getType()); + this.writer.writeAttribute(ProblemElement.Fields.name.toString(), pe.getName()); + if (pe.getType().equals(Criterion.Type)) + this.writer.writeAttribute(Criterion.Fields.cost.toString(), ((Criterion) pe).isCost() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ + + if(pe.getType().equals(Expert.Type)) { + Expert e = ((Expert)pe); + if(e.getMail() != null && !e.getMail().equals("")) + writer.writeAttribute(Expert.Fields.mail.toString(), e.getMail()); + } + + if (pe.hasChildren()) { + this.writer.writeStartElement(ProblemElement.Fields.children.toString()); + for (ProblemElement cpe : pe.getChildren()) + this.writePE(cpe); + + this.writer.writeEndElement(); + } + this.writer.writeEndElement(); + } + + /** + * Read experts. + * + * @param node the node + */ + private void readExperts(WNode node) { + for (WNode item : node.getChildren()) + this.readExpert(item); + } + + /** + * Read alternative. + * + * @param node the node + * @param parent the parent + * @return the alternative + */ + private Alternative readAlternative(WNode node) { + + String name = node.getAttribute(ProblemElement.Fields.name); + Alternative mainPE = new Alternative(name); + this.problemService.add(mainPE); + this.valid++; + + return mainPE; + } + + /** + * Read alternatives. + * + * @param node the node + */ + private void readAlternatives(WNode node) { + for (WNode item : node.getChildren()) + this.readAlternative(item); + } + + /** + * Read criterion. + * + * @param node the node + * @param parent the parent + * @return the criterion + */ + private Criterion readCriterion(WNode node) { + + String name = node.getAttribute(ProblemElement.Fields.name); + boolean cost = (node.getAttribute(Criterion.Fields.cost) + .equals("true")) ? true : false; //$NON-NLS-1$ + Criterion mainPE = new Criterion(name); + mainPE.setCost(cost); + +// mainPE.setParent(null); + this.problemService.add(mainPE); + this.valid++; + + WNode children = node.getFirst(ProblemElement.Fields.children); + + if (children != null) + for (WNode item : children.getChildren()) { + Criterion childPE = this.readCriterion(item); + mainPE.addChildren(childPE); + } + + return mainPE; + + } + + /** + * Read criterion. + * + * @param node the node + */ + private void readCriterions(WNode node) { + for (WNode item : node.getChildren()) + this.readCriterion(item); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + this.problemService.deleteAll(); + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.framework.problemelements"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "elements"; //$NON-NLS-1$ + } +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProfileAssignment40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProfileAssignment40.java new file mode 100644 index 0000000..367e412 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOProfileAssignment40.java @@ -0,0 +1,120 @@ +package flintstones.helper.data.io.modules; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; + +public class IOProfileAssignment40 extends BaseIO { + + @Inject + IProfileAssignmentService profileService; + + @Inject + IProblemElementService problemService; + + @Inject + IEclipseContext context; + + public IOProfileAssignment40() { + } + + @Override + public void beforeRead() { + } + + @Override + public void read(WNode node) { + if (node == null) + return; + + List assignments = node.getFirst(ProfileAssignment.Fields.ProfileAssignments).getChildren(); + for (WNode assignmentN : assignments) { + + String expertName = assignmentN.getAttribute(Expert.Fields.Expert); + Expert e = (Expert) problemService.getByName(Expert.Type, expertName); + + String criterionName = assignmentN.getAttribute(Criterion.Fields.Criterion); + Criterion c = (Criterion) problemService.getByName(Criterion.Type, criterionName); + +// String domainName = assignmentN.getAttribute(Domain.Fields.Domain); +// AHPSortDomain d = (AHPSortDomain) domainService.getByName(domainName); + + List profiles = assignmentN.getChildren(); + + LinkedList list = new LinkedList<>(); + + for (WNode profileN : profiles) { + double value = Double.parseDouble(profileN.getAttribute(SortingProfile.Fields.value)); + list.add(value); + } + + ProfileAssignment pa = profileService.create(e, c); + for (Double val : list) { + SortingProfile profile = new SortingProfile(e, c, val); + pa.addProfile(profile); + } + + profileService.addOrUpdate(pa); + + } + } + + @Override + public String getPhase() { + return "flintstones.resolutionphase.gathering.preferences.assignments"; + } + + @Override + public String getPart() { + return "assignment"; + } + + @Override + public void write() throws XMLStreamException { + + writer.writeStartElement(ProfileAssignment.Fields.ProfileAssignments.toString()); + for (Entry> entry : profileService.getAll().entrySet()) { + String expertName = entry.getKey().getName(); + for (Entry entry2 : entry.getValue().entrySet()) { + String criterionName = entry2.getKey().getName(); +// String domainName = entry2.getValue().getDomain().getName(); + ProfileAssignment pa = entry2.getValue(); + writeAssignment(expertName, criterionName, pa); + } + } + writer.writeEndElement(); + + } + + private void writeAssignment(String expert, String criterion, ProfileAssignment assigment) + throws XMLStreamException { + writer.writeStartElement(ProfileAssignment.Fields.ProfileAssignment.toString()); + writer.writeAttribute(Expert.Fields.Expert.toString(), expert); +// writer.writeAttribute(Domain.Fields.Domain.toString(), domain); + writer.writeAttribute(Criterion.Fields.Criterion.toString(), criterion); + + for (SortingProfile p : assigment.getAllProfiles()) { + writer.writeStartElement(SortingProfile.Fields.SortingProfile.toString()); + writer.writeAttribute(SortingProfile.Fields.value.toString(), p.getValue() + ""); + writer.writeEndElement(); + } + + writer.writeEndElement(); + + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOReferencePoints40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOReferencePoints40.java new file mode 100644 index 0000000..6a8b183 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOReferencePoints40.java @@ -0,0 +1,92 @@ +package flintstones.helper.data.io.modules; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; + +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; +import flintstones.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.problemelement.service.IProblemElementService; + +public class IOReferencePoints40 extends BaseIO { + + @Inject + IProblemElementService problemService; + + @Inject + IReferencePointService referenceService; + + public IOReferencePoints40() { + } + + @Override + public void beforeRead() { + // TODO Auto-generated method stub + + } + + @Override + public void read(WNode node) { + List refPoints = node.getFirst("AHPSortReferencences").getChildren(); + for(WNode refPoint : refPoints) { + String cName = refPoint.getAttribute("criterion"); + Criterion c = (Criterion) problemService.getByName(Criterion.Type, cName); + + ArrayList points = new ArrayList<>(); + for(WNode point : refPoint.getChildren()) { + double min = DoubleHelper.ParseDouble(point.getAttribute("value")); + points.add(min); + } + + referenceService.addOrUpdate(c, points.toArray(new Double[0])); + + LinkedList pointsPE = referenceService.get(c); + for(AHPSortReferencencePoint pointPE: pointsPE) + problemService.add(pointPE); + } + + } + + @Override + public String getPhase() { + return "flintstones.resolutionphase.gathering.ahp"; + } + + @Override + public String getPart() { + return "references"; + } + + @Override + public void write() throws XMLStreamException { + + ProblemElement[] criterions = problemService.getAll(Criterion.Type); + writer.writeStartElement("AHPSortReferencences"); + + for (ProblemElement c : criterions) { + LinkedList points = referenceService.get((Criterion) c); + if (points.size() > 0) { + writer.writeStartElement("AHPSortReferencencePoints"); + writer.writeAttribute("criterion", c.getName()); + for (AHPSortReferencencePoint point : points) { + writer.writeStartElement("ReferencePoint"); + writer.writeAttribute("value", point.getValue() + ""); + writer.writeEndElement(); + } + writer.writeEndElement(); + } + } + + writer.writeEndElement(); + + }; + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOSortingClass40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOSortingClass40.java new file mode 100644 index 0000000..2ed3063 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOSortingClass40.java @@ -0,0 +1,68 @@ +package flintstones.helper.data.io.modules; + +import java.util.Arrays; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; + +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.model.problemelement.service.IProblemElementService; + +public class IOSortingClass40 extends BaseIO { + + @Inject + IProblemElementService problemService; + + public IOSortingClass40() { + } + + @Override + public void beforeRead() { + // TODO Auto-generated method stub + + } + + + @Override + public void write() throws XMLStreamException { + + SortingClass[] classes = Arrays.stream( problemService.getAll(SortingClass.Type)).map(k -> (SortingClass)k).toArray(SortingClass[]::new); + for (SortingClass classItem : classes) { + writer.writeStartElement("SortingClass"); + writer.writeAttribute(SortingClass.Fields.name.toString(), classItem.getName()); + writer.writeEndElement(); + } + + }; + + + @Override + public void read(WNode node) { + + if(node == null) + return ; + + WNode[] nodes = node.getChildren().toArray(new WNode[0]); + for (WNode wnode : nodes) { + String name = wnode.getAttribute(SortingClass.Fields.name); + SortingClass ahpClass = new SortingClass(name); + problemService.add(ahpClass); + } + + } + + + + @Override + public String getPhase() { + return "flintstones.resolutionphase.framework.problemelements.sorting"; + } + + @Override + public String getPart() { + return "sorting"; + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOValuation30.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOValuation30.java new file mode 100644 index 0000000..285036f --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOValuation30.java @@ -0,0 +1,129 @@ +package flintstones.helper.data.io.modules; + +import java.util.List; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamWriter; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.problemelement.ProblemElementKey; +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.helper.data.io.interfaces.BaseIO30; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.debug.DH; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class IOValuation30. + */ +public class IOValuation30 extends BaseIO30 { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO valuation 30. + */ + public IOValuation30() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + List nodes = node.getChildren(); + this.expected = nodes.size(); + + for (WNode item : nodes) { + + String expertCanonicalName = item.getAttribute("expert"); //$NON-NLS-1$ + String alternativeCanonicalName = item.getAttribute("alternative"); //$NON-NLS-1$ + String criterionCanonicalName = item.getAttribute("criterion"); //$NON-NLS-1$ + + Expert expert = (Expert) this.problemService.getByCanonicalName(Expert.Type, expertCanonicalName); + Alternative alternative = (Alternative) this.problemService.getByCanonicalName(Alternative.Type, alternativeCanonicalName); + Criterion criterion = (Criterion) this.problemService.getByCanonicalName(Criterion.Type, criterionCanonicalName); + + if (expert == null) { + DH.out("!ERRORFS El experto " + expertCanonicalName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$ + this.failed++; + continue; + } + + if (alternative == null) { + DH.out("!ERRORFS La alternativa " + alternativeCanonicalName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$ + this.failed++; + continue; + } + + if (criterion == null) { + DH.out("!ERRORFS El criterio " + criterionCanonicalName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$ + this.failed++; + continue; + } + + ProblemElementKey pek = new ProblemElementKey(expert, alternative, criterion); + Valuation valuation = this.valuationService.getValuationFor(pek); + valuation.read(item); + valuation.setEvaluated(true); + this.valuationService.addOrUpdate(pek, valuation); + this.valid++; + + } + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.gathering"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "valuations"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see + * flintstones.helper.data.io.BaseIO#setWriter(javax.xml.stream.XMLStreamWriter) */ + @Override + public void setWriter(XMLStreamWriter writer) { + } + +} diff --git a/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOValuation40.java b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOValuation40.java new file mode 100644 index 0000000..b948479 --- /dev/null +++ b/bundles/flintstones.helper.data.io/src/flintstones/helper/data/io/modules/IOValuation40.java @@ -0,0 +1,156 @@ +package flintstones.helper.data.io.modules; + +import java.util.List; +import java.util.Map.Entry; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; + +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.problemelement.ProblemElementKey; +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.helper.data.io.interfaces.BaseIO; +import flintstones.helper.data.wxml.WNode; +import flintstones.helper.debug.DH; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * The Class IOValuation40. + */ +public class IOValuation40 extends BaseIO { + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The broker. */ + @Inject + IEventBroker broker; + + /** + * Instantiates a new IO valuation 40. + */ + public IOValuation40() { + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#read(flintstones.helper.wxml.WNode) */ + @Override + public void read(WNode node) { + + List nodes = node.getChildren(); + this.expected = nodes.size(); + + for (WNode item : nodes) { + + String expertName = item.getAttribute(Expert.Fields.Expert.toString()); + String alternativeName = item.getAttribute(Alternative.Fields.Alternative.toString()); + String criterionName = item.getAttribute(Criterion.Fields.Criterion.toString()); + + Expert expert = (Expert) this.problemService.getByName(Expert.Fields.Expert.toString(), expertName); + Alternative alternative = (Alternative) this.problemService.getByName(Alternative.Fields.Alternative.toString(), alternativeName); + Criterion criterion = (Criterion) this.problemService.getByName(Criterion.Fields.Criterion.toString(), criterionName); + + if (expert == null) { + DH.out("!ERRORFS El experto " + expertName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$ + this.failed++; + continue; + } + + if (alternative == null) { + DH.out("!ERRORFS La alternativa " + alternativeName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$ + this.failed++; + continue; + } + + if (criterion == null) { + DH.out("!ERRORFS El criterio " + criterionName + " no se ha encontrado. Valuation ignorada."); //$NON-NLS-1$ //$NON-NLS-2$ + this.failed++; + continue; + } + + ProblemElementKey pek = new ProblemElementKey(expert, alternative, criterion); + Valuation valuation = this.valuationService.getValuationFor(pek); + valuation.read(item); + valuation.setEvaluated(true); + this.valuationService.addOrUpdate(pek, valuation); + this.valid++; + + } + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#write() */ + @Override + public void write() throws XMLStreamException { + + for (Entry entry : this.valuationService.getAllKV() + .entrySet()) + this.writeValuation(entry.getKey(), entry.getValue()); + } + + private void writeValuation(ProblemElementKey pek, Valuation v) throws XMLStreamException { + if (!v.isEvaluated()) + return; + + this.writer.writeStartElement(Valuation.Fields.Valuation.toString()); + this.writer.writeAttribute(Valuation.Fields.type.toString(), v.getClass() + .getName()); + this.writer.writeAttribute(Valuation.Fields.domain.toString(), v.getDomain() + .getName()); + + this.writer.writeAttribute(Alternative.Fields.Alternative.toString(), pek.getAlternative() + .getName()); + this.writer.writeAttribute(Criterion.Fields.Criterion.toString(), pek.getCriterion() + .getName()); + this.writer.writeAttribute(Expert.Fields.Expert.toString(), pek.getExpert() + .getName()); + + v.write(this.writer); + + this.writer.writeEndElement(); + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#beforeRead() */ + @Override + public void beforeRead() { + + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPhase() */ + @Override + public String getPhase() { + return "flintstones.resolutionphase.gathering"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * + * @see flintstones.helper.data.io.BaseIO#getPart() */ + @Override + public String getPart() { + return "valuations"; //$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.helper.data.wxml/.classpath b/bundles/flintstones.helper.data.wxml/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.data.wxml/.polyglot.META-INF b/bundles/flintstones.helper.data.wxml/.polyglot.META-INF new file mode 100644 index 0000000..472ba0e --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.data.wxml + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Wxml + diff --git a/bundles/flintstones.helper.data.wxml/.project b/bundles/flintstones.helper.data.wxml/.project new file mode 100644 index 0000000..efe0c3a --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.data.wxml + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362608 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.data.wxml/META-INF/MANIFEST.MF b/bundles/flintstones.helper.data.wxml/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b628737 --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Wxml +Bundle-SymbolicName: flintstones.helper.data.wxml +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.data.wxml +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.helper.data.wxml, + flintstones.helper.data.wxml.exception +Require-Bundle: flintstones.entity.extensionenum;visibility:=reexport diff --git a/bundles/flintstones.helper.data.wxml/build.properties b/bundles/flintstones.helper.data.wxml/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.data.wxml/src/flintstones/helper/data/wxml/WNode.java b/bundles/flintstones.helper.data.wxml/src/flintstones/helper/data/wxml/WNode.java new file mode 100644 index 0000000..f5e58a5 --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/src/flintstones/helper/data/wxml/WNode.java @@ -0,0 +1,290 @@ +package flintstones.helper.data.wxml; + +import java.text.MessageFormat; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.data.wxml.exception.WNodeNotFound; + +/** + * Wrapper Node + * A Wrapper for w3c.Element and w3c.Node + */ +public class WNode { + + /** The node. */ + private Element node; + + /** The version. */ + private String version; + + /** + * Instantiates a new wnode. + * + * @param enode the enode + */ + public WNode(Element enode) { + this.node = enode; + } + + /** + * Instantiates a new wnode. + * + * @param nnode the nnode + */ + public WNode(Node nnode) { + if (nnode instanceof Element) + this.node = (Element) nnode; + else + throw new Error("Clase incorrecta"); //$NON-NLS-1$ + } + + /** + * Gets the children for the given node. + * + * @return the children + */ + public List getChildren() { + Stream stream = IntStream.range(0, this.node.getChildNodes() + .getLength()) + .mapToObj(this.node.getChildNodes()::item); + return stream.filter(x -> x instanceof Element) + .map(y -> this.withVersion(new WNode(y))) + .collect(Collectors.toList()); + } + + /* (non-Javadoc) + * + * @see java.lang.Object#toString() */ + @Override + public String toString() { + String template = "[{0}] {1}, {2}"; //$NON-NLS-1$ + String line = MessageFormat.format(template, this.version, this.node.getNodeName(), this.node.hasAttribute("id") ? this.node.getAttribute("id") : "") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + .toString(); + return line; + } + + /** + * Gets the attribute as int. + * + * @param key the key + * @return the attribute int + */ + public int getAttributeInt(ExtensionEnum key) { + return Integer.valueOf(this.getAttribute(key) + .replace(".0", "")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * Gets the attribute as int. + * + * @param key the key + * @return the attribute int + */ + public int getAttributeInt(String key) { + return Integer.valueOf(this.getAttribute(key)); + } + + /** + * Gets the attribute as int. + * + * @param key the key + * @return the attribute int + */ + public boolean getAttributeBoolean(ExtensionEnum key) { + return getAttributeBoolean(key.toString()); + } + + /** + * Gets the attribute as int. + * + * @param key the key + * @return the attribute int + */ + public boolean getAttributeBoolean(String key) { + return this.getAttribute(key).equals("true"); + + } + + /** + * Gets the attribute as string. + * + * @param key the key + * @return the attribute + */ + public String getAttribute(ExtensionEnum key) { + return this.getAttribute(key.toString()); + } + + /** + * Gets the attribute as string. + * + * @param key the key + * @return the attribute + */ + public String getAttribute(String key) { + return this.node.getAttribute(key) != "" ? this.node.getAttribute(key) : null; //$NON-NLS-1$ + } + + /** + * Gets the name of the node. + * + * @return the name + */ + public String getName() { + return this.node.getNodeName(); + } + + /** + * Checks for a given attribute. + * + * @param key the key + * @return true, if successful + */ + public boolean hasAttribute(String key) { + return this.node.hasAttribute(key); + } + + /** + * Checks for child. + * + * @return true, if successful + */ + public boolean hasChild() { + return this.node.hasChildNodes(); + } + + /** + * Gets the first child with the given name or null. + * + * @param nodeName the nodeName + * @return the first + */ + public WNode getFirst(ExtensionEnum nodeName) { + WNode item = this.getFirst(nodeName.toString()); + return this.withVersion(item); + } + + /** + * Gets the first child with the given name or null. + * + * @param nodeName the node name + * @return the first + */ + public WNode getFirst(String nodeName) { + + for (int i = 0; i < this.node.getChildNodes() + .getLength(); i++) + if (this.node.getChildNodes() + .item(i) instanceof Element) { + WNode item = new WNode(this.node.getChildNodes() + .item(i)); + + if (item.getName() + .equals(nodeName)) + return this.withVersion(item); + + } + return null; + } + + /** + * Gets the first child with the given name that has the given value. + * + * @param attributeKey the attribute key + * @param attributeValue the attribute value + * @return the first + * @throws WNodeNotFound + */ + public WNode getFirst(String attributeKey, String attributeValue) throws WNodeNotFound { + + for (int i = 0; i < this.node.getChildNodes() + .getLength(); i++) + if (this.node.getChildNodes() + .item(i) instanceof Element) { + + WNode item = new WNode(this.node.getChildNodes() + .item(i)); + + if (!item.hasAttribute(attributeKey)) + continue; + + if (item.getAttribute(attributeKey) + .equals(attributeValue)) + return this.withVersion(item); + + } + + throw new WNodeNotFound(attributeKey, attributeValue); + } + + /** + * Gets the first child with the given attribute. + * + * @param attributeKey the attribute key + * @return the first by attribute + */ + public WNode getFirstByAttribute(ExtensionEnum attributeKey) { + return this.getFirstByAttribute(attributeKey.toString()); + } + + /** + * Gets the first child with the given attribute. + * + * @param attributeKey the attribute key + * @return the first by attribute + */ + public WNode getFirstByAttribute(String attributeKey) { + for (int i = 0; i < this.node.getChildNodes() + .getLength(); i++) + if (this.node.getChildNodes() + .item(i) instanceof Element) { + + WNode item = new WNode(this.node.getChildNodes() + .item(i)); + + if (item.hasAttribute(attributeKey)) + return this.withVersion(item); + } + + throw new Error("No encontrado el elemento con atributo" + attributeKey);//$NON-NLS-1$ + + } + + /** + * Spread the wnode version attribute across child nodes. + * + * @param node the node + * @return the w node + */ + private WNode withVersion(WNode node) { + if (node != null) + node.setVersion(this.getVersion()); + return node; + } + + /** + * Gets the version attribute. + * + * @return the version + */ + public String getVersion() { + return this.version; + } + + /** + * Sets the version attribute. + * + * @param version the new version + */ + public void setVersion(String version) { + this.version = version; + } + +} diff --git a/bundles/flintstones.helper.data.wxml/src/flintstones/helper/data/wxml/exception/WNodeNotFound.java b/bundles/flintstones.helper.data.wxml/src/flintstones/helper/data/wxml/exception/WNodeNotFound.java new file mode 100644 index 0000000..91592d0 --- /dev/null +++ b/bundles/flintstones.helper.data.wxml/src/flintstones/helper/data/wxml/exception/WNodeNotFound.java @@ -0,0 +1,21 @@ +package flintstones.helper.data.wxml.exception; + +/** + * The Class WNodeNotFound. + */ +public class WNodeNotFound extends Exception { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 1L; + + /** + * Instantiates a new w node not found. + * + * @param key the key + * @param value the value + */ + public WNodeNotFound(String key, String value) { + super("No se encuentra el elemento " + key + " => " + value); + } + +} diff --git a/bundles/flintstones.helper.data/.classpath b/bundles/flintstones.helper.data/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.helper.data/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.data/.polyglot.META-INF b/bundles/flintstones.helper.data/.polyglot.META-INF new file mode 100644 index 0000000..8974537 --- /dev/null +++ b/bundles/flintstones.helper.data/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.data + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Data + diff --git a/bundles/flintstones.helper.data/.project b/bundles/flintstones.helper.data/.project new file mode 100644 index 0000000..4cefb44 --- /dev/null +++ b/bundles/flintstones.helper.data/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.data + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362605 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.data/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.data/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.data/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.data/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.data/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.data/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.data/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.data/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.data/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.data/META-INF/MANIFEST.MF b/bundles/flintstones.helper.data/META-INF/MANIFEST.MF new file mode 100644 index 0000000..99e0441 --- /dev/null +++ b/bundles/flintstones.helper.data/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Data +Bundle-SymbolicName: flintstones.helper.data +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.data +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.helper, + flintstones.helper.data, + flintstones.helper.data.adapter, + flintstones.helper.data.text +Require-Bundle: flintstones.helper.extensionpoint, + flintstones.helper.debug, + org.eclipse.osgi, + org.eclipse.equinox.registry, + org.eclipse.swt, + org.apache.commons.math3, + org.apache.commons.lang diff --git a/bundles/flintstones.helper.data/build.properties b/bundles/flintstones.helper.data/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.data/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/DoubleHelper.java b/bundles/flintstones.helper.data/src/flintstones/helper/DoubleHelper.java new file mode 100644 index 0000000..0759791 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/DoubleHelper.java @@ -0,0 +1,332 @@ +package flintstones.helper; + +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.ArrayList; +import java.util.Arrays; +import org.apache.commons.lang.ArrayUtils; + +/** + * The Class DoubleHelper. + */ +public class DoubleHelper { + + /** The Constant NUMBER_OF_DECIMALS. */ + private final static int NUMBER_OF_DECIMALS = 3; + + public static String Draw(double val, int decimalPlaces, boolean zeroesAfterComma) { + + String pattern = "0."; + String placeholder = zeroesAfterComma ? "0" : "#"; + for (int i = 0; i < decimalPlaces; i++) + pattern += placeholder; + + DecimalFormatSymbols decimalSymbol = new DecimalFormatSymbols(); + decimalSymbol.setDecimalSeparator(','); + + DecimalFormat df = new DecimalFormat(pattern, decimalSymbol); + String formatted = df.format(val); + return formatted; + + } + + public static String Draw(Double val, int decimalPlaces) { + return Draw(val, decimalPlaces, true); + } + + /** + * Draw. + * + * @param val the value + * @return the string ready to be drawn in the UI. + */ + public static String Draw(Double val) { + return Draw(val, NUMBER_OF_DECIMALS); + } + + /** + * Parses a string fraction into a double. + * + * @param fraction the fraction + * @return the double + */ + public static Double ParseFraction(String fraction) { + if (fraction.contains("/")) { + String[] rat = fraction.split("/"); + return Double.parseDouble(rat[0]) / Double.parseDouble(rat[1]); + } + return Double.parseDouble(fraction); + } + + /** + * Parses the double that uses a comma. + * + * @param numberString the number string + * @return the double + */ + public static Double ParseDouble(String numberString) { + + if (numberString.equals("") || numberString.equals("-")) + return 0.0; + + String number = numberString.replace(",", "."); + return Double.parseDouble(number); + } + + /** + * Normalize. + * + * @param arr the arr + * @return the array normalized as double[] + */ + public static double[] Normalize(double[] arr) { + double sum = 0.0; + double result[] = new double[arr.length]; + + for (double x : arr) + sum += x; + + for (int i = 0; i < arr.length; i++) + result[i] = arr[i] / sum; + + return result; + + } + + /** + * Round the value. + * + * @param value the value + * @param places the places + * @return the double + */ + public static double Round(double value, int places) { + double scale = Math.pow(10, places); + return Math.round(value * scale) / scale; + } + + /** + * Find the max item and return it index. + * + * @param arr the arr + * @return the int + */ + public static int FindMaxIndex(double[] arr) { + int maxIndex = -1; + double max = Double.MIN_VALUE; + + for (int i = 0; i < arr.length; i++) { + + double val = arr[i]; + if (val > max) { + max = val; + maxIndex = i; + + } + } + return maxIndex; + + } + + public static int[] FindMaxIndexes(double[] arr) { + + ArrayList maxIndexes = new ArrayList<>(); + + double max = Double.MIN_VALUE; + + for (int i = 0; i < arr.length; i++) { + + double val = arr[i]; + if (val > max) { + + max = val; + + maxIndexes.clear(); + maxIndexes.add(i); + + } else if( val == max ) { + maxIndexes.add(i); + } + } + return ArrayUtils.toPrimitive(maxIndexes.toArray(new Integer[0])); + + } + + /** + * Find the max item and return it index. + * + * @param arr the arr + * @return the int + */ + public static int FindMinIndex(double[] arr) { + int minIndex = -1; + double min = Double.MAX_VALUE; + + for (int i = 0; i < arr.length; i++) { + + double val = arr[i]; + if (val < min) { + min = val; + minIndex = i; + + } + } + return minIndex; + + } + + public static int[] FindMinIndexes(double[] arr) { + + ArrayList minIndexes = new ArrayList<>(); + + double min = Double.MAX_VALUE; + + for (int i = 0; i < arr.length; i++) { + + double val = arr[i]; + if (val < min) { + min = val; + + minIndexes.clear(); + minIndexes.add(i); + + } else if( val == min) { + minIndexes.add(i); + } + } + return ArrayUtils.toPrimitive(minIndexes.toArray(new Integer[0])); + + } + + /** + * Check if a value can be double. + * + * @param str the str + * @return true, if successful + */ + public static boolean IsDouble(String str) { + try { + Double.valueOf(str); + } catch (NumberFormatException e) { + return false; + } + return true; + } + + public static double NormalizeZeroToOne(String singleValue) { + double value = DoubleHelper.ParseDouble(singleValue); + if (value > 1.0) { + int length = singleValue.length(); + double div = Math.pow(10, length); + value = (value / div); + } + return value; + } + + public static double[] ToRange(double min, double max, int parts, boolean addLast) { + + double total = max - min; + + double partSize = total / parts; + int partNumber = addLast ? parts + 1 : parts; + double[] values = new double[partNumber]; + + double sum = partSize; + double start = min; + + for (int i = 0; i < partNumber; i++) + values[i] = Math.round((start + (sum * i)) * 100d) / 100d; + + return values; + } + + public static Double[] GetCentralPoints(Double[] data) { + + Double centrals[] = new Double[data.length-1]; + for(int i = 0; i < data.length-1; i++) { + double low = data[i]; + double up = data[i+1]; + + double cen = (up+low)/2; + centrals[i] = cen; + } + + return centrals; + } + + + public static boolean IsAscending(double[] data) { + int len = data.length; + for (int i = 0; i < len - 1; i++) { + if (data[i] > data[i + 1]) + return false; + } + return true; + } + + public static boolean IsDescending(double[] data) { + int len = data.length; + for (int i = 0; i < len - 1; i++) { + if (data[i] < data[i + 1]) + return false; + } + return true; + } + + public static boolean IsSorted(double[] data) { + return IsAscending(data) || IsDescending(data); + } + + public static double[] Convert(String[] data) { + double[] arr = new double[data.length]; + for(int i = 0; i < data.length; i++) { + arr[i] = ParseDouble( data[i] ); + } + return arr; + } + + public static double[] Add(double[] arr, double element) { + arr = Arrays.copyOf(arr, arr.length+1); + arr[arr.length-1] = element; + return arr; + } + + public static Double[] Add(Double[] arr, double element) { + arr = Arrays.copyOf(arr, arr.length+1); + arr[arr.length-1] = element; + return arr; + } + + public static int FindInAscendingRange(double[] arr, double val) { + for(int i = 0; i< arr.length;i++) { + double current = arr[i]; + if(val < current) + return i-1; + if(val == current) + return i; + } + return arr.length-1; + } + + public static int FindInDescendingRange(double[] arr, double val) { + for(int i = 0; i< arr.length;i++) { + double current = arr[i]; + if(val >= current) + return i; + } + return arr.length-1; + } + + public static boolean Equals(double first, double second, int decPrecision) { + + double pAdd = 1.0/Math.pow(10, decPrecision); // 0.1, 0.01, 0.001... + double max = first + pAdd; + double min = first - pAdd; + + if(max > second && min < second) + return true; + return false; + + } + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/EigenHelper.java b/bundles/flintstones.helper.data/src/flintstones/helper/EigenHelper.java new file mode 100644 index 0000000..1899e6e --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/EigenHelper.java @@ -0,0 +1,102 @@ +package flintstones.helper; + +import flintstones.helper.debug.DH; +import org.apache.commons.math3.linear.EigenDecomposition; +import org.apache.commons.math3.linear.MatrixUtils; +import org.apache.commons.math3.linear.RealMatrix; +import org.apache.commons.math3.linear.RealVector; + +/** + * The Class EigenHelper can be used to call the EigenDecomposition and Normalization. + */ +public class EigenHelper { + + /** + * Instantiates a new eigen helper. + */ + public EigenHelper() { + + + } + + /** + * Gets the eigen vector. + * + * @param values the values + * @return the double[] + */ + private static double[] GetEigenVector(double[][] values) { + + // Matrix to library + RealMatrix realMatrix = MatrixUtils.createRealMatrix(values); + + // Get Max eigenvalue + EigenDecomposition descomposition = new EigenDecomposition(realMatrix); + int pos = DoubleHelper.FindMaxIndex(descomposition.getRealEigenvalues()); + + // Get its vector + RealVector eigenVector = descomposition.getEigenvector(pos); + + return eigenVector.toArray(); + } + + /** + * Gets the normalized eigen vector. + * + * @param values the values + * @return the double[] + */ + public static double[] GetNormalizedEigenVector(double[][] values) { + + double[] result = GetEigenVector(values); + + // Normalize + return DoubleHelper.Normalize(result); + } + + /** + * Show 2 x 2 matrix into console. + */ + public static void Show2x2Matrix() { + double[][] values = new double[2][2]; + values[0][0] = 1; + values[0][1] = 1; + values[1][0] = 1; + values[1][1] = 1; + + for(int i = 1; i < 10; i++) { + + values[0][1] = i; + values[1][0] = (double)1/i; + + + double[] result = EigenHelper.GetNormalizedEigenVector(values); + DH.out("(" + i + ", " + "1/" + i + ") " + " ==> " + DoubleHelper.Draw(result[0]) + ", " + DoubleHelper.Draw(result[1])); + + } + + } + + + public static void Show2x2MatrixNotNormalize() { + double[][] values = new double[2][2]; + values[0][0] = 1; + values[0][1] = 1; + values[1][0] = 1; + values[1][1] = 1; + + for(int i = 1; i < 10; i++) { + + values[0][1] = i; + values[1][0] = (double)1/i; + + + double[] result = EigenHelper.GetEigenVector(values); + DH.out("(" + i + ", " + "1/" + i + ") " + " ==> " + DoubleHelper.Draw(result[0]) + ", " + DoubleHelper.Draw(result[1])); + + } + + } + + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/FileHelper.java b/bundles/flintstones.helper.data/src/flintstones/helper/FileHelper.java new file mode 100644 index 0000000..e9900e8 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/FileHelper.java @@ -0,0 +1,100 @@ +package flintstones.helper; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; + +/** + * The Class FileHelper solves common problem on file loading into a helper. + */ +public class FileHelper { + + /** + * Read file. + * + * @param path the path + * @param encoding the encoding + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + static String readFile(String path, Charset encoding) throws IOException { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } + + /** + * Read file. + * + * @param path the path + * @return the string + * @throws IOException Signals that an I/O exception has occurred. + */ + public static String readFile(String path) throws IOException { + return readFile(path, StandardCharsets.UTF_8); + } + + /** + * Read file. + * + * @param fileURL the file URL + * @return the string + */ + public static String readFile(URL fileURL) { + StringBuilder sb = new StringBuilder(); + + try { + String inputLine; + BufferedReader in = new BufferedReader(new InputStreamReader(fileURL.openStream(), "UTF-8")); + + while ((inputLine = in.readLine()) != null) { + sb.append(inputLine); + sb.append('\n'); + } + + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + return sb.toString(); + + } + + /** + * Read file. + * + * @param fileName the file name + * @param bundle the bundle + * @return the string + */ + public static String readFile(String fileName, Bundle bundle) { + URL fileURL = bundle.getEntry(fileName); + return readFile(fileURL); + } + + public static URL getFileURL(Class classFromBundle, String path) { + Bundle b = FrameworkUtil.getBundle(classFromBundle); + + return b.getEntry(path); + } + + public static String encode(String uri) { + try { + return URLEncoder.encode(uri,"UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return uri; + } + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/MapHelper.java b/bundles/flintstones.helper.data/src/flintstones/helper/MapHelper.java new file mode 100644 index 0000000..f26bf00 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/MapHelper.java @@ -0,0 +1,67 @@ +package flintstones.helper; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import flintstones.helper.data.HashMatrix; + +/** + * The Class MapHelper. + */ +public class MapHelper { + + /** + * Sort by value a map. + * + * @param the key type + * @param the value type + * @param map the map + * @return the map + */ + // https://stackoverflow.com/questions/109383/sort-a-mapkey-value-by-values + public static > Map sortByValue(Map map, boolean descending) { + List> list = new ArrayList<>(map.entrySet()); + list.sort(Entry.comparingByValue()); + if(descending) + Collections.reverse(list); + + Map result = new LinkedHashMap<>(); + for (Entry entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + + return result; + } + + + // Return a map, ordered in the order of the given array + public static LinkedHashMap sortByExample(Map map, K[] examples) { + + LinkedHashMap linked = new LinkedHashMap<>(); + for (K item : examples) + linked.put(item, map.get(item)); + + return linked; + } + + // Not working? + public static LinkedHashMap> sortByExample(HashMatrix map, + K1[] examples1, K2[] examples2) { + + LinkedHashMap> outer = new LinkedHashMap<>(); + for (K1 item1 : examples1) { + LinkedHashMap inner = new LinkedHashMap<>(); + for (K2 item2 : examples2) + inner.put(item2, map.get(item1, item2)); + outer.put(item1, inner); + } + return outer; + + } + + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/MatrixHelper.java b/bundles/flintstones.helper.data/src/flintstones/helper/MatrixHelper.java new file mode 100644 index 0000000..b0072b6 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/MatrixHelper.java @@ -0,0 +1,172 @@ +package flintstones.helper; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import flintstones.helper.data.HashMatrix; + +/** + * The Class MatrixHelper. + */ +public class MatrixHelper { + + /** + * Transpose a matrix. + * + * @param the generic type + * @param arrayList the array list + * @return the list + */ + public static List> transpose(ArrayList> arrayList) { + List> ret = new ArrayList>(); + final int N = arrayList.get(0).size(); + for (int i = 0; i < N; i++) { + List col = new ArrayList(); + for (List row : arrayList) { + col.add(row.get(i)); + } + ret.add(col); + } + return ret; + } + + /** + * Transpose a matrix. + * + * @param m the m + * @return the double[][] + */ + public static double[][] transpose(double[][] m) { + double[][] temp = new double[m[0].length][m.length]; + for (int i = 0; i < m.length; i++) + for (int j = 0; j < m[0].length; j++) + temp[j][i] = m[i][j]; + return temp; + } + + /** + * Transpose a matrix. + * + * @param m the m + * @return the string[][] + */ + public static String[][] transpose(String[][] m) { + String[][] temp = new String[m[0].length][m.length]; + for (int i = 0; i < m.length; i++) + for (int j = 0; j < m[0].length; j++) + temp[j][i] = m[i][j]; + return temp; + } + + /** + * Return a matrix as a formatted String + * + * @param m the m + * @return the string[][] + */ + public static String[][] asString(double[][] m) { + String[][] temp = new String[m.length][m[0].length]; + + for (int i = 0; i < m.length; i++) { + for (int j = 0; j < m[0].length; j++) { + temp[i][j] = DoubleHelper.Draw(m[i][j]); + } + } + + return temp; + } + + public static String[][] asString(int[][] m) { + String[][] temp = new String[m.length][m[0].length]; + + for (int i = 0; i < m.length; i++) { + for (int j = 0; j < m[0].length; j++) { + temp[i][j] = m[i][j]+""; + } + } + + return temp; + } + + public static HashMatrix toHashMatrix(String textMatrix, boolean hasHeaders) { + + String[] rows = textMatrix.split("\r\n"); + + // H Header + String[] hHeader = new String[0]; + if (hasHeaders) { + hHeader = rows[0].split("\t"); + rows = Arrays.copyOfRange(rows, 1, rows.length); + } + + // Calculate sizes + int nCols = rows[0].split("\t").length; + if (hasHeaders) + nCols--; + + // Fix horizontal header removing first element if it is not empty + if(nCols < hHeader.length) + hHeader = Arrays.copyOfRange(hHeader, 1, hHeader.length); + + + String[][] matrix = new String[rows.length][nCols]; + String[] vHeader = new String[rows.length]; + + for (int i = 0; i < rows.length; i++) { + String row = rows[i]; + String[] column = row.split("\t"); + int colLength = hasHeaders ? column.length -1 : column.length; + + for (int j = 0; j < colLength; j++) { + int jj = hasHeaders ? j+1 : j; + matrix[i][j] = column[jj]; + } + + if (hasHeaders) + vHeader[i] = column[0]; + + } + + vHeader = Arrays.stream(vHeader).map(k -> StringHelper.Draw(k)).toArray(String[]::new); + hHeader = Arrays.stream(hHeader).map(k -> StringHelper.Draw(k)).toArray(String[]::new); + + return new HashMatrix<>(matrix, vHeader, hHeader); + + } + + + + public static String[][] addHeaders(String[][] matrix, String[] hHeaders, String[] vHeaders){ + + int rowC = matrix.length; + int colC = matrix[0].length; + + if(rowC != vHeaders.length) + throw new RuntimeException("l1 != hHeaders"); + + if(colC != hHeaders.length) + throw new RuntimeException("l2 != vHeaders"); + + + String m[][] = new String[rowC+1][colC+1]; + + // add hHeader + m[0][colC] = " "; + for(int i = 0; i < colC; i++) { + m[0][i] = hHeaders[i]; + } + + for(int i = 0; i < rowC; i++) { + int row = i+1; + for(int j = 0; j < colC; j++) { + m[row][j] = matrix[i][j]; + } + m[row][colC] = vHeaders[i]; // Add last item to the row + } + + return m; + + } + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/StringHelper.java b/bundles/flintstones.helper.data/src/flintstones/helper/StringHelper.java new file mode 100644 index 0000000..ecda449 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/StringHelper.java @@ -0,0 +1,107 @@ +package flintstones.helper; + +import java.util.regex.Pattern; + +import org.apache.commons.lang.RandomStringUtils; + +public class StringHelper { + + public static String PrintTable(String[][] table) { + + // Find out what the maximum number of columns is in any row + int maxColumns = 0; + for (int i = 0; i < table.length; i++) { + maxColumns = Math.max(table[i].length, maxColumns); + } + + // Find the maximum length of a string in each column + int[] lengths = new int[maxColumns]; + for (int i = 0; i < table.length; i++) { + for (int j = 0; j < table[i].length; j++) { + lengths[j] = Math.max(table[i][j].length(), lengths[j]); + } + } + + // Generate a format string for each column + String[] formats = new String[lengths.length]; + for (int i = 0; i < lengths.length; i++) { + formats[i] = "%1$" + lengths[i] + "s" + + (i + 1 == lengths.length ? "\n" : " "); + } + + StringBuilder mod = new StringBuilder(); + // Print 'em out + for (int i = 0; i < table.length; i++) { + for (int j = 0; j < table[i].length; j++) { + mod.append(String.format(formats[j], table[i][j])); + } + } + return mod.toString(); + } + + public static String Draw(String text) { + + // Remove text between parentheses + text = text.replaceAll("\\(.*\\)", ""); + + // Trip + text = text.trim(); + + // Replace _ and - with space " " + text = text.replaceAll("_", " "); + text = text.replaceAll("-", " "); + text = text.replaceAll("’", " "); + text = text.replaceAll("'", " "); + text = text.replaceAll("\"", " "); + + // Remove double..+ spaces + text = text.replaceAll(" +", " "); + + return text; + + } + + public static int IndexOf(String[] arr, String text) { + for(int i = 0; i < arr.length; i++) + if(arr[i].equals(text)) + return i; + return -1; + } + + public static String Random(int lmax, int lmin) { + int result = (int) (Math.random() * (lmax - lmin)) + lmin; + return RandomStringUtils.randomAlphanumeric(result); + } + + public static String[] SplitSplit(String plainText) { + String[] elements = plainText.split("\r\n"); + if(elements.length == 1) + elements = plainText.split("\t"); + + for(int i = 0; i < elements.length; i++) + elements[i] = elements[i].replaceAll("\n","").replaceAll("\r","").replaceAll("\t",""); + + return elements; + + } + + public static String GetLastAfterSplit(String text, String separator) { + + String[] arr = text.split(Pattern.quote(separator)); + return arr[arr.length-1]; + + } + + public static String GetButLastAfterSplit(String text, String separator) { + + String[] arr = text.split(Pattern.quote(separator)); + String[] narr = new String[arr.length-1]; + for(int i = 0; i < arr.length-1; i++) { + narr[i] = arr[i]; + } + + return String.join(separator, narr); + + + } +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/Config.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/Config.java new file mode 100644 index 0000000..476418a --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/Config.java @@ -0,0 +1,36 @@ +package flintstones.helper.data; + +import java.util.HashMap; + +public class Config { + + private HashMap config = new HashMap<>(); + + public void set(String key, String val) { + config.put(key, val); + } + + public void set(String key, Boolean val) { + config.put(key, val); + } + + public String get(String key) { + return (String) config.get(key); + } + + public Boolean is(String key) { + return (Boolean) config.get(key); + } + + public Config defaultEnabled(String... ars) { + for(String key : ars) + set(key, true); + return this; + } + + public Config defaultDisabled(String... ars) { + for(String key : ars) + set(key, false); + return this; + } +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/HashMapList.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/HashMapList.java new file mode 100644 index 0000000..4ce74fd --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/HashMapList.java @@ -0,0 +1,126 @@ +package flintstones.helper.data; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.stream.IntStream; +import java.util.Map.Entry; + +import flintstones.helper.StringHelper; + +public class HashMapList implements Iterable>> { + + private HashMap> content = new HashMap>(); + + public HashMapList() { + } + + public void add(K key, V value) { + ArrayList arr = content.get(key); + if (arr == null) + arr = new ArrayList<>(); + + arr.add(value); + content.put(key, arr); + } + + public void put(K key, ArrayList values) { + content.put(key, values); + } + + public void put(K key, V[] values) { + ArrayList valuesL = new ArrayList(Arrays.asList(values)); + put(key, valuesL); + } + + public ArrayList get(K key) { + return content.get(key); + } + + public ArrayList getSafe(K key) { + ArrayList arr = content.get(key); + return arr == null ? new ArrayList() : arr; + } + + public HashMap> getMap() { + return content; + } + + public boolean contains(K key) { + return content.get(key) != null; + } + + public boolean contains(K key, V value) { + ArrayList arr = content.get(key); + if (arr == null) + return false; + + return arr.contains(value); + } + + public void clear() { + content.clear(); + } + + public int size() { + return content.size(); + } + + public int size(K key) { + ArrayList arr = content.get(key); + if (arr == null) + return 0; + return arr.size(); + } + + @Override + public Iterator>> iterator() { + return content.entrySet().iterator(); + } + + public Collection> values() { + return content.values(); + } + + public Set>> entrySet() { + return content.entrySet(); + } + + public Set keySet() { + return content.keySet(); + } + + + @Override + public String toString() { + String[] hHeaders = content.keySet().stream().map(k -> k.toString()).toArray(String[]::new); + int size = content.values().iterator().next().size(); + String[] vHeaders = IntStream.rangeClosed(1, size).mapToObj(k -> "_" + k + "_").toArray(String[]::new); + + String[][] matrix = new String[hHeaders.length+1][vHeaders.length+1]; + for(int i = 0; i < vHeaders.length; i++) { + matrix[0][i] = vHeaders[i]; + } + matrix[0][vHeaders.length] = ""; + + int i = 0; + for(Entry> entry : content.entrySet()) { + ArrayList innerList = entry.getValue(); + int j = 0; + for(V innerEntry : innerList) { + matrix[i+1][j] = innerEntry.toString(); + j++; + } + matrix[i+1][j] = hHeaders[i]; + i++; + } + + return StringHelper.PrintTable(matrix); + + } + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/HashMatrix.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/HashMatrix.java new file mode 100644 index 0000000..f1fb95d --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/HashMatrix.java @@ -0,0 +1,113 @@ +package flintstones.helper.data; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import flintstones.helper.StringHelper; + +public class HashMatrix implements Iterable>> { + + private HashMap> content = new HashMap<>(); + + public HashMatrix() { + }; + + public HashMatrix(V[][] matrix, K1[] verticalHeader, K2[] horizontalHeader) { + + for(int i = 0; i < verticalHeader.length; i++) { + K1 item1 = verticalHeader[i]; + for(int j = 0; j < horizontalHeader.length; j++) { + K2 item2 = horizontalHeader[j]; + V value = matrix[i][j]; + put(item1, item2, value); + } + } + } + + public void put(K1 key1, K2 key2, V value) { + + HashMap innerMap = content.get(key1); + if (innerMap == null) + innerMap = new HashMap<>(); + innerMap.put(key2, value); + content.put(key1, innerMap); + + } + + public V get(K1 key1, K2 key2) { + HashMap innerMap = content.get(key1); + if (innerMap == null) + return null; + return innerMap.get(key2); + } + + public HashMap get(K1 key1) { + HashMap innerMap = content.get(key1); + return innerMap; + } + + public int size() { + return content.size(); + } + + public int innerSize() { + return content.values().iterator().next().size(); + } + + public void clear() { + content.clear(); + } + + public HashMap> getMap() { + return content; + } + + @Override + public Iterator>> iterator() { + return content.entrySet().iterator(); + } + + public Collection> values() { + return content.values(); + } + + public Set>> entrySet() { + return content.entrySet(); + } + + public Set keySet() { + return content.keySet(); + } + + @Override + public String toString() { + String[] hHeaders = content.keySet().stream().map(k -> k.toString()).toArray(String[]::new); + String[] vHeaders = content.values().iterator().next().keySet().stream().map(k -> k.toString()) + .toArray(String[]::new); + + String[][] matrix = new String[hHeaders.length + 1][vHeaders.length + 1]; + for (int i = 0; i < vHeaders.length; i++) { + matrix[0][i] = vHeaders[i]; + } + matrix[0][vHeaders.length] = ""; + + int i = 0; + for (Entry> entry : content.entrySet()) { + HashMap innerMap = entry.getValue(); + int j = 0; + for (Entry innerEntry : innerMap.entrySet()) { + matrix[i + 1][j] = innerEntry.getValue().toString(); + j++; + } + matrix[i + 1][j] = hHeaders[i]; + i++; + } + + return StringHelper.PrintTable(matrix); + + } +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/LinkedHashMatrix.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/LinkedHashMatrix.java new file mode 100644 index 0000000..3cfca8c --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/LinkedHashMatrix.java @@ -0,0 +1,115 @@ +package flintstones.helper.data; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import flintstones.helper.StringHelper; + +public class LinkedHashMatrix implements Iterable>> { + + private LinkedHashMap> content = new LinkedHashMap<>(); + + public LinkedHashMatrix() { + }; + + public LinkedHashMatrix(V[][] matrix, K1[] verticalHeader, K2[] horizontalHeader) { + + for(int i = 0; i < verticalHeader.length; i++) { + K1 item1 = verticalHeader[i]; + for(int j = 0; j < horizontalHeader.length; j++) { + K2 item2 = horizontalHeader[j]; + V value = matrix[i][j]; + put(item1, item2, value); + } + } + + } + + public void put(K1 key1, K2 key2, V value) { + + LinkedHashMap innerMap = content.get(key1); + if (innerMap == null) + innerMap = new LinkedHashMap<>(); + innerMap.put(key2, value); + content.put(key1, innerMap); + + } + + public V get(K1 key1, K2 key2) { + LinkedHashMap innerMap = content.get(key1); + if (innerMap == null) + return null; + return innerMap.get(key2); + } + + public LinkedHashMap get(K1 key1) { + LinkedHashMap innerMap = content.get(key1); + return innerMap; + } + + public int size() { + return content.size(); + } + + public int innerSize() { + return content.values().iterator().next().size(); + } + + public void clear() { + content.clear(); + } + + public LinkedHashMap> getMap() { + return content; + } + + @Override + public Iterator>> iterator() { + return content.entrySet().iterator(); + } + + public Collection> values() { + return content.values(); + } + + public Set>> entrySet() { + return content.entrySet(); + } + + public Set keySet() { + return content.keySet(); + } + + @Override + public String toString() { + String[] hHeaders = content.keySet().stream().map(k -> k.toString()).toArray(String[]::new); + String[] vHeaders = content.values().iterator().next().keySet().stream().map(k -> k.toString()) + .toArray(String[]::new); + + String[][] matrix = new String[hHeaders.length + 1][vHeaders.length + 1]; + for (int i = 0; i < vHeaders.length; i++) { + matrix[0][i] = vHeaders[i]; + } + matrix[0][vHeaders.length] = ""; + + int i = 0; + for (Entry> entry : content.entrySet()) { + HashMap innerMap = entry.getValue(); + int j = 0; + for (Entry innerEntry : innerMap.entrySet()) { + matrix[i + 1][j] = innerEntry.getValue().toString(); + j++; + } + matrix[i + 1][j] = hHeaders[i]; + i++; + } + + return StringHelper.PrintTable(matrix); + + } +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/LinkedMapList.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/LinkedMapList.java new file mode 100644 index 0000000..93c27fb --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/LinkedMapList.java @@ -0,0 +1,126 @@ +package flintstones.helper.data; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Set; +import java.util.stream.IntStream; +import java.util.Map.Entry; + +import flintstones.helper.StringHelper; + +public class LinkedMapList implements Iterable>> { + + private LinkedHashMap> content = new LinkedHashMap>(); + + public LinkedMapList() { + } + + public void add(K key, V value) { + LinkedList arr = content.get(key); + if (arr == null) + arr = new LinkedList<>(); + + arr.add(value); + content.put(key, arr); + } + + public void put(K key, LinkedList values) { + content.put(key, values); + } + + public void put(K key, V[] values) { + LinkedList valuesL = new LinkedList(Arrays.asList(values)); + put(key, valuesL); + } + + public LinkedList get(K key) { + return content.get(key); + } + + public LinkedList getSafe(K key) { + LinkedList arr = content.get(key); + return arr == null ? new LinkedList() : arr; + } + + public LinkedHashMap> getMap() { + return content; + } + + public boolean contains(K key) { + return content.get(key) != null; + } + + public boolean contains(K key, V value) { + LinkedList arr = content.get(key); + if (arr == null) + return false; + + return arr.contains(value); + } + + public void clear() { + content.clear(); + } + + public int size() { + return content.size(); + } + + public int size(K key) { + LinkedList arr = content.get(key); + if (arr == null) + return 0; + return arr.size(); + } + + @Override + public Iterator>> iterator() { + return content.entrySet().iterator(); + } + + public Collection> values() { + return content.values(); + } + + public Set>> entrySet() { + return content.entrySet(); + } + + public Set keySet() { + return content.keySet(); + } + + + @Override + public String toString() { + String[] hHeaders = content.keySet().stream().map(k -> k.toString()).toArray(String[]::new); + int size = content.values().iterator().next().size(); + String[] vHeaders = IntStream.rangeClosed(1, size).mapToObj(k -> "_" + k + "_").toArray(String[]::new); + + String[][] matrix = new String[hHeaders.length+1][vHeaders.length+1]; + for(int i = 0; i < vHeaders.length; i++) { + matrix[0][i] = vHeaders[i]; + } + matrix[0][vHeaders.length] = ""; + + int i = 0; + for(Entry> entry : content.entrySet()) { + LinkedList innerList = entry.getValue(); + int j = 0; + for(V innerEntry : innerList) { + matrix[i+1][j] = innerEntry.toString(); + j++; + } + matrix[i+1][j] = hHeaders[i]; + i++; + } + + return StringHelper.PrintTable(matrix); + + } + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/Pair.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/Pair.java new file mode 100644 index 0000000..447afc7 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/Pair.java @@ -0,0 +1,127 @@ +package flintstones.helper.data; + +/** + * The Class Pair. + * + * @param the generic type + * @param the generic type + */ +public class Pair { + + /** The left. */ + private L _left; + + /** The right. */ + private R _right; + + /** + * Instantiates a new pair. + */ + public Pair() { + this._left = null; + this._right = null; + } + + /** + * Instantiates a new pair. + * + * @param left the left + * @param right the right + */ + public Pair(L left, R right) { + this._left = left; + this._right = right; + } + + /** + * Gets the left value. + * + * @return the left + */ + public L getLeft() { + return this._left; + } + + /** + * Gets the key. + * + * @return the key + */ + public L getKey() { + return getLeft(); + } + + /** + * Gets the right value. + * + * @return the right + */ + public R getRight() { + return this._right; + } + + /** + * Gets the value. + * + * @return the value + */ + public R getValue() { + return getRight(); + } + + /** + * Adds the. + * + * @param left the left + * @param right the right + */ + public void add(L left, R right) { + this._left = left; + this._right = right; + } + + /* (non-Javadoc) + * + * @see java.lang.Object#hashCode() */ + @Override + public int hashCode() { + return this._left.hashCode() ^ this._right.hashCode(); + } + + /* (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) */ + @Override + public boolean equals(Object o) { + + if (!(o instanceof Pair)) + return false; + Pair pairo = (Pair) o; + return this._left.equals(pairo.getLeft()) && this._right.equals(pairo.getRight()); + } + + /** + * Checks if is empty. + * + * @return true, if is empty + */ + public boolean isEmpty() { + return (this._left == null) && (this._right == null); + } + + /** + * Clear. + */ + public void clear() { + this._left = null; + this._right = null; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "[" + _left.toString() + ", " + _right.toString() + "]"; + } +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/PairList.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/PairList.java new file mode 100644 index 0000000..c5ea54d --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/PairList.java @@ -0,0 +1,106 @@ +package flintstones.helper.data; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; + +/** + * The Class PairList is a ArrayList>. It allows to replace and convert Maps<> to PairList<>. + * + * @param the generic type + * @param the generic type + */ +public class PairList implements Iterable< Pair > { + + private /** The data. */ + ArrayList< Pair > data = new ArrayList<>(); + + /** + * Instantiates a new pair list. + */ + public PairList() {} + + /** + * Instantiates a new pair list. + * + * @param map the map + */ + public PairList(HashMap map) { + for(Entry entry : map.entrySet()) + put(entry.getKey(), entry.getValue()); + } + + /** + * Put. + * + * @param key the key + * @param value the value + */ + public void put(L key, R value) { + data.add(new Pair(key,value)); + } + + /** + * Gets the. + * + * @param index the index + * @return the pair + */ + public Pair get(int index){ + return data.get(index); + } + + /** + * Gets the key. + * + * @param index the index + * @return the key + */ + public L getKey(int index) { + return get(index).getLeft(); + } + + /** + * Gets the value. + * + * @param index the index + * @return the value + */ + public R getValue(int index) { + return get(index).getRight(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for( Pair pair : data ) { + sb.append(pair.toString() + "\n"); + } + return sb.toString(); + } + + /* (non-Javadoc) + * @see java.lang.Iterable#iterator() + */ + @Override + public Iterator> iterator() { + return data.iterator(); + } + + /** + * Size. + * + * @return the int + */ + public int size() { + return data.size(); + } + + public ArrayList> getAll(){ + return data; + } +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/adapter/TableAdapter.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/adapter/TableAdapter.java new file mode 100644 index 0000000..e6a19a5 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/adapter/TableAdapter.java @@ -0,0 +1,162 @@ +package flintstones.helper.data.adapter; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map.Entry; +import java.util.Set; + +import flintstones.helper.DoubleHelper; +import flintstones.helper.StringHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.data.LinkedHashMatrix; + +public class TableAdapter { + + private String[] vHeader; + private String[] hHeader; + + private String[][] data; + + public TableAdapter() { + check(); + } + + public TableAdapter(HashMap items) { + + check(); + + int cols = items.size(); + hHeader = new String[cols]; + vHeader = new String[0]; + data = new String[1][cols]; + + Set itemList = items.keySet(); + + int i = 0; + for(Object item : itemList) { + hHeader[i] = asString(item); + data[0][i] = asString(items.get(item)); + i++; + } + + } + + + public TableAdapter(LinkedHashMatrix items) { + + check(); + + int cols = items.innerSize(); + int rows = items.size(); + + hHeader = new String[cols]; + vHeader = new String[rows]; + data = new String[rows][cols]; + + int i = 0; + for(Entry entry1 : items.entrySet()) { + Object k1 = entry1.getKey(); + Object v1 = entry1.getValue(); + vHeader[i] = asString(k1); + + int j = 0; + LinkedHashMap innerMap = (LinkedHashMap) v1; + for(Entry entry2 : innerMap.entrySet()) { + Object k2 = entry2.getKey(); + Object v2 = entry2.getValue(); + + hHeader[j] = asString(k2); // Se repite en todas las iteraciones, no deberia + data[i][j] = asString(v2); + j++; + } + + i++; + } + + } + + public TableAdapter(HashMatrix items) { + + check(); + + int cols = items.innerSize(); + int rows = items.size(); + + hHeader = new String[cols]; + vHeader = new String[rows]; + data = new String[rows][cols]; + + int i = 0; + for(Entry entry1 : items.entrySet()) { + Object k1 = entry1.getKey(); + Object v1 = entry1.getValue(); + vHeader[i] = asString(k1); + + int j = 0; + HashMap innerMap = (HashMap) v1; + for(Entry entry2 : innerMap.entrySet()) { + Object k2 = entry2.getKey(); + Object v2 = entry2.getValue(); + + hHeader[j] = asString(k2); // Se repite en todas las iteraciones, no deberia + data[i][j] = asString(v2); + j++; + } + + i++; + } + + } + + + + private String asString(Object item) { + + if(item instanceof Double) { + Double val = (Double) item; + return DoubleHelper.Draw(val); + } + + return StringHelper.Draw(item.toString()); + } + + private void check(){ + if(vHeader != null || hHeader != null || data != null) + throw new RuntimeException("No"); + } + + + + + + public void setVerticalHeaders(String[] headers) { + this.vHeader = headers; + } + + public String[] getVerticalHeaders() { + return vHeader; + } + + public void setHorizontalHeaders(String[] headers) { + this.hHeader = headers; + } + + public String[] getHorizontalHeaders() { + return hHeader; + } + + public void setData(String[][] d) { + data = d; + } + + public String[][] getData(){ + return data; + } + + public String[] getDataRow() { + if(data.length != 1) + throw new RuntimeException("No"); + return data[0]; + } + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/text/ClassAttributesToString.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/text/ClassAttributesToString.java new file mode 100644 index 0000000..84b8487 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/text/ClassAttributesToString.java @@ -0,0 +1,45 @@ +package flintstones.helper.data.text; + +import java.lang.reflect.Field; + +/** + * The Class ClassAttributesToString. + */ +public class ClassAttributesToString { + + /** + * To string. + * + * @param item the item + * @return the string + */ + public static String toString(Object item) { + StringBuilder result = new StringBuilder(); + String newLine = System.getProperty("line.separator"); + + result.append( item.getClass().getName() ); + result.append( " Object {" ); + result.append(newLine); + + //determine fields declared in this class only (no fields of superclass) + Field[] fields = item.getClass().getDeclaredFields(); + + //print field names paired with their values + for ( Field field : fields ) { + result.append(" "); + try { + result.append( field.getName() ); + result.append(": "); + //requires access to private field: + result.append( toString(field.get(item)) ); + } catch ( IllegalAccessException ex ) { + System.out.println(ex); + } + result.append(newLine); + } + result.append("}"); + + return result.toString(); + } + +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/text/ClassToString.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/text/ClassToString.java new file mode 100644 index 0000000..ce169a0 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/text/ClassToString.java @@ -0,0 +1,135 @@ +package flintstones.helper.data.text; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; + +import flintstones.helper.data.HashMapList; +import flintstones.helper.data.HashMatrix; + +/** + * The Class ClassToString. + * + * @author igmunoz + */ +/** + * @author igmunoz + * + */ +@SuppressWarnings("rawtypes") +public class ClassToString { + + /** + * Gets the class as string. + * + * @param item the item + * @return the class as string + */ + public static String getClassAsString(Object item) { + + String value = item.getClass().getSimpleName(); + String newValue = ""; + if( item instanceof HashMap ) { + newValue = getHashMapAsString((HashMap) item); + } else if( item instanceof ArrayList ) { + newValue = getArrayListAsString((ArrayList) item); + } else if( item instanceof LinkedList ) { + newValue = getLinkedListAsString((LinkedList) item); + } else if( item instanceof HashMatrix ) { + newValue = getHashMatrixAsString((HashMatrix) item); + } else if( item instanceof HashMapList ) { + newValue = getHashMapListAsString((HashMapList)item); + } + + if( newValue != "") + return newValue; + return value; + + } + + private static String getHashMapListAsString(HashMapList matrix) { + String value = "HashMapList"; + if( matrix.size() > 0 ){ + value = "HashMapList<"; + value += getClassAsString(matrix.getMap().keySet().toArray()[0]); + value += ","; + ArrayList innerArr = (ArrayList) matrix.getMap().values().toArray()[0]; + value += getClassAsString(innerArr.iterator().next()); + value += ">"; + + } + return value; + } + + private static String getHashMatrixAsString(HashMatrix matrix) { + String value = "HashMatrix"; + if( matrix.size() > 0 ){ + value = "HashMatrix<"; + value += getClassAsString(matrix.getMap().keySet().toArray()[0]); + value += ","; + HashMap innerMap = (HashMap) matrix.getMap().values().toArray()[0]; + value += getClassAsString(innerMap.keySet().toArray()[0]); + value += ","; + value += getClassAsString(innerMap.values().toArray()[0]); + value += ">"; + + } + return value; + } + + /** + * Gets the hash map as string. + * + * @param map the map + * @return the hash map as string + */ + private static String getHashMapAsString(HashMap map) { + + String value = "HashMap"; + if( map.size() > 0 ) { + value = "HashMap<"; + value += getClassAsString(map.keySet().toArray()[0]); + value += ","; + value += getClassAsString(map.values().toArray()[0]); + value += ">"; + } + return value; + + } + + /** + * Gets the array list as string. + * + * @param arr the arr + * @return the array list as string + */ + private static String getArrayListAsString(ArrayList arr) { + + String value = "ArrayList"; + if( arr.size() > 0) { + value = "ArrayList<"; + value += getClassAsString(arr.get(0)); + value += ">"; + } + return value; + + } + + /** + * Gets the linked list as string. + * + * @param list the list + * @return the linked list as string + */ + private static String getLinkedListAsString(LinkedList list) { + + String value = "LinkedList"; + if( list.size() > 0) { + value = "LinkedList<"; + value += getClassAsString(list.get(0)); + value += ">"; + } + return value; + + } +} diff --git a/bundles/flintstones.helper.data/src/flintstones/helper/data/text/DebugStream.java b/bundles/flintstones.helper.data/src/flintstones/helper/data/text/DebugStream.java new file mode 100644 index 0000000..cdf7fc5 --- /dev/null +++ b/bundles/flintstones.helper.data/src/flintstones/helper/data/text/DebugStream.java @@ -0,0 +1,41 @@ +package flintstones.helper.data.text; +// https://jeeeyul.wordpress.com/2012/10/18/make-system-out-println-rocks/ + +import java.io.PrintStream; +import java.text.MessageFormat; + +/** + * @author Jeeeyul 2011. 11. 1. 오후 4:36:51 + * @since M1.10 + */ +public class DebugStream extends PrintStream { + private static final DebugStream INSTANCE = new DebugStream(); + + public static void activate() { + System.setOut(INSTANCE); + System.setErr(INSTANCE); + } + + private DebugStream() { + super(System.out); + } + + @Override + public void println(Object x) { + showLocation(); + super.println(x); + } + + @Override + public void println(String x) { + showLocation(); + super.println(x); + } + + private void showLocation() { + StackTraceElement element = Thread.currentThread().getStackTrace()[3]; + if(element.getFileName().equals("DebugHelper.java")) + element = Thread.currentThread().getStackTrace()[4]; + super.print(MessageFormat.format("({0}:{1, number,#}) : ", element.getFileName(), element.getLineNumber())); + } +} \ No newline at end of file diff --git a/bundles/flintstones.helper.debug/.classpath b/bundles/flintstones.helper.debug/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.debug/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.debug/.polyglot.META-INF b/bundles/flintstones.helper.debug/.polyglot.META-INF new file mode 100644 index 0000000..daf59f0 --- /dev/null +++ b/bundles/flintstones.helper.debug/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.debug + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Debug + diff --git a/bundles/flintstones.helper.debug/.project b/bundles/flintstones.helper.debug/.project new file mode 100644 index 0000000..af91422 --- /dev/null +++ b/bundles/flintstones.helper.debug/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.debug + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362609 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.debug/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.debug/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.debug/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.debug/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.debug/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.debug/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.debug/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.debug/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.debug/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.debug/META-INF/MANIFEST.MF b/bundles/flintstones.helper.debug/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9b86787 --- /dev/null +++ b/bundles/flintstones.helper.debug/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Debug +Bundle-SymbolicName: flintstones.helper.debug +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.debug +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.helper.debug diff --git a/bundles/flintstones.helper.debug/build.properties b/bundles/flintstones.helper.debug/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.debug/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.debug/src/flintstones/helper/debug/DH.java b/bundles/flintstones.helper.debug/src/flintstones/helper/debug/DH.java new file mode 100644 index 0000000..d15a93c --- /dev/null +++ b/bundles/flintstones.helper.debug/src/flintstones/helper/debug/DH.java @@ -0,0 +1,6 @@ +package flintstones.helper.debug; + +public class DH extends DebugHelper { + + +} diff --git a/bundles/flintstones.helper.debug/src/flintstones/helper/debug/DebugHelper.java b/bundles/flintstones.helper.debug/src/flintstones/helper/debug/DebugHelper.java new file mode 100644 index 0000000..0dd5e54 --- /dev/null +++ b/bundles/flintstones.helper.debug/src/flintstones/helper/debug/DebugHelper.java @@ -0,0 +1,102 @@ +package flintstones.helper.debug; + +import java.util.Arrays; +import java.util.HashMap; + +class DebugHelper { + + static DebugHelper instance; + + private HashMap hiddenTypes = new HashMap<>(); + + protected DebugHelper() { + } + + // Modify output here + private static void _out(String text) { + System.out.println(text); + } + + private static void _l() { + System.out.println(); + } + + private static void _iout(int index, String text) { + _out(index + " -> " + text); + } + + public static void hide(String type) { + DebugHelper.getInstance().hiddenTypes.put(type, true); + } + + private static boolean isHidden(String type) { + Boolean val = DebugHelper.getInstance().hiddenTypes.get(type); + if (val == null) + return false; + return val; + } + + public static DebugHelper getInstance() { + if (instance == null) + instance = new DebugHelper(); + return instance; + } + + // APIS + + public static void out(String text) { + _out(text); + } + + public static void out(Object obj) { + String x = obj != null ? obj.toString() : "null"; + _out(x); + } + + public static void out(String type, String text) { + if (!isHidden(type)) + _out(text); + }; + + public static void l() { + _l(); + } + + public static void l(int lines) { + for (int i = 0; i < lines; i++) + _l(); + } + + public static void out(Object[] arr) { + _out(Arrays.toString(arr)); + } + + public static void out(double[] arr) { + _out(Arrays.toString(arr)); + } + + public static void out(int[] arr) { + _out(Arrays.toString(arr)); + } + + public static void out(float[] arr) { + _out(Arrays.toString(arr)); + } + + public static void out(int index, Object[] arr) { + _iout(index, Arrays.toString(arr)); + } + + public static void out(int index, double[] arr) { + _iout(index, Arrays.toString(arr)); + } + + public static void out(int index, int[] arr) { + _iout(index, Arrays.toString(arr)); + } + + public static void out(int index, float[] arr) { + _iout(index, Arrays.toString(arr)); + } + +} diff --git a/bundles/flintstones.helper.extensionpoint/.classpath b/bundles/flintstones.helper.extensionpoint/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.extensionpoint/.polyglot.META-INF b/bundles/flintstones.helper.extensionpoint/.polyglot.META-INF new file mode 100644 index 0000000..7d9cf50 --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.extensionpoint + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.helper.extensionpoint/.project b/bundles/flintstones.helper.extensionpoint/.project new file mode 100644 index 0000000..4569384 --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.extensionpoint + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362610 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.extensionpoint/META-INF/MANIFEST.MF b/bundles/flintstones.helper.extensionpoint/META-INF/MANIFEST.MF new file mode 100644 index 0000000..72ce7cc --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.helper.extensionpoint +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.di;visibility:=reexport, + org.eclipse.e4.core.contexts;visibility:=reexport, + org.eclipse.core.runtime;visibility:=reexport, + flintstones.entity.extensionenum;visibility:=reexport, + flintstones.helper.locale +Export-Package: flintstones.helper.extensionpoint +Automatic-Module-Name: flintstones.helper.extensionpoint diff --git a/bundles/flintstones.helper.extensionpoint/build.properties b/bundles/flintstones.helper.extensionpoint/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.extensionpoint/src/flintstones/helper/extensionpoint/BaseRegistry.java b/bundles/flintstones.helper.extensionpoint/src/flintstones/helper/extensionpoint/BaseRegistry.java new file mode 100644 index 0000000..963677c --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/src/flintstones/helper/extensionpoint/BaseRegistry.java @@ -0,0 +1,405 @@ +package flintstones.helper.extensionpoint; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.extensionenum.ExtensionEnum; + +/** + * The Class BaseRegistry. + */ +public class BaseRegistry { + + /** The registers. */ + private final ArrayList registers; + + /** The extension point. */ + private final String extensionPoint; + + /** The label id. */ + private String label_id = "uid"; //$NON-NLS-1$ + + /** The label implementation. */ + private String label_implementation = "implementation"; //$NON-NLS-1$ + + /** + * Instantiates a new domain service provider. + * @param extensionPoint The extensionPoint + */ + public BaseRegistry(String extensionPoint) { + this.extensionPoint = extensionPoint; + this.registers = new ArrayList<>(); + this.loadRegisters(); + } + + + /** + * Gets the registry id. + * + * @return the registry id + */ + public String getRegistryId() { + return this.extensionPoint; + } + + + /** + * Load registers. + */ + private void loadRegisters() { + IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); + IConfigurationElement[] extensionElements = extensionRegistry.getConfigurationElementsFor(this.extensionPoint); // Domain.EXTENSION_POINT + Arrays.stream(extensionElements) + .forEach(this::loadRegistry); + } + + /** + * Load registry. + * + * @param extensionElement the extension element + */ + private void loadRegistry(IConfigurationElement extensionElement) { + ExtensionRegistry registry = new ExtensionRegistry(extensionElement); + this.registers.add(registry); + } + + /** + * Gets the first registry where. + * + * @param key The key of the item you are looking for + * @param value The value of the key. + * @return The first ExtensionRegistry with the given key,value, null if the value does not exists for the given key. If the ke + */ + public ExtensionRegistry getFirstRegistryWhere(ExtensionEnum key, String value) { + return this.getFirstRegistryWhere(key.toString(), value); + } + + /** + * Gets the first registry where. + * + * @param key The key of the item you are looking for + * @param value The value of the key. + * @return The first ExtensionRegistry with the given key,value, null if the value does not exists for the given key. If the ke + */ + public ExtensionRegistry getFirstRegistryWhere(String key, String value) { + for (ExtensionRegistry er : this.registers) { + if (er.getAttribute(key) == null) + throw new InvalidKeyIdentifier(key,value); + if (er.getAttribute(key) + .equals(value)) + return er; + } + return null; + } + + /** + * Gets the all registries where. + * + * @param key The key of the item you are looking for + * @param value The value of the key. + * @return all the ExtensionRegistry with the given key + */ + public ExtensionRegistry[] getAllRegistriesWhere(ExtensionEnum key, String value) { + return this.getAllRegistriesWhere(key.toString(), value); + } + + /** + * Gets the all registries where. + * + * @param key The key of the item you are looking for + * @param value The value of the key. + * @return all the ExtensionRegistry with the given key + */ + public ExtensionRegistry[] getAllRegistriesWhere(String key, String value) { + ArrayList erl = new ArrayList<>(); + for (ExtensionRegistry er : this.registers) + if (er.getAttribute(key) + .equals(value)) + erl.add(er); + return erl.toArray(new ExtensionRegistry[erl.size()]); + } + + /** + * Gets the all attributes where. + * + * @param key The key of the item you are looking for + * @param value The value of the key. + * @param attribute The attribute to get from the obtained registers + * @return An array with the wanted attribute from the registers where key=value. + */ + public String[] getAllAttributesWhere(ExtensionEnum key, String value, ExtensionEnum attribute) { + return this.getAllAttributesWhere(key.toString(), value, attribute.toString()); + } + + /** + * Gets the all attributes where. + * + * @param key The key of the item you are looking for + * @param value The value of the key. + * @param attribute The attribute to get from the obtained registers + * @return An array with the wanted attribute from the registers where key=value. + */ + public String[] getAllAttributesWhere(String key, String value, String attribute) { + ExtensionRegistry[] arr = this.getAllRegistriesWhere(key, value); + return Arrays.asList(arr) + .stream() + .map(k -> k.getAttribute(attribute)) + .toArray(String[]::new); + } + + /** + * Gets the all registries. + * + * @return Every ExtensionRegistry available. + */ + public ExtensionRegistry[] getAllRegistries() { + return this.registers.toArray(new ExtensionRegistry[this.registers.size()]); + } + + /** + * Gets the all attributes. + * + * @param attr The attribute of the ExtensionRegistry you are looking for + * @return The value for the given attribute of every ExtensionRegistry. + */ + public String[] getAllAttributes(ExtensionEnum attr) { + return this.getAllAttributes(attr.toString()); + } + + /** + * Gets the all attributes. + * + * @param attr The attribute of the ExtensionRegistry you are looking for + * @return The value for the given attribute of every ExtensionRegistry. + */ + public String[] getAllAttributes(String attr) { + ArrayList attrs = new ArrayList<>(); + for (ExtensionRegistry er : this.registers) { + String val = er.getAttribute(attr); + if (val != null) + attrs.add(val); + } + return attrs.toArray(new String[attrs.size()]); + } + + /** + * Gets the all attributes unique. + * + * @param attr The attribute of the ExtensionRegistry you are looking for + * @return The value for the given attribute of every ExtensionRegistry, deleting the duplicated ones. + */ + public String[] getAllAttributesUnique(ExtensionEnum attr) { + return this.getAllAttributesUnique(attr.toString()); + } + + /** + * Gets the all attributes unique. + * + * @param attr The attribute of the ExtensionRegistry you are looking for + * @return The value for the given attribute of every ExtensionRegistry, deleting the duplicated ones. + */ + public String[] getAllAttributesUnique(String attr) { + return this.unique(this.getAllAttributes(attr)); + } + + /** + * Gets the attribute from an ExtensionRegistry id + * @param attrId The ExtensionRegistry id + * @param attr The attribute you are looking for + * @return + */ + public String getAttributeFromId(String attrId, ExtensionEnum attr) { + ExtensionRegistry extensionRegistry = this.getFirstRegistryWhere(this.getLabel_id(), attrId); + return extensionRegistry.getAttribute(attr); + } + + /** + * Unique. + * + * @param arr An array of items + * @return The same items without repeats + */ + private String[] unique(String[] arr) { + int end = arr.length; + + Set set = new HashSet<>(); + for (int i = 0; i < end; i++) + set.add(arr[i]); + return set.toArray(new String[set.size()]); + } + + /** + * Instantiate. + * + * @param id The ID of the extension registry to instantiate + * @return The instantiated item + */ + public Object instantiate(String id) { + return this.instantiate(id, null); + } + + /** + * Instantiate using the extension Registry directy. Pretty usefull for creating child items. + * @param extensionRegistry The extension registry to instantiate + * @return The instantiated item + */ + public Object instantiate(ExtensionRegistry extensionRegistry) { + return this.instantiate(extensionRegistry, null); + } + + /** + * Instantiate. + * + * @param id The ID of the extension registry to instantiate + * @param context The context to register the object in. If it is null, it won't be registered. + * @return The instantiated item + */ + public Object instantiate(String id, IEclipseContext context) { + + // Grab + ExtensionRegistry extensionRegistry = this.getFirstRegistryWhere(this.getLabel_id(), id); + if (extensionRegistry == null) { + System.err.println("Extensión no encontrada: ID: " + id); //$NON-NLS-1$ + System.err.println("Extensiones disponibles para el punto de extension " + this.extensionPoint); //$NON-NLS-1$ + System.err.println(this.toString()); + throw new InvalidExtensionIdentifier(id); + } + + return this.instantiate(extensionRegistry, context); + } + + /** + * Instantiate using the extension Registry directy. Pretty usefull for creating child items. + * @param extensionRegistry The extension registry to instantiate + * @param context The context to register the object in. If it is null, it won't be registered. + * @return The instantiated item + */ + public Object instantiate(ExtensionRegistry extensionRegistry, IEclipseContext context) { + + // Grab + IConfigurationElement conf = extensionRegistry.getConfiguration(); + try { + + Object item = conf.createExecutableExtension(this.getLabel_implementation()); + if (context != null) + ContextInjectionFactory.inject(item, context); + + return item; + } catch (CoreException e) { + e.printStackTrace(); + return null; + } + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + for (ExtensionRegistry de : this.getAllRegistries()) { + sb.append(de.toString()); + sb.append("\n"); //$NON-NLS-1$ + } + + return sb.toString(); + } + + /** + * Gets the label id. + * + * @return The label for the extension point ID. The default value is "id". + */ + public String getLabel_id() { + return this.label_id; + } + + /** + * Sets the label id. + * + * @param label_id The new label for the extension point ID. The default value is "id". + */ + public void setLabel_id(String label_id) { + this.label_id = label_id; + } + + /** + * Gets the label implementation. + * + * @return The label for the extension point implementation. The default value is "implementation". + */ + public String getLabel_implementation() { + return this.label_implementation; + } + + /** + * Sets the label implementation. + * + * @param label_implementation The new label for the extension point implementation. The default value is "implementation". + */ + public void setLabel_implementation(ExtensionEnum label_implementation) { + this.setLabel_implementation(label_implementation.toString()); + } + + /** + * Sets the label implementation. + * + * @param label_implementation The new label for the extension point implementation. The default value is "implementation". + */ + public void setLabel_implementation(String label_implementation) { + this.label_implementation = label_implementation; + } + + /** + * The Class InvalidExtensionIdentifier. + */ + public class InvalidExtensionIdentifier extends RuntimeException { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = -517005676614953393L; + + /** + * Instantiates a new invalid extension identifier. + * + * @param text the text + */ + private InvalidExtensionIdentifier(String text) { + super("Identificador de extensión no encontrado: " + text); //$NON-NLS-1$ + } + } + + /** + * The Class InvalidKeyIdentifier. + */ + private class InvalidKeyIdentifier extends RuntimeException { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 924357389433409796L; + + /** + * Instantiates a new invalid key identifier. + * + * @param text the text + */ + private InvalidKeyIdentifier(String text) { + super("Clave no encontrada en el punto de extensión: " + text); //$NON-NLS-1$ + } + + private InvalidKeyIdentifier(String text, String t2) { + super("Clave no encontrada en el punto de extensión: " + text + "// " + t2); //$NON-NLS-1$ + } + + } + + +} diff --git a/bundles/flintstones.helper.extensionpoint/src/flintstones/helper/extensionpoint/ExtensionRegistry.java b/bundles/flintstones.helper.extensionpoint/src/flintstones/helper/extensionpoint/ExtensionRegistry.java new file mode 100644 index 0000000..ebcba7a --- /dev/null +++ b/bundles/flintstones.helper.extensionpoint/src/flintstones/helper/extensionpoint/ExtensionRegistry.java @@ -0,0 +1,133 @@ +package flintstones.helper.extensionpoint; + +import java.text.MessageFormat; +import java.util.Arrays; + +import org.eclipse.core.runtime.IConfigurationElement; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.helper.locale.LocaleHelper; + +/** + * The Class ExtensionRegistry. + * + * @author Sinbad2 + * Generic IConfigurationElement Wrapper + */ +public class ExtensionRegistry { + + /** The configuration. */ + private final IConfigurationElement configuration; + + /** + * Builder. + * + * @param element Domain configuration element + */ + public ExtensionRegistry(IConfigurationElement element) { + this.configuration = element; + } + + /** + * Gets the attribute. + * + * @param element the element + * @return the attribute + */ + public String getAttribute(ExtensionEnum element) { + return this.getAttribute(element.toString()); + } + + /** + * Return Element attribute value. + * + * @param element ENUM, element key + * @return element value + */ + public String getAttribute(String element) { + + String result = null; + String locale = LocaleHelper.getLocale(); + + if (this.configuration != null) { + try { + result = this.configuration.getAttribute(element, locale); + } catch(java.lang.IllegalArgumentException ex) { + result = configuration.getAttribute(element); + } + } + + return result; + } + + /** + * Return Element value as boolean. + * + * @param element ENUM, element key + * @return element value + */ + + public boolean getAttributeBoolean(ExtensionEnum element) { + return this.getAttributeBoolean(element.toString()); + } + + /** + * Return Element value as Boolean. + * + * @param element ENUM, element key + * @return element value + */ + public boolean getAttributeBoolean(String element) { + return this.getAttribute(element) + .equals("true"); //$NON-NLS-1$ + } + + /** + * Gets the attribute references. + * + * @param element the element + * @return the attribute references + */ + public ExtensionRegistry[] getAttributeReferences(ExtensionEnum element) { + return this.getAttributeReferences(element.toString()); + } + + /** + * Gets the attribute referenced ExtensionRegistry for the given field. + * + * @param element the element + * @return the attribute references + */ + public ExtensionRegistry[] getAttributeReferences(String element) { + IConfigurationElement[] config = this.configuration.getChildren(element); + return Arrays.stream(config) + .map(ExtensionRegistry::new) + .toArray(ExtensionRegistry[]::new); + } + + /* (non-Javadoc) + * + * @see java.lang.Object#toString() */ + @Override + public String toString() { + String template = "ExtensionRegistry: {0}"; //$NON-NLS-1$ + String arg = ""; //$NON-NLS-1$ + + if (this.getAttribute("id") != null) //$NON-NLS-1$ + arg = arg + this.configuration.getAttribute("id"); //$NON-NLS-1$ + if (this.getAttribute("uid") != null) //$NON-NLS-1$ + arg = arg + this.configuration.getAttribute("uid"); //$NON-NLS-1$ + if (this.getAttribute("name") != null) //$NON-NLS-1$ + arg = arg + ", " + this.configuration.getAttribute("name"); //$NON-NLS-1$ //$NON-NLS-2$ + + return MessageFormat.format(template, arg); + } + + /** + * Gets the configuration. + * + * @return the IConfigurationElement + */ + public IConfigurationElement getConfiguration() { + return this.configuration; + } +} diff --git a/bundles/flintstones.helper.faq.ui/.classpath b/bundles/flintstones.helper.faq.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.faq.ui/.polyglot.META-INF b/bundles/flintstones.helper.faq.ui/.polyglot.META-INF new file mode 100644 index 0000000..15d7318 --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.faq.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.helper.faq.ui/.project b/bundles/flintstones.helper.faq.ui/.project new file mode 100644 index 0000000..f5b111d --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.faq.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362611 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.faq.ui/META-INF/MANIFEST.MF b/bundles/flintstones.helper.faq.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ded937f --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.helper.faq.ui +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.faq.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.ui, + javax.inject, + org.eclipse.e4.ui.services, + flintstones.helper.html, + flintstones.model.ui.service +Export-Package: flintstones.helper.faq.ui.dialog +Import-Package: org.osgi.framework diff --git a/bundles/flintstones.helper.faq.ui/build.properties b/bundles/flintstones.helper.faq.ui/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.faq.ui/src/flintstones/helper/faq/ui/dialog/MarkdownFAQDialog.java b/bundles/flintstones.helper.faq.ui/src/flintstones/helper/faq/ui/dialog/MarkdownFAQDialog.java new file mode 100644 index 0000000..8f14cd5 --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/src/flintstones/helper/faq/ui/dialog/MarkdownFAQDialog.java @@ -0,0 +1,84 @@ +package flintstones.helper.faq.ui.dialog; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.osgi.framework.Bundle; + +import flintstones.helper.html.HtmlMarkdown; +import flintstones.model.ui.service.UiService; + +public class MarkdownFAQDialog extends Dialog { + + + private Bundle bundle; + + private String markdownFile; + /** + * Create the dialog. + * @param parentShell + */ + @Inject + public MarkdownFAQDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell parentShell) { + super(parentShell); + } + + public void setMarkdown(String md) { + this.markdownFile = md; + } + + public void setBundle(Bundle bundle) { + this.bundle = bundle; + } + + /** + * Create contents of the dialog. + * @param parent + */ + @Override + protected Control createDialogArea(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + UiService.setGridLayout(container, 1, true); + UiService.setGridData(container, 9, 9, true, true); + + Composite mdBase = new Composite(container,0); + UiService.setGridLayout(mdBase, 1, true); + UiService.setGridData(mdBase, 9, 9, true, true); + UiService.setMargin(mdBase, 40); + + HtmlMarkdown markdownViewer = new HtmlMarkdown(mdBase); + markdownViewer.setFile(markdownFile,bundle); + markdownViewer.render(); + + return container; + } + + /** + * Create contents of the button bar. + * @param parent + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { +// createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + createButton(parent, IDialogConstants.CANCEL_ID, "Cerrar", false); + } + + /** + * Return the initial size of the dialog. + */ + @Override + protected Point getInitialSize() { + return new Point(700, 700); + } + + + + +} diff --git a/bundles/flintstones.helper.faq.ui/src/flintstones/helper/faq/ui/dialog/TextFAQDialog.java b/bundles/flintstones.helper.faq.ui/src/flintstones/helper/faq/ui/dialog/TextFAQDialog.java new file mode 100644 index 0000000..d41abad --- /dev/null +++ b/bundles/flintstones.helper.faq.ui/src/flintstones/helper/faq/ui/dialog/TextFAQDialog.java @@ -0,0 +1,72 @@ +package flintstones.helper.faq.ui.dialog; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.eclipse.e4.ui.services.IServiceConstants; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +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 flintstones.model.ui.service.UiService; + +public class TextFAQDialog extends Dialog { + + + private String text; + + /** + * Create the dialog. + * @param parentShell + */ + @Inject + public TextFAQDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell parentShell) { + super(parentShell); + } + + public void setText(String text) { + this.text = text; + } + + /** + * Create contents of the dialog. + * @param parent + */ + @Override + protected Control createDialogArea(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + + UiService.setGridLayout(container, 1, true); + UiService.setGridData(container, 9, 9, true, true); + + Label l = new Label(container, SWT.WRAP); + l.setLayoutData(new GridData(SWT.HORIZONTAL, SWT.TOP, true, false, 1, 1)); + l.setText(text); + + return container; + } + + /** + * Create contents of the button bar. + * @param parent + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); + createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); + } + + /** + * Return the initial size of the dialog. + */ + @Override + protected Point getInitialSize() { + return new Point(450, 300); + } +} diff --git a/bundles/flintstones.helper.faq/.classpath b/bundles/flintstones.helper.faq/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.faq/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.faq/.polyglot.META-INF b/bundles/flintstones.helper.faq/.polyglot.META-INF new file mode 100644 index 0000000..d152686 --- /dev/null +++ b/bundles/flintstones.helper.faq/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.faq + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Faq + diff --git a/bundles/flintstones.helper.faq/.project b/bundles/flintstones.helper.faq/.project new file mode 100644 index 0000000..0b5690f --- /dev/null +++ b/bundles/flintstones.helper.faq/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.faq + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362610 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.faq/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.faq/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.faq/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.faq/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.faq/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.faq/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.faq/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.faq/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.faq/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.faq/META-INF/MANIFEST.MF b/bundles/flintstones.helper.faq/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6e9c856 --- /dev/null +++ b/bundles/flintstones.helper.faq/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Faq +Bundle-SymbolicName: flintstones.helper.faq +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.faq +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.model.application.service, + org.eclipse.osgi, + javax.inject, + flintstones.helper.faq.ui, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.eclipse.jface, + flintstones.helper.data +Import-Package: org.eclipse.core.runtime +Export-Package: flintstones.helper.faq, + flintstones.helper.faq.interfaces diff --git a/bundles/flintstones.helper.faq/build.properties b/bundles/flintstones.helper.faq/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.faq/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.faq/src/flintstones/helper/faq/FaqHelper.java b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/FaqHelper.java new file mode 100644 index 0000000..55ebb45 --- /dev/null +++ b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/FaqHelper.java @@ -0,0 +1,92 @@ +package flintstones.helper.faq; + +import java.net.URL; +import java.text.MessageFormat; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.osgi.framework.FrameworkUtil; +import flintstones.application.model.IApplicationService; +import flintstones.helper.FileHelper; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.helper.faq.interfaces.ITextFAQ; +import flintstones.helper.faq.ui.dialog.MarkdownFAQDialog; +import flintstones.helper.faq.ui.dialog.TextFAQDialog; + +public class FaqHelper { + + private static String MARKDOWN_FILE_NAME = ".{0}.md"; + + private static String DEFAULT_FAQ_LOCALE = "en"; + + @Inject + IApplicationService appService; + + @Inject + IEclipseContext context; + + public FaqHelper() { + + } + + public void showFAQ(Object item) { + + if (item instanceof ITextFAQ) + showTextFaq((ITextFAQ) item); + + if (item instanceof IMarkdownFAQ) + showMarkdownFaq((IMarkdownFAQ) item); + + } + + public String getMarkdownFile(Object item) { + + IMarkdownFAQ faq = (IMarkdownFAQ) item; + + String currentLocale = appService.getCurrentLocale(); + URL url = getMarkdownFileUrl(faq, currentLocale); + if (url == null && currentLocale != DEFAULT_FAQ_LOCALE) { + url = getMarkdownFileUrl(faq, DEFAULT_FAQ_LOCALE); + } + + return FileHelper.readFile(url); + } + + private void showFAQ(IMarkdownFAQ faq, String fileContent) { + + MarkdownFAQDialog infoDialog = ContextInjectionFactory.make(MarkdownFAQDialog.class, context); + infoDialog.setMarkdown(fileContent); + infoDialog.setBundle(FrameworkUtil.getBundle(faq.getClass())); + infoDialog.open(); + + } + + private void showTextFaq(ITextFAQ faq) { + + String text = faq.getFAQ(); + TextFAQDialog faqDialog = ContextInjectionFactory.make(TextFAQDialog.class, context); + faqDialog.setText(text); + faqDialog.open(); + + } + + private void showMarkdownFaq(IMarkdownFAQ faq) { + + String markdownFile = getMarkdownFile(faq); + showFAQ(faq, markdownFile); + + } + + private URL getMarkdownFileUrl(IMarkdownFAQ item, String locale) { + + String path = item.getFAQFile() + MARKDOWN_FILE_NAME; + path = MessageFormat.format(path, locale).toString(); + + URL url = FileHelper.getFileURL(item.getClass(), path); + + return url; + } + +} diff --git a/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IFAQ.java b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IFAQ.java new file mode 100644 index 0000000..5a6890e --- /dev/null +++ b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IFAQ.java @@ -0,0 +1,5 @@ +package flintstones.helper.faq.interfaces; + +public interface IFAQ { + +} diff --git a/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IHtmlFAQ.java b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IHtmlFAQ.java new file mode 100644 index 0000000..65ea71b --- /dev/null +++ b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IHtmlFAQ.java @@ -0,0 +1,7 @@ +package flintstones.helper.faq.interfaces; + +public interface IHtmlFAQ extends IFAQ { + + String getHTMLFAQ(); + +} diff --git a/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IMarkdownFAQ.java b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IMarkdownFAQ.java new file mode 100644 index 0000000..376112d --- /dev/null +++ b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/IMarkdownFAQ.java @@ -0,0 +1,6 @@ +package flintstones.helper.faq.interfaces; + +public interface IMarkdownFAQ extends IFAQ { + + String getFAQFile(); +} diff --git a/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/ITextFAQ.java b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/ITextFAQ.java new file mode 100644 index 0000000..553075d --- /dev/null +++ b/bundles/flintstones.helper.faq/src/flintstones/helper/faq/interfaces/ITextFAQ.java @@ -0,0 +1,6 @@ +package flintstones.helper.faq.interfaces; + +public interface ITextFAQ extends IFAQ { + + public String getFAQ(); +} diff --git a/bundles/flintstones.helper.git/.classpath b/bundles/flintstones.helper.git/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.git/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.git/.polyglot.META-INF b/bundles/flintstones.helper.git/.polyglot.META-INF new file mode 100644 index 0000000..77e10cb --- /dev/null +++ b/bundles/flintstones.helper.git/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.git + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Git + diff --git a/bundles/flintstones.helper.git/.project b/bundles/flintstones.helper.git/.project new file mode 100644 index 0000000..1a9dad3 --- /dev/null +++ b/bundles/flintstones.helper.git/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.git + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362611 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.git/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.git/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.git/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.git/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.git/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.git/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.git/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.git/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.git/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.git/META-INF/MANIFEST.MF b/bundles/flintstones.helper.git/META-INF/MANIFEST.MF new file mode 100644 index 0000000..480a242 --- /dev/null +++ b/bundles/flintstones.helper.git/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Git +Bundle-SymbolicName: flintstones.helper.git +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.git +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.equinox.registry, + org.eclipse.osgi, + org.eclipse.swt, + org.eclipse.core.runtime +Export-Package: flintstones.helper.git diff --git a/bundles/flintstones.helper.git/build.properties b/bundles/flintstones.helper.git/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.git/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.git/src/flintstones/helper/git/GitInformation.java b/bundles/flintstones.helper.git/src/flintstones/helper/git/GitInformation.java new file mode 100644 index 0000000..73e9496 --- /dev/null +++ b/bundles/flintstones.helper.git/src/flintstones/helper/git/GitInformation.java @@ -0,0 +1,145 @@ +package flintstones.helper.git; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; + +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; + +/** + * The Class GitInformation provides development time only git information. + */ +public class GitInformation { + + /** The buiild file. */ + private String filename = "build.txt"; //$NON-NLS-1$ + + /** + * Instantiates a new git information class. + */ + public GitInformation() { + } + + /** + * Gets the last GIT hash. + * + * @return the app hash + */ + public String getAppHash() { + String path = this.getProyectPath() + File.separator + "flintstones.application" + File.separator + this.filename; //$NON-NLS-1$ + + // 1.Obtener el hash de GIT, solo desarrollo + String hash = this.getLastHash(); + + if (hash != null && !hash.equals("")) { //$NON-NLS-1$ + // 2. Si tenemos hash en desarrollo lo guardamos en la carpeta + PrintWriter writer; + try { + writer = new PrintWriter(path, "UTF-8"); //$NON-NLS-1$ + writer.println(hash); + writer.close(); + } catch (FileNotFoundException | UnsupportedEncodingException e) { + System.out.println("No es posible encontrar build.txt en la ruta " + path + "."); + e.printStackTrace(); + } + } else + // 3.Obtener el hash de fichero, solo producción. + hash = this.getFileHash(); + + // 3.Guardar el hash + return hash; + + } + + /** + * Gets the HASH from the build file. + * + * @return the file hash + */ + private String getFileHash() { + String path = this.getProyectPath() + File.separator + "flintstones.application" + File.separator + this.filename; //$NON-NLS-1$ + + String content = ""; //$NON-NLS-1$ + try { + content = new String(Files.readAllBytes(Paths.get(path))); + } catch (IOException e) { + System.err.println("!ERRORFS build-id no encontrada"); //$NON-NLS-1$ + } + return content; + + } + + /** + * Gets hash in development executing a console command. + * + * @return the last hash + */ + private String getLastHash() { + String path = this.getProyectPath(); + + Runtime runtime = Runtime.getRuntime(); + Process process; + try { + process = runtime.exec("git rev-parse --short HEAD", null, new File(path)); //$NON-NLS-1$ + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + String revision = reader.readLine(); + + if (revision != null) + return revision; + } + } catch (IOException e) { + System.err.println("!ERRORFS git no encontrado"); //$NON-NLS-1$ + } + + Bundle bundle = Platform.getBundle("flintstones.application"); + URL fileURL = bundle.getEntry("build.txt"); + + + try { + InputStream inputStream = fileURL.openConnection().getInputStream(); + BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); + String inputLine; + + while ((inputLine = in.readLine()) != null) { + return inputLine; + } + in.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + + + + return ""; //$NON-NLS-1$ + } + + /** + * Gets the proyect path on disk. + * + * @return the proyect path + */ + private String getProyectPath() { + String pluginFolderPath = GitInformation.class.getProtectionDomain() + .getCodeSource() + .getLocation() + .getPath(); + String[] parts = pluginFolderPath.split("/"); //$NON-NLS-1$ + String[] parts2 = Arrays.copyOf(parts, parts.length - 1); // Elimina derecha + String[] parts3 = Arrays.copyOfRange(parts2, 1, parts2.length); // Elimina primera barra + String[] parts4 = Arrays.copyOfRange(parts3, 1, parts3.length); // Elimina el resto y segunda barra + + return parts[1] + File.separator + String.join("/", parts4); //$NON-NLS-1$ + + } +} diff --git a/bundles/flintstones.helper.html/.classpath b/bundles/flintstones.helper.html/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.html/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.html/.polyglot.META-INF b/bundles/flintstones.helper.html/.polyglot.META-INF new file mode 100644 index 0000000..0304a7a --- /dev/null +++ b/bundles/flintstones.helper.html/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.html + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Html + diff --git a/bundles/flintstones.helper.html/.project b/bundles/flintstones.helper.html/.project new file mode 100644 index 0000000..29e3f04 --- /dev/null +++ b/bundles/flintstones.helper.html/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.html + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362612 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.html/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.html/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.html/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.html/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.html/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.html/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.html/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.html/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.html/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.html/META-INF/MANIFEST.MF b/bundles/flintstones.helper.html/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c2a955e --- /dev/null +++ b/bundles/flintstones.helper.html/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Html +Bundle-SymbolicName: flintstones.helper.html +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.html +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.data;visibility:=reexport, + flintstones.helper.debug;visibility:=reexport, + org.eclipse.swt, + org.eclipse.equinox.registry, + org.eclipse.osgi +Export-Package: flintstones.helper.html, + flintstones.helper.html.browser, + flintstones.helper.html.svg, + flintstones.helper.html.svg.chart, + flintstones.helper.html.svg.components, + flintstones.helper.html.table, + flintstones.helper.html.tags +Eclipse-BundleShape: dir diff --git a/bundles/flintstones.helper.html/assets/css/ahpmatrix.css b/bundles/flintstones.helper.html/assets/css/ahpmatrix.css new file mode 100644 index 0000000..c77e9f5 --- /dev/null +++ b/bundles/flintstones.helper.html/assets/css/ahpmatrix.css @@ -0,0 +1,28 @@ +.matrix { + position: relative; + margin: 0 auto; +} + +.matrix::before, .matrix::after { + content: ""; + position: absolute; + top: 0; + border: 1px solid #000; + width: 6px; + height: 100%; +} + +.matrix::before { + left: -6px; + border-right: 0px; +} + +.matrix::after { + right: -6px; + border-left: 0px; +} + +.matrix td { + padding: 5px; + text-align: center; +} diff --git a/bundles/flintstones.helper.html/assets/css/widget.css b/bundles/flintstones.helper.html/assets/css/widget.css new file mode 100644 index 0000000..3fac26a --- /dev/null +++ b/bundles/flintstones.helper.html/assets/css/widget.css @@ -0,0 +1,21 @@ +html{ + background-color: #F0F0F0; + margin: 0px; +} +body{ + margin: 0px; + } +small{ + color: white; +} + +.disabled{ + width: 100%; + height: 100%; + background-color: grey; + background-color: rgba(128, 128, 128, 0.3); + position: absolute; + top: 0; + left: 0; + z-index: 999; +} \ No newline at end of file diff --git a/bundles/flintstones.helper.html/assets/js/debug.js b/bundles/flintstones.helper.html/assets/js/debug.js new file mode 100644 index 0000000..4560170 --- /dev/null +++ b/bundles/flintstones.helper.html/assets/js/debug.js @@ -0,0 +1,3 @@ +var bodyTag = document.getElementsByTagName("body"); +var d = '' +window.location.href+ ''; +bodyTag[0].innerHTML = bodyTag[0].innerHTML + d; \ No newline at end of file diff --git a/bundles/flintstones.helper.html/assets/js/exp.js b/bundles/flintstones.helper.html/assets/js/exp.js new file mode 100644 index 0000000..a439939 --- /dev/null +++ b/bundles/flintstones.helper.html/assets/js/exp.js @@ -0,0 +1,37 @@ +var console=(function(oldCons){ + return { + log: function(text){ + jConsoleLog(text); + // Your code + }, + info: function (text) { + jConsoleLog(text); + // Your code + }, + warn: function (text) { + jConsoleLog(text); + // Your code + }, + error: function (text) { + jConsoleLog(text); + // Your code + } + }; +}(window.console)); + +//Then redefine the old console +window.console = console; + + +console.log("Calm down"); + +function a(){ + console.log("Wenas java 1"); + console.log("Calm down a 1"); + var p = prueba(1); + console.log(p); + console.log("Wenas java 2"); + console.log("Calm down a 2"); + +} + diff --git a/bundles/flintstones.helper.html/assets/js/marked.min.js b/bundles/flintstones.helper.html/assets/js/marked.min.js new file mode 100644 index 0000000..96ffa55 --- /dev/null +++ b/bundles/flintstones.helper.html/assets/js/marked.min.js @@ -0,0 +1,6 @@ +/** + * marked - a markdown parser + * Copyright (c) 2011-2018, Christopher Jeffrey. (MIT Licensed) + * https://github.com/markedjs/marked + */ +!function(e){"use strict";var k={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:g,hr:/^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,nptable:g,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:"^ {0,3}(?:<(script|pre|style)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?\\?>\\n*|\\n*|\\n*|)[\\s\\S]*?(?:\\n{2,}|$)|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=\\h*\\n)[\\s\\S]*?(?:\\n{2,}|$)|(?=\\h*\\n)[\\s\\S]*?(?:\\n{2,}|$))",def:/^ {0,3}\[(label)\]: *\n? *]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,table:g,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading| {0,3}>|<\/?(?:tag)(?: +|\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)*)/,text:/^[^\n]+/};function a(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||d.defaults,this.rules=k.normal,this.options.pedantic?this.rules=k.pedantic:this.options.gfm&&(this.options.tables?this.rules=k.tables:this.rules=k.gfm)}k._label=/(?!\s*\])(?:\\[\[\]]|[^\[\]])+/,k._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,k.def=t(k.def).replace("label",k._label).replace("title",k._title).getRegex(),k.bullet=/(?:[*+-]|\d+\.)/,k.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,k.item=t(k.item,"gm").replace(/bull/g,k.bullet).getRegex(),k.list=t(k.list).replace(/bull/g,k.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+k.def.source+")").getRegex(),k._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",k._comment=//,k.html=t(k.html,"i").replace("comment",k._comment).replace("tag",k._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),k.paragraph=t(k.paragraph).replace("hr",k.hr).replace("heading",k.heading).replace("lheading",k.lheading).replace("tag",k._tag).getRegex(),k.blockquote=t(k.blockquote).replace("paragraph",k.paragraph).getRegex(),k.normal=f({},k),k.gfm=f({},k.normal,{fences:/^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\n? *\1 *(?:\n+|$)/,paragraph:/^/,heading:/^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/}),k.gfm.paragraph=t(k.paragraph).replace("(?!","(?!"+k.gfm.fences.source.replace("\\1","\\2")+"|"+k.list.source.replace("\\1","\\3")+"|").getRegex(),k.tables=f({},k.gfm,{nptable:/^ *([^|\n ].*\|.*)\n *([-:]+ *\|[-| :]*)(?:\n((?:.*[^>\n ].*(?:\n|$))*)\n*|$)/,table:/^ *\|(.+)\n *\|?( *[-:]+[-| :]*)(?:\n((?: *[^>\n ].*(?:\n|$))*)\n*|$)/}),k.pedantic=f({},k.normal,{html:t("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",k._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/}),a.rules=k,a.lex=function(e,t){return new a(t).lex(e)},a.prototype.lex=function(e){return e=e.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,"\n"),this.token(e,!0)},a.prototype.token=function(e,t){var n,r,s,i,l,o,a,h,p,c,u,g,f,d,b,m;for(e=e.replace(/^ +$/gm,"");e;)if((s=this.rules.newline.exec(e))&&(e=e.substring(s[0].length),1 ?/gm,""),this.token(s,t),this.tokens.push({type:"blockquote_end"});else if(s=this.rules.list.exec(e)){for(e=e.substring(s[0].length),a={type:"list_start",ordered:d=1<(i=s[2]).length,start:d?+i:"",loose:!1},this.tokens.push(a),n=!(h=[]),f=(s=s[0].match(this.rules.item)).length,u=0;u?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:g,tag:"^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^",link:/^!?\[(label)\]\(href(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,nolink:/^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,strong:/^__([^\s])__(?!_)|^\*\*([^\s])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,em:/^_([^\s_])_(?!_)|^\*([^\s*"<\[])\*(?!\*)|^_([^\s][\s\S]*?[^\s_])_(?!_)|^_([^\s_][\s\S]*?[^\s])_(?!_)|^\*([^\s"<\[][\s\S]*?[^\s*])\*(?!\*)|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:g,text:/^(`+|[^`])[\s\S]*?(?=[\\?@\[\]\\^_`{|}~])/g,n._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,n._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,n.autolink=t(n.autolink).replace("scheme",n._scheme).replace("email",n._email).getRegex(),n._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,n.tag=t(n.tag).replace("comment",k._comment).replace("attribute",n._attribute).getRegex(),n._label=/(?:\[[^\[\]]*\]|\\[\[\]]?|`[^`]*`|[^\[\]\\])*?/,n._href=/\s*(<(?:\\[<>]?|[^\s<>\\])*>|(?:\\[()]?|\([^\s\x00-\x1f\\]*\)|[^\s\x00-\x1f()\\])*?)/,n._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,n.link=t(n.link).replace("label",n._label).replace("href",n._href).replace("title",n._title).getRegex(),n.reflink=t(n.reflink).replace("label",n._label).getRegex(),n.normal=f({},n),n.pedantic=f({},n.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:t(/^!?\[(label)\]\((.*?)\)/).replace("label",n._label).getRegex(),reflink:t(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",n._label).getRegex()}),n.gfm=f({},n.normal,{escape:t(n.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,del:/^~+(?=\S)([\s\S]*?\S)~+/,text:t(n.text).replace("]|","~]|").replace("|$","|https?://|ftp://|www\\.|[a-zA-Z0-9.!#$%&'*+/=?^_`{\\|}~-]+@|$").getRegex()}),n.gfm.url=t(n.gfm.url).replace("email",n.gfm._extended_email).getRegex(),n.breaks=f({},n.gfm,{br:t(n.br).replace("{2,}","*").getRegex(),text:t(n.gfm.text).replace("{2,}","*").getRegex()}),h.rules=n,h.output=function(e,t,n){return new h(t,n).output(e)},h.prototype.output=function(e){for(var t,n,r,s,i,l,o="";e;)if(i=this.rules.escape.exec(e))e=e.substring(i[0].length),o+=i[1];else if(i=this.rules.autolink.exec(e))e=e.substring(i[0].length),r="@"===i[2]?"mailto:"+(n=c(this.mangle(i[1]))):n=c(i[1]),o+=this.renderer.link(r,null,n);else if(this.inLink||!(i=this.rules.url.exec(e))){if(i=this.rules.tag.exec(e))!this.inLink&&/^/i.test(i[0])&&(this.inLink=!1),!this.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(i[0])?this.inRawBlock=!0:this.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(i[0])&&(this.inRawBlock=!1),e=e.substring(i[0].length),o+=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(i[0]):c(i[0]):i[0];else if(i=this.rules.link.exec(e))e=e.substring(i[0].length),this.inLink=!0,r=i[2],this.options.pedantic?(t=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(r))?(r=t[1],s=t[3]):s="":s=i[3]?i[3].slice(1,-1):"",r=r.trim().replace(/^<([\s\S]*)>$/,"$1"),o+=this.outputLink(i,{href:h.escapes(r),title:h.escapes(s)}),this.inLink=!1;else if((i=this.rules.reflink.exec(e))||(i=this.rules.nolink.exec(e))){if(e=e.substring(i[0].length),t=(i[2]||i[1]).replace(/\s+/g," "),!(t=this.links[t.toLowerCase()])||!t.href){o+=i[0].charAt(0),e=i[0].substring(1)+e;continue}this.inLink=!0,o+=this.outputLink(i,t),this.inLink=!1}else if(i=this.rules.strong.exec(e))e=e.substring(i[0].length),o+=this.renderer.strong(this.output(i[4]||i[3]||i[2]||i[1]));else if(i=this.rules.em.exec(e))e=e.substring(i[0].length),o+=this.renderer.em(this.output(i[6]||i[5]||i[4]||i[3]||i[2]||i[1]));else if(i=this.rules.code.exec(e))e=e.substring(i[0].length),o+=this.renderer.codespan(c(i[2].trim(),!0));else if(i=this.rules.br.exec(e))e=e.substring(i[0].length),o+=this.renderer.br();else if(i=this.rules.del.exec(e))e=e.substring(i[0].length),o+=this.renderer.del(this.output(i[1]));else if(i=this.rules.text.exec(e))e=e.substring(i[0].length),this.inRawBlock?o+=this.renderer.text(i[0]):o+=this.renderer.text(c(this.smartypants(i[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}else{if("@"===i[2])r="mailto:"+(n=c(i[0]));else{for(;l=i[0],i[0]=this.rules._backpedal.exec(i[0])[0],l!==i[0];);n=c(i[0]),r="www."===i[1]?"http://"+n:n}e=e.substring(i[0].length),o+=this.renderer.link(r,null,n)}return o},h.escapes=function(e){return e?e.replace(h.rules._escapes,"$1"):e},h.prototype.outputLink=function(e,t){var n=t.href,r=t.title?c(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(n,r,this.output(e[1])):this.renderer.image(n,r,c(e[1]))},h.prototype.smartypants=function(e){return this.options.smartypants?e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…"):e},h.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t,n="",r=e.length,s=0;s'+(n?e:c(e,!0))+"\n":"
"+(n?e:c(e,!0))+"
"},r.prototype.blockquote=function(e){return"
\n"+e+"
\n"},r.prototype.html=function(e){return e},r.prototype.heading=function(e,t,n){return this.options.headerIds?"'+e+"\n":""+e+"\n"},r.prototype.hr=function(){return this.options.xhtml?"
\n":"
\n"},r.prototype.list=function(e,t,n){var r=t?"ol":"ul";return"<"+r+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"\n"},r.prototype.listitem=function(e){return"
  • "+e+"
  • \n"},r.prototype.checkbox=function(e){return" "},r.prototype.paragraph=function(e){return"

    "+e+"

    \n"},r.prototype.table=function(e,t){return t&&(t=""+t+""),"\n\n"+e+"\n"+t+"
    \n"},r.prototype.tablerow=function(e){return"\n"+e+"\n"},r.prototype.tablecell=function(e,t){var n=t.header?"th":"td";return(t.align?"<"+n+' align="'+t.align+'">':"<"+n+">")+e+"\n"},r.prototype.strong=function(e){return""+e+""},r.prototype.em=function(e){return""+e+""},r.prototype.codespan=function(e){return""+e+""},r.prototype.br=function(){return this.options.xhtml?"
    ":"
    "},r.prototype.del=function(e){return""+e+""},r.prototype.link=function(e,t,n){if(this.options.sanitize){try{var r=decodeURIComponent(u(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return n}if(0===r.indexOf("javascript:")||0===r.indexOf("vbscript:")||0===r.indexOf("data:"))return n}this.options.baseUrl&&!o.test(e)&&(e=i(this.options.baseUrl,e));try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return n}var s='
    "},r.prototype.image=function(e,t,n){this.options.baseUrl&&!o.test(e)&&(e=i(this.options.baseUrl,e));var r=''+n+'":">"},r.prototype.text=function(e){return e},s.prototype.strong=s.prototype.em=s.prototype.codespan=s.prototype.del=s.prototype.text=function(e){return e},s.prototype.link=s.prototype.image=function(e,t,n){return""+n},s.prototype.br=function(){return""},p.parse=function(e,t){return new p(t).parse(e)},p.prototype.parse=function(e){this.inline=new h(e.links,this.options),this.inlineText=new h(e.links,f({},this.options,{renderer:new s})),this.tokens=e.reverse();for(var t="";this.next();)t+=this.tok();return t},p.prototype.next=function(){return this.token=this.tokens.pop()},p.prototype.peek=function(){return this.tokens[this.tokens.length-1]||0},p.prototype.parseText=function(){for(var e=this.token.text;"text"===this.peek().type;)e+="\n"+this.next().text;return this.inline.output(e)},p.prototype.tok=function(){switch(this.token.type){case"space":return"";case"hr":return this.renderer.hr();case"heading":return this.renderer.heading(this.inline.output(this.token.text),this.token.depth,u(this.inlineText.output(this.token.text)));case"code":return this.renderer.code(this.token.text,this.token.lang,this.token.escaped);case"table":var e,t,n,r,s="",i="";for(n="",e=0;e"']/,c.escapeReplace=/[&<>"']/g,c.replacements={"&":"&","<":"<",">":">",'"':""","'":"'"},c.escapeTestNoEncode=/[<>"']|&(?!#?\w+;)/,c.escapeReplaceNoEncode=/[<>"']|&(?!#?\w+;)/g;var l={},o=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function g(){}function f(e){for(var t,n,r=1;rt)n.splice(t);else for(;n.lengthAn error occurred:

    "+c(e.message+"",!0)+"
    ";throw e}}g.exec=g,d.options=d.setOptions=function(e){return f(d.defaults,e),d},d.getDefaults=function(){return{baseUrl:null,breaks:!1,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:new r,sanitize:!1,sanitizer:null,silent:!1,smartLists:!1,smartypants:!1,tables:!0,xhtml:!1}},d.defaults=d.getDefaults(),d.Parser=p,d.parser=p.parse,d.Renderer=r,d.TextRenderer=s,d.Lexer=a,d.lexer=a.lex,d.InlineLexer=h,d.inlineLexer=h.output,d.parse=d,"undefined"!=typeof module&&"object"==typeof exports?module.exports=d:"function"==typeof define&&define.amd?define(function(){return d}):e.marked=d}(this||("undefined"!=typeof window?window:global)); \ No newline at end of file diff --git a/bundles/flintstones.helper.html/assets/js/showdown.min.js b/bundles/flintstones.helper.html/assets/js/showdown.min.js new file mode 100644 index 0000000..72ed9bc --- /dev/null +++ b/bundles/flintstones.helper.html/assets/js/showdown.min.js @@ -0,0 +1,3 @@ +/*! showdown v 1.9.0 - 10-11-2018 */ +(function(){function e(e){"use strict";var r={omitExtraWLInCodeBlocks:{defaultValue:!1,describe:"Omit the default extra whiteline added to code blocks",type:"boolean"},noHeaderId:{defaultValue:!1,describe:"Turn on/off generated header id",type:"boolean"},prefixHeaderId:{defaultValue:!1,describe:"Add a prefix to the generated header ids. Passing a string will prefix that string to the header id. Setting to true will add a generic 'section-' prefix",type:"string"},rawPrefixHeaderId:{defaultValue:!1,describe:'Setting this option to true will prevent showdown from modifying the prefix. This might result in malformed IDs (if, for instance, the " char is used in the prefix)',type:"boolean"},ghCompatibleHeaderId:{defaultValue:!1,describe:"Generate header ids compatible with github style (spaces are replaced with dashes, a bunch of non alphanumeric chars are removed)",type:"boolean"},rawHeaderId:{defaultValue:!1,describe:"Remove only spaces, ' and \" from generated header ids (including prefixes), replacing them with dashes (-). WARNING: This might result in malformed ids",type:"boolean"},headerLevelStart:{defaultValue:!1,describe:"The header blocks level start",type:"integer"},parseImgDimensions:{defaultValue:!1,describe:"Turn on/off image dimension parsing",type:"boolean"},simplifiedAutoLink:{defaultValue:!1,describe:"Turn on/off GFM autolink style",type:"boolean"},excludeTrailingPunctuationFromURLs:{defaultValue:!1,describe:"Excludes trailing punctuation from links generated with autoLinking",type:"boolean"},literalMidWordUnderscores:{defaultValue:!1,describe:"Parse midword underscores as literal underscores",type:"boolean"},literalMidWordAsterisks:{defaultValue:!1,describe:"Parse midword asterisks as literal asterisks",type:"boolean"},strikethrough:{defaultValue:!1,describe:"Turn on/off strikethrough support",type:"boolean"},tables:{defaultValue:!1,describe:"Turn on/off tables support",type:"boolean"},tablesHeaderId:{defaultValue:!1,describe:"Add an id to table headers",type:"boolean"},ghCodeBlocks:{defaultValue:!0,describe:"Turn on/off GFM fenced code blocks support",type:"boolean"},tasklists:{defaultValue:!1,describe:"Turn on/off GFM tasklist support",type:"boolean"},smoothLivePreview:{defaultValue:!1,describe:"Prevents weird effects in live previews due to incomplete input",type:"boolean"},smartIndentationFix:{defaultValue:!1,description:"Tries to smartly fix indentation in es6 strings",type:"boolean"},disableForced4SpacesIndentedSublists:{defaultValue:!1,description:"Disables the requirement of indenting nested sublists by 4 spaces",type:"boolean"},simpleLineBreaks:{defaultValue:!1,description:"Parses simple line breaks as
    (GFM Style)",type:"boolean"},requireSpaceBeforeHeadingText:{defaultValue:!1,description:"Makes adding a space between `#` and the header text mandatory (GFM Style)",type:"boolean"},ghMentions:{defaultValue:!1,description:"Enables github @mentions",type:"boolean"},ghMentionsLink:{defaultValue:"https://github.com/{u}",description:"Changes the link generated by @mentions. Only applies if ghMentions option is enabled.",type:"string"},encodeEmails:{defaultValue:!0,description:"Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities",type:"boolean"},openLinksInNewWindow:{defaultValue:!1,description:"Open all links in new windows",type:"boolean"},backslashEscapesHTMLTags:{defaultValue:!1,description:"Support for HTML Tag escaping. ex:
    foo
    ",type:"boolean"},emoji:{defaultValue:!1,description:"Enable emoji support. Ex: `this is a :smile: emoji`",type:"boolean"},underline:{defaultValue:!1,description:"Enable support for underline. Syntax is double or triple underscores: `__underline word__`. With this option enabled, underscores no longer parses into `` and ``",type:"boolean"},completeHTMLDocument:{defaultValue:!1,description:"Outputs a complete html document, including ``, `` and `` tags",type:"boolean"},metadata:{defaultValue:!1,description:"Enable support for document metadata (defined at the top of the document between `«««` and `»»»` or between `---` and `---`).",type:"boolean"},splitAdjacentBlockquotes:{defaultValue:!1,description:"Split adjacent blockquote blocks",type:"boolean"}};if(!1===e)return JSON.parse(JSON.stringify(r));var t={};for(var a in r)r.hasOwnProperty(a)&&(t[a]=r[a].defaultValue);return t}function r(e,r){"use strict";var t=r?"Error in "+r+" extension->":"Error in unnamed extension",n={valid:!0,error:""};a.helper.isArray(e)||(e=[e]);for(var s=0;s").replace(/&/g,"&")};var c=function(e,r,t,a){"use strict";var n,s,o,i,l,c=a||"",u=c.indexOf("g")>-1,d=new RegExp(r+"|"+t,"g"+c.replace(/g/g,"")),p=new RegExp(r,c.replace(/g/g,"")),h=[];do{for(n=0;o=d.exec(e);)if(p.test(o[0]))n++||(i=(s=d.lastIndex)-o[0].length);else if(n&&!--n){l=o.index+o[0].length;var _={left:{start:i,end:s},match:{start:s,end:o.index},right:{start:o.index,end:l},wholeMatch:{start:i,end:l}};if(h.push(_),!u)return h}}while(n&&(d.lastIndex=s));return h};a.helper.matchRecursiveRegExp=function(e,r,t,a){"use strict";for(var n=c(e,r,t,a),s=[],o=0;o0){var d=[];0!==i[0].wholeMatch.start&&d.push(e.slice(0,i[0].wholeMatch.start));for(var p=0;p=0?n+(t||0):n},a.helper.splitAtIndex=function(e,r){"use strict";if(!a.helper.isString(e))throw"InvalidArgumentError: first parameter of showdown.helper.regexIndexOf function must be a string";return[e.substring(0,r),e.substring(r)]},a.helper.encodeEmailAddress=function(e){"use strict";var r=[function(e){return"&#"+e.charCodeAt(0)+";"},function(e){return"&#x"+e.charCodeAt(0).toString(16)+";"},function(e){return e}];return e=e.replace(/./g,function(e){if("@"===e)e=r[Math.floor(2*Math.random())](e);else{var t=Math.random();e=t>.9?r[2](e):t>.45?r[1](e):r[0](e)}return e})},a.helper.padEnd=function(e,r,t){"use strict";return r>>=0,t=String(t||" "),e.length>r?String(e):((r-=e.length)>t.length&&(t+=t.repeat(r/t.length)),String(e)+t.slice(0,r))},"undefined"==typeof console&&(console={warn:function(e){"use strict";alert(e)},log:function(e){"use strict";alert(e)},error:function(e){"use strict";throw e}}),a.helper.regexes={asteriskDashAndColon:/([*_:~])/g},a.helper.emojis={"+1":"👍","-1":"👎",100:"💯",1234:"🔢","1st_place_medal":"🥇","2nd_place_medal":"🥈","3rd_place_medal":"🥉","8ball":"🎱",a:"🅰️",ab:"🆎",abc:"🔤",abcd:"🔡",accept:"🉑",aerial_tramway:"🚡",airplane:"✈️",alarm_clock:"⏰",alembic:"⚗️",alien:"👽",ambulance:"🚑",amphora:"🏺",anchor:"⚓️",angel:"👼",anger:"💢",angry:"😠",anguished:"😧",ant:"🐜",apple:"🍎",aquarius:"♒️",aries:"♈️",arrow_backward:"◀️",arrow_double_down:"⏬",arrow_double_up:"⏫",arrow_down:"⬇️",arrow_down_small:"🔽",arrow_forward:"▶️",arrow_heading_down:"⤵️",arrow_heading_up:"⤴️",arrow_left:"⬅️",arrow_lower_left:"↙️",arrow_lower_right:"↘️",arrow_right:"➡️",arrow_right_hook:"↪️",arrow_up:"⬆️",arrow_up_down:"↕️",arrow_up_small:"🔼",arrow_upper_left:"↖️",arrow_upper_right:"↗️",arrows_clockwise:"🔃",arrows_counterclockwise:"🔄",art:"🎨",articulated_lorry:"🚛",artificial_satellite:"🛰",astonished:"😲",athletic_shoe:"👟",atm:"🏧",atom_symbol:"⚛️",avocado:"🥑",b:"🅱️",baby:"👶",baby_bottle:"🍼",baby_chick:"🐤",baby_symbol:"🚼",back:"🔙",bacon:"🥓",badminton:"🏸",baggage_claim:"🛄",baguette_bread:"🥖",balance_scale:"⚖️",balloon:"🎈",ballot_box:"🗳",ballot_box_with_check:"☑️",bamboo:"🎍",banana:"🍌",bangbang:"‼️",bank:"🏦",bar_chart:"📊",barber:"💈",baseball:"⚾️",basketball:"🏀",basketball_man:"⛹️",basketball_woman:"⛹️‍♀️",bat:"🦇",bath:"🛀",bathtub:"🛁",battery:"🔋",beach_umbrella:"🏖",bear:"🐻",bed:"🛏",bee:"🐝",beer:"🍺",beers:"🍻",beetle:"🐞",beginner:"🔰",bell:"🔔",bellhop_bell:"🛎",bento:"🍱",biking_man:"🚴",bike:"🚲",biking_woman:"🚴‍♀️",bikini:"👙",biohazard:"☣️",bird:"🐦",birthday:"🎂",black_circle:"⚫️",black_flag:"🏴",black_heart:"🖤",black_joker:"🃏",black_large_square:"⬛️",black_medium_small_square:"◾️",black_medium_square:"◼️",black_nib:"✒️",black_small_square:"▪️",black_square_button:"🔲",blonde_man:"👱",blonde_woman:"👱‍♀️",blossom:"🌼",blowfish:"🐡",blue_book:"📘",blue_car:"🚙",blue_heart:"💙",blush:"😊",boar:"🐗",boat:"⛵️",bomb:"💣",book:"📖",bookmark:"🔖",bookmark_tabs:"📑",books:"📚",boom:"💥",boot:"👢",bouquet:"💐",bowing_man:"🙇",bow_and_arrow:"🏹",bowing_woman:"🙇‍♀️",bowling:"🎳",boxing_glove:"🥊",boy:"👦",bread:"🍞",bride_with_veil:"👰",bridge_at_night:"🌉",briefcase:"💼",broken_heart:"💔",bug:"🐛",building_construction:"🏗",bulb:"💡",bullettrain_front:"🚅",bullettrain_side:"🚄",burrito:"🌯",bus:"🚌",business_suit_levitating:"🕴",busstop:"🚏",bust_in_silhouette:"👤",busts_in_silhouette:"👥",butterfly:"🦋",cactus:"🌵",cake:"🍰",calendar:"📆",call_me_hand:"🤙",calling:"📲",camel:"🐫",camera:"📷",camera_flash:"📸",camping:"🏕",cancer:"♋️",candle:"🕯",candy:"🍬",canoe:"🛶",capital_abcd:"🔠",capricorn:"♑️",car:"🚗",card_file_box:"🗃",card_index:"📇",card_index_dividers:"🗂",carousel_horse:"🎠",carrot:"🥕",cat:"🐱",cat2:"🐈",cd:"💿",chains:"⛓",champagne:"🍾",chart:"💹",chart_with_downwards_trend:"📉",chart_with_upwards_trend:"📈",checkered_flag:"🏁",cheese:"🧀",cherries:"🍒",cherry_blossom:"🌸",chestnut:"🌰",chicken:"🐔",children_crossing:"🚸",chipmunk:"🐿",chocolate_bar:"🍫",christmas_tree:"🎄",church:"⛪️",cinema:"🎦",circus_tent:"🎪",city_sunrise:"🌇",city_sunset:"🌆",cityscape:"🏙",cl:"🆑",clamp:"🗜",clap:"👏",clapper:"🎬",classical_building:"🏛",clinking_glasses:"🥂",clipboard:"📋",clock1:"🕐",clock10:"🕙",clock1030:"🕥",clock11:"🕚",clock1130:"🕦",clock12:"🕛",clock1230:"🕧",clock130:"🕜",clock2:"🕑",clock230:"🕝",clock3:"🕒",clock330:"🕞",clock4:"🕓",clock430:"🕟",clock5:"🕔",clock530:"🕠",clock6:"🕕",clock630:"🕡",clock7:"🕖",clock730:"🕢",clock8:"🕗",clock830:"🕣",clock9:"🕘",clock930:"🕤",closed_book:"📕",closed_lock_with_key:"🔐",closed_umbrella:"🌂",cloud:"☁️",cloud_with_lightning:"🌩",cloud_with_lightning_and_rain:"⛈",cloud_with_rain:"🌧",cloud_with_snow:"🌨",clown_face:"🤡",clubs:"♣️",cocktail:"🍸",coffee:"☕️",coffin:"⚰️",cold_sweat:"😰",comet:"☄️",computer:"💻",computer_mouse:"🖱",confetti_ball:"🎊",confounded:"😖",confused:"😕",congratulations:"㊗️",construction:"🚧",construction_worker_man:"👷",construction_worker_woman:"👷‍♀️",control_knobs:"🎛",convenience_store:"🏪",cookie:"🍪",cool:"🆒",policeman:"👮",copyright:"©️",corn:"🌽",couch_and_lamp:"🛋",couple:"👫",couple_with_heart_woman_man:"💑",couple_with_heart_man_man:"👨‍❤️‍👨",couple_with_heart_woman_woman:"👩‍❤️‍👩",couplekiss_man_man:"👨‍❤️‍💋‍👨",couplekiss_man_woman:"💏",couplekiss_woman_woman:"👩‍❤️‍💋‍👩",cow:"🐮",cow2:"🐄",cowboy_hat_face:"🤠",crab:"🦀",crayon:"🖍",credit_card:"💳",crescent_moon:"🌙",cricket:"🏏",crocodile:"🐊",croissant:"🥐",crossed_fingers:"🤞",crossed_flags:"🎌",crossed_swords:"⚔️",crown:"👑",cry:"😢",crying_cat_face:"😿",crystal_ball:"🔮",cucumber:"🥒",cupid:"💘",curly_loop:"➰",currency_exchange:"💱",curry:"🍛",custard:"🍮",customs:"🛃",cyclone:"🌀",dagger:"🗡",dancer:"💃",dancing_women:"👯",dancing_men:"👯‍♂️",dango:"🍡",dark_sunglasses:"🕶",dart:"🎯",dash:"💨",date:"📅",deciduous_tree:"🌳",deer:"🦌",department_store:"🏬",derelict_house:"🏚",desert:"🏜",desert_island:"🏝",desktop_computer:"🖥",male_detective:"🕵️",diamond_shape_with_a_dot_inside:"💠",diamonds:"♦️",disappointed:"😞",disappointed_relieved:"😥",dizzy:"💫",dizzy_face:"😵",do_not_litter:"🚯",dog:"🐶",dog2:"🐕",dollar:"💵",dolls:"🎎",dolphin:"🐬",door:"🚪",doughnut:"🍩",dove:"🕊",dragon:"🐉",dragon_face:"🐲",dress:"👗",dromedary_camel:"🐪",drooling_face:"🤤",droplet:"💧",drum:"🥁",duck:"🦆",dvd:"📀","e-mail":"📧",eagle:"🦅",ear:"👂",ear_of_rice:"🌾",earth_africa:"🌍",earth_americas:"🌎",earth_asia:"🌏",egg:"🥚",eggplant:"🍆",eight_pointed_black_star:"✴️",eight_spoked_asterisk:"✳️",electric_plug:"🔌",elephant:"🐘",email:"✉️",end:"🔚",envelope_with_arrow:"📩",euro:"💶",european_castle:"🏰",european_post_office:"🏤",evergreen_tree:"🌲",exclamation:"❗️",expressionless:"😑",eye:"👁",eye_speech_bubble:"👁‍🗨",eyeglasses:"👓",eyes:"👀",face_with_head_bandage:"🤕",face_with_thermometer:"🤒",fist_oncoming:"👊",factory:"🏭",fallen_leaf:"🍂",family_man_woman_boy:"👪",family_man_boy:"👨‍👦",family_man_boy_boy:"👨‍👦‍👦",family_man_girl:"👨‍👧",family_man_girl_boy:"👨‍👧‍👦",family_man_girl_girl:"👨‍👧‍👧",family_man_man_boy:"👨‍👨‍👦",family_man_man_boy_boy:"👨‍👨‍👦‍👦",family_man_man_girl:"👨‍👨‍👧",family_man_man_girl_boy:"👨‍👨‍👧‍👦",family_man_man_girl_girl:"👨‍👨‍👧‍👧",family_man_woman_boy_boy:"👨‍👩‍👦‍👦",family_man_woman_girl:"👨‍👩‍👧",family_man_woman_girl_boy:"👨‍👩‍👧‍👦",family_man_woman_girl_girl:"👨‍👩‍👧‍👧",family_woman_boy:"👩‍👦",family_woman_boy_boy:"👩‍👦‍👦",family_woman_girl:"👩‍👧",family_woman_girl_boy:"👩‍👧‍👦",family_woman_girl_girl:"👩‍👧‍👧",family_woman_woman_boy:"👩‍👩‍👦",family_woman_woman_boy_boy:"👩‍👩‍👦‍👦",family_woman_woman_girl:"👩‍👩‍👧",family_woman_woman_girl_boy:"👩‍👩‍👧‍👦",family_woman_woman_girl_girl:"👩‍👩‍👧‍👧",fast_forward:"⏩",fax:"📠",fearful:"😨",feet:"🐾",female_detective:"🕵️‍♀️",ferris_wheel:"🎡",ferry:"⛴",field_hockey:"🏑",file_cabinet:"🗄",file_folder:"📁",film_projector:"📽",film_strip:"🎞",fire:"🔥",fire_engine:"🚒",fireworks:"🎆",first_quarter_moon:"🌓",first_quarter_moon_with_face:"🌛",fish:"🐟",fish_cake:"🍥",fishing_pole_and_fish:"🎣",fist_raised:"✊",fist_left:"🤛",fist_right:"🤜",flags:"🎏",flashlight:"🔦",fleur_de_lis:"⚜️",flight_arrival:"🛬",flight_departure:"🛫",floppy_disk:"💾",flower_playing_cards:"🎴",flushed:"😳",fog:"🌫",foggy:"🌁",football:"🏈",footprints:"👣",fork_and_knife:"🍴",fountain:"⛲️",fountain_pen:"🖋",four_leaf_clover:"🍀",fox_face:"🦊",framed_picture:"🖼",free:"🆓",fried_egg:"🍳",fried_shrimp:"🍤",fries:"🍟",frog:"🐸",frowning:"😦",frowning_face:"☹️",frowning_man:"🙍‍♂️",frowning_woman:"🙍",middle_finger:"🖕",fuelpump:"⛽️",full_moon:"🌕",full_moon_with_face:"🌝",funeral_urn:"⚱️",game_die:"🎲",gear:"⚙️",gem:"💎",gemini:"♊️",ghost:"👻",gift:"🎁",gift_heart:"💝",girl:"👧",globe_with_meridians:"🌐",goal_net:"🥅",goat:"🐐",golf:"⛳️",golfing_man:"🏌️",golfing_woman:"🏌️‍♀️",gorilla:"🦍",grapes:"🍇",green_apple:"🍏",green_book:"📗",green_heart:"💚",green_salad:"🥗",grey_exclamation:"❕",grey_question:"❔",grimacing:"😬",grin:"😁",grinning:"😀",guardsman:"💂",guardswoman:"💂‍♀️",guitar:"🎸",gun:"🔫",haircut_woman:"💇",haircut_man:"💇‍♂️",hamburger:"🍔",hammer:"🔨",hammer_and_pick:"⚒",hammer_and_wrench:"🛠",hamster:"🐹",hand:"✋",handbag:"👜",handshake:"🤝",hankey:"💩",hatched_chick:"🐥",hatching_chick:"🐣",headphones:"🎧",hear_no_evil:"🙉",heart:"❤️",heart_decoration:"💟",heart_eyes:"😍",heart_eyes_cat:"😻",heartbeat:"💓",heartpulse:"💗",hearts:"♥️",heavy_check_mark:"✔️",heavy_division_sign:"➗",heavy_dollar_sign:"💲",heavy_heart_exclamation:"❣️",heavy_minus_sign:"➖",heavy_multiplication_x:"✖️",heavy_plus_sign:"➕",helicopter:"🚁",herb:"🌿",hibiscus:"🌺",high_brightness:"🔆",high_heel:"👠",hocho:"🔪",hole:"🕳",honey_pot:"🍯",horse:"🐴",horse_racing:"🏇",hospital:"🏥",hot_pepper:"🌶",hotdog:"🌭",hotel:"🏨",hotsprings:"♨️",hourglass:"⌛️",hourglass_flowing_sand:"⏳",house:"🏠",house_with_garden:"🏡",houses:"🏘",hugs:"🤗",hushed:"😯",ice_cream:"🍨",ice_hockey:"🏒",ice_skate:"⛸",icecream:"🍦",id:"🆔",ideograph_advantage:"🉐",imp:"👿",inbox_tray:"📥",incoming_envelope:"📨",tipping_hand_woman:"💁",information_source:"ℹ️",innocent:"😇",interrobang:"⁉️",iphone:"📱",izakaya_lantern:"🏮",jack_o_lantern:"🎃",japan:"🗾",japanese_castle:"🏯",japanese_goblin:"👺",japanese_ogre:"👹",jeans:"👖",joy:"😂",joy_cat:"😹",joystick:"🕹",kaaba:"🕋",key:"🔑",keyboard:"⌨️",keycap_ten:"🔟",kick_scooter:"🛴",kimono:"👘",kiss:"💋",kissing:"😗",kissing_cat:"😽",kissing_closed_eyes:"😚",kissing_heart:"😘",kissing_smiling_eyes:"😙",kiwi_fruit:"🥝",koala:"🐨",koko:"🈁",label:"🏷",large_blue_circle:"🔵",large_blue_diamond:"🔷",large_orange_diamond:"🔶",last_quarter_moon:"🌗",last_quarter_moon_with_face:"🌜",latin_cross:"✝️",laughing:"😆",leaves:"🍃",ledger:"📒",left_luggage:"🛅",left_right_arrow:"↔️",leftwards_arrow_with_hook:"↩️",lemon:"🍋",leo:"♌️",leopard:"🐆",level_slider:"🎚",libra:"♎️",light_rail:"🚈",link:"🔗",lion:"🦁",lips:"👄",lipstick:"💄",lizard:"🦎",lock:"🔒",lock_with_ink_pen:"🔏",lollipop:"🍭",loop:"➿",loud_sound:"🔊",loudspeaker:"📢",love_hotel:"🏩",love_letter:"💌",low_brightness:"🔅",lying_face:"🤥",m:"Ⓜ️",mag:"🔍",mag_right:"🔎",mahjong:"🀄️",mailbox:"📫",mailbox_closed:"📪",mailbox_with_mail:"📬",mailbox_with_no_mail:"📭",man:"👨",man_artist:"👨‍🎨",man_astronaut:"👨‍🚀",man_cartwheeling:"🤸‍♂️",man_cook:"👨‍🍳",man_dancing:"🕺",man_facepalming:"🤦‍♂️",man_factory_worker:"👨‍🏭",man_farmer:"👨‍🌾",man_firefighter:"👨‍🚒",man_health_worker:"👨‍⚕️",man_in_tuxedo:"🤵",man_judge:"👨‍⚖️",man_juggling:"🤹‍♂️",man_mechanic:"👨‍🔧",man_office_worker:"👨‍💼",man_pilot:"👨‍✈️",man_playing_handball:"🤾‍♂️",man_playing_water_polo:"🤽‍♂️",man_scientist:"👨‍🔬",man_shrugging:"🤷‍♂️",man_singer:"👨‍🎤",man_student:"👨‍🎓",man_teacher:"👨‍🏫",man_technologist:"👨‍💻",man_with_gua_pi_mao:"👲",man_with_turban:"👳",tangerine:"🍊",mans_shoe:"👞",mantelpiece_clock:"🕰",maple_leaf:"🍁",martial_arts_uniform:"🥋",mask:"😷",massage_woman:"💆",massage_man:"💆‍♂️",meat_on_bone:"🍖",medal_military:"🎖",medal_sports:"🏅",mega:"📣",melon:"🍈",memo:"📝",men_wrestling:"🤼‍♂️",menorah:"🕎",mens:"🚹",metal:"🤘",metro:"🚇",microphone:"🎤",microscope:"🔬",milk_glass:"🥛",milky_way:"🌌",minibus:"🚐",minidisc:"💽",mobile_phone_off:"📴",money_mouth_face:"🤑",money_with_wings:"💸",moneybag:"💰",monkey:"🐒",monkey_face:"🐵",monorail:"🚝",moon:"🌔",mortar_board:"🎓",mosque:"🕌",motor_boat:"🛥",motor_scooter:"🛵",motorcycle:"🏍",motorway:"🛣",mount_fuji:"🗻",mountain:"⛰",mountain_biking_man:"🚵",mountain_biking_woman:"🚵‍♀️",mountain_cableway:"🚠",mountain_railway:"🚞",mountain_snow:"🏔",mouse:"🐭",mouse2:"🐁",movie_camera:"🎥",moyai:"🗿",mrs_claus:"🤶",muscle:"💪",mushroom:"🍄",musical_keyboard:"🎹",musical_note:"🎵",musical_score:"🎼",mute:"🔇",nail_care:"💅",name_badge:"📛",national_park:"🏞",nauseated_face:"🤢",necktie:"👔",negative_squared_cross_mark:"❎",nerd_face:"🤓",neutral_face:"😐",new:"🆕",new_moon:"🌑",new_moon_with_face:"🌚",newspaper:"📰",newspaper_roll:"🗞",next_track_button:"⏭",ng:"🆖",no_good_man:"🙅‍♂️",no_good_woman:"🙅",night_with_stars:"🌃",no_bell:"🔕",no_bicycles:"🚳",no_entry:"⛔️",no_entry_sign:"🚫",no_mobile_phones:"📵",no_mouth:"😶",no_pedestrians:"🚷",no_smoking:"🚭","non-potable_water":"🚱",nose:"👃",notebook:"📓",notebook_with_decorative_cover:"📔",notes:"🎶",nut_and_bolt:"🔩",o:"⭕️",o2:"🅾️",ocean:"🌊",octopus:"🐙",oden:"🍢",office:"🏢",oil_drum:"🛢",ok:"🆗",ok_hand:"👌",ok_man:"🙆‍♂️",ok_woman:"🙆",old_key:"🗝",older_man:"👴",older_woman:"👵",om:"🕉",on:"🔛",oncoming_automobile:"🚘",oncoming_bus:"🚍",oncoming_police_car:"🚔",oncoming_taxi:"🚖",open_file_folder:"📂",open_hands:"👐",open_mouth:"😮",open_umbrella:"☂️",ophiuchus:"⛎",orange_book:"📙",orthodox_cross:"☦️",outbox_tray:"📤",owl:"🦉",ox:"🐂",package:"📦",page_facing_up:"📄",page_with_curl:"📃",pager:"📟",paintbrush:"🖌",palm_tree:"🌴",pancakes:"🥞",panda_face:"🐼",paperclip:"📎",paperclips:"🖇",parasol_on_ground:"⛱",parking:"🅿️",part_alternation_mark:"〽️",partly_sunny:"⛅️",passenger_ship:"🛳",passport_control:"🛂",pause_button:"⏸",peace_symbol:"☮️",peach:"🍑",peanuts:"🥜",pear:"🍐",pen:"🖊",pencil2:"✏️",penguin:"🐧",pensive:"😔",performing_arts:"🎭",persevere:"😣",person_fencing:"🤺",pouting_woman:"🙎",phone:"☎️",pick:"⛏",pig:"🐷",pig2:"🐖",pig_nose:"🐽",pill:"💊",pineapple:"🍍",ping_pong:"🏓",pisces:"♓️",pizza:"🍕",place_of_worship:"🛐",plate_with_cutlery:"🍽",play_or_pause_button:"⏯",point_down:"👇",point_left:"👈",point_right:"👉",point_up:"☝️",point_up_2:"👆",police_car:"🚓",policewoman:"👮‍♀️",poodle:"🐩",popcorn:"🍿",post_office:"🏣",postal_horn:"📯",postbox:"📮",potable_water:"🚰",potato:"🥔",pouch:"👝",poultry_leg:"🍗",pound:"💷",rage:"😡",pouting_cat:"😾",pouting_man:"🙎‍♂️",pray:"🙏",prayer_beads:"📿",pregnant_woman:"🤰",previous_track_button:"⏮",prince:"🤴",princess:"👸",printer:"🖨",purple_heart:"💜",purse:"👛",pushpin:"📌",put_litter_in_its_place:"🚮",question:"❓",rabbit:"🐰",rabbit2:"🐇",racehorse:"🐎",racing_car:"🏎",radio:"📻",radio_button:"🔘",radioactive:"☢️",railway_car:"🚃",railway_track:"🛤",rainbow:"🌈",rainbow_flag:"🏳️‍🌈",raised_back_of_hand:"🤚",raised_hand_with_fingers_splayed:"🖐",raised_hands:"🙌",raising_hand_woman:"🙋",raising_hand_man:"🙋‍♂️",ram:"🐏",ramen:"🍜",rat:"🐀",record_button:"⏺",recycle:"♻️",red_circle:"🔴",registered:"®️",relaxed:"☺️",relieved:"😌",reminder_ribbon:"🎗",repeat:"🔁",repeat_one:"🔂",rescue_worker_helmet:"⛑",restroom:"🚻",revolving_hearts:"💞",rewind:"⏪",rhinoceros:"🦏",ribbon:"🎀",rice:"🍚",rice_ball:"🍙",rice_cracker:"🍘",rice_scene:"🎑",right_anger_bubble:"🗯",ring:"💍",robot:"🤖",rocket:"🚀",rofl:"🤣",roll_eyes:"🙄",roller_coaster:"🎢",rooster:"🐓",rose:"🌹",rosette:"🏵",rotating_light:"🚨",round_pushpin:"📍",rowing_man:"🚣",rowing_woman:"🚣‍♀️",rugby_football:"🏉",running_man:"🏃",running_shirt_with_sash:"🎽",running_woman:"🏃‍♀️",sa:"🈂️",sagittarius:"♐️",sake:"🍶",sandal:"👡",santa:"🎅",satellite:"📡",saxophone:"🎷",school:"🏫",school_satchel:"🎒",scissors:"✂️",scorpion:"🦂",scorpius:"♏️",scream:"😱",scream_cat:"🙀",scroll:"📜",seat:"💺",secret:"㊙️",see_no_evil:"🙈",seedling:"🌱",selfie:"🤳",shallow_pan_of_food:"🥘",shamrock:"☘️",shark:"🦈",shaved_ice:"🍧",sheep:"🐑",shell:"🐚",shield:"🛡",shinto_shrine:"⛩",ship:"🚢",shirt:"👕",shopping:"🛍",shopping_cart:"🛒",shower:"🚿",shrimp:"🦐",signal_strength:"📶",six_pointed_star:"🔯",ski:"🎿",skier:"⛷",skull:"💀",skull_and_crossbones:"☠️",sleeping:"😴",sleeping_bed:"🛌",sleepy:"😪",slightly_frowning_face:"🙁",slightly_smiling_face:"🙂",slot_machine:"🎰",small_airplane:"🛩",small_blue_diamond:"🔹",small_orange_diamond:"🔸",small_red_triangle:"🔺",small_red_triangle_down:"🔻",smile:"😄",smile_cat:"😸",smiley:"😃",smiley_cat:"😺",smiling_imp:"😈",smirk:"😏",smirk_cat:"😼",smoking:"🚬",snail:"🐌",snake:"🐍",sneezing_face:"🤧",snowboarder:"🏂",snowflake:"❄️",snowman:"⛄️",snowman_with_snow:"☃️",sob:"😭",soccer:"⚽️",soon:"🔜",sos:"🆘",sound:"🔉",space_invader:"👾",spades:"♠️",spaghetti:"🍝",sparkle:"❇️",sparkler:"🎇",sparkles:"✨",sparkling_heart:"💖",speak_no_evil:"🙊",speaker:"🔈",speaking_head:"🗣",speech_balloon:"💬",speedboat:"🚤",spider:"🕷",spider_web:"🕸",spiral_calendar:"🗓",spiral_notepad:"🗒",spoon:"🥄",squid:"🦑",stadium:"🏟",star:"⭐️",star2:"🌟",star_and_crescent:"☪️",star_of_david:"✡️",stars:"🌠",station:"🚉",statue_of_liberty:"🗽",steam_locomotive:"🚂",stew:"🍲",stop_button:"⏹",stop_sign:"🛑",stopwatch:"⏱",straight_ruler:"📏",strawberry:"🍓",stuck_out_tongue:"😛",stuck_out_tongue_closed_eyes:"😝",stuck_out_tongue_winking_eye:"😜",studio_microphone:"🎙",stuffed_flatbread:"🥙",sun_behind_large_cloud:"🌥",sun_behind_rain_cloud:"🌦",sun_behind_small_cloud:"🌤",sun_with_face:"🌞",sunflower:"🌻",sunglasses:"😎",sunny:"☀️",sunrise:"🌅",sunrise_over_mountains:"🌄",surfing_man:"🏄",surfing_woman:"🏄‍♀️",sushi:"🍣",suspension_railway:"🚟",sweat:"😓",sweat_drops:"💦",sweat_smile:"😅",sweet_potato:"🍠",swimming_man:"🏊",swimming_woman:"🏊‍♀️",symbols:"🔣",synagogue:"🕍",syringe:"💉",taco:"🌮",tada:"🎉",tanabata_tree:"🎋",taurus:"♉️",taxi:"🚕",tea:"🍵",telephone_receiver:"📞",telescope:"🔭",tennis:"🎾",tent:"⛺️",thermometer:"🌡",thinking:"🤔",thought_balloon:"💭",ticket:"🎫",tickets:"🎟",tiger:"🐯",tiger2:"🐅",timer_clock:"⏲",tipping_hand_man:"💁‍♂️",tired_face:"😫",tm:"™️",toilet:"🚽",tokyo_tower:"🗼",tomato:"🍅",tongue:"👅",top:"🔝",tophat:"🎩",tornado:"🌪",trackball:"🖲",tractor:"🚜",traffic_light:"🚥",train:"🚋",train2:"🚆",tram:"🚊",triangular_flag_on_post:"🚩",triangular_ruler:"📐",trident:"🔱",triumph:"😤",trolleybus:"🚎",trophy:"🏆",tropical_drink:"🍹",tropical_fish:"🐠",truck:"🚚",trumpet:"🎺",tulip:"🌷",tumbler_glass:"🥃",turkey:"🦃",turtle:"🐢",tv:"📺",twisted_rightwards_arrows:"🔀",two_hearts:"💕",two_men_holding_hands:"👬",two_women_holding_hands:"👭",u5272:"🈹",u5408:"🈴",u55b6:"🈺",u6307:"🈯️",u6708:"🈷️",u6709:"🈶",u6e80:"🈵",u7121:"🈚️",u7533:"🈸",u7981:"🈲",u7a7a:"🈳",umbrella:"☔️",unamused:"😒",underage:"🔞",unicorn:"🦄",unlock:"🔓",up:"🆙",upside_down_face:"🙃",v:"✌️",vertical_traffic_light:"🚦",vhs:"📼",vibration_mode:"📳",video_camera:"📹",video_game:"🎮",violin:"🎻",virgo:"♍️",volcano:"🌋",volleyball:"🏐",vs:"🆚",vulcan_salute:"🖖",walking_man:"🚶",walking_woman:"🚶‍♀️",waning_crescent_moon:"🌘",waning_gibbous_moon:"🌖",warning:"⚠️",wastebasket:"🗑",watch:"⌚️",water_buffalo:"🐃",watermelon:"🍉",wave:"👋",wavy_dash:"〰️",waxing_crescent_moon:"🌒",wc:"🚾",weary:"😩",wedding:"💒",weight_lifting_man:"🏋️",weight_lifting_woman:"🏋️‍♀️",whale:"🐳",whale2:"🐋",wheel_of_dharma:"☸️",wheelchair:"♿️",white_check_mark:"✅",white_circle:"⚪️",white_flag:"🏳️",white_flower:"💮",white_large_square:"⬜️",white_medium_small_square:"◽️",white_medium_square:"◻️",white_small_square:"▫️",white_square_button:"🔳",wilted_flower:"🥀",wind_chime:"🎐",wind_face:"🌬",wine_glass:"🍷",wink:"😉",wolf:"🐺",woman:"👩",woman_artist:"👩‍🎨",woman_astronaut:"👩‍🚀",woman_cartwheeling:"🤸‍♀️",woman_cook:"👩‍🍳",woman_facepalming:"🤦‍♀️",woman_factory_worker:"👩‍🏭",woman_farmer:"👩‍🌾",woman_firefighter:"👩‍🚒",woman_health_worker:"👩‍⚕️",woman_judge:"👩‍⚖️",woman_juggling:"🤹‍♀️",woman_mechanic:"👩‍🔧",woman_office_worker:"👩‍💼",woman_pilot:"👩‍✈️",woman_playing_handball:"🤾‍♀️",woman_playing_water_polo:"🤽‍♀️",woman_scientist:"👩‍🔬",woman_shrugging:"🤷‍♀️",woman_singer:"👩‍🎤",woman_student:"👩‍🎓",woman_teacher:"👩‍🏫",woman_technologist:"👩‍💻",woman_with_turban:"👳‍♀️",womans_clothes:"👚",womans_hat:"👒",women_wrestling:"🤼‍♀️",womens:"🚺",world_map:"🗺",worried:"😟",wrench:"🔧",writing_hand:"✍️",x:"❌",yellow_heart:"💛",yen:"💴",yin_yang:"☯️",yum:"😋",zap:"⚡️",zipper_mouth_face:"🤐",zzz:"💤",octocat:':octocat:',showdown:"S"},a.Converter=function(e){"use strict";function t(e,t){if(t=t||null,a.helper.isString(e)){if(e=a.helper.stdExtName(e),t=e,a.extensions[e])return console.warn("DEPRECATION WARNING: "+e+" is an old extension that uses a deprecated loading method.Please inform the developer that the extension should be updated!"),void function(e,t){"function"==typeof e&&(e=e(new a.Converter));a.helper.isArray(e)||(e=[e]);var n=r(e,t);if(!n.valid)throw Error(n.error);for(var s=0;s[ \t]+¨NBSP;<"),!r){if(!window||!window.document)throw new Error("HTMLParser is undefined. If in a webworker or nodejs environment, you need to provide a WHATWG DOM and HTML such as JSDOM");r=window.document}var n=r.createElement("div");n.innerHTML=e;var s={preList:function(e){for(var r=e.querySelectorAll("pre"),t=[],n=0;n'}else t.push(r[n].innerHTML),r[n].innerHTML="",r[n].setAttribute("prenum",n.toString());return t}(n)};t(n);for(var o=n.childNodes,i="",l=0;l? ?(['"].*['"])?\)$/m)>-1)o="";else if(!o){if(s||(s=n.toLowerCase().replace(/ ?\n/g," ")),o="#"+s,a.helper.isUndefined(t.gUrls[s]))return e;o=t.gUrls[s],a.helper.isUndefined(t.gTitles[s])||(c=t.gTitles[s])}var u='
    "};return e=(e=t.converter._dispatch("anchors.before",e,r,t)).replace(/\[((?:\[[^\]]*]|[^\[\]])*)] ?(?:\n *)?\[(.*?)]()()()()/g,n),e=e.replace(/\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]?<([^>]*)>(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g,n),e=e.replace(/\[((?:\[[^\]]*]|[^\[\]])*)]()[ \t]*\([ \t]??(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g,n),e=e.replace(/\[([^\[\]]+)]()()()()()/g,n),r.ghMentions&&(e=e.replace(/(^|\s)(\\)?(@([a-z\d]+(?:[a-z\d.-]+?[a-z\d]+)*))/gim,function(e,t,n,s,o){if("\\"===n)return t+s;if(!a.helper.isString(r.ghMentionsLink))throw new Error("ghMentionsLink option must be a string");var i=r.ghMentionsLink.replace(/\{u}/g,o),l="";return r.openLinksInNewWindow&&(l=' target="¨E95Eblank"'),t+'"+s+""})),e=t.converter._dispatch("anchors.after",e,r,t)});var u=/([*~_]+|\b)(((https?|ftp|dict):\/\/|www\.)[^'">\s]+?\.[^'">\s]+?)()(\1)?(?=\s|$)(?!["<>])/gi,d=/([*~_]+|\b)(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+?)([.!?,()\[\]])?(\1)?(?=\s|$)(?!["<>])/gi,p=/()<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)()>()/gi,h=/(^|\s)(?:mailto:)?([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?=$|\s)/gim,_=/<()(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,g=function(e){"use strict";return function(r,t,n,s,o,i,l){var c=n=n.replace(a.helper.regexes.asteriskDashAndColon,a.helper.escapeCharactersCallback),u="",d="",p=t||"",h=l||"";return/^www\./i.test(n)&&(n=n.replace(/^www\./i,"http://www.")),e.excludeTrailingPunctuationFromURLs&&i&&(u=i),e.openLinksInNewWindow&&(d=' target="¨E95Eblank"'),p+'"+c+""+u+h}},m=function(e,r){"use strict";return function(t,n,s){var o="mailto:";return n=n||"",s=a.subParser("unescapeSpecialChars")(s,e,r),e.encodeEmails?(o=a.helper.encodeEmailAddress(o+s),s=a.helper.encodeEmailAddress(s)):o+=s,n+''+s+""}};a.subParser("autoLinks",function(e,r,t){"use strict";return e=t.converter._dispatch("autoLinks.before",e,r,t),e=e.replace(p,g(r)),e=e.replace(_,m(r,t)),e=t.converter._dispatch("autoLinks.after",e,r,t)}),a.subParser("simplifiedAutoLinks",function(e,r,t){"use strict";return r.simplifiedAutoLink?(e=t.converter._dispatch("simplifiedAutoLinks.before",e,r,t),e=r.excludeTrailingPunctuationFromURLs?e.replace(d,g(r)):e.replace(u,g(r)),e=e.replace(h,m(r,t)),e=t.converter._dispatch("simplifiedAutoLinks.after",e,r,t)):e}),a.subParser("blockGamut",function(e,r,t){"use strict";return e=t.converter._dispatch("blockGamut.before",e,r,t),e=a.subParser("blockQuotes")(e,r,t),e=a.subParser("headers")(e,r,t),e=a.subParser("horizontalRule")(e,r,t),e=a.subParser("lists")(e,r,t),e=a.subParser("codeBlocks")(e,r,t),e=a.subParser("tables")(e,r,t),e=a.subParser("hashHTMLBlocks")(e,r,t),e=a.subParser("paragraphs")(e,r,t),e=t.converter._dispatch("blockGamut.after",e,r,t)}),a.subParser("blockQuotes",function(e,r,t){"use strict";e=t.converter._dispatch("blockQuotes.before",e,r,t),e+="\n\n";var n=/(^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+/gm;return r.splitAdjacentBlockquotes&&(n=/^ {0,3}>[\s\S]*?(?:\n\n)/gm),e=e.replace(n,function(e){return e=e.replace(/^[ \t]*>[ \t]?/gm,""),e=e.replace(/¨0/g,""),e=e.replace(/^[ \t]+$/gm,""),e=a.subParser("githubCodeBlocks")(e,r,t),e=a.subParser("blockGamut")(e,r,t),e=e.replace(/(^|\n)/g,"$1 "),e=e.replace(/(\s*
    [^\r]+?<\/pre>)/gm,function(e,r){var t=r;return t=t.replace(/^  /gm,"¨0"),t=t.replace(/¨0/g,"")}),a.subParser("hashBlock")("
    \n"+e+"\n
    ",r,t)}),e=t.converter._dispatch("blockQuotes.after",e,r,t)}),a.subParser("codeBlocks",function(e,r,t){"use strict";e=t.converter._dispatch("codeBlocks.before",e,r,t);return e=(e+="¨0").replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=¨0))/g,function(e,n,s){var o=n,i=s,l="\n";return o=a.subParser("outdent")(o,r,t),o=a.subParser("encodeCode")(o,r,t),o=a.subParser("detab")(o,r,t),o=o.replace(/^\n+/g,""),o=o.replace(/\n+$/g,""),r.omitExtraWLInCodeBlocks&&(l=""),o="
    "+o+l+"
    ",a.subParser("hashBlock")(o,r,t)+i}),e=e.replace(/¨0/,""),e=t.converter._dispatch("codeBlocks.after",e,r,t)}),a.subParser("codeSpans",function(e,r,t){"use strict";return void 0===(e=t.converter._dispatch("codeSpans.before",e,r,t))&&(e=""),e=e.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,function(e,n,s,o){var i=o;return i=i.replace(/^([ \t]*)/g,""),i=i.replace(/[ \t]*$/g,""),i=a.subParser("encodeCode")(i,r,t),i=n+""+i+"",i=a.subParser("hashHTMLSpans")(i,r,t)}),e=t.converter._dispatch("codeSpans.after",e,r,t)}),a.subParser("completeHTMLDocument",function(e,r,t){"use strict";if(!r.completeHTMLDocument)return e;e=t.converter._dispatch("completeHTMLDocument.before",e,r,t);var a="html",n="\n",s="",o='\n',i="",l="";void 0!==t.metadata.parsed.doctype&&(n="\n","html"!==(a=t.metadata.parsed.doctype.toString().toLowerCase())&&"html5"!==a||(o=''));for(var c in t.metadata.parsed)if(t.metadata.parsed.hasOwnProperty(c))switch(c.toLowerCase()){case"doctype":break;case"title":s=""+t.metadata.parsed.title+"\n";break;case"charset":o="html"===a||"html5"===a?'\n':'\n';break;case"language":case"lang":i=' lang="'+t.metadata.parsed[c]+'"',l+='\n';break;default:l+='\n'}return e=n+"\n\n"+s+o+l+"\n\n"+e.trim()+"\n\n",e=t.converter._dispatch("completeHTMLDocument.after",e,r,t)}),a.subParser("detab",function(e,r,t){"use strict";return e=t.converter._dispatch("detab.before",e,r,t),e=e.replace(/\t(?=\t)/g," "),e=e.replace(/\t/g,"¨A¨B"),e=e.replace(/¨B(.+?)¨A/g,function(e,r){for(var t=r,a=4-t.length%4,n=0;n/g,">"),e=t.converter._dispatch("encodeAmpsAndAngles.after",e,r,t)}),a.subParser("encodeBackslashEscapes",function(e,r,t){"use strict";return e=t.converter._dispatch("encodeBackslashEscapes.before",e,r,t),e=e.replace(/\\(\\)/g,a.helper.escapeCharactersCallback),e=e.replace(/\\([`*_{}\[\]()>#+.!~=|-])/g,a.helper.escapeCharactersCallback),e=t.converter._dispatch("encodeBackslashEscapes.after",e,r,t)}),a.subParser("encodeCode",function(e,r,t){"use strict";return e=t.converter._dispatch("encodeCode.before",e,r,t),e=e.replace(/&/g,"&").replace(//g,">").replace(/([*_{}\[\]\\=~-])/g,a.helper.escapeCharactersCallback),e=t.converter._dispatch("encodeCode.after",e,r,t)}),a.subParser("escapeSpecialCharsWithinTagAttributes",function(e,r,t){"use strict";return e=(e=t.converter._dispatch("escapeSpecialCharsWithinTagAttributes.before",e,r,t)).replace(/<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi,function(e){return e.replace(/(.)<\/?code>(?=.)/g,"$1`").replace(/([\\`*_~=|])/g,a.helper.escapeCharactersCallback)}),e=e.replace(/-]|-[^>])(?:[^-]|-[^-])*)--)>/gi,function(e){return e.replace(/([\\`*_~=|])/g,a.helper.escapeCharactersCallback)}),e=t.converter._dispatch("escapeSpecialCharsWithinTagAttributes.after",e,r,t)}),a.subParser("githubCodeBlocks",function(e,r,t){"use strict";return r.ghCodeBlocks?(e=t.converter._dispatch("githubCodeBlocks.before",e,r,t),e+="¨0",e=e.replace(/(?:^|\n)(?: {0,3})(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n(?: {0,3})\1/g,function(e,n,s,o){var i=r.omitExtraWLInCodeBlocks?"":"\n";return o=a.subParser("encodeCode")(o,r,t),o=a.subParser("detab")(o,r,t),o=o.replace(/^\n+/g,""),o=o.replace(/\n+$/g,""),o="
    "+o+i+"
    ",o=a.subParser("hashBlock")(o,r,t),"\n\n¨G"+(t.ghCodeBlocks.push({text:e,codeblock:o})-1)+"G\n\n"}),e=e.replace(/¨0/,""),t.converter._dispatch("githubCodeBlocks.after",e,r,t)):e}),a.subParser("hashBlock",function(e,r,t){"use strict";return e=t.converter._dispatch("hashBlock.before",e,r,t),e=e.replace(/(^\n+|\n+$)/g,""),e="\n\n¨K"+(t.gHtmlBlocks.push(e)-1)+"K\n\n",e=t.converter._dispatch("hashBlock.after",e,r,t)}),a.subParser("hashCodeTags",function(e,r,t){"use strict";e=t.converter._dispatch("hashCodeTags.before",e,r,t);return e=a.helper.replaceRecursiveRegExp(e,function(e,n,s,o){var i=s+a.subParser("encodeCode")(n,r,t)+o;return"¨C"+(t.gHtmlSpans.push(i)-1)+"C"},"]*>","
    ","gim"),e=t.converter._dispatch("hashCodeTags.after",e,r,t)}),a.subParser("hashElement",function(e,r,t){"use strict";return function(e,r){var a=r;return a=a.replace(/\n\n/g,"\n"),a=a.replace(/^\n/,""),a=a.replace(/\n+$/g,""),a="\n\n¨K"+(t.gHtmlBlocks.push(a)-1)+"K\n\n"}}),a.subParser("hashHTMLBlocks",function(e,r,t){"use strict";e=t.converter._dispatch("hashHTMLBlocks.before",e,r,t);var n=["pre","div","h1","h2","h3","h4","h5","h6","blockquote","table","dl","ol","ul","script","noscript","form","fieldset","iframe","math","style","section","header","footer","nav","article","aside","address","audio","canvas","figure","hgroup","output","video","p"],s=function(e,r,a,n){var s=e;return-1!==a.search(/\bmarkdown\b/)&&(s=a+t.converter.makeHtml(r)+n),"\n\n¨K"+(t.gHtmlBlocks.push(s)-1)+"K\n\n"};r.backslashEscapesHTMLTags&&(e=e.replace(/\\<(\/?[^>]+?)>/g,function(e,r){return"<"+r+">"}));for(var o=0;o]*>)","im"),c="<"+n[o]+"\\b[^>]*>",u="";-1!==(i=a.helper.regexIndexOf(e,l));){var d=a.helper.splitAtIndex(e,i),p=a.helper.replaceRecursiveRegExp(d[1],s,c,u,"im");if(p===d[1])break;e=d[0].concat(p)}return e=e.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,a.subParser("hashElement")(e,r,t)),e=a.helper.replaceRecursiveRegExp(e,function(e){return"\n\n¨K"+(t.gHtmlBlocks.push(e)-1)+"K\n\n"},"^ {0,3}\x3c!--","--\x3e","gm"),e=e.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,a.subParser("hashElement")(e,r,t)),e=t.converter._dispatch("hashHTMLBlocks.after",e,r,t)}),a.subParser("hashHTMLSpans",function(e,r,t){"use strict";function a(e){return"¨C"+(t.gHtmlSpans.push(e)-1)+"C"}return e=t.converter._dispatch("hashHTMLSpans.before",e,r,t),e=e.replace(/<[^>]+?\/>/gi,function(e){return a(e)}),e=e.replace(/<([^>]+?)>[\s\S]*?<\/\1>/g,function(e){return a(e)}),e=e.replace(/<([^>]+?)\s[^>]+?>[\s\S]*?<\/\1>/g,function(e){return a(e)}),e=e.replace(/<[^>]+?>/gi,function(e){return a(e)}),e=t.converter._dispatch("hashHTMLSpans.after",e,r,t)}),a.subParser("unhashHTMLSpans",function(e,r,t){"use strict";e=t.converter._dispatch("unhashHTMLSpans.before",e,r,t);for(var a=0;a]*>\\s*]*>","^ {0,3}\\s*
    ","gim"),e=t.converter._dispatch("hashPreCodeTags.after",e,r,t)}),a.subParser("headers",function(e,r,t){"use strict";function n(e){var n,s;if(r.customizedHeaderId){var o=e.match(/\{([^{]+?)}\s*$/);o&&o[1]&&(e=o[1])}return n=e,s=a.helper.isString(r.prefixHeaderId)?r.prefixHeaderId:!0===r.prefixHeaderId?"section-":"",r.rawPrefixHeaderId||(n=s+n),n=r.ghCompatibleHeaderId?n.replace(/ /g,"-").replace(/&/g,"").replace(/¨T/g,"").replace(/¨D/g,"").replace(/[&+$,\/:;=?@"#{}|^¨~\[\]`\\*)(%.!'<>]/g,"").toLowerCase():r.rawHeaderId?n.replace(/ /g,"-").replace(/&/g,"&").replace(/¨T/g,"¨").replace(/¨D/g,"$").replace(/["']/g,"-").toLowerCase():n.replace(/[^\w]/g,"").toLowerCase(),r.rawPrefixHeaderId&&(n=s+n),t.hashLinkCounts[n]?n=n+"-"+t.hashLinkCounts[n]++:t.hashLinkCounts[n]=1,n}e=t.converter._dispatch("headers.before",e,r,t);var s=isNaN(parseInt(r.headerLevelStart))?1:parseInt(r.headerLevelStart),o=r.smoothLivePreview?/^(.+)[ \t]*\n={2,}[ \t]*\n+/gm:/^(.+)[ \t]*\n=+[ \t]*\n+/gm,i=r.smoothLivePreview?/^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm:/^(.+)[ \t]*\n-+[ \t]*\n+/gm;e=(e=e.replace(o,function(e,o){var i=a.subParser("spanGamut")(o,r,t),l=r.noHeaderId?"":' id="'+n(o)+'"',c=""+i+"";return a.subParser("hashBlock")(c,r,t)})).replace(i,function(e,o){var i=a.subParser("spanGamut")(o,r,t),l=r.noHeaderId?"":' id="'+n(o)+'"',c=s+1,u=""+i+"";return a.subParser("hashBlock")(u,r,t)});var l=r.requireSpaceBeforeHeadingText?/^(#{1,6})[ \t]+(.+?)[ \t]*#*\n+/gm:/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm;return e=e.replace(l,function(e,o,i){var l=i;r.customizedHeaderId&&(l=i.replace(/\s?\{([^{]+?)}\s*$/,""));var c=a.subParser("spanGamut")(l,r,t),u=r.noHeaderId?"":' id="'+n(i)+'"',d=s-1+o.length,p=""+c+"";return a.subParser("hashBlock")(p,r,t)}),e=t.converter._dispatch("headers.after",e,r,t)}),a.subParser("horizontalRule",function(e,r,t){"use strict";e=t.converter._dispatch("horizontalRule.before",e,r,t);var n=a.subParser("hashBlock")("
    ",r,t);return e=e.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm,n),e=e.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm,n),e=e.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm,n),e=t.converter._dispatch("horizontalRule.after",e,r,t)}),a.subParser("images",function(e,r,t){"use strict";function n(e,r,n,s,o,i,l,c){var u=t.gUrls,d=t.gTitles,p=t.gDimensions;if(n=n.toLowerCase(),c||(c=""),e.search(/\(? ?(['"].*['"])?\)$/m)>-1)s="";else if(""===s||null===s){if(""!==n&&null!==n||(n=r.toLowerCase().replace(/ ?\n/g," ")),s="#"+n,a.helper.isUndefined(u[n]))return e;s=u[n],a.helper.isUndefined(d[n])||(c=d[n]),a.helper.isUndefined(p[n])||(o=p[n].width,i=p[n].height)}r=r.replace(/"/g,""").replace(a.helper.regexes.asteriskDashAndColon,a.helper.escapeCharactersCallback);var h=''+r+'"}return e=(e=t.converter._dispatch("images.before",e,r,t)).replace(/!\[([^\]]*?)] ?(?:\n *)?\[([\s\S]*?)]()()()()()/g,n),e=e.replace(/!\[([^\]]*?)][ \t]*()\([ \t]??(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g,function(e,r,t,a,s,o,i,l){return a=a.replace(/\s/g,""),n(e,r,t,a,s,o,0,l)}),e=e.replace(/!\[([^\]]*?)][ \t]*()\([ \t]?<([^>]*)>(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(?:(["'])([^"]*?)\6))?[ \t]?\)/g,n),e=e.replace(/!\[([^\]]*?)][ \t]*()\([ \t]??(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g,n),e=e.replace(/!\[([^\[\]]+)]()()()()()/g,n),e=t.converter._dispatch("images.after",e,r,t)}),a.subParser("italicsAndBold",function(e,r,t){"use strict";function a(e,r,t){return r+e+t}return e=t.converter._dispatch("italicsAndBold.before",e,r,t),e=r.literalMidWordUnderscores?(e=(e=e.replace(/\b___(\S[\s\S]*?)___\b/g,function(e,r){return a(r,"","")})).replace(/\b__(\S[\s\S]*?)__\b/g,function(e,r){return a(r,"","")})).replace(/\b_(\S[\s\S]*?)_\b/g,function(e,r){return a(r,"","")}):(e=(e=e.replace(/___(\S[\s\S]*?)___/g,function(e,r){return/\S$/.test(r)?a(r,"",""):e})).replace(/__(\S[\s\S]*?)__/g,function(e,r){return/\S$/.test(r)?a(r,"",""):e})).replace(/_([^\s_][\s\S]*?)_/g,function(e,r){return/\S$/.test(r)?a(r,"",""):e}),e=r.literalMidWordAsterisks?(e=(e=e.replace(/([^*]|^)\B\*\*\*(\S[\s\S]*?)\*\*\*\B(?!\*)/g,function(e,r,t){return a(t,r+"","")})).replace(/([^*]|^)\B\*\*(\S[\s\S]*?)\*\*\B(?!\*)/g,function(e,r,t){return a(t,r+"","")})).replace(/([^*]|^)\B\*(\S[\s\S]*?)\*\B(?!\*)/g,function(e,r,t){return a(t,r+"","")}):(e=(e=e.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g,function(e,r){return/\S$/.test(r)?a(r,"",""):e})).replace(/\*\*(\S[\s\S]*?)\*\*/g,function(e,r){return/\S$/.test(r)?a(r,"",""):e})).replace(/\*([^\s*][\s\S]*?)\*/g,function(e,r){return/\S$/.test(r)?a(r,"",""):e}),e=t.converter._dispatch("italicsAndBold.after",e,r,t)}),a.subParser("lists",function(e,r,t){"use strict";function n(e,n){t.gListLevel++,e=e.replace(/\n{2,}$/,"\n");var s=/(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0| {0,3}([*+-]|\d+[.])[ \t]+))/gm,o=/\n[ \t]*\n(?!¨0)/.test(e+="¨0");return r.disableForced4SpacesIndentedSublists&&(s=/(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0|\2([*+-]|\d+[.])[ \t]+))/gm),e=e.replace(s,function(e,n,s,i,l,c,u){u=u&&""!==u.trim();var d=a.subParser("outdent")(l,r,t),p="";return c&&r.tasklists&&(p=' class="task-list-item" style="list-style-type: none;"',d=d.replace(/^[ \t]*\[(x|X| )?]/m,function(){var e='-1?(d=a.subParser("githubCodeBlocks")(d,r,t),d=a.subParser("blockGamut")(d,r,t)):(d=(d=a.subParser("lists")(d,r,t)).replace(/\n$/,""),d=(d=a.subParser("hashHTMLBlocks")(d,r,t)).replace(/\n\n+/g,"\n\n"),d=o?a.subParser("paragraphs")(d,r,t):a.subParser("spanGamut")(d,r,t)),d=d.replace("¨A",""),d=""+d+"\n"}),e=e.replace(/¨0/g,""),t.gListLevel--,n&&(e=e.replace(/\s+$/,"")),e}function s(e,r){if("ol"===r){var t=e.match(/^ *(\d+)\./);if(t&&"1"!==t[1])return' start="'+t[1]+'"'}return""}function o(e,t,a){var o=r.disableForced4SpacesIndentedSublists?/^ ?\d+\.[ \t]/gm:/^ {0,3}\d+\.[ \t]/gm,i=r.disableForced4SpacesIndentedSublists?/^ ?[*+-][ \t]/gm:/^ {0,3}[*+-][ \t]/gm,l="ul"===t?o:i,c="";if(-1!==e.search(l))!function r(u){var d=u.search(l),p=s(e,t);-1!==d?(c+="\n\n<"+t+p+">\n"+n(u.slice(0,d),!!a)+"\n",l="ul"===(t="ul"===t?"ol":"ul")?o:i,r(u.slice(d))):c+="\n\n<"+t+p+">\n"+n(u,!!a)+"\n"}(e);else{var u=s(e,t);c="\n\n<"+t+u+">\n"+n(e,!!a)+"\n"}return c}return e=t.converter._dispatch("lists.before",e,r,t),e+="¨0",e=t.gListLevel?e.replace(/^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,function(e,r,t){return o(r,t.search(/[*+-]/g)>-1?"ul":"ol",!0)}):e.replace(/(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,function(e,r,t,a){return o(t,a.search(/[*+-]/g)>-1?"ul":"ol",!1)}),e=e.replace(/¨0/,""),e=t.converter._dispatch("lists.after",e,r,t)}),a.subParser("metadata",function(e,r,t){"use strict";function a(e){t.metadata.raw=e,(e=(e=e.replace(/&/g,"&").replace(/"/g,""")).replace(/\n {4}/g," ")).replace(/^([\S ]+): +([\s\S]+?)$/gm,function(e,r,a){return t.metadata.parsed[r]=a,""})}return r.metadata?(e=t.converter._dispatch("metadata.before",e,r,t),e=e.replace(/^\s*«««+(\S*?)\n([\s\S]+?)\n»»»+\n/,function(e,r,t){return a(t),"¨M"}),e=e.replace(/^\s*---+(\S*?)\n([\s\S]+?)\n---+\n/,function(e,r,n){return r&&(t.metadata.format=r),a(n),"¨M"}),e=e.replace(/¨M/g,""),e=t.converter._dispatch("metadata.after",e,r,t)):e}),a.subParser("outdent",function(e,r,t){"use strict";return e=t.converter._dispatch("outdent.before",e,r,t),e=e.replace(/^(\t|[ ]{1,4})/gm,"¨0"),e=e.replace(/¨0/g,""),e=t.converter._dispatch("outdent.after",e,r,t)}),a.subParser("paragraphs",function(e,r,t){"use strict";for(var n=(e=(e=(e=t.converter._dispatch("paragraphs.before",e,r,t)).replace(/^\n+/g,"")).replace(/\n+$/g,"")).split(/\n{2,}/g),s=[],o=n.length,i=0;i=0?s.push(l):l.search(/\S/)>=0&&(l=(l=a.subParser("spanGamut")(l,r,t)).replace(/^([ \t]*)/g,"

    "),l+="

    ",s.push(l))}for(o=s.length,i=0;i]*>\s*]*>/.test(u)&&(d=!0)}s[i]=u}return e=s.join("\n"),e=e.replace(/^\n+/g,""),e=e.replace(/\n+$/g,""),t.converter._dispatch("paragraphs.after",e,r,t)}),a.subParser("runExtension",function(e,r,t,a){"use strict";if(e.filter)r=e.filter(r,a.converter,t);else if(e.regex){var n=e.regex;n instanceof RegExp||(n=new RegExp(n,"g")),r=r.replace(n,e.replace)}return r}),a.subParser("spanGamut",function(e,r,t){"use strict";return e=t.converter._dispatch("spanGamut.before",e,r,t),e=a.subParser("codeSpans")(e,r,t),e=a.subParser("escapeSpecialCharsWithinTagAttributes")(e,r,t),e=a.subParser("encodeBackslashEscapes")(e,r,t),e=a.subParser("images")(e,r,t),e=a.subParser("anchors")(e,r,t),e=a.subParser("autoLinks")(e,r,t),e=a.subParser("simplifiedAutoLinks")(e,r,t),e=a.subParser("emoji")(e,r,t),e=a.subParser("underline")(e,r,t),e=a.subParser("italicsAndBold")(e,r,t),e=a.subParser("strikethrough")(e,r,t),e=a.subParser("ellipsis")(e,r,t),e=a.subParser("hashHTMLSpans")(e,r,t),e=a.subParser("encodeAmpsAndAngles")(e,r,t),r.simpleLineBreaks?/\n\n¨K/.test(e)||(e=e.replace(/\n+/g,"
    \n")):e=e.replace(/ +\n/g,"
    \n"),e=t.converter._dispatch("spanGamut.after",e,r,t)}),a.subParser("strikethrough",function(e,r,t){"use strict";return r.strikethrough&&(e=(e=t.converter._dispatch("strikethrough.before",e,r,t)).replace(/(?:~){2}([\s\S]+?)(?:~){2}/g,function(e,n){return function(e){return r.simplifiedAutoLink&&(e=a.subParser("simplifiedAutoLinks")(e,r,t)),""+e+""}(n)}),e=t.converter._dispatch("strikethrough.after",e,r,t)),e}),a.subParser("stripLinkDefinitions",function(e,r,t){"use strict";var n=function(e,n,s,o,i,l,c){return n=n.toLowerCase(),s.match(/^data:.+?\/.+?;base64,/)?t.gUrls[n]=s.replace(/\s/g,""):t.gUrls[n]=a.subParser("encodeAmpsAndAngles")(s,r,t),l?l+c:(c&&(t.gTitles[n]=c.replace(/"|'/g,""")),r.parseImgDimensions&&o&&i&&(t.gDimensions[n]={width:o,height:i}),"")};return e=(e+="¨0").replace(/^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n\n|(?=¨0)|(?=\n\[))/gm,n),e=e.replace(/^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*\s]+)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=¨0))/gm,n),e=e.replace(/¨0/,"")}),a.subParser("tables",function(e,r,t){"use strict";function n(e){return/^:[ \t]*--*$/.test(e)?' style="text-align:left;"':/^--*[ \t]*:[ \t]*$/.test(e)?' style="text-align:right;"':/^:[ \t]*--*[ \t]*:$/.test(e)?' style="text-align:center;"':""}function s(e,n){var s="";return e=e.trim(),(r.tablesHeaderId||r.tableHeaderId)&&(s=' id="'+e.replace(/ /g,"_").toLowerCase()+'"'),e=a.subParser("spanGamut")(e,r,t),""+e+"\n"}function o(e,n){return""+a.subParser("spanGamut")(e,r,t)+"\n"}function i(e){var i,l=e.split("\n");for(i=0;i\n\n\n",n=0;n\n";for(var s=0;s\n"}return t+="\n\n"}(p,_)}if(!r.tables)return e;return e=t.converter._dispatch("tables.before",e,r,t),e=e.replace(/\\(\|)/g,a.helper.escapeCharactersCallback),e=e.replace(/^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|¨0)/gm,i),e=e.replace(/^ {0,3}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|¨0)/gm,i),e=t.converter._dispatch("tables.after",e,r,t)}),a.subParser("underline",function(e,r,t){"use strict";return r.underline?(e=t.converter._dispatch("underline.before",e,r,t),e=r.literalMidWordUnderscores?(e=e.replace(/\b___(\S[\s\S]*?)___\b/g,function(e,r){return""+r+""})).replace(/\b__(\S[\s\S]*?)__\b/g,function(e,r){return""+r+""}):(e=e.replace(/___(\S[\s\S]*?)___/g,function(e,r){return/\S$/.test(r)?""+r+"":e})).replace(/__(\S[\s\S]*?)__/g,function(e,r){return/\S$/.test(r)?""+r+"":e}),e=e.replace(/(_)/g,a.helper.escapeCharactersCallback),e=t.converter._dispatch("underline.after",e,r,t)):e}),a.subParser("unescapeSpecialChars",function(e,r,t){"use strict";return e=t.converter._dispatch("unescapeSpecialChars.before",e,r,t),e=e.replace(/¨E(\d+)E/g,function(e,r){var t=parseInt(r);return String.fromCharCode(t)}),e=t.converter._dispatch("unescapeSpecialChars.after",e,r,t)}),a.subParser("makeMarkdown.blockquote",function(e,r){"use strict";var t="";if(e.hasChildNodes())for(var n=e.childNodes,s=n.length,o=0;o "+t.split("\n").join("\n> ")}),a.subParser("makeMarkdown.codeBlock",function(e,r){"use strict";var t=e.getAttribute("language"),a=e.getAttribute("precodenum");return"```"+t+"\n"+r.preList[a]+"\n```"}),a.subParser("makeMarkdown.codeSpan",function(e){"use strict";return"`"+e.innerHTML+"`"}),a.subParser("makeMarkdown.emphasis",function(e,r){"use strict";var t="";if(e.hasChildNodes()){t+="*";for(var n=e.childNodes,s=n.length,o=0;o",e.hasAttribute("width")&&e.hasAttribute("height")&&(r+=" ="+e.getAttribute("width")+"x"+e.getAttribute("height")),e.hasAttribute("title")&&(r+=' "'+e.getAttribute("title")+'"'),r+=")"),r}),a.subParser("makeMarkdown.links",function(e,r){"use strict";var t="";if(e.hasChildNodes()&&e.hasAttribute("href")){var n=e.childNodes,s=n.length;t="[";for(var o=0;o",e.hasAttribute("title")&&(t+=' "'+e.getAttribute("title")+'"'),t+=")"}return t}),a.subParser("makeMarkdown.list",function(e,r,t){"use strict";var n="";if(!e.hasChildNodes())return"";for(var s=e.childNodes,o=s.length,i=e.getAttribute("start")||1,l=0;l"+r.preList[t]+""}),a.subParser("makeMarkdown.strikethrough",function(e,r){"use strict";var t="";if(e.hasChildNodes()){t+="~~";for(var n=e.childNodes,s=n.length,o=0;otr>th"),l=e.querySelectorAll("tbody>tr");for(t=0;t_&&(_=g)}for(t=0;t/g,"\\$1>"),r=r.replace(/^#/gm,"\\#"),r=r.replace(/^(\s*)([-=]{3,})(\s*)$/,"$1\\$2$3"),r=r.replace(/^( {0,3}\d+)\./gm,"$1\\."),r=r.replace(/^( {0,3})([+-])/gm,"$1\\$2"),r=r.replace(/]([\s]*)\(/g,"\\]$1\\("),r=r.replace(/^ {0,3}\[([\S \t]*?)]:/gm,"\\[$1]:")});"function"==typeof define&&define.amd?define(function(){"use strict";return a}):"undefined"!=typeof module&&module.exports?module.exports=a:this.showdown=a}).call(this); +//# sourceMappingURL=showdown.min.js.map diff --git a/bundles/flintstones.helper.html/assets/js/snarkdown.umd.js b/bundles/flintstones.helper.html/assets/js/snarkdown.umd.js new file mode 100644 index 0000000..6a59f64 --- /dev/null +++ b/bundles/flintstones.helper.html/assets/js/snarkdown.umd.js @@ -0,0 +1,2 @@ +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.snarkdown=n()}(this,function(){function e(e){return e.replace(RegExp("^"+(e.match(/^(\t| )+/)||"")[0],"gm"),"")}function n(e){return e.replace(/"/g,""")}function r(o){function c(e){var n=e.replace(/\*/g,"_").replace(/^( {2}\n\n*|\n{2,})/g,"\n\n"),r=f[f.length-1]===e,o=t[n];return o?o[1]?(f[r?"pop":"push"](e),o[r?1:0]):o[0]:e}function a(){for(var e="",n=f.length;n--;)e+=c(f[n]);return e}var l,u,s,p,g,i=/(?:^```(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:\!\[([^\]]*?)\]\(([^\)]+?)\))|(\[)|(\](?:\(([^\)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(\-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,3})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*])/gm,f=[],d="",m=0,h={};for(o=o.replace(/^\n+|\n+$/g,"").replace(/^\[(.+?)\]:\s*(.+)$/gm,function(e,n,r){return h[n.toLowerCase()]=r,""});s=i.exec(o);)u=o.substring(m,s.index),m=i.lastIndex,l=s[0],u.match(/[^\\](\\\\)*\\$/)||(s[2]||s[3]?l='
    '+e((s[2]||s[3]).replace(/^\n+|\n+$/g,""))+"
    ":s[5]?(g=s[5],"."===g.charAt(g.length-1)&&(g=".",s[4]=s[4].replace(/^\d+/gm,"")),p=r(e(s[4].replace(/^\s*[>*+.-]/gm,""))),">"!==g&&(g="."===g?"#":"*",p=p.replace(/^(.*)(\n|$)/gm,"
  • $1
  • ")),l=t[g][0]+p+t[g][1]):s[7]?l=''+n(s[6])+'':s[9]?(d=d.replace("",''),l=a()+""):s[8]?l="":s[11]||s[13]?(g="h"+(s[13]?s[13].length:"="===s[12][0]?1:2),l="<"+g+">"+r(s[11]||s[14])+""):s[15]?l=""+s[15]+"":s[16]&&(l=c(s[16]))),d+=u,d+=l;return(d+o.substring(m)+a()).trim()}var t={_:["",""],__:["",""],"\n\n":["
    "],">":["
    ","
    "],"*":["
      ","
    "],"#":["
      ","
    "]};return r}); +//# sourceMappingURL=snarkdown.umd.js.map \ No newline at end of file diff --git a/bundles/flintstones.helper.html/assets/templates/showdown.template.js b/bundles/flintstones.helper.html/assets/templates/showdown.template.js new file mode 100644 index 0000000..353ba87 --- /dev/null +++ b/bundles/flintstones.helper.html/assets/templates/showdown.template.js @@ -0,0 +1,12 @@ +/* Library snarkdown umd */ +%s + +var target = document.getElementById("content"); +var source = document.getElementById("markdown-text"); + +var converter = new showdown.Converter(), + text = source.innerHTML, + html = converter.makeHtml(text); + +target.innerHTML = html; + diff --git a/bundles/flintstones.helper.html/assets/templates/snarkdown.template.js b/bundles/flintstones.helper.html/assets/templates/snarkdown.template.js new file mode 100644 index 0000000..8b30efb --- /dev/null +++ b/bundles/flintstones.helper.html/assets/templates/snarkdown.template.js @@ -0,0 +1,8 @@ +/* Library snarkdown umd */ +%s + +var target = document.getElementById("content"); +var source = document.getElementById("markdown-text"); + +var html = snarkdown(source.innerHTML); +target.innerHTML = html; diff --git a/bundles/flintstones.helper.html/build.properties b/bundles/flintstones.helper.html/build.properties new file mode 100644 index 0000000..70ab445 --- /dev/null +++ b/bundles/flintstones.helper.html/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + assets/ diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlExp.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlExp.java new file mode 100644 index 0000000..5afdef0 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlExp.java @@ -0,0 +1,54 @@ +package flintstones.helper.html; + + +import org.eclipse.swt.widgets.Composite; +import org.osgi.framework.FrameworkUtil; + +import flintstones.helper.FileHelper; +import flintstones.helper.html.function.JConsoleFunction; +import flintstones.helper.html.function.JConsoleLog; + +/** + * The Class HtmlTextTable. + */ +public class HtmlExp extends HtmlWidget { + + /** The html. */ + private StringBuilder html = new StringBuilder(); + + /** + * Instantiates a new html table. + * + * @param base the base + * @param values the values + * @param vertical the vertical + */ + public HtmlExp(Composite base) { + super(base); + + new JConsoleLog(browser, "jConsoleLog"); + new JConsoleFunction(browser, "prueba"); + + html.append(""); + html.append(""); + + } + + /* (non-Javadoc) + * @see flintstones.helper.html.table.HtmlWidget#getResult() + */ + @Override + protected String getResult() { + return html.toString(); + } + + @Override + String getScript() { + String js = FileHelper.readFile("./assets/js/exp.js", FrameworkUtil.getBundle(getClass())); + StringBuilder sb = new StringBuilder(); + sb.append(js); + return sb.toString(); + } + + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlMarkdown.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlMarkdown.java new file mode 100644 index 0000000..073bbfa --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlMarkdown.java @@ -0,0 +1,123 @@ +package flintstones.helper.html; + +import java.io.IOException; +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.swt.widgets.Composite; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; + +import flintstones.helper.FileHelper; +import flintstones.helper.html.tags.Div; +import flintstones.helper.html.tags.HtmlTag; +import flintstones.helper.html.tags.Text; + +/** + * The Class HtmlMarkdown. + */ +public class HtmlMarkdown extends HtmlWidget { + /** + * Instantiates a new html markdown. + * + * @param base the base + */ + public HtmlMarkdown(Composite base) { + super(base); + HtmlTag div = body.add(new Div()); + div.setId("content"); + } + + public void setFile(String markdownFile) { + setFile(markdownFile,null); + } + + public void setFile(String markdownFile, Bundle bundle) { + + if(bundle != null) + markdownFile = fixImagesPath(markdownFile, bundle); + + HtmlTag div = body.add(new Div()); + div.setId("markdown-text"); + div.addClass("markdown-invisible"); + div.add(new Text(markdownFile)); + + } + + /* (non-Javadoc) + * @see flintstones.helper.html.table.HtmlWidget#getResult() + */ + @Override + protected String getResult() { + return body.toString(); + } + + /* (non-Javadoc) + * @see flintstones.helper.html.table.HtmlWidget#getScript() + */ + @Override + String getScript() { + String markdownLibrary = FileHelper.readFile("./assets/js/showdown.min.js", FrameworkUtil.getBundle(getClass())); + String jsTemplate = FileHelper.readFile("./assets/templates/showdown.template.js", FrameworkUtil.getBundle(getClass())); + + StringBuilder sb = new StringBuilder(); + sb.append(String.format(jsTemplate, markdownLibrary)); + return sb.toString(); + } + + /* (non-Javadoc) + * @see flintstones.helper.html.table.HtmlWidget#getStyle() + */ + @Override + protected String getStyle(){ + return ".markdown-invisible {display: none;} #content{text-align: justify !important;} img { width: 100%; } pre {background-color: aliceblue; }"; + } + + + /** + * Fix images path to point the path in the filesystem + * Convert: + * ![imagen](borrar/tpr.jpg) + * into: + * [imagen](file:/C:/Users/igmunoz/Desktop/Eclipse RCP/eclipse/../flintstones/bundles/flintstones.application.debug/borrar/tpr.jpg) + * + * @param markdown the markdown + * @param bundle the bundle + * @return the string + */ + private String fixImagesPath(String markdown, Bundle bundle) { + + StringBuilder sb = new StringBuilder(); + for(String line : markdown.split("\n")) { + + // Image linea + if(line.startsWith("!")) { + String[] parts = line.split("\\("); + + // Online images will not be processed + String path = parts[1].replace(")",""); + if(path.startsWith("http")) + continue; + + URL url = bundle.getEntry(path); + String diskPath = null; + try { + URL fileUrl = FileLocator.toFileURL(url); + diskPath = fileUrl.toString(); + } catch (IOException | NullPointerException e ) { + e.printStackTrace(); +// return "# Fichero no encontrado " + url; + } + + diskPath = diskPath.replaceAll(" ", "%20"); + line = parts[0] + "(" + diskPath + ")"; + } + sb.append(line); + sb.append("\n"); + } + + return sb.toString(); + } + + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlMatrix.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlMatrix.java new file mode 100644 index 0000000..98cb430 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlMatrix.java @@ -0,0 +1,41 @@ +package flintstones.helper.html; + +import org.eclipse.swt.widgets.Composite; +import org.osgi.framework.FrameworkUtil; + +import flintstones.helper.FileHelper; +import flintstones.helper.html.tags.B; +import flintstones.helper.html.tags.HtmlTag; +import flintstones.helper.html.tags.Table; +import flintstones.helper.html.tags.Td; +import flintstones.helper.html.tags.Text; +import flintstones.helper.html.tags.Tr; + +public class HtmlMatrix extends HtmlWidget { + + public HtmlMatrix(Composite base, String[][] values) { + super(base); + + HtmlTag table = body.add(new Table()); + table.addClass("matrix"); + + for (String[] row : values) { + HtmlTag tr = table.add(new Tr()); + for (String val : row) { + HtmlTag td = tr.add(new Td()); + td.add(new B().add(new Text(val))); + } + } + } + + @Override + protected String getResult() { + return body.toString(); + } + + @Override + protected String getStyle() { + return FileHelper.readFile("./assets/css/ahpmatrix.css", FrameworkUtil.getBundle(getClass())); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlWidget.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlWidget.java new file mode 100644 index 0000000..2867924 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/HtmlWidget.java @@ -0,0 +1,189 @@ +package flintstones.helper.html; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map.Entry; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.osgi.framework.FrameworkUtil; + +import flintstones.helper.FileHelper; +import flintstones.helper.html.tags.Body; +import flintstones.helper.html.tags.Div; +import flintstones.helper.html.tags.HtmlTag; + +/** + * The Class HtmlWidget. + */ +public abstract class HtmlWidget { + + /** The base. */ + Composite base; + + /** The browser. */ + protected Browser browser; + protected HtmlTag disabled = new Div(); + protected HtmlTag body = new Body(); + + boolean debug = false; + boolean isDisabled = false; + + private HashMap> userCss = new HashMap<>(); + + /** + * Instantiates a new html widget. + * + * @param base the base + */ + public HtmlWidget(Composite base) { + + this.base = base; + + // If the composite to draw had an HtmlWidget, it just delete it so this new + // widget will replace it. + // It the composite have any other item, exception. + if (base.getChildren().length > 0) { + Arrays.stream(base.getChildren()).forEach(k -> { + if (k instanceof Browser) { + k.dispose(); + } else { + throw new RuntimeException("Composite must have a HTMLWidget or be empty"); + } + }); + } + + base.setLayout(new FillLayout()); + + browser = new Browser(base, SWT.NONE); + browser.setText(""); + + base.layout(); + + body.add(disabled); + + } + + /** + * Render. + */ + public void render() { + StringBuilder sb = new StringBuilder(); + sb.append(""); + sb.append(getResult()); + + // Style + sb.append(""); + + // Script + sb.append(""); + + sb.append(""); + + browser.setText(sb.toString()); + } + + /** + * Gets the result. + * + * @return the result + */ + protected abstract String getResult(); + + /** + * Gets the style. + * + * @return the style + */ + protected String getStyle() { + return ""; + }; + + /** + * Gets the script. + * + * @return the script + */ + String getScript() { + return ""; + }; + + /** + * Gets the base style. + * + * @return the base style + */ + private String getBaseStyle() { + return FileHelper.readFile("./assets/css/widget.css", FrameworkUtil.getBundle(getClass())); + } + + private String getBaseScript() { + if (!debug) + return ""; + return FileHelper.readFile("./assets/js/debug.js", FrameworkUtil.getBundle(getClass())); + } + + /** + * Gets the parent. + * + * @return the parent + */ + public Composite getParent() { + return base; + } + + public void setCss(String selector, String key, String value) { + HashMap selectorMap = userCss.get(selector); + if (selectorMap == null) + selectorMap = new HashMap<>(); + + selectorMap.put(key, value); + userCss.put(selector, selectorMap); + } + + private String getUserStyle() { + + StringBuilder sb = new StringBuilder(); + for (Entry> selectorEntry : userCss.entrySet()) { + String selector = selectorEntry.getKey(); + sb.append(selector); + sb.append("{ "); + for (Entry propertyEntry : selectorEntry.getValue().entrySet()) { + + String key = propertyEntry.getKey(); + String val = propertyEntry.getValue(); + + sb.append(key); + sb.append(":"); + sb.append(val); + sb.append(";"); + + } + sb.append("}"); + } + + return sb.toString(); + } + + public Browser getBrowser() { + return browser; + } + + public void setEnabled(boolean isEnabled) { + if (isEnabled) + disabled.deleteClass("disabled"); + else + disabled.addClass("disabled"); + + render(); + } +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/browser/BrowserShell.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/browser/BrowserShell.java new file mode 100644 index 0000000..8e507e1 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/browser/BrowserShell.java @@ -0,0 +1,68 @@ +package flintstones.helper.html.browser; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; + +import flintstones.helper.debug.DH; +import flintstones.helper.html.HtmlWidget; + +public class BrowserShell { + + private HtmlWidget widget; + private final Shell shell; + + public BrowserShell() { + + shell = new Shell( + Display.getDefault().getActiveShell(), + SWT.RESIZE | + SWT.MAX | + SWT.MIN | + SWT.CLOSE | + SWT.SYSTEM_MODAL + ); + + shell.setLayout(new GridLayout(2, false)); + shell.setBackgroundMode(SWT.INHERIT_FORCE); + + // Toolbar + Menu menuBar = new Menu(shell, SWT.BAR); + MenuItem addFirebugItem = new MenuItem(menuBar, SWT.PUSH); + + addFirebugItem.setText("Debugger"); + addFirebugItem.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + widget.getBrowser().setUrl("javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');"); + } + + }); + + shell.setMenuBar(menuBar); + + + + } + + public Shell get() { + return shell; + } + + public void setWidget(HtmlWidget widget) { + this.widget = widget; + } + + public void open() { + DH.out("Hook things here"); + + shell.open(); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/function/JConsoleFunction.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/function/JConsoleFunction.java new file mode 100644 index 0000000..43f067c --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/function/JConsoleFunction.java @@ -0,0 +1,20 @@ +package flintstones.helper.html.function; + +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.BrowserFunction; + +import flintstones.helper.debug.DH; + +public class JConsoleFunction extends BrowserFunction { + + public JConsoleFunction(Browser browser, String name) { + super(browser, name); + } + + @Override + public Object function(Object[] arguments) { + DH.out(arguments); + return 1; + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/function/JConsoleLog.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/function/JConsoleLog.java new file mode 100644 index 0000000..295108f --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/function/JConsoleLog.java @@ -0,0 +1,19 @@ +package flintstones.helper.html.function; + +import flintstones.helper.debug.DH; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.browser.BrowserFunction; + +public class JConsoleLog extends BrowserFunction { + + public JConsoleLog(Browser browser, String name) { + super(browser, name); + } + + @Override + public Object function(Object[] arguments) { + DH.out(arguments); + return null; + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/Svg.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/Svg.java new file mode 100644 index 0000000..081f381 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/Svg.java @@ -0,0 +1,179 @@ +package flintstones.helper.html.svg; + +import flintstones.helper.html.tags.Text; + +public class Svg { + + public static enum LineStroke{ Normal, Dotted, Dashed }; + public static enum CircleStroke{ Normal, Small, Big, Hollow }; + + public static Tag getVerticalLine(int x, int ystart, int size) { + return getLine(x, ystart, x, ystart + size); + } + + public static Tag getHorizontalLine(int xstart, int y, int size) { + return getLine(xstart, y, xstart+size, y); + } + + public static Tag getLine(int x, int y, int nx, int ny) { + // + Tag line = (Tag) new Tag("line") + .attr("y1",y) + .attr("y2",ny) + .attr("x1",x) + .attr("x2",nx) + .attr("stroke-width", 2) + .attr("fill", "none") + .attr("stroke", "#000"); + return line; + + } + + + public static void addStroke(Tag tag, int textsize, LineStroke stroke) { + if(stroke.equals(LineStroke.Dashed)) + tag.attr("stroke-dasharray",(textsize/4)*5); + if(stroke.equals(LineStroke.Dotted)) + tag.attr("stroke-dasharray",(textsize/4)*1.5); + + } + + public static Tag getText(int x, int y, int size, String textcontent) { + // 555 +// int chars = textcontent.length(); +// double mchars = (double)chars/4; + + double mheight = (size*0.6)/2; // 0.6 -> Ratio alto-ancho de fuentes habitual. + + Tag text = (Tag) new Tag("text") + .attr("x", x) + .attr("y", y ) +// .attr("dx",-(mchars*size) ) + .attr("dy", mheight) + .attr("text-anchor","middle") + .attr("font-size", size); + + text.add(new Text(textcontent)); + return text; + } + + public static Tag getLeftMarker(int x, int y, int size, String textcontent) { + + Tag group = new Tag("g"); + Tag line = getHorizontalLine(x-(size/2), y, size); + Tag text = getText(x - size - size/2, y ,size, textcontent); + + group.add(line); + group.add(text); + + return group; + + } + + + public static Tag getBottomMarker(int x, int y, int size, String textcontent) { + // 555 + + Tag group = new Tag("g"); + Tag line = getVerticalLine(x, y-(size/2), size); + Tag text = getText(x, y + size ,size, textcontent); + + group.add(line); + group.add(text); + + return group; + + } + + public static Tag getStar(int x, int y, int size) { + // + + String points = "100,10 40,198 190,78 10,78 160,198"; + int originalSize = 210; + double prod = (double) size/originalSize; + + int tx = x - size/2; + int ty = y - size/2; + + String translate = "translate("+tx+","+ty+")"; + String scale = "scale("+prod+","+prod+")"; + + Tag star = (Tag) new Tag("polygon") + .attr("transform", translate + " " + scale ) + .attr("points", points); + return star; + + } + + + public static Tag getDot(int x, int y, int size) { + return getDot(x,y,size,CircleStroke.Normal); + } + + public static Tag getDot(int x, int y, int size, CircleStroke stroke) { + + if(stroke.equals(CircleStroke.Small)) + size *= 2; + if(stroke.equals(CircleStroke.Normal)) + size *= 5; + if(stroke.equals(CircleStroke.Big)) + size *= 10; + + // + Tag circle = (Tag) new Tag("circle") + .attr("cx", x ) + .attr("cy", y ) + .attr("r", size); + + + return circle; + + } + + public static Tag getEllipse(int x, int y, int rx, int ry, CircleStroke stroke) { + + Tag circle = (Tag) new Tag("ellipse") + .attr("cx", x ) + .attr("cy", y ) + .attr("rx", rx) + .attr("ry", ry) + .attr("fill","none") + .attr("stroke","black") + .attr("stroke-width","2"); + + return circle; + + } + + public static Tag getRectangle(int x, int y, int x2, int y2) { + + int width = x2-x; + int height = y2-y; + Tag rect = (Tag) new Tag("rect") + .attr("x",x) + .attr("y",y) + .attr("width",width) + .attr("height",height) + .attr("fill","none") + .attr("style","stroke:black; stroke-width: 2"); + return rect; + + } + + public static Tag getBox(int x, int y, int x2, int y2) { + + int width = x2-x; + int height = y2-y; + Tag rect = (Tag) new Tag("rect") + .attr("x",x) + .attr("y",y) + .attr("width",width) + .attr("height",height); +// .attr("style","stroke:black; stroke-width: 2"); + return rect; + + } + + + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/SvgBrowser.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/SvgBrowser.java new file mode 100644 index 0000000..1dcb2e5 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/SvgBrowser.java @@ -0,0 +1,44 @@ +package flintstones.helper.html.svg; + +import org.eclipse.swt.widgets.Composite; + +import flintstones.helper.html.HtmlWidget; +import flintstones.helper.html.svg.chart.SvgChartCanvas; + +public class SvgBrowser extends HtmlWidget { + + SvgCanvas canvas; + + public SvgBrowser(Composite base) { + super(base); + } + + public SvgBrowser(Composite base, SvgChartCanvas canvas) { + super(base); + this.canvas = canvas; + } + + public void setCanvas(SvgCanvas canvas){ + this.canvas = canvas; + } + + @Override + protected String getResult() { + System.out.println(canvas); + return canvas.toString(); + } + + @Override + protected String getStyle() { + return "html, body { margin:0; padding:0; overflow:hidden; background-color: white; } svg { position: absolute; top: 5%; left: 5%; width: 90%; height: 90%; } text:hover {\r\n" + + " paint-order: stroke;\r\n" + + " stroke: #000000;\r\n" + + " stroke-width: 1px;\r\n" + + " stroke-linecap: butt;\r\n" + + " stroke-linejoin: miter;\r\n" + + "}"; + }; + + + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/SvgCanvas.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/SvgCanvas.java new file mode 100644 index 0000000..a319175 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/SvgCanvas.java @@ -0,0 +1,5 @@ +package flintstones.helper.html.svg; + +public class SvgCanvas { + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/Tag.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/Tag.java new file mode 100644 index 0000000..bd83b76 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/Tag.java @@ -0,0 +1,11 @@ +package flintstones.helper.html.svg; + +import flintstones.helper.html.tags.HtmlTag; + +public class Tag extends HtmlTag { + + public Tag(String name) { + super(name); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/chart/SvgChart.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/chart/SvgChart.java new file mode 100644 index 0000000..9d1be14 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/chart/SvgChart.java @@ -0,0 +1,217 @@ +package flintstones.helper.html.svg.chart; + +import flintstones.helper.DoubleHelper; +import flintstones.helper.html.svg.Svg; +import flintstones.helper.html.svg.Tag; +import flintstones.helper.html.svg.Svg.CircleStroke; +import flintstones.helper.html.svg.components.LineSeries; +import flintstones.helper.html.svg.components.Point; + +public class SvgChart extends SvgChartCanvas { + + double maxX; + double maxY; + + public SvgChart(int sizeX, int sizeY, double maxX, double maxY) { + super(sizeX,sizeY); + + this.maxX = maxX; + this.maxY = maxY; + + Tag vline = (Tag) Svg.getVerticalLine(ix, iy, canvasHeigth).attr("stroke-width", 5); + Tag hline = (Tag) Svg.getHorizontalLine(ix, tHeight, canvasWidth).attr("stroke-width", 5); + + svg.add(vline); + svg.add(hline); + } + + public void drawMarkers(boolean left, boolean bottom, double distance) { + + if(bottom) { + for(double i = 0.0; i < maxX; i+= distance) { + Double xper = getXPer(i); + Tag x = getBottonMarker(xper, DoubleHelper.Draw(i)); + svg.add(x); + } + } + + if(left) { + for(double i = 0.0; i < maxY; i+= distance) { + Double yper = getYPer(i); + Tag x = getLeftMarker(yper, DoubleHelper.Draw(i)); + svg.add(x); + } + } + + + } + + public Tag drawHorizontalLine(double ypos, double xposStart, double xposEnd) { + return drawLine(xposStart, ypos, xposEnd, ypos); + } + + public Tag drawHorizontalLine(double ypos) { + return drawHorizontalLine(ypos,0,maxX); + } +// + public Tag drawVerticalLine(double xpos) { + return drawVerticalLine(xpos,0,maxY); + } + + public Tag drawVerticalLine(double xpos, double yposStart, double yposEnd) { + return drawLine(xpos, yposStart, xpos, yposEnd); + } +// + public Tag drawLine(double xposStart, double yposStart, double xposEnd, double yposEnd) { + + Double xperStart = getXPer(xposStart); + Double xperEnd = getXPer(xposEnd); + Double yperStart = getYPer(yposStart); + Double yperEnd = getYPer(yposEnd); + + Tag line = getLine(xperStart, yperStart, xperEnd, yperEnd); + svg.add(line); + return line; + + } +// + public Tag drawText(double xpos, double ypos, double yperExtra, String text) { + + Double xper = getXPer(xpos); + Double yper = getYPer(ypos); + + Tag textE = getText(xper, yper + yperExtra, text); + svg.add(textE); + return textE; + } +// + public Tag drawBottonMarker(double xpos, String text) { + + Double xper = getXPer(xpos); + + Tag x = getBottonMarker(xper, text); + svg.add(x); + return x; + } +// + public Tag drawLeftMarker(double ypos, String text) { + + Double yper = getYPer(ypos); + + Tag x = getLeftMarker(yper, text); + svg.add(x); + return x; + } + + public Tag drawStar(double xpos, double ypos) { + + Double xper = getXPer(xpos); + Double yper = getYPer(ypos); + + Tag x = getStar(xper, yper); + svg.add(x); + return x; + + } + + public Tag drawBox(double xposStart, double yposStart, double xposEnd, double yposEnd) { + + Double xperStart = getXPer(xposStart); + Double xperEnd = getXPer(xposEnd); + Double yperStart = getYPer(yposStart); + Double yperEnd = getYPer(yposEnd); + + Tag rect = getBox(xperStart, yperStart, xperEnd, yperEnd); + svg.add(rect); + return rect; + } +// +// public Tag drawHollowCircle(double xper, double yper, int size ) { +// Tag x = getHollowCircle(xper, yper, size); +// svg.add(x); +// return x; +// } +// +// public Tag drawDot(double xper, double yper) { +// return drawDot(xper, yper, ts/10, CircleStroke.Normal); +// } +// + public Tag drawPoint(Point point, CircleStroke stroke) { + + Double xper = getXPer(point.getFirst()); + Double yper = getYPer(point.getSecond()); + + Tag x = getDot(xper, yper, ts, stroke); + svg.add(x); + + return x; + } + + + public Tag drawLineSeries(LineSeries series) { + + Double x = null; + Double y = null; + String color = series.getColor(); + boolean showLegend = series.showLegend(); + + Tag g = new Tag("g"); + + for(Point point : series.getPoints()) { + + Double nx = getXPer(point.getFirst()); + Double ny = getYPer(point.getSecond()); + + Tag dot = (Tag) getDot(nx, ny, ts/10, CircleStroke.Small) + .attr("stroke",color) + .attr("stroke-width",5) + .attr("fill", color); + + g.add(dot); + + if(x != null && y != null) { + Tag line = getLine(x, y, nx, ny); + g.add(line) + .attr("stroke",color) + .attr("stroke-width",5); + } + + // Valus on the top of the point + String p1Name = DoubleHelper.Draw(point.getFirst()); + String p2Name = DoubleHelper.Draw(point.getSecond()); + + if(showLegend) { + Tag pointName = getText(nx, ny+3, p1Name + " | " + p2Name ); + g.add(pointName); + } + + if(series.showMarkers()) { + Tag bottomMarker = getBottonMarker(nx, p1Name); + svg.add(bottomMarker); + } + + if(series.showMarkers()) { + Tag leftMarker = getLeftMarker(ny, p2Name); + svg.add(leftMarker); + } + + + x = nx; + y = ny; + + } + + svg.add(g); + return g; + + } + + public double getXPer(double xval) { + return (xval / maxX)*100; + } + + public double getYPer(double yval) { + return (yval / maxY)*100; + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/chart/SvgChartCanvas.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/chart/SvgChartCanvas.java new file mode 100644 index 0000000..832b3e5 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/chart/SvgChartCanvas.java @@ -0,0 +1,169 @@ +package flintstones.helper.html.svg.chart; + +import flintstones.helper.html.svg.Svg; +import flintstones.helper.html.svg.SvgCanvas; +import flintstones.helper.html.svg.Tag; +import flintstones.helper.html.svg.Svg.CircleStroke; + +public class SvgChartCanvas extends SvgCanvas { + + // Data + protected int canvasHeigth; + protected int canvasWidth; + + protected int ix; + protected int iy; + protected int ts; + + protected Tag svg; + + protected int tHeight; + protected int tWidth; + + public SvgChartCanvas(int sizeX, int sizeY) { + + // Fill vars + canvasHeigth = sizeY; + canvasWidth = sizeX; + + ix = canvasWidth / 25; + iy = canvasHeigth / 25; + ts = canvasHeigth > canvasWidth ? canvasHeigth / 50 : canvasWidth / 50; + + tHeight = canvasHeigth + iy; + tWidth = canvasWidth + ix; + + svg = (Tag) new Tag("svg") + .attr("xmlns","http://www.w3.org/2000/svg") + .attr("viewbox", "0 0 " + tWidth + " " + tHeight) + .attr("width", "100%") + .attr("height", "100%"); + + } + + + protected Tag getHorizontalLine(double yper, double xperStart, double xperEnd) { + return getLine(xperStart, yper, xperEnd, yper); + } + + protected Tag getHorizontalLine(double yper) { + return getHorizontalLine(yper,0,100); + } + + protected Tag getVerticalLine(double xper) { + return getVerticalLine(xper,0,100); + } + + protected Tag getVerticalLine(double xper, double yperStart, double yperEnd) { + return getLine(xper, yperStart, xper, yperEnd); + } + + protected Tag getLine(double xperStart, double yperStart, double xperEnd, double yperEnd) { + + int xmin = realocateX(xperStart); + int xmax = realocateX(xperEnd); + int ymin = realocateY(yperStart); + int yend = realocateY(yperEnd); + + Tag line = Svg.getLine(xmin+ix, ymin+iy, xmax+ix, yend+iy); + + return line; + + } + + protected Tag getText(double xper, double yper, String text) { + + int x = realocateX(xper); + int y = realocateY(yper); + + Tag textTag = Svg.getText(x+ix, y+iy, ts, text); + + return textTag; + + } + + protected Tag getBottonMarker(double xper, String text) { + int x = realocateX(xper); + Tag marker = Svg.getBottomMarker(x+ix, canvasHeigth + iy, ts, text); + return marker; + } + + protected Tag getLeftMarker(double yper, String text) { + int y = realocateY(yper); + Tag marker = Svg.getLeftMarker(ix, y+iy, ts, text); + return marker; + } + + protected Tag getStar(double xper, double yper) { + int x = realocateX(xper); + int y = realocateY(yper); + + Tag star = Svg.getStar(ix+x, y+iy,ts); + return star; + } + + protected Tag getBox(double xperStart, double yperStart, double xperEnd, double yperEnd) { + + int xmin = realocateX(xperStart); + int xmax = realocateX(xperEnd); + int ymin = realocateY(yperStart); + int yend = realocateY(yperEnd); + + return Svg.getBox(xmin+ix, ymin+iy, xmax+ix, yend+iy); + + } + + protected Tag getHollowCircle(double xper, double yper, int size ) { + + CircleStroke stroke = CircleStroke.Hollow; + int x = realocateX(xper); + int y = realocateY(yper); + int rx = realocateX(size); + int ry = realocateY(100-size); + + Tag elip = Svg.getEllipse(ix+x, y+iy,rx,ry,stroke); + return elip; + } + + protected Tag getDot(double xper, double yper) { + return getDot(xper, yper, ts/10, CircleStroke.Normal); + } + + protected Tag getDot(double xper, double yper, int size, CircleStroke stroke) { + + int x = realocateX(xper); + int y = realocateY(yper); + + Tag circle = Svg.getDot(ix+x, y+iy,size,stroke); + return circle; + } + + private int realocateX(double xper) { + + if(xper < 0.0 || xper > 100.0) + throw new RuntimeException("XPer Between 0,100 :( -> " + xper); + + double prod = (double)canvasWidth / 100.0; + + return (int) (xper*prod); + } + + + private int realocateY(double yper) { + + yper = 100.0 - yper; + + if(yper < 0 || yper > 100.0) + throw new RuntimeException("YPer Between 0,100 :( -> " + yper); + + double prod = (double)canvasHeigth / 100.0; + + return (int) (yper*prod); + } + + @Override + public String toString() { + return svg.toString(); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/components/LineSeries.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/components/LineSeries.java new file mode 100644 index 0000000..49aa941 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/components/LineSeries.java @@ -0,0 +1,56 @@ +package flintstones.helper.html.svg.components; + +import java.util.ArrayList; +import java.util.List; + +public class LineSeries { + + List points = new ArrayList<>(); + + boolean showLegend = false; + boolean showMarkers = false; + + String color = "#ffffff"; + + public LineSeries() {} + + public LineSeries(double[][] pointsM) { + + for(double[] arr : pointsM) { + Point p = new Point(arr[0], arr[1]); + points.add(p); + } + + } + + public void add(Point p) { + points.add(p); + } + + public void add(double a, double b) { + Point p = new Point(a, b); + points.add(p); + } + + public void setColor(String color) { + this.color = color; + } + + public String getColor() { + return color; + } + + public void showLegend(boolean x) {showLegend = x;} + + public boolean showLegend() {return showLegend;} + + public void showMarkers(boolean x) {showMarkers = x;} + + public boolean showMarkers() {return showMarkers;} + + + public List getPoints(){ + return points; + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/components/Point.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/components/Point.java new file mode 100644 index 0000000..df6dd7b --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/svg/components/Point.java @@ -0,0 +1,16 @@ +package flintstones.helper.html.svg.components; + +public class Point { + + double a; + double b; + + public Point(double a, double b) { + this.a = a; + this.b = b; + } + + public double getFirst() {return a;} + public double getSecond() {return b;} + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/table/GenericHtmlTable.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/table/GenericHtmlTable.java new file mode 100644 index 0000000..85222ef --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/table/GenericHtmlTable.java @@ -0,0 +1,310 @@ +package flintstones.helper.html.table; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +import flintstones.helper.html.HtmlWidget; +import flintstones.helper.html.tags.B; +import flintstones.helper.html.tags.HtmlTag; +import flintstones.helper.html.tags.Table; +import flintstones.helper.html.tags.Td; +import flintstones.helper.html.tags.Text; +import flintstones.helper.html.tags.Tr; + +/** + * The Class HtmlTable. + */ +class GenericHtmlTable extends HtmlWidget { + + private int row = 0; + private int col = 0; + + private int numRows = 0; + private int numCols = 0; + + private Composite base; + private Map content; + + /** + * Instantiates a new html table. + * + * @param base the base + * @param values the values + * @param vertical the vertical + */ + public GenericHtmlTable(Composite base, HtmlTag[] values, boolean vertical) { + super(base); + + this.base = base; + + content = new LinkedHashMap<>(); + + HtmlTag table = body.add(new Table()); + if (vertical) { + numRows = values.length; + numCols = 1; + for(int i = 0; i < values.length; i++) { + HtmlTag[] arr = new HtmlTag[1]; + arr[0] = values[i]; + addRow(table, arr); + } + } else { + numRows = 1; + numCols = values.length; + addRow(table, values); + } + } + + /** + * Instantiates a new html table. + * + * @param base the base + * @param values the values + * @param headers the headers + * @param vertical the vertical + */ + public GenericHtmlTable(Composite base, HtmlTag[] values, String[] headers, boolean vertical) { + super(base); + + this.base = base; + + content = new LinkedHashMap<>(); + + HtmlTag table = body.add(new Table()); + if (vertical) { + numRows = values.length; + numCols = 1; + for(int i = 0; i < values.length; i++) { + HtmlTag[] arr = new HtmlTag[1]; + arr[0] = values[i]; + addRow(table, arr, headers[i]); + } + } else { + numRows = 1; + numCols = values.length; + addHeaderRow(table, headers, false); + addRow(table, values); + } + } + + /** + * Instantiates a new html table. + * + * @param base the base + * @param values the values + * @param colHeaders the col headers + * @param rowHeaders the row headers + */ + public GenericHtmlTable(Composite base, HtmlTag[][] values, String[] colHeaders, String[] rowHeaders) { + super(base); + + this.base = base; + + content = new LinkedHashMap<>(); + + numRows = values.length; + numCols = values[0].length; + + HtmlTag table = body.add(new Table()); + addHeaderRow(table, colHeaders, true); + + for(int i = 0; i < values.length; i++) + addRow(table, values[i], rowHeaders[i]); + } + + /** + * Instantiates a new html table. + * + * @param base the base + * @param values the values + * @param colHeaders the col headers + */ + public GenericHtmlTable(Composite base, HtmlTag[][] values, String[] colHeaders) { + super(base); + + this.base = base; + + content = new LinkedHashMap<>(); + + numRows = values.length; + numCols = values[0].length; + + HtmlTag table = body.add(new Table()); + + addHeaderRow(table, colHeaders, false); + + for(int i = 0; i < values.length; i++) + addRow(table, values[i]); + + } + + /** + * Adds the cell. + * + * @param content the content + */ + private void addCell(HtmlTag tr, HtmlTag content) { + String[] classes = new String[] { + "row_" + row, + "col_" + col, + "value_" + content + }; + + HtmlTag td = tr.add(new Td(classes)); + td.add(content); + + this.content.put(td, classes); + + col++; + } + + /** + * Adds the header cell. + * + * @param content the content + * @param isHorizontal the is horizontal + */ + private void addHeaderCell(HtmlTag tr, String content, boolean isHorizontal) { + + String cssClass = isHorizontal ? "table__header-horizontal" : "table__header-vertical"; + HtmlTag td = tr.add(new Td(new String[] {"table__header", cssClass})); + + HtmlTag b = td.add(new B()); + b.add(new Text(content)); + + } + + /** + * Adds the row. + * + * @param values the values + */ + private void addRow(HtmlTag table, HtmlTag[] values) { + this.addRow(table, values, null); + } + + /** + * Adds the row. + * + * @param values the values + * @param rowHeader the row header + */ + private void addRow(HtmlTag table, HtmlTag[] values, String rowHeader) { + + HtmlTag tr = table.add(new Tr()); + + if (rowHeader != null) + addHeaderCell(tr, rowHeader, false); + + for (HtmlTag value : values) + addCell(tr, value); + + col = 0; + row++; + } + + /** + * Adds the header row. + * + * @param values the values + * @param emptyCell the empty cell + */ + private void addHeaderRow(HtmlTag table, String[] values, boolean emptyCell) { + + HtmlTag tr = table.add(new Tr()); + + if(emptyCell) + addHeaderCell(tr, "", true); + + for (String value : values) + addHeaderCell(tr, value, true); + } + + public int getNumberOfRows() { + return numRows; + } + + public int getNumberOfColumns() { + return numCols; + } + + public void refresh(String[][] values) { + HtmlTag[][] valuesTag = Text.asText(values); + + int row, col; + String classes[]; + for(int i = 0; i < valuesTag.length; ++i) { + for(int j = 0; j < valuesTag[i].length; ++j) { + for(HtmlTag tag: content.keySet()) { + classes = content.get(tag); + row = Integer.parseInt(classes[0].replace("row_", "")); + col = Integer.parseInt(classes[1].replace("col_", "")); + if(row == i && col == j) { + tag.clear(); + tag.deleteClass("value_"); + tag.add(valuesTag[row][col]); + break; + } + } + } + } + } + + public void refresh(String[] values) { + HtmlTag[] valuesTag = Text.asText(values); + + int col; + String classes[]; + for(int i = 0; i < valuesTag.length; ++i) { + for(HtmlTag tag: content.keySet()) { + classes = content.get(tag); + col = Integer.parseInt(classes[1].replace("col_", "")); + if(col == i) { + tag.clear(); + tag.deleteClass("value_"); + tag.add(valuesTag[col]); + break; + } + } + } + } + + public void dispose() { + clearContent(); + for(Control child: base.getChildren()) + child.dispose(); + numCols = 0; + numRows = 0; + row = 0; + col = 0; + } + + public void clearContent() { + for(HtmlTag tag: content.keySet()) + tag.remove(); + content.clear(); + } + + /* (non-Javadoc) + * @see flintstones.helper.html.table.HtmlWidget#getResult() + */ + @Override + public String getResult() { + return body.toString(); + } + + /* (non-Javadoc) + * @see flintstones.helper.html.table.HtmlWidget#getStyle() + */ + @Override + protected String getStyle() { + return "table, th, td { border: 1px solid black; }" + + ".table__header{ background-color: aliceblue; width: 10%; white-space: nowrap; }" + + "table { border-collapse: collapse; }" + + "td{ padding: 5px; background-color: white; }" + + "table{ width: 100%; font-size: 13px; }"; + } +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/table/HtmlComboTable.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/table/HtmlComboTable.java new file mode 100644 index 0000000..8690671 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/table/HtmlComboTable.java @@ -0,0 +1,13 @@ +package flintstones.helper.html.table; + +import org.eclipse.swt.widgets.Composite; + +import flintstones.helper.html.tags.HtmlTag; + +public class HtmlComboTable extends GenericHtmlTable { + + public HtmlComboTable(Composite base, HtmlTag[][] values, String[] colHeaders, String[] rowHeaders) { + super(base, values, colHeaders, rowHeaders); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/table/HtmlTextTable.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/table/HtmlTextTable.java new file mode 100644 index 0000000..bf9d7b8 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/table/HtmlTextTable.java @@ -0,0 +1,25 @@ +package flintstones.helper.html.table; + +import org.eclipse.swt.widgets.Composite; + +import flintstones.helper.html.tags.Text; + +public class HtmlTextTable extends GenericHtmlTable { + + public HtmlTextTable(Composite base, String[] values, boolean vertical) { + super(base, Text.asText(values), vertical); + } + + public HtmlTextTable(Composite base, String[] values, String[] headers, boolean vertical) { + super(base, Text.asText(values), headers, vertical); + } + + public HtmlTextTable(Composite base, String[][] values, String[] colHeaders, String[] rowHeaders) { + super(base, Text.asText(values), colHeaders, rowHeaders); + } + + public HtmlTextTable(Composite base, String[][] values, String[] colHeaders) { + super(base, Text.asText(values), colHeaders); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/B.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/B.java new file mode 100644 index 0000000..0d75edd --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/B.java @@ -0,0 +1,13 @@ +package flintstones.helper.html.tags; + +public class B extends HtmlTag { + + public B(String[] classes) { + super("b", classes); + } + + public B() { + super("b"); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Body.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Body.java new file mode 100644 index 0000000..8a3ecd5 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Body.java @@ -0,0 +1,13 @@ +package flintstones.helper.html.tags; + +public class Body extends HtmlTag { + + public Body(String[] classes) { + super("body", classes); + } + + public Body() { + super("body"); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Div.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Div.java new file mode 100644 index 0000000..b857513 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Div.java @@ -0,0 +1,13 @@ +package flintstones.helper.html.tags; + +public class Div extends HtmlTag { + + public Div() { + super("div"); + } + + public Div(String[] classes) { + super("div", classes); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/HtmlTag.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/HtmlTag.java new file mode 100644 index 0000000..113bc87 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/HtmlTag.java @@ -0,0 +1,125 @@ +package flintstones.helper.html.tags; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class HtmlTag { + + protected String id; + protected Set classes = new HashSet<>(); + protected List childNodes = new ArrayList<>(); + protected Map attributes = new HashMap<>(); + + protected String className; + + protected HtmlTag(String name) { + className = name; + } + + protected HtmlTag(String name, String[] classes) { + className = name; + for (String classs : classes) + addClass(classs); + } + + public HtmlTag add(HtmlTag tag) { + childNodes.add(tag); + return tag; + } + + public void deleteClass(String classs) { + classes.remove(classs); + } + + public void addClass(String classs) { + classes.add(classs); + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public Set getClasses() { + return this.classes; + } + + public void clear() { + childNodes.clear(); + } + + public void remove() { + classes.clear(); + childNodes.clear(); + } + + public String attr(String attr) { + return attributes.get(attr); + } + + public HtmlTag attr(String key, String val) { + attributes.put(key, val); + return this; + } + + public HtmlTag attr(String key, int val) { + return attr(key, val+""); + } + + public HtmlTag attr(String key, double val) { + return attr(key, val+""); + } + + @Override + public String toString() { + + StringBuilder html = new StringBuilder(); + html.append("<"); + html.append(className); + html.append(" "); + if(id != null) { + html.append("id=\""); + html.append(id); + html.append("\" "); + } + + if (classes.size() > 0) { + String classesS = String.join(" ", classes); + html.append("class=\""); + html.append(classesS); + html.append("\" "); + } + + for(Entry attr : attributes.entrySet()) { + html.append(attr.getKey()); + html.append("=\""); + html.append(attr.getValue()); + html.append("\" "); + } + + html.append(">"); + + for (HtmlTag tag : childNodes) + html.append(tag.toString()); + + html.append("<"); + html.append("/"); + html.append(className); + html.append(">"); + + return html.toString(); + } + + public List getChildren(){ + return childNodes; + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Table.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Table.java new file mode 100644 index 0000000..1018d51 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Table.java @@ -0,0 +1,14 @@ +package flintstones.helper.html.tags; + +public class Table extends HtmlTag { + + public Table() { + super("table"); + } + + public Table(String[] classes) { + super("table", classes); + } + + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Td.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Td.java new file mode 100644 index 0000000..ed4777f --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Td.java @@ -0,0 +1,13 @@ +package flintstones.helper.html.tags; + +public class Td extends HtmlTag { + + public Td() { + super("td"); + } + + public Td(String[] classes) { + super("td",classes); + } + +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Text.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Text.java new file mode 100644 index 0000000..9eb99a8 --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Text.java @@ -0,0 +1,29 @@ +package flintstones.helper.html.tags; + +import java.util.Arrays; + +public class Text extends HtmlTag { + + private String textContent; + public Text(String text) { + super(""); + textContent = text; + } + + @Override + public String toString() { + return textContent; + } + + public void setText(String text) { + textContent = text; + } + + public static Text[] asText(String[] data) { + return Arrays.stream(data).map(k -> new Text(k)).toArray(Text[]::new); + } + + public static Text[][] asText(String[][] data) { + return Arrays.stream(data).map( k -> asText(k) ).toArray(Text[][]::new); + } +} diff --git a/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Tr.java b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Tr.java new file mode 100644 index 0000000..59e02dd --- /dev/null +++ b/bundles/flintstones.helper.html/src/flintstones/helper/html/tags/Tr.java @@ -0,0 +1,14 @@ +package flintstones.helper.html.tags; + +public class Tr extends HtmlTag{ + + public Tr() { + super("tr"); + } + + public Tr(String[] classes) { + super("tr",classes); + } + + +} diff --git a/bundles/flintstones.helper.locale/.classpath b/bundles/flintstones.helper.locale/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.locale/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.locale/.polyglot.META-INF b/bundles/flintstones.helper.locale/.polyglot.META-INF new file mode 100644 index 0000000..fcfe929 --- /dev/null +++ b/bundles/flintstones.helper.locale/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.locale + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Locale + diff --git a/bundles/flintstones.helper.locale/.project b/bundles/flintstones.helper.locale/.project new file mode 100644 index 0000000..e83b647 --- /dev/null +++ b/bundles/flintstones.helper.locale/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.locale + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362614 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.locale/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.locale/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.locale/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.locale/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.locale/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.locale/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.locale/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.locale/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.locale/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.locale/META-INF/MANIFEST.MF b/bundles/flintstones.helper.locale/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f7ae30d --- /dev/null +++ b/bundles/flintstones.helper.locale/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Locale +Bundle-SymbolicName: flintstones.helper.locale +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.helper.locale +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.helper.locale diff --git a/bundles/flintstones.helper.locale/build.properties b/bundles/flintstones.helper.locale/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.locale/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.locale/src/flintstones/helper/locale/LocaleHelper.java b/bundles/flintstones.helper.locale/src/flintstones/helper/locale/LocaleHelper.java new file mode 100644 index 0000000..146e66a --- /dev/null +++ b/bundles/flintstones.helper.locale/src/flintstones/helper/locale/LocaleHelper.java @@ -0,0 +1,36 @@ +package flintstones.helper.locale; + +public class LocaleHelper { + + private String locale; + + private static LocaleHelper instance; + + public static LocaleHelper get() { + if(instance == null) + instance = new LocaleHelper(); + return instance; + + } + + private LocaleHelper() { + } + + public static void setLocale(String locale) { + always(); + + instance.locale = locale; + } + + public static String getLocale() { + always(); + + return instance.locale; + } + + private static void always() { + if(instance == null) + LocaleHelper.get(); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.ui/.classpath b/bundles/flintstones.helper.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.ui/.polyglot.META-INF b/bundles/flintstones.helper.ui/.polyglot.META-INF new file mode 100644 index 0000000..d6d7d61 --- /dev/null +++ b/bundles/flintstones.helper.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.helper.ui/.project b/bundles/flintstones.helper.ui/.project new file mode 100644 index 0000000..04f8a88 --- /dev/null +++ b/bundles/flintstones.helper.ui/.project @@ -0,0 +1,50 @@ + + + flintstones.helper.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362614 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.ui/META-INF/MANIFEST.MF b/bundles/flintstones.helper.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7a88c6e --- /dev/null +++ b/bundles/flintstones.helper.ui/META-INF/MANIFEST.MF @@ -0,0 +1,28 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.helper.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + org.eclipse.wb.swt, + org.eclipse.osgi, + org.eclipse.jface;visibility:=reexport, + org.eclipse.equinox.registry, + javax.inject, + flintstones.helper.html, + org.eclipse.swt, + org.eclipse.nebula.widgets.tablecombo, + javax.annotation, + flintstones.entity.extensionenum, + flintstones.model.ui.service, + org.eclipse.nebula.widgets.nebulaslider, + flintstones.helper.data, + org.apache.commons.lang, + org.lorissecuro.ui +Export-Package: + flintstones.helper.ui.components, + flintstones.helper.ui.components.listeners +Automatic-Module-Name: flintstones.helper.ui diff --git a/bundles/flintstones.helper.ui/build.properties b/bundles/flintstones.helper.ui/build.properties new file mode 100644 index 0000000..f250f99 --- /dev/null +++ b/bundles/flintstones.helper.ui/build.properties @@ -0,0 +1,4 @@ +output.. = bin/ +bin.includes = META-INF/,\ + . +source.. = src/ diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ActionButton.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ActionButton.java new file mode 100644 index 0000000..4c5cea9 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ActionButton.java @@ -0,0 +1,64 @@ +package flintstones.helper.ui.components; + +import org.eclipse.swt.widgets.Composite; +import org.lorissecuro.ui.CustomButton; + +import flintstones.model.ui.service.UiService; + +public class ActionButton { + + CustomButton button; + + public ActionButton(Composite bas, int style, int fontSize) { + + button = new CustomButton(bas,style); + addStyles(fontSize); + } + + private void addStyles(int fontSize) { + + // NORMAL + button.setBorderWidth(2); + button.setBorder2Width(0); + + // PRESSED + button.setBackgroundPressed(UiService.COLOR_MAIN); + button.setForegroundPressed(UiService.COLOR_MAIN_FG); + button.setBorderWidthPressed(2); + + // HOVER + button.setBackgroundHover(UiService.COLOR_MAIN_HOVER); + button.setBorderWidthHover(2); + button.setBorder2WidthHover(0); + + // SELECTED + button.setBackgroundSelected(UiService.COLOR_MAIN); + button.setForegroundSelected(UiService.COLOR_MAIN_FG); + + button.setColorTransition(false); + + UiService.setFont(button, UiService.FONT_BUTTON); + UiService.setFontSize(button, fontSize); + + } + + public CustomButton getButton() { + return button; + } + + public void setText(String label) { + button.setText(label); + } + + public void setSelection(boolean b) { + button.setSelection(b); + } + + public void setEnabled(boolean b) { + button.setEnabled(b); + } + + public void setHeight(int i) { + button.heightHint = i; + } +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/DecimalSpinner.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/DecimalSpinner.java new file mode 100644 index 0000000..fd68d23 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/DecimalSpinner.java @@ -0,0 +1,190 @@ +package flintstones.helper.ui.components; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +import flintstones.helper.DoubleHelper; +import flintstones.helper.ui.components.listeners.WItemChanged; +import flintstones.model.ui.service.UiService; + +public class DecimalSpinner { + + private double value = 0.0; + private double stepBase = 1.0; + private double stepPlus = 10.0; + private double stepExtra = 100.0; + private int decPlaces = 0; + double min = -100000.0; + double max = 100000.0; + + Composite base; + Text input; + + WItemChanged changeListener; + + public DecimalSpinner(Composite parent, double minv, double maxv, int decimalPlaces) { + + stepBase = 1 / Math.pow(10, decimalPlaces); + stepPlus = stepBase * 10; + stepExtra = stepBase * 100; + decPlaces = decimalPlaces; + min = minv; + max = maxv; + + base = new Composite(parent, SWT.BORDER); + GridLayout layout = UiService.setGridLayout(base, 3, false); + UiService.setGridData(base, -1, 0, false, false); + UiService.setMargin(base, 0); + + layout.horizontalSpacing = 0; + layout.marginBottom = 0; + layout.marginHeight = 0; + layout.marginLeft = 0; + layout.marginRight = 0; + layout.marginTop = 0; + layout.marginWidth = 0; + layout.verticalSpacing = 0; + + base.setLayout(layout); + + // LESS BUTTON + Button lessButton = new Button(base, SWT.PUSH); + lessButton.setImage(UiService.getImage("action_reduce.png").createImage()); + lessButton.addMouseListener(new MouseAdapter() { + public void mouseDown(MouseEvent e) { + double usedStep = getStep(e.button); + double newValue = value - usedStep; + setValue(newValue); + } + }); + lessButton.setToolTipText("LC: -" + stepBase + " MC: -" + stepPlus + " RC: -" + stepExtra); + + // INPUT + input = new Text(base, SWT.SINGLE | SWT.CENTER); + input.setText(DoubleHelper.Draw(value, decimalPlaces + 5)); + input.addVerifyListener(new VerifyListener() { + @Override + public void verifyText(VerifyEvent e) { + + final String oldS = input.getText(); + String newS = oldS.substring(0, e.start) + e.text + oldS.substring(e.end); + + if (newS.equals("")) { + e.doit = true; + setValue(0.0); + return; + } + + if (newS.contains("d") || newS.contains("f")) { + e.doit = false; + return; + } + + newS = newS.replace(",", "."); + if (newS.endsWith(".")) + newS += "0"; + + double finalValue = 0.0; + try { + finalValue = Double.parseDouble(newS); + } catch (NumberFormatException ex) { + e.doit = false; + return; + } + + if (finalValue < min || finalValue > max) { + e.doit = false; + return; + } + + updateValue(finalValue); + +// System.out.println("MOD: " + value); +// System.out.println(min + " -- " + max); + + } + }); + + UiService.setGridData(input, 0, 0, false, true); + + // MORE BUTTON + Button moreButton = new Button(base, SWT.PUSH); + moreButton.setImage(UiService.getImage("action_add.png").createImage()); + moreButton.addMouseListener(new MouseAdapter() { + public void mouseDown(MouseEvent e) { + double usedStep = getStep(e.button); + double newValue = value + usedStep; + setValue(newValue); + } + }); + moreButton.setToolTipText("LC: +" + stepBase + " MC: +" + stepPlus + " RC: +" + stepExtra); + + } + + private void updateValue(double updatedValue) { + value = updatedValue; + if (changeListener != null) + changeListener.onWidgetChange(); + } + + public void setValue(double val) { + + if (val < max && val > min) { + UiService.setBackgroundColor(base, UiService.COLOR_BG_NORMAL); + UiService.setBackgroundColor(input, UiService.COLOR_BG_NORMAL); + String cleanValue = DoubleHelper.Draw(val, decPlaces, true); + input.setText(cleanValue); + + updateValue(val); + + correctSelection(); +// System.out.println("Clean value " + value); + + } else { + UiService.setBackgroundColor(base, UiService.COLOR_BG_WRONG); + UiService.setBackgroundColor(input, UiService.COLOR_BG_NORMAL); + } + +// System.out.println("Underlying value " + value); +// System.out.println(min + " -- " + max); + } + + private void correctSelection() { + if (input.getText().equals("0")) + input.setSelection(1); + } + + public double getValue() { + double curr = DoubleHelper.ParseDouble(input.getText()); + if (curr != value) + updateValue(curr); + return value; + } + + private double getStep(int mouseButton) { + double usedStep = stepBase; + switch (mouseButton) { + case 1: + usedStep = stepBase; + break; + case 2: + usedStep = stepPlus; + break; + case 3: + usedStep = stepExtra; + break; + } + return usedStep; + } + + public void setChangeListener(WItemChanged lis) { + changeListener = lis; + } +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/SliderCollector.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/SliderCollector.java new file mode 100644 index 0000000..2b9863a --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/SliderCollector.java @@ -0,0 +1,411 @@ +package flintstones.helper.ui.components; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Scale; + +import flintstones.helper.DoubleHelper; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.helper.ui.components.listeners.WEvent; +import flintstones.helper.ui.components.listeners.WItemBeforeOperation; +import flintstones.helper.ui.components.listeners.WItemChanged; +import flintstones.model.ui.service.UiService; + +/** + * The Class WCollector. + */ +public class SliderCollector { + + Scale input; + Label inputValue; + + /** The add button. */ + Button addButton; + + /** The delete button. */ + Button deleteButton; + + /** The table. */ + HtmlTextTable table; + + /** The table headers. */ + String[] tableHeaders; + + /** The values. */ + ArrayList values = new ArrayList<>(); + + /** The change listener. */ + WItemChanged changeListener; + + /** The operation listener. */ + WItemBeforeOperation checkListener; + + + /** + * Instantiates a new w collector. + * + * @param parent the parent + */ + public SliderCollector(Composite parent) { + preInit(parent, 0, 100, 0); + } + + public SliderCollector(Composite parent, double min, double max) { + preInit(parent, min, max, 0); + } + + public SliderCollector(Composite parent, double min, double max, int decimalPlaces) { + preInit(parent, min, max, decimalPlaces); + } + + int min = 0; + int max; + double desp; + int mult; + int decPlaces; + + private void preInit(Composite parent, double minValue, double maxValue, int decimalPlaces) { + cacheTranslation(minValue, maxValue, decimalPlaces); + init(parent); + } + + private void cacheTranslation(double minValue, double maxValue, int decimalPlaces) { + if (minValue == maxValue) + throw new RuntimeException("Differents please"); + + if (minValue > maxValue) + throw new RuntimeException("Ordered please"); + + double Xmax = Math.abs(minValue - maxValue); + desp = -minValue; + + mult = (int) Math.pow(10, decimalPlaces); + + max = (int) Xmax * mult; + decPlaces = decimalPlaces; + } + + public void reSet(double minValue, double maxValue, int decimalPlaces) { + cacheTranslation(minValue, maxValue, decimalPlaces); + + input.setMinimum(min); + input.setMaximum(max); + inputValue.setText(getValue() + " "); + } + + /** + * Sets the values. + * + * @param values the new values + */ + public void setValues(Double[] values) { + ArrayList arrayList = new ArrayList(Arrays.asList(values)); + this.values = arrayList; + refreshTable(); + } + + /** + * Sets the headers. + * + * @param headers the new headers + */ + public void setHeaders(String headers[]) { + tableHeaders = headers; + refreshTable(); + } + + /** + * Inits the. + */ + private void init(Composite parent) { + + Composite base = new Composite(parent, SWT.BORDER); + UiService.setGridLayout(base, 1); + UiService.setGridData(base, 9, 9, true, true); + + Composite row1 = new Composite(base, 0); + UiService.setGridLayout(row1, 4); + UiService.setGridData(row1, 9, 9, true, false); + UiService.setBackgroundColor(base, UiService.getColor(255, 255, 255)); + + input = new Scale(row1, 0); + input.setMinimum(min); + input.setMaximum(max); + UiService.setGridData(input, 9, 0, true, false); + + inputValue = new Label(row1, 0); + inputValue.setText("XX.XXXXXXXX"); +// input.setToolTipText("Pulsa [INTRO] para añadir un elemento"); +// input.addListener(SWT.Traverse, onEnterListener()); + + input.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + inputValue.setText(getValue() + ""); + } + }); + + inputValue.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent event) { + super.mouseUp(event); + + if (event.getSource() instanceof Label) { + Label label = (Label) event.getSource(); + String text = label.getText().trim(); + + InputDialog dialog = new InputDialog(Display.getDefault().getActiveShell(), "Editando valor", + "Introduce un valor", text, new IInputValidator() { + + @Override + public String isValid(String newText) { + Double val = DoubleHelper.ParseDouble(newText); + if (val > min && val < max) + return null; + return "Valor no valido"; + } + }); + dialog.open(); + String newVal = dialog.getValue(); + if(newVal != null) { + + // ADD to table + Double val = DoubleHelper.ParseDouble(newVal); + addData(val); + + inputValue.setText(newVal + " "); + + } + + } + } + }); + + inputValue.addListener(SWT.MouseMove, new Listener() { + public void handleEvent(Event event) { + final Cursor cursor = new Cursor(Display.getDefault(), SWT.CURSOR_HAND); + inputValue.setCursor(cursor); + } + }); + + + addButton = new Button(row1, SWT.PUSH); +// addButton.setText(" + "); + addButton.setImage(UiService.getIcon("action_add").createImage()); + addButton.addListener(SWT.Selection, onAddClickListener()); + + UiService.setGridData(addButton, 1, 0, false, false); + + deleteButton = new Button(row1, SWT.PUSH); +// deleteButton.setText(" X "); + deleteButton.setImage(UiService.getIcon("action_delete").createImage()); + deleteButton.addListener(SWT.Selection, onDeleteClickListener()); + + UiService.setGridData(addButton, 1, 0, false, false); +// UiService.setBackgroundColor(deleteButton, 200, 0, 0); + + Composite row2 = new Composite(base, 0); + UiService.setGridLayout(row2, 1); + UiService.setGridData(row2, 9, 9, true, true); + + table = new HtmlTextTable(row2, new String[] {}, true); + table.render(); + + // + inputValue.setText(getValue() + " "); + } + + /** + * Can be executed. + * + * @param operationType the operation type + * @param before the before + * @param after the after + * @return true, if successful + */ + private boolean canBeExecuted(WEvent operationType, String before, String after) { + boolean ok = true; + + if (checkListener != null && !checkListener.shouldBeExecuted(operationType, before, after)) + ok = false; + + if (ok) { + input.getParent().setBackground(UiService.COLOR_BG_NORMAL); + } else { + input.getParent().setBackground(UiService.COLOR_BG_WRONG); + } + + return ok; + } + + /** + * Adds the data. + */ + + private void addData(double data) { + + String dataS = data + "";// .getText(); + + if (!canBeExecuted(WEvent.ADD, dataS, "")) + return; + +// if(operationListener != null) +// dataS = operationListener.getModifiedValue(WEvent.ADD, dataS, ""); + + values.add(data); + refreshTable(); + + if (changeListener != null) + changeListener.onWidgetChange(); + } + + private void addData() { + + double data = getValue(); + addData(data); + + } + + /** + * Clear data. + */ + private void clearData() { + + if (checkListener != null && !checkListener.shouldBeExecuted(WEvent.CLEAR, "", "")) + return; + + input.getParent().setBackground(UiService.COLOR_BG_NORMAL); + + values.clear(); + + if (changeListener != null) + changeListener.onWidgetChange(); + + refreshTable(); + } + + /** + * Clear. + */ + public void clear() { + values.clear(); + refreshTable(); + } + + /** + * Refresh table. + */ + private void refreshTable() { + + if (table == null) + return; + + int headerLength = tableHeaders != null ? tableHeaders.length : 0; + + Composite row = table.getParent(); + Arrays.stream(row.getChildren()).forEach(k -> k.dispose()); + + String[] data = new String[values.size() > headerLength ? values.size() : headerLength]; + Arrays.fill(data, ""); + + Double[] filledData = getData(); + for (int i = 0; i < filledData.length; i++) + data[i] = filledData[i] + ""; + + if (tableHeaders != null) + table = new HtmlTextTable(row, data, tableHeaders, true); + else + table = new HtmlTextTable(row, data, true); + + table.render(); + row.layout(); + + } + + /** + * Gets the data. + * + * @return the data + */ + public Double[] getData() { + return values.toArray(new Double[values.size()]); + } + + /** + * On delete click listener. + * + * @return the listener + */ + private Listener onDeleteClickListener() { + return new Listener() { + public void handleEvent(Event e) { + if (e.type == SWT.Selection) + clearData(); + } + }; + } + + /** + * On add click listener. + * + * @return the listener + */ + private Listener onAddClickListener() { + return new Listener() { + public void handleEvent(Event e) { + if (e.type == SWT.Selection) + addData(); + } + }; + } + + /** + * Sets the change listener. + * + * @param listener the new change listener + */ + public void setChangeListener(WItemChanged listener) { + changeListener = listener; + } + + /** + * Sets the operation listener. + * + * @param listener the new operation listener + */ + public void setBeforeOperationListener(WItemBeforeOperation listener) { + checkListener = listener; + } + +// public void setOperationListener(WItemOperation listener) { +// operationListener = listener; +// } +// + // CORRECT VALUES ONLY HERE + private double getValue() { + double val = input.getSelection(); + val = val / mult; + val = val - desp; + val = DoubleHelper.Round(val, decPlaces); + return val; + } + + public Composite getBase() { + return input.getParent(); + } +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/TableComboStatus.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/TableComboStatus.java new file mode 100644 index 0000000..6ae4d11 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/TableComboStatus.java @@ -0,0 +1,275 @@ +package flintstones.helper.ui.components; + +import java.util.ArrayList; +import java.util.stream.Stream; + +import org.eclipse.nebula.widgets.tablecombo.TableCombo; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TableItem; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.model.ui.service.UiService; + +/** + * The Class TableComboStatus. + */ +public class TableComboStatus { + + /** + * The Enum Status. + */ + public static enum Status implements ExtensionEnum { + + /** The Wrong. */ + Wrong, + /** The Unknown. */ + Unknown, + /** The Right. */ + Right + } + + /** The ui service. */ + + /** The combo. */ + public TableCombo combo; + + /** The unknown image. */ + Image unknownImage; + + /** The right image. */ + Image rightImage; + + /** The wrong image. */ + Image wrongImage; + + /** The parent. */ + Composite parent; + + /** The style. */ + int style; + + /** The combo selection adapter. */ + SelectionAdapter comboSelectionAdapter; + + /** + * Instantiates a new table combo status. + * + * @param parent the parent + * @param style the style + */ + public TableComboStatus(Composite parent, int style) { + + Composite intermediate = new Composite(parent, 0); + intermediate.setLayout(new FillLayout()); + this.parent = intermediate; + this.style = style; + addNewCombo(); + + unknownImage = UiService.getIcon("status_unknown").createImage(); + wrongImage = UiService.getIcon("status_wrong").createImage(); + rightImage = UiService.getIcon("status_right").createImage(); + } + + /** + * Adds the selection listener. + * + * @param comboSelectionAdapter the combo selection adapter + */ + public void addSelectionListener(SelectionAdapter comboSelectionAdapter) { + this.comboSelectionAdapter = comboSelectionAdapter; + combo.addSelectionListener(comboSelectionAdapter); + } + + /** + * Adds the table item. + * + * @param text the text + * @param image the image + */ + private void addTableItem(String text, Image image) { + TableItem ti = new TableItem(combo.getTable(), 0); + ti.setText(text); + ti.setImage(image); + } + + /** + * Sets the items. + * + * @param array the new items + */ + public void setItems(String[] array) { + addNewCombo(); + Stream.of(array).forEach(k -> addTableItem(k, unknownImage)); + } + + /** + * Gets the position. + * + * @param text the text + * @return the position + */ + public int getPosition(String text) { + int pos = -1; + for (int i = 0; i < combo.getTable().getItems().length; i++) { + String itemText = combo.getTable().getItems()[i].getText(); + if (text.equals(itemText)) { + pos = i; + break; + } + } + + return pos; + } + + /** + * Gets the image for status. + * + * @param status the status + * @return the image for status + */ + private Image getImageForStatus(Status status) { + + if (status.equals(Status.Wrong)) + return wrongImage; + if (status.equals(Status.Unknown)) + return unknownImage; + if (status.equals(Status.Right)) + return rightImage; + + return unknownImage; + } + + /** + * Sets the status. + * + * @param pos the pos + * @param status the status + */ + public void setStatus(int pos, Status status) { + Image img = getImageForStatus(status); + combo.getTable().getItems()[pos].setImage(img); + refreshTable(); + } + + /** + * Sets the status. + * + * @param item the item + * @param status the status + */ + public void setStatus(String item, Status status) { + int pos = getPosition(item); + setStatus(pos, status); + } + + /** + * Gets the status. + * + * @param item the item + * @param status the status + */ + public boolean getStatus(String item) { + int pos = getPosition(item); + int status = getStatus(pos); + + if(status == 1) + return true; + else + return false; + } + + /** + * Select. + * + * @param pos the pos + */ + public void select(int pos) { + combo.select(pos); + } + + /** + * Refresh table. + */ + private void refreshTable() { + + int lastSelected = combo.getSelectionIndex(); + ArrayList itemsText = new ArrayList<>(); + ArrayList itemsImage = new ArrayList<>(); + for (TableItem ti : combo.getTable().getItems()) { + itemsText.add(ti.getText()); + itemsImage.add(ti.getImage()); + } + + combo.getTable().removeAll(); + + for (int i = 0; i < itemsText.size(); i++) { + addTableItem(itemsText.get(i), itemsImage.get(i)); + } + + // Draw again the selected item + combo.select(lastSelected); + } + + /** + * Gets the status. + * + * @return the status + */ + public boolean getStatus() { + TableItem[] items = combo.getTable().getItems(); + for (int i = 0; i < items.length; i++) + if (getStatus(i) != 1) + return false; + return true; + } + + /** + * Gets the status. + * + * @param pos the pos + * @return the status + */ + private int getStatus(int pos) { + if (combo.getTable().getItems()[pos].getImage().equals(rightImage)) + return 1; + else if (combo.getTable().getItems()[pos].getImage().equals(unknownImage)) + return 0; + else + return -1; + } + + /** + * Gets the text. + * + * @return the text + */ + public String getText() { + return combo.getText(); + } + + /** + * Adds the new combo. + */ + private void addNewCombo() { + + if (combo != null && !combo.isDisposed()) + combo.dispose(); + + combo = new TableCombo(parent, style); + + if (comboSelectionAdapter != null) + combo.addSelectionListener(comboSelectionAdapter); + } + + /** + * Gets the parent. + * + * @return the parent + */ + public Composite getParent() { + return parent; + } + +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ToggleButton.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ToggleButton.java new file mode 100644 index 0000000..dbe0c48 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ToggleButton.java @@ -0,0 +1,50 @@ +package flintstones.helper.ui.components; + +import org.apache.commons.lang.StringUtils; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; + +import flintstones.helper.ui.components.listeners.IToggle; + +public class ToggleButton { + + Button button; + + boolean isState1 = true; + + public ToggleButton(Composite base, int style, IToggle toggle) { + button = new Button(base,style); + + button.setText(getButtonSpaces(toggle)); + button.setText(toggle.getBaseText()); + button.setImage(toggle.getBaseImage()); + + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if(isState1) { + button.setText(toggle.getAltText()); + button.setImage(toggle.getAltImage()); + toggle.onBaseTextClick(); + + } else { + button.setText(toggle.getBaseText()); + button.setImage(toggle.getBaseImage()); + toggle.onAltTextClick(); + } + toggle.always(); + isState1 = !isState1; + + } + + }); + } + + private String getButtonSpaces(IToggle toggle) { + int spaces = toggle.getBaseText().length() > toggle.getAltText().length() ? toggle.getBaseText().length() : toggle.getAltText().length(); + return StringUtils.leftPad("", spaces*3); + } + +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ValidatedField.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ValidatedField.java new file mode 100644 index 0000000..f663deb --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/ValidatedField.java @@ -0,0 +1,120 @@ +package flintstones.helper.ui.components; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import flintstones.model.ui.service.UiService; + +public class ValidatedField { + + private Label titleLabel; + private WLabel errorLabel; + private Text input; + + public ValidatedField(Composite row, String label) { + this(row, label, ""); + } + + public ValidatedField(Composite base, String label, String defaultText) { + + UiService.setMargin(base, 0); +// UiService.setBackgroundColor(base, 0, 0, 100); + + addRow1(base, label); + addRow2(base,defaultText); + + } + + private void addRow1(Composite base, String label) { + + Composite row = new Composite(base, SWT.NONE); + UiService.setGridData(row, 9, -1, true, false); + UiService.setGridLayout(row, 2); +// UiService.setBackgroundColor(row, 0, 100, 0); + UiService.setMargin(row, 0); + + titleLabel = addLabel(row, label); + errorLabel = addErrorLabel(row); + + } + + private void addRow2(Composite base, String defaultText) { + + Composite row = new Composite(base, SWT.NONE); + UiService.setGridData(row, 9, -1, true, false); + UiService.setGridLayout(row, 1); +// UiService.setBackgroundColor(row, 100, 0, 0); + UiService.setMargin(row, 0); + + input = addInput(row); + setText(defaultText); + + } + + private Label addLabel(Composite row, String text) { + + Label label = new Label(row, SWT.NONE); + label.setText(text); + UiService.setGridData(label, -1, 0, false, false); + UiService.setFont(label, UiService.FONT_SECTION_TITLE); + + return label; + + } + + private WLabel addErrorLabel(Composite row) { + + Composite subBase = new Composite(row, SWT.NONE); + UiService.setGridLayout(subBase, 1); + UiService.setGridDataAuto(subBase); + + WLabel label = new WLabel(subBase, SWT.NONE); + UiService.setGridData(label, -1, 0, false, false); + UiService.setFont(label, UiService.FONT_TEXT_ERROR); + + return label; + } + + private Text addInput(Composite row) { + Text input = new Text(row, SWT.BORDER); + UiService.setGridData(input, 9, -1, true, false); + return input; + } + + public Text getInput() { + return input; + } + + public String getText() { + return input.getText(); + } + + public void setText(String text) { + + if(text == null) + text = ""; + + String clean = text.trim(); + + if(!getText().equals(clean)) + input.setText(clean); + } + + public void setTitle(String label) { + titleLabel.setText(label); + } + + public void setError(String text) { + + if(text == null || text.equals("")) { + input.setBackground(UiService.COLOR_BG_NORMAL); + errorLabel.setText(""); + return ; + } + + input.setBackground(UiService.COLOR_BG_WRONG); + errorLabel.setText(text); + } +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/WCollector.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/WCollector.java new file mode 100644 index 0000000..54c76ff --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/WCollector.java @@ -0,0 +1,346 @@ +package flintstones.helper.ui.components; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; + +import flintstones.helper.StringHelper; +import flintstones.helper.data.Config; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.helper.ui.components.listeners.WEvent; +import flintstones.helper.ui.components.listeners.WItemAfterOperation; +import flintstones.helper.ui.components.listeners.WItemBeforeOperation; +import flintstones.helper.ui.components.listeners.WItemChanged; +import flintstones.helper.ui.components.listeners.WItemOperation; +import flintstones.model.ui.service.UiService; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * The Class WCollector. + */ +public class WCollector { + + /** The input. */ + Text input; + + /** The add button. */ + Button addButton; + + /** The delete button. */ + Button deleteButton; + + /** The table. */ + HtmlTextTable table; + + /** The table headers. */ + String[] tableHeaders; + + /** The values. */ + ArrayList values = new ArrayList<>(); + + WItemChanged changeListener; + WItemOperation operationListener; + WItemBeforeOperation checkListener; + WItemAfterOperation afterListener; + + Config config = new Config().defaultEnabled("paste"); + + /** + * Instantiates a new w collector. + * + * @param parent the parent + */ + public WCollector(Composite parent) { + init(parent); + } + + /** + * Sets the values. + * + * @param values the new values + */ + public void setValues( ArrayList values ) { + this.values = values; + refreshTable(); + } + + /** + * Sets the headers. + * + * @param headers the new headers + */ + public void setHeaders(String headers[]) { + tableHeaders = headers; + refreshTable(); + } + + /** + * Inits the. + */ + private void init(Composite parent) { + + Composite base = new Composite(parent, SWT.NONE); + UiService.setGridLayout(base, 1); + UiService.setGridData(base, 9, 9, true, true); + + Composite row1 = new Composite(base, 0); + int cols = config.is("paste") ? 4 : 3; + UiService.setGridLayout(row1, cols); + UiService.setGridData(row1, 9, 9, true, false); + + input = new Text(row1, SWT.BORDER); + input.setToolTipText("Pulsa [INTRO] para añadir un elemento"); + input.addListener(SWT.Traverse, onEnterListener()); + + UiService.setGridData(input, 9, 0, true, false); + + addButton = new Button(row1, SWT.PUSH); +// addButton.setText(" + "); + addButton.setImage( UiService.getIcon("action_add").createImage() ); + addButton.addListener(SWT.Selection, onAddClickListener()); + + UiService.setGridData(addButton, 1, 0, false, false); + + deleteButton = new Button(row1, SWT.PUSH); +// deleteButton.setText(" X "); + deleteButton.setImage( UiService.getIcon("action_delete").createImage() ); + deleteButton.addListener(SWT.Selection, onDeleteClickListener()); + + UiService.setGridData(deleteButton, 1, 0, false, false); +// UiService.setBackgroundColor(deleteButton, 200, 0, 0); + + if(config.is("paste")) { + Button pasteButton = new Button(row1,SWT.PUSH); + pasteButton.setImage( UiService.getIcon("action_paste").createImage() ); + UiService.setGridData(pasteButton, 1, 0, false, false); + pasteButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + Clipboard clipboard = new Clipboard(Display.getCurrent()); + String plainText = (String) clipboard.getContents(TextTransfer.getInstance()); + + if(plainText == null) { + input.setText(""); + } else { + String[] items = StringHelper.SplitSplit(plainText); + for(String text : items) { + input.setText(text); + addData(); + } + } + } + + }); + } + + + Composite row2 = new Composite(base, 0); + UiService.setGridLayout(row2, 1); + UiService.setGridData(row2, 9, 9, true, true); + + table = new HtmlTextTable(row2, new String[] {}, true); + table.render(); + } + + /** + * Can be executed. + * + * @param operationType the operation type + * @param before the before + * @param after the after + * @return true, if successful + */ + private boolean canBeExecuted(WEvent operationType, String before, String after) { + boolean ok = true; + + if(checkListener != null && !checkListener.shouldBeExecuted(operationType, before, after)) + ok = false; + + if(ok){ + input.setBackground(UiService.COLOR_BG_NORMAL); + } else { + input.setBackground(UiService.COLOR_BG_WRONG); + } + + return ok; + } + + /** + * Adds the data. + */ + private void addData() { + + String data = input.getText(); + if(data.equals("")) + return ; + + if(!canBeExecuted(WEvent.ADD, data, "")) + return ; + + if(operationListener != null) + data = operationListener.getModifiedValue(WEvent.ADD, data, ""); + + if (!data.equals("")) { + values.add(data); + input.setText(""); + refreshTable(); + + if( changeListener != null ) + changeListener.onWidgetChange(); + } + + if(afterListener != null) + afterListener.afterOperation(WEvent.ADD, data, getData()); + } + + /** + * Clear data. + */ + private void clearData() { + + if(checkListener != null && !checkListener.shouldBeExecuted(WEvent.CLEAR, "", "")) + return ; + + values.clear(); + + if( changeListener != null ) + changeListener.onWidgetChange(); + + refreshTable(); + } + + /** + * Clear. + */ + public void clear() { + values.clear(); + refreshTable(); + } + + /** + * Refresh table. + */ + private void refreshTable() { + + if(table == null) + return ; + + int headerLength = tableHeaders != null ? tableHeaders.length : 0; + + Composite row = table.getParent(); + Arrays.stream(row.getChildren()).forEach(k -> k.dispose()); + + String[] data = new String[ values.size() > headerLength ? values.size() : headerLength ]; + Arrays.fill(data, ""); + + String[] filledData = getData(); + for(int i = 0; i < filledData.length ; i++ ) + data[i] = filledData[i]; + + + if(tableHeaders != null) + table = new HtmlTextTable(row, data, tableHeaders, true); + else + table = new HtmlTextTable(row, data, true); + + table.render(); + row.layout(); + + } + + /** + * Gets the data. + * + * @return the data + */ + public String[] getData() { + return values.toArray(new String[values.size()]); + } + + + /** + * On delete click listener. + * + * @return the listener + */ + private Listener onDeleteClickListener() { + return new Listener() { + public void handleEvent(Event e) { + if (e.type == SWT.Selection) + clearData(); + } + }; + } + + /** + * On add click listener. + * + * @return the listener + */ + private Listener onAddClickListener() { + return new Listener() { + public void handleEvent(Event e) { + if (e.type == SWT.Selection) + addData(); + } + }; + } + + /** + * On enter listener. + * + * @return the listener + */ + private Listener onEnterListener() { + return new Listener() { + @Override + public void handleEvent(Event event) { + if (event.detail == SWT.TRAVERSE_RETURN) // Hit Enter + addData(); + } + }; + } + + /** + * Sets the change listener. + * + * @param listener the new change listener + */ + public void setChangeListener(WItemChanged listener) { + changeListener = listener; + } + + /** + * Sets the operation listener. + * + * @param listener the new operation listener + */ + public void setBeforeOperationListener(WItemBeforeOperation listener) { + checkListener = listener; + } + + public void setOperationListener(WItemOperation listener) { + operationListener = listener; + } + + public void setAfterListener(WItemAfterOperation listener) { + afterListener = listener; + } + + public void setEnabled(boolean status) { + table.setEnabled(status); + } +} + + diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/WLabel.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/WLabel.java new file mode 100644 index 0000000..990027e --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/WLabel.java @@ -0,0 +1,38 @@ +package flintstones.helper.ui.components; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.widgets.Composite; + +@SuppressWarnings("javadoc") +public class WLabel extends CLabel { + + private Composite parent; + + public WLabel(Composite parent) { + this(parent, SWT.NONE); + this.parent = parent; + } + + public WLabel(Composite parent, int style) { + super(parent, style); + this.parent = parent; + this.setTopMargin(0); + this.setBottomMargin(0); + } + + @Override + public void setText(String string) { + super.setText(string); + this.parent.layout(); + } + + public void clear() { + super.setText(""); //$NON-NLS-1$ + } + + @Override + public void checkSubclass() { + + } +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/IStatusProvider.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/IStatusProvider.java new file mode 100644 index 0000000..6ecba46 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/IStatusProvider.java @@ -0,0 +1,7 @@ +package flintstones.helper.ui.components.listeners; + +import flintstones.helper.ui.components.TableComboStatus.Status; + +public interface IStatusProvider { + Status getStatusFor(String name); +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/IToggle.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/IToggle.java new file mode 100644 index 0000000..72beb74 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/IToggle.java @@ -0,0 +1,21 @@ +package flintstones.helper.ui.components.listeners; + +import org.eclipse.swt.graphics.Image; + +public interface IToggle { + + String getBaseText(); + + String getAltText(); + + Image getBaseImage(); + + Image getAltImage(); + + void onAltTextClick(); + + void onBaseTextClick(); + + void always(); + +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WEvent.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WEvent.java new file mode 100644 index 0000000..17dd335 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WEvent.java @@ -0,0 +1,5 @@ +package flintstones.helper.ui.components.listeners; + +public enum WEvent { + ADD, CLEAR +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemAfterOperation.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemAfterOperation.java new file mode 100644 index 0000000..9f918a7 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemAfterOperation.java @@ -0,0 +1,7 @@ +package flintstones.helper.ui.components.listeners; + +public interface WItemAfterOperation { + + // Based on javascript functional interfaces + void afterOperation(WEvent operationType, String element, String[] arr); +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemBeforeOperation.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemBeforeOperation.java new file mode 100644 index 0000000..c30fbc3 --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemBeforeOperation.java @@ -0,0 +1,17 @@ +package flintstones.helper.ui.components.listeners; + +/** + * The Interface WItemBeforeOperation. + */ +public interface WItemBeforeOperation { + + /** + * Should be executed. + * + * @param operationType the operation type + * @param before the before + * @param after the after + * @return true, if successful + */ + boolean shouldBeExecuted(WEvent operationType, String before, String after); +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemChanged.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemChanged.java new file mode 100644 index 0000000..d86428e --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemChanged.java @@ -0,0 +1,12 @@ +package flintstones.helper.ui.components.listeners; + +/** + * The Interface WItemChanged. + */ +public interface WItemChanged { + + /** + * On widget change. + */ + void onWidgetChange(); +} diff --git a/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemOperation.java b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemOperation.java new file mode 100644 index 0000000..55461fb --- /dev/null +++ b/bundles/flintstones.helper.ui/src/flintstones/helper/ui/components/listeners/WItemOperation.java @@ -0,0 +1,7 @@ +package flintstones.helper.ui.components.listeners; + +public interface WItemOperation { + + String getModifiedValue(WEvent operationType, String before, String after); + +} diff --git a/bundles/flintstones.helper.validator/.classpath b/bundles/flintstones.helper.validator/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.validator/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.validator/.polyglot.META-INF b/bundles/flintstones.helper.validator/.polyglot.META-INF new file mode 100644 index 0000000..5dd33fe --- /dev/null +++ b/bundles/flintstones.helper.validator/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.validator + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Validator + diff --git a/bundles/flintstones.helper.validator/.project b/bundles/flintstones.helper.validator/.project new file mode 100644 index 0000000..96b3451 --- /dev/null +++ b/bundles/flintstones.helper.validator/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.validator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362615 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.validator/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.validator/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.validator/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.validator/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.validator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.validator/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.validator/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.validator/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.validator/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.validator/META-INF/MANIFEST.MF b/bundles/flintstones.helper.validator/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f4afdac --- /dev/null +++ b/bundles/flintstones.helper.validator/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Validator +Bundle-SymbolicName: flintstones.helper.validator +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.helper.validator +Automatic-Module-Name: flintstones.helper.validator +Require-Bundle: org.eclipse.e4.core.services;visibility:=reexport, + javax.inject diff --git a/bundles/flintstones.helper.validator/build.properties b/bundles/flintstones.helper.validator/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.validator/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.validator/src/flintstones/helper/validator/Validator.java b/bundles/flintstones.helper.validator/src/flintstones/helper/validator/Validator.java new file mode 100644 index 0000000..07d5846 --- /dev/null +++ b/bundles/flintstones.helper.validator/src/flintstones/helper/validator/Validator.java @@ -0,0 +1,509 @@ +package flintstones.helper.validator; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.helper.validator.messages.Messages; + +@SuppressWarnings("javadoc") +public class Validator { + + @Inject + @Translation + private Messages messages; + + /** + * Cadena para mostrar si no se aceptan valores nulos. + */ + private final static String NOT_NULL = Messages.Cannot_pass_null_value; + /** + * Cadena para mostrar si no se aceptan cadenas vacías. + */ + private final static String NOT_EMPTY_STRING = Messages.Cannot_pass_empty_string; + + /** + * Cadena para mostrar si no se aceptan arrays vacíos. + */ + private final static String NOT_EMPTY_ARRAY = Messages.ParameterValidator_Cannot_pass_empty_array; + + /** + * Cadena para mostrar si el tamaño es inválido. + */ + private final static String INVALID_SIZE = Messages.ParameterValidator_Invalid_size; + + /** + * Cadena para mostrar si el rango es inválido. + */ + private final static String INVALID_RANGE = Messages.ParameterValidator_Invalid_range; + + /** + * Cadena para mostrar que no se permiten valores negativos. + */ + private final static String NOT_NEGATIVE = Messages.ParameterValidator_Cannot_pass_negative_value; + + /** + * Cadena para mostrar que no se permiten valores negativos. + */ + private final static String NOT_DISORDER = Messages.ParameterValidator_Cannot_pass_disorder_values; + + /** + * Cadena para mostrar que no se permiten tipos ilegales. + */ + private final static String NOT_ILLEGAL_TYPE = Messages.ParameterValidator_Cannot_pass_illegal_objects; + + private final static String NOT_SAME_ELEMENT = Messages.ParameterValidator_Cannot_pass_same_element; + + /** + * Comprueba que un valor esté en el rango especificado. + * + * @param value + * Valor a comprobar. + * @param min + * Límite inferior del rango. + * @param max + * Límite superior del rango. + * @return True si el valor está dentro del rango establecido, False en caso + * contrario. + * @throws IllegalArgumentException + * Si el rango no es válido. + */ + public static boolean inRange(int value, int min, int max) { + if (min > max) + throw new IllegalArgumentException(Validator.INVALID_RANGE); + return ((min <= value) && (value <= max)); + } + + /** + * Comprueba que un valor esté en el rango especificado. + * + * @param value + * Valor a comprobar. + * @param min + * Límite inferior del rango. + * @param max + * Límite superior del rango. + * @return True si el valor está dentro del rango establecido, False en caso + * contrario. + * @throws IllegalArgumentException + * Si el rango no es válido. + */ + public static boolean inRange(double value, double min, double max) { + if (min > max) + throw new IllegalArgumentException(Validator.INVALID_RANGE); + return ((min <= value) && (value <= max)); + } + + /** + * Comprueba que un valor esté en el rango especificado. + * + * @param value + * Valor a comprobar. + * @param min + * Límite inferior del rango. + * @param max + * Límite superior del rango. + * @param includeStartpoint + * Considerar el valor inicial dentro del rango. + * + * @return True si el valor está dentro del rango establecido, False en caso + * contrario. + * @throws IllegalArgumentException + * Si el rango no es válido. + */ + public static boolean inRange(int value, int min, int max, boolean includeStartpoint, boolean includeEndpoint) { + if (min > max) + throw new IllegalArgumentException(Validator.INVALID_RANGE); + if (includeStartpoint) { + if (includeEndpoint) + return ((min <= value) && (value <= max)); + else + return ((min <= value) && (value < max)); + } else if (includeEndpoint) + return ((min < value) && (value <= max)); + else + return ((min < value) && (value < max)); + } + + /** + * Comprueba que un valor esté en el rango especificado. + * + * @param value + * Valor a comprobar. + * @param min + * Límite inferior del rango. + * @param max + * Límite superior del rango. + * @param includeStartpoint + * Considerar el valor inicial dentro del rango. + * + * @return True si el valor está dentro del rango establecido, False en caso + * contrario. + * @throws IllegalArgumentException + * Si el rango no es válido. + */ + public static boolean inRange(double value, double min, double max, boolean includeStartpoint, boolean includeEndpoint) { + if (min > max) + throw new IllegalArgumentException(Validator.INVALID_RANGE); + if (includeStartpoint) { + if (includeEndpoint) + return ((min <= value) && (value <= max)); + return ((min <= value) && (value < max)); + } else if (includeEndpoint) + return ((min < value) && (value <= max)); + else + return ((min < value) && (value < max)); + } + + /** + * Comprueba si una parámetro es nulo. + * + * @param parameter + * Parámetro a comprobar. + * @return True si es nulo, False en caso contrario. + */ + public static boolean isNull(Object parameter) { + return (parameter == null); + } + + /** + * Comprueba si una cadena está vacía. + * + * @param parameter + * Parámetro a comprobar. + * @return True si es la cadena vacía, False en caso contrario. + * @throws IllegalArgumentException + * Si el parámetro es nulo. + */ + public static boolean isEmpty(String parameter) { + Validator.notNull(parameter); + return (parameter.trim() + .isEmpty()); + } + + /** + * Comprueba si un array está vacío. + * + * @param parameter + * Parámetro a comprobar. + * @return True si el array está vacío, False en caso contrario. + * + * @throws IllegalArgumentException + * Si el parámetro es nulo. + */ + public static boolean isEmpty(Object[] parameter) { + Validator.notNull(parameter); + return (parameter.length == 0); + } + + /** + * Comprueba si un valor es negativo. + * + * @param value + * Valor a comprobar. + * + * @return True si el valor es negativo, False en caso contrario. + */ + public static boolean isNegative(double value) { + return (value < 0); + } + + /** + * Comprueba que un conjunto de valores esté desordenado + * + * @param values + * Valores a comprobar. + * + * @return True si los valores están en orden, False en caso contrario. + * + * @throws IllegalArgumentException + * Si los valores son nulos. + */ + public static boolean isOrdered(double[] values) { + + int length; + + Validator.notNull(values); + + length = values.length; + if (length < 2) + return true; + for (int i = 0; i < length; i++) { + for (int j = 0; j < i; j++) + if (values[j] > values[i]) + return false; + for (int j = i + 1; j < length; j++) + if (values[j] < values[i]) + return false; + } + return true; + } + + /** + * Comprueba que un conjunto de valores esté ordenado de forma estricta. + * + * @param values + * Valores a comprobar. + * @return True si los valores están en orden extricto, False en caso contrario. + * @throws IllegalArgumentException + * Si los valores son nulos. + */ + public static boolean isStrictlyOrdered(double[] values) { + + int length; + + Validator.notNull(values); + + length = values.length; + if (length < 2) + return true; + for (int i = 0; i < length; i++) { + for (int j = 0; j < i; j++) + if (values[j] >= values[i]) + return false; + for (int j = i + 1; j < length; j++) + if (values[j] <= values[i]) + return false; + } + return true; + } + + /** + * Comprueba que un elemento sea de alguno de los tipos indicados. + * + * @param object + * Objeto que debe ser del tipo indicado. + * @param types + * Tipos permitidos. + * @return True si el elemento es de alguno de los tipos indicados, False en + * caso contrario. + * @throw IllegalArgumentException Si object es null o, + *

    + * si types está vacío o + *

    + * si types es null. + */ + public static boolean validElementType(Object object, String[] types) { + + Validator.notEmpty(types); + Validator.notNull(object); + + String objectClass = object.getClass() + .toString(); + + for (String type : types) + if (objectClass.equals(type)) + return true; + + return false; + } + + /** + * Comprueba si una cadena es nula o está vacía. + * + * @param parameter + * Parámetro a comprobar. + * @return True si es la cadena es nula o está vacía, False en caso contrario. + */ + public static boolean isNullOrEmpty(String parameter) { + return (parameter == null) ? true + : parameter.trim() + .isEmpty(); + } + + public static boolean isSameElement(Object element, Object other) { + return (element == other); + } + + /** + * Comprueba que un parametro no sea nulo. + * + * @param parameter + * Parametro a comprobar. + * + * @throws IllegalArgumentException + * Si el parámetro es nulo. + */ + public static void notNull(Object parameter) { + if (Validator.isNull(parameter)) + throw new IllegalArgumentException(Validator.NOT_NULL); + } + + /** + * Comprueba que una cadena no sea vacía. + * + * @param parameter + * Parametro a comprobar. + * @throws IllegalArgumentException + * Si la cadena está vacía o es nula. + */ + public static void notEmpty(String parameter) { + if (Validator.isEmpty(parameter)) + throw new IllegalArgumentException(Validator.NOT_EMPTY_STRING); + } + + /** + * Comprueba que un array no esté vacío + * + * @param parameter + * Array a comprobar. + * @throws IllegalArgumentException + * Si el array está vacía o es nulo. + */ + public static void notEmpty(Object[] parameter) { + if (Validator.isEmpty(parameter)) + throw new IllegalArgumentException(Validator.NOT_EMPTY_ARRAY); + } + + /** + * Comprueba que el tamaño de un elemento esté dentro de los valores permitidos. + * + * @param size + * Tamaño del elemento. + * @param minValidSize + * Tamaño mínimo permitido. + * @param maxValidSize + * Tamaño máximo permitido. + * @throws IllegalArgumentException + * Si el tamaño no está dentro del rango permitido o si el rango es + * inválido. + */ + public static void notInvalidSize(int size, int minValidSize, int maxValidSize) { + if (!Validator.inRange(size, minValidSize, maxValidSize)) + throw new IllegalArgumentException(Validator.INVALID_SIZE + Messages.ParameterValidator_Value_must_be_in_range_1 + size + ", " //$NON-NLS-1$ + + minValidSize + ", " //$NON-NLS-1$ + + maxValidSize + "]."); //$NON-NLS-1$ + } + + /** + * Comprueba que el tamaño de un elemento esté dentro de los valores permitidos. + * + * @param size + * Tamaño del elemento. + * @param minValidSize + * Tamaño mínimo permitido. + * @param maxValidSize + * Tamaño máximo permitido. + * @throws IllegalArgumentException + * Si el tamaño no está dentro del rango permitido o si el rango es + * inválido. + */ + public static void notInvalidSize(double size, double minValidSize, double maxValidSize, String parameterName) { + if (!Validator.inRange(size, minValidSize, maxValidSize)) + throw new IllegalArgumentException(Validator.INVALID_SIZE + "" + size + ", " //$NON-NLS-1$//$NON-NLS-2$ + + minValidSize + ", " //$NON-NLS-1$ + + maxValidSize + "]."); //$NON-NLS-1$ + } + + /** + * Comprueba que el tamaño de un elemento esté dentro de los valores permitidos. + * + * @param size + * Tamaño del elemento. + * @param minValidSize + * Tamaño mínimo permitido. + * @param maxValidSize + * Tamaño máximo permitido. + * @param includeStartpoint + * Incluir el valor inicial dentro del rango. + * @throws IllegalArgumentException + * Si el tamaño no está dentro del rango permitido o si el rango es + * inválido. + */ + public static void notInvalidSize(int size, int minValidSize, int maxValidSize, boolean includeStartpoint, boolean includeEndpoint, String parameterName) { + if (!Validator.inRange(size, minValidSize, maxValidSize, includeStartpoint, includeEndpoint)) { + String open = (includeEndpoint) ? "[" : "("; //$NON-NLS-1$ //$NON-NLS-2$ + String close = (includeEndpoint) ? "]" : ")"; //$NON-NLS-1$ //$NON-NLS-2$ + throw new IllegalArgumentException(Validator.INVALID_SIZE + Messages.ParameterValidator_Value_must_be_in_range_2 + open + minValidSize + ", " //$NON-NLS-1$ + + maxValidSize + close + "."); //$NON-NLS-1$ + } + + } + + /** + * Comprueba que el tamaño de un elemento esté dentro de los valores permitidos. + * + * @param size + * Tamaño del elemento. + * @param minValidSize + * Tamaño mínimo permitido. + * @param maxValidSize + * Tamaño máximo permitido. + * @param includeStartpoint + * Incluir el valor inicial dentro del rango. + * @throws IllegalArgumentException + * Si el tamaño no está dentro del rango permitido o si el rango es + * inválido. + */ + public static void notInvalidSize(double size, double minValidSize, double maxValidSize, boolean includeStartpoint, boolean includeEndpoint) { + if (!Validator.inRange(size, minValidSize, maxValidSize, includeStartpoint, includeEndpoint)) { + String open = (includeEndpoint) ? "[" : "("; //$NON-NLS-1$ //$NON-NLS-2$ + String close = (includeEndpoint) ? "]" : ")"; //$NON-NLS-1$ //$NON-NLS-2$ + throw new IllegalArgumentException(Validator.INVALID_SIZE + "" + open + minValidSize + ", " //$NON-NLS-1$//$NON-NLS-2$ + + maxValidSize + close + "."); //$NON-NLS-1$ + } + + } + + /** + * Comprueba que un valor no sea negativo. + * + * @param value + * Valor a comprobar. + * @throw IllegalArgumentException Si el parámetro es negativo. + */ + public static void notNegative(double value) { + if (Validator.isNegative(value)) + throw new IllegalArgumentException(Validator.NOT_NEGATIVE); + } + + /** + * Comprueba que un conjunto de valores no estén desordenados. + * + * @param values + * Valores a comprobar. + * @param strictlyOrder + * Orden estricto. + * @throw IllegalArgumentException Si los valores son nulos o están + * desordenados. + */ + public static void notDisorder(double[] values, boolean strictlyOrder) { + + boolean disorder; + + if (strictlyOrder) + disorder = !Validator.isStrictlyOrdered(values); + else + disorder = !Validator.isOrdered(values); + + if (disorder) + throw new IllegalArgumentException(Validator.NOT_DISORDER); + } + + /** + * Comprueba que un elemento sea de alguno de los tipos indicados. + * + * @param object + * Objeto que debe ser del tipo indicado. + * @param types + * Tipos permitidos. + * @throw IllegalArgumentException Si el objeto no es de alguno de los tipos + * indicados o, + *

    + * si object es null o, + *

    + * si types está vacío o + *

    + * si types es null. + */ + public static void notIllegalElementType(Object object, String[] types) { + if (!Validator.validElementType(object, types)) + throw new IllegalArgumentException(Validator.NOT_ILLEGAL_TYPE); + } + + public static void notSameElement(Object element, Object other) { + if (Validator.isSameElement(element, other)) + throw new IllegalArgumentException(Validator.NOT_SAME_ELEMENT); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/Messages.java b/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/Messages.java new file mode 100644 index 0000000..c793e49 --- /dev/null +++ b/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/Messages.java @@ -0,0 +1,22 @@ +// This file has been auto-generated +package flintstones.helper.validator.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public static String Cannot_pass_null_value; + public static String Cannot_pass_empty_string; + public static String ParameterValidator_Cannot_pass_empty_array; + public static String ParameterValidator_Invalid_size; + public static String ParameterValidator_Invalid_range; + public static String ParameterValidator_Cannot_pass_negative_value; + public static String ParameterValidator_Cannot_pass_disorder_values; + public static String ParameterValidator_Cannot_pass_illegal_objects; + public static String ParameterValidator_Cannot_pass_same_element; + public static String ParameterValidator_Value_must_be_in_range_1; + public static String ParameterValidator_Value_must_be_in_range_2; + +} diff --git a/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/messages.properties b/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/messages.properties new file mode 100644 index 0000000..6224772 --- /dev/null +++ b/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/messages.properties @@ -0,0 +1,11 @@ +Cannot_pass_empty_string=Cannot pass empty string +Cannot_pass_null_value=Cannot pass null value +ParameterValidator_Cannot_pass_disorder_values=Cannot pass disorder values +ParameterValidator_Cannot_pass_empty_array=Cannot pass empty array +ParameterValidator_Cannot_pass_illegal_objects=Cannot pass illegal objects +ParameterValidator_Cannot_pass_negative_value=Cannot pass negative value +ParameterValidator_Cannot_pass_same_element=Cannot pass same element +ParameterValidator_Invalid_range=Invalid range +ParameterValidator_Invalid_size=Invalid size +ParameterValidator_Value_must_be_in_range_1=\ Value must be in range [ +ParameterValidator_Value_must_be_in_range_2=\ Value must be in range \ No newline at end of file diff --git a/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/messages_es.properties b/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/messages_es.properties new file mode 100644 index 0000000..a924406 --- /dev/null +++ b/bundles/flintstones.helper.validator/src/flintstones/helper/validator/messages/messages_es.properties @@ -0,0 +1,9 @@ +ParameterValidator_Cannot_pass_disorder_values=No se pueden pasar valores desordenados +ParameterValidator_Cannot_pass_empty_array=No se puede pasar un array vaco +ParameterValidator_Cannot_pass_illegal_objects=No se puede pasar objetos invlidos +ParameterValidator_Cannot_pass_negative_value=No se puede pasar valores negativos +ParameterValidator_Cannot_pass_same_element=No se puede pasar elementos iguales +ParameterValidator_Invalid_range=Rango invlidos +ParameterValidator_Invalid_size=Tamao invlido +ParameterValidator_Value_must_be_in_range_1=\\ El valor debe de estar en el rango [ +ParameterValidator_Value_must_be_in_range_2=\\ El valor debe de estar en el rango \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/.classpath b/bundles/flintstones.helper.wtable/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.helper.wtable/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.helper.wtable/.polyglot.META-INF b/bundles/flintstones.helper.wtable/.polyglot.META-INF new file mode 100644 index 0000000..37b47e9 --- /dev/null +++ b/bundles/flintstones.helper.wtable/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.helper.wtable + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Wtable + diff --git a/bundles/flintstones.helper.wtable/.project b/bundles/flintstones.helper.wtable/.project new file mode 100644 index 0000000..6aea21e --- /dev/null +++ b/bundles/flintstones.helper.wtable/.project @@ -0,0 +1,45 @@ + + + flintstones.helper.wtable + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362616 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.helper.wtable/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.helper.wtable/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.helper.wtable/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.helper.wtable/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.helper.wtable/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.helper.wtable/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.helper.wtable/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.helper.wtable/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.helper.wtable/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.helper.wtable/META-INF/MANIFEST.MF b/bundles/flintstones.helper.wtable/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8b47588 --- /dev/null +++ b/bundles/flintstones.helper.wtable/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Wtable +Bundle-SymbolicName: flintstones.helper.wtable +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.swt;visibility:=reexport, + de.kupzog.ktable;visibility:=reexport +Export-Package: flintstones.helper.wcellrenderer, + flintstones.helper.wtable, + flintstones.helper.wtable.cell, + flintstones.helper.wtable.event, + flintstones.helper.wtable.example, + flintstones.helper.wtable.interfaces, + flintstones.helper.wtable.wcelleditor +Automatic-Module-Name: flintstones.helper.wtable diff --git a/bundles/flintstones.helper.wtable/build.properties b/bundles/flintstones.helper.wtable/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.helper.wtable/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererDisabled.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererDisabled.java new file mode 100644 index 0000000..85aed64 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererDisabled.java @@ -0,0 +1,26 @@ +package flintstones.helper.wcellrenderer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; + +/** + * @author Sinbad2 + * + */ +public class WCellRendererDisabled extends FixedCellRenderer { + + /** + * Disable cell / light shadow cell + */ + public WCellRendererDisabled() { + super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + this.setBackground(Display.getCurrent() + .getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); + this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererEmpty.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererEmpty.java new file mode 100644 index 0000000..7012690 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererEmpty.java @@ -0,0 +1,26 @@ +package flintstones.helper.wcellrenderer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; + +/** + * @author Sinbad2 + * + */ +public class WCellRendererEmpty extends FixedCellRenderer { + + /** + * Emprty cell / white cell + */ + public WCellRendererEmpty() { + super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + this.setBackground(Display.getCurrent() + .getSystemColor(SWT.COLOR_WHITE)); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererFilled.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererFilled.java new file mode 100644 index 0000000..a3c56b6 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererFilled.java @@ -0,0 +1,26 @@ +package flintstones.helper.wcellrenderer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; + +/** + * @author Sinbad2 + * + */ +public class WCellRendererFilled extends FixedCellRenderer { + + /** + * Filled cell / white cell with black text + */ + public WCellRendererFilled() { + super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + this.setBackground(Display.getCurrent() + .getSystemColor(SWT.COLOR_WHITE)); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererHeader.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererHeader.java new file mode 100644 index 0000000..881d8d9 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererHeader.java @@ -0,0 +1,23 @@ +package flintstones.helper.wcellrenderer; + +import org.eclipse.swt.SWT; + +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; + +/** + * @author Sinbad2 + * + */ +public class WCellRendererHeader extends FixedCellRenderer { + + /** + * Header cell / gray cell + */ + public WCellRendererHeader() { + super(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererRight.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererRight.java new file mode 100644 index 0000000..8897776 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererRight.java @@ -0,0 +1,26 @@ +package flintstones.helper.wcellrenderer; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; + +/** + * @author Sinbad2 + * + */ +public class WCellRendererRight extends FixedCellRenderer { + + /** + * Red cell/wrong cell + */ + public WCellRendererRight() { + super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + this.setBackground(new Color(Display.getCurrent(), new RGB(240, 248, 255))); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererWrong.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererWrong.java new file mode 100644 index 0000000..029eec4 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wcellrenderer/WCellRendererWrong.java @@ -0,0 +1,26 @@ +package flintstones.helper.wcellrenderer; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; + +/** + * @author Sinbad2 + * + */ +public class WCellRendererWrong extends FixedCellRenderer { + + /** + * Red cell/wrong cell + */ + public WCellRendererWrong() { + super(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + this.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + this.setBackground(new Color(Display.getCurrent(), new RGB(255, 160, 160))); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTable.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTable.java new file mode 100644 index 0000000..826882d --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTable.java @@ -0,0 +1,31 @@ +package flintstones.helper.wtable; + +import org.eclipse.swt.widgets.Composite; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableModel; + +/** + * The Class WTable, wrapper around ktable. + */ +public class WTable extends KTable { + + /** + * Instantiates a new w table. + * + * @param parent the parent + * @param style the style + */ + public WTable(Composite parent, int style) { + super(parent, style); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTable#setModel(de.kupzog.ktable.KTableModel) */ + @Override + public void setModel(KTableModel model) { + super.setModel(model); + } + +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableContent.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableContent.java new file mode 100644 index 0000000..9f441b2 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableContent.java @@ -0,0 +1,100 @@ +package flintstones.helper.wtable; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * @author Sinbad2 + * Table content matrix + */ +class WTableContent { + private final HashMap> items; + private final Integer sizeX; + private final Integer sizeY; + + /** + * Builder + */ + public WTableContent() { + this.sizeX = 0; + this.sizeY = 0; + this.items = new HashMap<>(); + } + + /** + * Builder with content + * @param itemsArr content matrix + */ + WTableContent(ArrayList> itemsArr) { + + // Obtener las dimensiones de la matriz + int maxI = 0; + int maxJ = 0; + int i; + + for (i = 0; i < itemsArr.size(); i++) + for (int j = 0; j < itemsArr.get(i) + .size(); j++) + if (j > maxJ) + maxJ = j; + + maxI = i; + maxJ++; + this.sizeX = maxI; + this.sizeY = maxJ; + + this.items = new HashMap<>(); + for (i = 0; i < itemsArr.size(); i++) { + this.items.put(i, new HashMap()); + for (int j = 0; j < itemsArr.get(i) + .size(); j++) + this.items.get(i) + .put(j, itemsArr.get(i) + .get(j)); + } + } + + /** + * @return The number of cols + */ + public Integer sizeX() { + return this.sizeX; + } + + /** + * @return The number of rows of the longer col + */ + public Integer sizeY() { + return this.sizeY; + } + + /** + * @param col col + * @param row row + * @return The item at the table col,row + */ + public Object get(int col, int row) { + + HashMap arr = this.items.get(col); + + if (arr == null) + return null; + + return arr.get(row); + } + + /** + * @param col col + * @param row row + * @param item Sets the item at the table col,row + */ + public void set(int col, int row, Object item) { + HashMap arrAnterior = this.items.get(col); + if (arrAnterior == null) + arrAnterior = new HashMap<>(); + + arrAnterior.put(row, item); + this.items.put(col, arrAnterior); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeader.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeader.java new file mode 100644 index 0000000..c7f10f6 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeader.java @@ -0,0 +1,91 @@ +package flintstones.helper.wtable; + +import java.util.ArrayList; + +/** + * The Class WTableHeader. + */ +class WTableHeader { + + /** The items. */ + public ArrayList items; + + /** + * Instantiates a new w table header. + */ + public WTableHeader() { + this.items = new ArrayList<>(); + } + + /** + * Instantiates a new w table header. + * + * @param headers + * the headers + */ + public WTableHeader(ArrayList headers) { + this.items = headers; + } + + /** + * Length. + * + * @return the integer + */ + + // N�mero de items + public Integer Length() { + return this.items.size(); + } + + /** + * Wide. + * + * @return the integer + */ + + // Si alg�n item tiene subgrupos es 2, sino es 1. + public Integer Wide() { + for (int i = 0; i < this.items.size(); i++) + if (this.items.get(i) + .hasSubItems()) + return 2; + + return 1; + } + + /** + * Adds the. + * + * @param item + * A�ade una cabecera + */ + public void add(WTableHeaderItem item) { + this.items.add(item); + } + + /** + * @param index The position of the item + * @return The item at the given position + */ + public WTableHeaderItem get(int index) { + if (index < this.items.size()) + return this.items.get(index); + + return null; + } + + /** + * Gets the main header text of a given index. + * + * @param index + * Posici�n + * @return the main + */ + public String getMainText(int index) { + if (index < this.items.size()) + return this.items.get(index) + .getMain(); + return ""; //$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeaderCell.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeaderCell.java new file mode 100644 index 0000000..18d3302 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeaderCell.java @@ -0,0 +1,63 @@ +package flintstones.helper.wtable; + +/** + * @author XXXX + * Header cell of the table + */ +class WTableHeaderCell { + String text = ""; //$NON-NLS-1$ + Boolean joinUp = false; + Boolean joinLeft = false; + + WTableHeaderCell(String text) { + this.text = text; + } + + WTableHeaderCell(String text, Boolean up, Boolean left) { + this.text = text; + this.joinUp = up; + this.joinLeft = left; + } + + @Override + public String toString() { + String str = this.text + " " + this.joinUp + " " + this.joinLeft; //$NON-NLS-1$ //$NON-NLS-2$ + + return str; + } + + /** + * @return Return true if the cell should join the cell at the left. + */ + public Boolean getJoinLeft() { + return this.joinLeft; + } + + /** + * @param joinLeft True if the cell should join the cell at left + */ + public void setJoinLeft(Boolean joinLeft) { + this.joinLeft = joinLeft; + } + + /** + * @return Return true if the cell should join the upper cell. + */ + public Boolean getJoinUp() { + return this.joinUp; + } + + /** + * @param joinUp True if cell should join the upper cell + */ + public void setJoinUp(Boolean joinUp) { + this.joinUp = joinUp; + } + + /** + * @return The cell label + */ + public String getText() { + return this.text; + } +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeaderItem.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeaderItem.java new file mode 100644 index 0000000..1faf947 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableHeaderItem.java @@ -0,0 +1,72 @@ +package flintstones.helper.wtable; + +/** + * The Class WTableHeaderItem. + */ +class WTableHeaderItem { + + /** The main item. */ + private final String mainItem; + + /** The sub items. */ + public String[] subItems; + + /** + * Inicializa sin grupos. + * + * @param text + * the text + */ + WTableHeaderItem(String text) { + this.mainItem = text; + this.subItems = null; + } + + /** + * Inicializa con grupos. + * + * @param text + * the text + * @param subgroups + * the subgroups + */ + public WTableHeaderItem(String text, String[] subgroups) { + this.mainItem = text; + this.subItems = subgroups; + } + + /** + * Adds subitems in bulk + * @param arr List of headers + */ + public void addSub(String[] arr) { + this.subItems = arr; + } + + /** + * Devuelve el texto de la cabecera principal. Si no hay grupo es el elemento, + * si hay grupo es el nombre del grupo. + * + * @return the main + */ + public String getMain() { + return this.mainItem; + } + + /** + * @param index Position of the item + * @return Return the subheader for the given position + */ + public String getSub(int index) { + return this.subItems[index]; + } + + /** + * Checks for subgroups. + * + * @return the boolean + */ + public Boolean hasSubItems() { + return this.subItems != null; + } +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableModel.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableModel.java new file mode 100644 index 0000000..2571ad3 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/WTableModel.java @@ -0,0 +1,1168 @@ +package flintstones.helper.wtable; + +import java.util.ArrayList; + +import org.eclipse.swt.graphics.Point; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableCellSelectionListener; +import de.kupzog.ktable.KTableNoScrollModel; +import flintstones.helper.wcellrenderer.WCellRendererEmpty; +import flintstones.helper.wcellrenderer.WCellRendererFilled; +import flintstones.helper.wcellrenderer.WCellRendererHeader; +import flintstones.helper.wcellrenderer.WCellRendererWrong; +import flintstones.helper.wtable.cell.WTableCell; +import flintstones.helper.wtable.event.WTableCellClickListener; +import flintstones.helper.wtable.event.WTableCellModifiedListener; +import flintstones.helper.wtable.exception.InvalidTypeException; +import flintstones.helper.wtable.interfaces.IWTableAbbreviation; +import flintstones.helper.wtable.interfaces.IWTableCellContent; +import flintstones.helper.wtable.interfaces.IWTableCellEditor; +import flintstones.helper.wtable.interfaces.IWTableCellEventClicked; +import flintstones.helper.wtable.interfaces.IWTableCellEventModified; +import flintstones.helper.wtable.interfaces.IWTableCellStyle; +import flintstones.helper.wtable.interfaces.IWTablePlaceholder; +import flintstones.helper.wtable.interfaces.IWTableRow; + +/** + * The Class WTableModel. + */ +public class WTableModel extends KTableNoScrollModel implements KTableCellSelectionListener, WTableCellClickListener { + + /** The Constant emptyCellPlaceholder. */ + private String emptyCellPlaceholder = "";//$NON-NLS-1$ + + /** The table. */ + private final /** The table. */ + KTable _table; + + /** The vertical header. col = 0 */ + private WTableHeader verticalHeader; + + /** The horizontal header. row = 0*/ + private WTableHeader horizontalHeader; + + /** The content matrix. */ + private WTableContent content; + + /** The abbreviation. */ + private WTableContent abbreviation; + + /** The placeholder. */ + private WTableContent placeholder; + + /** The cell size Y. */ + private Integer cellSizeHeight; + + /** The cell size X. */ + private Integer cellSizeWidth; + + /** The cell column ( without headers ). */ + private Integer currentCellY; + + /** The cell row ( without headers ). */ + private Integer currentCellX; + + /** Config. Minimum size for a cell to display it full text. If cell width is under it will display the abbreviation text */ + private Integer cellSizeWidthThreshold; + + /** If enabled will highlight cells without content. */ + private Boolean emptyIsWrong = false; + + /** Cell styles avaliable for use. */ + private final KTableCellRenderer cellHeader = new WCellRendererHeader(); + + /** The cell disabled. */ + // private KTableCellRenderer cellDisabled = new WCellRendererDisabled(); + + /** The cell filled. */ + private final KTableCellRenderer cellFilled = new WCellRendererFilled(); + + /** The cell empty. */ + private final KTableCellRenderer cellEmpty = new WCellRendererEmpty(); + + /** The cell wrong. */ + private final KTableCellRenderer cellWrong = new WCellRendererWrong(); + + /** The main header horizontal. */ + private /** The main header horizontal. */ + ArrayList mainHeaderHorizontal; + + /** The main header vertical. */ + private /** The main header vertical. */ + ArrayList mainHeaderVertical; + + /** The sub header horizontal. */ + private /** The sub header horizontal. */ + ArrayList subHeaderHorizontal; + + /** The sub header vertical. */ + private /** The sub header vertical. */ + ArrayList subHeaderVertical; + + /** + * Instantiates a new w table model. + * + * @param table the table + */ + public WTableModel(WTable table) { + this((KTable) table); + } + + /** + * Instantiates a new w table model. + * + * @param table the table + */ + public WTableModel(KTable table) { + + super(table); + this._table = table; + + this.horizontalHeader = new WTableHeader(); + this.verticalHeader = new WTableHeader(); + + this.setCellSizeHeight(20); + this.setCellSizeWidth(100); + this.setCellSizeWidthThreshold(50); + + this.content = new WTableContent(); + this.placeholder = new WTableContent(); + + // Add a listener to cell clicked to manage WCell cellclicked + this.addListener(this); + // contentAbbr = new WTableContent(); + } + + /** + * Inits the table model. + */ + public void init() { + this.initialize(); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableModel#getFixedHeaderRowCount() */ + @Override + public int getFixedHeaderRowCount() { + return this.verticalHeader.Wide(); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableModel#getFixedSelectableRowCount() */ + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableModel#getFixedHeaderColumnCount() */ + @Override + public int getFixedHeaderColumnCount() { + return this.horizontalHeader.Wide(); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableModel#getFixedSelectableColumnCount() */ + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableModel#isColumnResizable(int) */ + @Override + public boolean isColumnResizable(int col) { + return false; + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableModel#isRowResizable(int) */ + @Override + public boolean isRowResizable(int row) { + return false; + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableModel#getRowHeightMinimum() */ + @Override + public int getRowHeightMinimum() { + return this.getCellSizeHeight(); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#getInitialColumnWidth(int) */ + @Override + public int getInitialColumnWidth(int column) { + return this.getCellSizeWidth(); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#getInitialRowHeight(int) */ + @Override + public int getInitialRowHeight(int row) { + return this.getCellSizeHeight(); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#doGetContentAt(int, int) */ + @Override + public Object doGetContentAt(int col, int row) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + Object result = ""; //$NON-NLS-1$ + + // 1. Vertical header + if (this.isVerticalHeader(col, row)) { + if (col == 0 && row < this.mainHeaderVertical.size()) + result = this.mainHeaderVertical.get(row).text; + if (col == 1 && row < this.subHeaderVertical.size()) + result = this.subHeaderVertical.get(row).text; + // 2. Horizontal header + } else if (this.isHorizontalHeader(col, row)) { + if (row == 0 && col < this.mainHeaderHorizontal.size()) + result = this.mainHeaderHorizontal.get(col).text; + if (row == 1 && col < this.subHeaderHorizontal.size()) + result = this.subHeaderHorizontal.get(col).text; + } + // 3. Table content + else if (this.isCell(col, row)) { + + col = col - vSize; + row = row - hSize; + + result = this.getContentAt(col, row, true); + + } + + return result; + } + + /** + * Gets the content of a cell. + * + * @param col the column + * @param row the row + * @param abbr If enabled it will try to return the abbreviation instead of the placeholder. + * @return the content that the cell will display. It returns the object and the cell will display the method .toString() of the returned object. + */ + private Object getContentAt(int col, int row, Boolean abbr) { + + Object cell = this.content.get(col, row); + + if (cell != null) { + + // 1. CONTENT + if (cell instanceof IWTableCellContent) { + Object content = ((IWTableCellContent) cell).getContent(cell); + if (content != null) + return content; + } + + // 2. PLACEHOLDER TINY + if (abbr && this.getColumnWidth(col) < this.getCellSizeWidthThreshold() && cell instanceof IWTableAbbreviation) { + String content = ((IWTableAbbreviation) cell).getAbbreviation(); + if (content != null) + return content; + } + + // 3. PH + if (cell instanceof IWTablePlaceholder) { + String content = ((IWTablePlaceholder) cell).getPlaceholder(); + if (content != null) + return content; + } + + // 4.Content from var, toString called. + return cell; + + } + + // 5. Abbreviation if exist from var + if (abbr && this.getColumnWidth(col) < this.getCellSizeWidthThreshold() && this.abbreviation != null) { + cell = this.abbreviation.get(col, row); + if (cell != null) + return cell; + } + + // 6. Placeholder from var + else { + cell = this.placeholder.get(col, row); + if (cell != null) + return cell; + } + + // 7. No content + return this.getEmptyCellPlaceholder(); + + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#doBelongsToCell(int, int) */ + @Override + public Point doBelongsToCell(int col, int row) { + + // Headers must be cached before with cacheHeaders + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + if (this.isVerticalHeader(col, row)) { + + if (vSize == 1) + return new Point(col, row); + + if (col == 0 && row >= hSize) + if (row < this.mainHeaderVertical.size() && this.mainHeaderVertical.get(row).joinUp) + return new Point(col, row - 1); + + if (col == 1 && row >= hSize) + if (row < this.subHeaderVertical.size() && this.subHeaderVertical.get(row).joinLeft) + return new Point(col - 1, row); + + } + + if (this.isHorizontalHeader(col, row)) { + if (hSize == 1) + return new Point(col, row); + + if (row == 0 && col >= vSize) + if (col < this.mainHeaderHorizontal.size() && this.mainHeaderHorizontal.get(col).joinLeft) + return new Point(col - 1, row); + + if (row == 1 && col >= vSize) + if (col < this.mainHeaderHorizontal.size() && this.subHeaderHorizontal.get(col).joinUp) + return new Point(col, row - 1); + + } + + return new Point(col, row); + + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#doGetCellEditor(int, int) */ + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + col = col - vSize; + row = row - hSize; + + Object value = this.content.get(col, row); + if (value instanceof IWTableCellEditor) { + IWTableCellEditor cell = (IWTableCellEditor) value; + return cell.getCellEditor(); + } + + if (col < hSize || row < vSize) + return null; + return null; + /* return new WCellEditorSpinner(); return new WCellEditorFloatingSpinner(); + * String[] values = new String[] { "o1", "o2", "o3", "o4", "o5" }; + * KTableCellEditor combo = new WCellEditorCombo(values); return combo; */ + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#doSetContentAt(int, int, + * java.lang.Object) */ + @Override + public void doSetContentAt(int col, int row, Object value) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + col = col - vSize; + row = row - hSize; + + Object oldValue = this.content.get(col, row); + if (this.isChangeValid(col, row, oldValue, value)) { + + // Notify WTableCell when a control made a change + if (oldValue instanceof IWTableCellEventModified) { + IWTableCellEventModified item = (IWTableCellEventModified) oldValue; + item.cellModified(col, row, oldValue, value); + } + + // How should doSetContentAt be handled + if (oldValue instanceof IWTableCellContent) { + IWTableCellContent item = (IWTableCellContent) oldValue; + + if (item.shouldFireModifiedEvent()) + this.fireCellModifiedEvent(col, row, oldValue, value); + + if (item.shouldSetContent()) + this.content.set(col, row, value); + + } else { + this.fireCellModifiedEvent(col, row, oldValue, value); + this.content.set(col, row, value); + } + } + + // _table.redraw(); + + } + + /** + * Checks if a change in a cell is valid and should trigger the event. + * + * @param col the column + * @param row the row + * @param oldValue the old value + * @param newValue the new value + * @return If true change will be aplied and event will be fired. + */ + private Boolean isChangeValid(int col, int row, Object oldValue, Object newValue) { + + // Create new object if null to avoid comparing with null + Object o = new Object(); + if (newValue == null) + newValue = o; + if (oldValue == null) + oldValue = o; + + if (oldValue == newValue) + return false; + + // If the table is showing the abbreviation and a cell is opened for changing is + // value, we avoid it to save the abbreviation as a value + // if the user click out of the cell without editing it. + if (this.getColumnWidth(col) < this.getCellSizeWidthThreshold() && this.abbreviation.get(col, row) + .toString() + .equals(newValue.toString())) + return false; + + // Value won't change + if (oldValue != null) + if (oldValue.toString() + .equals(newValue.toString())) + return false; + + // Value changes but to a placeholders. Value should not be recorded. + if (this.placeholder.get(col, row) != null) { + if (newValue.toString() + .equals(this.placeholder.get(col, row) + .toString())) + return false; + } + + // There is no content or placeholder, we should avoid to save the empty cell + // value. + else if (newValue.toString() + .equals(this.getEmptyCellPlaceholder())) + return false; + + return true; + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#doGetCellRenderer(int, int) */ + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + + if (this.isHeader(col, row)) + return this.cellHeader; + else if (this.isCell(col, row)) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + col = col - vSize; + row = row - hSize; + + Object item = this.content.get(col, row); + if (item instanceof IWTableCellStyle) { + KTableCellRenderer renderer = ((IWTableCellStyle) item).getCellRenderer(); + if (renderer != null) + return renderer; + } + + if (this.content.get(col, row) != null) + return this.cellFilled; + else if (this.emptyIsWrong) + return this.cellWrong; + else + return this.cellEmpty; + } + return this.cellFilled; + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#doGetRowCount() */ + @Override + public int doGetRowCount() { + WTableContent c = this.content; + if (c.sizeX() == 0) + c = this.placeholder; + + int size = c.sizeY(); + int headerSize = this.verticalHeader.items.size(); + + int max = size > headerSize ? size : headerSize; + return max + this.horizontalHeader.Wide(); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#doGetColumnCount() */ + @Override + public int doGetColumnCount() { + WTableContent c = this.content; + if (c.sizeX() == 0) + c = this.placeholder; + + int size = c.sizeX(); + int headerSize = this.horizontalHeader.items.size(); + + int max = size > headerSize ? size : headerSize; + return max + this.verticalHeader.Wide(); + // return c.sizeX() + verticalHeader.Wide(); + } + + /* (non-Javadoc) + * + * @see de.kupzog.ktable.KTableDefaultModel#doGetTooltipAt(int, int) */ + @Override + public String doGetTooltipAt(int col, int row) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + Object resultado = ""; //$NON-NLS-1$ + if (this.isCell(col, row)) { + + col = col - vSize; + row = row - hSize; + + resultado = this.getContentAt(col, row, false); + + } + + return resultado.toString(); + + } + + /** + * Draw rating. + * + * @param col the col + * @param row the row + */ + private void cellClicked(int col, int row) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + if (!this.isHeader(col, row)) { + + col = col - vSize; + row = row - hSize; + + Object item = this.content.get(col, row); + + this.fireCellClickEvent(col, row, item); + } + + } + + /** + * Checks if is vertical header. + * + * @param col the col + * @param row the row + * @return the boolean + */ + private Boolean isVerticalHeader(int col, int row) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + if (col < vSize) + if (row >= hSize - 1) + return true; + return false; + + } + + /** + * Checks if is horizontal header. + * + * @param col the col + * @param row the row + * @return the boolean + */ + private Boolean isHorizontalHeader(int col, int row) { + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + if (row < hSize) + if (col >= vSize - 1) + return true; + return false; + + } + + /** + * Checks if is first cell. + * + * @param col the col + * @param row the row + * @return the boolean + */ + private Boolean isFirstCell(int col, int row) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + if (col == 0 && row == 0) + if (hSize != 0 && vSize != 0) + return true; + return false; + } + + /** + * Checks if is any kind of header. + * + * @param col the col + * @param row the row + * @return the boolean + */ + private Boolean isHeader(int col, int row) { + if (this.isFirstCell(col, row)) + return true; + + if (this.isVerticalHeader(col, row)) + return true; + + if (this.isHorizontalHeader(col, row)) + return true; + return false; + } + + /** + * Checks if is content cell. + * + * @param col Longitud de las columnas + * @param row Longitud de las filas + * @return the boolean + */ + private Boolean isCell(int col, int row) { + + int hSize = this.horizontalHeader.Wide(); + int vSize = this.verticalHeader.Wide(); + + if (col >= vSize && row >= hSize) + return true; + return false; + } + + /** + * Add content to the table. + * + * @param items Matrix with table items. + */ + @SuppressWarnings("unchecked") + public void addContent(Object items) { + if (items.getClass() != ArrayList.class) + throw new InvalidTypeException(items.getClass() + .toString()); + + this.content = new WTableContent((ArrayList>) items); + } + + /** + * Adds the rows. + * + * @param rows the rows + */ + public void addRows(IWTableRow[] rows) { + + ArrayList> items = new ArrayList<>(); + int cols = rows[0].getCells().length; + + for (int i = 0; i < cols; i++) + items.add(new ArrayList()); + + for (IWTableRow row : rows) { + for (int i = 0; i < cols; i++) + items.get(i) + .add(row.getCells()[i]); + } + + this.addContent(items); + + } + + /** + * Adds the abbreviation. + * + * @param items Matrix with table abbreviations. + */ + @SuppressWarnings("unchecked") + public void addAbbreviation(Object items) { + if (items.getClass() != ArrayList.class) + throw new InvalidTypeException(items.getClass() + .toString()); + + this.abbreviation = new WTableContent((ArrayList>) items); + } + + /** + * Adds the placeholder. + * + * @param items Matrix with table placeholder. + */ + @SuppressWarnings("unchecked") + public void addPlaceholder(Object items) { + if (items.getClass() != ArrayList.class) + throw new InvalidTypeException(items.getClass() + .toString()); + + this.placeholder = new WTableContent((ArrayList>) items); + } + + /** + * Adds the vertical headers. + * + * @param arr List with header text + */ + public void setVerticalHeaders(String[] arr) { + this.verticalHeader = new WTableHeader(); + this.addHeader(arr, this.verticalHeader); + this.cacheHeaders(); + } + + /** + * Adds the horizontal headers. + * + * @param arr List with header text + */ + public void setHorizontalHeaders(String[] arr) { + this.horizontalHeader = new WTableHeader(); + this.addHeader(arr, this.horizontalHeader); + this.cacheHeaders(); + } + + /** + * Adds the header. + * + * @param arr List with header text + * @param headerContainer Container for the header + */ + private void addHeader(String[] arr, WTableHeader headerContainer) { + for (String headerText : arr) { + WTableHeaderItem item = new WTableHeaderItem(headerText); + headerContainer.add(item); + } + } + + /** + * Cache how the headers should join. + */ + public void cacheHeaders() { + + this.mainHeaderHorizontal = new ArrayList<>(); + this.mainHeaderVertical = new ArrayList<>(); + this.subHeaderHorizontal = new ArrayList<>(); + this.subHeaderVertical = new ArrayList<>(); + + // V + int hSize = this.horizontalHeader.Wide(); + for (int i = 0; i < hSize; i++) { + this.mainHeaderVertical.add(new WTableHeaderCell("", false, false)); //$NON-NLS-1$ + this.subHeaderVertical.add(new WTableHeaderCell("", false, false)); //$NON-NLS-1$ + } + + for (WTableHeaderItem item : this.verticalHeader.items) + if (item.hasSubItems()) { + Boolean first = true; + for (String subItem : item.subItems) { + + // Up + if (first) { + this.mainHeaderVertical.add(new WTableHeaderCell(item.getMain())); + first = false; + } else + this.mainHeaderVertical.add(new WTableHeaderCell("", true, false)); //$NON-NLS-1$ + + // Down + this.subHeaderVertical.add(new WTableHeaderCell(subItem)); + + } + + } else { + this.mainHeaderVertical.add(new WTableHeaderCell(item.getMain(), false, false)); + this.subHeaderVertical.add(new WTableHeaderCell(item.getMain(), false, true)); + + } + + // H + int vSize = this.verticalHeader.Wide(); + for (int i = 0; i < vSize; i++) { + this.mainHeaderHorizontal.add(new WTableHeaderCell("", false, false)); //$NON-NLS-1$ + this.subHeaderHorizontal.add(new WTableHeaderCell("", false, false)); //$NON-NLS-1$ + } + + for (WTableHeaderItem item : this.horizontalHeader.items) + if (item.hasSubItems()) { + Boolean first = true; + for (String subItem : item.subItems) { + + // Up + if (first) { + this.mainHeaderHorizontal.add(new WTableHeaderCell(item.getMain())); + first = false; + } else + this.mainHeaderHorizontal.add(new WTableHeaderCell("", false, true)); //$NON-NLS-1$ + + // Down + this.subHeaderHorizontal.add(new WTableHeaderCell(subItem)); + + } + + } else { + this.mainHeaderHorizontal.add(new WTableHeaderCell(item.getMain(), false, false)); + this.subHeaderHorizontal.add(new WTableHeaderCell(item.getMain(), true, false)); + + } + + } + + /** + * Adds the sub headers. + * + * @param arr the subheaders text + * @param index the index of the parent header + * @param headerContainer the header container + */ + private void addSubHeaders(String[] arr, int index, WTableHeader headerContainer) { + headerContainer.get(index) + .addSub(arr); + } + + /** + * Adds the horizontal sub headers. + * + * @param arr the subheaders text + * @param index the index of the parent header + */ + public void addHorizontalSubHeaders(String[] arr, int index) { + this.addSubHeaders(arr, index, this.horizontalHeader); + this.cacheHeaders(); + } + + /** + * Adds the vertical sub headers. + * + * @param arr the subheaders text + * @param index the index of the parent header + */ + public void addVerticalSubHeaders(String[] arr, int index) { + this.addSubHeaders(arr, index, this.verticalHeader); + this.cacheHeaders(); + } + + /** + * Adds the content of a cell. + * + * @param col the col + * @param row the row + * @param value the value + */ + public void addContentAt(int col, int row, Object value) { + this.doSetContentAt(col, row, value); + } + + /** + * Removes the content of a cell. + * + * @param col the col + * @param row the row + */ + public void removeContentAt(int col, int row) { + this.doSetContentAt(col, row, null); + this._table.redraw(); + } + + /** + * Removes the current cell content. + */ + public void removeCurrentCellContent() { + this.removeContentAt(this.getCurrentCellY(), this.getCurrentCellX()); + } + + /** + * If enabled, cell without content will be highlighted. + * + * @param emptyIsWrong the new empty is wrong + */ + public void setEmptyIsWrong(Boolean emptyIsWrong) { + this.emptyIsWrong = emptyIsWrong; + } + + /** + * Sets the cell size width threshold. + * + * @param cellSizeWidthThreshold the cellSizeWidthThreshold to set + */ + public void setCellSizeWidthThreshold(Integer cellSizeWidthThreshold) { + this.cellSizeWidthThreshold = cellSizeWidthThreshold; + this._table.redraw(); + } + + /** + * Gets the cell size width threshold. + * + * @return the cellSizeWidthThreshold + */ + private Integer getCellSizeWidthThreshold() { + return this.cellSizeWidthThreshold; + } + + /** The cell click listener list. */ + private final ArrayList ccListenerList = new ArrayList<>(); + + /** The cell modified listener list. */ + private final ArrayList cmListenerList = new ArrayList<>(); + + /** + * Remove every listener. + */ + public void clearListeners() { + this.ccListenerList.clear(); + this.cmListenerList.clear(); + this._table.removeCellSelectionListener(this); + } + + /** + * Adds the listener. + * + * @param listener the listeneing class + */ + public void addListener(WTableCellClickListener listener) { + // KTable listener. WTableModel listen cell click on ktable and fire cellClicked + // outside ktable + + // Origintal listener + this._table.addCellSelectionListener(this); + + // Our listener + this.ccListenerList.add(listener); + } + + /** + * Adds the listener. + * + * @param listener the listeneing class + */ + public void addListener(WTableCellModifiedListener listener) { + this.cmListenerList.add(listener); + } + + /** + * Fire cell click event. + * + * @param col the col + * @param row the row + * @param item the sent item + */ + public void fireCellClickEvent(int col, int row, Object item) { + + Point p[] = this._table.getCellSelection(); + for (WTableCellClickListener cclistener : this.ccListenerList) { + cclistener.cellClicked(col, row, item); + + this.setCurrentCellY(p[0].x); + this.setCurrentCellX(p[0].y); + + } + } + + /** + * Fire cell modified event. + * + * @param col the column + * @param row the row + * @param oldValue the old value + * @param newValue the new value + */ + public void fireCellModifiedEvent(int col, int row, Object oldValue, Object newValue) { + + for (WTableCellModifiedListener cmlistener : this.cmListenerList) { + Point[] p = this._table.getCellSelection(); + + cmlistener.cellModified(col, row, oldValue, newValue); + + this.setCurrentCellY(p[0].x); + this.setCurrentCellX(p[0].y); + } + } + + /** + * Gets the cell size height. + * + * @return the cellSizeHeight + */ + private Integer getCellSizeHeight() { + return this.cellSizeHeight; + } + + /** + * Sets the cell size height. + * + * @param cellSizeHeight the cellSizeHeight to set + */ + public void setCellSizeHeight(Integer cellSizeHeight) { + this.cellSizeHeight = cellSizeHeight; + this._table.redraw(); + } + + /** + * Gets the cell size width. + * + * @return the cellSizeWidth + */ + private Integer getCellSizeWidth() { + return this.cellSizeWidth; + } + + /** + * Sets the cell size width. Won't work if the table is responsive + * + * @param cellSizeWidth the cellSizeWidth to set + */ + public void setCellSizeWidth(Integer cellSizeWidth) { + this.cellSizeWidth = cellSizeWidth; + // _table.redraw(); + } + + /** + * Gets the current cell Y. + * + * @return the currentCellY + */ + private Integer getCurrentCellY() { + return this.currentCellY; + } + + /** + * Sets the current cell Y. + * + * @param currentCellY the currentCellY to set + */ + private void setCurrentCellY(Integer currentCellY) { + this.currentCellY = currentCellY; + } + + /** + * Gets the current cell X. + * + * @return the currentCellX + */ + public Integer getCurrentCellX() { + return this.currentCellX; + } + + /** + * Sets the current cell X. + * + * @param currentCellX the currentCellX to set + */ + private void setCurrentCellX(Integer currentCellX) { + this.currentCellX = currentCellX; + } + + /* (non-Javadoc) + * @see de.kupzog.ktable.KTableCellSelectionListener#cellSelected(int, int, int) + */ + @Override + public void cellSelected(int col, int row, int statemask) { + this.cellClicked(col, row); + } + + /* (non-Javadoc) + * @see de.kupzog.ktable.KTableCellSelectionListener#fixedCellSelected(int, int, int) + */ + @Override + public void fixedCellSelected(int col, int row, int statemask) { + this.cellClicked(col, row); + } + + /** + * Gets the empty cell placeholder. + * + * @return The placeholder for empty cell + */ + public String getEmptyCellPlaceholder() { + return this.emptyCellPlaceholder; + } + + /** + * Sets the placeholder shown in empty cells. + * + * @param emptyCellPlaceholder the new empty cell placeholder + */ + public void setEmptyCellPlaceholder(String emptyCellPlaceholder) { + this.emptyCellPlaceholder = emptyCellPlaceholder; + } + + /* (non-Javadoc) + * @see flintstones.helper.wtable.event.WTableCellClickListener#cellClicked(int, int, java.lang.Object) + */ + @Override + public void cellClicked(int col, int row, Object text) { + + Object item = this.content.get(col, row); + + if (item instanceof IWTableCellEventClicked) { + IWTableCellEventClicked itemX = (IWTableCellEventClicked) item; + itemX.cellClicked(col, row, itemX); + this._table.redraw(); + } + + } + + /** + * Gets the vertical header. + * + * @param i the i + * @return the vertical header + */ + public String getVerticalHeader(int i) { + return this.mainHeaderVertical.get(i) + .getText(); + } + + /** + * Gets the horizontal header. + * + * @param i the i + * @return the horizontal header + */ + public String getHorizontalHeader(int i) { + return this.mainHeaderHorizontal.get(i) + .getText(); + } + + /* Fin listeners */ + +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/cell/WTableCell.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/cell/WTableCell.java new file mode 100644 index 0000000..72f7492 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/cell/WTableCell.java @@ -0,0 +1,11 @@ +package flintstones.helper.wtable.cell; + +@SuppressWarnings("javadoc") +public class WTableCell { + + @Override + public String toString() { + return ""; //$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/cell/WTableCellDeactivable.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/cell/WTableCellDeactivable.java new file mode 100644 index 0000000..b89f5d8 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/cell/WTableCellDeactivable.java @@ -0,0 +1,65 @@ +package flintstones.helper.wtable.cell; + +import de.kupzog.ktable.KTableCellRenderer; +import flintstones.helper.wcellrenderer.WCellRendererDisabled; +import flintstones.helper.wcellrenderer.WCellRendererFilled; +import flintstones.helper.wcellrenderer.WCellRendererWrong; +import flintstones.helper.wtable.interfaces.IWTableCellStyle; + +/** + * The Class WTableCellDeactivable. + */ +public class WTableCellDeactivable extends WTableCell implements IWTableCellStyle { + + /** The renderer enabled. */ + public KTableCellRenderer rendererEnabled; + + /** The renderer disabled. */ + public KTableCellRenderer rendererDisabled; + + /** The renderer obligatory. */ + public KTableCellRenderer rendererObligatory; + + /** The enabled. */ + public boolean enabled = false; + + /** + * Instantiates a new w table cell deactivable. + * + * @param isEnabled the is enabled + */ + public WTableCellDeactivable(boolean isEnabled) { + rendererEnabled = new WCellRendererFilled(); + rendererDisabled = new WCellRendererDisabled(); + rendererObligatory = new WCellRendererWrong(); + + if(isEnabled) + enable(); + disable(); + + } + + /* (non-Javadoc) + * @see flintstones.helper.wtable.interfaces.IWTableCellStyle#getCellRenderer() + */ + @Override + public KTableCellRenderer getCellRenderer() { + if(enabled) + return rendererEnabled; + return rendererDisabled; + } + + /** + * Disable. + */ + public void disable() { + enabled = false; + } + + /** + * Enable. + */ + public void enable() { + enabled = true; + } +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/event/WTableCellClickListener.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/event/WTableCellClickListener.java new file mode 100644 index 0000000..248f143 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/event/WTableCellClickListener.java @@ -0,0 +1,14 @@ +package flintstones.helper.wtable.event; + +/** + * @author Sinbad 2 + * + */ +public interface WTableCellClickListener { + /** Listener that notifys on cell clicked + * @param col col + * @param row row + * @param text text + */ + void cellClicked(int col, int row, Object text); +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/event/WTableCellModifiedListener.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/event/WTableCellModifiedListener.java new file mode 100644 index 0000000..d3992a4 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/event/WTableCellModifiedListener.java @@ -0,0 +1,16 @@ +package flintstones.helper.wtable.event; + +/** + * @author Sinbad2 + * + */ +public interface WTableCellModifiedListener { + /** + * Listener thats notifys on cell changes. + * @param col col + * @param row row + * @param oldValue The older value of the cell + * @param newValue The new value of the cell + */ + void cellModified(int col, int row, Object oldValue, Object newValue); +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/example/ExampleTableModel.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/example/ExampleTableModel.java new file mode 100644 index 0000000..448ff7e --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/example/ExampleTableModel.java @@ -0,0 +1,124 @@ +package flintstones.helper.wtable.example; + +import java.util.ArrayList; + +import de.kupzog.ktable.KTable; +import flintstones.helper.wtable.WTableModel; + +/** + * @author Sinbad2 + * Example table to work with in a given composite + */ +@SuppressWarnings("nls") +public class ExampleTableModel { + + private static final String[] vHeader1 = new String[] { "11", "12" }; + private static final String[] vHeader = new String[] { "1", "2", "3", "4", "5" }; + + /** + * Builder that create some elements in memory to populate the table + */ + public ExampleTableModel() { + } + + private static final String[] hHeader = new String[] { "a", "b", "c", "d", "e", "f" }; + private static final String[] hSubHeader1 = new String[] { "a1", "a2" }; + private static final String[] hSubHeader2 = new String[] { "d1", "d2" }; + + ArrayList> contentItems = new ArrayList<>(); + ArrayList> abbreviation = new ArrayList<>(); + ArrayList> placeHolder = new ArrayList<>(); + + /** + * Basic table with single headers + * @param _table A kTable instance + * @param exampleText Some text to be added in every cell + * @return A WTableModel ready for usage + */ + public WTableModel getBasicTable(KTable _table, String exampleText) { + WTableModel w = new WTableModel(_table); + + // Cabeceras + w.setHorizontalHeaders(ExampleTableModel.hHeader); + w.setVerticalHeaders(ExampleTableModel.vHeader); + + // Contenido + this.addContentPlaceholderAbbreviation(exampleText); + + w.addContent(this.contentItems); + w.addAbbreviation(this.abbreviation); + w.addPlaceholder(this.placeHolder); + + return w; + } + + /** + * Basic table with single headers + * @param _table A kTable instance + * @param exampleText Some text to be added in every cell + * @param extraVHeader Should the extra vertical header be draw? + * @param extraHHeader Should the extra horizontal header be draw? + * @return A WTableModel ready for usage + */ + public WTableModel getFullTable(KTable _table, String exampleText, Boolean extraVHeader, Boolean extraHHeader) { + + WTableModel w = new WTableModel(_table); + // Cabeceras + w.setHorizontalHeaders(ExampleTableModel.hHeader); + if (extraHHeader) { + w.addHorizontalSubHeaders(ExampleTableModel.hSubHeader1, 0); + w.addHorizontalSubHeaders(ExampleTableModel.hSubHeader2, 3); + } + w.setVerticalHeaders(ExampleTableModel.vHeader); + if (extraVHeader) + w.addVerticalSubHeaders(ExampleTableModel.vHeader1, 0); + + // Contenido + this.addContentPlaceholderAbbreviation(exampleText); + + // Vacia celdas para ver si es robusta + this.contentItems.set(3, new ArrayList()); + this.placeHolder.set(2, new ArrayList()); + + w.addContent(this.contentItems); + w.addAbbreviation(this.abbreviation); + w.addPlaceholder(this.placeHolder); + + return w; + + } + + private void addContent(String exampleText) { + for (int i = 0; i < 8; i++) { + this.contentItems.add(new ArrayList()); + for (int j = 0; j < 8; j++) + this.contentItems.get(i) + .add(new ItemWTable("Cont " + exampleText, (1 + i) * (j + 1))); + } + } + + private void addPlaceholder(String exampleText) { + for (int i = 0; i < 8; i++) { + this.placeHolder.add(new ArrayList()); + for (int j = 0; j < 8; j++) + this.placeHolder.get(i) + .add(new ItemWTable("Dominio " + exampleText, (1 + i) * (j + 1))); + } + } + + private void addAbbreviation() { + for (int i = 0; i < 8; i++) { + this.abbreviation.add(new ArrayList()); + for (int j = 0; j < 8; j++) + this.abbreviation.get(i) + .add(new ItemWTable("D", i + j)); + } + } + + private void addContentPlaceholderAbbreviation(String exampleText) { + this.addPlaceholder(exampleText); + this.addContent(exampleText); + this.addAbbreviation(); + } + +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/example/ItemWTable.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/example/ItemWTable.java new file mode 100644 index 0000000..9fc4c71 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/example/ItemWTable.java @@ -0,0 +1,35 @@ +package flintstones.helper.wtable.example; + +/** + * The Class ItemWTable. + */ +class ItemWTable { + + private final /** The text. */ + String _text; + + private final /** The id. */ + int _id; + + /** + * Instantiates a new item W table. + * + * @param text + * the text + * @param id + * the id + */ + public ItemWTable(String text, int id) { + this._text = text; + this._id = id; + } + + /* (non-Javadoc) + * + * @see java.lang.Object#toString() */ + @Override + public String toString() { + return this._text + " " + this._id; //$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/exception/InvalidTypeException.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/exception/InvalidTypeException.java new file mode 100644 index 0000000..24a0745 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/exception/InvalidTypeException.java @@ -0,0 +1,19 @@ +package flintstones.helper.wtable.exception; + +/** + * @author Sinbad2 + * + */ +public class InvalidTypeException extends RuntimeException { + /** + * + */ + private static final long serialVersionUID = 2342304032009813014L; + + /** + * @param text Error text + */ + public InvalidTypeException(String text) { + super("Clase incorrecta, debe ser ArrayList> y se ha recibido " + text); //$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableAbbreviation.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableAbbreviation.java new file mode 100644 index 0000000..7af063a --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableAbbreviation.java @@ -0,0 +1,12 @@ +package flintstones.helper.wtable.interfaces; + +/** + * This class should be used on items added to WTable. It will define the short text of them. + * Future revisions may limit the length of this text. (5 char max should be fine) + */ +public interface IWTableAbbreviation { + /** + * @return The cell label abbreviation + */ + String getAbbreviation(); +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellContent.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellContent.java new file mode 100644 index 0000000..50cdfac --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellContent.java @@ -0,0 +1,27 @@ +package flintstones.helper.wtable.interfaces; + +/** + * This class allows the user to define the content of a table cell. + * Usually should return a String to show it as table text. + * It allows having an object into the table and controlling the text of the table based on the object state. + * Can also be used to control if the current cell should change it content to the one returned from the KTableCellEditor + * and if this change should be notified to other listeners. + */ +public interface IWTableCellContent { + + /** + * @param cellContent The cell content, need to be cast + * @return The cell content + */ + Object getContent(Object cellContent); + + /** + * @return true to fire modifiedEvent + */ + boolean shouldFireModifiedEvent(); + + /** + * @return true to let the table change it content by itself + */ + boolean shouldSetContent(); +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEditor.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEditor.java new file mode 100644 index 0000000..05cc09c --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEditor.java @@ -0,0 +1,17 @@ +package flintstones.helper.wtable.interfaces; + +import de.kupzog.ktable.KTableCellEditor; + +/** + * Allows to define the cell editor used to edit the current cell. + * Used along IWTableCellContent allows to show some text and rendering an editor when clicking the text. + */ +public interface IWTableCellEditor { + + /** + * Gets the cell editor. + * + * @return the cell editor + */ + KTableCellEditor getCellEditor(); +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEventClicked.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEventClicked.java new file mode 100644 index 0000000..8041646 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEventClicked.java @@ -0,0 +1,16 @@ +package flintstones.helper.wtable.interfaces; + +/** + * The Interface IWTableCellEventClicked allows a cell to execute code when clicked. + */ +public interface IWTableCellEventClicked { + + /** + * Cell clicked. + * + * @param col the col + * @param row the row + * @param content the content + */ + void cellClicked(int col, int row, Object content); +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEventModified.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEventModified.java new file mode 100644 index 0000000..90e59a5 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellEventModified.java @@ -0,0 +1,17 @@ +package flintstones.helper.wtable.interfaces; + +/** + * The Interface IWTableCellEventModified allows a cell to execute code when modified. + */ +public interface IWTableCellEventModified { + + /** + * Cell modified. + * + * @param col the col + * @param row the row + * @param oldContent the old content + * @param newContent the new content + */ + void cellModified(int col, int row, Object oldContent, Object newContent); +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellStyle.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellStyle.java new file mode 100644 index 0000000..80d5db9 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableCellStyle.java @@ -0,0 +1,18 @@ +package flintstones.helper.wtable.interfaces; + +import de.kupzog.ktable.KTableCellRenderer; + +/** + * The Interface IWTableCellStyle lets you define the renderer of a cell. + * Usually used to change cell and font color, background. + * + */ +public interface IWTableCellStyle { + + /** + * Gets the cell renderer. + * + * @return The cell label abbreviation + */ + KTableCellRenderer getCellRenderer(); +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTablePlaceholder.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTablePlaceholder.java new file mode 100644 index 0000000..91d3e5b --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTablePlaceholder.java @@ -0,0 +1,11 @@ +package flintstones.helper.wtable.interfaces; + +/** + * Allows to define a placeholder text in case that the items dont provide any. + */ +public interface IWTablePlaceholder { + /** + * @return The cell placeholder + */ + String getPlaceholder(); +} \ No newline at end of file diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableRow.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableRow.java new file mode 100644 index 0000000..61128d2 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/interfaces/IWTableRow.java @@ -0,0 +1,17 @@ +package flintstones.helper.wtable.interfaces; + +import flintstones.helper.wtable.cell.WTableCell; + +/** + * The Interface IWTableRow let you insert data in the wtable in rows that share some data. + */ +public interface IWTableRow { + + /** + * Should return every cell of the row. + * + * @return the cells + */ + WTableCell[] getCells(); + +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/ktable/KTableCellEditorComboFix.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/ktable/KTableCellEditorComboFix.java new file mode 100644 index 0000000..f03040e --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/ktable/KTableCellEditorComboFix.java @@ -0,0 +1,145 @@ +package flintstones.helper.wtable.ktable; +/* +FIX de la clase con el mismo nombre sin "FIX". +Arregla el combo +*/ +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; + +/** + * A combobox cell editor. + * + * @author Friederich Kupzog + */ +public class KTableCellEditorComboFix extends KTableCellEditor { + protected CCombo m_Combo; + private String m_Items[]; + private Cursor m_ArrowCursor; + + private KeyAdapter keyListener = new KeyAdapter() { + public void keyPressed(KeyEvent e) { + try { + onKeyPressed(e); + } catch (Exception ex) { + // Do nothing + } + e.doit = false; + } + }; + + private TraverseListener travListener = new TraverseListener() { + public void keyTraversed(TraverseEvent e) { + onTraverse(e); + } + }; + + // ATTENTION: Before the col/row parameters were mis-labeled. + public void open(KTable table, int col, int row, Rectangle rect) { + m_ArrowCursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW); + super.open(table, col, row, rect); + String content =m_Model.getContentAt(m_Col, m_Row).toString(); + m_Combo.setText(content); + m_Combo.setSelection(new Point(0, content.length())); + } + + public void close(boolean save) { + if (save) + m_Model.setContentAt(m_Col, m_Row, m_Combo.getText()); + m_Combo.removeKeyListener(keyListener); + m_Combo.removeTraverseListener(travListener); + super.close(save); + m_Combo = null; + m_ArrowCursor.dispose(); + } + + protected Control createControl() { + m_Combo = new CCombo(m_Table, SWT.READ_ONLY ); + m_Combo.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + + if (m_Items != null) + m_Combo.setItems(m_Items); + + m_Combo.addKeyListener(keyListener); + m_Combo.addTraverseListener(travListener); + + m_Combo.setCursor(m_ArrowCursor); + return m_Combo; + } + + /** + * Overwrite the onTraverse method to ignore arrowup and arrowdown + * events so that they get interpreted by the editor control.

    + * Comment that out if you want the up and down keys move the editor.
    + * Hint by David Sciamma. + */ + protected void onTraverse(TraverseEvent e) + { + // set selection to the appropriate next element: + switch (e.keyCode) + { + case SWT.ARROW_UP: // Go to previous item + case SWT.ARROW_DOWN: // Go to next item + { + // Just don't treat the event + break; + } + default: { + super.onTraverse(e); + break; + } + } + } + + public void setBounds(Rectangle rect) + { + super.setBounds(new Rectangle(rect.x, rect.y+1, + rect.width, rect.height-2)); + } + + public void setItems(String items[]) { + m_Items = items; + } + + /* (non-Javadoc) + * @see de.kupzog.ktable.KTableCellEditor#setContent(java.lang.String) + */ + public void setContent(Object content) { + if (content instanceof Integer) { + m_Combo.select(((Integer)content).intValue()); + } else if (content instanceof String) { + setSelectionToClosestMatch((String)content); + } else { + setSelectionToClosestMatch(content.toString()); + } + } + + private void setSelectionToClosestMatch(String content) { + content = content.toLowerCase(); + + String[] citems = m_Combo.getItems(); + String[] items = new String[citems.length]; + for (int i=0; i=0; length--) { + String part = content.substring(0, length); + for (int i=0; i WCellEditorFloatingSpinner.this.onTraverse(e); + + @Override + protected Control createControl() { + this.component = new Spinner(this.m_Table, SWT.NONE); + this.component.setDigits(this.digits); + // component.setMaximum(9); + // component.setMinimum(6); + this.component.addKeyListener(this.keyListener); + this.component.addTraverseListener(this.travListener); + + return this.component; + } + + @Override + public void setContent(Object content) { + this.component.setData(content); + } + + @Override + public void open(KTable table, int col, int row, Rectangle rect) { + super.open(table, col, row, rect); + + try { + Float val = Float.parseFloat(this.getEditorContent() + .replace(",", "."));// El la tabla se dibujan con coma pero para //$NON-NLS-1$ //$NON-NLS-2$ + // parsearlos hace falta punto. + Integer i = (int) (val * Math.pow(10, this.digits)); + this.component.setSelection(i); + } catch (java.lang.NumberFormatException e) { + this.component.setData(""); //$NON-NLS-1$ + } + + } + + @Override + public void close(boolean save) { + if (save) + this.m_Model.setContentAt(this.m_Col, this.m_Row, this.component.getText()); + super.close(save); + } + + protected String getEditorContent() { + return this.m_Model.getContentAt(this.m_Col, this.m_Row) + .toString(); + } +} diff --git a/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/wcelleditor/WCellEditorSpinner.java b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/wcelleditor/WCellEditorSpinner.java new file mode 100644 index 0000000..3171346 --- /dev/null +++ b/bundles/flintstones.helper.wtable/src/flintstones/helper/wtable/wcelleditor/WCellEditorSpinner.java @@ -0,0 +1,83 @@ +package flintstones.helper.wtable.wcelleditor; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Spinner; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; + +/** + * @author Sinbad2 + * Spinner cell + */ +public class WCellEditorSpinner extends KTableCellEditor { + + @Override + public int getActivationSignals() { + return KTableCellEditor.SINGLECLICK; + } + + Spinner component; + + // Cuando estas editanto el spinner, al pulsar en teclado + private final KeyAdapter keyListener = new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + try { + WCellEditorSpinner.this.onKeyPressed(e); + } catch (Exception ex) { + // Do nothing + } + } + }; + + // Cuando estas editanto el spinner, al moverte a otra celda con teclado + private final TraverseListener travListener = e -> WCellEditorSpinner.this.onTraverse(e); + + @Override + protected Control createControl() { + this.component = new Spinner(this.m_Table, SWT.NONE); + // component.setMaximum(9); + // component.setMinimum(6); + this.component.addKeyListener(this.keyListener); + this.component.addTraverseListener(this.travListener); + + return this.component; + } + + @Override + public void setContent(Object content) { + this.component.setData(content); + } + + @Override + public void open(KTable table, int col, int row, Rectangle rect) { + super.open(table, col, row, rect); + try { + Integer val = Integer.parseInt(this.getEditorContent()); + this.component.setSelection(val); + } catch (java.lang.NumberFormatException e) { + this.component.setData(""); //$NON-NLS-1$ + } + /* m_Text.setText(getEditorContent()); m_Text.selectAll(); + * m_Text.setVisible(true); m_Text.setFocus(); */ + } + + @Override + public void close(boolean save) { + if (save) + this.m_Model.setContentAt(this.m_Col, this.m_Row, this.component.getText()); + super.close(save); + } + + protected String getEditorContent() { + return this.m_Model.getContentAt(this.m_Col, this.m_Row) + .toString(); + } + +} diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/.classpath b/bundles/flintstones.method.ahp.phase.ranking.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/.polyglot.META-INF b/bundles/flintstones.method.ahp.phase.ranking.ui/.polyglot.META-INF new file mode 100644 index 0000000..3cc8281 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.phase.ranking.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/.project b/bundles/flintstones.method.ahp.phase.ranking.ui/.project new file mode 100644 index 0000000..cf17144 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.phase.ranking.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362619 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.phase.ranking.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..cb85848 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.ahp.phase.ranking.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.phase.ranking.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.method.ahp.phase.ranking, + javax.inject, + flintstones.helper.ui, + flintstones.helper.wtable, + org.eclipse.swt, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.helper.html, + flintstones.helper.data, + org.eclipse.osgi, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/build.properties b/bundles/flintstones.method.ahp.phase.ranking.ui/build.properties new file mode 100644 index 0000000..c81e30a --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml\ diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/plugin.xml b/bundles/flintstones.method.ahp.phase.ranking.ui/plugin.xml new file mode 100644 index 0000000..b75ac9f --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.phase.ranking.ui/src/flintstones/method/ahp/phase/ranking/ui/AHPRankingUI.java b/bundles/flintstones.method.ahp.phase.ranking.ui/src/flintstones/method/ahp/phase/ranking/ui/AHPRankingUI.java new file mode 100644 index 0000000..344c1d4 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking.ui/src/flintstones/method/ahp/phase/ranking/ui/AHPRankingUI.java @@ -0,0 +1,126 @@ +package flintstones.method.ahp.phase.ranking.ui; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.DoubleHelper; +import flintstones.helper.MatrixHelper; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.ahp.phase.ranking.AHPRankingModel; +import flintstones.model.ui.service.UiService; + +public class AHPRankingUI extends PhaseMethodUI { + + AHPRankingModel model; + + + @Inject + IEclipseContext context; + + @Override + public void init() { + model = (AHPRankingModel) this.getModel(); + model.execute(); + createPartControls(this.getBaseComposite()); + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return false; + } + + private void createPartControls(Composite parent) { + + UiService.setGridData(parent, 9, 9, true, true); + UiService.setGridLayout(parent, 1); + + createTitleRow(parent); + createTableRow(parent); + createTitleRow2(parent); + createResultViewer(parent); + + } + + private void createTitleRow2(Composite parent) { + Label titleLabel = new Label(parent, 0); + titleLabel.setText("Aggregating these two priorities it is obtained global priority"); + UiService.setGridData(titleLabel, -1, 1, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + } + + private void createTableRow(Composite parent) { + + Composite base = new Composite(parent, 0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 2, true); + + createCriteriaViewer(base); + createAlternativeViewer(base); + + } + + private void createTitleRow(Composite parent) { + + Composite base = new Composite(parent, 0); + UiService.setGridData(base, 9, -1, true, false); + UiService.setGridLayout(base, 2, true); + + Label titleLabel = new Label(base, 0); + titleLabel.setText("Priorities among criteria"); + UiService.setGridData(titleLabel, -1, 1, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + Label titleLabel2 = new Label(base, 0); + titleLabel2.setText("Local alternative priorities regarding criteria"); + UiService.setGridData(titleLabel2, -1, 1, true, false); + UiService.setFont(titleLabel2, UiService.FONT_SECTION_TITLE); + + } + + private void createResultViewer(Composite parent) { + Composite row2 = new Composite(parent, 0); + UiService.setGridData(row2, 9, 9, true, true); + UiService.setGridLayout(row2, 1); + + createRowTable(row2, model.getResult(), model.getAlternativeNames(), false); + } + + private void createAlternativeViewer(Composite row1) { + Composite right = new Composite(row1, 0); + UiService.setGridData(right, 9, 9, true, true); + UiService.setGridLayout(right, 1); + + createMatrix(right, model.getAlternativesPriorities(),model.getAlternativeNames(), model.getCriteriaPrioritiesNames()); + } + + private void createCriteriaViewer(Composite row1) { + Composite left = new Composite(row1, 0); + UiService.setGridData(left, 9, 9, true, true); + UiService.setGridLayout(left, 1); + + createRowTable(left, model.getCriteriaPriorities(), model.getCriteriaPrioritiesNames(), true); + } + + private void createRowTable(Composite base, double[] values, String[] items, boolean vertical) { + String[] valuesT = new String[values.length]; + for (int i = 0; i < values.length; i++) { + valuesT[i] = DoubleHelper.Draw(values[i]); + } + HtmlTextTable table = new HtmlTextTable(base, valuesT, items, vertical); + table.render(); + } + + private void createMatrix(Composite base, double[][] values, String[] alternatives, String[] criteria) { + String[][] valuesT = MatrixHelper.asString(values); + HtmlTextTable table = new HtmlTextTable(base, valuesT, criteria, alternatives); + table.render(); + } +} diff --git a/bundles/flintstones.method.ahp.phase.ranking/.classpath b/bundles/flintstones.method.ahp.phase.ranking/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.phase.ranking/.polyglot.META-INF b/bundles/flintstones.method.ahp.phase.ranking/.polyglot.META-INF new file mode 100644 index 0000000..8fd6469 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.phase.ranking + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ranking + diff --git a/bundles/flintstones.method.ahp.phase.ranking/.project b/bundles/flintstones.method.ahp.phase.ranking/.project new file mode 100644 index 0000000..97c39ea --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.phase.ranking + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362619 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.phase.ranking/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.phase.ranking/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ca8f267 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/META-INF/MANIFEST.MF @@ -0,0 +1,27 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ranking +Bundle-SymbolicName: flintstones.method.ahp.phase.ranking;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.phase.ranking +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.operator, + javax.inject, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric.real, + flintstones.operator.aggregation.geometricMean, + org.apache.commons.math3, + org.eclipse.e4.core.contexts, + flintstones.entity.ahp, + flintstones.model.ahppreferences.service, + flintstones.entity.ahppreferences, + flintstones.model.problemelement.service, + flintstones.entity.preferences.preferencecollection, + org.eclipse.e4.core.di, + flintstones.model.domain.service, + flintstones.helper.data, + flintstones.entity.domain, + flintstones.entity.method.phase +Export-Package: flintstones.method.ahp.phase.ranking diff --git a/bundles/flintstones.method.ahp.phase.ranking/assets/AHP Ranking.md b/bundles/flintstones.method.ahp.phase.ranking/assets/AHP Ranking.md new file mode 100644 index 0000000..4e08617 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/assets/AHP Ranking.md @@ -0,0 +1,47 @@ +

    + Snarkdown +
    +
    npm travis +

    + + +Snarkdown is a dead simple **1kb** [Markdown] parser. + +It's designed to be as minimal as possible, for constrained use-cases where a full Markdown parser would be inappropriate. + + +## Features + +- **Fast:** since it's basically one regex and a huge if statement +- **Tiny:** it's 1kb of gzipped ES3 +- **Simple:** pass a Markdown string, get back an HTML string + +> **Note:** Tables are not yet supported. If you love impossible to read regular expressions, submit a PR! + +## Demos & Examples + +- ⚛️ [**Snarky**](https://snarky.surge.sh) - markdown editor built with Preact & Snarkdown +- ✏️ [**Simple Markdown Editor**](http://jsfiddle.net/developit/828w6t1x/) + + +## Usage + +Snarkdown exports a single function, which parses a string of Markdown and returns a String of HTML. Couldn't be simpler. + +The snarkdown module is available in [every module format](https://unpkg.com/snarkdown/dist/) you'd ever need: ES Modules, CommonJS, UMD... + +```js +import snarkdown from 'snarkdown'; + +let md = '_this_ is **easy** to `use`.'; +let html = snarkdown(md); +console.log(html); +// this is easy to use. +``` + + +## License + +MIT + +[Markdown]: http://daringfireball.net/projects/markdown/ \ No newline at end of file diff --git a/bundles/flintstones.method.ahp.phase.ranking/build.properties b/bundles/flintstones.method.ahp.phase.ranking/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.phase.ranking/plugin.xml b/bundles/flintstones.method.ahp.phase.ranking/plugin.xml new file mode 100644 index 0000000..aa21ca5 --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.phase.ranking/src/flintstones/method/ahp/phase/ranking/AHPRankingModel.java b/bundles/flintstones.method.ahp.phase.ranking/src/flintstones/method/ahp/phase/ranking/AHPRankingModel.java new file mode 100644 index 0000000..d75ef7e --- /dev/null +++ b/bundles/flintstones.method.ahp.phase.ranking/src/flintstones/method/ahp/phase/ranking/AHPRankingModel.java @@ -0,0 +1,233 @@ +package flintstones.method.ahp.phase.ranking; + +import java.util.Arrays; + +import javax.inject.Inject; + +import org.apache.commons.math3.linear.EigenDecomposition; +import org.apache.commons.math3.linear.MatrixUtils; +import org.apache.commons.math3.linear.RealMatrix; +import org.apache.commons.math3.linear.RealVector; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.ahp.AHPAggregatedMatrix; +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; +import flintstones.helper.MatrixHelper; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; + +/** + * The Class AHPRankingModel. + */ +public class AHPRankingModel extends PhaseMethod { + + /** The op service. */ + @Inject + IOperatorService opService; + + /** The pref service. */ + @Inject + IProblemPreferencesService prefService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The context. */ + @Inject + IEclipseContext context; + + /* (non-Javadoc) + * @see flintstones.phasemethod.PhaseMethod#getName() + */ + @Override + public String getName() { + return "AHP Ranking"; + } + + /** The eigen vector criterion. */ + // Cache + double[] eigenVectorCriterion; + + /** The eigen matrix alternative. */ + double[][] eigenMatrixAlternative; + + /** The final eigen vector. */ + double[] finalEigenVector; + + /** The eigen vector criterions. */ + ProblemElement[] eigenVectorCriterions; + + /** The eigen matrix alternatives. */ + ProblemElement[] eigenMatrixAlternatives; + + /** + * Execute the model. + */ + public void execute() { + + eigenVectorCriterion = getCriterionEigenVector(); + eigenMatrixAlternative = getAlternativesEigenMatrix(); + + finalEigenVector = new double[eigenMatrixAlternative.length]; + + for (int i = 0; i < eigenMatrixAlternative.length; i++) { + + double[] sumVector = new double[eigenVectorCriterion.length]; + for (int j = 0; j < eigenVectorCriterion.length; j++) { + double a = eigenVectorCriterion[j]; + double b = eigenMatrixAlternative[i][j]; + double r = a * b; + sumVector[j] = r; + } + double sum = Arrays.stream(sumVector).sum(); + finalEigenVector[i] = sum; + + } + + } + + /** + * Gets the criterion eigen vector. + * + * @return the criterion eigen vector + */ + private double[] getCriterionEigenVector() { + double[] eigenVectorCriterion = new double[problemService.getAll(Criterion.Type).length]; + + // NEW + PreferenceCollection col = prefService.get(null, Expert.Type, Criterion.Type, Criterion.Type); + AHPAggregatedMatrix aggMatrix = aggregatedMatrix(col.getEveryAHPMatrix()); + // + + double[][] resultMatrix = aggMatrix.getResultMatrix(); + eigenVectorCriterions = aggMatrix.getRow(); + + RealMatrix realMatrix = MatrixUtils.createRealMatrix(resultMatrix); + EigenDecomposition descomposition = new EigenDecomposition(realMatrix); + + // Obtenemos el autovector (sin normalizar) del autovalor que le indiquemos + int pos = DoubleHelper.FindMaxIndex(descomposition.getRealEigenvalues()); + RealVector eigenVector = descomposition.getEigenvector(pos); + + eigenVectorCriterion = eigenVector.toArray(); + eigenVectorCriterion = DoubleHelper.Normalize(eigenVectorCriterion); + + return eigenVectorCriterion; + } + + /** + * Gets the alternatives eigen matrix. + * + * @return the alternatives eigen matrix + */ + private double[][] getAlternativesEigenMatrix() { + + double[][] eigenMatrixAlternativeMatrix = new double[problemService.getAll(Criterion.Type).length][problemService.getAll(Alternative.Type).length]; + PreferenceCollection col = prefService.get(Expert.Type, Criterion.Type, Alternative.Type, Alternative.Type); + + // Foreach criterion + ProblemElement[] criterions = eigenVectorCriterions; + for (int i = 0; i < criterions.length; i++) { + + ProblemElement c = criterions[i]; + + AHPAggregatedMatrix aggMatrix = aggregatedMatrix(col.getEveryAHPMatrixOther(c)); +// AHPAggregatedMatrix aggMatrix = getAggregatedMatrix(ahpService.getAllAlternativesPreferencesFor((Criterion)c)); + double[][] resultMatrix = aggMatrix.getResultMatrix(); + eigenMatrixAlternatives = aggMatrix.getRow(); + + RealMatrix realMatrix = MatrixUtils.createRealMatrix(resultMatrix); + EigenDecomposition descomposition = new EigenDecomposition(realMatrix); + + // Obtenemos el autovector (sin normalizar) del autovalor que le indiquemos + int pos = DoubleHelper.FindMaxIndex(descomposition.getRealEigenvalues()); + RealVector eigenVector = descomposition.getEigenvector(pos); + double[] eigenVectorArr = eigenVector.toArray(); + + eigenVectorArr = DoubleHelper.Normalize(eigenVectorArr); + eigenMatrixAlternativeMatrix[i] = eigenVectorArr; + } + + double[][] transposed = MatrixHelper.transpose(eigenMatrixAlternativeMatrix); + return transposed; + } + + /** + * Aggregates AHPMatrix into one matrix using geometric mean. + * + * @param preferences the preferences + * @return the AHP aggregated matrix + */ + private AHPAggregatedMatrix aggregatedMatrix(AHPMatrix[] preferences) { + AHPAggregatedMatrix aggregatedMatrix = ContextInjectionFactory.make(AHPAggregatedMatrix.class, context); + aggregatedMatrix.aggregate(preferences); + return aggregatedMatrix; + } + + + /** + * Gets the criteria priorities. + * + * @return the criteria priorities + */ + public double[] getCriteriaPriorities() { + return eigenVectorCriterion; + } + + /** + * Gets the criteria priorities names. + * + * @return the criteria priorities names + */ + public String[] getCriteriaPrioritiesNames() { + return Arrays.stream(eigenVectorCriterions).map(k -> k.getName()).sorted().toArray(String[]::new); + } + + /** + * Gets the alternatives priorities. + * + * @return the alternatives priorities + */ + public double[][] getAlternativesPriorities() { + return eigenMatrixAlternative; + } + + /** + * Gets the alternative names. + * + * @return the alternative names + */ + public String[] getAlternativeNames() { + return Arrays.stream(problemService.getAll(Alternative.Type)).map(k -> k.getName()).sorted().toArray(String[]::new); + } + + /** + * Gets the result. + * + * @return the result + */ + public double[] getResult() { + return finalEigenVector; + } + +} diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.classpath b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.polyglot.META-INF b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.polyglot.META-INF new file mode 100644 index 0000000..be4c9ad --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sort.fuzzy.ranking.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.project b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.project new file mode 100644 index 0000000..92e1c53 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sort.fuzzy.ranking.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362624 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..82e81d7 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.ahp.sort.fuzzy.ranking.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sort.fuzzy.ranking.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + javax.inject, + flintstones.model.problemelement.service, + flintstones.helper.html, + flintstones.entity.problemelement.ui, + flintstones.method.ahp.sortii.phase.ranking, + flintstones.method.ahp.sort.fuzzy.ranking, + flintstones.entity.method.phase, + flintstones.operator, + flintstones.entity.operator, + flintstones.valuation.proportionaltwotuple, + org.eclipse.e4.core.services, + flintstones.domain.fuzzyset.ui.chart, + flintstones.entity.domain, + org.jfree.chart.jfreechart diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/build.properties b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/plugin.xml b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/plugin.xml new file mode 100644 index 0000000..f2fe256 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/FuzzyAHPSortRankingUI.java b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/FuzzyAHPSortRankingUI.java new file mode 100644 index 0000000..53d3caf --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/FuzzyAHPSortRankingUI.java @@ -0,0 +1,294 @@ +package flintstones.method.ahp.sort.fuzzy.ranking.ui; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; + +import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.operator.AggregationOperator; +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.data.adapter.TableAdapter; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.ahp.sort.fuzzy.ranking.FuzzyAHPSortRanking; +import flintstones.method.ahp.sort.fuzzy.ranking.ui.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; +import flintstones.operator.service.IOperatorService; + +public class FuzzyAHPSortRankingUI extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + @Inject + IOperatorService operatorService; + + @Inject + @Translation + private Messages messages; + + Expert selectedExpert; + AggregationOperator operator; + LinguisticDomainChart chart; + Composite compositeChart; + + private ControlAdapter _controlListener; + + FuzzyAHPSortRanking model; + + HtmlTextTable profileGlobalTable; + HtmlTextTable alternativeGlobalTable; + HtmlTextTable alternativeAggregatedTable; + + @Override + public void init() { + model = (FuzzyAHPSortRanking) this.getModel(); + model.execute(); + + createPartControls(this.baseComposite); + } + + @Override + public void refresh() { + updateTables(); + updateChart(); + } + + @Override + protected boolean isForwardEnabled() { + // TODO Auto-generated method stub + return false; + } + + private void createPartControls(Composite base) { + + selectedExpert = (Expert) problemService.getAll(Expert.Type)[0]; + + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + Composite comboComposite = new Composite(base, SWT.NONE); + UiService.setGridData(comboComposite, 0, 9, false, false); + UiService.setGridLayout(comboComposite, 5); + ProblemElementSelector selectorExpert = new ProblemElementSelector(comboComposite, problemService.getAll(Expert.Type)); + selectorExpert.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + selectedExpert = (Expert) pe; + updateTables(); + updateChart(); + } + }); + + Combo typeSelector = new Combo(comboComposite, SWT.NONE); + typeSelector.add("Triangular"); //$NON-NLS-1$ + if (!model.central) + typeSelector.add("Trapezoidal"); //$NON-NLS-1$ + typeSelector.select(0); + + Label label = new Label(comboComposite, SWT.NONE); + label.setText("Alfa: "); + label.setVisible(false); + Spinner alfaValue = new Spinner(comboComposite, SWT.NONE); + alfaValue.setDigits(3); + alfaValue.setMinimum(0); + alfaValue.setMaximum(1000); + alfaValue.setValues(ChangeDoubleToInt(model.getAlfaValue(selectedExpert), alfaValue), 0, 1000, 3, 1, 1); + alfaValue.setVisible(false); + alfaValue.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + // Al modificar el valor Q, recalcula la solucion + model.setAlfaValue(selectedExpert, DoubleHelper.ParseDouble(alfaValue.getText())); + model.recalculate(); + updateTables(); + updateChart(); + sendRefresh(); + } + }); + + typeSelector.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + // Al modificar el ranking a usar, recalcula la solucion + switch (typeSelector.getSelectionIndex()) { + case 0: + model.triangular = true; + alfaValue.setVisible(false); + label.setVisible(false); + model.recalculate(); + updateTables(); + updateChart(); + break; + case 1: + model.triangular = false; + alfaValue.setValues(ChangeDoubleToInt(model.getAlfaValue(selectedExpert), alfaValue), 0, 1000, 3, 1, 1); + alfaValue.setVisible(true); + label.setVisible(true); + model.recalculate(); + break; + default: + model.triangular = true; + break; + } + + } + }); + + Composite compositeSuperior = new Composite(base, 0); + UiService.setGridData(compositeSuperior, 9, 9, true, true); + UiService.setGridLayout(compositeSuperior, 2); + + Composite classesPrioritiesComposite = createBlock(compositeSuperior, messages.profileGlobalPriorities); // $NON-NLS-1$ + UiService.setGridData(classesPrioritiesComposite, 9, 9, false, true); + createProfileGlobalPrioritiesTable(classesPrioritiesComposite); + + Composite alternativesPrioritiesComposite = createBlock(compositeSuperior, messages.alternativeGlobalPriorities); // $NON-NLS-1$ + createAlternativeGlobalPrioritiesTable(alternativesPrioritiesComposite); + + compositeChart = new Composite(base, SWT.NONE); + compositeChart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + updateChart(); + + // aggregationPart(compositeSuperior); + + } + + private void createAlternativeGlobalPrioritiesTable(Composite tableBase) { + + TableAdapter adapter = model.getAlternativeGlobalTable(selectedExpert); + alternativeGlobalTable = new HtmlTextTable(tableBase, adapter.getData(), adapter.getHorizontalHeaders(), adapter.getVerticalHeaders()); + + alternativeGlobalTable.render(); + } + + private void createProfileGlobalPrioritiesTable(Composite tableBase) { + + TableAdapter adapter = model.getClassesGlobalTable(selectedExpert); + profileGlobalTable = new HtmlTextTable(tableBase, adapter.getDataRow(), adapter.getHorizontalHeaders(), true); + profileGlobalTable.render(); + + } + + private void updateChart() { + removeChart(); + + Point size = compositeChart.getSize(); + chart = new LinguisticDomainChart(); + System.out.println(model.getMaxPriorityValue(selectedExpert)); + chart.initialize(model.getDomain(selectedExpert), compositeChart, size.x, size.y, 0, model.getMaxPriorityValue(selectedExpert) * 1.1, SWT.BORDER); + + if (_controlListener == null) { + _controlListener = new ControlAdapter() { + + @Override + public void controlResized(ControlEvent e) { + updateChart(); + } + }; + compositeChart.addControlListener(_controlListener); + } + } + + private void removeChart() { + if (chart != null) { + chart.getChartComposite().dispose(); + } + } + + private Composite createBlock(Composite parent, String name) { + + Composite base = new Composite(parent, SWT.NONE); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + CLabel title = new CLabel(base, SWT.NONE); + title.setText(name); + + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite tableBase = new Composite(base, SWT.NONE); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + return tableBase; + + } + + private void updateTables() { + + TableAdapter adapter1 = model.getAlternativeGlobalTable(selectedExpert); + TableAdapter adapter2 = model.getClassesGlobalTable(selectedExpert); + + profileGlobalTable.refresh(adapter2.getDataRow()); + alternativeGlobalTable.refresh(adapter1.getData()); + + profileGlobalTable.render(); + alternativeGlobalTable.render(); + } + + // Parte agregación + + /*private void aggregationPart(Composite compositeSuperior) { + Composite aggregatedPrioritiesComposite = createBlock(compositeSuperior, messages.aggregatedGlobalPriorities); // $NON-NLS-1$ + UiService.setGridData(aggregatedPrioritiesComposite, 9, 9, false, true); + UiService.setGridLayout(aggregatedPrioritiesComposite, 2); + Label operatorLabel = new Label(aggregatedPrioritiesComposite, SWT.NONE); + operatorLabel.setText(messages.operatorSelection); // $NON-NLS-1$ + Combo operatorSelector = new Combo(aggregatedPrioritiesComposite, SWT.NONE); + AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(ProportionalTwoTuple.ID, false); + String[] operatorsName = new String[operators.length]; + + for (int i = 0; i < operators.length; ++i) + operatorsName[i] = operators[i].getName(); + + operatorSelector.setItems(operatorsName); + operatorSelector.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + operator = operators[operatorSelector.getSelectionIndex()]; + } + + }); + operatorSelector.select(0); + // operatorId = operators[0].getId(); + + Composite aggregatedTableComposite = new Composite(aggregatedPrioritiesComposite, SWT.NONE); + UiService.setGridData(aggregatedTableComposite, 9, 9, true, true); + UiService.setGridLayout(aggregatedTableComposite, 1); + + createAlternativeAggregatedTable(aggregatedTableComposite); + }*/ + + /*private void createAlternativeAggregatedTable(Composite tableBase) { + TableAdapter adapter = model.getAggregatedTable(operator); + profileGlobalTable = new HtmlTextTable(tableBase, adapter.getDataRow(), adapter.getHorizontalHeaders(), true); + profileGlobalTable.render(); + }*/ + + private int ChangeDoubleToInt(double number, Spinner spinner) { + double newNumber = number; + newNumber *= Math.pow(10, spinner.getDigits()); + return (int) newNumber; + } + +} diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/Messages.java b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/Messages.java new file mode 100644 index 0000000..6e0d5b4 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/Messages.java @@ -0,0 +1,14 @@ +package flintstones.method.ahp.sort.fuzzy.ranking.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + public String profileGlobalPriorities; + public String alternativeGlobalPriorities; + public String aggregatedGlobalPriorities; + public String operatorSelection; + public String classesChart; + +} diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/messages.properties b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/messages.properties new file mode 100644 index 0000000..d09bc5b --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/messages.properties @@ -0,0 +1,5 @@ +profileGlobalPriorities=Classes global priorities +alternativeGlobalPriorities=Alternatives global priorities +aggregatedGlobalPriorities=Aggregated global priorities +operatorSelection=Select operator for aggregation: +classesChart=Classes chart \ No newline at end of file diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/messages_es.properties b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/messages_es.properties new file mode 100644 index 0000000..579bd5c --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking.ui/src/flintstones/method/ahp/sort/fuzzy/ranking/ui/messages/messages_es.properties @@ -0,0 +1,5 @@ +profileGlobalPriorities=Prioridades globales de las clases +alternativeGlobalPriorities=Prioridades globales de las alternativas +aggregatedGlobalPriorities=Prioridades globales agregadas +operatorSelection=Seleccione un operador para la agregacin: +classesChart=Grfico de clases diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.classpath b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.classpath new file mode 100644 index 0000000..c34bb53 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.polyglot.META-INF b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.polyglot.META-INF new file mode 100644 index 0000000..19b76fe --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sort.fuzzy.ranking + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.project b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.project new file mode 100644 index 0000000..124a1e7 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sort.fuzzy.ranking + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362624 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c872bd0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,10 @@ +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.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4bd0a01 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.ahp.sort.fuzzy.ranking;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sort.fuzzy.ranking +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.domain.fuzzyset, + flintstones.entity.method.phase, + flintstones.method.ahp.sortii.phase.ranking, + flintstones.model.ahpsort.profileassignment.service, + javax.inject, + flintstones.model.problemelement.service, + flintstones.entity.ahpsort.profileassignment, + flintstones.helper.data.wxml, + flintstones.valuation.proportionaltwotuple, + flintstones.helper.data, + flintstones.entity.valuation, + flintstones.operator, + org.eclipse.e4.core.contexts, + flintstones.entity.operator +Export-Package: flintstones.method.ahp.sort.fuzzy.ranking, + flintstones.method.ahp.sort.fuzzy.ranking.FuzzyClass diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/build.properties b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/plugin.xml b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/plugin.xml new file mode 100644 index 0000000..b0683a1 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/src/flintstones/method/ahp/sort/fuzzy/ranking/FuzzyAHPSortRanking.java b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/src/flintstones/method/ahp/sort/fuzzy/ranking/FuzzyAHPSortRanking.java new file mode 100644 index 0000000..e0f9ebf --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/src/flintstones/method/ahp/sort/fuzzy/ranking/FuzzyAHPSortRanking.java @@ -0,0 +1,307 @@ +package flintstones.method.ahp.sort.fuzzy.ranking; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.problemelement.entities.SortingProfile.SortingProfileType; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.LinkedHashMatrix; +import flintstones.helper.data.adapter.TableAdapter; +import flintstones.method.ahp.sort.fuzzy.ranking.FuzzyClass.FuzzyClass; +import flintstones.method.ahp.sortii.phase.ranking.AHPSortIIModelAgglomerative; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.proportionaltwotuple.ProportionalTwoTuple; + +public class FuzzyAHPSortRanking extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + IProfileAssignmentService profileService; + + @Inject + IOperatorService operatorService; + + AHPSortIIModelAgglomerative db; + + Expert[] experts; + Alternative[] alternatives; + SortingClass[] sortingClasses; + + public boolean triangular = true; + public boolean central = true; + + LinkedHashMap> expertClasses; // Expert, Classes + LinkedHashMap> tuples; + LinkedHashMap domains; + LinkedHashMap alfaValues; + + @Override + public String getName() { + return "FuzzyAHPSortRanking"; + } + + public void execute() { + db = (AHPSortIIModelAgglomerative) importData("model"); + if (profileService.getType() == SortingProfileType.Limiting) + central = false; + + ProblemElement[] aux = problemService.getAll(Expert.Type); + + experts = new Expert[aux.length]; + for (int i = 0; i < aux.length; i++) { + experts[i] = (Expert) aux[i]; + } + + aux = problemService.getAll(Alternative.Type); + + alternatives = new Alternative[aux.length]; + for (int i = 0; i < aux.length; i++) { + alternatives[i] = (Alternative) aux[i]; + } + + aux = problemService.getAll(SortingClass.Type); + + sortingClasses = new SortingClass[aux.length]; + for (int i = 0; i < aux.length; i++) { + sortingClasses[i] = (SortingClass) aux[i]; + } + + expertClasses = new LinkedHashMap<>(); + tuples = new LinkedHashMap<>(); + domains = new LinkedHashMap<>(); + alfaValues = new LinkedHashMap<>(); + + for (Expert expert : experts) { + alfaValues.put(expert, 0.0); + } + + createClassesFromProfiles(); + assignAlternativesToClasses(); + } + + public void recalculate() { + createClassesFromProfiles(); + assignAlternativesToClasses(); + } + + private void createClassesFromProfiles() { + + LinkedHashMap> profileGlobalPriorities = db.getProfileGlobalPriorities(); + + ArrayList globalPriorities; + LinkedList classes; + + for (Expert expert : experts) { + globalPriorities = new ArrayList(profileGlobalPriorities.get(expert).values()); + classes = new LinkedList(); + if (triangular) { + if (!central) + globalPriorities = limitingToCentralProfiles(globalPriorities); + for (int i = 0; i < globalPriorities.size(); i++) { // Triangular classes + if (i == 0) { // Class 1 + // a = cp2, b = cp1, d = Max + classes.add(new FuzzyClass(globalPriorities.get(1), globalPriorities.get(0), Integer.MAX_VALUE, i, sortingClasses[i].getName())); + } else if (i == globalPriorities.size() - 1) { // Class n + classes.add(new FuzzyClass(Integer.MIN_VALUE, globalPriorities.get(i), globalPriorities.get(i - 1), Integer.MAX_VALUE, + sortingClasses[i].getName())); // a=min, + // b=cpn, + // d=cp(n-1) + } else {// Remaining classes + classes.add(new FuzzyClass(globalPriorities.get(i + 1), globalPriorities.get(i), globalPriorities.get(i - 1), i, + sortingClasses[i].getName())); // a=cp(i+1), b=cpi, + // d=cp(i-1) + } + } + } else { + Double[] supportValues = new Double[globalPriorities.size() + 1]; + Double[] centralProfiles = new Double[globalPriorities.size() + 1]; + centralProfiles[0] = (1 + globalPriorities.get(0)) / 2; + centralProfiles[globalPriorities.size()] = globalPriorities.get(globalPriorities.size() - 1) / 2; + for (int i = 1; i <= globalPriorities.size(); i++) { // Support Values + if (i != globalPriorities.size()) + centralProfiles[i] = (globalPriorities.get(i) + globalPriorities.get(i - 1)) / 2; + supportValues[i] = globalPriorities.get(i - 1) - (centralProfiles[i] + alfaValues.get(expert)); + } + + System.out.println("Support:" + Arrays.toString(supportValues)); + System.out.println("GlobalPriorities: " + globalPriorities); + System.out.println("CentralProfiles:" + Arrays.toString(centralProfiles)); + + for (int i = 0; i < centralProfiles.length; i++) { // Trapezoidal classes + if (i == 0) { // Class 1 + classes.add(new FuzzyClass(globalPriorities.get(0) - supportValues[1], globalPriorities.get(0) + supportValues[1], Integer.MAX_VALUE, + Integer.MAX_VALUE, Double.NaN, supportValues[1], i, sortingClasses[i].getName())); + } else if (i == centralProfiles.length - 1) { // Class n + classes.add(new FuzzyClass(Integer.MIN_VALUE, Integer.MIN_VALUE, globalPriorities.get(i - 1) - supportValues[i], + globalPriorities.get(i - 1) + supportValues[i], supportValues[i], Double.NaN, Integer.MAX_VALUE, sortingClasses[i].getName())); + } else {// Remaining classes + classes.add(new FuzzyClass(globalPriorities.get(i) - supportValues[i + 1], globalPriorities.get(i) + supportValues[i + 1], + globalPriorities.get(i - 1) - supportValues[i], globalPriorities.get(i - 1) + supportValues[i], supportValues[i], + supportValues[i + 1], i, sortingClasses[i].getName())); + } + } + } + System.out.println(expert); + System.out.println(classes); + System.out.println(); + expertClasses.put(expert, classes); + } + } + + private void assignAlternativesToClasses() { + LinkedHashMap> alternativesGlobalPriorities = db.getAlternativeGlobalPriorities(); + + for (Expert expert : experts) { + LinkedHashMap expertAlternatives = alternativesGlobalPriorities.get(expert); + LinkedList classes = expertClasses.get(expert); + LinkedHashMap tupleList = new LinkedHashMap(); + FuzzySet fuzzySet = new FuzzySet(); + + for (FuzzyClass fuzzyClass : classes) { // Creamos el fuzzySet añadiendo una etiqueta por fuzzyClass + LabelLinguisticDomain label = new LabelLinguisticDomain(); + label.setName(fuzzyClass.getName()); + label.setSemantic(fuzzyClass); + fuzzySet.addLabel(label); + } + domains.put(expert, fuzzySet); + + for (Alternative alternative : this.alternatives) { + ProportionalTwoTuple tuple = new ProportionalTwoTuple(fuzzySet); // Creamos la tupla + boolean second = false; + FuzzyClass aux = null; + for (FuzzyClass fuzzyClass : classes) { + double membershipValue = fuzzyClass.getMembershipValue(expertAlternatives.get(alternative)); + if (second) { + tuple.setBeta(membershipValue); + tuple.setTerm2(fuzzySet.getLabelSet().getLabel(classes.size() - classes.indexOf(fuzzyClass) - 1)); + break; + } else if (membershipValue > 0) { + if (fuzzyClass.getClassNumber() == Integer.MAX_VALUE) { + tuple.setAlpha(aux.getMembershipValue(expertAlternatives.get(alternative))); + tuple.setTerm1(fuzzySet.getLabelSet().getLabel(classes.size() - classes.indexOf(fuzzyClass) - 1)); + tuple.setBeta(membershipValue); + tuple.setTerm2(fuzzySet.getLabelSet().getLabel(classes.size() - classes.indexOf(fuzzyClass) - 1)); + break; + } else { + tuple.setAlpha(membershipValue); // Asignamos el alfa al primer elemento con un valor de + // pertenencia mayor a 0 + tuple.setTerm1(fuzzySet.getLabelSet().getLabel(classes.size() - classes.indexOf(fuzzyClass) - 1)); + second = true; // Ponemos second a true para que el valor de pertenencia del siguiente + // elemento + // se asigne a beta. + } + } + aux = fuzzyClass; + } + tupleList.put(alternative, tuple); + } + tuples.put(expert, tupleList); + + } + } + + private ArrayList limitingToCentralProfiles(ArrayList globalPriorities) { + ArrayList centralProfiles = new ArrayList<>(); + centralProfiles.add((1 + globalPriorities.get(0)) / 2); + + for (int i = 1; i < globalPriorities.size(); i++) { + centralProfiles.add((globalPriorities.get(i) + globalPriorities.get(i - 1)) / 2); + } + centralProfiles.add(globalPriorities.get(globalPriorities.size() - 1) / 2); + return centralProfiles; + } + + @SuppressWarnings("unchecked") + public TableAdapter getClassesGlobalTable(Expert expert) { + HashMap data = (HashMap) db.getProfileGlobalPriorities().get(expert).clone(); + if (!central) { + SortingProfile fakeSortingProfile = new SortingProfile(expert, new Criterion(""), 0d); + fakeSortingProfile.setName(sortingClasses[sortingClasses.length - 1].getName() + " " + (sortingClasses.length - 1)); + data.put(fakeSortingProfile, 0d); + } + TableAdapter adapter = new TableAdapter(data); + return adapter; + } + + public TableAdapter getAlternativeGlobalTable(Expert expert) { + + HashMap data = db.getAlternativeGlobalPriorities().get(expert); + LinkedHashMap proportionalTwoTuples = tuples.get(expert); + + LinkedHashMatrix tableMatrix = new LinkedHashMatrix<>(); + FakeProblemElement f1 = new FakeProblemElement("Global priority"); + FakeProblemElement f2 = new FakeProblemElement("Proportional 2-tuple"); + + for (Entry entry : data.entrySet()) + tableMatrix.put(entry.getKey(), f1, entry.getValue()); + + if (proportionalTwoTuples != null) + for (Entry entry : proportionalTwoTuples.entrySet()) + tableMatrix.put(entry.getKey(), f2, entry.getValue()); + + TableAdapter adapter = new TableAdapter(tableMatrix); + + return adapter; + } + + public TableAdapter getAggregatedTable(AggregationOperator operator) { + LinkedHashMatrix tableMatrix = new LinkedHashMatrix<>(); + FakeProblemElement f2 = new FakeProblemElement("Aggregated Proportional Two Tuple"); + HashMap result = new HashMap<>(); + + + for (Alternative alternative : alternatives) { + LinkedList tuplesList = new LinkedList(); + for (Expert expert : experts) { + tuplesList.add((Valuation) tuples.get(expert).get(alternative)); + } + result.put(alternative, (ProportionalTwoTuple) operator.computeAggregation(tuplesList, null)); + } + + for (Entry entry : result.entrySet()) + tableMatrix.put(entry.getKey(), f2, entry.getValue()); + + TableAdapter adapter = new TableAdapter(tableMatrix); + + return adapter; + } + + public void setAlfaValue(Expert expert, Double value) { + alfaValues.put(expert, value); + } + + public double getAlfaValue(Expert expert) { + return alfaValues.get(expert); + } + + public Domain getDomain(Expert expert) { + return domains.get(expert); + } + + public double getMaxPriorityValue(Expert expert) { + return expertClasses.get(expert).getFirst().getB(); + } + +} diff --git a/bundles/flintstones.method.ahp.sort.fuzzy.ranking/src/flintstones/method/ahp/sort/fuzzy/ranking/FuzzyClass/FuzzyClass.java b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/src/flintstones/method/ahp/sort/fuzzy/ranking/FuzzyClass/FuzzyClass.java new file mode 100644 index 0000000..29eadf2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy.ranking/src/flintstones/method/ahp/sort/fuzzy/ranking/FuzzyClass/FuzzyClass.java @@ -0,0 +1,119 @@ +package flintstones.method.ahp.sort.fuzzy.ranking.FuzzyClass; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; + +public class FuzzyClass extends TrapezoidalFunction { + private int classNumber = 0; + private String className = null; + private double support1 = 0, support2 = 0; + + // Si b=c -> triangular + public FuzzyClass(double a, double b, double d, int classNumber) { + super(a, b, b, d); + this.classNumber = classNumber; + } + + public FuzzyClass(double a, double b, double d, int classNumber, String className) { + super(a, b, b, d); + this.classNumber = classNumber; + this.className = className; + } + + public FuzzyClass(double a, double b, double c, double d, double support1, double support2, int classNumber, String className) { + super(a, b, c, d); + this.classNumber = classNumber; + this.className = className; + this.support1 = support1; + this.support2 = support2; + } + + @Override + public double getMembershipValue(double x) { + if (this._b == this._c) { + if (classNumber == 0) { // Class 1 + if (x < this._a) { + return 0; + } else if (this._a <= x && x < this._b) { + return (x - _a) / (_b - _a); + } else if (this._b <= x) { + return 1; + } + } else if (classNumber == Integer.MAX_VALUE) { // Class n + if (this._d < x) { + return 0; + } else if (this._b < x && x <= this._d) { + return (_d - x) / (_d - _b); + } else if (x <= this._b) { + return 1; + } + } else { // Remaining classes + if (this._d < x || x < this._a) { + return 0; + } else if (this._a <= x && x < this._b) { + return (x - _a) / (_b - _a); + } else if (this._b < x && x <= this._d) { + return (_d - x) / (_d - _b); + } else if (x == this._b) { + return 1; + } + } + } else { + if (classNumber == 0) { // Class 1 + if (x < this._a) { + return 0; + } else if (this._a <= x && x < this._b) { + return (x - _a) / (2 * support2); + } else if (this._b <= x) { + return 1; + } + } else if (classNumber == Integer.MAX_VALUE) { // Class n + if (this._d < x) { + return 0; + } else if (this._c < x && x <= this._d) { + return (_c - x) / (2 * support1); + } else if (x <= this._c) { + return 1; + } + } else { // Remaining classes + if (this._d < x || x < this._a) { + return 0; + } else if (this._a <= x && x < this._b) { + return (x - _a) / (2 * support2); + } else if (this._c < x && x <= this._d) { + return (_d - x) / (2 * support1); + } else if (this._b <= x && x <= this._c) { + return 1; + } + } + } + return Double.NaN; + } + + public int getClassNumber() { + return classNumber; + } + + public String getClassName() { + if (className != null) { + return "Class " + className; + } else { + if (classNumber == Integer.MAX_VALUE) + return "Class n"; + return "Class " + classNumber; + } + } + + public String getName() { + return className; + } + + public String toString() { + if (className != null) + return "Class " + className + " - " + this._a + " - " + this._b + " - " + this._c + " - " + this._d; + + if (classNumber == Integer.MAX_VALUE) + return "Class n" + " - " + this._a + " - " + this._b + " - " + this._c + " - " + this._d; + return "Class " + classNumber + " - " + this._a + " - " + this._b + " - " + this._c + " - " + this._d; + + } +} diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/.classpath b/bundles/flintstones.method.ahp.sort.fuzzy/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/.polyglot.META-INF b/bundles/flintstones.method.ahp.sort.fuzzy/.polyglot.META-INF new file mode 100644 index 0000000..4994cde --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sort.fuzzy + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] FuzzyAHPSort + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/.project b/bundles/flintstones.method.ahp.sort.fuzzy/.project new file mode 100644 index 0000000..d9a2007 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sort.fuzzy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362621 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..cd8d089 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,15 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +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=disabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sort.fuzzy/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c063045 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: FuzzyAHPSort +Bundle-SymbolicName: flintstones.method.ahp.sort.fuzzy;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sort.fuzzy +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric, + flintstones.model.ahpsort.profileassignment.service diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/build.properties b/bundles/flintstones.method.ahp.sort.fuzzy/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/plugin.xml b/bundles/flintstones.method.ahp.sort.fuzzy/plugin.xml new file mode 100644 index 0000000..075a40f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/plugin.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/FuzzyAHPSortMethod.java b/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/FuzzyAHPSortMethod.java new file mode 100644 index 0000000..7dc1bc8 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/FuzzyAHPSortMethod.java @@ -0,0 +1,77 @@ +package flintstones.method.ahp.sort.fuzzy; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.ahp.sort.fuzzy.messages.Messages; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.valuation.numeric.NumericValuation; + +public class FuzzyAHPSortMethod extends ValidatedMethod { + @Inject + IProblemElementService problemService; + + @Inject + IProfileAssignmentService profileService; + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.method_name; // $NON-NLS-1$ + } + + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + String numProfileEntity = problemMessages.Profile_count; + String numSortingClassEntity = problemMessages.SortingClass_count; + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = new ValuationTypeOperation(valuationsEntity, + NumericValuation.class.getSimpleName(), valuations); + + int numProfiles = getProfilesByExpert(); + int numSortingClasses = problemService.getAll(SortingClass.Type).length; + + if (profileService.getType().equals(SortingProfile.SortingProfileType.Central)) { + validator.setReturn(this.getName()).greaterThan(numSortingClassEntity, numSortingClasses, 0) + .named("numSortingClasses") //$NON-NLS-1$ + .greaterThan(numProfileEntity, numProfiles, 0).named("numProfiles")//$NON-NLS-1$ + .equals(numProfileEntity, numProfiles, numSortingClasses).named("numProfiles")//$NON-NLS-1$ + .custom(valuationTypeOperator).named("valuations");//$NON-NLS-1$ + } else { + validator.setReturn(this.getName()).greaterThan(numSortingClassEntity, numSortingClasses, 0) + .named("numSortingClasses") //$NON-NLS-1$ + .greaterThan(numProfileEntity, numProfiles, 0).named("numProfiles")//$NON-NLS-1$ + .equals(numProfileEntity, numProfiles, numSortingClasses - 1).named("numProfiles")//$NON-NLS-1$ + .custom(valuationTypeOperator).named("valuations");//$NON-NLS-1$ + } + } + + private int getProfilesByExpert() { + int totalNumProfiles = problemService.getAll(SortingProfile.Type).length; + int numExperts = problemService.getAll(Expert.Type).length; + int numCriteria = problemService.getAll(Criterion.Type).length; + + if (numExperts > 0 && numCriteria > 0) { + int numProfiles = totalNumProfiles / numExperts; + return numProfiles /= numCriteria; + } else + return totalNumProfiles; + } +} diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/Messages.java b/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/Messages.java new file mode 100644 index 0000000..b797fb0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.ahp.sort.fuzzy.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + public String method_name; +} diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/messages.properties b/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/messages.properties new file mode 100644 index 0000000..31bad95 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/messages.properties @@ -0,0 +1 @@ +method_name=Fuzzy AHP Sort diff --git a/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/messages_es.properties b/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/messages_es.properties new file mode 100644 index 0000000..7796b8f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.fuzzy/src/flintstones/method/ahp/sort/fuzzy/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=AHP Sort difuso diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.classpath b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.polyglot.META-INF b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.polyglot.META-INF new file mode 100644 index 0000000..1e331eb --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sort.phase.groupaggregation.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.project b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.project new file mode 100644 index 0000000..b4e8bca --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sort.phase.groupaggregation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362628 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2e09c39 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.ahp.sort.phase.groupaggregation.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sort.phase.groupaggregation.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.method.ahp.sort.phase.groupaggregation, + org.eclipse.swt, + javax.inject, + flintstones.helper.ui, + flintstones.helper.html, + flintstones.entity.problemelement, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui, + flintstones.model.ahpsort.profileassignment.service diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/build.properties b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/plugin.xml b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/plugin.xml new file mode 100644 index 0000000..7fa838d --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/src/flintstones/method/ahp/sort/phase/groupaggregation/ui/AHPSortGroupAggregationUI.java b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/src/flintstones/method/ahp/sort/phase/groupaggregation/ui/AHPSortGroupAggregationUI.java new file mode 100644 index 0000000..9184dd5 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation.ui/src/flintstones/method/ahp/sort/phase/groupaggregation/ui/AHPSortGroupAggregationUI.java @@ -0,0 +1,79 @@ +package flintstones.method.ahp.sort.phase.groupaggregation.ui; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.ahp.sort.phase.groupaggregation.AHPSortGroupAggregationModel; +import flintstones.method.ahp.sort.phase.groupaggregation.GAHPSortResult; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.ui.service.UiService; + +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class AHPSortGroupAggregationUI extends PhaseMethodUI { + + @Inject + IProfileAssignmentService profileService; + + AHPSortGroupAggregationModel model; + + @Override + public void init() { + model = (AHPSortGroupAggregationModel) this.getModel(); + model.execute(profileService.getType().equals(SortingProfile.SortingProfileType.Central)); + createPartControls(this.getBaseComposite()); + + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return false; + } + + private void createPartControls(Composite parent) { + + UiService.setGridData(parent, 9, 9, true, true); + UiService.setGridLayout(parent, 1); + + Composite row = new Composite(parent, 0); + UiService.setGridLayout(row, 1); + UiService.setGridData(row, -1, 0, true, false); + + Label title = new Label(row,0); + title.setText("GAHPSort aggregated results"); + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite row1 = new Composite(parent,0); + UiService.setGridLayout(row1, 1); + UiService.setGridData(row1, 9, 9, true, true); + + ArrayList results = model.getResult(); + String[] colHeaders = new String[]{"Alternative", "Class", "Method"}; + + String[][] values = new String[model.getResult().size()][colHeaders.length]; + int i = 0; + GAHPSortResult[] sortedResults = results.stream().sorted( (a,b) -> a.getAlternative().getOrder() > b.getAlternative().getOrder() ? 1 : -1 ).toArray(GAHPSortResult[]::new); + for(GAHPSortResult result : sortedResults) { + values[i] = new String[3]; + values[i][0] = result.getAlternative().getName(); + values[i][1] = result.getSortClass().getName(); + values[i][2] = result.getType().toString(); + + i++; + } + + HtmlTextTable table = new HtmlTextTable(row1, values, colHeaders); + table.render(); + + } + +} diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.classpath b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.polyglot.META-INF b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.polyglot.META-INF new file mode 100644 index 0000000..6da3707 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sort.phase.groupaggregation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Groupaggregation + diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.project b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.project new file mode 100644 index 0000000..d3bc5e5 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sort.phase.groupaggregation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362625 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e15b27 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Groupaggregation +Bundle-SymbolicName: flintstones.method.ahp.sort.phase.groupaggregation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sort.phase.groupaggregation +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.extensionenum, + flintstones.helper.data, + flintstones.method.ahp.sort.phase.ranking, + javax.inject, + flintstones.model.problemelement.service, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment, + flintstones.entity.method.phase +Export-Package: flintstones.method.ahp.sort.phase.groupaggregation diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/build.properties b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/plugin.xml b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/plugin.xml new file mode 100644 index 0000000..451a8e1 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/src/flintstones/method/ahp/sort/phase/groupaggregation/AHPSortGroupAggregationModel.java b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/src/flintstones/method/ahp/sort/phase/groupaggregation/AHPSortGroupAggregationModel.java new file mode 100644 index 0000000..3a4d5e1 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/src/flintstones/method/ahp/sort/phase/groupaggregation/AHPSortGroupAggregationModel.java @@ -0,0 +1,243 @@ +package flintstones.method.ahp.sort.phase.groupaggregation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.data.Pair; +import flintstones.method.ahp.sort.phase.ranking.ExpertAHPSortModel; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class AHPSortGroupAggregationModel. + */ +public class AHPSortGroupAggregationModel extends PhaseMethod { + + // TODO: 06/06 revisar + boolean isOptimisitcx = false; + + boolean isCentralx = false; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** + * The Enum ClassificationType. + */ + public static enum ClassificationType implements ExtensionEnum { + + /** All agree in the class. */ + AllAgree, + + /** One class have at least 1 more than the others. */ + MostAgree, + + /** There where a tie and it was solved. */ + SolvedTie, + + /** Tie finally solved optimistic */ + SolvedTieOptimistic, + + /** Tie solved pesimistic . */ + SolvedTiePesimistic + } + + /** The results. */ + ArrayList results = new ArrayList<>(); + + /** The models. */ + // previous phase + private HashMap models; + + /** The experts. */ + private Expert[] experts; + + /* + * (non-Javadoc) + * + * @see flintstones.phasemethod.PhaseMethod#getName() + */ + @Override + public String getName() { + return "Group Aggregation"; + } + + /** + * Execute. + */ + @SuppressWarnings("unchecked") + public void execute(boolean useCentralProfiles) { + isCentralx = useCentralProfiles; + + models = (HashMap) importData("expertModels"); + experts = models.keySet().stream().toArray(Expert[]::new); + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + + for (ProblemElement a : alternatives) { + Pair pair = classify((Alternative) a); + SortingClass cclass = pair.getKey(); + ClassificationType type = pair.getValue(); + + results.add(new GAHPSortResult((Alternative) a, cclass, type)); + } + + } + + /** + * Classify. + * + * @param a the a + * @return the pair + */ + private Pair classify(Alternative a) { + + // AllAgree/MostAgree + + HashMap groups = new HashMap<>(); + for (Expert e : experts) { + SortingClass cclass = models.get(e).getClassification().get(a); + Integer count = groups.get(cclass); + if (count == null) + count = 0; + count++; + + groups.put(cclass, count); + + } + + // All Agree + if (groups.size() == 1) { + SortingClass cclass = groups.keySet().iterator().next(); + ClassificationType type = ClassificationType.AllAgree; + Pair pair = new Pair<>(cclass, type); + return pair; + } + + SortingClass biggerClass = null; + int biggerValue = 0; + boolean maxRepeated = false; + + for (Entry entry : groups.entrySet()) { + + int count = entry.getValue(); + if (count > biggerValue) { + biggerValue = count; + biggerClass = entry.getKey(); + maxRepeated = false; + } else if (count == biggerValue) { + maxRepeated = true; + } + + } + + // We have a winner! + if (!maxRepeated) { + SortingClass cclass = biggerClass; + ClassificationType type = ClassificationType.MostAgree; + Pair pair = new Pair<>(cclass, type); + return pair; + } + + // SolvedTie + + // Separate decision makers in groups + HashMap> classes = new HashMap<>(); + SortingClass[] tieClasses = groups.keySet().stream().toArray(SortingClass[]::new); + + // Init the lists + Arrays.stream(tieClasses).forEach(k -> classes.put(k, new ArrayList<>())); + + // Add each expert to the corresponding list + Arrays.stream(experts).forEach(e -> classes.get(models.get(e).getClassification().get(a)).add(e)); + + for (int i = 0; i < tieClasses.length - 1; i++) { + + SortingClass tieA = tieClasses[i]; + SortingClass tieB = tieClasses[i + 1]; + + Expert[] groupA = classes.get(tieA).toArray(new Expert[0]); + Expert[] groupB = classes.get(tieB).toArray(new Expert[0]); + + int comparaison = compare(groupA, groupB, a, i); + + if (comparaison > 0) + return new Pair<>(tieA, ClassificationType.SolvedTie); + else if (comparaison == 0) + if (isOptimisitcx) + return new Pair<>(tieA, ClassificationType.SolvedTie); + else + return new Pair<>(tieB, ClassificationType.SolvedTie); + + } + return new Pair<>(tieClasses[tieClasses.length-1], ClassificationType.SolvedTie); + + + } + + private int compare(Expert[] arr1, Expert[] arr2, Alternative a, int index) { + + Double sum1 = 0.0; + Double sum2 = 0.0; + + for (Expert classExpert : arr1) { + + // Sum all the values for the alternative ignoring class. + Double alternativeGlobalPriorityAgg = models.get(classExpert).getAlternativeGlobalPriorities().get(a) + .get(index); + + HashMatrix map = models.get(classExpert).getProfileGlobalPriorities(); + Double profileGlobalPriorityAgg = map.get(index).get(a); + + Double result = alternativeGlobalPriorityAgg - profileGlobalPriorityAgg; + if (isCentralx) { + result = alternativeGlobalPriorityAgg - profileGlobalPriorityAgg; + result = result < 0 ? result * -1 : result; + } + + sum1 += result; + + } + + for (Expert classExpert : arr2) { + // Sum all the values for the alternative ignoring class. + Double alternativeGlobalPriorityAgg = models.get(classExpert).getAlternativeGlobalPriorities().get(a) + .get(index); + + HashMatrix map = models.get(classExpert).getProfileGlobalPriorities(); + Double profileGlobalPriorityAgg = map.get(index).get(a); + + Double result = profileGlobalPriorityAgg - alternativeGlobalPriorityAgg; + if (isCentralx) { + result = profileGlobalPriorityAgg - alternativeGlobalPriorityAgg; + result = result < 0 ? result * -1 : result; + } + + sum2 += result; + + } + + return sum1.compareTo(sum2); + + } + + /** + * Gets the result. + * + * @return the result + */ + public ArrayList getResult() { + return results; + } + +} diff --git a/bundles/flintstones.method.ahp.sort.phase.groupaggregation/src/flintstones/method/ahp/sort/phase/groupaggregation/GAHPSortResult.java b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/src/flintstones/method/ahp/sort/phase/groupaggregation/GAHPSortResult.java new file mode 100644 index 0000000..2cbe1bf --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.groupaggregation/src/flintstones/method/ahp/sort/phase/groupaggregation/GAHPSortResult.java @@ -0,0 +1,62 @@ +package flintstones.method.ahp.sort.phase.groupaggregation; + +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.method.ahp.sort.phase.groupaggregation.AHPSortGroupAggregationModel.ClassificationType; + +/** + * The Class GAHPSortResult. (Support class) + */ +public class GAHPSortResult { + + /** The alternative. */ + Alternative alternative; + + /** The cclass. */ + SortingClass cclass; + + /** The type. */ + ClassificationType type; + + /** + * Instantiates a new GAHP sort result. + * + * @param alternative the alternative + * @param cclass the cclass + * @param type the type + */ + public GAHPSortResult(Alternative alternative, SortingClass cclass, ClassificationType type) { + this.alternative = alternative; + this.cclass = cclass; + this.type = type; + } + + /** + * Gets the alternative. + * + * @return the alternative + */ + public Alternative getAlternative() { + return alternative; + } + + /** + * Gets the sort class. + * + * @return the sort class + */ + public SortingClass getSortClass() { + return cclass; + } + + /** + * Gets the type. + * + * @return the type + */ + public ClassificationType getType() { + return type; + } + + +} diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.classpath b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.polyglot.META-INF b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.polyglot.META-INF new file mode 100644 index 0000000..54b2be1 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sort.phase.ranking.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.project b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.project new file mode 100644 index 0000000..3600f37 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sort.phase.ranking.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362630 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5dc3fe0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.ahp.sort.phase.ranking.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sort.phase.ranking.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.method.ahp.sort.phase.ranking, + org.eclipse.swt, + flintstones.model.ahppreferences.service, + javax.inject, + flintstones.helper.ui, + org.eclipse.e4.core.contexts, + flintstones.helper.html, + flintstones.entity.problemelement, + flintstones.model.problemelement.service, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment, + flintstones.model.domain.service, + flintstones.entity.domain, + flintstones.helper.data, + org.apache.commons.lang, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui, + flintstones.entity.problemelement.ui diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/build.properties b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/plugin.xml b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/plugin.xml new file mode 100644 index 0000000..ab8d423 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking.ui/src/flintstones/method/ahp/sort/phase/ranking/ui/AHPSortRankingUI.java b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/src/flintstones/method/ahp/sort/phase/ranking/ui/AHPSortRankingUI.java new file mode 100644 index 0000000..a34f116 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking.ui/src/flintstones/method/ahp/sort/phase/ranking/ui/AHPSortRankingUI.java @@ -0,0 +1,473 @@ +package flintstones.method.ahp.sort.phase.ranking.ui; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +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.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.problemelement.ui.widget.ProblemElementSelector; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.helper.DoubleHelper; +import flintstones.helper.MapHelper; +import flintstones.helper.MatrixHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.ahp.sort.phase.ranking.AHPSortRankingModel; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +/** + * The Class AHPSortRankingUI. + */ +public class AHPSortRankingUI extends PhaseMethodUI { + + boolean isCentralx = false; + + /** The model. */ + AHPSortRankingModel model; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The profile service. */ + @Inject + IProfileAssignmentService profileService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The criterion profiles table. */ + //HtmlTextTable criterionProfilesTable; + + /** The result table. */ + HtmlTextTable resultTable; + + /** The alternatives table. */ + HtmlTextTable alternativesTable; + + /** The profiles table. */ + HtmlTextTable profilesTable; + + /** The criterion weights table. */ + HtmlTextTable criterionWeightsTable; + + /** The current expert. */ + Expert currentExpert; + + /* (non-Javadoc) + * @see flintstones.phasemethod.ui.PhaseMethodUI#init() + */ + @Override + public void init() { + model = (AHPSortRankingModel) this.getModel(); + model.execute(); + createPartControls(this.getBaseComposite()); + + } + + /* (non-Javadoc) + * @see flintstones.phasemethod.ui.PhaseMethodUI#refresh() + */ + @Override + public void refresh() { + } + + /* (non-Javadoc) + * @see flintstones.phasemethod.ui.PhaseMethodUI#isForwardEnabled() + */ + @Override + public boolean isForwardEnabled() { + return true; + } + + /** + * Creates the part controls. + * + * @param parent the parent + */ + public void createPartControls(Composite parent) { + + isCentralx = profileService.getType().equals(SortingProfile.SortingProfileType.Central); + + UiService.setGridData(parent, 9, 9, true, true); + UiService.setGridLayout(parent, 1); + + createConfigurationRow(parent); + + Composite cols = new Composite(parent, 0); + UiService.setGridData(cols, 9, 9, true, true); + UiService.setGridLayout(cols, 2); + + Composite col0 = new Composite(cols,0); + UiService.setGridData(col0, 9, 9, true, true); + UiService.setGridLayout(col0, 1); + + createCriterionWeightsCol(col0); + //createCriterionProfilesCol(col0); + createAlternativesCol(col0); + createProfilesCol(col0); + + Composite col1 = new Composite(cols,0); + UiService.setGridData(col1, 9, 9, true, true); + UiService.setGridLayout(col1, 1); + + createResultRow(col1); + } + + /** + * Refresh tables. + */ + private void refreshTables() { + this.createWeightsTable(criterionWeightsTable.getParent()); + //this.createCriterionProfileTable(criterionProfilesTable.getParent()); + this.createAlternativesTable(alternativesTable.getParent()); + this.createProfilesTable(profilesTable.getParent()); + this.createResultTable(resultTable.getParent()); + } + + /** + * Creates the criterion profiles col. + * + * @param parent the parent + */ + /*private void createCriterionProfilesCol(Composite parent) { + + Composite base = new Composite(parent,0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Label title = new Label(base, 0); + title.setText("Sorting profiles"); + UiService.setGridData(title, -1, 0, true, false); + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite tableBase = new Composite(base,0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + createCriterionProfileTable(tableBase); + + }*/ + + /** + * Creates the criterion profile table. + * + * @param tableBase the table base + */ + /*private void createCriterionProfileTable(Composite tableBase) { + ProblemElement[] criteria = problemService.getAll(Criterion.Type); + criteria = ProblemElementHelper.getAsUserOrdered(criteria); + + ProfileAssignment[] assignments = new ProfileAssignment[criteria.length]; + for(int i = 0; i < criteria.length; i++) { + ProblemElement c = criteria[i]; + ProfileAssignment assignment = profileService.get(getCurrentExpert(), (Criterion) c); + assignments[i] = assignment; + } + + String[] vHeaders = Arrays.stream(criteria).map(k -> k.getName()).toArray(String[]::new); + String[] hHeaders = Arrays.stream(model.getClasses()).map(k -> k.getName()).toArray(String[]::new); + + if(!profileService.getType().equals(SortingProfile.SortingProfileType.Central)) + hHeaders = Arrays.copyOfRange(hHeaders, 0, hHeaders.length - 1); + + String[][] values = new String[vHeaders.length][hHeaders.length]; + + int numProfiles = problemService.getAll(SortingProfile.Type).length / criteria.length; + + for(int i = 0; i < assignments.length; i++) { + ProfileAssignment assignment = assignments[i]; + + String[] rowValues = new String[numProfiles]; + for(int prof = 0; prof < numProfiles; ++prof) + rowValues[prof] = assignment.getValues()[prof].toString(); + + values[i] = rowValues; + } + + criterionProfilesTable = new HtmlTextTable(tableBase, values, hHeaders, vHeaders); + criterionProfilesTable.render(); + }*/ + + + /** + * Creates the configuration row. + * + * @param parent the parent + */ + private void createConfigurationRow(Composite parent) { + + Composite row = new Composite(parent,0); + UiService.setGridData(row, 9, 0, true, false); + UiService.setGridLayout(row, 1); + + Label title = new Label(row, 0); + title.setText("Options"); + UiService.setGridData(title, -1, 0, true, false); + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + ProblemElement[] experts = problemService.getAll(Expert.Type); + ProblemElementSelector selector = new ProblemElementSelector(row,experts ); + selector.setListener(new IProblemElementChangedListener() { + public void problemElementChanged(ProblemElement pe) { + setCurrentExpert(pe); + refreshTables(); + } + }); + + + setCurrentExpert(selector.getSelectedElement()); + } + + + + /** + * Creates the criterion weights col. + * + * @param parent the parent + */ + private void createCriterionWeightsCol(Composite parent) { // X + + Composite base = new Composite(parent,0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Label title = new Label(base, 0); + title.setText("Criteria weight"); + UiService.setGridData(title, -1, 0, true, false); + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + + Composite tableBase = new Composite(base,0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + createWeightsTable(tableBase); + + } + + /** + * Creates the weights table. + * + * @param tableBase the table base + */ + private void createWeightsTable(Composite tableBase) { // X + + ProblemElement[] criteria = problemService.getAll(Criterion.Type); + Map map = model.getCriterionWeightsFor(getCurrentExpert()); + + LinkedHashMap criterionWeights = MapHelper.sortByExample(map, criteria); + + String[] vHeaders = criterionWeights.keySet().stream().map(k -> k.getName()).toArray(String[]::new); + String[] hHeaders = new String[] {"Weight"}; + String[][] values = new String[criteria.length][1]; + + int cont = 0; + for(ProblemElement crit: criterionWeights.keySet()) { + values[cont][0] = DoubleHelper.Draw(criterionWeights.get(crit)); + cont++; + } + + criterionWeightsTable = new HtmlTextTable(tableBase, values, hHeaders, vHeaders); + criterionWeightsTable.render(); + } + + /** + * Creates the alternatives col. + * + * @param parent the parent + */ + private void createAlternativesCol(Composite parent) { + + Composite base = new Composite(parent,0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Label title = new Label(base, 0); + title.setText("Alternatives global priorities"); + UiService.setGridData(title, -1, 0, true, false); + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + // Build Table + Composite tableBase = new Composite(base,0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + createAlternativesTable(tableBase); + + } + + /** + * Creates the alternatives table. + * + * @param tableBase the table base + */ + private void createAlternativesTable(Composite tableBase) { + // DATA + HashMatrix alternativePriorities = model.getAlternativeGlobalPrioritiesFor(getCurrentExpert()); + + // FORMAT into TABLE + String[] vHeaders = alternativePriorities.keySet().stream().map(k -> k.getName()).toArray(String[]::new); + String[] hHeaders = alternativePriorities.values().iterator().next().keySet().stream().map(k ->"Priority").toArray(String[]::new); + + String[][] valuesD = new String[vHeaders.length][hHeaders.length]; + + int i = 0; + for(ProblemElement a : alternativePriorities.keySet()) { + + for(int j = 0; j < hHeaders.length; j++) { + int jj = j; + valuesD[i][j] = DoubleHelper.Draw(alternativePriorities.get(a,jj)); + } + i++; + } + + alternativesTable = new HtmlTextTable(tableBase, valuesD, hHeaders, vHeaders); + alternativesTable.render(); + } + + /** + * Creates the profiles col. + * + * @param parent the parent + */ + private void createProfilesCol(Composite parent) { + + Composite base = new Composite(parent,0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Label title = new Label(base, 0); + title.setText("Profiles global priorities"); + UiService.setGridData(title, -1, 0, true, false); + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite tableBase = new Composite(base,0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + createProfilesTable(tableBase); + + } + + /** + * Creates the profiles table. + * + * @param tableBase the table base + */ + private void createProfilesTable(Composite tableBase) { + HashMatrix profilePriorities = model.getProfileGlobalPrioritiesFor(getCurrentExpert()); + + ProblemElement[] criteria = problemService.getAll(Criterion.Type); + int numProfiles = problemService.getAll(SortingProfile.Type).length / criteria.length; + + Integer[] profiles = profilePriorities.keySet().stream().toArray(Integer[]::new); + Alternative[] alternatives = profilePriorities.values().iterator().next().keySet().stream().toArray(Alternative[]::new); + + String[] hHeaders = Arrays.stream(model.getClasses()).map(k -> k.getName()).toArray(String[]::new); + + if(!profileService.getType().equals(SortingProfile.SortingProfileType.Central)) + hHeaders = Arrays.copyOfRange(hHeaders, 0, hHeaders.length - 1); + + String[] vHeaders = Arrays.stream(alternatives).map(k -> k.getName()).toArray(String[]::new); + + String[][] valuesD = new String[numProfiles][alternatives.length]; + + for(int i = 0; i < numProfiles; i++) { + for(int j = 0; j < alternatives.length; j++) { + valuesD[i][j] = DoubleHelper.Draw(profilePriorities.get(profiles[i], alternatives[j])); + } + } + + valuesD = MatrixHelper.transpose(valuesD); + + profilesTable = new HtmlTextTable(tableBase, valuesD, hHeaders, vHeaders); + profilesTable.render(); + } + + /** + * Creates the result row. + * + * @param base the base + */ + private void createResultRow(Composite base) { + Label title = new Label(base, 0); + title.setText("Classified classes"); + UiService.setGridData(title, -1, 0, true, false); + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite tableBase = new Composite(base,0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + createResultTable(tableBase); + + } + + /** + * Creates the result table. + * + * @param tableBase the table base + */ + private void createResultTable(Composite tableBase) { + + HashMap map = model.getClassificationFor(getCurrentExpert()); + ProblemElement[] alternatives = ProblemElementHelper.getAsUserOrdered(problemService.getAll(Alternative.Type)); + LinkedHashMap sortedMap = MapHelper.sortByExample(map, alternatives); + + String[] vHeaders = sortedMap.keySet().stream().map(k -> k.getName()).toArray(String[]::new); + String[] hHeaders = new String[] {"Class"}; + String[][] values = new String[alternatives.length][1]; + + int cont = 0; + for(ProblemElement alt: sortedMap.keySet()) { + values[cont][0] = sortedMap.get(alt).getName(); + cont++; + } + + resultTable = new HtmlTextTable(tableBase, values, hHeaders, vHeaders); + resultTable.render(); + } + + + /** + * Gets the current expert. + * + * @return the current expert + */ + public Expert getCurrentExpert() { + return currentExpert; + } + + /** + * Sets the current expert. + * + * @param name the new current expert + */ + public void setCurrentExpert(ProblemElement pe) { + currentExpert = (Expert) pe; + } + +} diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/.classpath b/bundles/flintstones.method.ahp.sort.phase.ranking/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/.polyglot.META-INF b/bundles/flintstones.method.ahp.sort.phase.ranking/.polyglot.META-INF new file mode 100644 index 0000000..d1c9778 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sort.phase.ranking + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ranking + diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/.project b/bundles/flintstones.method.ahp.sort.phase.ranking/.project new file mode 100644 index 0000000..901d3b7 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sort.phase.ranking + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362629 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sort.phase.ranking/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3a86953 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/META-INF/MANIFEST.MF @@ -0,0 +1,28 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ranking +Bundle-SymbolicName: flintstones.method.ahp.sort.phase.ranking;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sort.phase.ranking +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.model.ahppreferences.service, + javax.inject, + flintstones.model.problemelement.service, + flintstones.entity.problemelement, + flintstones.entity.preferences.preferencecollection, + flintstones.entity.ahp, + org.apache.commons.math3, + flintstones.helper.data, + flintstones.entity.ahppreferences, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment, + flintstones.model.domain.service, + flintstones.entity.domain, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.entity.method.phase, + flintstones.entity.ahpsort.priority, + flintstones.helper.debug, + org.apache.commons.lang +Export-Package: flintstones.method.ahp.sort.phase.ranking, + flintstones.method.ahp.sort.phase.ranking.ahpcluster diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/build.properties b/bundles/flintstones.method.ahp.sort.phase.ranking/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/plugin.xml b/bundles/flintstones.method.ahp.sort.phase.ranking/plugin.xml new file mode 100644 index 0000000..2196a39 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/AHPSortRankingModel.java b/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/AHPSortRankingModel.java new file mode 100644 index 0000000..9d14418 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/AHPSortRankingModel.java @@ -0,0 +1,198 @@ +package flintstones.method.ahp.sort.phase.ranking; + +import java.util.Arrays; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.data.HashMatrix; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class AHPSortRankingModel. + */ +public class AHPSortRankingModel extends PhaseMethod { + + /** The pref service. */ + @Inject + IProblemPreferencesService prefService; + + /** The problem service. */ + @Inject + IProblemElementService problemService; + + /** The profile service. */ + @Inject + IProfileAssignmentService profileService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The db. */ + HashMap db = new HashMap<>(); + + /** The experts. */ + ProblemElement[] experts; + + /** The criteria. */ + ProblemElement[] criteria; + + /* + * (non-Javadoc) + * + * @see flintstones.phasemethod.PhaseMethod#getName() + */ + @Override + public String getName() { + return "AHPSort Ranking"; + } + + /** + * Execute. + */ + public void execute() { + exec(); + export(); + } + + /** + * Export. + */ + private void export() { + exportData("expertModels", db); + } + + /** + * Exec. + */ + private void exec() { + // Vars + experts = problemService.getAll(Expert.Type); + criteria = problemService.getAll(Criterion.Type); + + for (ProblemElement e : experts) + execFor((Expert) e); + + } + + /** + * Exec the model for an expert. + * + * @param expert the e + */ + private void execFor(Expert expert) { + + ExpertAHPSortModel emodel = new ExpertAHPSortModel(expert, profileService.getType().equals(SortingProfile.SortingProfileType.Central)); + + // Prepare + db.put(expert, emodel); + ContextInjectionFactory.inject(emodel, context); + + // Weights + PreferenceCollection criterionCol = prefService.get(null, Expert.Type, Criterion.Type, Criterion.Type); + emodel.cacheCriterionWeightsFor(criterionCol); + + // Priorities + PreferenceCollection altProfCol = prefService.get(Expert.Type, Criterion.Type, Alternative.Type, + SortingProfile.Type); + PreferenceCollection profProfCol = prefService.get(Expert.Type, Criterion.Type, SortingProfile.Type, + SortingProfile.Type); + + for (ProblemElement c : criteria) { + AHPMatrix[] matrixesAltProf = altProfCol.getAHPMatrixesFor(expert, c); + AHPMatrix[] matrixesProfProf = profProfCol.getAHPMatrixesFor(expert, c); + AHPMatrix[] combinedMatrices = combineMatrices(matrixesAltProf, matrixesProfProf); + emodel.cacheLocalPriorities((Criterion) c, combinedMatrices); + } + + emodel.cacheGlobalPriorities(); + + emodel.classify(getClasses()); + + } + + private AHPMatrix[] combineMatrices(AHPMatrix[] matrixesAltProf, AHPMatrix[] matrixesProfProf) { + + for (int i = 0; i < matrixesAltProf.length; i++) { + ProblemElement[] fil = matrixesProfProf[0].getRows(); + ProblemElement[] col = matrixesProfProf[0].getCols(); + for (ProblemElement problemElement : fil) { + for (ProblemElement problemElement2 : col) { + matrixesAltProf[i].set(problemElement, problemElement2, + matrixesProfProf[0].getIndex(problemElement, problemElement2)); + } + } + } + return matrixesAltProf; + } + + /** + * Gets the criterion weights for. + * + * @param currentExpert the current expert + * @return the criterion weights for + */ + public HashMap getCriterionWeightsFor(Expert currentExpert) { + return db.get(currentExpert).getCriterionWeights(); + } + + /** + * Gets the alternative global priorities for. + * + * @param currentExpert the current expert + * @return the alternative global priorities for + */ + public HashMatrix getAlternativeGlobalPrioritiesFor(Expert currentExpert) { + return db.get(currentExpert).getAlternativeGlobalPriorities(); + } + + /** + * Gets the profile global priorities for. + * + * @param currentExpert the current expert + * @return the profile global priorities for + */ + public HashMatrix getProfileGlobalPrioritiesFor(Expert currentExpert) { + return db.get(currentExpert).getProfileGlobalPriorities(); + } + + /** + * Gets the classification for. + * + * @param currentExpert the current expert + * @return the classification for + */ + public HashMap getClassificationFor(Expert currentExpert) { + return db.get(currentExpert).getClassification(); + } + + public SortingClass[] getClasses() { + + SortingClass[] classes = Arrays // + .stream(problemService.getAll(SortingClass.Type)) // + .map(k -> (SortingClass) k).toArray(SortingClass[]::new); + + return classes; + } + +} diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ExpertAHPSortModel.java b/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ExpertAHPSortModel.java new file mode 100644 index 0000000..fa9eb7a --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ExpertAHPSortModel.java @@ -0,0 +1,353 @@ +/* + * + */ +package flintstones.method.ahp.sort.phase.ranking; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.ahpsort.priority.AHPSortPriority; +import flintstones.entity.ahpsort.priority.AHPSortPriorityManager; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.DoubleHelper; +import flintstones.helper.EigenHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.debug.DH; + +/** + * The Class ExpertAHPSortModel. + */ +public class ExpertAHPSortModel { + + // TODO REVISAR 06/06 + boolean isOptimisticx = false; + + /** The expert. */ + Expert expert; + + /** The criterions. */ + Criterion[] criterions; + + /** The profiles. */ + SortingProfile[] profiles; + + /** The alternatives. */ + Alternative[] alternatives; + + /** The criterion weights. */ + HashMap criterionWeights = new HashMap<>(); + + /** The local priorities. */ + HashMap localPriorities = new HashMap<>(); + + /** The alternative global priorities. */ + HashMatrix alternativeG = new HashMatrix<>(); + + /** The profiles global priorities. */ + HashMatrix profileG = new HashMatrix<>(); + + /** The classification. */ + HashMap classification = new HashMap<>(); + + boolean isCentralx = true; + + /** + * Instantiates a new expert AHP sort model. + * + * @param expert the expert + */ + public ExpertAHPSortModel(Expert expert, boolean useCentralProfiles) { + this.expert = expert; + isCentralx = useCentralProfiles; + } + + /** + * Cache criterion weights for the given Preference collection. + * + * @param col the col + */ + public void cacheCriterionWeightsFor(PreferenceCollection col) { + AHPMatrix matrix = col.getAHPMatrix(null, expert); + + double[] values = EigenHelper.GetNormalizedEigenVector(matrix.getValues()); + + for (int i = 0; i < matrix.getCols().length; i++) { + ProblemElement criterion = matrix.getCols()[i]; + Double value = values[i]; + criterionWeights.put(criterion, value); + } + criterions = criterionWeights.keySet().stream().toArray(Criterion[]::new); + + } + + /** + * Cache local priorities. + * + * @param c the c + * @param matrixes the matrixes + */ + public void cacheLocalPriorities(Criterion c, AHPMatrix[] matrixes) { + + AHPSortPriorityManager manager = new AHPSortPriorityManager(); + + for (AHPMatrix matrix : matrixes) { + + double[] values = EigenHelper.GetNormalizedEigenVector(matrix.getValues()); + + ProblemElement[] col = matrix.getCols(); + Alternative a = (Alternative) col[0]; + SortingProfile[] profile = new SortingProfile[col.length - 1]; + + for (int i = 1; i < col.length; i++) { + profile[i - 1] = (SortingProfile) col[i]; + } + + double[] valoresPerfiles = new double[values.length - 1]; + + for (int i = 1; i < values.length; i++) { + valoresPerfiles[i - 1] = values[i]; + } + + AHPSortPriority prior = new AHPSortPriority(profile, a, values[0], valoresPerfiles); + manager.add(prior); + + } + + localPriorities.put(c, manager); + + } + + /** + * Cache global priorities. + */ + public void cacheGlobalPriorities() { + + profiles = localPriorities.values().iterator().next().getProfiles(); + ProblemElement[] pes = localPriorities.values().iterator().next().getLeftElements(); + alternatives = Arrays.stream(pes).map(k -> (Alternative) k).toArray(Alternative[]::new); + + cacheAlternativesGlobalPriorities(); + cacheProfileGlobalPriorities(); + + } + + /** + * Cache profile global priorities. + */ + private void cacheProfileGlobalPriorities() { + + for (Alternative alternative : alternatives) { + for (Integer index = 0; index < profiles.length; index++) { + double wGlobalProf = 0.0; + for (Criterion c : criterions) { + + AHPSortPriorityManager manager = localPriorities.get(c); + + double criterionWeight = criterionWeights.get(c); + + double localPro = manager.get(alternative, 0).getProfilePriority()[index]; + double wLocalPro = localPro * criterionWeight; + + wGlobalProf += wLocalPro; + profileG.put(index, alternative, wGlobalProf); + } + + } + + } + } + + /** + * Cache alternatives global priorities. + */ + private void cacheAlternativesGlobalPriorities() { + + for (Alternative alternative : alternatives) { + double wGlobalAlt = 0.0; + + for (Criterion c : criterions) { + + AHPSortPriorityManager manager = localPriorities.get(c); + + double criterionWeight = criterionWeights.get(c); + + double localAlt = manager.get(alternative, 0).getAlternativePriority(); + double wLocalAlt = localAlt * criterionWeight; + + wGlobalAlt += wLocalAlt; + + } + + alternativeG.put(alternative, 0, wGlobalAlt); + + } + DH.out("Alternatives GLOBAL " + expert.getName()); + DH.out(alternativeG.toString()); + DH.l(); + } + + /** + * Gets the criterion weights. + * + * @return the criterion weights + */ + // G/S + public HashMap getCriterionWeights() { + return this.criterionWeights; + } + + /** + * Classify. + * + * @param domain the domain + */ + public void classify(SortingClass[] classes) { + + if (!isCentralx) { + for (Alternative alternative : alternatives) { + + int index = classifyByLimitingAlternativeV2(alternative); + + SortingClass classs = classes[index]; + classification.put(alternative, classs); + + } + } else { + for (Alternative alternative : alternatives) { + + int index = classifyByCentralAlternativeV2(alternative); + SortingClass classs = classes[index]; + classification.put(alternative, classs); + + } + } + DH.l(2); + + } + + private ArrayList getAlternativePrioritiesFor(Alternative a) { + Map altMap = alternativeG.get(a); + + ArrayList alternativeHits = new ArrayList<>(); + alternativeHits.addAll(altMap.values()); + return alternativeHits; + } + + private ArrayList getProfileLimitsFor(Alternative a) { + ArrayList profileLimits = (ArrayList) profileG.entrySet().stream().map(k -> k.getValue().get(a)) + .collect(Collectors.toList()); + return profileLimits; + } + + private ArrayList getProfileCentersFor(Alternative a) { + + ArrayList limits = getProfileLimitsFor(a); + limits.add(0, 0.0); + Double[] arr = limits.toArray(new Double[0]); + Double[] centrals = DoubleHelper.GetCentralPoints(arr); + + return new ArrayList(Arrays.asList(centrals)); + } + + private int classifyByCentralAlternativeV2(Alternative alternative) { + + ArrayList alternativeHits = getAlternativePrioritiesFor(alternative); + ArrayList profileCenters = getProfileCentersFor(alternative); + + System.out.println(alternativeHits); + System.out.println(profileCenters); + + double minDistance = Double.MAX_VALUE; + int minDistanceIndex = -1; + + for (int i = 0; i < alternativeHits.size(); i++) { + + double hit = alternativeHits.get(i); + for (int j = 0; j < profileCenters.size(); j++) { + + double limit = profileCenters.get(j); + double diff = Math.abs(limit - hit); + + if (diff < minDistance) { // WIN!!! + minDistance = diff; + minDistanceIndex = j; + } else if (diff == minDistance) { // TIE!! + + if (!isOptimisticx) { // GET THE NEW ONE, ELSE KEEP THE OLD ONE + minDistanceIndex = j; + } + + } + + } + + } + + return minDistanceIndex; + + } + + private int classifyByLimitingAlternativeV2(Alternative alternative) { + + ArrayList alternativeHits = getAlternativePrioritiesFor(alternative); + ArrayList profileLimits = getProfileLimitsFor(alternative); + System.out.println(profileLimits); + double hit = alternativeHits.get(0); + + for (int i = 0; i < profileLimits.size(); i++) { + double limit = profileLimits.get(i); + + if (hit > limit) + return i; + + } + + // No clasification, last one, bad. + return profileLimits.size(); + } + + /** + * Classify by limiting alternative. + * + * @param alternative the alternative + * @return the index + */ + + /** + * Gets the alternative global priorities. + * + * @return the alternative global priorities + */ + public HashMatrix getAlternativeGlobalPriorities() { + return alternativeG; + } + + /** + * Gets the profile global priorities. + * + * @return the profile global priorities + */ + public HashMatrix getProfileGlobalPriorities() { + return profileG; + } + + /** + * Gets the classification. + * + * @return the classification + */ + public HashMap getClassification() { + return classification; + } + +} diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ahpcluster/AHPCluster.java b/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ahpcluster/AHPCluster.java new file mode 100644 index 0000000..f899679 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ahpcluster/AHPCluster.java @@ -0,0 +1,88 @@ +package flintstones.method.ahp.sort.phase.ranking.ahpcluster; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; + +import flintstones.entity.problemelement.entities.ProblemElement; + +public class AHPCluster implements Iterable{ + + LinkedList elements = new LinkedList(); + LinkedList localPriorities = new LinkedList<>(); + LinkedList joinedPriorities = new LinkedList<>(); + + public AHPCluster(ProblemElement[] pes) { + elements = new LinkedList<>(Arrays.asList(pes)); + } + + public void add(ProblemElement pe) { + elements.add(pe); + } + + @Override + public Iterator iterator() { + return elements.iterator(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("<"); + sb.append(elements.toString()); + sb.append(">"); + return sb.toString(); + } + + public ProblemElement[] getElements() { + return elements.toArray(new ProblemElement[0]); + } + + public void setLocalPriorities(double[] arr) { + + if(localPriorities.size() > 0) + throw new RuntimeException("No"); + + for(double item : arr) + localPriorities.add(item); + } + + public Double[] getLocalPriorities() { + return localPriorities.toArray(new Double[0]); + } + + public ProblemElement getFirstElement() { + return elements.get(0); + } + + public Double getFirstPriority() { + return localPriorities.get(0); + } + + public ProblemElement getLastElement() { + return elements.get(elements.size()-1); + } + + public Double getLastPriority() { + return localPriorities.get(localPriorities.size()-1); + } + + public void setJoinedPriorities(double[] arr) { + + if(joinedPriorities.size() > 0) + throw new RuntimeException("No"); + + for(double item : arr) + joinedPriorities.add(item); + } + + public Double[] getJoinedPriorities() { + if(joinedPriorities.size() == 0) + return localPriorities.toArray(new Double[0]); + return joinedPriorities.toArray(new Double[0]); + } + + public int size() { + return elements.size(); + } +} diff --git a/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ahpcluster/AHPClusterer.java b/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ahpcluster/AHPClusterer.java new file mode 100644 index 0000000..3fb7ce2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort.phase.ranking/src/flintstones/method/ahp/sort/phase/ranking/ahpcluster/AHPClusterer.java @@ -0,0 +1,196 @@ +package flintstones.method.ahp.sort.phase.ranking.ahpcluster; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import org.apache.commons.lang.ArrayUtils; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; + +public class AHPClusterer implements Iterable { + + LinkedList originalElements = new LinkedList<>(); + LinkedList clusters = new LinkedList<>(); + LinkedHashMap normalizedValues = new LinkedHashMap<>(); + + private int clusterSize = -1; + private int totalSize = -1; + + public AHPClusterer(ProblemElement[] pes) { + + originalElements = new LinkedList<>(Arrays.asList(pes)); + + int size = pes.length; + totalSize = size; + if (size <= 7) { + clusters.add(new AHPCluster(pes)); + return; + } + + int finalPos = -1; + + int[] modules = getModules(size, 7); + int[] divisions = getDivisions(size, 7); + double[] modulesD = Arrays.stream(modules).asDoubleStream().toArray(); + int[] minModules = DoubleHelper.FindMinIndexes(modulesD); + + if (minModules.length > 1) { + + int minDiv = Integer.MAX_VALUE; + int minDivPos = -1; + for (int i = 0; i < minModules.length; i++) { + int pos = minModules[i]; + int div = divisions[pos]; + + if (div < minDiv) { + minDiv = div; + minDivPos = pos; + } + } + finalPos = minDivPos; + + } else { + finalPos = minModules[0]; + } + + clusterSize = size / divisions[finalPos]; + addClusters(clusterSize, pes); + } + + private void addClusters(int size, ProblemElement[] pes) { + + ArrayList elements = new ArrayList<>(); + ProblemElement lastElement = null; + for (ProblemElement item : pes) { + + if (lastElement != null && elements.size() == 0) + elements.add(lastElement); + + elements.add(item); + + if (elements.size() == size) { + clusters.add(new AHPCluster(elements.toArray(new ProblemElement[0]))); + elements.clear(); + } + + lastElement = item; + } + + // Add new cluster with remaining elements + if (elements.size() != 0) + clusters.add(new AHPCluster(elements.toArray(new ProblemElement[0]))); + + // Add the remaining elements to the last cluster. If any +// for(ProblemElement pe : elements) +// clusters.get(clusters.size()-1).add(pe); + + } + + private int[] getModules(int size, int maxSize) { + + int[] values = new int[maxSize - 1]; + for (int i = 2; i < maxSize + 1; i++) + values[i - 2] = size % i; + + return values; + + } + + private int[] getDivisions(int size, int maxSize) { + + int[] values = new int[maxSize - 1]; + for (int i = 2; i < maxSize + 1; i++) { + values[i - 2] = size / i; + } + return values; + + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Clusters: \n clusterSize=" + clusterSize + " totalSize=" + totalSize); + for (AHPCluster c : clusters) { + sb.append("\n"); + sb.append(c.toString()); + } + return sb.toString(); + } + + @Override + public Iterator iterator() { + return clusters.iterator(); + } + + public LinkedHashMap getNormalizedPriorities() { + + if(normalizedValues.size() != 0) + return normalizedValues; + + if(clusters.size() == 1) { + ProblemElement[] pes = clusters.get(0).getElements(); + Double[] vals = clusters.get(0).getLocalPriorities(); + + LinkedHashMap map = new LinkedHashMap<>(); + for(int i = 0; i < pes.length; i++ ) { + map.put(pes[i], vals[i]); + } + return map; + } + + for(int i = 0; i < clusters.size()-1; i+=1) { + AHPCluster a = clusters.get(i); + AHPCluster b = clusters.get(i+1); + join(a,b); + } + + + double[] weights = new double[originalElements.size()]; + int w = 0; + + AHPCluster firstCluster = clusters.get(0); + Double[] firstPrior = firstCluster.getJoinedPriorities(); + for(int j = 0; j < firstPrior.length; j++) { + weights[w] = firstPrior[j]; + w++; + } + + for(int i = 1; i < clusters.size(); i++) { + Double[] prior = clusters.get(i).getJoinedPriorities(); + for(int j = 1; j < prior.length; j++) { + weights[w] = prior[j]; + w++; + } + } + + Double[] nweights = ArrayUtils.toObject(DoubleHelper.Normalize(weights)); + + for(int i = 0; i < nweights.length; i++) + normalizedValues.put(originalElements.get(i), nweights[i]); + + return normalizedValues; + + } + + public void join(AHPCluster top, AHPCluster bottom) { + + double pA = top.getJoinedPriorities()[top.getJoinedPriorities().length - 1]; + double pB = bottom.getFirstPriority(); + + double ratio = pA/pB; + + double[] oldPriorities = ArrayUtils.toPrimitive(bottom.getLocalPriorities()); + double[] newPriorities = new double[oldPriorities.length]; + for(int i = 0; i < oldPriorities.length; i++) + newPriorities[i] = oldPriorities[i]*ratio; + + bottom.setJoinedPriorities(newPriorities); + } + + public int size() { + return clusterSize; + } + +} diff --git a/bundles/flintstones.method.ahp.sort/.classpath b/bundles/flintstones.method.ahp.sort/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort/.polyglot.META-INF b/bundles/flintstones.method.ahp.sort/.polyglot.META-INF new file mode 100644 index 0000000..a5a2718 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sort + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] AHPSort + diff --git a/bundles/flintstones.method.ahp.sort/.project b/bundles/flintstones.method.ahp.sort/.project new file mode 100644 index 0000000..2c391fe --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sort + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362620 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sort/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sort/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8459a63 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.ahp.sort;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sort +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric, + flintstones.model.ahpsort.profileassignment.service diff --git a/bundles/flintstones.method.ahp.sort/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.ahp.sort/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..a9fb61f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.ahp.sort +Bundle-Name = AHPSort \ No newline at end of file diff --git a/bundles/flintstones.method.ahp.sort/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.ahp.sort/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..a9fb61f --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.ahp.sort +Bundle-Name = AHPSort \ No newline at end of file diff --git a/bundles/flintstones.method.ahp.sort/build.properties b/bundles/flintstones.method.ahp.sort/build.properties new file mode 100644 index 0000000..3e5f9ad --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/ diff --git a/bundles/flintstones.method.ahp.sort/plugin.xml b/bundles/flintstones.method.ahp.sort/plugin.xml new file mode 100644 index 0000000..2d287e7 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/plugin.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/AHPSortMethod.java b/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/AHPSortMethod.java new file mode 100644 index 0000000..7ed44d3 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/AHPSortMethod.java @@ -0,0 +1,82 @@ + +package flintstones.method.ahp.sort; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.ahp.sort.messages.Messages; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.valuation.numeric.NumericValuation; + +public class AHPSortMethod extends ValidatedMethod { + + @Inject + IProblemElementService problemService; + + @Inject + IProfileAssignmentService profileService; + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.method_name; //$NON-NLS-1$ + } + + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + String numProfileEntity = problemMessages.Profile_count; + String numSortingClassEntity = problemMessages.SortingClass_count; + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, NumericValuation.class.getSimpleName(), valuations); + + int numProfiles = getProfilesByExpert(); + int numSortingClasses = problemService.getAll(SortingClass.Type).length; + + if(profileService.getType().equals(SortingProfile.SortingProfileType.Central)) { + validator.setReturn(this.getName()) + .greaterThan(numSortingClassEntity, numSortingClasses, 0).named("numSortingClasses") //$NON-NLS-1$ + .greaterThan(numProfileEntity, numProfiles, 0).named("numProfiles")//$NON-NLS-1$ + .equals(numProfileEntity, numProfiles, numSortingClasses).named("numProfiles")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } else { + validator.setReturn(this.getName()) + .greaterThan(numSortingClassEntity, numSortingClasses, 0).named("numSortingClasses") //$NON-NLS-1$ + .greaterThan(numProfileEntity, numProfiles, 0).named("numProfiles")//$NON-NLS-1$ + .equals(numProfileEntity, numProfiles, numSortingClasses - 1).named("numProfiles")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + } + + private int getProfilesByExpert() { + int totalNumProfiles = problemService.getAll(SortingProfile.Type).length; + int numExperts = problemService.getAll(Expert.Type).length; + int numCriteria = problemService.getAll(Criterion.Type).length; + + if(numExperts > 0 && numCriteria > 0) { + int numProfiles = totalNumProfiles / numExperts; + return numProfiles /= numCriteria; + } else + return totalNumProfiles; + } +} diff --git a/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/Messages.java b/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/Messages.java new file mode 100644 index 0000000..518f4bd --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/Messages.java @@ -0,0 +1,6 @@ +package flintstones.method.ahp.sort.messages; + +public class Messages { + public String method_name; +} + diff --git a/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/messages.properties b/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/messages.properties new file mode 100644 index 0000000..bbc7eb2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/messages.properties @@ -0,0 +1 @@ +method_name=Analytic Hierarchy Process Sort (AHPSort) diff --git a/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/messages_es.properties b/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/messages_es.properties new file mode 100644 index 0000000..1c14917 --- /dev/null +++ b/bundles/flintstones.method.ahp.sort/src/flintstones/method/ahp/sort/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Proceso Analtico Jerrquico de Ordenacin (AHPSort) diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.classpath b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.polyglot.META-INF b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.polyglot.META-INF new file mode 100644 index 0000000..16bda97 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sortii.phase.ranking.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.project b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.project new file mode 100644 index 0000000..fc0ddfa --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sortii.phase.ranking.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362634 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ebb6371 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.ahp.sortii.phase.ranking.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sortii.phase.ranking.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.method.ahp.sortii.phase.ranking, + flintstones.entity.method.phase, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.helper.data, + flintstones.helper.html, + flintstones.entity.problemelement, + flintstones.entity.problemelement.ui, + flintstones.model.problemelement.service, + javax.inject, + org.eclipse.jface, + org.jfree.chart.jfreechart diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/build.properties b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/plugin.xml b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/plugin.xml new file mode 100644 index 0000000..8b1a22f --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/plugin.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRanking2AgglomerativeUI.java b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRanking2AgglomerativeUI.java new file mode 100644 index 0000000..a830f26 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRanking2AgglomerativeUI.java @@ -0,0 +1,174 @@ +package flintstones.method.ahp.sortii.phase.ranking.ui; + +import java.util.ArrayList; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.ui.widget.ProblemElementSelector; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.helper.data.adapter.TableAdapter; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.ahp.sortii.phase.ranking.AHPSortIIRanking2ModelAgglomerative; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class AHPSortIIRanking2AgglomerativeUI extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + AHPSortIIRanking2ModelAgglomerative model; + + Expert selectedExpert; + + HtmlTextTable criterionWeightsTable; + HtmlTextTable clustersTable; + HtmlTextTable alternativeLocalTable; + HtmlTextTable profileGlobalTable; + HtmlTextTable alternativeGlobalTable; + HtmlTextTable globalClassificationTable; + + HashMap visibleComposite = new HashMap<>(); + + @Override + public void init() { + model = (AHPSortIIRanking2ModelAgglomerative) this.getModel(); + model.execute(); + createPartControls(this.getBaseComposite()); + } + + @Override + public void refresh() { + // TODO Auto-generated method stub + + } + + @Override + protected boolean isForwardEnabled() { + return true; + } + + private void createPartControls(Composite base) { + + selectedExpert = (Expert) problemService.getAll(Expert.Type)[0]; + + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + Composite c3 = createBlock(base, "Alternative local priorities"); + createAlternativeLocalPrioritiesTable(c3); + + Composite comboComposite = new Composite(base, SWT.NONE); + UiService.setGridData(comboComposite, 9, 9, false, false); + UiService.setGridLayout(comboComposite, 1); + ProblemElementSelector selectorExpert = new ProblemElementSelector(comboComposite, problemService.getAll(Expert.Type)); + selectorExpert.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + selectedExpert = (Expert) pe; + updateTables(); + } + }); + + Composite divide45 = new Composite(base, 0); + UiService.setGridData(divide45, 9, 9, true, true); + UiService.setGridLayout(divide45, 3); + + Composite c4 = createBlock(divide45, "Profile global priorities"); + createProfileGlobalPrioritiesTable(c4); + + Composite c5 = createBlock(divide45, "Individual classification"); + createAlternativeGlobalPrioritiesTable(c5); + + Composite c6 = createBlock(divide45, "Group classification"); + createGlobalClassificationTable(c6); + + } + + private Composite createBlock(Composite parent, String name) { + + Composite base = new Composite(parent, 0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + CLabel title = new CLabel(base, 0); + title.setText(name); + + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite tableBase = new Composite(base, 0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + return tableBase; + + } + + private void createAlternativeGlobalPrioritiesTable(Composite tableBase) { + + TableAdapter adapter = model.getAlternativeGlobalTable(selectedExpert); + alternativeGlobalTable = new HtmlTextTable(tableBase, adapter.getData(), adapter.getHorizontalHeaders(), adapter.getVerticalHeaders()); + + alternativeGlobalTable.render(); + } + + private void createProfileGlobalPrioritiesTable(Composite tableBase) { + + TableAdapter adapter = model.getProfilesGlobalTable(selectedExpert); + profileGlobalTable = new HtmlTextTable(tableBase, adapter.getDataRow(), adapter.getHorizontalHeaders(), true); + profileGlobalTable.render(); + + } + + private void createAlternativeLocalPrioritiesTable(Composite tableBase) { // X + + TableAdapter adapter = model.getAlternativeLocalTable(selectedExpert); + + alternativeLocalTable = new HtmlTextTable(tableBase, adapter.getData(), adapter.getHorizontalHeaders(), + adapter.getVerticalHeaders()); + alternativeLocalTable.render(); + } + + private void createGlobalClassificationTable(Composite tableBase) { + TableAdapter adapter = model.getGlobalClassificationTable(); + + globalClassificationTable = new HtmlTextTable(tableBase, adapter.getDataRow(), adapter.getHorizontalHeaders(), true); + + ArrayList classes = model.getClasses(); + + Color[] colors = UiService.getColorScale(classes.size(), false); + for(int i = 0; i < classes.size(); i++) { + SortingClass cl = classes.get(i); + globalClassificationTable.setCss(".value_"+cl.getName(), "background-color", UiService.toHEX(colors[i]) ); + } + + globalClassificationTable.render(); + + } + + private void updateTables() { + + TableAdapter adapter1 = model.getAlternativeGlobalTable(selectedExpert); + TableAdapter adapter2 = model.getProfilesGlobalTable(selectedExpert); + TableAdapter adapter3 = model.getAlternativeLocalTable(selectedExpert); + + alternativeLocalTable.refresh(adapter3.getData()); + profileGlobalTable.refresh(adapter2.getDataRow()); + alternativeGlobalTable.refresh(adapter1.getData()); + + alternativeLocalTable.render(); + profileGlobalTable.render(); + alternativeGlobalTable.render(); + } + +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRanking2UI.java b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRanking2UI.java new file mode 100644 index 0000000..9d7c37c --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRanking2UI.java @@ -0,0 +1,177 @@ +package flintstones.method.ahp.sortii.phase.ranking.ui; + +import java.util.ArrayList; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.ui.widget.ProblemElementSelector; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.data.adapter.TableAdapter; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.ahp.sortii.phase.ranking.AHPSortIIRanking2Model; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class AHPSortIIRanking2UI extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + AHPSortIIRanking2Model model; + + Expert selectedExpert; + + HtmlTextTable criterionWeightsTable; + HtmlTextTable clustersTable; + HtmlTextTable alternativeLocalTable; + HtmlTextTable profileGlobalTable; + HtmlTextTable alternativeGlobalTable; + HtmlTextTable globalClassificationTable; + + HashMap visibleComposite = new HashMap<>(); + + @Override + public void init() { + model = (AHPSortIIRanking2Model) this.getModel(); + model.execute(); + createPartControls(this.getBaseComposite()); + } + + @Override + public void refresh() { + // TODO Auto-generated method stub + + } + + @Override + protected boolean isForwardEnabled() { + return true; + } + + private void createPartControls(Composite base) { + + selectedExpert = (Expert) problemService.getAll(Expert.Type)[0]; + + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + Composite c3 = createBlock(base, "Alternative local priorities"); + createAlternativeLocalPrioritiesTable(c3); + + Composite comboComposite = new Composite(base, SWT.NONE); + UiService.setGridData(comboComposite, 9, 9, false, false); + UiService.setGridLayout(comboComposite, 1); + ProblemElementSelector selectorExpert = new ProblemElementSelector(comboComposite, problemService.getAll(Expert.Type)); + selectorExpert.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + selectedExpert = (Expert) pe; + updateTables(); + } + }); + + Composite divide45 = new Composite(base, 0); + UiService.setGridData(divide45, 9, 9, true, true); + UiService.setGridLayout(divide45, 3); + + Composite c4 = createBlock(divide45, "Profile global priorities"); + createProfileGlobalPrioritiesTable(c4); + + Composite c5 = createBlock(divide45, "Alternative global priorities"); + createAlternativeGlobalPrioritiesTable(c5); + + Composite c6 = createBlock(divide45, "Group classification"); + createGlobalClassificationTable(c6); + + } + + private Composite createBlock(Composite parent, String name) { + + Composite base = new Composite(parent, 0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + CLabel title = new CLabel(base, 0); + title.setText(name); + + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite tableBase = new Composite(base, 0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + return tableBase; + + } + + private void createAlternativeGlobalPrioritiesTable(Composite tableBase) { + + TableAdapter adapter = model.getAlternativeGlobalTable(selectedExpert); + alternativeGlobalTable = new HtmlTextTable(tableBase, adapter.getData(), adapter.getHorizontalHeaders(), adapter.getVerticalHeaders()); + alternativeGlobalTable.render(); + } + + private void createProfileGlobalPrioritiesTable(Composite tableBase) { + + TableAdapter adapter = model.getProfilesGlobalTable(selectedExpert); + profileGlobalTable = new HtmlTextTable(tableBase, adapter.getDataRow(), adapter.getHorizontalHeaders(), true); + profileGlobalTable.render(); + + } + + private void createAlternativeLocalPrioritiesTable(Composite tableBase) { // X + + TableAdapter adapter = model.getAlternativeLocalTable(selectedExpert); + + alternativeLocalTable = new HtmlTextTable(tableBase, adapter.getData(), adapter.getHorizontalHeaders(), + adapter.getVerticalHeaders()); + alternativeLocalTable.render(); + } + + private void createGlobalClassificationTable(Composite tableBase) { + TableAdapter adapter = model.getGlobalClassificationTable(); + + globalClassificationTable = new HtmlTextTable(tableBase, adapter.getDataRow(), adapter.getHorizontalHeaders(), true); + + ArrayList classes = model.getClasses(); + + Color[] colors = UiService.getColorScale(classes.size(), false); + for(int i = 0; i < classes.size(); i++) { + SortingClass cl = classes.get(i); + globalClassificationTable.setCss(".value_"+cl.getName(), "background-color", UiService.toHEX(colors[i]) ); + } + + globalClassificationTable.render(); + + } + + private void updateTables() { + TableAdapter adapter1 = model.getAlternativeGlobalTable(selectedExpert); + TableAdapter adapter2 = model.getProfilesGlobalTable(selectedExpert); + TableAdapter adapter3 = model.getAlternativeLocalTable(selectedExpert); + + alternativeLocalTable.refresh(adapter3.getData()); + profileGlobalTable.refresh(adapter2.getDataRow()); + alternativeGlobalTable.refresh(adapter1.getData()); + + alternativeLocalTable.render(); + profileGlobalTable.render(); + + alternativeGlobalTable.setCss(".value_High", "background-color", "green"); + alternativeGlobalTable.setCss(".value_Moderate", "background-color", "blue"); + alternativeGlobalTable.setCss(".value_Low", "background-color", "red"); + + alternativeGlobalTable.render(); + } + +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRankingAgglomerativeUI.java b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRankingAgglomerativeUI.java new file mode 100644 index 0000000..ce33881 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRankingAgglomerativeUI.java @@ -0,0 +1,190 @@ +package flintstones.method.ahp.sortii.phase.ranking.ui; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.chart.swt.ChartComposite; + +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.data.adapter.TableAdapter; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.ahp.sortii.phase.ranking.AHPSortIIRankingModelAgglomerative; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class AHPSortIIRankingAgglomerativeUI extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + Expert selectedExpert; + Criterion selectedCriterion; + + AHPSortIIRankingModelAgglomerative model; + + HtmlTextTable criterionWeightsTable; + HtmlTextTable clustersTable; + HtmlTextTable alternativeLocalTable; + HtmlTextTable profileGlobalTable; + HtmlTextTable alternativeGlobalTable; + + HashMap visibleComposite = new HashMap<>(); + + @Override + public void init() { + model = (AHPSortIIRankingModelAgglomerative) this.getModel(); + model.execute(); + createPartControls(this.getBaseComposite()); + } + + @Override + public void refresh() { + // TODO Auto-generated method stub + + } + + @Override + protected boolean isForwardEnabled() { + return true; + } + + private void createPartControls(Composite base) { + + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + Composite chartC = createBlock(base, "Chart"); + createChart(chartC); + + Composite chartOptionsC = new Composite(chartC, SWT.NONE); + UiService.setGridData(chartOptionsC, 9, 9, false, false); + UiService.setGridLayout(chartOptionsC, 9, false); + + createChartOptions(chartOptionsC); + + Composite c2 = createBlock(base, "Profile/ReferencePoint local priorities"); + createClutersTable(c2); + } + + JFreeChart chart; + ChartComposite chartBase; + + private void createChartOptions(Composite parent) { + + ProblemElementSelector selectorExpert = new ProblemElementSelector(parent, problemService.getAll(Expert.Type)); + selectorExpert.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + selectedExpert = (Expert) pe; + drawChart(); + drawTable(); + } + }); + + ProblemElementSelector selectorCriterion = new ProblemElementSelector(parent, problemService.getAll(Criterion.Type)); + selectorCriterion.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + selectedCriterion = (Criterion) pe; + drawChart(); + drawTable(); + } + }); + + } + + private void drawChart() { + + if (selectedCriterion == null) + selectedCriterion = (Criterion) problemService.getAll(Criterion.Type)[0]; + + if (selectedExpert == null) + selectedExpert = (Expert) problemService.getAll(Expert.Type)[0]; + + chart = ChartFactory.createXYLineChart("Local priorities for " + selectedExpert.getName() + " - " + selectedCriterion.getName(), "Reference Points/Profiles", + "Value", model.getDataset(selectedExpert, selectedCriterion), PlotOrientation.VERTICAL, false, true, false); + + if (chartBase != null) { + chartBase.setChart(chart); + chart.fireChartChanged(); + } + + addChartDecorations(); + + } + + private void addChartDecorations() { + XYPlot plot = chart.getXYPlot(); + + XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); + renderer.setSeriesStroke(0, new BasicStroke(2.0f)); + + plot.setRenderer(renderer); + plot.setBackgroundPaint(Color.WHITE); + } + + private void createChart(Composite parent) { + + drawChart(); + + chartBase = new ChartComposite(parent, 0, chart); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gd.heightHint = 160; + chartBase.setLayoutData(gd); + //UiService.setGridData(chartBase, 9, 9, true, true); + + } + + private Composite createBlock(Composite parent, String name) { + + Composite base = new Composite(parent, 0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + CLabel title = new CLabel(base, 0); + title.setText(name); + + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite tableBase = new Composite(base, 0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + return tableBase; + + } + + private void drawTable() { + TableAdapter adapter = model.getClustersTable(selectedExpert); + + clustersTable.refresh(adapter.getData()); + clustersTable.render(); + } + + private void createClutersTable(Composite tableBase) { // X + + TableAdapter adapter = model.getClustersTable(selectedExpert); + + clustersTable = new HtmlTextTable(tableBase, adapter.getData(), adapter.getHorizontalHeaders(), + adapter.getVerticalHeaders()); + clustersTable.render(); + } + +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRankingUI.java b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRankingUI.java new file mode 100644 index 0000000..23ec4c7 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking.ui/src/flintstones/method/ahp/sortii/phase/ranking/ui/AHPSortIIRankingUI.java @@ -0,0 +1,190 @@ +package flintstones.method.ahp.sortii.phase.ranking.ui; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.chart.swt.ChartComposite; + +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.data.adapter.TableAdapter; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.ahp.sortii.phase.ranking.AHPSortIIRankingModel; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class AHPSortIIRankingUI extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + Expert selectedExpert; + Criterion selectedCriterion; + + AHPSortIIRankingModel model; + + HtmlTextTable criterionWeightsTable; + HtmlTextTable clustersTable; + HtmlTextTable alternativeLocalTable; + HtmlTextTable profileGlobalTable; + HtmlTextTable alternativeGlobalTable; + + HashMap visibleComposite = new HashMap<>(); + + @Override + public void init() { + model = (AHPSortIIRankingModel) this.getModel(); + model.execute(); + createPartControls(this.getBaseComposite()); + } + + @Override + public void refresh() { + // TODO Auto-generated method stub + + } + + @Override + protected boolean isForwardEnabled() { + return true; + } + + private void createPartControls(Composite base) { + + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + Composite chartC = createBlock(base, "Chart"); + createChart(chartC); + + Composite chartOptionsC = new Composite(chartC, SWT.NONE); + UiService.setGridData(chartOptionsC, 9, 9, false, false); + UiService.setGridLayout(chartOptionsC, 9, false); + + createChartOptions(chartOptionsC); + + Composite c2 = createBlock(base, "Profile/ReferencePoint local priorities"); + createClutersTable(c2); + } + + JFreeChart chart; + ChartComposite chartBase; + + private void createChartOptions(Composite parent) { + + ProblemElementSelector selectorExpert = new ProblemElementSelector(parent, problemService.getAll(Expert.Type)); + selectorExpert.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + selectedExpert = (Expert) pe; + drawChart(); + drawTable(); + } + }); + + ProblemElementSelector selectorCriterion = new ProblemElementSelector(parent, problemService.getAll(Criterion.Type)); + selectorCriterion.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + selectedCriterion = (Criterion) pe; + drawChart(); + drawTable(); + } + }); + + } + + private void drawChart() { + + if (selectedCriterion == null) + selectedCriterion = (Criterion) problemService.getAll(Criterion.Type)[0]; + + if (selectedExpert == null) + selectedExpert = (Expert) problemService.getAll(Expert.Type)[0]; + + chart = ChartFactory.createXYLineChart("Local priorities for " + selectedExpert.getName() + " - " + selectedCriterion.getName(), "Reference Points/Profiles", + "Value", model.getDataset(selectedExpert, selectedCriterion), PlotOrientation.VERTICAL, false, true, false); + + if (chartBase != null) { + chartBase.setChart(chart); + chart.fireChartChanged(); + } + + addChartDecorations(); + + } + + private void addChartDecorations() { + XYPlot plot = chart.getXYPlot(); + + XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); + renderer.setSeriesStroke(0, new BasicStroke(2.0f)); + + plot.setRenderer(renderer); + plot.setBackgroundPaint(Color.WHITE); + } + + private void createChart(Composite parent) { + + drawChart(); + + chartBase = new ChartComposite(parent, 0, chart); + GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gd.heightHint = 160; + chartBase.setLayoutData(gd); + //UiService.setGridData(chartBase, 9, 9, true, true); + + } + + private Composite createBlock(Composite parent, String name) { + + Composite base = new Composite(parent, 0); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + CLabel title = new CLabel(base, 0); + title.setText(name); + + UiService.setFont(title, UiService.FONT_SECTION_TITLE); + + Composite tableBase = new Composite(base, 0); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + + return tableBase; + + } + + private void drawTable() { + TableAdapter adapter = model.getClustersTable(selectedExpert); + + clustersTable.refresh(adapter.getData()); + clustersTable.render(); + } + + private void createClutersTable(Composite tableBase) { // X + + TableAdapter adapter = model.getClustersTable(selectedExpert); + + clustersTable = new HtmlTextTable(tableBase, adapter.getData(), adapter.getHorizontalHeaders(), + adapter.getVerticalHeaders()); + clustersTable.render(); + } + +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/.classpath b/bundles/flintstones.method.ahp.sortii.phase.ranking/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/.polyglot.META-INF b/bundles/flintstones.method.ahp.sortii.phase.ranking/.polyglot.META-INF new file mode 100644 index 0000000..37fd83f --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sortii.phase.ranking + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ranking + diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/.project b/bundles/flintstones.method.ahp.sortii.phase.ranking/.project new file mode 100644 index 0000000..fa08a63 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sortii.phase.ranking + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362633 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sortii.phase.ranking/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c3a09a6 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/META-INF/MANIFEST.MF @@ -0,0 +1,37 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ranking +Bundle-SymbolicName: flintstones.method.ahp.sortii.phase.ranking;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sortii.phase.ranking +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di, + flintstones.entity.preferences.preferencecollection, + flintstones.model.ahppreferences.service, + flintstones.entity.ahp, + flintstones.helper.data, + flintstones.entity.problemelement, + flintstones.entity.ahppreferences, + flintstones.model.problemelement.service, + flintstones.entity.ahpsort.referencepoint, + flintstones.method.ahp.sort.phase.ranking, + flintstones.entity.ahpsort.priority, + flintstones.model.valuation.service, + flintstones.entity.valuation, + flintstones.valuation.numeric.real, + flintstones.model.ahp.referencepoint.service, + flintstones.model.domain.service, + flintstones.helper.debug, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment, + flintstones.clustering.agglomerative, + org.apache.commons.lang, + flintstones.entity.domain, + org.jfree.chart.jfreechart, + flintstones.helper.ahp, + flintstones.domain.numeric.real, + flintstones.engine.R +Export-Package: flintstones.method.ahp.sortii.phase.ranking diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/build.properties b/bundles/flintstones.method.ahp.sortii.phase.ranking/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/plugin.xml b/bundles/flintstones.method.ahp.sortii.phase.ranking/plugin.xml new file mode 100644 index 0000000..52014d1 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/plugin.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIModel.java b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIModel.java new file mode 100644 index 0000000..74f5257 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIModel.java @@ -0,0 +1,566 @@ +package flintstones.method.ahp.sortii.phase.ranking; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import org.apache.commons.lang.ArrayUtils; + +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.ahppreferences.PreferenceCollectionKey; +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.DoubleHelper; +import flintstones.helper.EigenHelper; +import flintstones.helper.MapHelper; +import flintstones.helper.ahp.AHPHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.data.LinkedHashMatrix; +import flintstones.helper.data.Pair; +import flintstones.helper.debug.DH; +import flintstones.method.ahp.sort.phase.ranking.ahpcluster.AHPCluster; +import flintstones.method.ahp.sort.phase.ranking.ahpcluster.AHPClusterer; +import flintstones.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.numeric.real.RealValuation; + +public class AHPSortIIModel { + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + @Inject + IReferencePointService referenceService; + + @Inject + IProblemPreferencesService preferenceService; + + @Inject + IProfileAssignmentService profileService; + + Criterion[] criteria; + Expert[] experts; + + // TODO: REVISAR 06/06/2019 + boolean isOptimisticx = false; + + public ArrayList getClasses() { + SortingClass[] classes = Arrays // + .stream(problemService.getAll(SortingClass.Type)) // + .map(k -> (SortingClass) k).toArray(SortingClass[]::new); + return new ArrayList(Arrays.asList(classes)); + } + // + + LinkedHashMap> expertsWeights = new LinkedHashMap<>(); + + public LinkedHashMap> getExpertsWeights() { + return expertsWeights; + } + + public void cacheCriterionWeightsFor(PreferenceCollection col) { + // Cache some data + ProblemElement[] expertsPes = ProblemElementHelper.getAsUserOrdered(problemService.getAll(Expert.Type)); + experts = ProblemElementHelper.asExperts(expertsPes); + ProblemElement[] criterionsPes = ProblemElementHelper.getAsUserOrdered(problemService.getAll(Criterion.Type)); + criteria = ProblemElementHelper.asCriterions(criterionsPes); + + for(Expert expert: experts) { + + LinkedHashMap criteriaWeights = new LinkedHashMap<>(); + HashMap criteriaWeightsA = new HashMap<>(); + + AHPMatrix matrix = col.getAHPMatrix(null, expert); + + double[] values = EigenHelper.GetNormalizedEigenVector(matrix.getValues()); + + for (int i = 0; i < matrix.getCols().length; i++) { + ProblemElement criterion = matrix.getCols()[i]; + Double value = values[i]; + criteriaWeightsA.put((Criterion) criterion, value); + } + + criteriaWeights = MapHelper.sortByExample(criteriaWeightsA, criteria); + expertsWeights.put(expert, criteriaWeights); + } + } + + // + + public void execute() { + + cacheClusters(); + + cacheProfileAndReferenceLocalPriorities(); + + cacheAlternativeLocalPriorities(); + cacheAlternativeGlobalPriorities(); + + cacheProfileGlobalPriorities(); + } + + LinkedHashMap> expertsClusterers = new LinkedHashMap<>(); + + // Punto de referencia + Perfiles + LinkedHashMap>> expertsRepresentativePoints = new LinkedHashMap<>(); + + private void cacheClusters() { + + for(Expert expert: experts) { + + LinkedHashMap clusterers = new LinkedHashMap<>(); + LinkedHashMap> representativePoints = new LinkedHashMap<>(); + + for (Criterion c : criteria) { + + LinkedList profiles = profileService.get(expert, c).getAllProfiles(); + Double[] values = profiles.stream().map(k -> Double.valueOf(k.getValue())).toArray(Double[]::new); + + double[] valuesp = ArrayUtils.toPrimitive(values); + if (DoubleHelper.IsDescending(valuesp)) + Collections.reverse(profiles); + + LinkedList refPoints = referenceService.get(c); + LinkedList elements_criterion = new LinkedList<>(); + LinkedList values_criterion = new LinkedList<>(); + + int pIndex = 0; + int rIndex = 0; + + for (int i = 0; i < profiles.size() + refPoints.size(); i++) { + + SortingProfile profile = pIndex < profiles.size() ? profiles.get(pIndex) : null; + AHPSortReferencencePoint refPoint = rIndex < refPoints.size() ? refPoints.get(rIndex) : null; + + Double pValue = profile != null ? profile.getValue() : null; + Double rValue = refPoint != null ? refPoint.getValue() : null; + + if (rValue == null) { + elements_criterion.add(profile); + values_criterion.add(pValue); + pIndex++; + } else if (pValue == null) { + elements_criterion.add(refPoint); + values_criterion.add(rValue); + rIndex++; + } else if (pValue < rValue) { + elements_criterion.add(profile); + values_criterion.add(pValue); + pIndex++; + } else { + elements_criterion.add(refPoint); + values_criterion.add(rValue); + rIndex++; + } + } + + AHPClusterer clusterer = new AHPClusterer(elements_criterion.toArray(new ProblemElement[0]));//Aquí se hace la división del clustering + clusterers.put(c, clusterer); + + representativePoints.put(c, elements_criterion); + } + + expertsClusterers.put(expert, clusterers); + expertsRepresentativePoints.put(expert, representativePoints); + } + } + + public LinkedHashMap> getClusterers() { + return expertsClusterers; + } + + LinkedHashMap> pro_ref_localPriorities = new LinkedHashMap<>(); + + private void cacheProfileAndReferenceLocalPriorities() { + + PreferenceCollectionKey prof_prof = new PreferenceCollectionKey(Expert.Type, Criterion.Type, + SortingProfile.Type, SortingProfile.Type); + PreferenceCollection prof_prof_col = preferenceService.get(prof_prof); + + PreferenceCollectionKey ref_ref = new PreferenceCollectionKey(Expert.Type, Criterion.Type, + AHPSortReferencencePoint.Type, AHPSortReferencencePoint.Type); + PreferenceCollection ref_ref_col = preferenceService.get(ref_ref); + + PreferenceCollectionKey ref_pro = new PreferenceCollectionKey(Expert.Type, Criterion.Type, + AHPSortReferencencePoint.Type, SortingProfile.Type); + PreferenceCollection ref_pro_col = preferenceService.get(ref_pro); + + for(Expert expert: experts) { + + LinkedHashMatrix prof_ref_localPriorities_matrix = new LinkedHashMatrix<>(); + + for (Criterion c : criteria) { + + AHPMatrix ppm = prof_prof_col.getAHPMatrix(expert, c); + AHPMatrix rrm = ref_ref_col.getAHPMatrix(expert, c); + + AHPClusterer clusterer = expertsClusterers.get(expert).get(c); + for (AHPCluster cluster : clusterer) { + + AHPMatrix ahpmatrix = new AHPMatrix(cluster.getElements()); + + for (ProblemElement pe1 : cluster) { + for (ProblemElement pe2 : cluster) { + Integer index = null; + if (pe1.getType().equals(SortingProfile.Type) && pe2.getType().equals(SortingProfile.Type)) { + index = ppm.getIndex(pe1, pe2); + } else if (pe1.getType().equals(AHPSortReferencencePoint.Type) + && pe2.getType().equals(AHPSortReferencencePoint.Type)) { + index = rrm.getIndex(pe1, pe2); + } else if (pe1.getType().equals(AHPSortReferencencePoint.Type) + && pe2.getType().equals(SortingProfile.Type)) { + index = ref_pro_col.get(expert, c, pe1, pe2); + } else if (pe1.getType().equals(SortingProfile.Type) + && pe2.getType().equals(AHPSortReferencencePoint.Type)) { + index = AHPHelper.getInverseIndex(ref_pro_col.get(expert, c, pe2, pe1)); + } + + ahpmatrix.set(pe1, pe2, index); + } + + } + + double[] weights = EigenHelper.GetNormalizedEigenVector(ahpmatrix.getValues()); + cluster.setLocalPriorities(weights); + } + + LinkedHashMap pes = clusterer.getNormalizedPriorities(); + for (Entry pe : pes.entrySet()) + prof_ref_localPriorities_matrix.put(c, pe.getKey(), pe.getValue()); + } + + pro_ref_localPriorities.put(expert, prof_ref_localPriorities_matrix); + + } + } + + // Alt, Int, Double + LinkedHashMap> expertsAlternativeG = new LinkedHashMap<>(); + + public LinkedHashMap> getAlternativeGlobalPriorities() { + return expertsAlternativeG; + } + + private void cacheAlternativeGlobalPriorities() { + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + + for(Expert expert: experts) { + + LinkedHashMap alternativeG = new LinkedHashMap<>(); + + for (ProblemElement a : alternatives) { + + Double indexTotal = 0.0; + + for (ProblemElement c : criteria) { + + double localValue = alternativeLocalPriorities.get(expert).get((Alternative) a, (Criterion) c); + double weight = expertsWeights.get(expert).get(c); + double weighted = localValue * weight; + + indexTotal += weighted; + } + + alternativeG.put((Alternative) a, indexTotal); + } + + expertsAlternativeG.put(expert, alternativeG); + + } + } + + LinkedHashMap> expertsProfileG = new LinkedHashMap<>(); + + public LinkedHashMap> getProfileGlobalPriorities() { + return expertsProfileG; + } + + private void cacheProfileGlobalPriorities() { + + Criterion[] criteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + Expert[] experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + + int indexes = profileService.get(experts[0], criteria[0]).getAllProfiles().size(); + ArrayList cls = getClasses(); + + for(Expert expert: experts) { + + LinkedHashMap profileG = new LinkedHashMap<>(); + + for (int index = 0; index < indexes; index++) { + + Double indexTotal = 0.0; + + for (Criterion c : criteria) { + + SortingProfile profile = profileService.get(expert, c).getAllProfiles().get(index); + + double localValue = pro_ref_localPriorities.get(expert).get(c, profile); + double weight = expertsWeights.get(expert).get(c); + double weighted = localValue * weight; + + indexTotal += weighted; + } + + String name = cls.get(index) + " " + index; + SortingProfile prof = new SortingProfile(expert, new Criterion(name), indexTotal); + prof.setName(name); + + profileG.put(prof, indexTotal); + + } + + expertsProfileG.put(expert, profileG); + } + + } + + LinkedHashMap> alternativeLocalPriorities = new LinkedHashMap<>(); + + public LinkedHashMap> getAlternativeLocalPriorities() { + return alternativeLocalPriorities; + } + + private void cacheAlternativeLocalPriorities() { + + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + for(Expert expert: experts) { + + HashMatrix alternativeLocalPrioritiesMatrix = new HashMatrix<>(); + + for (ProblemElement a : alternatives) { + for (ProblemElement c : criteria) { + double pkj = p(expert, (Alternative) a, (Criterion) c); + alternativeLocalPrioritiesMatrix.put((Alternative) a, (Criterion) c, pkj); + } + } + + alternativeLocalPriorities.put(expert, alternativeLocalPrioritiesMatrix); + } + } + + private double p(Expert e, Alternative a, Criterion c) { + + double gaj = gaj(e, a, c); + Pair pair = getAlternativeIntervalElements(e, c, gaj); + ProblemElement refA = pair.getLeft(); + ProblemElement refB = pair.getRight(); + + double soj = soj(refA); + double so1j = soj(refB); + + double poj = poj(e, c, refA); + double poj1 = poj(e, c, refB); + + double up = poj1 - poj; + double down = so1j - soj; + + double division = up / down; + + double right = gaj - soj; + + double total = poj + (division * right); + + return total; + } + + private Pair getAlternativeIntervalElements(Expert e, Criterion c, double gaj) { + LinkedList points = expertsRepresentativePoints.get(e).get(c); + + double[] pointsArr = points.stream().map(k -> { + if (k instanceof SortingProfile) { + return ((SortingProfile) k).getValue(); + } else { + return ((AHPSortReferencencePoint) k).getValue(); + } + }).mapToDouble(Double::doubleValue).toArray(); + + int pos = -1; + if (DoubleHelper.IsAscending(pointsArr)) { + pos = DoubleHelper.FindInAscendingRange(pointsArr, gaj); + } else if (DoubleHelper.IsDescending(pointsArr)) { + pos = DoubleHelper.FindInDescendingRange(pointsArr, gaj); + } else { + throw new RuntimeException("Not orderer"); + } + + if (pos == pointsArr.length - 1) { + pos = pos - 1; + } + + ProblemElement pA = points.get(pos); + ProblemElement pB = points.get(pos + 1); + return new Pair<>(pA, pB); + + } + + private double poj(Expert e, Criterion c, ProblemElement ref) { + return pro_ref_localPriorities.get(e).get(c).get(ref); + } + + private double soj(ProblemElement k) { + + if (k instanceof SortingProfile) { + return ((SortingProfile) k).getValue(); + } else { + return ((AHPSortReferencencePoint) k).getValue(); + } + + } + + private double gaj(Expert expert, Alternative a, Criterion c) { + RealValuation v = (RealValuation) valuationService.getValuationFor(new ProblemElementKey(expert, a, c)); + double value = v.getValue(); + return value; + } + + //////////////////////////// + //////////////////////////// + //////////////////////////// + //////////////////////////// + //////////////////////////// + //////////////////////////// + + LinkedHashMap> classification = new LinkedHashMap<>(); + + public LinkedHashMap> getClassification() { + return classification; + } + + public void classify() { + + // REVISAR + Criterion[] criterions = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + Expert[] experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + Alternative[] alternatives = Arrays.stream(problemService.getAll(Alternative.Type)).map(k -> (Alternative) k).toArray(Alternative[]::new); + + int profileNumber = profileService.get(experts[0], criterions[0]).getAllProfiles().size();; + int classNumber = getClasses().size(); + + boolean isCentral = profileNumber == classNumber; + + if (!isCentral) { + for(Expert expert: experts) { + + HashMap classificationAlternative = new HashMap<>(); + + for (Alternative alternative : alternatives) { + + int index = classifyByLimitingAlternativeV2(expert, alternative); + + SortingClass classs = getClasses().get(index); + classificationAlternative.put(alternative, classs); + } + + classification.put(expert, classificationAlternative); + } + } else if (isCentral) { + for(Expert expert: experts) { + + HashMap classificationAlternative = new HashMap<>(); + + for (Alternative alternative : alternatives) { + + int index = classifyByCentralAlternativeV2(expert, alternative); + SortingClass classs = getClasses().get(index); + classificationAlternative.put(alternative, classs); + + } + + classification.put(expert, classificationAlternative); + } + } + DH.l(2); + + } + +// +// + private Double getAlternativePrioritiesFor(Expert e, Alternative a) { + return expertsAlternativeG.get(e).get(a); + } + +//// + private ArrayList getProfileLimits(Expert e) { + return new ArrayList(expertsProfileG.get(e).values()); + } + +// +// +// + private int classifyByCentralAlternativeV2(Expert expert, Alternative alternative) { + + Double onlyHit = getAlternativePrioritiesFor(expert, alternative); + + ArrayList limits = getProfileLimits(expert); + + DH.l(2); + DH.out(onlyHit); + + double minDistance = Double.MAX_VALUE; + int minDistanceIndex = -1; + + int i = 0; + for (Double limit : limits) { + + double diff = Math.abs(limit - onlyHit); + if (diff < minDistance) { + minDistanceIndex = i; + minDistance = diff; + } else if (diff == minDistance) { // TIE!! + + if (!isOptimisticx) { // GET THE NEW ONE, ELSE KEEP THE OLD ONE + minDistanceIndex = i; + } + + } + + i++; + } + + return minDistanceIndex; +// + } +// + + private int classifyByLimitingAlternativeV2(Expert expert, Alternative alternative) { + + Double onlyHit = getAlternativePrioritiesFor(expert, alternative); + + ArrayList profileLimits = getProfileLimits(expert); + + for (int i = 0; i < profileLimits.size(); i++) { + + double hit = onlyHit; + double limit = profileLimits.get(i); + + if (hit > limit) + return i; + + } + + // No clasification, last one, bad. + return profileLimits.size(); + } + +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIModelAgglomerative.java b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIModelAgglomerative.java new file mode 100644 index 0000000..ebd6e32 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIModelAgglomerative.java @@ -0,0 +1,1055 @@ +package flintstones.method.ahp.sortii.phase.ranking; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import org.apache.commons.lang.ArrayUtils; +import org.rosuda.JRI.Rengine; + +import flintstones.clustering.agglomerative.AgglomerativeCluster; +import flintstones.clustering.agglomerative.AgglomerativeClustering; +import flintstones.clustering.agglomerative.SingleLinkageCriterion; +import flintstones.clustering.agglomerative.exception.InvalidClusterException; +import flintstones.clustering.agglomerative.function.EuclideanDistance; +import flintstones.entity.ahp.AHPMatrix; +import flintstones.entity.ahppreferences.PreferenceCollectionKey; +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.DoubleHelper; +import flintstones.helper.EigenHelper; +import flintstones.helper.MapHelper; +import flintstones.helper.ahp.AHPHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.data.LinkedHashMatrix; +import flintstones.helper.data.Pair; +import flintstones.helper.debug.DH; +import flintstones.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.numeric.real.RealValuation; + +public class AHPSortIIModelAgglomerative { + + Rengine rengine; + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + @Inject + IReferencePointService referenceService; + + @Inject + IProblemPreferencesService preferenceService; + + @Inject + IProfileAssignmentService profileService; + + Criterion[] criteria; + Expert[] experts; + + // TODO: REVISAR 06/06/2019 + boolean isOptimisticx = false; + + public ArrayList getClasses() { + SortingClass[] classes = Arrays // + .stream(problemService.getAll(SortingClass.Type)) // + .map(k -> (SortingClass) k).toArray(SortingClass[]::new); + return new ArrayList(Arrays.asList(classes)); + } + + LinkedHashMap> expertsWeights = new LinkedHashMap<>(); + + public LinkedHashMap> getExpertsWeights() { + return expertsWeights; + } + + public void cacheCriterionWeightsFor(PreferenceCollection col) { + // Cache some data + ProblemElement[] expertsPes = ProblemElementHelper.getAsUserOrdered(problemService.getAll(Expert.Type)); + experts = ProblemElementHelper.asExperts(expertsPes); + ProblemElement[] criterionsPes = ProblemElementHelper.getAsUserOrdered(problemService.getAll(Criterion.Type)); + criteria = ProblemElementHelper.asCriterions(criterionsPes); + + for(Expert expert: experts) { + + LinkedHashMap criteriaWeights = new LinkedHashMap<>(); + HashMap criteriaWeightsA = new HashMap<>(); + + AHPMatrix matrix = col.getAHPMatrix(null, expert); + + double[] values = EigenHelper.GetNormalizedEigenVector(matrix.getValues()); + + for (int i = 0; i < matrix.getCols().length; i++) { + ProblemElement criterion = matrix.getCols()[i]; + Double value = values[i]; + criteriaWeightsA.put((Criterion) criterion, value); + } + + criteriaWeights = MapHelper.sortByExample(criteriaWeightsA, criteria); + expertsWeights.put(expert, criteriaWeights); + } + } + + public void execute() { + + /*if(rengine == null) { + rengine = new Rengine(new String[] { "--vanilla" }, false, null); + }*/ + + //consensualRefPointsRefPointsComparisons(); + + try { + cacheClusters(); + cacheProfileAndReferenceLocalPriorities(); + + cacheAlternativeLocalPriorities(); + cacheAlternativeGlobalPriorities(); + + cacheProfileGlobalPriorities(); + } catch (InvalidClusterException e) { + e.printStackTrace(); + } + } + + /*private LinkedHashMap, Double>>> consensualMatricesRef_Ref = new LinkedHashMap<>(); + + private void consensualRefPointsRefPointsComparisons() { + PreferenceCollectionKey ref_ref = new PreferenceCollectionKey(Expert.Type, Criterion.Type, AHPSortReferencencePoint.Type, AHPSortReferencencePoint.Type); + PreferenceCollection ref_ref_col = preferenceService.get(ref_ref); + + LinkedHashMap, Double> consensualMatrix = null; + LinkedHashMap, Double>> consensualMatrices = new LinkedHashMap<>(); + + Double result; + String pref; + + AHPMatrix matrix = null; + + for(Criterion c: criteria) { + + LinkedList refPoints = referenceService.get(c); + + consensualMatrix = new LinkedHashMap<>(); + + for(int i = 0; i < refPoints.size() - 1; ++i) { + for(int j = i + 1; j < refPoints.size(); ++j) { + + pref = "pref <- c("; + + for(Expert e: experts) { + matrix = ref_ref_col.getAHPMatrix(e, c); + pref += matrix.getValues()[i][j] + ", "; + } + + pref = pref.substring(0, pref.length() - 2); + pref += ");"; + + result = executeMCC(pref, 0.5d); + + consensualMatrix.put(new Pair(refPoints.get(i), refPoints.get(j)), result); + consensualMatrix.put(new Pair(refPoints.get(j), refPoints.get(i)), 1d / result); + } + } + + consensualMatrices.put(c, consensualMatrix); + } + + for(Expert e: experts) + consensualMatricesRef_Ref.put(e, consensualMatrices); + } + + private double executeMCC(String pref, Double epsilon) { + rengine.eval("library(Rsolnp);"); + rengine.eval(pref); + rengine.eval("cost <- rep(1,length(pref));"); + rengine.eval("epsilon <- "+ epsilon + ";"); + rengine.eval("weights <- rep(1/length(pref),length(pref));"); + rengine.eval("fn1 <- function(x) { sum(cost * abs(pref - x)); }"); + rengine.eval("ineq1 <- function(x) { acum = sum(x * weights); return (abs(x - acum)); }"); + rengine.eval("sol <- try(solnp(pref, fun = fn1, ineqfun = ineq1, ineqLB = rep(0, length(pref)), ineqUB = rep(epsilon, length(pref)), LB=rep(0,length(pref)), UB=rep(Inf,length(pref)), control=list(outer.iter=400,delta = 0.01, tol = 0.01)));"); + + REXP rengineSolution = rengine.eval("sum(sol$pars)/length(pref)"); + + return rengineSolution.asDouble(); + }*/ + + LinkedHashMap>> expertsClusterers = new LinkedHashMap<>(); + + // Punto de referencia + Perfiles + LinkedHashMap>> expertsRepresentativePoints = new LinkedHashMap<>(); + + private void cacheClusters() throws InvalidClusterException { + + for(Expert expert: experts) { + + LinkedHashMap> clusterers = new LinkedHashMap<>(); + LinkedHashMap> representativePoints = new LinkedHashMap<>(); + + for (Criterion c : criteria) { + + LinkedList profiles = profileService.get(expert, c).getAllProfiles(); + Double[] values = profiles.stream().map(k -> Double.valueOf(k.getValue())).toArray(Double[]::new); + + double[] valuesp = ArrayUtils.toPrimitive(values); + if (DoubleHelper.IsDescending(valuesp)) + Collections.reverse(profiles); + + LinkedList refPoints = referenceService.get(c); + LinkedList elements_criterion = new LinkedList<>(); + LinkedList values_criterion = new LinkedList<>(); + + int pIndex = 0; + int rIndex = 0; + + for (int i = 0; i < profiles.size() + refPoints.size(); i++) { + + SortingProfile profile = pIndex < profiles.size() ? profiles.get(pIndex) : null; + AHPSortReferencencePoint refPoint = rIndex < refPoints.size() ? refPoints.get(rIndex) : null; + + Double pValue = profile != null ? profile.getValue() : null; + Double rValue = refPoint != null ? refPoint.getValue() : null; + + if (rValue == null) { + elements_criterion.add(profile); + values_criterion.add(pValue); + pIndex++; + } else if (pValue == null) { + elements_criterion.add(refPoint); + values_criterion.add(rValue); + rIndex++; + } else if (pValue < rValue) { + elements_criterion.add(profile); + values_criterion.add(pValue); + pIndex++; + } else { + elements_criterion.add(refPoint); + values_criterion.add(rValue); + rIndex++; + } + } + + Double[] values_criterion_prim = new Double[elements_criterion.size()]; + ProblemElement[] elements_criterion_prim = new ProblemElement[elements_criterion.size()]; + + List clusters = AgglomerativeClustering.process(values_criterion.toArray(values_criterion_prim), + elements_criterion.toArray(elements_criterion_prim), + 3, new SingleLinkageCriterion(new EuclideanDistance())); + + joinPoints(clusters); + + clusterers.put(c, clusters); + representativePoints.put(c, elements_criterion); + + } + + expertsClusterers.put(expert, clusterers); + expertsRepresentativePoints.put(expert, representativePoints); + } + } + + private void joinPoints(List clusters) { + AgglomerativeCluster cluster1, cluster2; + double[] joinedValues; + Object[] joinedElements; + + double joinValue; + ProblemElement joinElement; + + for(int i = 0; i < clusters.size() - 1; ++i) { + cluster1 = clusters.get(i); + cluster2 = clusters.get(i+1); + + joinValue = cluster1.getValues()[cluster1.getValues().length - 1]; + joinElement = (ProblemElement) cluster1.getElements()[cluster1.getElements().length - 1]; + + joinedValues = new double[cluster2.getValues().length + 1]; + joinedElements = new Object[cluster2.getElements().length + 1]; + + joinedValues[0] = joinValue; + joinedElements[0] = joinElement; + + System.arraycopy(cluster2.getValues(), 0, joinedValues, 1, cluster2.getValues().length); + System.arraycopy(cluster2.getElements(), 0, joinedElements, 1, cluster2.getElements().length); + + cluster2.setValues(joinedValues); + cluster2.setElements(joinedElements); + } + } + + public LinkedHashMap>> getExpertsClusterers() { + return expertsClusterers; + } + + LinkedHashMap> pro_ref_localPriorities = new LinkedHashMap<>(); + + public LinkedHashMap> getLocalPrioritiesRepresentativePoints() { + return pro_ref_localPriorities; + } + + /*private void cacheProfileAndReferenceLocalPrioritiesConsensus() { + + PreferenceCollectionKey prof_prof = new PreferenceCollectionKey(Expert.Type, Criterion.Type, + SortingProfile.Type, SortingProfile.Type); + PreferenceCollection prof_prof_col = preferenceService.get(prof_prof); + + PreferenceCollectionKey ref_pro = new PreferenceCollectionKey(Expert.Type, Criterion.Type, + AHPSortReferencencePoint.Type, SortingProfile.Type); + PreferenceCollection ref_pro_col = preferenceService.get(ref_pro); + + for(Expert expert: experts) { + + LinkedHashMatrix prof_ref_localPriorities_matrix = new LinkedHashMatrix<>(); + + for (Criterion c : criteria) { + + AHPMatrix ppm = prof_prof_col.getAHPMatrix(expert, c); + + LinkedHashMap, Double> rrm = consensualMatricesRef_Ref.get(expert).get(c); + + List clusterer = expertsClusterers.get(expert).get(c); + for (AgglomerativeCluster cluster : clusterer) { + + Object[] cluster_elements = cluster.getElements(); + ProblemElement[] elements = new ProblemElement[cluster_elements.length]; + for(int e = 0; e < elements.length; ++e) { + elements[e] = (ProblemElement) cluster_elements[e]; + } + + double[][] matrix = new double[cluster.getElements().length][cluster.getElements().length]; + + ProblemElement pe1, pe2; + for (int i = 0; i < cluster.getElements().length; ++i) { + for (int j = 0; j < cluster.getElements().length; ++j) { + pe1 = (ProblemElement) cluster.getElements()[i]; + pe2 = (ProblemElement) cluster.getElements()[j]; + + Double value = null; + + if(pe1 == pe2) { + value = 1d; + } else { + if (pe1.getType().equals(SortingProfile.Type) && pe2.getType().equals(SortingProfile.Type)) { + value = ppm.getValue(pe1, pe2); + } else if (pe1.getType().equals(AHPSortReferencencePoint.Type) + && pe2.getType().equals(AHPSortReferencencePoint.Type)) { + value = rrm.get(new Pair(pe1, pe2)); + } else if (pe1.getType().equals(AHPSortReferencencePoint.Type) + && pe2.getType().equals(SortingProfile.Type)) { + String string_value = AHPHelper.getLabels()[ref_pro_col.get(expert, c, pe1, pe2)]; + if(string_value.contains("/")) { + String[] string_values = string_value.split("/"); + double v1 = Double.parseDouble(string_values[0]); + double v2 = Double.parseDouble(string_values[1]); + value = v1 / v2; + } else { + value = Double.parseDouble(string_value); + } + } else if (pe1.getType().equals(SortingProfile.Type) + && pe2.getType().equals(AHPSortReferencencePoint.Type)) { + String string_value = AHPHelper.getLabels()[AHPHelper.getInverseIndex(ref_pro_col.get(expert, c, pe2, pe1))]; + if(string_value.contains("/")) { + String[] string_values = string_value.split("/"); + double v1 = Double.parseDouble(string_values[0]); + double v2 = Double.parseDouble(string_values[1]); + value = v1 / v2; + } else { + value = Double.parseDouble(string_value); + } + } + } + + matrix[i][j] = value; + } + } + + double[] weights = EigenHelper.GetNormalizedEigenVector(matrix); + cluster.setValues(weights); + } + + LinkedHashMap pes = normalizePriorities(clusterer, expertsRepresentativePoints.get(expert).get(c)); + for (Entry pe : pes.entrySet()) + prof_ref_localPriorities_matrix.put(c, pe.getKey(), pe.getValue()); + } + + pro_ref_localPriorities.put(expert, prof_ref_localPriorities_matrix); + } + + computeConsensualProfilesPriorities(); + }*/ + + private void cacheProfileAndReferenceLocalPriorities() { + + PreferenceCollectionKey prof_prof = new PreferenceCollectionKey(Expert.Type, Criterion.Type, + SortingProfile.Type, SortingProfile.Type); + PreferenceCollection prof_prof_col = preferenceService.get(prof_prof); + + PreferenceCollectionKey ref_ref = new PreferenceCollectionKey(Expert.Type, Criterion.Type, + AHPSortReferencencePoint.Type, AHPSortReferencencePoint.Type); + PreferenceCollection ref_ref_col = preferenceService.get(ref_ref); + + PreferenceCollectionKey ref_pro = new PreferenceCollectionKey(Expert.Type, Criterion.Type, + AHPSortReferencencePoint.Type, SortingProfile.Type); + PreferenceCollection ref_pro_col = preferenceService.get(ref_pro); + + for(Expert expert: experts) { + + LinkedHashMatrix prof_ref_localPriorities_matrix = new LinkedHashMatrix<>(); + + for (Criterion c : criteria) { + + AHPMatrix ppm = prof_prof_col.getAHPMatrix(expert, c); + AHPMatrix rrm = ref_ref_col.getAHPMatrix(expert, c); + + List clusterer = expertsClusterers.get(expert).get(c); + for (AgglomerativeCluster cluster : clusterer) { + + Object[] cluster_elements = cluster.getElements(); + ProblemElement[] elements = new ProblemElement[cluster_elements.length]; + for(int e = 0; e < elements.length; ++e) { + elements[e] = (ProblemElement) cluster_elements[e]; + } + + AHPMatrix ahpmatrix = new AHPMatrix(elements); + + ProblemElement pe1, pe2; + for (Object element1 : cluster.getElements()) { + for (Object element2 : cluster.getElements()) { + pe1 = (ProblemElement) element1; + pe2 = (ProblemElement) element2; + + Integer index = null; + + if (pe1.getType().equals(SortingProfile.Type) && pe2.getType().equals(SortingProfile.Type)) { + index = ppm.getIndex(pe1, pe2); + } else if (pe1.getType().equals(AHPSortReferencencePoint.Type) + && pe2.getType().equals(AHPSortReferencencePoint.Type)) { + index = rrm.getIndex(pe1, pe2); + } else if (pe1.getType().equals(AHPSortReferencencePoint.Type) + && pe2.getType().equals(SortingProfile.Type)) { + index = ref_pro_col.get(expert, c, pe1, pe2); + } else if (pe1.getType().equals(SortingProfile.Type) + && pe2.getType().equals(AHPSortReferencencePoint.Type)) { + index = AHPHelper.getInverseIndex(ref_pro_col.get(expert, c, pe2, pe1)); + } + + ahpmatrix.set(pe1, pe2, index); + } + } + + double[] weights = EigenHelper.GetNormalizedEigenVector(ahpmatrix.getValues()); + cluster.setValues(weights); + } + + LinkedHashMap pes = normalizePriorities(clusterer, expertsRepresentativePoints.get(expert).get(c)); + for (Entry pe : pes.entrySet()) + prof_ref_localPriorities_matrix.put(c, pe.getKey(), pe.getValue()); + } + + pro_ref_localPriorities.put(expert, prof_ref_localPriorities_matrix); + } + } + + /*private void computeConsensualProfilesPriorities() { + + computeConsensualProfiles(); + + int numProfiles = profileService.get(experts[0], criteria[0]).getAllProfiles().size(); + + String pref; + for(Criterion c: criteria) { + + for(int p = 0; p < numProfiles; ++p) { + + pref = "pref <- c("; + + for(Expert e: experts) { + + LinkedList priorities = consensualProfilesPriorities.get(new Pair (e, c)); + double priority = priorities.get(p); + pref += priority + ", "; + } + + pref = pref.substring(0, pref.length() - 2); + pref += ");"; + + double consensual_priority = executeMCC(pref, 0.05d); + + for(Expert e: experts) { + + SortingProfile profile = profileService.get(e, c).getAllProfiles().get(p); + profile.setValue(Math.round(consensualProfiles.get(new Pair (e, c)).get(p) * 1000d) / 1000d); + pro_ref_localPriorities.get(e).get(c).put(profile, consensual_priority); + + List clusterer = expertsClusterers.get(e).get(c); + for (AgglomerativeCluster cluster: clusterer) { + + orderPrioritiesCluster(cluster, profile, consensual_priority); + orderRepresentativePoints(e, c, profile); + } + } + } + } + } + + private void orderPrioritiesCluster(AgglomerativeCluster cluster, SortingProfile profile, double consensual_priority) { + Object[] elements = cluster.getElements(); + double[] values = cluster.getValues(); + + for(int element = 0; element < elements.length; ++element) { + + if(elements[element].equals(profile)) { + values[element] = consensual_priority; + break; + } + } + } + + private void orderRepresentativePoints(Expert e, Criterion c, SortingProfile profile) { + + LinkedList representativePoints = expertsRepresentativePoints.get(e).get(c); + + boolean isLowerThan; + + for(int rPoints = 0; rPoints < representativePoints.size(); ++rPoints) { + + isLowerThan = false; + + if(representativePoints.get(rPoints).equals(profile)) { + + double profileValue = profile.getValue(); + + if(rPoints != 0) { + + ProblemElement beforeRP = representativePoints.get(rPoints - 1); + + if(beforeRP instanceof AHPSortReferencencePoint) { + + AHPSortReferencencePoint beforeReferencePoint = (AHPSortReferencencePoint) beforeRP; + + if(profileValue < beforeReferencePoint.getValue()) { + + ProblemElement auxElement = representativePoints.get(rPoints - 1); + + representativePoints.set(rPoints - 1, profile); + representativePoints.set(rPoints, auxElement); + + isLowerThan = true; + } + } else { + SortingProfile beforeSortingProfile = (SortingProfile) beforeRP; + if(profileValue < beforeSortingProfile.getValue()) { + + ProblemElement auxElement = representativePoints.get(rPoints - 1); + + + representativePoints.set(rPoints - 1, profile); + representativePoints.set(rPoints, auxElement); + + + isLowerThan = true; + } + } + } + + if(rPoints != representativePoints.size() - 1 && !isLowerThan) { + + ProblemElement afterRP = representativePoints.get(rPoints + 1); + + if(afterRP instanceof AHPSortReferencencePoint) { + + AHPSortReferencencePoint afterReferencePoint = (AHPSortReferencencePoint) afterRP; + + if(profileValue > afterReferencePoint.getValue()) { + + ProblemElement auxElement = representativePoints.get(rPoints + 1); + + representativePoints.set(rPoints + 1, profile); + representativePoints.set(rPoints, auxElement); + + } + } else { + + SortingProfile afterSortingProfile = (SortingProfile) afterRP; + if(profileValue > afterSortingProfile.getValue()) { + + ProblemElement auxElement = representativePoints.get(rPoints + 1); + + representativePoints.set(rPoints + 1, profile); + representativePoints.set(rPoints, auxElement); + } + } + } + } + } + } + + private void computeConsensualProfiles() { + + int numProfiles = problemService.getAll(SortingProfile.Type).length; + numProfiles /= (experts.length * criteria.length); + + List profiles_values; + + String pref; + Double prof, result; + for(Criterion c: criteria) { + + for(int p = 0; p < numProfiles; ++p) { + + pref = "pref <- c("; + + profiles_values = new LinkedList<>(); + for(Expert e: experts) { + ProfileAssignment profAssignment = profileService.get(e, c); + prof = profAssignment.getValues()[p]; + profiles_values.add(prof); + + pref += prof + ", "; + } + + pref = pref.substring(0, pref.length() - 2); + pref += ");"; + + result = executeMCC(pref, (Collections.max(profiles_values) - Collections.min(profiles_values)) / 3d); + + computePriorityConsensualProfile(c, p, result); + } + } + } + + LinkedHashMap, LinkedList> consensualProfilesPriorities = new LinkedHashMap<>(); + LinkedHashMap, LinkedList> consensualProfiles = new LinkedHashMap<>(); + + private void computePriorityConsensualProfile(Criterion c, int numProfile, double consensualProfileValue) { + + for(Expert e: experts) { + + Pair pair = new Pair<>(e, c); + + double priority = p(e, consensualProfileValue, c); + + if(consensualProfilesPriorities.get(pair) != null) { + consensualProfilesPriorities.get(pair).add(numProfile, priority); + consensualProfiles.get(pair).add(consensualProfileValue); + } else { + LinkedList priorities = new LinkedList<>(); + priorities.add(numProfile, priority); + consensualProfilesPriorities.put(pair, priorities); + + LinkedList profiles = new LinkedList<>(); + profiles.add(numProfile, consensualProfileValue); + consensualProfiles.put(pair, profiles); + } + } + } + + private double p(Expert e, double value, Criterion c) { + + double gaj = value; + Pair pair = getAlternativeIntervalElements(e, c, gaj); + ProblemElement refA = pair.getLeft(); + ProblemElement refB = pair.getRight(); + + double soj = soj(refA); + double so1j = soj(refB); + + double poj = poj(e, c, refA); + double poj1 = poj(e, c, refB); + + double up = poj1 - poj; + double down = so1j - soj; + + double division = up / down; + + double right = gaj - soj; + + double total = poj + (division * right); + + return total; + }*/ + + private LinkedHashMap normalizePriorities(List clusters, LinkedList representativePoints) { + + if(clusters.size() == 1) { + ProblemElement[] pes = (ProblemElement[]) clusters.get(0).getElements(); + double[] vals = clusters.get(0).getValues(); + + LinkedHashMap map = new LinkedHashMap<>(); + for(int i = 0; i < pes.length; i++ ) { + map.put(pes[i], vals[i]); + } + + return map; + } + + for(int i = 0; i < clusters.size()-1; i+=1) { + AgglomerativeCluster a = clusters.get(i); + AgglomerativeCluster b = clusters.get(i+1); + join(a,b); + } + + double[] priorities = new double[representativePoints.size()]; + int w = 0; + + AgglomerativeCluster firstCluster = clusters.get(0); + double[] firstPrior = firstCluster.getValues(); + for(int j = 0; j < firstPrior.length; j++) { + priorities[w] = firstPrior[j]; + w++; + } + + for(int i = 1; i < clusters.size(); i++) { + double[] prior = clusters.get(i).getValues(); + for(int j = 1; j < prior.length; j++) { + priorities[w] = prior[j]; + w++; + } + } + + Double[] nPriorities = ArrayUtils.toObject(DoubleHelper.Normalize(priorities)); + LinkedHashMap normalizedValues = new LinkedHashMap<>(); + for(int i = 0; i < nPriorities.length; i++) + normalizedValues.put((ProblemElement) representativePoints.get(i), nPriorities[i]); + + return normalizedValues; + } + + public void join(AgglomerativeCluster top, AgglomerativeCluster bottom) { + + double pA = top.getValues()[top.getValues().length - 1]; + double pB = bottom.getValues()[0]; + + double ratio = pA/pB; + + double[] oldPriorities = bottom.getValues(); + double[] newPriorities = new double[oldPriorities.length]; + for(int i = 0; i < oldPriorities.length; i++) + newPriorities[i] = oldPriorities[i] * ratio; + + bottom.setValues(newPriorities); + } + + // Alt, Int, Double + LinkedHashMap> expertsAlternativeG = new LinkedHashMap<>(); + + public LinkedHashMap> getAlternativeGlobalPriorities() { + return expertsAlternativeG; + } + + private void cacheAlternativeGlobalPriorities() { + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + + for(Expert expert: experts) { + + LinkedHashMap alternativeG = new LinkedHashMap<>(); + + for (ProblemElement a : alternatives) { + + Double indexTotal = 0.0; + + for (ProblemElement c : criteria) { + + double localValue = alternativeLocalPriorities.get(expert).get((Alternative) a, (Criterion) c); + double weight = expertsWeights.get(expert).get(c); + double weighted = localValue * weight; + + indexTotal += weighted; + } + + alternativeG.put((Alternative) a, indexTotal); + } + + expertsAlternativeG.put(expert, alternativeG); + + } + } + + LinkedHashMap> expertsProfileG = new LinkedHashMap<>(); + + public LinkedHashMap> getProfileGlobalPriorities() { + return expertsProfileG; + } + + private void cacheProfileGlobalPriorities() { + + Criterion[] criteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + Expert[] experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + + int indexes = profileService.get(experts[0], criteria[0]).getAllProfiles().size(); + ArrayList cls = getClasses(); + + for(Expert expert: experts) { + + LinkedHashMap profileG = new LinkedHashMap<>(); + + for (int index = 0; index < indexes; index++) { + + Double indexTotal = 0.0; + + for (Criterion c : criteria) { + + SortingProfile profile = profileService.get(expert, c).getAllProfiles().get(index); + + double localValue = pro_ref_localPriorities.get(expert).get(c, profile); + double weight = expertsWeights.get(expert).get(c); + double weighted = localValue * weight; + + indexTotal += weighted; + } + + String name = cls.get(index) + " " + index; + SortingProfile prof = new SortingProfile(expert, new Criterion(name), indexTotal); + prof.setName(name); + + profileG.put(prof, indexTotal); + + } + + expertsProfileG.put(expert, profileG); + } + + } + + LinkedHashMap> alternativeLocalPriorities = new LinkedHashMap<>(); + + public LinkedHashMap> getAlternativeLocalPriorities() { + return alternativeLocalPriorities; + } + + private void cacheAlternativeLocalPriorities() { + + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + for(Expert expert: experts) { + + HashMatrix alternativeLocalPrioritiesMatrix = new HashMatrix<>(); + + for (ProblemElement a : alternatives) { + for (ProblemElement c : criteria) { + double pkj = p(expert, (Alternative) a, (Criterion) c); + alternativeLocalPrioritiesMatrix.put((Alternative) a, (Criterion) c, pkj); + } + } + + alternativeLocalPriorities.put(expert, alternativeLocalPrioritiesMatrix); + } + } + + private double p(Expert e, Alternative a, Criterion c) { + + double gaj = gaj(e, a, c); + Pair pair = getAlternativeIntervalElements(e, c, gaj); + ProblemElement refA = pair.getLeft(); + ProblemElement refB = pair.getRight(); + + double soj = soj(refA); + double so1j = soj(refB); + + double poj = poj(e, c, refA); + double poj1 = poj(e, c, refB); + + double up = poj1 - poj; + double down = so1j - soj; + + double division = up / down; + + double right = gaj - soj; + + double total = poj + (division * right); + + return total; + } + + private Pair getAlternativeIntervalElements(Expert e, Criterion c, double gaj) { + LinkedList points = expertsRepresentativePoints.get(e).get(c); + + double[] pointsArr = points.stream().map(k -> { + if (k instanceof SortingProfile) { + return ((SortingProfile) k).getValue(); + } else { + return ((AHPSortReferencencePoint) k).getValue(); + } + }).mapToDouble(Double::doubleValue).toArray(); + + int pos = -1; + if (DoubleHelper.IsAscending(pointsArr)) { + pos = DoubleHelper.FindInAscendingRange(pointsArr, gaj); + } else if (DoubleHelper.IsDescending(pointsArr)) { + pos = DoubleHelper.FindInDescendingRange(pointsArr, gaj); + } else { + throw new RuntimeException("Not orderer"); + } + + if (pos == pointsArr.length - 1) { + pos = pos - 1; + } + + ProblemElement pA = points.get(pos); + ProblemElement pB = points.get(pos + 1); + return new Pair<>(pA, pB); + + } + + private double poj(Expert e, Criterion c, ProblemElement ref) { + return pro_ref_localPriorities.get(e).get(c).get(ref); + } + + private double soj(ProblemElement k) { + + if (k instanceof SortingProfile) { + return ((SortingProfile) k).getValue(); + } else { + return ((AHPSortReferencencePoint) k).getValue(); + } + + } + + private double gaj(Expert expert, Alternative a, Criterion c) { + RealValuation v = (RealValuation) valuationService.getValuationFor(new ProblemElementKey(expert, a, c)); + double value = v.getValue(); + return value; + } + + //////////////////////////// + //////////////////////////// + //////////////////////////// + //////////////////////////// + //////////////////////////// + //////////////////////////// + + LinkedHashMap> classification = new LinkedHashMap<>(); + + public LinkedHashMap> getClassification() { + return classification; + } + + public void classify() { + + // REVISAR + Criterion[] criterions = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + Expert[] experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + Alternative[] alternatives = Arrays.stream(problemService.getAll(Alternative.Type)).map(k -> (Alternative) k).toArray(Alternative[]::new); + + int profileNumber = profileService.get(experts[0], criterions[0]).getAllProfiles().size(); + int classNumber = getClasses().size(); + + boolean isCentral = profileNumber == classNumber; + + if (!isCentral) { + for(Expert expert: experts) { + + HashMap classificationAlternative = new HashMap<>(); + + for (Alternative alternative : alternatives) { + + int index = classifyByLimitingAlternativeV2(expert, alternative); + + SortingClass classs = getClasses().get(index); + classificationAlternative.put(alternative, classs); + } + + classification.put(expert, classificationAlternative); + } + } else if (isCentral) { + for(Expert expert: experts) { + + HashMap classificationAlternative = new HashMap<>(); + + for (Alternative alternative : alternatives) { + + int index = classifyByCentralAlternativeV2(expert, alternative); + SortingClass classs = getClasses().get(index); + classificationAlternative.put(alternative, classs); + + } + + classification.put(expert, classificationAlternative); + } + } + + DH.l(2); + } + + private Double getAlternativePrioritiesFor(Expert e, Alternative a) { + return expertsAlternativeG.get(e).get(a); + } + + private ArrayList getProfileLimits(Expert e) { + return new ArrayList(expertsProfileG.get(e).values()); + } + + private int classifyByCentralAlternativeV2(Expert expert, Alternative alternative) { + + Double onlyHit = getAlternativePrioritiesFor(expert, alternative); + + ArrayList limits = getProfileLimits(expert); + + DH.l(2); + DH.out(onlyHit); + + double minDistance = Double.MAX_VALUE; + int minDistanceIndex = -1; + + int i = 0; + for (Double limit : limits) { + + double diff = Math.abs(limit - onlyHit); + if (diff < minDistance) { + minDistanceIndex = i; + minDistance = diff; + } else if (diff == minDistance) { // TIE!! + + if (!isOptimisticx) { // GET THE NEW ONE, ELSE KEEP THE OLD ONE + minDistanceIndex = i; + } + } + + i++; + } + + return minDistanceIndex; +// + } +// + + private int classifyByLimitingAlternativeV2(Expert expert, Alternative alternative) { + + Double onlyHit = getAlternativePrioritiesFor(expert, alternative); + + ArrayList profileLimits = getProfileLimits(expert); + + for (int i = 0; i < profileLimits.size(); i++) { + + double hit = onlyHit; + double limit = profileLimits.get(i); + + if (hit > limit) + return i; + + } + + // No clasification, last one, bad. + return profileLimits.size(); + } + +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRanking2Model.java b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRanking2Model.java new file mode 100644 index 0000000..804eeb9 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRanking2Model.java @@ -0,0 +1,104 @@ +package flintstones.method.ahp.sortii.phase.ranking; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.data.LinkedHashMatrix; +import flintstones.helper.data.adapter.TableAdapter; +import flintstones.model.problemelement.service.IProblemElementService; + +public class AHPSortIIRanking2Model extends PhaseMethod { + + AHPSortIIModel db; + + @Inject + IProblemElementService problemService; + + @Override + public String getName() { + return "Classification"; + } + + public void execute() { + db = (AHPSortIIModel) importData("model"); + } + + public ArrayList getClasses(){ + return db.getClasses(); + } + + public TableAdapter getAlternativeLocalTable(Expert expert) { + HashMatrix alternatives_local = db.getAlternativeLocalPriorities().get(expert); + TableAdapter adapter = new TableAdapter(alternatives_local); + return adapter; + } + + public TableAdapter getAlternativeGlobalTable(Expert expert) { + + HashMap data = db.getAlternativeGlobalPriorities().get(expert); + HashMap classification = db.getClassification().get(expert); + + LinkedHashMatrix aggregatedMatrix = new LinkedHashMatrix<>(); + FakeProblemElement f1 = new FakeProblemElement("Global priority"); + FakeProblemElement f2 = new FakeProblemElement("Classification"); + + for(Entry entry : data.entrySet()) + aggregatedMatrix.put(entry.getKey(), f1, entry.getValue()); + + for(Entry entry : classification.entrySet()) + aggregatedMatrix.put(entry.getKey(), f2, entry.getValue()); + + TableAdapter adapter = new TableAdapter(aggregatedMatrix); + + return adapter; + } + + public TableAdapter getProfilesGlobalTable(Expert expert) { + HashMap data = db.getProfileGlobalPriorities().get(expert); + TableAdapter adapter = new TableAdapter(data); + return adapter; + } + + public TableAdapter getGlobalClassificationTable() { + LinkedHashMap globalClassification = new LinkedHashMap<>(); + + LinkedHashMap> classificationByExperts = db.getClassification(); + + ProblemElement[] sClasses = problemService.getAll(SortingClass.Type); + LinkedHashMap assignments = new LinkedHashMap<>(); + + int count; + for(ProblemElement alternative: problemService.getAll(Alternative.Type)) { + + for(ProblemElement sClass: sClasses) + assignments.put(sClass, 0); + + for(Expert expert: classificationByExperts.keySet()) { + HashMap classification = classificationByExperts.get(expert); + count = assignments.get(classification.get(alternative)); + assignments.put(classification.get(alternative), count + 1); + } + + //Take the first one (optimistic vision) for applying pesimistic TODO + ProblemElement max = Collections.max(assignments.entrySet(), (entry1, entry2) -> entry1.getValue() - entry2.getValue()).getKey(); + globalClassification.put(alternative, max); + } + + TableAdapter adapter = new TableAdapter(globalClassification); + return adapter; + } +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRanking2ModelAgglomerative.java b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRanking2ModelAgglomerative.java new file mode 100644 index 0000000..7b770e4 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRanking2ModelAgglomerative.java @@ -0,0 +1,104 @@ +package flintstones.method.ahp.sortii.phase.ranking; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.data.LinkedHashMatrix; +import flintstones.helper.data.adapter.TableAdapter; +import flintstones.model.problemelement.service.IProblemElementService; + +public class AHPSortIIRanking2ModelAgglomerative extends PhaseMethod { + + AHPSortIIModelAgglomerative db; + + @Inject + IProblemElementService problemService; + + @Override + public String getName() { + return "Classification"; + } + + public void execute() { + db = (AHPSortIIModelAgglomerative) importData("model"); + } + + public ArrayList getClasses(){ + return db.getClasses(); + } + + public TableAdapter getAlternativeLocalTable(Expert expert) { + HashMatrix alternatives_local = db.getAlternativeLocalPriorities().get(expert); + TableAdapter adapter = new TableAdapter(alternatives_local); + return adapter; + } + + public TableAdapter getAlternativeGlobalTable(Expert expert) { + + HashMap data = db.getAlternativeGlobalPriorities().get(expert); + HashMap classification = db.getClassification().get(expert); + + LinkedHashMatrix aggregatedMatrix = new LinkedHashMatrix<>(); + FakeProblemElement f1 = new FakeProblemElement("Global priority"); + FakeProblemElement f2 = new FakeProblemElement("Classification"); + + for(Entry entry : data.entrySet()) + aggregatedMatrix.put(entry.getKey(), f1, entry.getValue()); + + for(Entry entry : classification.entrySet()) + aggregatedMatrix.put(entry.getKey(), f2, entry.getValue()); + + TableAdapter adapter = new TableAdapter(aggregatedMatrix); + + return adapter; + } + + public TableAdapter getProfilesGlobalTable(Expert expert) { + HashMap data = db.getProfileGlobalPriorities().get(expert); + TableAdapter adapter = new TableAdapter(data); + return adapter; + } + + public TableAdapter getGlobalClassificationTable() { + LinkedHashMap globalClassification = new LinkedHashMap<>(); + + LinkedHashMap> classificationByExperts = db.getClassification(); + + ProblemElement[] sClasses = problemService.getAll(SortingClass.Type); + LinkedHashMap assignments = new LinkedHashMap<>(); + + int count; + for(ProblemElement alternative: problemService.getAll(Alternative.Type)) { + + for(ProblemElement sClass: sClasses) + assignments.put(sClass, 0); + + for(Expert expert: classificationByExperts.keySet()) { + HashMap classification = classificationByExperts.get(expert); + count = assignments.get(classification.get(alternative)); + assignments.put(classification.get(alternative), count + 1); + } + + //Take the first one (optimistic vision) for applying pesimistic TODO + ProblemElement max = Collections.max(assignments.entrySet(), (entry1, entry2) -> entry1.getValue() - entry2.getValue()).getKey(); + globalClassification.put(alternative, max); + } + + TableAdapter adapter = new TableAdapter(globalClassification); + return adapter; + } +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRankingModel.java b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRankingModel.java new file mode 100644 index 0000000..3a9e2c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRankingModel.java @@ -0,0 +1,151 @@ +package flintstones.method.ahp.sortii.phase.ranking; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.DoubleHelper; +import flintstones.helper.StringHelper; +import flintstones.helper.data.adapter.TableAdapter; +import flintstones.method.ahp.sort.phase.ranking.ahpcluster.AHPClusterer; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; + +public class AHPSortIIRankingModel extends PhaseMethod { + + @Inject + IEclipseContext context; + + @Inject + IProblemPreferencesService prefService; + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + @Override + public String getName() { + return "Priority Functions"; + } + + AHPSortIIModel db; + + public void execute() { + + // XTRA + db = ContextInjectionFactory.make(AHPSortIIModel.class, context); + + // Weights + PreferenceCollection criterionCol = prefService.get(null, Expert.Type, Criterion.Type, Criterion.Type); + db.cacheCriterionWeightsFor(criterionCol); + + db.execute(); + db.classify(); + + exportData("model",db); + } + + public TableAdapter getClustersTable(Expert expert) { + + TableAdapter adapter = new TableAdapter(); + + LinkedHashMap clusterers = db.getClusterers().get(expert); + + LinkedHashMap criterionWeights = db.getExpertsWeights().get(expert); + ProblemElement[] criterions = clusterers.keySet().toArray(new ProblemElement[0]); + + int nCriterion = clusterers.size(); + int nExperts = db.getExpertsWeights().size(); + int nProfiles = problemService.getAll(SortingProfile.Type).length / (nCriterion * nExperts); + int nRefPoints = problemService.getAll(AHPSortReferencencePoint.Type).length / nCriterion; + int cols = nProfiles + nRefPoints; + + // VHeader + ArrayList vHeaderL = new ArrayList<>(); + for (int i = 0; i < nCriterion; i++) { + vHeaderL.add(StringHelper.Draw(criterions[i].getName())); + } + + adapter.setVerticalHeaders(vHeaderL.toArray(new String[0])); + + // H Header + String[] hHeader = new String[cols + 1]; + hHeader[0] = "C. Weight"; + for (int i = 1; i < cols+1; i++) { + hHeader[i] = "E. " + i; + } + adapter.setHorizontalHeaders(hHeader); + + String[][] data = new String[nCriterion][cols+1]; + for (int i = 0; i < nCriterion; i++) { + + Criterion c = (Criterion) criterions[i]; + AHPClusterer clusterer = clusterers.get(c); + LinkedHashMap priorities = clusterer.getNormalizedPriorities(); + + int j = 1; + for (Entry entry : priorities.entrySet()) { + + String cellName = entry.getKey().getShortName() + " (" + DoubleHelper.Draw(entry.getValue()) + ")"; + data[i][j] = cellName; + j++; + } + + data[i][0] = DoubleHelper.Draw(criterionWeights.get(c)); + + } + + adapter.setData(data); + + return adapter; + } + + public XYDataset getDataset(Expert e, Criterion c) { + + LinkedHashMap clusterers = db.getClusterers().get(e); + + XYSeriesCollection dataset = new XYSeriesCollection(); + + XYSeries series = new XYSeries(c.getName()); + AHPClusterer cluster = clusterers.get(c); + LinkedHashMap values = cluster.getNormalizedPriorities(); + + for (Entry entry : values.entrySet()) { + ProblemElement pe = entry.getKey(); + Double keyVal = null; + if (pe instanceof AHPSortReferencencePoint) { + keyVal = ((AHPSortReferencencePoint) pe).getValue(); + } else if (pe instanceof SortingProfile) { + keyVal = ((SortingProfile) pe).getValue(); + } + Double val = entry.getValue(); + + // ABAJO - > IZQ + series.add(keyVal, val); + } + + dataset.addSeries(series); + + return dataset; + } + + +} diff --git a/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRankingModelAgglomerative.java b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRankingModelAgglomerative.java new file mode 100644 index 0000000..e4dcf43 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii.phase.ranking/src/flintstones/method/ahp/sortii/phase/ranking/AHPSortIIRankingModelAgglomerative.java @@ -0,0 +1,145 @@ +package flintstones.method.ahp.sortii.phase.ranking; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.DoubleHelper; +import flintstones.helper.StringHelper; +import flintstones.helper.data.adapter.TableAdapter; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; + +public class AHPSortIIRankingModelAgglomerative extends PhaseMethod { + + @Inject + IEclipseContext context; + + @Inject + IProblemPreferencesService prefService; + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + @Override + public String getName() { + return "Priority Functions"; + } + + AHPSortIIModelAgglomerative db; + + public void execute() { + + // XTRA + db = ContextInjectionFactory.make(AHPSortIIModelAgglomerative.class, context); + + // Weights + PreferenceCollection criterionCol = prefService.get(null, Expert.Type, Criterion.Type, Criterion.Type); + db.cacheCriterionWeightsFor(criterionCol); + + db.execute(); + db.classify(); + + exportData("model",db); + } + + public TableAdapter getClustersTable(Expert expert) { + + TableAdapter adapter = new TableAdapter(); + + LinkedHashMap criterionWeights = db.getExpertsWeights().get(expert); + + int nCriterion = criterionWeights.size(); + int nExperts = db.getExpertsWeights().size(); + int nProfiles = problemService.getAll(SortingProfile.Type).length / (nCriterion * nExperts); + int nRefPoints = problemService.getAll(AHPSortReferencencePoint.Type).length / nCriterion; + int cols = nProfiles + nRefPoints; + + // VHeader + ProblemElement[] criteria = problemService.getAll(Criterion.Type); + ArrayList vHeaderL = new ArrayList<>(); + for (int i = 0; i < nCriterion; i++) + vHeaderL.add(StringHelper.Draw(criteria[i].getName())); + + adapter.setVerticalHeaders(vHeaderL.toArray(new String[0])); + + // H Header + String[] hHeader = new String[cols + 1]; + hHeader[0] = "C. Weight"; + for (int i = 1; i < cols+1; i++) + hHeader[i] = "E. " + i; + + adapter.setHorizontalHeaders(hHeader); + + String[][] data = new String[nCriterion][cols+1]; + for (int i = 0; i < nCriterion; i++) { + + Criterion c = (Criterion) criteria[i]; + + LinkedHashMap priorities = db.getLocalPrioritiesRepresentativePoints().get(expert).get(c); + + int j = 1; + for (Entry entry : priorities.entrySet()) { + + String cellName = entry.getKey().getShortName() + " (" + DoubleHelper.Draw(entry.getValue()) + ")"; + data[i][j] = cellName; + j++; + } + + data[i][0] = DoubleHelper.Draw(criterionWeights.get(c)); + + } + + adapter.setData(data); + + return adapter; + } + + public XYDataset getDataset(Expert e, Criterion c) { + + LinkedHashMap localPriorities = db.getLocalPrioritiesRepresentativePoints().get(e).get(c); + + XYSeriesCollection dataset = new XYSeriesCollection(); + + XYSeries series = new XYSeries(c.getName()); + + for (Entry entry : localPriorities.entrySet()) { + ProblemElement pe = entry.getKey(); + Double keyVal = null; + if (pe instanceof AHPSortReferencencePoint) + keyVal = ((AHPSortReferencencePoint) pe).getValue(); + else if (pe instanceof SortingProfile) + keyVal = ((SortingProfile) pe).getValue(); + + Double val = entry.getValue(); + + // ABAJO - > IZQ + series.add(keyVal, val); + } + + dataset.addSeries(series); + + return dataset; + } + + +} diff --git a/bundles/flintstones.method.ahp.sortii/.classpath b/bundles/flintstones.method.ahp.sortii/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp.sortii/.polyglot.META-INF b/bundles/flintstones.method.ahp.sortii/.polyglot.META-INF new file mode 100644 index 0000000..e098fc2 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp.sortii + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] AHPSortII + diff --git a/bundles/flintstones.method.ahp.sortii/.project b/bundles/flintstones.method.ahp.sortii/.project new file mode 100644 index 0000000..5070e93 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp.sortii + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362633 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp.sortii/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp.sortii/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6624f72 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.ahp.sortii;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp.sortii +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric.real diff --git a/bundles/flintstones.method.ahp.sortii/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.ahp.sortii/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..68d2bd5 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.ahp.sortii +Bundle-Name = AHPSortII \ No newline at end of file diff --git a/bundles/flintstones.method.ahp.sortii/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.ahp.sortii/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..68d2bd5 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.ahp.sortii +Bundle-Name = AHPSortII \ No newline at end of file diff --git a/bundles/flintstones.method.ahp.sortii/build.properties b/bundles/flintstones.method.ahp.sortii/build.properties new file mode 100644 index 0000000..3e5f9ad --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/ diff --git a/bundles/flintstones.method.ahp.sortii/plugin.xml b/bundles/flintstones.method.ahp.sortii/plugin.xml new file mode 100644 index 0000000..a82cd88 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/plugin.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sortii/problem/AHPSortII-Example.flintstones b/bundles/flintstones.method.ahp.sortii/problem/AHPSortII-Example.flintstones new file mode 100644 index 0000000..db92b14 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/problem/AHPSortII-Example.flintstones @@ -0,0 +1,902 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/AHPSortIIMethod.java b/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/AHPSortIIMethod.java new file mode 100644 index 0000000..8646f31 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/AHPSortIIMethod.java @@ -0,0 +1,65 @@ +package flintstones.method.ahp.sortii; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.ahp.sortii.messages.Messages; +import flintstones.valuation.numeric.real.RealValuation; + +public class AHPSortIIMethod extends ValidatedMethod { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.method_name; //$NON-NLS-1$ + } + + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + String numProfileEntity = problemMessages.Profile_count; + String numSortingClassEntity = problemMessages.SortingClass_count; + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, RealValuation.class.getSimpleName(), valuations); + + int numProfiles = getProfilesByExpert(); + int numSortingClasses = problemService.getAll(SortingClass.Type).length; + + validator.setReturn(this.getName()) + .greaterThan(numSortingClassEntity, numSortingClasses, 0).named("numSortingClasses") //$NON-NLS-1$ + .greaterThan(numProfileEntity, numProfiles, 0).named("numProfiles")//$NON-NLS-1$ + .greaterOrEqualsThan(numProfileEntity, numSortingClasses, numProfiles).named("numSortingClasses")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + + private int getProfilesByExpert() { + int totalNumProfiles = problemService.getAll(SortingProfile.Type).length; + int numExperts = problemService.getAll(Expert.Type).length; + int numCriteria = problemService.getAll(Criterion.Type).length; + + if(numExperts > 0 && numCriteria > 0) { + int numProfiles = totalNumProfiles / numExperts; + return numProfiles /= numCriteria; + } else + return totalNumProfiles; + } + +} diff --git a/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/Messages.java b/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/Messages.java new file mode 100644 index 0000000..1bbbe13 --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/Messages.java @@ -0,0 +1,6 @@ +package flintstones.method.ahp.sortii.messages; + +public class Messages { + public String method_name; +} + diff --git a/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/messages.properties b/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/messages.properties new file mode 100644 index 0000000..c9d8a9f --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/messages.properties @@ -0,0 +1 @@ +method_name=Analytic Hierarchy Process Sort II (AHPSort II) diff --git a/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/messages_es.properties b/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/messages_es.properties new file mode 100644 index 0000000..459359d --- /dev/null +++ b/bundles/flintstones.method.ahp.sortii/src/flintstones/method/ahp/sortii/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Proceso Analtico Jerrquico de Ordenacin II (AHPSort II) diff --git a/bundles/flintstones.method.ahp/.classpath b/bundles/flintstones.method.ahp/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.ahp/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.ahp/.polyglot.META-INF b/bundles/flintstones.method.ahp/.polyglot.META-INF new file mode 100644 index 0000000..f9c5f41 --- /dev/null +++ b/bundles/flintstones.method.ahp/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.ahp + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] AHP + diff --git a/bundles/flintstones.method.ahp/.project b/bundles/flintstones.method.ahp/.project new file mode 100644 index 0000000..cf900cb --- /dev/null +++ b/bundles/flintstones.method.ahp/.project @@ -0,0 +1,45 @@ + + + flintstones.method.ahp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362616 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.ahp/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.ahp/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.ahp/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.ahp/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.ahp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.ahp/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.ahp/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.ahp/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.ahp/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.ahp/META-INF/MANIFEST.MF b/bundles/flintstones.method.ahp/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e187d3f --- /dev/null +++ b/bundles/flintstones.method.ahp/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.ahp;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.ahp +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric diff --git a/bundles/flintstones.method.ahp/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.ahp/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..f43bd67 --- /dev/null +++ b/bundles/flintstones.method.ahp/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.ahp +Bundle-Name = AHP \ No newline at end of file diff --git a/bundles/flintstones.method.ahp/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.ahp/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..f43bd67 --- /dev/null +++ b/bundles/flintstones.method.ahp/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.ahp +Bundle-Name = AHP \ No newline at end of file diff --git a/bundles/flintstones.method.ahp/build.properties b/bundles/flintstones.method.ahp/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.method.ahp/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.method.ahp/plugin.xml b/bundles/flintstones.method.ahp/plugin.xml new file mode 100644 index 0000000..8dfb25e --- /dev/null +++ b/bundles/flintstones.method.ahp/plugin.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.ahp/src/flintstones/method/ahp/AHPMethod.java b/bundles/flintstones.method.ahp/src/flintstones/method/ahp/AHPMethod.java new file mode 100644 index 0000000..93041a9 --- /dev/null +++ b/bundles/flintstones.method.ahp/src/flintstones/method/ahp/AHPMethod.java @@ -0,0 +1,40 @@ +package flintstones.method.ahp; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.ahp.messages.Messages; +import flintstones.valuation.numeric.NumericValuation; + +public class AHPMethod extends ValidatedMethod { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.method_name; //$NON-NLS-1$ + } + + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, NumericValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/Messages.java b/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/Messages.java new file mode 100644 index 0000000..83e6a78 --- /dev/null +++ b/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/Messages.java @@ -0,0 +1,5 @@ +package flintstones.method.ahp.messages; + +public class Messages { + public String method_name; +} diff --git a/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/messages.properties b/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/messages.properties new file mode 100644 index 0000000..b9cb732 --- /dev/null +++ b/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/messages.properties @@ -0,0 +1 @@ +method_name=Analytic Hierarchy Process (AHP) diff --git a/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/messages_es.properties b/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/messages_es.properties new file mode 100644 index 0000000..2910757 --- /dev/null +++ b/bundles/flintstones.method.ahp/src/flintstones/method/ahp/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Proceso Analtico Jerrquico (AHP) diff --git a/bundles/flintstones.method.common.model.retranslation/.classpath b/bundles/flintstones.method.common.model.retranslation/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.model.retranslation/.polyglot.META-INF b/bundles/flintstones.method.common.model.retranslation/.polyglot.META-INF new file mode 100644 index 0000000..b3f9a4e --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.model.retranslation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Retranslation + + Sinbad2 + + diff --git a/bundles/flintstones.method.common.model.retranslation/.project b/bundles/flintstones.method.common.model.retranslation/.project new file mode 100644 index 0000000..26c24f4 --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.model.retranslation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362634 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.model.retranslation/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.model.retranslation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0e57570 --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Retranslation +Bundle-SymbolicName: flintstones.method.common.model.retranslation +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.common.retranslation +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.domain, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.valuation.twoTuple, + flintstones.domain.fuzzyset.unbalanced, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di +Export-Package: flintstones.method.common.model.retranslation diff --git a/bundles/flintstones.method.common.model.retranslation/build.properties b/bundles/flintstones.method.common.model.retranslation/build.properties new file mode 100644 index 0000000..41eb6ad --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.method.common.model.retranslation/src/flintstones/method/common/model/retranslation/RetranslationModel.java b/bundles/flintstones.method.common.model.retranslation/src/flintstones/method/common/model/retranslation/RetranslationModel.java new file mode 100644 index 0000000..0ab8ddd --- /dev/null +++ b/bundles/flintstones.method.common.model.retranslation/src/flintstones/method/common/model/retranslation/RetranslationModel.java @@ -0,0 +1,213 @@ +package flintstones.method.common.model.retranslation; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class RetranslationModel { + + private static final int LEFT = 0; + private static final int RIGHT = 1; + + private List retranslationDomains = new LinkedList<>(); + + @Inject + IEclipseContext context; + + public RetranslationModel() {} + + public List getRetranslationDomains() { + return retranslationDomains; + } + + public void setRetranslationDomains(List retranslationDomains) { + this.retranslationDomains = retranslationDomains; + } + + public String[] getRetranslationDomainsIds() { + String[] ids = new String[retranslationDomains.size()]; + for(int i = 0; i < ids.length; ++i) + ids[i] = (String) retranslationDomains.get(i)[1]; + + return ids; + } + + public Domain getRetranslationDomain(String id) { + for(int i = 0; i < retranslationDomains.size(); ++i) + if(retranslationDomains.get(i)[1].equals(id)) + return (Domain) retranslationDomains.get(i)[2]; + return null; + } + + public Map retranslate(Map aggregationResults, FuzzySet retranslationDomain) { + Map retranslationResults = new HashMap<>(); + + Valuation valuation, auxValuation = null; + for (ProblemElement alternative : aggregationResults.keySet()) { + valuation = aggregationResults.get(alternative); + if (retranslationDomain instanceof Unbalanced) { + auxValuation = transformUnbalancedValuation((TwoTupleValuation) valuation, (Unbalanced) retranslationDomain); + } else { + auxValuation = ((TwoTupleValuation) valuation).transform(retranslationDomain); + } + retranslationResults.put((Alternative)alternative, auxValuation); + } + + return retranslationResults; + } + + private Valuation transformUnbalancedValuation(TwoTupleValuation result, Unbalanced retranslationDomain) { + + Map domains = null; + + int testPos, domainSize; + boolean find = false; + Integer labelPos; + + Unbalanced domainTest; + Unbalanced[] auxDomains; + + LabelLinguisticDomain labelTest = null; + LabelLinguisticDomain[] labels; + + double[] alphas = null; + + int size; + int[] sizes = null; + + int[] lh = retranslationDomain.getLh(); + Map lhDomains = new HashMap(); + + for (int i = 0; i < lh.length; i++) { + lhDomains.put(lh[i], generateDomain(lh[i])); + } + + LabelLinguisticDomain label = ((TwoTupleValuation) result).getLabel(); + double alpha = ((TwoTupleValuation) result).getAlpha(); + + int domainPos = lh.length - 1; + do { + domainSize = lh[domainPos]; + domainTest = lhDomains.get(domainSize); + testPos = domainTest.getLabelSet().getPos(label); + labelPos = retranslationDomain.labelPos(domainSize, testPos); + + if (labelPos != null) { + find = true; + + labelTest = retranslationDomain.getLabelSet().getLabel(labelPos); + domains = retranslationDomain.getLabel(labelPos); + + size = domains.size(); + + auxDomains = new Unbalanced[size]; + labels = new LabelLinguisticDomain[size]; + sizes = new int[size]; + alphas = new double[size]; + + int i = 0; + for (Integer auxSize : domains.keySet()) { + auxDomains[i] = lhDomains.get(auxSize); + labels[i] = auxDomains[i].getLabelSet().getLabel(domains.get(auxSize)); + sizes[i] = auxSize; + if (labels[i] == label) + alphas[i] = alpha; + else + alphas[i] = ((TwoTupleValuation) result).transform(auxDomains[i]).getAlpha(); + + i++; + } + } else { + domainPos--; + result = ((TwoTupleValuation) result).transform(lhDomains.get(lh[domainPos])); + label = ((TwoTupleValuation) result).getLabel(); + alpha = ((TwoTupleValuation) result).getAlpha(); + } + } while (!find); + + if ((domains.size() == 1) || (alpha == 0)) { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain); + } else { + if (alpha > 0) { + if (smallSide(labelTest) == RIGHT) { + if (sizes[0] > sizes[1]) { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain); + } else { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[1], retranslationDomain); + } + } else { + if (sizes[0] > sizes[1]) { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[1], retranslationDomain); + } else { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain); + } + } + } else { + if (smallSide(label) == RIGHT) { + if (sizes[0] > sizes[1]) { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[1], retranslationDomain); + } else { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain); + } + } else { + if (sizes[0] > sizes[1]) { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[0], retranslationDomain); + } else { + result = (TwoTupleValuation) transformToResultsDomain(labelTest, alphas[1], retranslationDomain); + } + } + } + } + + return result; + } + + private Unbalanced generateDomain(int cardinality) { + String[] labels = new String[cardinality]; + for (int i = 0; i < cardinality; i++) { + labels[i] = Integer.toString(i); + } + + Unbalanced domain = ContextInjectionFactory.make(Unbalanced.class, context); + domain.createTrapezoidalFunction(labels); + + return domain; + } + + private Valuation transformToResultsDomain(LabelLinguisticDomain label, double alpha, Unbalanced unificationDomain) { + TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context); + result.build(unificationDomain, label, alpha); + return result; + } + + private int smallSide(LabelLinguisticDomain l) { + NumericRealDomain center = l.getSemantic().getCenter(); + NumericRealDomain coverage = l.getSemantic().getCoverage(); + + double left = center.getMin() - coverage.getMin(); + double right = coverage.getMax() - center.getMax(); + + if (left > right) { + return RIGHT; + } else { + return LEFT; + } + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/.classpath b/bundles/flintstones.method.common.phase.aggregation.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.aggregation.ui/.polyglot.META-INF new file mode 100644 index 0000000..b9883b5 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.aggregation.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/.project b/bundles/flintstones.method.common.phase.aggregation.ui/.project new file mode 100644 index 0000000..1b397f0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.aggregation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362635 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.aggregation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7138852 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/build.properties b/bundles/flintstones.method.common.phase.aggregation.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/plugin.xml b/bundles/flintstones.method.common.phase.aggregation.ui/plugin.xml new file mode 100644 index 0000000..6f32379 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationChartUi.java b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationChartUi.java new file mode 100644 index 0000000..08c4b8e --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationChartUi.java @@ -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 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(); + } + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationResultUI.java b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationResultUI.java new file mode 100644 index 0000000..60ba2a2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationResultUI.java @@ -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 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 aggregationResult) { + + Collections.sort(alternatives, new Comparator() { + + @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; + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationUI.java b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationUI.java new file mode 100644 index 0000000..c181df3 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/AggregationUI.java @@ -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); + + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/Messages.java b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/Messages.java new file mode 100644 index 0000000..7611d9d --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/Messages.java @@ -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; + +} diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/messages.properties b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/messages.properties new file mode 100644 index 0000000..e3b4b04 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/messages.properties @@ -0,0 +1,4 @@ +AggregationResultUI_Element=Element +AggregationResultUI_Enabled=Enabled +AggregationResultUI_Ranking=Ranking +AggregationResultUI_Result_valuation=Result valuation diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/messages_es.properties b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/messages_es.properties new file mode 100644 index 0000000..588a1fc --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/messages/messages_es.properties @@ -0,0 +1,4 @@ +AggregationResultUI_Element=Elemento +AggregationResultUI_Enabled=Habilitado +AggregationResultUI_Ranking=Ranking +AggregationResultUI_Result_valuation=Resultado diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/EvaluationColumnLabelProviderRepetido.java b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/EvaluationColumnLabelProviderRepetido.java new file mode 100644 index 0000000..5849cbf --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/EvaluationColumnLabelProviderRepetido.java @@ -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"; + } + } +} diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RankingColumnLabelProvider.java b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RankingColumnLabelProvider.java new file mode 100644 index 0000000..df8b07f --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RankingColumnLabelProvider.java @@ -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(); + } +} diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RankingViewerProvider.java b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RankingViewerProvider.java new file mode 100644 index 0000000..c75438b --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RankingViewerProvider.java @@ -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 _results; + + private class MyComparator implements Comparator { + @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) 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 result = new LinkedList(); + 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]; + } + } +} + diff --git a/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RetranslationViewerProvider.java b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RetranslationViewerProvider.java new file mode 100644 index 0000000..8a0728e --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation.ui/src/flintstones/method/common/phase/aggregation/ui/provider/RetranslationViewerProvider.java @@ -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) inputElement).toArray(); + } +} diff --git a/bundles/flintstones.method.common.phase.aggregation/.classpath b/bundles/flintstones.method.common.phase.aggregation/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.aggregation/.polyglot.META-INF b/bundles/flintstones.method.common.phase.aggregation/.polyglot.META-INF new file mode 100644 index 0000000..1d6cdb5 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.aggregation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Aggregation + diff --git a/bundles/flintstones.method.common.phase.aggregation/.project b/bundles/flintstones.method.common.phase.aggregation/.project new file mode 100644 index 0000000..5456173 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.aggregation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362635 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.aggregation/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.aggregation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4b5bfd7 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/META-INF/MANIFEST.MF @@ -0,0 +1,36 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Aggregation +Bundle-SymbolicName: flintstones.method.common.phase.aggregation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.aggregation +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator, + flintstones.helper.wtable;visibility:=reexport, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.operator, + flintstones.valuation.twoTuple, + flintstones.valuation.linguistic, + org.eclipse.jface, + org.eclipse.wb.swt, + flintstones.domain.fuzzyset.unbalanced, + flintstones.entity.problemelement, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.helper.data, + flintstones.model.problemelement.service, + org.eclipse.e4.core.services, + flintstones.entity.domain, + javax.annotation, + flintstones.entity.operator, + flintstones.entity.method.phase, + flintstones.model.method.phase.service, + flintstones.model.domain.service, + flintstones.entity.aggregation, + flintstones.method.common.model.retranslation +Export-Package: flintstones.method.common.phase.aggregation, + flintstones.method.common.phase.aggregation.exception, + flintstones.method.common.phase.aggregation.provider +Import-Package: flintstones.domain.fuzzyset.unbalanced diff --git a/bundles/flintstones.method.common.phase.aggregation/build.properties b/bundles/flintstones.method.common.phase.aggregation/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.aggregation/plugin.xml b/bundles/flintstones.method.common.phase.aggregation/plugin.xml new file mode 100644 index 0000000..4e1994a --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationModel.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationModel.java new file mode 100644 index 0000000..80d334f --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationModel.java @@ -0,0 +1,35 @@ +package flintstones.method.common.phase.aggregation; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.method.common.phase.aggregation.messages.Messages; + +/** + * The Class Aggregation. + */ +public class AggregationModel extends PhaseMethod { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /* + * (non-Javadoc) + * + * @see flintstones.phasemethod.PhaseMethod#getName() + */ + @Override + public String getName() { + return messages.Aggregation_phase; + } + + + public void export(String k, Object v) { + this.exportData(k, v, true); + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationResultModel.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationResultModel.java new file mode 100644 index 0000000..384ea19 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationResultModel.java @@ -0,0 +1,271 @@ +package flintstones.method.common.phase.aggregation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.aggregation.AggregationItem; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.ImportedDataNotFoundException; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +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.entity.valuation.Valuation; +import flintstones.helper.MapHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.method.common.model.retranslation.RetranslationModel; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +public class AggregationResultModel extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + @Inject + IDomainService domainService; + + @Inject + IEclipseContext context; + + // Model + private RetranslationModel retranslationModel; + private AggregationModel baseModel; + + private Map cacheRankingPosition = new LinkedHashMap<>(); + + // Data + private Map aggregationResults = new LinkedHashMap<>(); + private Map retranslatedResults = new HashMap<>(); + + // Options + private String firstToAggregate = Expert.Type; + + public AggregationResultModel() { + + } + + @PostConstruct + private void init() { + retranslationModel = ContextInjectionFactory.make(RetranslationModel.class, context); + } + + @Override + public String getName() { + return "Aggregation Result Model"; + } + + public void setAggregationModel(AggregationModel baseModel) { + this.baseModel = baseModel; + } + + @SuppressWarnings("unchecked") + public Map aggregate(Alternative[] alternatives) { + + // 1. Aggregation + String importItem = firstToAggregate.equals(Expert.Type) ? "expertCriterionWeightsMainTtem" + : "criterionExpertWeightsMainItem"; + + AggregationItem item = (AggregationItem) importData(importItem); + + Aggregator aggregator = new Aggregator(getValuations()); + ContextInjectionFactory.inject(aggregator, context); + + HashMap result = aggregator.aggregateAll(alternatives, item); + + LinkedHashMap sortedResult = (LinkedHashMap) MapHelper + .sortByValue(result, true); + + // 2. Decision Matrix + ArrayList subCriteriaItems = (ArrayList) importData("criterionExpertSubItems"); + + HashMap criteriaWeights = (HashMap) importData("criterionWeights"); + + HashMatrix decisionResult = aggregator + .aggregateAndGetDecisionMatrix(alternatives, subCriteriaItems.toArray(new AggregationItem[0])); + + // 3. Export the results + + String[] exported = getExportedKeys(false); + for(String ex : exported) + baseModel.export(ex, this.importData(ex)); + + baseModel.export("aggregationresults", sortedResult); + baseModel.export("decisionmatrix", decisionResult); + baseModel.export("aggregatedWeights", criteriaWeights); + + // Retro + aggregationResults = sortedResult; + return sortedResult; + + } + + public Map getAggregationResults() { + return this.aggregationResults; + } + + public void setFirstToAggregate(String firstToAggregate) { + this.firstToAggregate = firstToAggregate; + } + + public String getFirstToAggregate() { + return firstToAggregate; + } + + public Map retranslateAggregationResults(FuzzySet retranslationDomain) { + Map result = retranslationModel.retranslate(getAggregationResults(), + (FuzzySet) retranslationDomain); + return (LinkedHashMap) MapHelper.sortByValue(result, true); + } + + public Map getRetranslationResult() { + return retranslatedResults; + } + + public Domain getUnifiedDomain() { + Domain d = null; + try { + d = (Domain) importData("unifiedDomain"); + + } catch (ImportedDataNotFoundException e) { + + } + + if (d == null) + d = valuationService.getAll()[0].getDomain(); + + return d; + } + + @SuppressWarnings("unchecked") + private Map getValuations() { + Map valuations; + + try { + valuations = (Map) importData("twoTupleUnifiedValuations"); + } catch(ImportedDataNotFoundException e) { + valuations = valuationService.getAllKV(); + } + + return valuations; + + } + + public void computeRankingAlternatives(Map result) { + cacheRankingPosition.clear(); + + int pos = 1; + + List> results = result.entrySet().stream().collect(Collectors.toList()); + for (int i = 0; i < results.size() - 1; i++) { + Entry entry1 = results.get(i); + Entry entry2 = results.get(i + 1); + + Alternative a = entry1.getKey(); + Valuation v1 = entry1.getValue(); + Valuation v2 = entry2.getValue(); + + cacheRankingPosition.put(a, pos); + + if (v1.compareTo(v2) != 0) + pos++; + } + + if (results.size() != 0) + cacheRankingPosition.put(results.get(results.size() - 1).getKey(), pos); + + } + + public int getRankingAlternative(Alternative alternative) { + Integer pos = cacheRankingPosition.get(alternative); + return pos != null ? pos : 1; + } + + public String[] getRetranslationDomainsIds() { + if (retranslationModel.getRetranslationDomains().isEmpty()) { + try { + retranslationModel.setRetranslationDomains(importLinguisticHierarchiesDomains()); + } catch (ImportedDataNotFoundException e) { + retranslationModel.setRetranslationDomains(importGeneralRetranslationDomains()); + } + } + return retranslationModel.getRetranslationDomainsIds(); + } + + public void computeRetranslationResults(String id) { + Domain domain = getRetranslationDomain(id); + + if (domain.getName().equals(this.getUnifiedDomain().getName())) + retranslatedResults = aggregationResults; + else + retranslatedResults = retranslateAggregationResults((FuzzySet) domain); + } + + /** + * Get retranslation domain id retranslation domain id + * + * @return the retranslation domain + */ + public Domain getRetranslationDomain(String id) { + if (id.equals(this.getUnifiedDomain().getName())) { + return this.getUnifiedDomain(); + } else { + Domain retranslationDomain = retranslationModel.getRetranslationDomain(id); + return retranslationDomain; + } + } + + /** + * Get the linguistic hierarchies domains except unification domain + * + * @return lh domains + */ + @SuppressWarnings("unchecked") + private List importLinguisticHierarchiesDomains() { + List elhDomains = (List) this.importData("elhDomains"); + elhDomains.remove(elhDomains.size() - 1); + return elhDomains; + } + + /** + * Get all the domains except unification domain + * + * @return retranslation domains + */ + private List importGeneralRetranslationDomains() { + Domain unifiedDomain = getUnifiedDomain(); + List domainsStructured = new LinkedList(); + List domains = Arrays.asList(domainService.getAll()); + for (Domain domain : domains) + if (!domain.equals(unifiedDomain) && domain instanceof FuzzySet) + domainsStructured.add( + new Object[] { ((FuzzySet) domain).getLabelSet().getCardinality(), domain.getName(), domain }); + + return domainsStructured; + } + + public Alternative[] getAlternatives() { + return ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationWeights.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationWeights.java new file mode 100644 index 0000000..e0cdce5 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/AggregationWeights.java @@ -0,0 +1,49 @@ +package flintstones.method.common.phase.aggregation; + +import java.util.HashMap; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.HashMatrix; + +public class AggregationWeights { + + HashMatrix expertCriterionWeights; + HashMatrix criterionExpertWeights; + HashMap expertWeights; + HashMap criterionWeights; + + public AggregationWeights(HashMatrix expertCriterionWeights, // + HashMatrix criterionExpertWeights, // + HashMap expertWeights, // + HashMap criterionWeights // + ) { +// super(); + this.expertCriterionWeights = expertCriterionWeights; + this.criterionExpertWeights = criterionExpertWeights; + this.expertWeights = expertWeights; + this.criterionWeights = criterionWeights; + } + + public Double get(ProblemElement first) { + return get(first,null); + } + + public Double get(ProblemElement first, ProblemElement second) { + + // Only one element + if (second == null) { + Double val = expertWeights.get(first); + if (val == null) + criterionWeights.get(first); + return val; + } + + if (first.getType().equals(Expert.Type)) + return expertCriterionWeights.get((Expert) first, (Criterion) second); + return criterionExpertWeights.get((Criterion) first, (Expert) second); + + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/Aggregator.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/Aggregator.java new file mode 100644 index 0000000..f51b21d --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/Aggregator.java @@ -0,0 +1,129 @@ +package flintstones.method.common.phase.aggregation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.inject.Inject; + +import flintstones.entity.aggregation.AggregationItem; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IParameterizedOperator; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.operator.service.IOperatorService; + +class Aggregator { + + @Inject + IOperatorService operatorService; + + Map uvaluations; + + public Aggregator(Map unifiedValuations) { + this.uvaluations = unifiedValuations; + } + + public HashMap aggregateAll(Alternative[] alternatives, AggregationItem root) { + HashMap result = aggregateAlternatives(alternatives, root); + return result; + } + + private HashMap aggregateAlternatives(Alternative[] alternatives, AggregationItem root){ + + HashMap result = new HashMap<>(); + for(Alternative a : alternatives) { + Valuation v = aggregateAlternative(a,root); + result.put(a, v); + } + return result; + + } + + private Valuation aggregateAlternative(Alternative a, AggregationItem root) { + + try { + AggregationItem rootAux = (AggregationItem) root.clone(); + rootAux.setAlternative(a, true); + return aggregateItem(rootAux); + } catch (CloneNotSupportedException e) { + e.printStackTrace(); + return null; + } + } + + private Valuation aggregateItem(AggregationItem parentItem) { + + AggregationItem[] children = parentItem.getChildren(); + + // Bottom element -- Return the valuation + if(children.length == 0) { + ProblemElementKey pek = new ProblemElementKey() // + .assign(parentItem.getAlternative()) // + .assign(parentItem.getElement2()) // + .assign(parentItem.getElement3()); + + Valuation v = uvaluations.get(pek); + return v; + } + + // Middle element, aggregate its children and return the result + List valuations = new ArrayList<>(); + List items = new ArrayList<>(); + + for(AggregationItem item : children) { + + if(!item.isEnabled()) + continue; + + items.add(item.getElement2()); + + Valuation v = aggregateItem(item); + valuations.add(v); + } + + String operatorId = parentItem.getOperatorId(); + + List weights = Arrays.stream(children).map(k -> k.getWeight()).collect(Collectors.toList()); + + if(valuations.size() == 1) + return valuations.get(0); + + if(operatorId.isEmpty()) + return null; + + AggregationOperator operator = operatorService.getAggregationOperator(operatorId, valuations.get(0).getId()); + + Valuation v = null; + if(operator instanceof IParameterizedOperator)//To visualize the dialog + v = operator.computeParameterizedAggregation(items.toArray(new ProblemElement[0]), valuations, weights); + else + v = operator.computeAggregation(valuations, weights); + + return v; + } + + public HashMatrix aggregateAndGetDecisionMatrix(Alternative[] alternatives, AggregationItem[] subCriteria) { + + HashMatrix dMatrix = new HashMatrix<>(); + for(Alternative a : alternatives) { + for(AggregationItem critItem : subCriteria ) { + // Prepare things + critItem.setAlternative(a, true); + Valuation v = aggregateItem(critItem); + dMatrix.put(a, (Criterion)critItem.getElement2(), v); + + } + } + + return dMatrix; + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/exception/AtLeastOneTopLevelElementEnabled.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/exception/AtLeastOneTopLevelElementEnabled.java new file mode 100644 index 0000000..8a51f4d --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/exception/AtLeastOneTopLevelElementEnabled.java @@ -0,0 +1,21 @@ +package flintstones.method.common.phase.aggregation.exception; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Class AtLeastOneTopLevelElementEnabled. + */ +public class AtLeastOneTopLevelElementEnabled extends Exception { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = -3604211158243889353L; + + /** + * Instantiates a new at least one top level element enabled. + * + * @param pe the pe + */ + public AtLeastOneTopLevelElementEnabled(ProblemElement pe) { + super("You mast enable at least one top-level element with at least one enabled final children. Error found when aggregating " + pe.getName() + " (" + pe.getType()+ ")" ); + } +} diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/exception/OperatorNotAssignedException.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/exception/OperatorNotAssignedException.java new file mode 100644 index 0000000..ed0b600 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/exception/OperatorNotAssignedException.java @@ -0,0 +1,21 @@ +package flintstones.method.common.phase.aggregation.exception; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Class OperatorNotAssignedException. + */ +public class OperatorNotAssignedException extends Exception { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 968207884931855311L; + + /** + * Instantiates a new operator not assigned exception. + * + * @param pe the pe + */ + public OperatorNotAssignedException(ProblemElement pe) { + super("El elemento no tiene un operador asignado: " + pe.getName() + " ("+pe.getType()+")" ); + } +} diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/listener/ProblemElementAggregationCheckStateListener.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/listener/ProblemElementAggregationCheckStateListener.java new file mode 100644 index 0000000..9124571 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/listener/ProblemElementAggregationCheckStateListener.java @@ -0,0 +1,45 @@ +package flintstones.method.common.phase.aggregation.listener; + +import java.util.HashMap; + +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.ICheckStateListener; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The listener interface for receiving problemElementAggregationCheckState events. + * The class that is interested in processing a problemElementAggregationCheckState + * event implements this interface, and the object created + * with that class is registered with a component using the + * component's addProblemElementAggregationCheckStateListener method. When + * the problemElementAggregationCheckState event occurs, that object's appropriate + * method is invoked. + * + * @see ProblemElementAggregationCheckStateEvent + */ +public class ProblemElementAggregationCheckStateListener implements ICheckStateListener { + + /** The enabled PE. */ + HashMap enabledPE; + + /** + * Instantiates a new problem element aggregation check state listener. + * + * @param enabledPE the enabled PE + */ + public ProblemElementAggregationCheckStateListener(HashMap enabledPE){ + this.enabledPE = enabledPE; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent) + */ + @Override + public void checkStateChanged(CheckStateChangedEvent event) { + boolean status = event.getChecked(); + ProblemElement pe = (ProblemElement) event.getElement(); + enabledPE.put(pe, status); + } + +} diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/Messages.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/Messages.java new file mode 100644 index 0000000..ce8d8c7 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/Messages.java @@ -0,0 +1,21 @@ +package flintstones.method.common.phase.aggregation.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String WeightsDialog_0; + public String WeightsDialog_Invalid_range; + public String WeightsDialog_Invalid_value; + public String WeightsDialog_Values_for; + public String WeightsDialog_Simple_aggregation; + public Object WeightsDialog_All; + public String WeightsDialog_Cancel_all; + public String WeightsDialog_Cancel; + public String WeightsDialog_Save; + public String Aggregation_phase; + + +} diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/messages.properties b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/messages.properties new file mode 100644 index 0000000..9a4d51c --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/messages.properties @@ -0,0 +1,15 @@ +AggregationProcess_Aggregation_process=Aggregation process +AggregationProcess_Criterion=Criterion +AggregationProcess_Expert=Expert +AggregationProcess_GRP=GRP +AggregationProcess_Weight=Weight +Aggregation_phase=Aggregation +WeightsDialog_0=Invalid_range +WeightsDialog_All=All +WeightsDialog_Cancel=Cancel +WeightsDialog_Cancel_all=Cancel all +WeightsDialog_Invalid_range=Invalid range +WeightsDialog_Invalid_value=Invalid value +WeightsDialog_Save=Save +WeightsDialog_Simple_aggregation=Simple aggregation +WeightsDialog_Values_for=Values for diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/messages_es.properties b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/messages_es.properties new file mode 100644 index 0000000..cd7bbe3 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/messages/messages_es.properties @@ -0,0 +1,6 @@ +AggregationProcess_Aggregation_process=Proceso de agregacin +AggregationProcess_Criterion=Criterio +AggregationProcess_Expert=Experto +AggregationProcess_GRP=GRP +AggregationProcess_Weight=Peso +Aggregation_phase=Agregacin \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/provider/ProblemElementAggregationCheckStateProvider.java b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/provider/ProblemElementAggregationCheckStateProvider.java new file mode 100644 index 0000000..c00db52 --- /dev/null +++ b/bundles/flintstones.method.common.phase.aggregation/src/flintstones/method/common/phase/aggregation/provider/ProblemElementAggregationCheckStateProvider.java @@ -0,0 +1,46 @@ +package flintstones.method.common.phase.aggregation.provider; + +import java.util.HashMap; + +import org.eclipse.jface.viewers.ICheckStateProvider; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Class ProblemElementAggregationCheckStateProvider. + */ +public class ProblemElementAggregationCheckStateProvider implements ICheckStateProvider { + + /** The enabled PE. */ + HashMap enabledPE; + + /** + * Instantiates a new problem element aggregation check state provider. + * + * @param enabledPE the enabled PE + */ + public ProblemElementAggregationCheckStateProvider(HashMap enabledPE) { + this.enabledPE = enabledPE; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ICheckStateProvider#isChecked(java.lang.Object) + */ + @Override + public boolean isChecked(Object element) { + ProblemElement pe = (ProblemElement) element; + Boolean status = enabledPE.get(pe); + if(status != null && status.booleanValue()) + return true; + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ICheckStateProvider#isGrayed(java.lang.Object) + */ + @Override + public boolean isGrayed(Object element) { + return false; + } + +} diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.classpath b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.polyglot.META-INF new file mode 100644 index 0000000..fba3521 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.ahp.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.project b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.project new file mode 100644 index 0000000..c79b94b --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.ahp.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362640 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4ffe2c8 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.common.phase.collectweights.ahp.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights.ahp.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.valuation.ahp.ui, + flintstones.method.common.phase.collectweights.ahp, + flintstones.entity.problemelement, + flintstones.entity.method.phase, + flintstones.entity.ahppreferences, + flintstones.entity.problemelement.ui, + flintstones.helper.html, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/build.properties b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/plugin.xml new file mode 100644 index 0000000..253aae0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp.ui/src/flintstones/method/common/phase/collectweights/ahp/ui/CollectWeightsAHPUI.java b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/src/flintstones/method/common/phase/collectweights/ahp/ui/CollectWeightsAHPUI.java new file mode 100644 index 0000000..555d82e --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp.ui/src/flintstones/method/common/phase/collectweights/ahp/ui/CollectWeightsAHPUI.java @@ -0,0 +1,139 @@ +package flintstones.method.common.phase.collectweights.ahp.ui; + +import java.util.ArrayList; +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.ahppreferences.PreferenceMatrix; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.ui.widget.ProblemElementSelector; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.common.phase.collectweights.ahp.CollectWeightsAHPModel; +import flintstones.model.ui.service.UiService; +import flintstones.valuation.ahp.ui.AHPValuationPanel; +import flintstones.valuation.ahp.ui.IAHPValuationPanelClickListener; + +public class CollectWeightsAHPUI extends PhaseMethodUI implements IAHPValuationPanelClickListener { + + ProblemElementSelector selector; + + CollectWeightsAHPModel model; + AHPValuationPanel panel; + + HtmlTextTable table; + + @Inject + IEclipseContext context; + + @Override + public void init() { + + model = (CollectWeightsAHPModel) this.getModel(); + + Composite base = new Composite(this.getBaseComposite(), 0); + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + ProblemElement[] criterions = model.getCriterions(); + ProblemElement[] experts = model.getExperts(); + + Composite row1 = new Composite(base, 0); + UiService.setGridLayout(row1, 1); + UiService.setGridData(row1, 9, 0, true, false); + + Label expertLabel = new Label(row1, 0); + expertLabel.setText("Experto: "); + UiService.setFont(expertLabel, UiService.FONT_SECTION_TITLE); + + selector = new ProblemElementSelector(row1, experts); + selector.setListener(new IProblemElementChangedListener() { + + @Override + public void problemElementChanged(ProblemElement pe) { + panel.clear(); + panel.base1( model.getCriterions(), model.getCriterions(),getCurrentPreferenceMatrix().getMatrix()); + refreshWeights(); + } + }); + + ScrolledComposite c1 = new ScrolledComposite(base, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + UiService.setGridLayout(c1, 1); + UiService.setGridData(c1, 9, 9, true, true); + + c1.setExpandHorizontal(true); + c1.setExpandVertical(true); + c1.addListener(SWT.Resize, event -> { + int width = c1.getClientArea().width; + c1.setMinSize(base.computeSize(width, SWT.DEFAULT)); + }); + + Composite row2 = new Composite(c1, 0); + UiService.setGridLayout(row2, 1); + UiService.setGridData(row2, 9, 0, true, false); + + c1.setContent(row2); + + panel = new AHPValuationPanel(row2); + panel.show(false); + ContextInjectionFactory.inject(panel, context); + panel.setButtonOnClickListener(this); + panel.base1(criterions, criterions, getCurrentPreferenceMatrix().getMatrix()); + + Composite htmlrow = new Composite(base,0); + UiService.setGridLayout(htmlrow, 1); + UiService.setGridData(htmlrow, 9, 1, true, false); + + String[] headers = Arrays.stream(model.getCriterions()).map(k -> k.getName()).toArray(String[]::new); + String[] values = new String[headers.length]; + Arrays.fill(values, " "); + table = new HtmlTextTable(htmlrow, values, headers, false); + table.render(); + } + + @Override + public void refresh() { + } + + @Override + protected boolean isForwardEnabled() { + model.getWeights(getCurrentExpert()); + return true; + } + + @Override + public void onClick(ProblemElement a, ProblemElement b, int position) { + getCurrentPreferenceMatrix().setDiagonal(a, b, position); + panel.select(a, b, position); + + refreshWeights(); + + sendRefresh(); + } + + private void refreshWeights() { + ArrayList arr = model.getWeights(getCurrentExpert()); + String[] values = arr.stream().map(k -> k+"").toArray(String[]::new); + + String[] headers = Arrays.stream(model.getCriterions()).map(k -> k.getName()).toArray(String[]::new); + table = new HtmlTextTable(table.getParent(), values, headers, false); + table.render(); + } + + private ProblemElement getCurrentExpert() { + return selector.getSelectedElement(); + } + + private PreferenceMatrix getCurrentPreferenceMatrix() { + return model.getMatrix(getCurrentExpert()); + } +} diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/.classpath b/bundles/flintstones.method.common.phase.collectweights.ahp/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.ahp/.polyglot.META-INF new file mode 100644 index 0000000..3fb2f7b --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.ahp + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ahp + diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/.project b/bundles/flintstones.method.common.phase.collectweights.ahp/.project new file mode 100644 index 0000000..14d8185 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.ahp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362639 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.ahp/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2867d1d --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ahp +Bundle-SymbolicName: flintstones.method.common.phase.collectweights.ahp;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights.ahp +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase, + flintstones.model.domain.service, + javax.inject, + flintstones.entity.problemelement, + flintstones.model.problemelement.service, + flintstones.method.common.phase.collectweights, + flintstones.entity.ahppreferences, + javax.annotation, + flintstones.helper.data, + flintstones.entity.ahp, + flintstones.entity.domain +Export-Package: flintstones.method.common.phase.collectweights.ahp diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/build.properties b/bundles/flintstones.method.common.phase.collectweights.ahp/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.ahp/plugin.xml new file mode 100644 index 0000000..1cbb76c --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/plugin.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ahp/src/flintstones/method/common/phase/collectweights/ahp/CollectWeightsAHPModel.java b/bundles/flintstones.method.common.phase.collectweights.ahp/src/flintstones/method/common/phase/collectweights/ahp/CollectWeightsAHPModel.java new file mode 100644 index 0000000..2ae8e0e --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ahp/src/flintstones/method/common/phase/collectweights/ahp/CollectWeightsAHPModel.java @@ -0,0 +1,74 @@ +package flintstones.method.common.phase.collectweights.ahp; + +import java.util.ArrayList; +import java.util.HashMap; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import flintstones.entity.ahppreferences.PreferenceMatrix; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.EigenHelper; +import flintstones.helper.data.HashMapList; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; + +public class CollectWeightsAHPModel extends PhaseMethod { + + @Inject + IDomainService domainService; + + @Inject + IProblemElementService problemService; + + HashMap eMatrix = new HashMap<>(); + HashMap experts = new HashMap<>(); + HashMapList weights = new HashMapList<>(); + + @PostConstruct + private void init() { + for (ProblemElement e : getExperts()) { + PreferenceMatrix matrix = new PreferenceMatrix(getCriterions(), getCriterions()); + eMatrix.put(e, matrix); + experts.put(e.getName(), e); + } + } + + @Override + public String getName() { + return "AHP"; + } + + + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + public ProblemElement[] getCriterions() { + return problemService.getAll(Criterion.Type); + } + + public PreferenceMatrix getMatrix(ProblemElement e) { + return eMatrix.get(e); + } + + public ArrayList getWeights(ProblemElement e) { + + weights.clear(); + + for (ProblemElement pe : getExperts()) { + PreferenceMatrix matrix = eMatrix.get(pe); + double[] arrd = EigenHelper.GetNormalizedEigenVector(matrix.getAHPMatrix().getValues()); + for (double d : arrd) + weights.add(pe, d); + } + + exportData("ahpCriterionWeights",weights); + exportData("criterionWeights",weights); + return weights.get(e); + } + +} diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.classpath b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.polyglot.META-INF new file mode 100644 index 0000000..18718aa --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.bestworst.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.project b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.project new file mode 100644 index 0000000..7b303c2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.bestworst.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362643 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6e252f0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.common.phase.collectweights.bestworst.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights.bestworst.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.method.common.phase.collectweights.bestworst, + flintstones.entity.method.phase, + flintstones.model.ui.service, + org.eclipse.swt, + flintstones.helper.ui, + flintstones.entity.problemelement, + org.eclipse.nebula.widgets.opal.commons, + org.apache.commons.lang, + flintstones.entity.problemelement.ui diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/build.properties b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/plugin.xml new file mode 100644 index 0000000..c74e26e --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/src/flintstones/method/common/phase/collectweights/bestworst/ui/BestWorstUI.java b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/src/flintstones/method/common/phase/collectweights/bestworst/ui/BestWorstUI.java new file mode 100644 index 0000000..eef18e8 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst.ui/src/flintstones/method/common/phase/collectweights/bestworst/ui/BestWorstUI.java @@ -0,0 +1,273 @@ +package flintstones.method.common.phase.collectweights.bestworst.ui; + + +import java.util.ArrayList; + +import org.eclipse.nebula.widgets.opal.commons.SWTGraphicUtil; +import org.eclipse.swt.SWT; +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.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +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.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.method.common.phase.collectweights.bestworst.BestWorstModel; +import flintstones.model.ui.service.UiService; + +public class BestWorstUI extends PhaseMethodUI implements IProblemElementChangedListener { + + BestWorstModel model; + + ProblemElement currentItem; + + ProblemElementSelector selector; + + Combo bestCombo; + WCollector bestCollector; + + Combo worstCombo; + WCollector worstCollector; + + Composite leftInner; + Composite rightInner; + + @Override + public void init() { + model = (BestWorstModel) this.getModel(); + + Composite base = this.getBaseComposite(); + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + selector = new ProblemElementSelector(base, model.getExperts()); + selector.setListener(this); + selector.setText(Expert.Type); + currentItem = model.getExperts()[0]; + + Composite comparisons = new Composite(base, SWT.NONE); + UiService.setGridLayout(comparisons, 2, true); + UiService.setGridDataAuto(comparisons); + + Composite left = new Composite(comparisons,0); + UiService.setGridLayout(left, 1); + UiService.setGridDataAuto(left); + + Composite right = new Composite(comparisons,0); + UiService.setGridLayout(right, 1); + UiService.setGridDataAuto(right); + + // Left + Label bestLabel = new Label(left,0); + bestLabel.setText("The BEST criterion is: "); + UiService.setFont(bestLabel, UiService.FONT_SECTION_TITLE); + + bestCombo = new Combo(left, SWT.READ_ONLY); + GridData gd = UiService.setGridData(bestCombo, 9, -1, true, false); + gd.verticalIndent = 10; + + Label bestLabel2 = new Label(left,0); + bestLabel2.setText("Best -> Others: (1-9) "); + UiService.setFont(bestLabel2, UiService.FONT_SECTION_TITLE); + gd = UiService.setGridData(bestLabel2, 9, 9, true, false); + gd.verticalIndent = 10; + + leftInner = new Composite(left,0); + UiService.setGridLayout(leftInner, 1); + UiService.setGridDataAuto(leftInner); + + bestCollector = new WCollector(leftInner); + + // Right + Label worstLabel = new Label(right,0); + worstLabel.setText("The WORST criterion is: "); + UiService.setFont(worstLabel, UiService.FONT_SECTION_TITLE); + + worstCombo = new Combo(right, SWT.READ_ONLY ); + gd = UiService.setGridData(worstCombo, 9, -1, true, false); + gd.verticalIndent = 10; + + Label worstLabel2 = new Label(right,0); + worstLabel2.setText("Others -> Worst: (1-9) "); + UiService.setFont(worstLabel2, UiService.FONT_SECTION_TITLE); + gd = UiService.setGridData(worstLabel2, 9, 9, true, false); + gd.verticalIndent = 10; + + rightInner = new Composite(right,0); + UiService.setGridLayout(rightInner, 1); + UiService.setGridDataAuto(rightInner); + + worstCollector = new WCollector(rightInner); + + // Status + SWTGraphicUtil.disableAllChildrenWidgets(leftInner); + SWTGraphicUtil.disableAllChildrenWidgets(rightInner); + + // Data + String[] headers = model.getCriteriaNames(); + + bestCombo.setItems(headers); + worstCombo.setItems(headers); + + // Listeners + bestCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + + SWTGraphicUtil.enableAllChildrenWidgets(leftInner); + bestCollector.setHeaders(headers); + + } + + }); + + worstCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + + SWTGraphicUtil.enableAllChildrenWidgets(rightInner); + worstCollector.setHeaders(headers); + } + + }); + + bestCollector.setBeforeOperationListener(getCheckListener(true)); + worstCollector.setBeforeOperationListener(getCheckListener(false)); + + bestCollector.setChangeListener(getChangeListener(true)); + worstCollector.setChangeListener(getChangeListener(false)); + + Button execute = new Button(base, SWT.NONE); + UiService.setGridData(execute, 9, 9, true, false); + execute.setText("Execute"); + execute.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.execute(); + } + }); + } + + private WItemChanged getChangeListener(boolean best) { + return new WItemChanged() { + + @Override + public void onWidgetChange() { + ProblemElement[] subItems = model.getCriteria(); + + boolean status; + if(best) + status = addBestComparisons(subItems); + else + status = addWorstComparsions(subItems); + + + sendRefresh(); + + selector.setStatus(currentItem, status); + } + }; + } + + private boolean addBestComparisons(ProblemElement[] subItems) { + String[] data = bestCollector.getData(); + for (int i = 0; i < subItems.length && i < data.length; i++) + model.setBestComparison(currentItem, subItems[i], data[i]); + + return data.length == subItems.length; + } + + private boolean addWorstComparsions(ProblemElement[] subItems) { + String[] data = worstCollector.getData(); + for (int i = 0; i < subItems.length && i < data.length; i++) + model.setWorstComparison(currentItem, subItems[i], data[i]); + + return data.length == subItems.length; + } + + private WItemBeforeOperation getCheckListener(boolean best) { + return new WItemBeforeOperation() { + + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + + if(operationType.equals(WEvent.ADD)) { + + WCollector collector = (best) ? bestCollector : worstCollector; + if(collector.getData().length == model.getCriteriaNames().length) + return false; + + int val = -1; + try{ + val = Integer.parseInt(before); + } catch(NumberFormatException e) { + + } + + if(val >= 1 && val <= 9) + return true; + return false; + } + + return true; + + } + }; + } + + @Override + public void problemElementChanged(ProblemElement pe) { + ProblemElement[] subItems = model.getCriteria(); + + currentItem = pe; + + loadBestComparisons(subItems); + loadWorstComparisons(subItems); + } + + private void loadBestComparisons(ProblemElement[] subItems) { + ArrayList data = new ArrayList<>(); + + for (int i = 0; i < subItems.length; i++) { + String value = model.getBerstComparison(currentItem, subItems[i]); + if (value != null) + data.add(value); + } + + bestCollector.setValues(data); + } + + private void loadWorstComparisons(ProblemElement[] subItems) { + ArrayList data = new ArrayList<>(); + + for (int i = 0; i < subItems.length; i++) { + String value = model.getWorstComparison(currentItem, subItems[i]); + if (value != null) + data.add(value); + } + + worstCollector.setValues(data); + } + + @Override + public void refresh() { + } + + @Override + protected boolean isForwardEnabled() { + return bestCollector.getData().length == model.getCriteriaNames().length && worstCollector.getData().length == model.getCriteriaNames().length; + } + +} diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/.classpath b/bundles/flintstones.method.common.phase.collectweights.bestworst/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.bestworst/.polyglot.META-INF new file mode 100644 index 0000000..2aefbee --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.bestworst + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bestworst + diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/.project b/bundles/flintstones.method.common.phase.collectweights.bestworst/.project new file mode 100644 index 0000000..0549c15 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.bestworst + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362643 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.bestworst/META-INF/MANIFEST.MF new file mode 100644 index 0000000..cdd6717 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Bestworst +Bundle-SymbolicName: flintstones.method.common.phase.collectweights.bestworst;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights.bestworst +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.method.common.phase.collectweights, + flintstones.model.problemelement.service, + flintstones.entity.problemelement, + flintstones.engine.R, + javax.inject, + org.eclipse.osgi, + org.eclipse.equinox.common, + org.eclipse.core.runtime, + flintstones.helper.data +Export-Package: flintstones.method.common.phase.collectweights.bestworst diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/build.properties b/bundles/flintstones.method.common.phase.collectweights.bestworst/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.bestworst/plugin.xml new file mode 100644 index 0000000..2e4a147 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/plugin.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/helpers.R b/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/helpers.R new file mode 100644 index 0000000..6cfdf75 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/helpers.R @@ -0,0 +1,7 @@ +assert <- function(expression, message) +{ + if(!all(expression)) + { + stop(if(is.null(message)) "Error" else message) + } +} diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/model.R b/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/model.R new file mode 100644 index 0000000..cc5d03f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/model.R @@ -0,0 +1,181 @@ +validateData <- function(bestToOthers, othersToWorst, criteriaNames){ + assert(length(bestToOthers) > 1, "Length of the best-to-others or others-to-worst vector should have at least 2 elements.") + assert(length(bestToOthers) == length(othersToWorst), "Lengths of best-to-others and others-to-worst vectors must be the same.") + assert(length(bestToOthers) == length(criteriaNames), "Lengths of best-to-others and criteriaNames must be the same.") + assert(1 %in% bestToOthers, "best-to-others vector should contain number 1.") + assert(1 %in% othersToWorst, "others-to-worst vector should contain number 1.") + assert(all(bestToOthers >= 1) && all(bestToOthers <= 9), "Numbers in best-to-others vector should be in range <1, 9>.") + assert(all(othersToWorst >= 1) && all(othersToWorst <= 9), "Numbers in others-to-worst vector should be in range <1, 9>.") + bestToOthersOneIndex <- match(1, bestToOthers) + othersToWorstOneIndex <- match(1, othersToWorst) + assert(!is.na(bestToOthersOneIndex) && !is.na(othersToWorstOneIndex), "best-to-others and others-to-worst vectors must contain number `1`.") + list(bestToOthers = bestToOthers, othersToWorst = othersToWorst, criteriaNames = criteriaNames) +} + +isConsistent <- function(model){ + worstCriterionIndex <- match(1, model$othersToWorst) + bestOverWorstPreferenceValue <- model$bestToOthers[worstCriterionIndex] + + # a_bj x a_jw = a_bw for all j + list(isConsistent = all(model$bestToOthers*model$othersToWorst == bestOverWorstPreferenceValue), a_bw = bestOverWorstPreferenceValue) +} +# tries to combine constraint, if constraint already belongs to the constraints set then +# it resturns constraints and a flag that indicates that constraints' state hasn't been changed +combineConstraints <- function(constraints, constraint){ + assert(!is.null(constraint$lhs), "Constraint should contain lhs vector") + assert(!is.null(constraint$rhs), "Constraint should contain rhs vector") + assert(!is.null(constraint$dir), "Constraint should contain direction sign") + assert(constraint$dir %in% c("<=", "==", ">="), "Constraint should be one of the following `<=, ==, >=`") + index <- length(constraints)+1 + #return when such constraint is already in constraints list + for(x in constraints){ + if( length(setdiff(x, constraint)) == 0 ){ + return(list(constraints = constraints, added = FALSE)) + } + } + + constraints[[index]] <- constraint + list(constraints = constraints, added = TRUE) +} + +# complementary constraint that should be added in case of abs +absConstraint <- function(constraint){ + lhs <- constraint$lhs + lhs[length(lhs)] <- lhs[length(lhs)] * -1 + abs <- list(lhs = lhs, + dir = ifelse(constraint$dir == "<=", ">=", ifelse(constraint$dir == ">=", "<=", "==")), + rhs = constraint$rhs * (-1)) +} + +# creates constraints, for each j, for w_b - a_bj*w_j or for w_j-a_jw*w_w +# first equation referes to the best-to-others vector, the second one to the others-to-worst vector +createBaseModelConstraints <- function(model, constraints, vectorType, dir, rhs = 0, ksiIndexValue = 0){ + assert(vectorType %in% c("best", "worst"), "vectorType should be either 'best' or 'worst'.") + vector <- if(vectorType == "best") model$bestToOthers else model$othersToWorst + + # weight that has a number 1 on its index in the vector + # should be ommited + weightWithOneIndex <- match(1, vector) + + # number of added constraints is + # useful for creating constraints opposite to these ones + numberOfAddedConstraints <-0 + + for(j in seq(length(vector))){ + if(j != weightWithOneIndex){ + lhs <- rep(0, length(vector) + 1) + + if(vectorType == "best"){ + # add w_b - a_bj*w_j = 0 + lhs[weightWithOneIndex] <- 1 + lhs[j] <- -vector[j] + } else { + # add w_j - a_jw*w_w = 0 + lhs[weightWithOneIndex] <- -vector[j] + lhs[j] <- 1 + } + + + lhs[model$ksiIndex] <- ksiIndexValue + result <- combineConstraints(constraints, list(lhs = lhs, dir = dir, rhs = rhs)) + if(result$added){ + constraints <- result$constraints + numberOfAddedConstraints <- numberOfAddedConstraints + 1 + } + } + } + list(constraints = constraints, numberOfAddedConstraints = numberOfAddedConstraints) +} + +#constraints for weights' sum and their minimal value (w >= 0) +buildBasicConstraints <- function(model){ + # n variables for weights, 1 for ksi index + numberOfVariables <- length(model$bestToOthers) + 1 + + lhs <- rep(0, numberOfVariables) + # sum up all weights to 1 + lhs[1:length(lhs)-1] <- 1 + dir <- "==" + rhs <- 1 + + constraints <- list() + constraints <- combineConstraints(constraints, list(lhs = lhs, dir = dir, rhs = rhs))$constraints + # all weights must be >= 0 + for(j in seq(length(model$bestToOthers))){ + lhs <- rep(0, numberOfVariables) + lhs[j] <- 1 + constraints <- combineConstraints(constraints, list(lhs = lhs, direction = ">=", rhs = 0))$constraints + } + constraints +} + +addConstraintsFromResult <- function(constraints, result){ + if(result$numberOfAddedConstraints > 0){ + constraints <- result$constraints + # add constraints that stem from removing abs + # take only result$numberOfAddedConstraints constraints that has just been added (there may have been some duplicates) + # and multiply them by -1 + constraintsToScale <- tail(constraints, n=result$numberOfAddedConstraints) + lapply(constraintsToScale, function(x){ + constraints <<- combineConstraints(constraints, absConstraint(x))$constraints # '<<-' refers to outer scope + }) + } + constraints +} + +constraintsListToMatrix <- function(constraints){ + result <- list() + #format constraints + result$lhs <- t(sapply(constraints, function(x){ + x$lhs + })) + result$dir <- sapply(constraints, function(x){ + x$dir + }) + result$rhs <- unlist(sapply(constraints, function(x){ + x$rhs + })) + result +} + +createModelsObjective <- function(model, objectiveIndex, objectiveValue = 1){ + objective <- rep(0, length(model$bestToOthers) + 1) + objective[objectiveIndex] <- objectiveValue + objective +} + +buildModel <- function(bestToOthers, othersToWorst, criteriaNames){ + model <- validateData(bestToOthers, othersToWorst, criteriaNames) + consistency <- isConsistent(model) + model$isConsistent <- consistency$isConsistent + model$a_bw <- consistency$a_bw + + #weights' sum and weights' limit value (w >= 0) + constraints <- buildBasicConstraints(model) + + # ksi index + model$ksiIndex <- length(model$bestToOthers)+1 + + if(model$isConsistent){ + #add best-to-others constraints + result <- createBaseModelConstraints(model, constraints, vectorType = "best", dir = "==") + if(result$numberOfAddedConstraints > 0){ + constraints <- result$constraints + } + } else { + #add best-to-others constraints + result <- createBaseModelConstraints(model, constraints, vectorType = "best", dir = "<=", ksiIndexValue = -1) + constraints <- addConstraintsFromResult(constraints, result) + + #add others-to-worst constraints + result <- createBaseModelConstraints(model, constraints, vectorType = "worst", dir = "<=", ksiIndexValue = -1) + constraints <- addConstraintsFromResult(constraints, result) + } + + model$constraints = constraintsListToMatrix(constraints) + model$objective <- createModelsObjective(model, model$ksiIndex) + #minimize objective's value by default + model$maximize <- FALSE + + model +} diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/solver.R b/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/solver.R new file mode 100644 index 0000000..8e71977 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/r_files/solver.R @@ -0,0 +1,38 @@ +#' calculateWeights +#' +#' Implementation based on https://doi.org/10.1016/j.omega.2015.12.001. +#' Calculates weights of the criteria using a linear model. +#' Steps: +#' 1. Build model (consists of validating model and constructing necessary constraints for LP problem). +#' 2. Solve LP problem. +#' 3. Calculate consistency ratio. +#' +#' @name calculateWeights +#' @param criteriaNames Names of the criteria +#' @param bestToOthers Vector of pairwise comparisons. Best criterion should be 1, others <2, 9>. +#' @param othersToWorst Vector of pairwise comparisons. Worst criterion should be 1, others <2, 9>. +#' @return Result that consist of \code{criteriaNames}, \code{criteriaWeights}, \code{consistencyRatio} and a model that was used to calculate weights. +#' @examples +#' criteriaNames <- c("quality", "price", "comfort", "safety", "style") +#' bestToOthers <- c(2, 1, 4, 2, 8) +#' othersToWorst <- c(4, 8, 2, 4, 1) +#' calculateWeights(criteriaNames, bestToOthers, othersToWorst) +#' @import Rglpk +#' @export +calculateWeights <- function(criteriaNames, bestToOthers, othersToWorst){ + model <- buildModel(bestToOthers, othersToWorst, criteriaNames) + #const values that are listed in the article + consistencyIndex <- c(0, .44, 1.0, 1.63, 2.3, 3., 3.73, 4.47, 5.23) + + #unique optimal solution + result <- solveLP(model) + weights <- result$solution[1:model$ksiIndex-1] + consistencyRatio <- result$solution[model$ksiIndex] / consistencyIndex[as.integer(model$a_bw)] + + result <- list(criteriaNames = criteriaNames, criteriaWeights = weights, consistencyRatio = consistencyRatio) + list(result = result, model = model) +} + +solveLP <- function(model){ + Rglpk_solve_LP(model$objective, model$constraints$lhs, model$constraints$dir, model$constraints$rhs, max = model$maximize) +} diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/BestWorstModel.java b/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/BestWorstModel.java new file mode 100644 index 0000000..3ea52d3 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/BestWorstModel.java @@ -0,0 +1,170 @@ +package flintstones.method.common.phase.collectweights.bestworst; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.Rengine; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.Pair; +import flintstones.method.common.phase.collectweights.bestworst.code.RFunctions; +import flintstones.method.common.phase.collectweights.bestworst.exception.ExecutionException; +import flintstones.model.problemelement.service.IProblemElementService; + +public class BestWorstModel extends PhaseMethod { + + Rengine rengine; + + @Inject + IProblemElementService problemService; + + HashMap criterionMap = new HashMap<>(); + HashMap, String> bestMap = new HashMap<>(); + HashMap, String> worstMap = new HashMap<>(); + HashMap criteriaWeights = new HashMap<>(); + HashMap consistencyRatios = new HashMap<>(); + + @Override + public String getName() { + return "Best Worst"; + } + + @Override + public boolean canBeExecuted() { + return true; + } + + public void execute() { + if(rengine == null) + rengine = new Rengine(new String[] { "--no-save" }, false, null); + + evaluateFunctions(); + + //load library + rengine.eval("library(Rglpk)"); + rengine.eval("criteriaNames <- " + formatCriteriaNames()); + + for(ProblemElement exp: this.getExperts()) { + evalBestWorstVectors(exp); + evalResult(); + computeCriteriaWeights(exp); + computeConsistencyRatio(exp); + } + + rengine.end(); + rengine.rniStop(0); + } + + private void evalResult() { + REXP result = rengine.eval("solution <- try(calculateWeights(criteriaNames, bestToOthers, worstToOthers))"); + REXP rengineSolution = rengine.eval("class(solution)"); + if ((rengineSolution.asString()).equals("try-error")) + new ExecutionException(result.asString()).getMessage(); + } + + private String formatCriteriaNames() { + StringBuilder sb = new StringBuilder("c("); + + String[] criteriaNames = getCriteriaNames(); + for(String name: criteriaNames) + sb.append("'" + name + "'" + ","); + + sb.deleteCharAt(sb.length() - 1); + sb.append(")"); + + return sb.toString(); + } + + private void evalBestWorstVectors(ProblemElement exp) { + StringBuilder sbBest = new StringBuilder("bestToOthers <- c("); + StringBuilder sbWorst = new StringBuilder("worstToOthers <- c("); + + for(ProblemElement crit: getCriteria()) { + sbBest.append(bestMap.get(new Pair(exp, crit))).append(","); + sbWorst.append(worstMap.get(new Pair(exp, crit))).append(","); + } + + sbBest.deleteCharAt(sbBest.length() - 1).append(")"); + sbWorst.deleteCharAt(sbWorst.length() - 1).append(")"); + + rengine.eval(sbBest.toString()); + rengine.eval(sbWorst.toString()); + } + + private void computeCriteriaWeights(ProblemElement expert) { + String weights = rengine.eval("print(solution$result$criteriaWeights)").toString(); + weights = weights.substring(weights.indexOf("(") + 1, weights.length() - 2); + String[] splitWeights = weights.split(","); + + ArrayList criteriaWeights = new ArrayList<>(); + for(String weight: splitWeights) + criteriaWeights.add(Double.parseDouble(weight)); + + this.criteriaWeights.put(expert, criteriaWeights.toArray(new Double[criteriaWeights.size()])); + } + + private void computeConsistencyRatio(ProblemElement exp) { + Double consistency_ratio = rengine.eval("print(solution$result$consistencyRatio)").asDouble(); + consistencyRatios.put(exp, consistency_ratio); + } + + public String[] getCriteriaNames() { + ProblemElement[] criteria = problemService.getAll(Criterion.Type); + Arrays.stream(criteria).forEach(k -> criterionMap.put(k.getName(),k)); + String[] arr = criterionMap.keySet().toArray(new String[0]); + Arrays.sort(arr); + return arr; + } + + public ProblemElement[] getCriteria() { + return problemService.getAll(Criterion.Type); + } + + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + public void setBestComparison(ProblemElement expert, ProblemElement criterion, String assessment) { + bestMap.put(new Pair(expert, criterion), assessment); + } + + public String getBerstComparison(ProblemElement expert, ProblemElement criterion) { + return bestMap.get(new Pair(expert, criterion)); + } + + public void setWorstComparison(ProblemElement expert, ProblemElement criterion, String assessment) { + worstMap.put(new Pair(expert, criterion), assessment); + } + + public String getWorstComparison(ProblemElement expert, ProblemElement criterion) { + return worstMap.get(new Pair(expert, criterion)); + } + + public Double getConsistencyRation(ProblemElement expert) { + return consistencyRatios.get(expert); + } + + private void evaluateFunctions() { + + rengine.eval(RFunctions.VALIDATE_DATA); + rengine.eval(RFunctions.IS_CONSISTENT); + rengine.eval(RFunctions.COMBINE_CONSTRAINTS); + rengine.eval(RFunctions.ABS_CONSTRAINT); + rengine.eval(RFunctions.CREATE_BASE_MODEL_CONSTRAINTS); + rengine.eval(RFunctions.BUILD_BASIC_CONSTRAINTS); + rengine.eval(RFunctions.ADD_CONSTRAINTS_FROM_RESULT); + rengine.eval(RFunctions.CONSTRAINTS_LIST_TO_MATRIX); + rengine.eval(RFunctions.CREATE_MODELS_OBJECTIVE); + rengine.eval(RFunctions.BUILD_MODEL); + + rengine.eval(RFunctions.CALCULATE_WEIGHTS); + rengine.eval(RFunctions.SOLVE_LP); + } +} diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/code/RFunctions.java b/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/code/RFunctions.java new file mode 100644 index 0000000..5913545 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/code/RFunctions.java @@ -0,0 +1,164 @@ +package flintstones.method.common.phase.collectweights.bestworst.code; + +public class RFunctions { + + public static final String VALIDATE_DATA = "validateData <- function(bestToOthers, othersToWorst, criteriaNames){\n" + + "bestToOthersOneIndex <- match(1, bestToOthers)\n" + + "othersToWorstOneIndex <- match(1, othersToWorst)\n" + + "list(bestToOthers = bestToOthers, othersToWorst = othersToWorst, criteriaNames = criteriaNames)\n" + + "}"; + + public static final String IS_CONSISTENT = "isConsistent <- function(model){\n" + + "worstCriterionIndex <- match(1, model$othersToWorst)\n" + + "bestOverWorstPreferenceValue <- model$bestToOthers[worstCriterionIndex]\n" + + "\n" + + "list(isConsistent = all(model$bestToOthers*model$othersToWorst == bestOverWorstPreferenceValue), a_bw = bestOverWorstPreferenceValue)\n" + + "}"; + + public static final String COMBINE_CONSTRAINTS = "combineConstraints <- function(constraints, constraint){\n" + + "index <- length(constraints)+1\n" + + "for(x in constraints){\n" + + "if(length(setdiff(x, constraint)) == 0 ){\n" + + "return(list(constraints = constraints, added = FALSE))\n" + + "}\n" + + "}\n" + + "\n" + + "constraints[[index]] <- constraint\n" + + "list(constraints = constraints, added = TRUE)\n" + + "}"; + + public static final String ABS_CONSTRAINT = "absConstraint <- function(constraint){\n" + + "lhs <- constraint$lhs\n" + + "lhs[length(lhs)] <- lhs[length(lhs)] * -1\n" + + "abs <- list(lhs = lhs,\n" + + "dir = ifelse(constraint$dir == \"<=\", \">=\", ifelse(constraint$dir == \">=\", \"<=\", \"==\")),\n" + + " rhs = constraint$rhs * (-1))\n" + + "}"; + + public static final String CREATE_BASE_MODEL_CONSTRAINTS = "createBaseModelConstraints <- function(model, constraints, vectorType, dir, rhs = 0, ksiIndexValue = 0){\n" + + "vector <- if(vectorType == \"best\") model$bestToOthers else model$othersToWorst\n" + + "\n" + + "weightWithOneIndex <- match(1, vector)\n" + + "\n" + + "numberOfAddedConstraints <-0\n" + + "\n" + + "for(j in seq(length(vector))){\n" + + "if(j != weightWithOneIndex){\n" + + "lhs <- rep(0, length(vector) + 1)\n" + + "\n" + + "if(vectorType == \"best\"){\n" + + "lhs[weightWithOneIndex] <- 1\n" + + "lhs[j] <- -vector[j]\n" + + "} else {\n" + + "lhs[weightWithOneIndex] <- -vector[j]\n" + + "lhs[j] <- 1\n" + + "}\n" + + "\n" + + "\n" + + "lhs[model$ksiIndex] <- ksiIndexValue\n" + + "result <- combineConstraints(constraints, list(lhs = lhs, dir = dir, rhs = rhs))\n" + + "if(result$added){\n" + + "constraints <- result$constraints\n" + + "numberOfAddedConstraints <- numberOfAddedConstraints + 1\n" + + "}\n" + + "}\n" + + "}\n" + + "list(constraints = constraints, numberOfAddedConstraints = numberOfAddedConstraints)\n" + + "}\n"; + + public static final String BUILD_BASIC_CONSTRAINTS = "buildBasicConstraints <- function(model){\n" + + "numberOfVariables <- length(model$bestToOthers) + 1\n" + + "\n" + + "lhs <- rep(0, numberOfVariables)\n" + + "lhs[1:length(lhs)-1] <- 1\n" + + "dir <- \"==\"\n" + + "rhs <- 1\n" + + "\n" + + "constraints <- list()\n" + + "constraints <- combineConstraints(constraints, list(lhs = lhs, dir = dir, rhs = rhs))$constraints\n" + + "for(j in seq(length(model$bestToOthers))){\n" + + "lhs <- rep(0, numberOfVariables)\n" + + "lhs[j] <- 1\n" + + "constraints <- combineConstraints(constraints, list(lhs = lhs, direction = \">=\", rhs = 0))$constraints\n" + + "}\n" + + "constraints\n" + + "}"; + + public static final String ADD_CONSTRAINTS_FROM_RESULT = "addConstraintsFromResult <- function(constraints, result){\n" + + "if(result$numberOfAddedConstraints > 0){\n" + + "constraints <- result$constraints\n" + + "constraintsToScale <- tail(constraints, n=result$numberOfAddedConstraints)\n" + + "lapply(constraintsToScale, function(x){\n" + + "constraints <<- combineConstraints(constraints, absConstraint(x))$constraints # '<<-' refers to outer scope\n" + + "})\n" + + "}\n" + + "constraints\n" + + "}"; + + public static final String CONSTRAINTS_LIST_TO_MATRIX = "constraintsListToMatrix <- function(constraints){\n" + + "result <- list()\n" + + "result$lhs <- t(sapply(constraints, function(x){\n" + + "x$lhs\n" + + "}))\n" + + "result$dir <- sapply(constraints, function(x){\n" + + "x$dir\n" + + "})\n" + + "result$rhs <- unlist(sapply(constraints, function(x){\n" + + "x$rhs\n" + + "}))\n" + + "result\n" + + "}"; + + public static final String CREATE_MODELS_OBJECTIVE = "createModelsObjective <- function(model, objectiveIndex, objectiveValue = 1){\n" + + "objective <- rep(0, length(model$bestToOthers) + 1)\n" + + "objective[objectiveIndex] <- objectiveValue\n" + + "objective\n" + + "}"; + + public static final String BUILD_MODEL = "buildModel <- function(bestToOthers, othersToWorst, criteriaNames){\n" + + "model <- validateData(bestToOthers, othersToWorst, criteriaNames)\n" + + "consistency <- isConsistent(model)\n" + + "model$isConsistent <- consistency$isConsistent\n" + + "model$a_bw <- consistency$a_bw\n" + + "\n" + + "constraints <- buildBasicConstraints(model)\n" + + "\n" + + "model$ksiIndex <- length(model$bestToOthers)+1\n" + + "\n" + + "if(model$isConsistent){\n" + + "result <- createBaseModelConstraints(model, constraints, vectorType = \"best\", dir = \"==\")\n" + + "if(result$numberOfAddedConstraints > 0){\n" + + "constraints <- result$constraints\n" + + "}\n" + + "} else {\n" + + "result <- createBaseModelConstraints(model, constraints, vectorType = \"best\", dir = \"<=\", ksiIndexValue = -1)\n" + + "constraints <- addConstraintsFromResult(constraints, result)\n" + + "\n" + + "result <- createBaseModelConstraints(model, constraints, vectorType = \"worst\", dir = \"<=\", ksiIndexValue = -1)\n" + + "constraints <- addConstraintsFromResult(constraints, result)\n" + + "}\n" + + "\n" + + "model$constraints = constraintsListToMatrix(constraints)\n" + + "model$objective <- createModelsObjective(model, model$ksiIndex)\n" + + "model$maximize <- FALSE\n" + + "\n" + + "model\n" + + "}"; + + public static final String CALCULATE_WEIGHTS = "calculateWeights <- function(criteriaNames, bestToOthers, othersToWorst){\n" + + "model <- buildModel(bestToOthers, othersToWorst, criteriaNames)\n" + + "consistencyIndex <- c(0, .44, 1.0, 1.63, 2.3, 3., 3.73, 4.47, 5.23)\n" + + "\n" + + "result <- solveLP(model)\n" + + "weights <- result$solution[1:model$ksiIndex-1]\n" + + "consistencyRatio <- result$solution[model$ksiIndex] / consistencyIndex[as.integer(model$a_bw)]\n" + + "\n" + + "result <- list(criteriaNames = criteriaNames, criteriaWeights = weights, consistencyRatio = consistencyRatio)\n" + + "list(result = result, model = model)\n" + + "}"; + + public static final String SOLVE_LP = "solveLP <- function(model){\n" + + "Rglpk_solve_LP(model$objective, model$constraints$lhs, model$constraints$dir, model$constraints$rhs, max = model$maximize)\n" + + "}"; + +} diff --git a/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/exception/ExecutionException.java b/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/exception/ExecutionException.java new file mode 100644 index 0000000..31898bc --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.bestworst/src/flintstones/method/common/phase/collectweights/bestworst/exception/ExecutionException.java @@ -0,0 +1,20 @@ +package flintstones.method.common.phase.collectweights.bestworst.exception; + +public class ExecutionException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + private String message; + + public ExecutionException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return "Execution failed: " + this.message; + } +} diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.classpath b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.polyglot.META-INF new file mode 100644 index 0000000..b2342db --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.criterion.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.project b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.project new file mode 100644 index 0000000..16904d8 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.criterion.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362645 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ae7a9e3 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.common.phase.collectweights.criterion.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights.criterion.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.model.method.phase.service, + flintstones.model.problemelement.service, + javax.inject, + org.eclipse.swt, + flintstones.helper.ui, + flintstones.entity.problemelement.ui, + flintstones.entity.problemelement, + flintstones.helper.data, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.method.common.phase.collectweights.criterion, + flintstones.helper.debug, + org.eclipse.e4.core.services diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/build.properties b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/plugin.xml new file mode 100644 index 0000000..9117e83 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/CollectWeightsCriterionUI.java b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/CollectWeightsCriterionUI.java new file mode 100644 index 0000000..47741f5 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/CollectWeightsCriterionUI.java @@ -0,0 +1,172 @@ +package flintstones.method.common.phase.collectweights.criterion.ui; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +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.common.phase.collectweights.criterion.CollectWeightsCriterionModel; +import flintstones.method.common.phase.collectweights.criterion.ui.messages.Messages; +import flintstones.model.ui.service.UiService; + +import java.util.ArrayList; +import java.util.Arrays; + +import javax.inject.Inject; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class CollectWeightsCriterionUI extends PhaseMethodUI + implements IProblemElementChangedListener, WItemChanged, WItemBeforeOperation, WItemOperation { + + @Inject + @Translation + Messages messages; + + CollectWeightsCriterionModel model; + + Composite phaseBase; + + // Components + ProblemElementSelector selector; + WCollector collector; + Label adviceLabel; + + ProblemElement currentItem; + + + @Override + public void init() { + model = (CollectWeightsCriterionModel) this.getModel(); + Composite base = this.getBaseComposite(); + + + createControls(base); + } + + @Override + public void refresh() { + } + + @Override + protected boolean isForwardEnabled() { + return model.isFilled(); + } + + private void createControls(Composite base) { + + ProblemElement[] items = model.getExperts(); + ProblemElement[] subItems = model.getCriteria(); + currentItem = items[0]; + + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + Composite row = new Composite(base, 0); + UiService.setGridLayout(row, 3, false); + UiService.setGridData(row, 9, -1, true, false); + + selector = new ProblemElementSelector(row, items); + selector.setListener(this); + selector.setText(Expert.Type); + + adviceLabel = new Label(row, 0); + adviceLabel.setText(messages.Condition); //$NON-NLS-1$ + + Composite row2 = new Composite(base, 0); + UiService.setGridLayout(row2, 1, true); + UiService.setGridDataAuto(row2); + + collector = new WCollector(row2); + collector.setHeaders(Arrays.stream(subItems).map(k -> k.getName()).toArray(String[]::new)); + collector.setChangeListener(this); + collector.setBeforeOperationListener(this); + collector.setOperationListener(this); + + } + + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + + ProblemElement[] subItems = model.getCriteria(); + + if (operationType.equals(WEvent.ADD)) { + + String[] data = collector.getData(); + + // Same lenth, limit reached + if(data.length == subItems.length) + return false; + + // Lets sum + double sum = 0.0; + for(String value : data) { + sum += Double.parseDouble(value); + } + sum += DoubleHelper.NormalizeZeroToOne(before); + + // When the last element in introduced must sum 1 + if(data.length == subItems.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; + } + + @Override + public void onWidgetChange() { + ProblemElement[] subItems = model.getCriteria(); + + String[] data = collector.getData(); + for (int i = 0; i < subItems.length && i < data.length; i++) { + model.addWeight(currentItem, subItems[i], DoubleHelper.ParseDouble(data[i])); + } + + sendRefresh(); + + boolean status = data.length == subItems.length; + selector.setStatus(currentItem, status); + + } + + @Override + public void problemElementChanged(ProblemElement pe) { + + ProblemElement[] subItems = model.getCriteria(); + + currentItem = pe; + + ArrayList data = new ArrayList<>(); + + for (int i = 0; i < subItems.length; i++) { + Double value = model.getWeight(currentItem, subItems[i]); + if (value != null) + data.add(value + ""); //$NON-NLS-1$ + } + + collector.setValues(data); + } + + @Override + public String getModifiedValue(WEvent operationType, String before, String after) { + if (operationType.equals(WEvent.ADD)) { + return DoubleHelper.NormalizeZeroToOne(before)+""; //$NON-NLS-1$ + } + return after; + + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/Messages.java b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/Messages.java new file mode 100644 index 0000000..0a975e0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/Messages.java @@ -0,0 +1,5 @@ +package flintstones.method.common.phase.collectweights.criterion.ui.messages; + +public class Messages { + public String Condition; +} diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/messages.properties b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/messages.properties new file mode 100644 index 0000000..02f4fa5 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/messages.properties @@ -0,0 +1 @@ +Condition=The values must add up to one. It is possible to introduce positive integers as shortcut. diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/messages_es.properties b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/messages_es.properties new file mode 100644 index 0000000..a48e5ae --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion.ui/src/flintstones/method/common/phase/collectweights/criterion/ui/messages/messages_es.properties @@ -0,0 +1 @@ +Condition=Los valores deben sumar exactamente 1. Es posible introducir nmeros enteros como atajo. diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/.classpath b/bundles/flintstones.method.common.phase.collectweights.criterion/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.criterion/.polyglot.META-INF new file mode 100644 index 0000000..dfb2699 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.criterion + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Basic + diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/.project b/bundles/flintstones.method.common.phase.collectweights.criterion/.project new file mode 100644 index 0000000..29404ac --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.criterion + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362644 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.criterion/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7ecb462 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Basic +Bundle-SymbolicName: flintstones.method.common.phase.collectweights.criterion;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights.criterion +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.helper.data, + flintstones.entity.problemelement, + flintstones.method.common.phase.collectweights, + flintstones.model.problemelement.service, + javax.inject +Export-Package: flintstones.method.common.phase.collectweights.criterion diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/build.properties b/bundles/flintstones.method.common.phase.collectweights.criterion/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.criterion/plugin.xml new file mode 100644 index 0000000..1ea2a1f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/plugin.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.criterion/src/flintstones/method/common/phase/collectweights/criterion/CollectWeightsCriterionModel.java b/bundles/flintstones.method.common.phase.collectweights.criterion/src/flintstones/method/common/phase/collectweights/criterion/CollectWeightsCriterionModel.java new file mode 100644 index 0000000..8da06e9 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.criterion/src/flintstones/method/common/phase/collectweights/criterion/CollectWeightsCriterionModel.java @@ -0,0 +1,56 @@ +package flintstones.method.common.phase.collectweights.criterion; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public class CollectWeightsCriterionModel extends PhaseMethod { + + + @Inject + IProblemElementService problemService; + + HashMatrix weights = new HashMatrix<>(); + + @Override + public String getName() { + return "Collect Weights Basic"; + } + + public void addWeight(ProblemElement p1, ProblemElement p2, Double w) { + weights.put(p1,p2,w); + exportData(); + } + + public Double getWeight(ProblemElement p1, ProblemElement p2) { + return weights.get(p1, p2); + } + + private void exportData() { + exportData("criterionWeights", weights); + } + + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + public ProblemElement[] getCriteria() { + return problemService.getAll(Criterion.Type); + } + + public boolean isFilled() { + + for(ProblemElement expert : getExperts()) + for(ProblemElement criterion : getCriteria()) + if(weights.get(expert, criterion) == null) + return false; + + return true; + } + +} diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/.classpath b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.polyglot.META-INF new file mode 100644 index 0000000..e067ff0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.expert.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/.project b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.project new file mode 100644 index 0000000..71d9d9a --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.expert.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362646 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.expert.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..21ed9ed --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.common.phase.collectweights.expert.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights.expert.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.entity.problemelement, + flintstones.method.common.phase.collectweights.expert, + flintstones.entity.method.phase, + flintstones.entity.problemelement.ui, + flintstones.helper.ui, + flintstones.model.problemelement.service, + javax.inject, + flintstones.model.ui.service, + flintstones.helper.data diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/build.properties b/bundles/flintstones.method.common.phase.collectweights.expert.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.expert.ui/plugin.xml new file mode 100644 index 0000000..c2a50ea --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.expert.ui/src/flintstones/method/common/phase/collectweights/expert/ui/CollectWeightExpertUI.java b/bundles/flintstones.method.common.phase.collectweights.expert.ui/src/flintstones/method/common/phase/collectweights/expert/ui/CollectWeightExpertUI.java new file mode 100644 index 0000000..01701e4 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert.ui/src/flintstones/method/common/phase/collectweights/expert/ui/CollectWeightExpertUI.java @@ -0,0 +1,146 @@ +package flintstones.method.common.phase.collectweights.expert.ui; + +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.ProblemElement; +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.common.phase.collectweights.expert.CollectWeightExpertModel; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class CollectWeightExpertUI extends PhaseMethodUI implements WItemChanged, WItemBeforeOperation, WItemOperation { + + @Inject + IProblemElementService problemService; + + CollectWeightExpertModel model; + + Composite phaseBase; + + // Components + WCollector collector; + Label adviceLabel; + + @Override + public void init() { + model = (CollectWeightExpertModel) this.getModel(); + Composite base = this.getBaseComposite(); + + + createControls(base); + } + + @Override + public void refresh() { + } + + @Override + protected boolean isForwardEnabled() { + return model.isFilled(); + } + + private void createControls(Composite base) { + + ProblemElement[] items = model.getExperts(); + + UiService.setGridLayout(base, 1); + UiService.setGridDataAuto(base); + + Composite row = new Composite(base, 0); + UiService.setGridLayout(row, 3, false); + UiService.setGridData(row, 9, -1, true, false); + + adviceLabel = new Label(row, 0); + adviceLabel.setText("Los valores deben sumar exactamente 1. Es posible introducir números enteros como atajo. "); + + Composite row2 = new Composite(base, 0); + UiService.setGridLayout(row2, 1, true); + UiService.setGridDataAuto(row2); + + collector = new WCollector(row2); + collector.setHeaders(Arrays.stream(items).map(k -> k.getName()).toArray(String[]::new)); + collector.setChangeListener(this); + collector.setBeforeOperationListener(this); + collector.setOperationListener(this); + + } + + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + + ProblemElement[] items = model.getExperts(); + + if (operationType.equals(WEvent.ADD)) { + + double sum = 0.0; + + String[] data = collector.getData(); + if(model.getExperts().length > 1) { + + // Same length, limit reached + if (data.length == items.length) + return false; + + // Lets sum + for (String value : data) { + sum += Double.parseDouble(value); + } + + sum += DoubleHelper.NormalizeZeroToOne(before); + + } else { + sum = DoubleHelper.ParseDouble(before); + } + + // When the last element in introduced must sum 1 + if (data.length == items.length - 1) { + return sum == 1.0; + } else { // Must not sum over 1 in any case + return sum <= 1.0; + } + + } else if (operationType.equals(WEvent.CLEAR)) { + return true; + } + + return false; + } + + @Override + public void onWidgetChange() { + + ProblemElement[] items = model.getExperts(); + + String[] data = collector.getData(); + for (int i = 0; i < items.length && i < data.length; i++) { + model.addWeight(items[i], DoubleHelper.ParseDouble(data[i])); + } + + sendRefresh(); + + } + + @Override + public String getModifiedValue(WEvent operationType, String before, String after) { + if (operationType.equals(WEvent.ADD)) { + if(model.getExperts().length == 1) + return DoubleHelper.ParseDouble(before) + ""; + else + return DoubleHelper.NormalizeZeroToOne(before) + ""; + } + return after; + + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/.classpath b/bundles/flintstones.method.common.phase.collectweights.expert/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.expert/.polyglot.META-INF new file mode 100644 index 0000000..2f3251e --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.expert + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Expert + diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/.project b/bundles/flintstones.method.common.phase.collectweights.expert/.project new file mode 100644 index 0000000..5b65f80 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.expert + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362645 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.expert/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1cbf0e9 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Expert +Bundle-SymbolicName: flintstones.method.common.phase.collectweights.expert;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights.expert +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.entity.problemelement, + javax.inject, + flintstones.model.problemelement.service +Export-Package: flintstones.method.common.phase.collectweights.expert diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/build.properties b/bundles/flintstones.method.common.phase.collectweights.expert/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.expert/plugin.xml new file mode 100644 index 0000000..965cac6 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.expert/src/flintstones/method/common/phase/collectweights/expert/CollectWeightExpertModel.java b/bundles/flintstones.method.common.phase.collectweights.expert/src/flintstones/method/common/phase/collectweights/expert/CollectWeightExpertModel.java new file mode 100644 index 0000000..fd253e3 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.expert/src/flintstones/method/common/phase/collectweights/expert/CollectWeightExpertModel.java @@ -0,0 +1,49 @@ +package flintstones.method.common.phase.collectweights.expert; + +import java.util.HashMap; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.problemelement.service.IProblemElementService; + +public class CollectWeightExpertModel extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + HashMap weights = new HashMap<>(); + + @Override + public String getName() { + return "Collect Experts Weights"; + } + + public void addWeight(ProblemElement p1, Double w) { + weights.put(p1, w); + exportData(); + } + + public Double getWeight(ProblemElement p1) { + return weights.get(p1); + } + + private void exportData() { + exportData("expertWeights", weights); + } + + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + public boolean isFilled() { + for (ProblemElement expert : getExperts()) + if (weights.get(expert) == null) + return false; + + return true; + } + +} diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/.classpath b/bundles/flintstones.method.common.phase.collectweights.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights.ui/.polyglot.META-INF new file mode 100644 index 0000000..730fd23 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/.project b/bundles/flintstones.method.common.phase.collectweights.ui/.project new file mode 100644 index 0000000..2b9dcf5 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362648 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c8663d8 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/build.properties b/bundles/flintstones.method.common.phase.collectweights.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/plugin.xml b/bundles/flintstones.method.common.phase.collectweights.ui/plugin.xml new file mode 100644 index 0000000..c86e439 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectAlternativeWeightColumn.java b/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectAlternativeWeightColumn.java new file mode 100644 index 0000000..1d7fa14 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectAlternativeWeightColumn.java @@ -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 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(); + } + } + + +} diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectWeightColumn.java b/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectWeightColumn.java new file mode 100644 index 0000000..036cf4d --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectWeightColumn.java @@ -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 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 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()); + + } +} diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectWeightsUI.java b/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectWeightsUI.java new file mode 100644 index 0000000..bfd5704 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/CollectWeightsUI.java @@ -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); + + } + +} diff --git a/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/interfaces/IToggled.java b/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/interfaces/IToggled.java new file mode 100644 index 0000000..44a5711 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights.ui/src/flintstones/method/common/phase/collectweights/ui/interfaces/IToggled.java @@ -0,0 +1,5 @@ +package flintstones.method.common.phase.collectweights.ui.interfaces; + +public interface IToggled { + void onToggle(boolean status); +} diff --git a/bundles/flintstones.method.common.phase.collectweights/.classpath b/bundles/flintstones.method.common.phase.collectweights/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweights/.polyglot.META-INF new file mode 100644 index 0000000..4adcfe5 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweights + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Collectweights + diff --git a/bundles/flintstones.method.common.phase.collectweights/.project b/bundles/flintstones.method.common.phase.collectweights/.project new file mode 100644 index 0000000..2d4223b --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweights + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362638 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweights/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweights/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ec38b83 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Collectweights +Bundle-SymbolicName: flintstones.method.common.phase.collectweights;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweights +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: javax.inject, + flintstones.entity.method.phase.ui, + flintstones.helper.extensionpoint, + javax.annotation, + flintstones.entity.method.phase, + flintstones.method.decision.common.phase.collectweights;bundle-version="1.0.0", + flintstones.model.method.phase.service, + org.eclipse.e4.core.contexts, + org.apache.commons.lang, + flintstones.entity.problemelement, + flintstones.helper.data +Export-Package: flintstones.method.common.phase.collectweights diff --git a/bundles/flintstones.method.common.phase.collectweights/build.properties b/bundles/flintstones.method.common.phase.collectweights/build.properties new file mode 100644 index 0000000..3595411 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + schema/ diff --git a/bundles/flintstones.method.common.phase.collectweights/plugin.xml b/bundles/flintstones.method.common.phase.collectweights/plugin.xml new file mode 100644 index 0000000..f6f0f66 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights/schema/flintstones.method.phase.collectWeights.exsd b/bundles/flintstones.method.common.phase.collectweights/schema/flintstones.method.phase.collectWeights.exsd new file mode 100644 index 0000000..083da5e --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/schema/flintstones.method.phase.collectWeights.exsd @@ -0,0 +1,102 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweights/src/flintstones/method/common/phase/collectweights/CollectWeightsModel.java b/bundles/flintstones.method.common.phase.collectweights/src/flintstones/method/common/phase/collectweights/CollectWeightsModel.java new file mode 100644 index 0000000..2faa2ef --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweights/src/flintstones/method/common/phase/collectweights/CollectWeightsModel.java @@ -0,0 +1,122 @@ +package flintstones.method.common.phase.collectweights; + +import java.util.Arrays; +import java.util.HashMap; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import org.eclipse.e4.core.contexts.IEclipseContext; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.model.method.phase.IPhaseMethodService; + +public class CollectWeightsModel extends PhaseMethod { + + @Inject + IPhaseMethodService phaseService; + + @Inject + IEclipseContext context; + + PhaseMethodUI expertUI; + PhaseMethodUI criterionUI; + + HashMap cachedPhases = new HashMap<>(); + + BaseRegistry basereg; + + @PostConstruct + private void init() { + basereg = new BaseRegistry("flintstones.method.phase.collectWeights"); + } + + @Override + public String getName() { + return "Collect Weights"; + } + + public void reExport(PhaseMethod phaseModel) { + + String[] exportedKeys = phaseModel.getExportedKeys(false); + for(String key : exportedKeys) + exportData(key, phaseModel.getExportedData(key)); + + } + + public void deleteExport(PhaseMethod phaseModel) { + + String[] exportedKeys = phaseModel.getExportedKeys(false); + for(String key : exportedKeys) + deleteData(key); + + } + + public void setCriterionPhase(PhaseMethodUI ui) { + if(criterionUI != null) { + deleteExport(criterionUI.getModel()); + } + criterionUI = ui; + reExport(ui.getModel()); + } + + public void setExpertPhase(PhaseMethodUI ui) { + if(expertUI != null) { + deleteExport(expertUI.getModel()); + } + expertUI = ui; + reExport(ui.getModel()); + } + + public PhaseMethodUI getExpertPhase() { + return expertUI; + } + + public PhaseMethodUI getCriterionPhase() { + return criterionUI; + } + + public String[] getCriterionWeightCollectorLabels() { + + if(cachedPhases.isEmpty()) { + ExtensionRegistry[] regs = basereg.getAllRegistries(); + PhaseMethodUI[] uis = new PhaseMethodUI[regs.length]; + int x = 0; + for(ExtensionRegistry reg : regs) + uis[x++] = phaseService.createPhase(reg.getAttribute(PhaseMethod.Fields.uid)); + + Arrays.stream(uis).forEach( k -> cachedPhases.put(k.getModel().getName(), k) ); + } + + return cachedPhases.values().stream().map(k -> k.getModel().getName()).toArray(String[]::new); + + } + + public String getPhaseIdBy(String name) { + return cachedPhases.get(name).getModel().getId(); + } + + + public void export(String key, HashMatrix weights) { + + if(weights.size() == 1) { + ProblemElement first = weights.keySet().iterator().next(); + if(first.getType().equals(FakeProblemElement.Type)) { + + } + exportData(key,weights.get(first)); + } else { + exportData(key, weights); + } + + } + + public void deleteExport(String key) { + this.deleteData(key); + } + +} diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.classpath b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.polyglot.META-INF new file mode 100644 index 0000000..068ca93 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweightsaggregation.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.project b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.project new file mode 100644 index 0000000..8df75b9 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweightsaggregation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362649 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6113d58 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/META-INF/MANIFEST.MF @@ -0,0 +1,27 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.common.phase.collectweightsaggregation.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweightsaggregation.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.method.common.phase.collectweightsaggregation, + org.eclipse.swt, + org.eclipse.jface, + flintstones.model.ui.service, + javax.inject, + flintstones.model.problemelement.service, + flintstones.entity.problemelement, + flintstones.helper.data, + org.eclipse.nebula.widgets.opal.notifier, + flintstones.helper.ui, + flintstones.entity.aggregation, + flintstones.entity.common, + org.lorissecuro.ui, + org.eclipse.e4.core.services, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di +Import-Package: flintstones.entity.method.phase +Export-Package: flintstones.method.common.phase.collectweightsaggregation.ui, + flintstones.method.common.phase.collectweightsaggregation.ui.provider diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/build.properties b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/plugin.xml b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/plugin.xml new file mode 100644 index 0000000..f2fa0a0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/CollectAggregationDataUI.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/CollectAggregationDataUI.java new file mode 100644 index 0000000..ced71ac --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/CollectAggregationDataUI.java @@ -0,0 +1,323 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui; + +import javax.inject.Inject; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.nebula.widgets.opal.notifier.WNotifier; +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.Image; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.aggregation.AggregationItem; +import flintstones.entity.common.interfaces.IChangedEntity; +import flintstones.entity.common.interfaces.IRefreshEntity; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.helper.ui.components.ToggleButton; +import flintstones.helper.ui.components.listeners.IToggle; +import flintstones.method.common.phase.collectweightsaggregation.CollectAggregationDataModel; +import flintstones.method.common.phase.collectweightsaggregation.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.method.common.phase.collectweightsaggregation.ui.provider.OperatorColumnEditingSupport; +import flintstones.method.common.phase.collectweightsaggregation.ui.provider.OperatorColumnLabelProvider; +import flintstones.method.common.phase.collectweightsaggregation.ui.provider.TreeContentProvider; +import flintstones.method.common.phase.collectweightsaggregation.ui.provider.WeightColumnEditingSupport; +import flintstones.method.common.phase.collectweightsaggregation.ui.provider.WeightColumnLabelProvider; +import flintstones.model.ui.service.UiService; + + +public class CollectAggregationDataUI implements IRefreshEntity { + + CollectAggregationDataModel model; + + // DATA + AggregationItem mainItemExpert; + AggregationItem mainItemCriterion; + + // UI + TreeViewer viewer; + Label errorLabel; + + // Type of aggregation + boolean firstExpertsToAggregate = false; + + IChangedEntity changedListener; + + @Inject + @Translation + Messages messages; + + public CollectAggregationDataUI() {} + + public CollectAggregationDataUI(CollectAggregationDataModel model, Composite base, Expert[] es, Criterion[] cs, Alternative[] as) { + + this.model = model; + mainItemExpert = new AggregationItem(new Alternative(""), es, cs); //$NON-NLS-1$ + mainItemCriterion = new AggregationItem(new Alternative(""), cs, es); //$NON-NLS-1$ + + // Weights + mainItemExpert.shareWeight(); + mainItemCriterion.shareWeight(); + + drawTree(base); + inputExpertCriterion(); + drawButtons(base); + + errorLabel = new Label(base,0); + errorLabel.setText(" "); //$NON-NLS-1$ + + refreshEntity(null); + + } + + public void build(CollectAggregationDataModel model, Composite base, Expert[] es, Criterion[] cs, Alternative[] as) { + this.model = model; + mainItemExpert = new AggregationItem(new Alternative(""), es, cs); //$NON-NLS-1$ + mainItemCriterion = new AggregationItem(new Alternative(""), cs, es); //$NON-NLS-1$ + + // Weights + mainItemExpert.shareWeight(); + mainItemCriterion.shareWeight(); + + drawTree(base); + inputExpertCriterion(); + drawButtons(base); + + errorLabel = new Label(base,0); + errorLabel.setText(" "); //$NON-NLS-1$ + + refreshEntity(null); + } + + private void inputExpertCriterion() { + viewer.setInput(new AggregationItem[] {mainItemExpert}); + model.refreshExpertWeights(mainItemExpert); + viewer.expandToLevel(3); + } + + private void inputCriterion() { + viewer.setInput(new AggregationItem[] {mainItemCriterion}); + model.refreshCriterionWeights(mainItemCriterion); + viewer.expandToLevel(3); + } + + private void drawButtons(Composite parent) { + + Composite base = new Composite(parent,0); + UiService.setGridData(base, 9, 0, true, false); + UiService.setGridLayout(base, 3); + + new ToggleButton(base, 0, new IToggle() { + + @Override + public void onBaseTextClick() { + firstExpertsToAggregate = true; + inputCriterion(); + } + + @Override + public void onAltTextClick() { + firstExpertsToAggregate = false; + inputExpertCriterion(); + } + + @Override + public String getBaseText() { + return messages.First_criteria; + } + + @Override + public String getAltText() { + return messages.First_experts; + } + + @Override + public void always() { + } + + @Override + public Image getBaseImage() { + return null; + //return UiService.getIcon("expertsFirst.png").createImage(); + } + + @Override + public Image getAltImage() { + return null; + //return UiService.getIcon("criteriaFirst.png").createImage(); + } + }); + + Button applyToChildren = new Button(base, 0); + applyToChildren.setText(messages.Apply_to_children); + applyToChildren.addSelectionListener(new SelectionAdapter() { + + @SuppressWarnings("static-access") + @Override + public void widgetSelected(SelectionEvent e) { + IStructuredSelection selection = viewer.getStructuredSelection(); + AggregationItem aggItem = (AggregationItem) selection.getFirstElement(); + + // Check 1 + if(aggItem == null) { + + new WNotifier("Error", messages.Select_element_first, WNotifier.Themes.YELLOW_THEME ) //$NON-NLS-1$ + .withCloseOnClick(true) + .withTimeout(30) + .send(); + + return ; + } + + // Check 2 + String operatorId = aggItem.getOperatorId(); + if(operatorId.equals("")) { //$NON-NLS-1$ + new WNotifier("Error", messages.No_operator_selected, WNotifier.Themes.YELLOW_THEME ) //$NON-NLS-1$ + .withCloseOnClick(true) + .withTimeout(30) + .send(); + } + + aggItem.setOperatorId(operatorId,true); + viewer.refresh(); + refreshEntity(null); + } + }); + + Button applyToAll = new Button(base, 0); + applyToAll.setText(messages.Fill_operators); //$NON-NLS-1$ + applyToAll.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AggregationItem aggItem = (AggregationItem) viewer.getTree().getItems()[0].getData(); // First item of current viewer + String operatorId = model.getOperatorsIdName().keySet().iterator().next(); + aggItem.setOperatorId(operatorId, true); + viewer.refresh(); + refreshEntity(null); + } + }); + + } + + private void drawTree(Composite parent) { + + Composite base = new Composite(parent, 0); + UiService.setGridDataAuto(base); + UiService.setGridLayout(base, 1); + + viewer = new TreeViewer(base, SWT.FULL_SELECTION); + viewer.setContentProvider(new TreeContentProvider()); + 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.Element); + viewerColumn.setLabelProvider(new MainColumnLabelProvider()); + + TreeViewerColumn viewerColumn2 = new TreeViewerColumn(viewer, SWT.NONE); + viewerColumn2.getColumn().setText(messages.Weight); + viewerColumn2.setLabelProvider(new WeightColumnLabelProvider()); + viewerColumn2.setEditingSupport(new WeightColumnEditingSupport(this, viewer)); + + TreeViewerColumn viewerColumn3 = new TreeViewerColumn(viewer, SWT.NONE); + viewerColumn3.getColumn().setText(messages.Enabled); + viewerColumn3.setLabelProvider(new EnabledColumnLabelProvider()); + viewerColumn3.setEditingSupport(new EnabledColumnEditingSupport(this, viewer)); + + TreeViewerColumn viewerColumn4 = new TreeViewerColumn(viewer, SWT.NONE); + viewerColumn4.getColumn().setText(messages.Operator); + viewerColumn4.setLabelProvider(new OperatorColumnLabelProvider(model.getOperatorsIdName(), messages)); + viewerColumn4.setEditingSupport(new OperatorColumnEditingSupport(this,viewer,model.getOperatorsNameId())); + + + GridLayoutFactory.fillDefaults().generateLayout(parent); + + // SIZE + parent.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + Composite composite = (Composite) e.widget; + int width = composite.getBounds().width; + + double total = 1.0d; + double c2 = 0.1; + double c3 = 0.12; + double c4 = 0.3; + double c1 = total -c2 -c3 -c4; + + viewerColumn.getColumn().setWidth((int) (width*c1)); + viewerColumn2.getColumn().setWidth((int) (width*c2)); + viewerColumn3.getColumn().setWidth((int) (width*c3)); + viewerColumn4.getColumn().setWidth((int) (width*c4)); + } + }); + } + + public void refreshEntity(Object x) { + model.refreshExpertWeights(mainItemExpert); + model.refreshCriterionWeights(mainItemCriterion); + + String error = getFirstError(); + if(error != null) + errorLabel.setText(error); + else + errorLabel.setText(""); //$NON-NLS-1$ + + if(changedListener != null) + changedListener.onEntityChange(firstExpertsToAggregate); + } + + public void setChangeListener(IChangedEntity lis) { + changedListener = lis; + } + + + public String getFirstError(){ + String err; + if(firstExpertsToAggregate) + err = getFirstError(mainItemCriterion); + else + err = getFirstError(mainItemExpert); + + System.err.println(err); + + return err; + + } + + private String getFirstError(AggregationItem item) { + + + if(item.getOperatorId().equals("") && item.getElement3() == null) //$NON-NLS-1$ + return messages.Operator_not_defined_for_element + item.toString(); + + if(!item.validateWeights() && item.getElement3() == null ) + return messages.Weights_not_defined_for_element + item.toString(); + + for(AggregationItem child : item.getChildren()) { + String err = getFirstError(child); + if(err != null) + return err; + } + + return null; + } + + public boolean isExpertFirst() { + return !firstExpertsToAggregate; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/CollectWeightsAggregationUi.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/CollectWeightsAggregationUi.java new file mode 100644 index 0000000..b761570 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/CollectWeightsAggregationUi.java @@ -0,0 +1,59 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.widgets.Composite; + +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.collectweightsaggregation.CollectAggregationDataModel; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class CollectWeightsAggregationUi extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + @Inject + IEclipseContext context; + + CollectAggregationDataModel model; + + @Override + public void init() { + + model = (CollectAggregationDataModel) getModel(); + + // CANVAS + Composite base = getBaseComposite(); + UiService.setGridDataAuto(base); + UiService.setGridLayout(base, 2); + + //DATA + Expert[] es = ProblemElementHelper.asExperts(problemService.getMainElements(Expert.Type)); + Criterion[] cs = ProblemElementHelper.asCriterions(problemService.getMainElements(Criterion.Type)); + Alternative[] as = ProblemElementHelper.asAlternatives(problemService.getMainElements(Alternative.Type)); + + CollectAggregationDataUI collectUi = ContextInjectionFactory.make(CollectAggregationDataUI.class, context); + collectUi.build(model, base, es, cs, as); + } + + @Override + public void refresh() { + // TODO Auto-generated method stub + + } + + @Override + protected boolean isForwardEnabled() { + // TODO Auto-generated method stub + return true; + } + +} diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/Messages.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/Messages.java new file mode 100644 index 0000000..9bce303 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/Messages.java @@ -0,0 +1,19 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.messages; + +public class Messages { + + public String Apply_to_children; + public String Element; + public String Enabled; + public String Fill_operators; + public String First_criteria; + public String First_experts; + public String No_operator_selected; + public String Operator; + public String Operator_not_defined_for_element; + public String Select_element_first; + public String Weight; + public String Weights_not_defined_for_element; + public String Select_operator; + +} diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/messages.properties b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/messages.properties new file mode 100644 index 0000000..a1f807e --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/messages.properties @@ -0,0 +1,14 @@ +Apply_to_children=Apply to children +Element=Element +Enabled=Enabled +Fill_operators=Fill operators +First_criteria=First criteria +First_experts=First experts +No_operator_selected=No operator for the selected element. +Operator=Operator +Operator_not_defined_for_element=No operator for element +Select_element_first=Select an element first. +Weight=Weight +Weights_not_defined_for_element=No weights for element +Select_operator=- SELECT OPERATOR - + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/messages_es.properties b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/messages_es.properties new file mode 100644 index 0000000..0785912 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/messages/messages_es.properties @@ -0,0 +1,14 @@ +Apply_to_children=Aplicar a hijos +Element=Elemento +Enabled=Habilitado +Fill_operators=Rellenar operadores +First_criteria=Criterios primero +First_experts=Expertos primero +No_operator_selected=El elemento seleccionado no tiene un operador asignado. +Operator=Operador +Operator_not_defined_for_element=Operador no definido para el elemento. +Select_element_first=Selecciona un elemento primero. +Weight=Peso +Weights_not_defined_for_element=Pesos no definidos para el elemento. +Select_operator=- SELECCIONAR OPERADOR - + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/EnabledColumnEditingSupport.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/EnabledColumnEditingSupport.java new file mode 100644 index 0000000..0e9c0b1 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/EnabledColumnEditingSupport.java @@ -0,0 +1,55 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.provider; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TreeViewer; +import flintstones.entity.aggregation.AggregationItem; +import flintstones.entity.common.interfaces.IRefreshEntity; + +public class EnabledColumnEditingSupport extends EditingSupport { + + private IRefreshEntity collectDataUi; + + private final TreeViewer viewer; + + public EnabledColumnEditingSupport(IRefreshEntity collectDataUi, TreeViewer viewer) { + super(viewer); + this.collectDataUi = collectDataUi; + this.viewer = viewer; + } + + @Override + protected boolean canEdit(Object element) { + // Toggle onclick + AggregationItem item = ((AggregationItem) element); + + item.setEnabled(!item.isEnabled()); + viewer.update(element, null); + viewer.setSelection(null); + + if(item.getParent() != null) + viewer.update(item.getParent(), null); + + + if(item.validateParentWeights()) + this.collectDataUi.refreshEntity(null); + + + return false; + } + + @Override + protected CellEditor getCellEditor(Object element) { + return null; + } + + @Override + protected Object getValue(Object element) { + return null; + } + + @Override + protected void setValue(Object element, Object value) { + + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/EnabledColumnLabelProvider.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/EnabledColumnLabelProvider.java new file mode 100644 index 0000000..51bf190 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/EnabledColumnLabelProvider.java @@ -0,0 +1,25 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.swt.graphics.Color; + +import flintstones.entity.aggregation.AggregationItem; +import flintstones.model.ui.service.UiService; + +public class EnabledColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + AggregationItem item = (AggregationItem) element; + return item.isEnabled() ? "Enabled" : "Disabled"; + } + + @Override + public Color getBackground(Object element) { + AggregationItem item = (AggregationItem) element; + if (item.isEnabled()) + return UiService.COLOR_BG_SUCCESS; + return UiService.COLOR_BG_WRONG; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/MainColumnLabelProvider.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/MainColumnLabelProvider.java new file mode 100644 index 0000000..a54ca7b --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/MainColumnLabelProvider.java @@ -0,0 +1,25 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.aggregation.AggregationItem; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.ui.service.UiService; + +public class MainColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + AggregationItem item = (AggregationItem) element; + return item.getFinalItem().getName(); + } + + @Override + public Image getImage(Object element) { + AggregationItem item = (AggregationItem) element; + String image = ProblemElementHelper.getImage(item.getFinalItem()); + return UiService.getImage(image).createImage(); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/OperatorColumnEditingSupport.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/OperatorColumnEditingSupport.java new file mode 100644 index 0000000..3e53358 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/OperatorColumnEditingSupport.java @@ -0,0 +1,79 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.provider; + +import java.util.HashMap; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.ComboBoxCellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; + +import flintstones.entity.aggregation.AggregationItem; +import flintstones.entity.common.interfaces.IRefreshEntity; + +public class OperatorColumnEditingSupport extends EditingSupport { + + private IRefreshEntity collectDataUi; + + private final TreeViewer viewer; + + private ComboBoxCellEditor cellEditor; + + private HashMap operators; + + public OperatorColumnEditingSupport(IRefreshEntity collectDataUi, TreeViewer viewer, HashMap operators) { + super(viewer); + this.collectDataUi = collectDataUi; + this.viewer = viewer; + this.operators = operators; + + cellEditor = new ComboBoxCellEditor(((TreeViewer) viewer).getTree(),operators.keySet().toArray(new String[0]), SWT.READ_ONLY); + + } + + @Override + protected CellEditor getCellEditor(Object element) { + if (element instanceof AggregationItem) + { + return cellEditor; + } + return null; + } + + @Override + protected boolean canEdit(Object element) + { + AggregationItem item = (AggregationItem) element; + if(item.getElement3() == null) + return true; + return false; + + } + + + @Override + protected Object getValue(Object element) + { + return 0; + } + + @Override + protected void setValue(Object element, Object value) + { + + CCombo combo = ((CCombo) cellEditor.getControl()); + String operatorName = combo.getItem(combo.getSelectionIndex()); + String operatorId = operators.get(operatorName); + + // Update + AggregationItem item = (AggregationItem) element; + item.setOperatorId(operatorId); + viewer.update(element, null); +// viewer.setSelection(null); + + collectDataUi.refreshEntity(null); + + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/OperatorColumnLabelProvider.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/OperatorColumnLabelProvider.java new file mode 100644 index 0000000..267f882 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/OperatorColumnLabelProvider.java @@ -0,0 +1,37 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.provider; + +import java.util.HashMap; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +import flintstones.entity.aggregation.AggregationItem; +import flintstones.method.common.phase.collectweightsaggregation.ui.messages.Messages; + +public class OperatorColumnLabelProvider extends ColumnLabelProvider { + + Messages messages; + + private HashMap operators; + + public OperatorColumnLabelProvider(HashMap operators, Messages messages) { + this.operators = operators; + this.messages = messages; + } + + @Override + public String getText(Object element) { + AggregationItem item = (AggregationItem) element; + String id = item.getOperatorId(); + String name = operators.get(id); + + if(name == null) { + if(item.getElement3() == null) + return messages.Select_operator; + else + return ""; //$NON-NLS-1$ + } + + return name; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/TreeContentProvider.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/TreeContentProvider.java new file mode 100644 index 0000000..9bbb2fb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/TreeContentProvider.java @@ -0,0 +1,31 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.provider; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; + +import flintstones.entity.aggregation.AggregationItem; + +public class TreeContentProvider implements ITreeContentProvider { + + @Override + public boolean hasChildren(Object element) { + AggregationItem item = (AggregationItem) element; + return item.hasChildren(); + } + + @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) { + AggregationItem item = (AggregationItem) parentElement; + return item.getChildren(); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/WeightColumnEditingSupport.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/WeightColumnEditingSupport.java new file mode 100644 index 0000000..d233cff --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/WeightColumnEditingSupport.java @@ -0,0 +1,65 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.provider; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jface.viewers.TreeViewer; + +import flintstones.entity.aggregation.AggregationItem; +import flintstones.entity.common.interfaces.IRefreshEntity; +import flintstones.helper.DoubleHelper; + +public class WeightColumnEditingSupport extends EditingSupport { + + /** + * + */ + private IRefreshEntity collectWeightsAggregationUi; + private final TreeViewer viewer; + private final CellEditor editor; + + public WeightColumnEditingSupport(IRefreshEntity collectDataUi, TreeViewer viewer) { + super(viewer); + this.collectWeightsAggregationUi = collectDataUi; + this.viewer = viewer; + this.editor = new TextCellEditor(viewer.getTree()); + } + + @Override + protected CellEditor getCellEditor(Object element) { + return editor; + } + + @Override + protected boolean canEdit(Object element) { + return true; + } + + @Override + protected Object getValue(Object element) { + return ((AggregationItem) element).getWeight() + ""; + } + + @Override + protected void setValue(Object element, Object userInputValue) { + + String sval = userInputValue.toString(); + double val = DoubleHelper.ParseDouble(sval); + if (val > 1.0) + val = DoubleHelper.NormalizeZeroToOne(sval); + + AggregationItem item = (AggregationItem) element; + ((AggregationItem) element).setWeight(val); + + // Update things + viewer.update(element, null); + if(item.getParent() != null) { + viewer.update(item.getParent(), null); + if(item.validateParentWeights()) + this.collectWeightsAggregationUi.refreshEntity(null); + } + +// viewer.setSelection(null); + + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/WeightColumnLabelProvider.java b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/WeightColumnLabelProvider.java new file mode 100644 index 0000000..b78a07b --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation.ui/src/flintstones/method/common/phase/collectweightsaggregation/ui/provider/WeightColumnLabelProvider.java @@ -0,0 +1,45 @@ +package flintstones.method.common.phase.collectweightsaggregation.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.swt.graphics.Color; + +import flintstones.entity.aggregation.AggregationItem; +import flintstones.helper.DoubleHelper; +import flintstones.model.ui.service.UiService; + +public class WeightColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + AggregationItem item = (AggregationItem) element; + return DoubleHelper.Draw(item.getWeight()); + } + + @Override + public Color getBackground(Object element) { + AggregationItem item = (AggregationItem) element; + + if(!item.isEnabled()) + return UiService.COLOR_BG_NORMAL; + + if (!item.hasChildren()) + return UiService.COLOR_BG_NORMAL; + + if (item.validateWeights()) + return UiService.COLOR_BG_SUCCESS; + + return UiService.COLOR_BG_WRONG; + } + + @Override + public Color getForeground(Object element) { + + AggregationItem item = (AggregationItem) element; + + if(!item.isEnabled()) + return UiService.COLOR_BG_NORMAL; + + return null; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/.classpath b/bundles/flintstones.method.common.phase.collectweightsaggregation/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/.polyglot.META-INF b/bundles/flintstones.method.common.phase.collectweightsaggregation/.polyglot.META-INF new file mode 100644 index 0000000..e785050 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.collectweightsaggregation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Collectweightsaggregation + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/.project b/bundles/flintstones.method.common.phase.collectweightsaggregation/.project new file mode 100644 index 0000000..3b35eaf --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.collectweightsaggregation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362648 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.collectweightsaggregation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..31838fc --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Collectweightsaggregation +Bundle-SymbolicName: flintstones.method.common.phase.collectweightsaggregation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.collectweightsaggregation +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.entity.problemelement, + flintstones.helper.data, + flintstones.entity.aggregation, + flintstones.entity.operator, + javax.inject, + flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service +Export-Package: flintstones.method.common.phase.collectweightsaggregation diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/build.properties b/bundles/flintstones.method.common.phase.collectweightsaggregation/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/plugin.xml b/bundles/flintstones.method.common.phase.collectweightsaggregation/plugin.xml new file mode 100644 index 0000000..783a1d0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.collectweightsaggregation/src/flintstones/method/common/phase/collectweightsaggregation/CollectAggregationDataModel.java b/bundles/flintstones.method.common.phase.collectweightsaggregation/src/flintstones/method/common/phase/collectweightsaggregation/CollectAggregationDataModel.java new file mode 100644 index 0000000..b500686 --- /dev/null +++ b/bundles/flintstones.method.common.phase.collectweightsaggregation/src/flintstones/method/common/phase/collectweightsaggregation/CollectAggregationDataModel.java @@ -0,0 +1,142 @@ +package flintstones.method.common.phase.collectweightsaggregation; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; +import flintstones.entity.aggregation.AggregationItem; +import flintstones.entity.method.phase.ImportedDataNotFoundException; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; + +public class CollectAggregationDataModel extends PhaseMethod { + + @Inject + IOperatorService operatorService; + + @Inject + IValuationService valuationService; + + @Override + public String getName() { + return "Collect Weights Aggregation"; + } + + private ArrayList getLeafItems(AggregationItem item) { + + ArrayList arr = new ArrayList<>(); + + if (item.getElement2() != null && item.getElement3() != null) + arr.add(item); + + Arrays.stream(item.getChildren()).forEach(k -> arr.addAll(getLeafItems(k))); + + return arr; + + } + + private ArrayList getLevel2ItemsOnly(AggregationItem item) { + + ArrayList arr = new ArrayList<>(); + + // Stop expanding tree + if(item.getElement3() != null) + return arr; + + if (item.getElement2() != null) + arr.add(item); + + Arrays.stream(item.getChildren()).forEach(k -> arr.addAll(getLevel2ItemsOnly(k))); + + return arr; + + } + + public void refreshExpertWeights(AggregationItem mainItem) { + + // Expert -> Criterion + HashMatrix expertCriterionWeights = new HashMatrix<>(); + ArrayList finalECChildren = getLeafItems(mainItem); + for (AggregationItem item : finalECChildren) + expertCriterionWeights.put((Expert)item.getElement2(), (Criterion)item.getElement3(), item.getWeight()); + + // Expert + HashMap expertWeights = new HashMap<>(); + ArrayList finalEChildren = getLevel2ItemsOnly(mainItem); + for (AggregationItem item : finalEChildren) + expertWeights.put((Expert)item.getElement2(), item.getWeight()); + + exportData("expertWeights",expertWeights, true); + exportData("expertCriterionWeights",expertCriterionWeights, true); + exportData("expertCriterionWeightsMainTtem", mainItem, true); + + } + + public void refreshCriterionWeights(AggregationItem mainItem) { + + HashMatrix criterionExpertWeights = new HashMatrix<>(); + ArrayList finalChildren = getLeafItems(mainItem); + for (AggregationItem item : finalChildren) + criterionExpertWeights.put((Criterion)item.getElement2(), (Expert)item.getElement3(), item.getWeight()); + + // Criterion + HashMap criterionWeights = new HashMap<>(); + ArrayList finalEChildren = getLevel2ItemsOnly(mainItem); + for (AggregationItem item : finalEChildren) + criterionWeights.put((Criterion)item.getElement2(), item.getWeight()); + + exportData("criterionWeights",criterionWeights, true); + exportData("criterionExpertWeights",criterionExpertWeights, true); + exportData("criterionExpertSubItems", finalEChildren, true); // List of Sub-Criteria + exportData("criterionExpertWeightsMainItem", mainItem, true); + + } + + @SuppressWarnings("unchecked") + private Map getValuations() { + Map valuations; + + try { + valuations = (Map) importData("twoTupleUnifiedValuations"); + } catch (ImportedDataNotFoundException e) { + valuations = valuationService.getAllKV(); + } + + return valuations; + + } + + public HashMap getOperatorsIdName(){ + + HashMap operatorsIdNameCache = new HashMap<>(); + + Valuation v = getValuations().values().iterator().next(); + AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(v.getId(), true); + for(AggregationOperator op : operators) + operatorsIdNameCache.put(op.getId(), op.getName()); + + return operatorsIdNameCache; + } + + public HashMap getOperatorsNameId(){ + + HashMap operatorsNameIdCache = new HashMap<>(); + + Valuation v = getValuations().values().iterator().next(); + AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(v.getId(), true); + for(AggregationOperator op : operators) + operatorsNameIdCache.put(op.getName(), op.getId()); + + return operatorsNameIdCache; + } + +} diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.classpath b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.polyglot.META-INF new file mode 100644 index 0000000..dd6c0a1 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.generateUnificationDomain.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.project b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.project new file mode 100644 index 0000000..0f4e182 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.generateUnificationDomain.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362650 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f0df891 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.common.phase.generateUnificationDomain.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.generateUnificationDomain.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.method.common.phase.generateUnificationDomain, + org.eclipse.swt, + flintstones.domain.fuzzyset.ui.dialog, + flintstones.method.common.phase.unification, + flintstones.domain.fuzzyset, + org.eclipse.wb.swt, + flintstones.entity.domain, + flintstones.domain.fuzzyset.ui.chart, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui, + org.jfree.chart.jfreechart, + javax.inject diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/build.properties b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/plugin.xml b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/plugin.xml new file mode 100644 index 0000000..d4fa04e --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/GenerateUnificationDomainUi.java b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/GenerateUnificationDomainUi.java new file mode 100644 index 0000000..9a94b21 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/GenerateUnificationDomainUi.java @@ -0,0 +1,181 @@ +package flintstones.method.common.phase.generateUnificationDomain.ui; + +import java.util.List; +import javax.inject.Inject; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.wb.swt.SWTResourceManager; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.method.common.phase.generateUnificationDomain.GenerateUnificationDomainModel; +import flintstones.method.common.phase.generateUnificationDomain.ui.messages.Messages; + +public class GenerateUnificationDomainUi extends PhaseMethodUI { + + GenerateUnificationDomainModel phaseMethod; + + // FS3 + Composite _parent; + private Composite domainInfoPanel; + private Composite domainChartPanel; + + private Label levelLabel; + private Label nameLabel; + private Label descriptionLabel; + + private LinguisticDomainChart _domainChart; + + private ControlAdapter _controlListener; + + private FuzzySet unifiedDomain; + + @Inject + @Translation + Messages messages; + + + @Override + public void init() { + phaseMethod = (GenerateUnificationDomainModel) this.getModel(); + createPartControl(this.getBaseComposite()); + + generateLH(); + refreshDomainChart(); + domainInfoPanel.layout(); + + phaseMethod.export(); + + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + @Override + public boolean isSkippable() { + return false; + } + + @Override + public void beforeSkip() { + } + + public void createPartControl(Composite parent) { + _parent = parent; + + _controlListener = null; + + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + _parent.setLayoutData(gridData); + GridLayout layout = new GridLayout(1, true); + layout.marginLeft = 20; + layout.marginRight = 20; + layout.marginBottom = 15; + layout.marginTop = 20; + _parent.setLayout(layout); + + createDomainInfoPanel(); + createDomainChartPanel(); + } + + private void createDomainInfoPanel() { + domainInfoPanel = new Composite(_parent, SWT.NONE); + domainInfoPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); + domainInfoPanel.setLayout(new GridLayout(2, false)); + + Label level = new Label(domainInfoPanel, SWT.NONE); + level.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.BOLD)); //$NON-NLS-1$ + level.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + level.setText(messages.Domain_level); + + levelLabel = new Label(domainInfoPanel, SWT.NONE); + levelLabel.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.NONE)); //$NON-NLS-1$ + levelLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + Label name = new Label(domainInfoPanel, SWT.NONE); + name.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.BOLD)); //$NON-NLS-1$ + name.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + name.setText(messages.Domain_name); + + nameLabel = new Label(domainInfoPanel, SWT.NONE); + nameLabel.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.NONE)); //$NON-NLS-1$ + nameLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); + + Label description = new Label(domainInfoPanel, SWT.NONE); + description.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.BOLD)); //$NON-NLS-1$ + description.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + description.setText(messages.Domain_description); //$NON-NLS-1$ + + descriptionLabel = new Label(domainInfoPanel, SWT.NONE); + descriptionLabel.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.NONE)); //$NON-NLS-1$ + descriptionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); + } + + private void createDomainChartPanel() { + domainChartPanel = new Composite(_parent, SWT.NONE); + domainChartPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + } + + private void removeChart() { + if (_domainChart != null) { + _domainChart.getChartComposite().dispose(); + } + } + + private void refreshDomainChart() { + removeChart(); + + Point size = domainChartPanel.getSize(); + _domainChart = new LinguisticDomainChart(); + _domainChart.initialize(unifiedDomain, domainChartPanel, size.x, size.y, SWT.BORDER); + + if(_controlListener == null) { + _controlListener = new ControlAdapter() { + + @Override + public void controlResized(ControlEvent e) { + refreshDomainChart(); + } + }; + domainChartPanel.addControlListener(_controlListener); + } + } + + private void generateLH() { + List elhDomains = phaseMethod.generateLH(); + Object[] result = null; + + if (elhDomains != null) { + result = elhDomains.get(elhDomains.size() - 1); + } + + if(result != null) { + levelLabel.setText((String) result[0]); + nameLabel.setText((String) result[1]); + unifiedDomain = ((FuzzySet) result[2]); + descriptionLabel.setText(unifiedDomain.formatDescriptionDomain()); + } else { + levelLabel.setText(""); //$NON-NLS-1$ + nameLabel.setText(""); //$NON-NLS-1$ + descriptionLabel.setText(""); //$NON-NLS-1$ + } + } + + + + +} diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/Messages.java b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/Messages.java new file mode 100644 index 0000000..d8ffb4f --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/Messages.java @@ -0,0 +1,10 @@ +package flintstones.method.common.phase.generateUnificationDomain.ui.messages; + +public class Messages { + + public String Domain_description; + public String Domain_level; + public String Domain_name; + +} + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/messages.properties b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/messages.properties new file mode 100644 index 0000000..0e9741e --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/messages.properties @@ -0,0 +1,3 @@ +Domain_description=Domain description +Domain_level=Domain level +Domain_name=Domain name diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/messages_es.properties b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/messages_es.properties new file mode 100644 index 0000000..3f60f46 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain.ui/src/flintstones/method/common/phase/generateUnificationDomain/ui/messages/messages_es.properties @@ -0,0 +1,3 @@ +Domain_description=Descripcin de dominio +Domain_level=Nivel de dominio +Domain_name=Nombre de dominio diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/.classpath b/bundles/flintstones.method.common.phase.generateUnificationDomain/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/.polyglot.META-INF b/bundles/flintstones.method.common.phase.generateUnificationDomain/.polyglot.META-INF new file mode 100644 index 0000000..4e9037f --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.generateUnificationDomain + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] GenerateUnificationDomain + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/.project b/bundles/flintstones.method.common.phase.generateUnificationDomain/.project new file mode 100644 index 0000000..e4034b1 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.generateUnificationDomain + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362649 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.generateUnificationDomain/META-INF/MANIFEST.MF new file mode 100644 index 0000000..abbec48 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: GenerateUnificationDomain +Bundle-SymbolicName: flintstones.method.common.phase.generateUnificationDomain;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.generateUnificationDomain +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: javax.inject, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.domain.fuzzyset, + org.eclipse.e4.core.contexts, + flintstones.model.problemelement.service, + org.eclipse.e4.core.di, + flintstones.entity.domain, + flintstones.entity.method.phase +Export-Package: flintstones.method.common.phase.generateUnificationDomain diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/build.properties b/bundles/flintstones.method.common.phase.generateUnificationDomain/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/plugin.xml b/bundles/flintstones.method.common.phase.generateUnificationDomain/plugin.xml new file mode 100644 index 0000000..a3f91f7 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.generateUnificationDomain/src/flintstones/method/common/phase/generateUnificationDomain/GenerateUnificationDomainModel.java b/bundles/flintstones.method.common.phase.generateUnificationDomain/src/flintstones/method/common/phase/generateUnificationDomain/GenerateUnificationDomainModel.java new file mode 100644 index 0000000..102f7a4 --- /dev/null +++ b/bundles/flintstones.method.common.phase.generateUnificationDomain/src/flintstones/method/common/phase/generateUnificationDomain/GenerateUnificationDomainModel.java @@ -0,0 +1,198 @@ + +package flintstones.method.common.phase.generateUnificationDomain; + +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + + + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +@SuppressWarnings("javadoc") +public class GenerateUnificationDomainModel extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + @Inject + IEclipseContext context; + + private List _elhDomains; + + private FuzzySet _unifiedDomain; + + @Override + public String getName() { + return "Generate Unification Domain"; + } + + public void export() { + this.exportData("unifiedDomain",_unifiedDomain); + this.exportData("elhDomains",_elhDomains, true); + } + + private class MyComparator implements Comparator { + @Override + public int compare(Object[] o1, Object[] o2) { + return Double.compare((Integer) o1[0], (Integer) o2[0]); + } + } + + private FuzzySet generateUnifiedDomain(Set sizes) { + + FuzzySet result = null; + + if(sizes.size() != 0) { + Integer[] formerModalPoints = sizes.toArray(new Integer[0]); + for(int i = 0; i < formerModalPoints.length; i++) { + formerModalPoints[i] = formerModalPoints[i] - 1; + } + + int unifiedDomainSize = lcm(formerModalPoints) + 1; + + if(!sizes.contains(unifiedDomainSize)) { + result = ContextInjectionFactory.make(FuzzySet.class, context); + + String[] labels = new String[unifiedDomainSize]; + for(int i = 0; i < unifiedDomainSize; i++) { + labels[i] = "s" + i; //$NON-NLS-1$ + } + result.createTrapezoidalFunction(labels); + } + } + + return result; + } + + + public List generateLH() { + + _elhDomains = new LinkedList(); + + List domains = new LinkedList(); + Set domainsNames = new HashSet(); + int i = 1, cardinality; + + String domainName; + Domain generateDomain, domain; + + for(ProblemElement alternative : problemService.getAll(Alternative.Type)) { + for(ProblemElement criterion : problemService.getAll(Criterion.Type)) { + if(!criterion.hasChildren()) { + for(ProblemElement expert : problemService.getAll(Expert.Type)) { + if(!expert.hasChildren()) { + Valuation v = valuationService.getValuationFor(new ProblemElementKey((Expert)expert, (Alternative)alternative, (Criterion)criterion)); + if(v != null) { + generateDomain = v.getDomain(); + if(generateDomain != null) { + domainName = generateDomain.getName(); + if(generateDomain instanceof FuzzySet) { + if(!domainsNames.contains(domainName)) { + if(((FuzzySet) generateDomain).isBLTS()) { + cardinality = ((FuzzySet) generateDomain).getLabelSet().getCardinality(); + domains.add(new Object[] { cardinality, domainName, generateDomain }); + domainsNames.add(domainName); + } + } + } else { + return null; + } + } + } + } + } + } + } + } + + Collections.sort(domains, new MyComparator()); + + Integer value; + i = 0; + Set sizes = new HashSet(); + int oldValue = -1; + for(Object[] entry : domains) { + value = (Integer) entry[0]; + sizes.add(value); + if(oldValue != value) { + oldValue = value; + i++; + } + entry[0] = "l(" + i + "," + value + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + _elhDomains.addAll(domains); + + String generate = "Generate"; + domain = generateUnifiedDomain(sizes); + int index; + if(domain != null) { + domainName = generate; + + index = 1; + while(domainsNames.contains(domainName)) { + domainName = generate + "_" + index++; //$NON-NLS-1$ + } + + cardinality = ((FuzzySet) domain).getLabelSet().getCardinality(); + if(cardinality != oldValue) { + i++; + } + + domain.setName(domainName); + domainsNames.add(domainName); + + _elhDomains.add(new Object[] { "l(" + i + "," + cardinality + ")", domainName, domain }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + _unifiedDomain = (FuzzySet) ((FuzzySet) _elhDomains.get(_elhDomains.size() - 1)[2]).clone(); + + return _elhDomains; + } + + + private int lcm(Integer[] input) { + int result = input[0]; + for(int i = 1; i < input.length; i++) { + result = lcm(result, input[i]); + } + + return result; + } + + private int lcm(int a, int b) { + return a * (b / gcd(a, b)); + } + + private int gcd(int a, int b) { + int aux; + while(b > 0) { + aux = b; + b = a % b; + a = aux; + } + return a; + } +} diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/.classpath b/bundles/flintstones.method.common.phase.selectBLTS.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.selectBLTS.ui/.polyglot.META-INF new file mode 100644 index 0000000..5d4c881 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.selectBLTS.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/.project b/bundles/flintstones.method.common.phase.selectBLTS.ui/.project new file mode 100644 index 0000000..6f5738d --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.selectBLTS.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362651 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.selectBLTS.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6ad62de --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/build.properties b/bundles/flintstones.method.common.phase.selectBLTS.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/plugin.xml b/bundles/flintstones.method.common.phase.selectBLTS.ui/plugin.xml new file mode 100644 index 0000000..da33af2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/SelectBLTSUi.java b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/SelectBLTSUi.java new file mode 100644 index 0000000..69ebff4 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/SelectBLTSUi.java @@ -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 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 domains = getBLTSDomains(); + FuzzySet selected = (FuzzySet) domains.get(0); + phaseModel.setUnifiedDomain(selected); + } + + public void createPartControl(Composite parent) { + + phaseModel = (SelectBLTSPhase) this.getModel(); + + domains = new LinkedList(); + 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) 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 getBLTSDomains() { + + List domains = Arrays.asList(domainService.getAll()); + + List bltsDomains = new LinkedList(); + + for (Domain domain : domains) { + if (domain instanceof FuzzySet) { + FuzzySet fDomain = (FuzzySet) domain; + if (fDomain.isBLTS()) { + bltsDomains.add(domain); + } + } + } + + return bltsDomains; + + } + + private FuzzySet getBLTSWithMaximumGranularity(List 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(); + } + } + +} diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/Messages.java b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/Messages.java new file mode 100644 index 0000000..902995c --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/Messages.java @@ -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; + +} diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/messages.properties b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/messages.properties new file mode 100644 index 0000000..2a9b2be --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/messages.properties @@ -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 diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/messages_es.properties b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/messages_es.properties new file mode 100644 index 0000000..fbdd009 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/selectBLTS/ui/messages/messages_es.properties @@ -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 diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/unification/ui/dialog/NewBLTSDomainDialog.java b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/unification/ui/dialog/NewBLTSDomainDialog.java new file mode 100644 index 0000000..46148eb --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/unification/ui/dialog/NewBLTSDomainDialog.java @@ -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 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; + } +} diff --git a/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/unification/ui/dialog/SemanticDialog.java b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/unification/ui/dialog/SemanticDialog.java new file mode 100644 index 0000000..338e176 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS.ui/src/flintstones/method/common/phase/unification/ui/dialog/SemanticDialog.java @@ -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 _textValues; + private List _controlDecorations; + private List _values = new LinkedList();; + + @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(); + _controlDecorations = new LinkedList(); + 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 getValues() { + return _values; + } + + @Override + protected void buttonPressed(int buttonId) { + setReturnCode(buttonId); + close(); + } +} diff --git a/bundles/flintstones.method.common.phase.selectBLTS/.classpath b/bundles/flintstones.method.common.phase.selectBLTS/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.selectBLTS/.polyglot.META-INF b/bundles/flintstones.method.common.phase.selectBLTS/.polyglot.META-INF new file mode 100644 index 0000000..fda6e91 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.selectBLTS + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] SelectBLTS + diff --git a/bundles/flintstones.method.common.phase.selectBLTS/.project b/bundles/flintstones.method.common.phase.selectBLTS/.project new file mode 100644 index 0000000..32dcbb6 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.selectBLTS + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362650 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.selectBLTS/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.selectBLTS/META-INF/MANIFEST.MF new file mode 100644 index 0000000..622d361 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: SelectBLTS +Bundle-SymbolicName: flintstones.method.common.phase.selectBLTS;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.selectBLTS +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.domain.fuzzyset, + org.eclipse.e4.core.services, + flintstones.entity.domain, + javax.inject, + flintstones.entity.method.phase +Export-Package: flintstones.method.common.phase.selectBLTS diff --git a/bundles/flintstones.method.common.phase.selectBLTS/build.properties b/bundles/flintstones.method.common.phase.selectBLTS/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.selectBLTS/plugin.xml b/bundles/flintstones.method.common.phase.selectBLTS/plugin.xml new file mode 100644 index 0000000..442f7ad --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/plugin.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/SelectBLTSPhase.java b/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/SelectBLTSPhase.java new file mode 100644 index 0000000..8ad013d --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/SelectBLTSPhase.java @@ -0,0 +1,52 @@ +package flintstones.method.common.phase.selectBLTS; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.method.common.phase.selectBLTS.messages.Messages; + +/** + * The Class SelectBLTSPhase. + */ +public class SelectBLTSPhase extends PhaseMethod { + + /** The unified domain. */ + private FuzzySet unifiedDomain; + + /** The messages. */ + @Inject + @Translation + Messages messages; + + /* (non-Javadoc) + * @see flintstones.phasemethod.PhaseMethod#getName() + */ + @Override + public String getName() { + return "Select BLTS"; + } + + /** + * Sets the unified domain. + * + * @param selectedDomain the new unified domain + */ + public void setUnifiedDomain(FuzzySet selectedDomain) { + this.unifiedDomain = selectedDomain; + this.exportData("unifiedDomain", selectedDomain); + } + + /** + * Gets the unified domain. + * + * @return the unified domain + */ + public Domain getUnifiedDomain() { + return this.unifiedDomain; + } + +} diff --git a/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/Messages.java b/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/Messages.java new file mode 100644 index 0000000..9c5156f --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/Messages.java @@ -0,0 +1,12 @@ +//This file has been auto-generated +package flintstones.method.common.phase.selectBLTS.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Select_BLTS_name; + +} diff --git a/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/messages.properties b/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/messages.properties new file mode 100644 index 0000000..0031e1e --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/messages.properties @@ -0,0 +1,3 @@ + +Select_BLTS_name=Select BLTS + diff --git a/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/messages_es.properties b/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/messages_es.properties new file mode 100644 index 0000000..08054a7 --- /dev/null +++ b/bundles/flintstones.method.common.phase.selectBLTS/src/flintstones/method/common/phase/selectBLTS/messages/messages_es.properties @@ -0,0 +1,3 @@ + +Select_BLTS_name=Elegir BLTS + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.classpath b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.polyglot.META-INF new file mode 100644 index 0000000..c054f78 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.sensitiveanalysis.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Sensitive analysis phase ui + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.project b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.project new file mode 100644 index 0000000..796cc61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.sensitiveanalysis.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362653 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..16cce8c --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Sensitive analysis phase ui +Bundle-SymbolicName: flintstones.method.common.phase.sensitiveanalysis.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.sensitiveanalysis.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.method.common.phase.sensitiveanalysis, + flintstones.model.sensitiveanalysismodel.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui, + flintstones.model.ui.service, + flintstones.helper.html, + org.eclipse.jface, + org.eclipse.e4.core.di.annotations, + javax.inject, + flintstones.entity.sensitiveanalysismodel, + org.jfree.chart.jfreechart, + flintstones.model.problemelement.service diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/build.properties b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/plugin.xml b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/plugin.xml new file mode 100644 index 0000000..7c3e225 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/src/flintstones/method/common/phase/sensitiveanalysis/ui/SensitiveAnalysisUi.java b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/src/flintstones/method/common/phase/sensitiveanalysis/ui/SensitiveAnalysisUi.java new file mode 100644 index 0000000..31c53bc --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis.ui/src/flintstones/method/common/phase/sensitiveanalysis/ui/SensitiveAnalysisUi.java @@ -0,0 +1,293 @@ +package flintstones.method.common.phase.sensitiveanalysis.ui; + +import javax.inject.Inject; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Combo; +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.jfree.chart.swt.ChartComposite; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel.FieldsChanges; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; +import flintstones.entity.sensitiveanalysismodel.ui.chart.RankingEvolutionChart; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.common.phase.sensitiveanalysis.SensitiveAnalysisPhase; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.sensitiveanalysismodel.service.ISensitiveAnalysisModelService; +import flintstones.model.ui.service.UiService; + +public class SensitiveAnalysisUi extends PhaseMethodUI { + + SensitiveAnalysisModelUi saModel; + + SensitiveAnalysisPhase model; + + @Inject + ISensitiveAnalysisModelService saService; + + @Inject + IProblemElementService problemService; + + Combo selectModelCombo; + Combo selectProblemCombo; + Combo selectChangeCombo; + Combo selectCriterionCombo; + + HtmlTextTable dmTable; + HtmlTextTable rankingTable; + HtmlTextTable changesTable; + + Composite decisionMatrixSection; + Composite rankingSection; + Composite changesSection; + Composite bottomSection; + + RankingEvolutionChart chart; + + @Override + public void init() { + createPartControl(this.baseComposite); + } + + public void createPartControl(Composite parent) { + + model = (SensitiveAnalysisPhase) this.getModel(); + + UiService.setGridData(parent, 9, 9, true, true); + UiService.setGridLayout(parent, 1, true); + + createHeader(parent); + + Composite body = new Composite(parent, SWT.NONE); + UiService.setGridData(body, 9, 9, true, true); + UiService.setGridLayout(body, 2, false); + + executeSensitiveAnalysisModel(); + + createLeftPart(body); + createRightPart(body); + createBottomPart(parent); + } + + private void createHeader(Composite parent) { + Composite header = new Composite(parent, SWT.NONE); + UiService.setGridLayout(header, 3, true); + UiService.setGridData(header, 0, 1, true, false); + + createLeftHeader(header); + createCentertHeader(header); + createRightHeader(header); + } + + private void createLeftHeader(Composite header) { + Composite leftHeader = new Composite(header, SWT.NONE); + UiService.setGridLayout(leftHeader, 2, false); + UiService.setGridData(leftHeader, 9, 9, true, true); + Label selectProblemLabel = new Label(leftHeader, SWT.NONE); + selectProblemLabel.setText("Select the problem"); + selectProblemCombo = new Combo(leftHeader, SWT.READ_ONLY); + selectProblemCombo.setItems(model.getSensitiveAnalysisProblemsIds()); + selectProblemCombo.select(0); + selectProblemCombo.addSelectionListener(createSelectionProblemListener()); + } + + private SelectionAdapter createSelectionProblemListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + executeSensitiveAnalysisModel(); + redrawChangesTable(); + } + }; + } + + private void executeSensitiveAnalysisModel() { + String problemId = selectProblemCombo.getText(); + String modelName = selectModelCombo.getText(); + saModel = saService.get(model.getSensitiveAnalysisModel(problemId, modelName).getId()); + model.executeSensitiveAnalysisModel(saModel.getModel()); + } + + private void createCentertHeader(Composite header) { + Composite centerHeader = new Composite(header, SWT.NONE); + UiService.setGridLayout(centerHeader, 2, false); + UiService.setGridData(centerHeader, 9, 9, true, true); + Label selectModelLabel = new Label(centerHeader, SWT.NONE); + selectModelLabel.setText("Select the model"); + selectModelCombo = new Combo(centerHeader, SWT.READ_ONLY); + selectModelCombo.setItems(model.getSensitiveAnalysisModelsNames(selectProblemCombo.getText())); + selectModelCombo.select(0); + UiService.setGridData(selectModelCombo, 9, 9, true, true); + selectModelCombo.addSelectionListener(createSelectionModelListener()); + } + + private SelectionAdapter createSelectionModelListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + refresh(); + } + }; + } + + private void createRightHeader(Composite header) { + Composite rightHeader = new Composite(header, SWT.NONE); + UiService.setGridLayout(rightHeader, 2, false); + UiService.setGridData(rightHeader, 9, 9, true, true); + Label selectChangesLabel = new Label(rightHeader, SWT.NONE); + selectChangesLabel.setText("Select type of changes"); + selectChangeCombo = new Combo(rightHeader, SWT.READ_ONLY); + selectChangeCombo.setItems(new String[] {"Absolute", "Relative"}); + selectChangeCombo.select(0); + UiService.setGridData(selectChangeCombo, 9, 9, true, true); + selectChangeCombo.addSelectionListener(createSelectionChangeListener()); + } + + private SelectionListener createSelectionChangeListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + saModel.refreshChangesTable(getTypeChange()); + } + }; + } + + private void createLeftPart(Composite body) { + Composite leftPart = new Composite(body, SWT.NONE); + UiService.setGridLayout(leftPart, 1, true); + UiService.setGridData(leftPart, 9, 9, true, true); + createDecisionMatrix(leftPart); + createRanking(leftPart); + } + + private void createDecisionMatrix(Composite leftPart) { + decisionMatrixSection = new Composite(leftPart, SWT.NONE); + UiService.setGridData(decisionMatrixSection, 9, 9, true, true); + UiService.setGridLayout(decisionMatrixSection, 1, true); + + dmTable = saModel.createDecisionMatrixTable(decisionMatrixSection); + + dmTable.render(); + } + + private void createRanking(Composite leftPart) { + rankingSection = new Composite(leftPart, SWT.NONE); + UiService.setGridData(rankingSection, 9, 9, true, true); + UiService.setGridLayout(rankingSection, 1, true); + + rankingTable = saModel.createRankingTable(rankingSection); + + rankingTable.render(); + } + + private void createRightPart(Composite body) { + Composite rigthPart = new Composite(body, SWT.NONE); + UiService.setGridLayout(rigthPart, 1, true); + UiService.setGridData(rigthPart, 9, 9, true, true); + createChangesMatrix(rigthPart); + } + + private void createChangesMatrix(Composite rigthPart) { + changesSection = new Composite(rigthPart, SWT.NONE); + UiService.setGridData(changesSection, 9, 9, true, true); + UiService.setGridLayout(changesSection, 1, true); + + changesTable = saModel.createChangesTable(changesSection, getTypeChange()); + + changesTable.render(); + } + + private FieldsChanges getTypeChange() { + if(selectChangeCombo.getText().equals("Relative")) + return FieldsChanges.relative; + return FieldsChanges.absolute; + } + + private void createBottomPart(Composite parent) { + bottomSection = new Composite(parent, SWT.BORDER); + bottomSection.setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + UiService.setGridData(bottomSection, 9, 9, true, true); + bottomSection.addControlListener(createResizeListener()); + selectCriterionCombo = new Combo(parent, SWT.NONE); + selectCriterionCombo.setItems(saModel.getCriteriaIds()); + selectCriterionCombo.addSelectionListener(createCriterionSelection()); + selectCriterionCombo.select(0); + } + + private ControlListener createResizeListener() { + return new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + for(Control child: bottomSection.getChildren()) { + if(child instanceof ChartComposite) + child.dispose(); + } + chart = saModel.createRankingEvolutionChart(bottomSection, problemService.getMainElements(Criterion.Type), + (Criterion) problemService.getByName(Criterion.Type, selectCriterionCombo.getText()), + bottomSection.getSize().x, bottomSection.getSize().y, SWT.NONE); + } + }; + } + + private SelectionListener createCriterionSelection() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + chart.refreshChart((Criterion) problemService.getByName(Criterion.Type, selectCriterionCombo.getText())); + } + }; + } + + @Override + public void refresh() { + executeSensitiveAnalysisModel(); + refreshChart(); + redrawDecisionMatrix(); + redrawRankingTable(); + redrawChangesTable(); + } + + private void refreshChart() { + for(Control child: bottomSection.getChildren()) + child.dispose(); + chart = saModel.createRankingEvolutionChart(bottomSection, problemService.getMainElements(Criterion.Type), + (Criterion) problemService.getByName(Criterion.Type, selectCriterionCombo.getText()), + bottomSection.getSize().x, bottomSection.getSize().y, SWT.NONE); + } + + private void redrawDecisionMatrix() { + dmTable.dispose(); + dmTable = saModel.createDecisionMatrixTable(decisionMatrixSection); + dmTable.render(); + } + + private void redrawRankingTable() { + rankingTable.dispose(); + rankingTable = saModel.createRankingTable(rankingSection); + rankingTable.render(); + } + + private void redrawChangesTable() { + changesTable.dispose(); + changesTable = saModel.createChangesTable(changesSection, getTypeChange()); + changesTable.render(); + } + + @Override + protected boolean isForwardEnabled() { + return false; + } + +} diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/.classpath b/bundles/flintstones.method.common.phase.sensitiveanalysis/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/.polyglot.META-INF b/bundles/flintstones.method.common.phase.sensitiveanalysis/.polyglot.META-INF new file mode 100644 index 0000000..eefdef2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.sensitiveanalysis + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Sensitive analysis phase + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/.project b/bundles/flintstones.method.common.phase.sensitiveanalysis/.project new file mode 100644 index 0000000..7be37b0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.sensitiveanalysis + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362651 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.sensitiveanalysis/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d3132c4 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Sensitive analysis phase +Bundle-SymbolicName: flintstones.method.common.phase.sensitiveanalysis;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.phase.sensitiveanalysis +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.model.problemelement.service, + flintstones.helper.data, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.entity.sensitiveanalysisproblem, + flintstones.entity.sensitiveanalysismodel, + javax.inject +Export-Package: flintstones.method.common.phase.sensitiveanalysis diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/build.properties b/bundles/flintstones.method.common.phase.sensitiveanalysis/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/plugin.xml b/bundles/flintstones.method.common.phase.sensitiveanalysis/plugin.xml new file mode 100644 index 0000000..d93fa2b --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.sensitiveanalysis/src/flintstones/method/common/phase/sensitiveanalysis/SensitiveAnalysisPhase.java b/bundles/flintstones.method.common.phase.sensitiveanalysis/src/flintstones/method/common/phase/sensitiveanalysis/SensitiveAnalysisPhase.java new file mode 100644 index 0000000..d1d4789 --- /dev/null +++ b/bundles/flintstones.method.common.phase.sensitiveanalysis/src/flintstones/method/common/phase/sensitiveanalysis/SensitiveAnalysisPhase.java @@ -0,0 +1,56 @@ +package flintstones.method.common.phase.sensitiveanalysis; + +import java.util.HashMap; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.sensitiveanalysisproblem.service.ISensitiveAnalysisProblemService; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public class SensitiveAnalysisPhase extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + ISensitiveAnalysisProblemService saProblemService; + + public SensitiveAnalysisPhase() {} + + @Override + public String getName() { + return "Sensitive analysis"; + } + + @SuppressWarnings("unchecked") + public void executeSensitiveAnalysisModel(SensitiveAnalysisModel saModel) { + saModel.execute((HashMatrix) this.importData("decisionmatrix"), + (HashMap) this.importData("criterionWeights")); + } + + public String[] getSensitiveAnalysisProblemsIds() { + return saProblemService.getSensitiveAnalysisProblemsIdsFor(checkValuationType()); + } + + @SuppressWarnings("unchecked") + private String checkValuationType() { + HashMatrix decisionMatrix = + (HashMatrix) this.importData("decisionmatrix"); + return decisionMatrix.get(problemService.getAll(Alternative.Type)[0], problemService.getMainElements(Criterion.Type)[0]).getId(); + } + + public SensitiveAnalysisModel getSensitiveAnalysisModel(String problemId, String modelId) { + return saProblemService.getSensitiveAnalysisModel(problemId, modelId, checkValuationType()); + } + + public String[] getSensitiveAnalysisModelsNames(String problemId) { + return saProblemService.getSensitiveAnalysisModelsNamesFor(problemId, checkValuationType()); + } +} diff --git a/bundles/flintstones.method.common.phase.unification.ui/.classpath b/bundles/flintstones.method.common.phase.unification.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.unification.ui/.polyglot.META-INF b/bundles/flintstones.method.common.phase.unification.ui/.polyglot.META-INF new file mode 100644 index 0000000..c56faa8 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.unification.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.common.phase.unification.ui/.project b/bundles/flintstones.method.common.phase.unification.ui/.project new file mode 100644 index 0000000..c429adc --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.unification.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362654 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.unification.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.unification.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..dd23fb6 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.common.phase.unification.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.unification.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.method.common.phase.unification, + flintstones.operator, + flintstones.valuation.twoTuple, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.linguistic, + flintstones.entity.problemelement, + flintstones.valuation.unifiedValuation, + flintstones.domain.fuzzyset.ui.dialog, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.helper.ui, + javax.inject, + flintstones.entity.domain, + 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 +Bundle-ActivationPolicy: lazy +Export-Package: flintstones.method.common.phase.unification.ui.messages, + flintstones.method.common.phase.unification.ui.provider diff --git a/bundles/flintstones.method.common.phase.unification.ui/build.properties b/bundles/flintstones.method.common.phase.unification.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.unification.ui/plugin.xml b/bundles/flintstones.method.common.phase.unification.ui/plugin.xml new file mode 100644 index 0000000..116cd92 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/UnificationUi.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/UnificationUi.java new file mode 100644 index 0000000..ca67e43 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/UnificationUi.java @@ -0,0 +1,279 @@ +package flintstones.method.common.phase.unification.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.nls.Translation; +import org.eclipse.jface.viewers.ITreeViewerListener; +import org.eclipse.jface.viewers.TreeExpansionEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.method.common.phase.unification.UnificationPhase; +import flintstones.method.common.phase.unification.ui.comparator.UnificationTreeViewerComparator; +import flintstones.method.common.phase.unification.ui.messages.Messages; +import flintstones.method.common.phase.unification.ui.provider.AlternativeColumnLabelProvider; +import flintstones.method.common.phase.unification.ui.provider.CriterionColumnLabelProvider; +import flintstones.method.common.phase.unification.ui.provider.DomainNameColumnLabelProvider; +import flintstones.method.common.phase.unification.ui.provider.EvaluationColumnLabelProvider; +import flintstones.method.common.phase.unification.ui.provider.ExpertColumnLabelProvider; +import flintstones.method.common.phase.unification.ui.provider.UnificationTreeViewerContentProvider; +import flintstones.method.common.phase.unification.ui.provider.UnifiedEvaluationColumnLabelProvider; +import flintstones.model.ui.service.UiService; + +public class UnificationUi extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + @Inject + @Translation + Messages messages; + + public static final String ID = "flintstones.phasemethod.unification.ui.view.unification"; //$NON-NLS-1$ + + private Composite _parent; + + private TreeViewer _treeViewer; + private Tree _tree; + + private Label domainLabel; + //private Button costValuation; + + private TreeViewerColumn _treeViewerExpertColumn; + private TreeColumn _treeExpertColumn; + private TreeViewerColumn _treeViewerAlternativeColumn; + private TreeColumn _treeAlternativeColumn; + private TreeViewerColumn _treeViewerCriterionColumn; + private TreeColumn _treeCriterionColumn; + private TreeViewerColumn _treeViewerDomainColumn; + private TreeColumn _treeDomainColumn; + private TreeViewerColumn _treeViewerEvaluationColumn; + private TreeColumn _treeEvaluationColumn; + private TreeViewerColumn _treeViewerUnifiedEvaluationColumn; + private TreeColumn _treeUnifiedEvaluationColumn; + UnificationPhase phaseMethod; + + @Override + public void init() { + phaseMethod = (UnificationPhase) this.getModel(); + + createPartControl(this.baseComposite); + phaseMethod.initDomain(); + compute(false); + domainLabel.setText(phaseMethod.getUnificationDomain().formatDescriptionDomain()); + } + + @Override + public void refresh() { + if(!phaseMethod.getUnificationDomain().equals(phaseMethod.getImportedDomain())) { + phaseMethod.initDomain(); + domainLabel.setText(phaseMethod.getUnificationDomain().formatDescriptionDomain()); + //if(costValuation.getSelection()) { + // compute(true); + //} else { + compute(false); + //} + } + } + + @Override + public boolean isSkippable() { + return false; + } + + @Override + public void beforeSkip() { + } + + private void compute(boolean changeCostValuations) { + UnificationTreeViewerContentProvider provider = new UnificationTreeViewerContentProvider(phaseMethod.unify(changeCostValuations)); + ContextInjectionFactory.inject(provider, context); + _treeViewer.setContentProvider(provider); + _treeViewer.setInput(provider.getInput()); + packColumns(); + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + public void createPartControl(Composite base) { + + _parent = base; + + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + _parent.setLayoutData(gridData); + GridLayout layout = new GridLayout(1, true); + layout.horizontalSpacing = 15; + layout.marginLeft = 20; + layout.marginRight = 20; + layout.marginBottom = 15; + layout.marginTop = 20; + _parent.setLayout(layout); + + createEvaluationsTable(); + //createCheckBoxCostValuations(); + + domainLabel = new Label(_parent,0); + UiService.setGridData(domainLabel, 0, 0, true, false); + + } + + private void createEvaluationsTable() { + Composite container = new Composite(_parent, SWT.NONE); + + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + gridData.verticalIndent = 0; + container.setLayoutData(gridData); + GridLayout gl_container = new GridLayout(1, false); + gl_container.verticalSpacing = 0; + gl_container.marginWidth = 0; + gl_container.marginHeight = 0; + gl_container.horizontalSpacing = 0; + container.setLayout(gl_container); + UiService.setGridData(container, 9, 9, true, true); + + _treeViewer = new TreeViewer(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + _treeViewer.setComparator(new UnificationTreeViewerComparator()); + _tree = _treeViewer.getTree(); + _tree.setHeaderVisible(true); + _tree.setLinesVisible(true); + _tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + _treeViewer.addTreeListener(new ITreeViewerListener() { + + @Override + public void treeExpanded(TreeExpansionEvent event) { + Display.getDefault() + .asyncExec(new Runnable() { + public void run() { + if (_tree != null) { + if (!_tree.isDisposed()) { + for (TreeColumn column : _tree.getColumns()) { + column.pack(); + } + } + } + } + }); + } + + @Override + public void treeCollapsed(TreeExpansionEvent event) { + Display.getDefault() + .asyncExec(new Runnable() { + public void run() { + if (_tree != null) { + if (!_tree.isDisposed()) { + for (TreeColumn column : _tree.getColumns()) { + column.pack(); + } + } + } + } + }); + } + }); + + _treeViewerUnifiedEvaluationColumn = new TreeViewerColumn(_treeViewer, SWT.NONE); + _treeUnifiedEvaluationColumn = _treeViewerUnifiedEvaluationColumn.getColumn(); + _treeUnifiedEvaluationColumn.setWidth(125); + _treeUnifiedEvaluationColumn.setText(messages.Unification_Unified); + _treeUnifiedEvaluationColumn.setImage(UiService.getImage("valuation.png").createImage()); + _treeUnifiedEvaluationColumn.addSelectionListener(getSelectionAdapter(_treeEvaluationColumn, 5)); + _treeViewerUnifiedEvaluationColumn.setLabelProvider(new UnifiedEvaluationColumnLabelProvider()); + + _treeViewerExpertColumn = new TreeViewerColumn(_treeViewer, SWT.NONE); + _treeExpertColumn = _treeViewerExpertColumn.getColumn(); + _treeExpertColumn.setWidth(125); + _treeExpertColumn.setText(messages.Unification_Expert); + + _treeExpertColumn.setImage(UiService.getImage("valuation.png").createImage()); + _treeExpertColumn.addSelectionListener(getSelectionAdapter(_treeExpertColumn, 0)); + _treeViewerExpertColumn.setLabelProvider(new ExpertColumnLabelProvider()); + + _treeViewerAlternativeColumn = new TreeViewerColumn(_treeViewer, SWT.NONE); + _treeAlternativeColumn = _treeViewerAlternativeColumn.getColumn(); + _treeAlternativeColumn.setWidth(125); + _treeAlternativeColumn.setText(messages.Unification_Alternative); + _treeAlternativeColumn.setImage(UiService.getImage("alternative.png").createImage()); + _treeAlternativeColumn.addSelectionListener(getSelectionAdapter(_treeAlternativeColumn, 1)); + _treeViewerAlternativeColumn.setLabelProvider(new AlternativeColumnLabelProvider()); + + _treeViewerCriterionColumn = new TreeViewerColumn(_treeViewer, SWT.NONE); + _treeCriterionColumn = _treeViewerCriterionColumn.getColumn(); + _treeCriterionColumn.setWidth(125); + _treeCriterionColumn.setText(messages.Unification_Criterion); + _treeCriterionColumn.setImage(UiService.getImage("criteria.png").createImage()); + _treeCriterionColumn.addSelectionListener(getSelectionAdapter(_treeCriterionColumn, 2)); + _treeViewerCriterionColumn.setLabelProvider(new CriterionColumnLabelProvider()); + + _treeViewerDomainColumn = new TreeViewerColumn(_treeViewer, SWT.NONE); + _treeDomainColumn = _treeViewerDomainColumn.getColumn(); + _treeDomainColumn.setWidth(125); + _treeDomainColumn.setText(messages.Unification_Source_domain); + _treeDomainColumn.setImage(UiService.getImage("domain.png").createImage()); + _treeDomainColumn.addSelectionListener(getSelectionAdapter(_treeDomainColumn, 3)); + _treeViewerDomainColumn.setLabelProvider(new DomainNameColumnLabelProvider()); + + _treeViewerEvaluationColumn = new TreeViewerColumn(_treeViewer, SWT.NONE); + _treeEvaluationColumn = _treeViewerEvaluationColumn.getColumn(); + _treeEvaluationColumn.setWidth(125); + _treeEvaluationColumn.setText(messages.Unification_Evaluation); + _treeEvaluationColumn.setImage(UiService.getImage("valuation.png").createImage()); + _treeEvaluationColumn.addSelectionListener(getSelectionAdapter(_treeEvaluationColumn, 4)); + _treeViewerEvaluationColumn.setLabelProvider(new EvaluationColumnLabelProvider()); + } + + private SelectionAdapter getSelectionAdapter(final TreeColumn column, final int index) { + + SelectionAdapter selectionAdapter = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + UnificationTreeViewerComparator comparator = (UnificationTreeViewerComparator) _treeViewer.getComparator(); + comparator.setColumn(index); + int dir = comparator.getDirection(); + _treeViewer.getTree().setSortDirection(dir); + _treeViewer.getTree().setSortColumn(column); + _treeViewer.refresh(); + } + }; + return selectionAdapter; + } + + /* + private void createCheckBoxCostValuations() { + costValuation = new Button(_parent, SWT.CHECK); + costValuation.setText("Transform cost evaluations"); + costValuation.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if(costValuation.getSelection()) { + compute(true); + } else { + compute(false); + } + } + }); + }*/ + + private void packColumns() { + for(TreeColumn tc: _treeViewer.getTree().getColumns()) { + tc.pack(); + } + } + +} diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/comparator/UnificationTreeViewerComparator.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/comparator/UnificationTreeViewerComparator.java new file mode 100644 index 0000000..c740fd6 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/comparator/UnificationTreeViewerComparator.java @@ -0,0 +1,106 @@ +package flintstones.method.common.phase.unification.ui.comparator; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; + +import flintstones.method.common.phase.unification.ui.provider.EvaluationColumnLabelProvider; + +@SuppressWarnings("javadoc") +public class UnificationTreeViewerComparator extends ViewerComparator { + + private int _propertyIndex; + private static final int DESCENDING = SWT.DOWN; + private static final int ASCENDING = SWT.UP; + private int direction = ASCENDING; + + public UnificationTreeViewerComparator() { + _propertyIndex = 0; + direction = ASCENDING; + } + + public int getDirection() { + return direction; + } + + public void setColumn(int column) { + if (column == _propertyIndex) { + if (direction == DESCENDING) { + direction = ASCENDING; + } else { + direction = DESCENDING; + } + } else { + _propertyIndex = column; + direction = ASCENDING; + } + } + + public int compare(Object[] e1, Object[] e2, int pos) { + + String text1; + String text2; + + int result; + if (pos < 4) { + result = ((String) e1[pos]).compareTo((String) e2[pos]); + } else if (pos == 4) { + result = compare(e1, e2, 5); + } else if (pos == 5) { + EvaluationColumnLabelProvider eclp = new EvaluationColumnLabelProvider(); + text1 = eclp.getText(e1); + text2 = eclp.getText(e2); + result = text1.compareTo(text2); + } else { + result = 0; + } + + if (result == 0) { + if (pos == _propertyIndex) { + if (pos != 0) { + result = compare(e1, e2, 0); + } else { + if (pos < 5) { + result = compare(e1, e2, pos + 1); + } + } + } else if (pos < _propertyIndex) { + if ((pos + 1) != _propertyIndex) { + result = compare(e1, e2, pos + 1); + } else { + if (_propertyIndex < 5) { + result = compare(e1, e2, pos + 2); + } + } + } else if (pos > _propertyIndex) { + if ((pos + 1) < 5) { + result = compare(e1, e2, pos + 1); + } + } + } + return result; + } + + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + + int result; + + if ((e1 instanceof Object[]) && (e2 instanceof Object[])) { + Object[] evaluation1 = (Object[]) e1; + Object[] evaluation2 = (Object[]) e2; + result = compare(evaluation1, evaluation2, _propertyIndex); + + if (direction == DESCENDING) { + result = -result; + } + + } else { + result = 0; + } + + return result; + } + +} + diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/Messages.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/Messages.java new file mode 100644 index 0000000..f9a9e53 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/Messages.java @@ -0,0 +1,21 @@ +package flintstones.method.common.phase.unification.ui.messages; +//This file has been auto-generated + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + + public String Unification_Unified; + public String Unification_Expert; + public String Unification_Alternative; + public String Unification_Criterion; + public String Unification_Source_domain; + public String Unification_Evaluation; + +} + + + diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/messages.properties b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/messages.properties new file mode 100644 index 0000000..a03daac --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/messages.properties @@ -0,0 +1,10 @@ + +Unification_Alternative=Alternative +Unification_Criterion=Criterion +Unification_Evaluation=Evaluation +Unification_Expert=Expert +Unification_Save=Save +Unification_Source_domain=Source domain +Unification_Unification=Unification +Unification_Unified=Unified + diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/messages_es.properties b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/messages_es.properties new file mode 100644 index 0000000..35dd6c1 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/messages/messages_es.properties @@ -0,0 +1,10 @@ + +Unification_Alternative=Alternativa +Unification_Criterion=Criterio +Unification_Evaluation=Valoracin +Unification_Expert=Experto +Unification_Save=Guardar +Unification_Source_domain=Dominio original +Unification_Unification=Unificacin +Unification_Unified=Unificado + diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/AlternativeColumnLabelProvider.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/AlternativeColumnLabelProvider.java new file mode 100644 index 0000000..f30bb2e --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/AlternativeColumnLabelProvider.java @@ -0,0 +1,14 @@ +package flintstones.method.common.phase.unification.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +public class AlternativeColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + if (element instanceof Object[]) { + return (String) ((Object[]) element)[1]; + } + return null; + } +} diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/CriterionColumnLabelProvider.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/CriterionColumnLabelProvider.java new file mode 100644 index 0000000..9d4b9f1 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/CriterionColumnLabelProvider.java @@ -0,0 +1,14 @@ +package flintstones.method.common.phase.unification.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +public class CriterionColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + if (element instanceof Object[]) { + return (String) ((Object[]) element)[2]; + } + return null; + } +} diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/DomainNameColumnLabelProvider.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/DomainNameColumnLabelProvider.java new file mode 100644 index 0000000..b1b4fc6 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/DomainNameColumnLabelProvider.java @@ -0,0 +1,11 @@ +package flintstones.method.common.phase.unification.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +public class DomainNameColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + return (String) ((Object[]) element)[3]; + } +} diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/EvaluationColumnLabelProvider.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/EvaluationColumnLabelProvider.java new file mode 100644 index 0000000..ecbab31 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/EvaluationColumnLabelProvider.java @@ -0,0 +1,21 @@ +package flintstones.method.common.phase.unification.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +import flintstones.entity.valuation.Valuation; + +public class EvaluationColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + if(element instanceof Object[]) { + Valuation result = (Valuation) ((Object[]) element)[4]; + if(result != null) { + return result.changeFormatValuationToString(); + } + return "Messages.EvaluationColumnLabelProvider_Not_evaluate"; + } + return null; + } + +} diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/ExpertColumnLabelProvider.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/ExpertColumnLabelProvider.java new file mode 100644 index 0000000..0375816 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/ExpertColumnLabelProvider.java @@ -0,0 +1,14 @@ +package flintstones.method.common.phase.unification.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +public class ExpertColumnLabelProvider extends ColumnLabelProvider { + + @Override + public String getText(Object element) { + if (element instanceof Object[]) { + return (String) ((Object[]) element)[0]; + } + return null; + } +} diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/UnificationTreeViewerContentProvider.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/UnificationTreeViewerContentProvider.java new file mode 100644 index 0000000..438ae91 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/UnificationTreeViewerContentProvider.java @@ -0,0 +1,110 @@ + + +package flintstones.method.common.phase.unification.ui.provider; + +import java.util.Map; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.ProblemElementKey; +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.model.valuation.service.IValuationService; + +@SuppressWarnings("javadoc") +public class UnificationTreeViewerContentProvider implements ITreeContentProvider { + + @Inject + IValuationService valuationService; + + private Map twoTupleUnifiedValuations; + + public UnificationTreeViewerContentProvider() { + } + + public UnificationTreeViewerContentProvider(Map twoTupleUnifiedValuations) { + this.twoTupleUnifiedValuations = twoTupleUnifiedValuations; + } + + @Override + public void dispose() {} + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + @Override + public Object[] getElements(Object inputElement) { + return ((Object[][]) inputElement); + } + + public Object[][] getInput(){ + Map valuations = valuationService.getAllKV(); + Object[][] information = new Object[valuations.size()][6]; + + Expert expert; + Alternative alternative; + Criterion criterion; + Domain domain; + Valuation valuation; + + int i = 0; + for(Entry entry : valuations.entrySet() ) { + + expert = entry.getKey().getExpert(); + alternative = entry.getKey().getAlternative(); + criterion = entry.getKey().getCriterion(); + valuation = entry.getValue(); + domain = entry.getValue().getDomain(); + + if( expert == null ) + throw new Error("expert null"); + + if( alternative == null ) + throw new Error("alternative null"); + + if( criterion == null ) + throw new Error("criterion null"); + + if( valuation == null ) + throw new Error("valuation null"); + + if( domain == null ) + throw new Error("domain null"); + + + information[i][0] = expert.getCanonicalName(); + information[i][1] = alternative.getName(); + information[i][2] = criterion.getCanonicalName(); + information[i][3] = domain.getName(); + information[i][4] = valuation; + information[i][5] = twoTupleUnifiedValuations.get(entry.getKey()); + + i++; + + } + + return information; + } + + @Override + public Object[] getChildren(Object parentElement) { + return null; + } + + @Override + public Object getParent(Object element) { + return null; + } + + @Override + public boolean hasChildren(Object element) { + return false; + } +} diff --git a/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/UnifiedEvaluationColumnLabelProvider.java b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/UnifiedEvaluationColumnLabelProvider.java new file mode 100644 index 0000000..f4ab5b8 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification.ui/src/flintstones/method/common/phase/unification/ui/provider/UnifiedEvaluationColumnLabelProvider.java @@ -0,0 +1,25 @@ +package flintstones.method.common.phase.unification.ui.provider; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +import flintstones.entity.valuation.Valuation; + +public class UnifiedEvaluationColumnLabelProvider extends ColumnLabelProvider { + + + @Override + public String getText(Object element) { + + if (element instanceof Object[]) { + Valuation result = (Valuation) ((Object[]) element)[5]; + if (result != null) { + Valuation valuation = (Valuation) result; + return valuation.changeFormatValuationToString(); + } else { + return "NA"; //$NON-NLS-1$ + } + } else { + return (String) element; + } + } +} diff --git a/bundles/flintstones.method.common.phase.unification/.classpath b/bundles/flintstones.method.common.phase.unification/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.common.phase.unification/.polyglot.META-INF b/bundles/flintstones.method.common.phase.unification/.polyglot.META-INF new file mode 100644 index 0000000..b2405fc --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.common.phase.unification + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Unification + diff --git a/bundles/flintstones.method.common.phase.unification/.project b/bundles/flintstones.method.common.phase.unification/.project new file mode 100644 index 0000000..bc50561 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/.project @@ -0,0 +1,45 @@ + + + flintstones.method.common.phase.unification + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362654 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.common.phase.unification/META-INF/MANIFEST.MF b/bundles/flintstones.method.common.phase.unification/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9712409 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Unification +Bundle-SymbolicName: flintstones.method.common.phase.unification;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.common.unification +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.unifiedValuation, + flintstones.valuation.twoTuple, + flintstones.valuation.linguistic, + flintstones.entity.problemelement, + flintstones.domain.numeric, + flintstones.operator, + org.eclipse.e4.core.contexts, + javax.inject, + flintstones.model.domain.service, + flintstones.entity.domain, + org.eclipse.e4.core.di, + flintstones.entity.method.phase, + flintstones.model.method.phase.service, + flintstones.operator.unification +Export-Package: flintstones.method.common.phase.unification diff --git a/bundles/flintstones.method.common.phase.unification/build.properties b/bundles/flintstones.method.common.phase.unification/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.common.phase.unification/plugin.xml b/bundles/flintstones.method.common.phase.unification/plugin.xml new file mode 100644 index 0000000..4117f21 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/plugin.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/bundles/flintstones.method.common.phase.unification/src/flintstones/method/common/phase/unification/UnificationPhase.java b/bundles/flintstones.method.common.phase.unification/src/flintstones/method/common/phase/unification/UnificationPhase.java new file mode 100644 index 0000000..c9477d3 --- /dev/null +++ b/bundles/flintstones.method.common.phase.unification/src/flintstones/method/common/phase/unification/UnificationPhase.java @@ -0,0 +1,187 @@ +/* + * + */ +package flintstones.method.common.phase.unification; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.numeric.NumericDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.valuation.Valuation; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.unification.service.IUnificationOperatorService; +import flintstones.valuation.unifiedValuation.UnifiedValuation; + +/** + * The Class UnificationPhase. + */ +public class UnificationPhase extends PhaseMethod { + + /** The unification service. */ + @Inject + IUnificationOperatorService unificationService; + + /** The domain service. */ + @Inject + IDomainService domainService; + + /** The valuation service. */ + @Inject + IValuationService valuationService; + + /** The phase service. */ + @Inject + IPhaseMethodService phaseService; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The two tuple unified valuations. */ + private Map twoTupleUnifiedValuations = new HashMap<>(); + + /** The unification domain. */ + FuzzySet unificationDomain; + + /** + * Instantiates a new unification phase. + */ + public UnificationPhase() { + } + + /* (non-Javadoc) + * @see flintstones.phasemethod.PhaseMethod#getName() + */ + @Override + public String getName() { + return "Unification"; + } + + /* (non-Javadoc) + * @see flintstones.phasemethod.PhaseMethod#canBeExecuted() + */ + @Override + public boolean canBeExecuted() { + if (domainService.getAll().length == 1 && domainService.getAll()[0] instanceof NumericDomain ) + return false; + return true; + } + + public void initDomain() { + FuzzySet domain = (FuzzySet) this.importData("unifiedDomain"); + if(domain == null) + domain = getBLTSDomainMaximumGranularity(); + unificationDomain = domain; + } + + private FuzzySet getBLTSDomainMaximumGranularity() { + int g = 0; + + FuzzySet blts = null; + for(Domain d: domainService.getAll()) { + if(d instanceof FuzzySet) { + if(((FuzzySet) d).getLabelSet().getCardinality() > g) { + g = ((FuzzySet) d).getLabelSet().getCardinality(); + blts = (FuzzySet) d; + } + } + } + return blts; + } + + public FuzzySet getUnificationDomain() { + return unificationDomain; + } + + public FuzzySet getImportedDomain() { + return (FuzzySet) this.importData("unifiedDomain"); + } + + /** + * Gets all the unified valuations. + * + * @return the unified valuations + */ + public Map unify(boolean cost) { + twoTupleUnifiedValuations = new LinkedHashMap<>(); + + if (unificationDomain == null) + initDomain(); + + Map valuations = valuationService.getAllKV(); + for (ProblemElementKey vk : valuations.keySet()) { + Valuation v = unificateThis(vk, cost); + if (v != null) + twoTupleUnifiedValuations.put(vk, v); + else + System.err.println("UnifiedValuation is null"); + } + + exportTwoTupleUnifiedValuations(); + + return twoTupleUnifiedValuations; + + } + + /** + * Unificate this pek with this domain. + * + * @param pek the pek + * @param unificationDomain the unified domain X + * @param cost + * @return the unified valuation + */ + protected Valuation unificateThis(ProblemElementKey pek, boolean cost) { + + Valuation valuation = valuationService.getValuationFor(pek); + + if(cost) { + Criterion criterion = pek.getCriterion(); + + Boolean isCost = criterion.isCost(); + + if (isCost) + valuation = valuation.negateValuation(); + } + + if (valuation instanceof UnifiedValuation) + throw new Error("Not supported valuation."); //$NON-NLS-1$ + + String methodId = (String) this.importDataFromMethod("methodId"); + String finalValuationId = (String) this.importDataFromMethod("finalValuationId"); + + return unificationService.unify(unificationDomain, valuation, finalValuationId, methodId); + } + + /** + * Gets the two tuple unified valuations. + * + * @return the twoTupleUnifiedValuations + */ + public Map getTwoTupleUnifiedValuations() { + return twoTupleUnifiedValuations; + } + + /** + * Sets the two tuple unified valuations. + * + * @param twoTupleUnifiedValuations the twoTupleUnifiedValuations to set + */ + public void exportTwoTupleUnifiedValuations() { + exportData("unifiedDomain", twoTupleUnifiedValuations.values().iterator().next().getDomain(), true); + exportData("twoTupleUnifiedValuations", twoTupleUnifiedValuations, true); + } + +} diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.classpath b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.classpath new file mode 100644 index 0000000..ca3785c --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.project b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.project new file mode 100644 index 0000000..a6409ae --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.project @@ -0,0 +1,28 @@ + + + flintstones.method.dEvaluation.phase.aggregation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bd1095b --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..aa13a2c --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: dEvaluation method aggregation phase ui +Bundle-SymbolicName: flintstones.method.dEvaluation.phase.aggregation.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.dEvaluation.phase.aggregation.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.model.ui.service, + flintstones.method.dEvaluation.phase.aggregation, + flintstones.entity.method.phase, + flintstones.helper.ui, + flintstones.helper.data, + flintstones.helper.html, + flintstones.entity.problemelement.ui, + org.eclipse.swt, + flintstones.entity.operator, + flintstones.valuation.fuzzy diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/build.properties b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/plugin.xml b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/plugin.xml new file mode 100644 index 0000000..ff93f6e --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/src/flintstones/method/dEvaluation/phase/aggregation/ui/AggregationUI.java b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/src/flintstones/method/dEvaluation/phase/aggregation/ui/AggregationUI.java new file mode 100644 index 0000000..010baa0 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation.ui/src/flintstones/method/dEvaluation/phase/aggregation/ui/AggregationUI.java @@ -0,0 +1,512 @@ +package flintstones.method.dEvaluation.phase.aggregation.ui; + + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IParameterizedOperator; +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.html.table.HtmlTextTable; +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.dEvaluation.phase.aggregation.DEvaluationAggregationModel; +import flintstones.model.ui.service.UiService; +import flintstones.valuation.fuzzy.FuzzyValuation; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import org.eclipse.jface.resource.JFaceResources; +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; + +public class AggregationUI extends PhaseMethodUI { + + private DEvaluationAggregationModel model; + + private Combo operatorsCombo; + + private WCollector criteriaCollector; + private WCollector subcriteriaCollector; + + private HtmlTextTable decisionMatrixExpert; + private HtmlTextTable decisionMatrix; + + private ProblemElementSelector expertSelector; + private ProblemElementSelector criterionSelector; + + @Override + public void init() { + model = (DEvaluationAggregationModel) this.getModel(); + model.init(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite twoColumns = new Composite(base, SWT.NONE); + UiService.setGridData(twoColumns, 9, 9, true, true); + UiService.setGridLayout(twoColumns, 2); + + createExpertDataPart(twoColumns); + } + + private void createExpertDataPart(Composite twoColumns) { + createLeftPart(twoColumns); + createRightPart(twoColumns); + } + + private void createLeftPart(Composite twoColumns) { + Composite leftPart = new Composite(twoColumns, SWT.BORDER); + UiService.setGridData(leftPart, 9, 9, true, true); + UiService.setGridLayout(leftPart, 1); + + Label expertWeights = new Label(leftPart, SWT.BOLD); + UiService.setGridData(expertWeights, -1, -1, false, false); + expertWeights.setText("Expert's weights"); + expertWeights.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); + + Composite expertsSelectorComposite = new Composite(leftPart, SWT.BORDER); + UiService.setGridLayout(expertsSelectorComposite, 3, false); + UiService.setGridData(expertsSelectorComposite, 0, -1, true, false); + + expertSelector = new ProblemElementSelector(expertsSelectorComposite, model.getExperts()); + expertSelector.setText(Expert.Type); + expertSelector.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + + HashMap criteriaWeights = model.getCriteriaParentWeights(expertSelector.getSelectedElement().getName()); + + String[] items = model.getCriteriaParentName(); + + ArrayList data = new ArrayList<>(); + + for (String criterion: items) { + Double value = criteriaWeights.get(criterion); + if (value != null) + data.add(value + ""); //$NON-NLS-1$ + } + + criteriaCollector.setValues(data); + + updateOperator(); + updateSubcriteriaCollectorData(criterionSelector.getSelectedElement()); + + refresh(); + } + }); + + Button load = new Button(expertsSelectorComposite, SWT.NONE); + UiService.setGridData(load, 0, -1, true, false); + load.setText("Load data"); + load.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.loadData(); + } + }); + + createCriterionCollectorWeight(leftPart); + createSubcriterionCollectorWeight(leftPart); + createExpertDecisionMatrix(leftPart); + } + + private void checkAllCriteriaWeights() { + String[] criteria = model.getCriteriaParentName(); + + ProblemElement selectedExpert = expertSelector.getSelectedElement(); + + boolean status = true; + + String[] subcriteria; + for(String criterion: criteria) { + + if(model.getCriterionWeight(selectedExpert.getName(), criterion) == null) + status = false; + + subcriteria = model.getCriterionChildrenName(criterion); + + for(String subcriterion: subcriteria) { + if(model.getCriterionWeight(selectedExpert.getName(), subcriterion) == null) { + criterionSelector.setStatus(model.getCriterion(criterion), false); + status = false; + } else + criterionSelector.setStatus(model.getCriterion(criterion), true); + } + } + + expertSelector.setStatus(selectedExpert, status); + } + + private void createCriterionCollectorWeight(Composite leftPart) { + Composite body = new Composite(leftPart, SWT.NONE); + UiService.setGridData(body, 9, 9, true, true); + UiService.setGridLayout(body, 1); + + criteriaCollector = new WCollector(body); + criteriaCollector.setHeaders(Arrays.stream(model.getCriteriaParentName()).toArray(String[]::new)); + addCollectorListeners(criteriaCollector); + addCriteriaCollectorListener(); + } + + private void addCollectorListeners(WCollector collector) { + collector.setOperationListener(new WItemOperation() { + @Override + public String getModifiedValue(WEvent operationType, String before, String after) { + return Double.toString(DoubleHelper.NormalizeZeroToOne(before)); + } + }); + } + + private void createSubcriterionCollectorWeight(Composite leftPart) { + Composite body = new Composite(leftPart, SWT.NONE); + UiService.setGridData(body, 9, 9, true, true); + UiService.setGridLayout(body, 1); + + Composite criterionSelection = new Composite(body, SWT.NONE); + UiService.setGridData(criterionSelection, 9, 9, true, false); + UiService.setGridLayout(criterionSelection, 3); + + criterionSelector = new ProblemElementSelector(criterionSelection, model.getParentCriteria()); + criterionSelector.setText(Criterion.Type); + criterionSelector.setListener(new IProblemElementChangedListener() { + @Override + public void problemElementChanged(ProblemElement pe) { + updateOperator(); + updateSubcriteriaCollectorData(pe); + } + }); + + operatorsCombo = new Combo(criterionSelection, SWT.READ_ONLY); + UiService.setGridData(operatorsCombo, 9, 9, false, true); + operatorsCombo.setItems(model.getOperatorsName()); + operatorsCombo.select(0); + operatorsCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + AggregationOperator operator = model.setAggregationOperator(operatorsCombo.getText(), expertSelector.getSelectedElement().getName(), + criterionSelector.getSelectedElement().getName()); + + if(operator instanceof IParameterizedOperator) + ((IParameterizedOperator) operator).openDialog(criterionSelector.getSelectedElement().getChildren()); + + refresh(); + } + }); + + subcriteriaCollector = new WCollector(body); + subcriteriaCollector.setHeaders(Arrays.stream(model.getCriterionChildrenName( + criterionSelector.getSelectedElement().getName())).toArray(String[]::new)); + addCollectorListeners(subcriteriaCollector); + addSubcriteriaCollectorListener(); + } + + private void updateOperator() { + String[] operatorsName = model.getOperatorsName(); + AggregationOperator operator = model.getAggregationOperator(expertSelector.getSelectedElement().getName(), + criterionSelector.getSelectedElement().getName()); + + int indexOperator = -1; + for(int i = 0; i < operatorsName.length; ++i) { + if(operatorsName[i].equals(operator.getName())) { + indexOperator = i; + break; + } + } + + operatorsCombo.select(indexOperator); + } + + private void updateSubcriteriaCollectorData(ProblemElement selectedCriterion) { + + checkAllCriteriaWeights(); + + HashMap subcriteriaWeights = model.getSubcriteriaWeights( + expertSelector.getSelectedElement().getName(), selectedCriterion.getName()); + + String[] subitems = model.getCriterionChildrenName(selectedCriterion.getName()); + + ArrayList data = new ArrayList<>(); + + for (String subcriterion: subitems) { + Double value = subcriteriaWeights.get(subcriterion); + if (value != null) + data.add(value + ""); //$NON-NLS-1$ + } + + subcriteriaCollector.clear(); + subcriteriaCollector.setHeaders(Arrays.stream(model.getCriterionChildrenName(selectedCriterion.getName())).toArray(String[]::new)); + subcriteriaCollector.setValues(data); + } + + private void addCriteriaCollectorListener() { + criteriaCollector.setChangeListener(new WItemChanged() { + @Override + public void onWidgetChange() { + + ProblemElement selectedExpert = expertSelector.getSelectedElement(); + + String[] criteria = model.getCriteriaParentName(); + String[] data = criteriaCollector.getData(); + + if(data.length == 0) //clear values + for (int i = 0; i < criteria.length; i++) + model.removeCriterionWeight(selectedExpert.getName(), criteria[i]); + else { + for (int i = 0; i < criteria.length && i < data.length; i++) + model.addCriterionWeight(selectedExpert.getName(), criteria[i], DoubleHelper.ParseDouble(data[i])); + } + + checkAllCriteriaWeights(); + + refresh(); + } + }); + + criteriaCollector.setBeforeOperationListener(new WItemBeforeOperation() { + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + String[] subItems = model.getCriteriaParentName(); + + if (operationType.equals(WEvent.ADD)) { + + String[] data = criteriaCollector.getData(); + + if(data.length == subItems.length) + return false; + + double sum = 0.0; + for(String value : data) + sum += Double.parseDouble(value); + + sum += DoubleHelper.NormalizeZeroToOne(before); + + if(data.length == subItems.length - 1) + return DoubleHelper.Equals(sum, 1.0, 5); + else + return sum <= 1.0; + + } else if (operationType.equals(WEvent.CLEAR)) + return true; + + return false; + } + }); + } + + private void addSubcriteriaCollectorListener() { + subcriteriaCollector.setChangeListener(new WItemChanged() { + @Override + public void onWidgetChange() { + ProblemElement selectedCriterion = criterionSelector.getSelectedElement(); + + String[] subcriteria = model.getCriterionChildrenName(selectedCriterion.getName()); + String[] data = subcriteriaCollector.getData(); + + if(data.length == 0) {//clear values + for (int i = 0; i < subcriteria.length; i++) + model.removeCriterionWeight(expertSelector.getSelectedElement().getName(), subcriteria[i]); + } else { + for (int i = 0; i < subcriteria.length && i < data.length; i++) + model.addCriterionWeight(expertSelector.getSelectedElement().getName(), subcriteria[i], DoubleHelper.ParseDouble(data[i])); + } + + checkAllCriteriaWeights(); + + refresh(); + } + }); + + subcriteriaCollector.setBeforeOperationListener(new WItemBeforeOperation() { + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + String[] subItems = model.getCriterionChildrenName(criterionSelector.getSelectedElement().getName()); + + if (operationType.equals(WEvent.ADD)) { + + String[] data = subcriteriaCollector.getData(); + + if(data.length == subItems.length) + return false; + + double sum = 0.0; + for(String value : data) + sum += Double.parseDouble(value); + + sum += DoubleHelper.NormalizeZeroToOne(before); + + if(data.length == subItems.length - 1) + return DoubleHelper.Equals(sum, 1.0, 5); + else + return sum <= 1.0; + + } else if (operationType.equals(WEvent.CLEAR)) + return true; + + return false; + } + }); + } + + private void createExpertDecisionMatrix(Composite leftPart) { + Label expertDecisionMatrix = new Label(leftPart, SWT.BOLD); + UiService.setGridData(expertDecisionMatrix, -1, -1, false, false); + expertDecisionMatrix.setText("Expert decision matrix"); + expertDecisionMatrix.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); + + Composite decisionMatrixExpertComposite = new Composite(leftPart, SWT.NONE); + UiService.setGridData(decisionMatrixExpertComposite, 9, 9, false, true); + UiService.setGridLayout(decisionMatrixExpertComposite, 1); + + String[] rowHeader = model.getAlternativesNames(); + String[] colHeader = model.getShortenedCriteriaNames(); + String[][] valuesSTR = new String [rowHeader.length][colHeader.length]; + + //Double[][] values = model.getDecisionMatrix(); + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = ""; + } + + decisionMatrixExpert = new HtmlTextTable(decisionMatrixExpertComposite, valuesSTR, colHeader, rowHeader); + decisionMatrixExpert.render(); + } + + private void createRightPart(Composite twoColumns) { + Composite rightPart = new Composite(twoColumns, SWT.BORDER); + UiService.setGridData(rightPart, 9, 9, true, true); + UiService.setGridLayout(rightPart, 1); + + Label expertsWeights = new Label(rightPart, SWT.BOLD); + UiService.setGridData(expertsWeights, -1, -1, false, false); + expertsWeights.setText("Experts weights"); + expertsWeights.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); + + createExpertCollectorWeight(rightPart); + + Label decisionMatrixLabel = new Label(rightPart, SWT.BOLD); + UiService.setGridData(decisionMatrixLabel, -1, -1, false, false); + decisionMatrixLabel.setText("Decision matrix"); + decisionMatrixLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)); + + Composite decisionMatrixComposite = new Composite(rightPart, SWT.NONE); + UiService.setGridData(decisionMatrixComposite, 9, 9, false, true); + UiService.setGridLayout(decisionMatrixComposite, 1); + + String[] rowHeader = model.getAlternativesNames(); + String[] colHeader = model.getShortenedCriteriaNames(); + String[][] valuesSTR = new String [rowHeader.length][colHeader.length]; + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = ""; + } + + decisionMatrix = new HtmlTextTable(decisionMatrixComposite, valuesSTR, colHeader, rowHeader); + decisionMatrix.render(); + } + + private void createExpertCollectorWeight(Composite leftPart) { + Composite body = new Composite(leftPart, SWT.NONE); + UiService.setGridData(body, 9, 9, true, true); + UiService.setGridLayout(body, 1); + + WCollector expertsCollector = new WCollector(body); + expertsCollector.setHeaders(Arrays.stream(model.getExpertsName()).toArray(String[]::new)); + addCollectorListeners(expertsCollector); + addExpertsCollectorListener(expertsCollector); + } + + private void addExpertsCollectorListener(WCollector expertsCollector) { + expertsCollector.setChangeListener(new WItemChanged() { + @Override + public void onWidgetChange() { + String[] experts = model.getExpertsName(); + + String[] data = expertsCollector.getData(); + + if(data.length == 0) { + for (int i = 0; i < experts.length; i++) + model.removeExpertWeight(experts[i]); + } else { + for (int i = 0; i < experts.length && i < data.length; i++) + model.addExpertWeight(experts[i], DoubleHelper.ParseDouble(data[i])); + } + + refresh(); + } + }); + } + + @Override + public void refresh() { + refreshExpertDecisionMatrix(); + refreshDecisionMatrix(); + } + + private void refreshExpertDecisionMatrix() { + String[][] valuesSTR = new String[model.getAlternatives().length][model.getParentCriteria().length]; + + if(expertSelector.getStatus(expertSelector.getSelectedElement())) { + FuzzyValuation[][] decisionMatrixExpert = model.computeDecisionMatrixByExpert(expertSelector.getSelectedElement()); + + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = decisionMatrixExpert[i][j].changeFormatValuationToString(); + } + + } else { + + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = ""; + } + } + + decisionMatrixExpert.refresh(valuesSTR); + decisionMatrixExpert.render(); + } + + private void refreshDecisionMatrix() { + String[][] valuesSTR = new String[model.getAlternatives().length][model.getParentCriteria().length]; + + if(expertSelector.getStatus() && (model.getExpertsWeights().size() == model.getExperts().length)) { + FuzzyValuation[][] decisionCollectiveMatrix = model.computeDecisionMatrix(); + + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = decisionCollectiveMatrix[i][j].changeFormatValuationToString(); + } + + } else { + + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) + valuesSTR[i][j] = ""; + } + } + + decisionMatrix.refresh(valuesSTR); + decisionMatrix.render(); + + this.sendRefresh(); + } + + @Override + protected boolean isForwardEnabled() { + return model.isFinished(); + } + +} diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation/.classpath b/bundles/flintstones.method.dEvaluation.phase.aggregation/.classpath new file mode 100644 index 0000000..ca3785c --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation/.project b/bundles/flintstones.method.dEvaluation.phase.aggregation/.project new file mode 100644 index 0000000..98638f8 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation/.project @@ -0,0 +1,28 @@ + + + flintstones.method.dEvaluation.phase.aggregation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.dEvaluation.phase.aggregation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.dEvaluation.phase.aggregation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bd1095b --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation/META-INF/MANIFEST.MF b/bundles/flintstones.method.dEvaluation.phase.aggregation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9d433bd --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: dEvaluation method aggregation phase +Bundle-SymbolicName: flintstones.method.dEvaluation.phase.aggregation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.dEvaluation.phase.aggregation +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase, + flintstones.model.problemelement.service, + javax.inject, + flintstones.operator, + flintstones.valuation.fuzzy, + flintstones.entity.operator, + flintstones.helper.data, + flintstones.entity.valuation, + flintstones.domain.fuzzyset, + flintstones.operator.aggregation.arithmeticmean +Export-Package: flintstones.method.dEvaluation.phase.aggregation diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation/build.properties b/bundles/flintstones.method.dEvaluation.phase.aggregation/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation/plugin.xml b/bundles/flintstones.method.dEvaluation.phase.aggregation/plugin.xml new file mode 100644 index 0000000..55b595d --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.dEvaluation.phase.aggregation/src/flintstones/method/dEvaluation/phase/aggregation/DEvaluationAggregationModel.java b/bundles/flintstones.method.dEvaluation.phase.aggregation/src/flintstones/method/dEvaluation/phase/aggregation/DEvaluationAggregationModel.java new file mode 100644 index 0000000..e16aac6 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation.phase.aggregation/src/flintstones/method/dEvaluation/phase/aggregation/DEvaluationAggregationModel.java @@ -0,0 +1,436 @@ +package flintstones.method.dEvaluation.phase.aggregation; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.data.Pair; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.operator.aggregation.arithmeticmean.ArithmeticMean; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.fuzzy.FuzzyValuation; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Scanner; + +import javax.inject.Inject; + +public class DEvaluationAggregationModel extends PhaseMethod { + + @Inject + private IProblemElementService problemService; + + @Inject + private IOperatorService operatorService; + + private HashMap fuzzyValuations; + + private LinkedHashMap expertsWeights; + private HashMap, Double> criteriaWeightsByExpert; + private HashMap, AggregationOperator> criteriaAggregationOperatorsByExpert; + private HashMap decisionMatricesByExpert; + private FuzzyValuation[][] decisionMatrix; + + @Override + public String getName() { + return "Aggregation"; + } + + public void loadData() { + try { + File data = new File( + "C:\\Users\\lvaro\\Workspaces\\flintstones_2020\\flintstones\\git\\bundles\\flintstones.method.dEvaluation\\data\\data.txt"); + Scanner myReader = new Scanner(data); + while (myReader.hasNextLine()) { + String line = myReader.nextLine(); + String[] split = line.split(";"); + if(split.length == 3) { + String expertS = split[0]; + String criterionS = split[1]; + String weightS = split[2]; + + ProblemElement expert = getExpert(expertS); + ProblemElement criterion = getCriterion(criterionS); + Double weight = Double.parseDouble(weightS); + + criteriaWeightsByExpert.put(new Pair(expert, criterion), weight); + } else { + String expertS = split[0]; + String weightS = split[1]; + + ProblemElement expert = getExpert(expertS); + Double weight = Double.parseDouble(weightS); + + expertsWeights.put(expert, weight); + } + } + myReader.close(); + } catch (FileNotFoundException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") + public void init() { + expertsWeights = new LinkedHashMap<>(); + criteriaWeightsByExpert = new HashMap<>(); + criteriaAggregationOperatorsByExpert = new HashMap<>(); + decisionMatricesByExpert = new HashMap<>(); + + fuzzyValuations = (HashMap) this.importData("twoTupleUnifiedValuations"); + + initAggregationOperators(); + } + + private void initAggregationOperators() { + AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(FuzzyValuation.ID, true); + + for (ProblemElement expert : getExperts()) { + for (ProblemElement criterion : getParentCriteria()) + criteriaAggregationOperatorsByExpert.put(new Pair(expert, criterion), + operators[0]); + } + } + + public void addExpertWeight(String expert, Double weight) { + expertsWeights.put(getExpert(expert), weight); + } + + public void removeExpertWeight(String expert) { + expertsWeights.remove(getExpert(expert)); + } + + public void addCriterionWeight(String expert, String criterion, Double weight) { + criteriaWeightsByExpert + .put(new Pair(getExpert(expert), getCriterion(criterion)), weight); + } + + public void removeCriterionWeight(String expert, String criterion) { + criteriaWeightsByExpert + .remove(new Pair(getExpert(expert), getCriterion(criterion))); + } + + public Double getCriterionWeight(String expert, String criterion) { + return criteriaWeightsByExpert + .get(new Pair(getExpert(expert), getCriterion(criterion))); + } + + public AggregationOperator getAggregationOperator(String expert, String criterion) { + Pair key = new Pair(getExpert(expert), + getCriterion(criterion)); + return criteriaAggregationOperatorsByExpert.get(key); + } + + public AggregationOperator setAggregationOperator(String operatorName, String expert, String criterion) { + Pair key = new Pair(getExpert(expert), + getCriterion(criterion)); + + AggregationOperator operator = criteriaAggregationOperatorsByExpert.get(key); + + if (!operator.getName().equals(operatorName)) { + operator = getOperator(operatorName); + criteriaAggregationOperatorsByExpert.put(key, operator); + } + + return operator; + } + + public HashMap getCriteriaParentWeights(String expert) { + String[] criteria = getCriteriaParentName(); + + HashMap result = new HashMap<>(); + for (String criterion : criteria) + result.put(criterion, getCriterionWeight(expert, criterion)); + + return result; + } + + public HashMap getSubcriteriaWeights(String expert, String criterion) { + String[] subcriteria = getCriterionChildrenName(criterion); + + HashMap result = new HashMap<>(); + for (String subcriterion : subcriteria) + result.put(subcriterion, getCriterionWeight(expert, subcriterion)); + + return result; + } + + public FuzzyValuation[][] computeDecisionMatrixByExpert(ProblemElement expert) { + ProblemElement[] alternatives = getAlternatives(); + ProblemElement[] criteria = getParentCriteria(); + + ProblemElement alternative, criterion; + AggregationOperator operator; + ArrayList valuationsToAggregate; + ArrayList weights; + + FuzzyValuation[][] decisionMatrix = new FuzzyValuation[alternatives.length][criteria.length]; + FuzzyValuation aggregatedValuation; + + for (int i = 0; i < alternatives.length; ++i) { + alternative = alternatives[i]; + for (int j = 0; j < criteria.length; ++j) { + criterion = criteria[j]; + valuationsToAggregate = new ArrayList(); + weights = new ArrayList(); + for (ProblemElement subcriterion : criterion.getChildren()) { + valuationsToAggregate + .add(fuzzyValuations.get(new ProblemElementKey(expert, subcriterion, alternative))); + weights.add(getCriterionWeight(expert.getName(), subcriterion.getName())); + } + + operator = criteriaAggregationOperatorsByExpert + .get(new Pair(expert, criterion)); + + aggregatedValuation = (FuzzyValuation) operator.computeAggregation(valuationsToAggregate, weights); + aggregatedValuation.setFuzzyNumber(aggregatedValuation.getFuzzyNumber().multiplicationScalar( + criteriaWeightsByExpert.get(new Pair(expert, criterion)))); + + decisionMatrix[i][j] = aggregatedValuation; + } + } + + decisionMatricesByExpert.put(expert, decisionMatrix); + + return decisionMatrix; + } + + public FuzzyValuation[][] computeDecisionMatrix() { + ProblemElement[] alternatives = getAlternatives(); + ProblemElement[] criteria = getParentCriteria(); + + decisionMatrix = new FuzzyValuation[alternatives.length][criteria.length]; + + AggregationOperator arithmeticMean = operatorService.getAggregationOperator(ArithmeticMean.ID, + FuzzyValuation.ID); + ArrayList valuations; + ArrayList weights; + + FuzzyValuation[][] decisionMatrixExpert; + + for (int i = 0; i < getAlternatives().length; ++i) { + for (int j = 0; j < getCriteriaParentName().length; ++j) { + valuations = new ArrayList(); + weights = new ArrayList(); + for (ProblemElement expert : getExperts()) { + decisionMatrixExpert = decisionMatricesByExpert.get(expert); + valuations.add(decisionMatrixExpert[i][j]); + weights.add(expertsWeights.get(expert)); + } + + decisionMatrix[i][j] = (FuzzyValuation) arithmeticMean.computeAggregation(valuations, weights); + } + } + + exportDecisionMatrix(); + + return decisionMatrix; + } + + private void exportDecisionMatrix() { + + //Export decision matrix for TOPSIS + HashMatrix decisionMatrix = transformDecisionMatrixToFuzzyTOPSIS(); + ArrayList weights = transformWeightsToFuzzyTOPSIS(); + + this.exportData("aggregatedValues", decisionMatrix, true); + this.exportData("aggregatedWeights", weights, true); + + //Export decision matrix for sensitive analysis + HashMatrix decisionMatrixSA = transformDecisionMatrixToSensitiveAnalysis(); + HashMap weightsSA = transformWeightsToSensitiveAnalysis(); + + this.exportData("decisionmatrix", decisionMatrixSA, true); + this.exportData("criterionWeights", weightsSA, true); + } + + private HashMatrix transformDecisionMatrixToFuzzyTOPSIS() { + HashMatrix dm = new HashMatrix<>(); + + ProblemElement[] alternatives = getAlternatives(); + ProblemElement[] criteria = getParentCriteria(); + + for(int i = 0; i < alternatives.length; ++i) { + for(int j = 0; j < criteria.length; ++j) { + dm.put(alternatives[i], criteria[j], decisionMatrix[i][j].getFuzzyNumber()); + } + } + + return dm; + } + + private ArrayList transformWeightsToFuzzyTOPSIS() { + ArrayList weights = new ArrayList<>(); + + ProblemElement[] criteria = getParentCriteria(); + ProblemElement[] experts = getExperts(); + + double aux, weight; + for(ProblemElement criterion: criteria) { + weight = 0; + for(ProblemElement expert: experts) { + aux = criteriaWeightsByExpert.get(new Pair(expert, criterion)); + aux *= expertsWeights.get(expert); + weight += aux; + } + weights.add(new TrapezoidalFunction(weight, weight, weight, weight)); + } + + return weights; + } + + private HashMap transformWeightsToSensitiveAnalysis() { + HashMap weights = new HashMap<>(); + + ProblemElement[] criteria = getParentCriteria(); + ProblemElement[] experts = getExperts(); + + double aux, weight; + for(ProblemElement criterion: criteria) { + weight = 0; + for(ProblemElement expert: experts) { + aux = criteriaWeightsByExpert.get(new Pair(expert, criterion)); + aux *= expertsWeights.get(expert); + weight += aux; + } + weights.put(criterion, weight); + } + + return weights; + } + + private HashMatrix transformDecisionMatrixToSensitiveAnalysis() { + HashMatrix dm = new HashMatrix<>(); + + ProblemElement[] alternatives = getAlternatives(); + ProblemElement[] criteria = getParentCriteria(); + + for(int i = 0; i < alternatives.length; ++i) { + for(int j = 0; j < criteria.length; ++j) { + dm.put(alternatives[i], criteria[j], decisionMatrix[i][j]); + } + } + + return dm; + } + + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + public ProblemElement getExpert(String name) { + return problemService.getByName(Expert.Type, name); + } + + public ProblemElement[] getAlternatives() { + return problemService.getAll(Alternative.Type); + } + + public ProblemElement[] getParentCriteria() { + return problemService.getMainElements(Criterion.Type); + } + + public ProblemElement[] getCriterionChildren(String name) { + ProblemElement criterion = problemService.getByName(Criterion.Type, name); + return criterion.getChildren(); + } + + public ProblemElement getCriterion(String name) { + return problemService.getByName(Criterion.Type, name); + } + + public AggregationOperator[] getOperators() { + AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(FuzzyValuation.ID, true); + return operators; + } + + public AggregationOperator getOperator(String operatorName) { + AggregationOperator[] operators = getOperators(); + + for (AggregationOperator operator : operators) { + if (operator.getName().equals(operatorName)) + return operator; + } + + return null; + } + + public LinkedHashMap getExpertsWeights() { + return expertsWeights; + } + + public String[] getExpertsName() { + ProblemElement[] experts = getExperts(); + + String[] names = new String[experts.length]; + for (int i = 0; i < names.length; ++i) + names[i] = experts[i].getName(); + + return names; + } + + public String[] getCriteriaParentName() { + ProblemElement[] criteria = getParentCriteria(); + + String[] names = new String[criteria.length]; + for (int i = 0; i < names.length; ++i) + names[i] = criteria[i].getName(); + + return names; + } + + public String[] getCriterionChildrenName(String name) { + ProblemElement[] children = getCriterionChildren(name); + + String[] names = new String[children.length]; + for (int i = 0; i < names.length; ++i) + names[i] = children[i].getName(); + + return names; + } + + public String[] getShortenedCriteriaNames() { + ProblemElement[] criteria = getParentCriteria(); + String[] str = new String[criteria.length]; + + for (int i = 0; i < criteria.length; i++) + str[i] = "C" + (i + 1); + + return str; + } + + public String[] getAlternativesNames() { + ProblemElement[] alternatives = getAlternatives(); + + String[] names = new String[alternatives.length]; + for (int i = 0; i < names.length; ++i) + names[i] = alternatives[i].getName(); + + return names; + } + + public String[] getOperatorsName() { + AggregationOperator[] operators = getOperators(); + + String[] names = new String[operators.length]; + for (int i = 0; i < names.length; ++i) + names[i] = operators[i].getName(); + + return names; + } + + public boolean isFinished() { + return decisionMatrix != null; + } +} diff --git a/bundles/flintstones.method.dEvaluation/.classpath b/bundles/flintstones.method.dEvaluation/.classpath new file mode 100644 index 0000000..ca3785c --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.dEvaluation/.project b/bundles/flintstones.method.dEvaluation/.project new file mode 100644 index 0000000..ea30a35 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/.project @@ -0,0 +1,28 @@ + + + flintstones.method.dEvaluation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/flintstones.method.dEvaluation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.dEvaluation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.dEvaluation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.dEvaluation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bd1095b --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.dEvaluation/META-INF/MANIFEST.MF b/bundles/flintstones.method.dEvaluation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5414ef1 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: DEvaluation +Bundle-SymbolicName: flintstones.method.dEvaluation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.dEvaluation +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.valuation.numeric.real, + flintstones.valuation.numeric.integer, + flintstones.valuation.linguistic, + flintstones.valuation.fuzzy, + flintstones.entity.validatedmethod diff --git a/bundles/flintstones.method.dEvaluation/build.properties b/bundles/flintstones.method.dEvaluation/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.dEvaluation/data/data.txt b/bundles/flintstones.method.dEvaluation/data/data.txt new file mode 100644 index 0000000..c4c18a2 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/data/data.txt @@ -0,0 +1,102 @@ +Expert 1;0.219 +Expert 2;0.063 +Expert 3;0.094 +Expert 4;0.281 +Expert 5;0.063 +Expert 6;0.281 +Expert 1;Passenger preference;0.255 +Expert 1;Competition;0.147 +Expert 1;Slot availability;0.143 +Expert 1;Connection;0.455 +Expert 2;Passenger preference;0.467 +Expert 2;Competition;0.284 +Expert 2;Slot availability;0.107 +Expert 2;Connection;0.142 +Expert 3;Passenger preference;0.479 +Expert 3;Competition;0.229 +Expert 3;Slot availability;0.181 +Expert 3;Connection;0.111 +Expert 4;Passenger preference;0.504 +Expert 4;Competition;0.19 +Expert 4;Slot availability;0.19 +Expert 4;Connection;0.116 +Expert 5;Passenger preference;0.575 +Expert 5;Competition;0.174 +Expert 5;Slot availability;0.176 +Expert 5;Connection;0.075 +Expert 6;Passenger preference;0.171 +Expert 6;Competition;0.083 +Expert 6;Slot availability;0.294 +Expert 6;Connection;0.452 +Expert 1;Hub local departure time;0.375 +Expert 1;Destination local arrival time;0.125 +Expert 1;Destination local departure time;0.125 +Expert 1;Hub local arrival time;0.375 +Expert 2;Hub local departure time;0.333 +Expert 2;Destination local arrival time;0.167 +Expert 2;Destination local departure time;0.167 +Expert 2;Hub local arrival time;0.333 +Expert 3;Hub local departure time;0.375 +Expert 3;Destination local arrival time;0.125 +Expert 3;Destination local departure time;0.125 +Expert 3;Hub local arrival time;0.375 +Expert 4;Hub local departure time;0.4 +Expert 4;Destination local arrival time;0.1 +Expert 4;Destination local departure time;0.1 +Expert 4;Hub local arrival time;0.4 +Expert 5;Hub local departure time;0.1 +Expert 5;Destination local arrival time;0.3 +Expert 5;Destination local departure time;0.3 +Expert 5;Hub local arrival time;0.3 +Expert 6;Hub local departure time;0.125 +Expert 6;Destination local arrival time;0.25 +Expert 6;Destination local departure time;0.5 +Expert 6;Hub local arrival time;0.125 +Expert 1;Schedule time of competitor aerlines;0.75 +Expert 1;Cannibalization effect current schedule;0.25 +Expert 2;Schedule time of competitor aerlines;0.8 +Expert 2;Cannibalization effect current schedule;0.2 +Expert 3;Schedule time of competitor aerlines;0.875 +Expert 3;Cannibalization effect current schedule;0.125 +Expert 4;Schedule time of competitor aerlines;0.8 +Expert 4;Cannibalization effect current schedule;0.2 +Expert 5;Schedule time of competitor aerlines;0.833 +Expert 5;Cannibalization effect current schedule;0.167 +Expert 6;Schedule time of competitor aerlines;0.857 +Expert 6;Cannibalization effect current schedule;0.143 +Expert 1;Hub slot availability;0.167 +Expert 1;Dest slot availability;0.833 +Expert 2;Hub slot availability;0 +Expert 2;Dest slot availability;1 +Expert 3;Hub slot availability;0.333 +Expert 3;Dest slot availability;0.667 +Expert 4;Hub slot availability;0.25 +Expert 4;Dest slot availability;0.75 +Expert 5;Hub slot availability;0.143 +Expert 5;Dest slot availability;0.857 +Expert 6;Hub slot availability;0.2 +Expert 6;Dest slot availability;0.8 +Expert 1;Departure connectivity;0.228 +Expert 1;Arrival connectivity;0.228 +Expert 1;Codeshare connectivity;0.055 +Expert 1;Dep_Arr connection potential;0.489 +Expert 2;Departure connectivity;0.192 +Expert 2;Arrival connectivity;0.192 +Expert 2;Codeshare connectivity;0.067 +Expert 2;Dep_Arr connection potential;0.549 +Expert 3;Departure connectivity;0.243 +Expert 3;Arrival connectivity;0.243 +Expert 3;Codeshare connectivity;0.063 +Expert 3;Dep_Arr connection potential;0.451 +Expert 4;Departure connectivity;0.231 +Expert 4;Arrival connectivity;0.231 +Expert 4;Codeshare connectivity;0.077 +Expert 4;Dep_Arr connection potential;0.461 +Expert 5;Departure connectivity;0.178 +Expert 5;Arrival connectivity;0.178 +Expert 5;Codeshare connectivity;0.082 +Expert 5;Dep_Arr connection potential;0.562 +Expert 6;Departure connectivity;0.215 +Expert 6;Arrival connectivity;0.215 +Expert 6;Codeshare connectivity;0.098 +Expert 6;Dep_Arr connection potential;0.472 \ No newline at end of file diff --git a/bundles/flintstones.method.dEvaluation/plugin.xml b/bundles/flintstones.method.dEvaluation/plugin.xml new file mode 100644 index 0000000..84cb738 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/DEvaluationMethod.java b/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/DEvaluationMethod.java new file mode 100644 index 0000000..8f1de12 --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/DEvaluationMethod.java @@ -0,0 +1,82 @@ + +package flintstones.method.dEvaluation; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.dEvaluation.messages.Messages; +import flintstones.valuation.fuzzy.FuzzyValuation; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.numeric.integer.IntegerValuation; +import flintstones.valuation.numeric.real.RealValuation; + +public class DEvaluationMethod extends ValidatedMethod { + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + int numDomains = domainService.getAll().length; + String numDomainEntity = domainMessages.Domain_count; + + Domain[] fuzzysetDomains = domainService.getAll(FuzzySet.ID); + String fuzzysetDomainsEntity = domainMessages.Domain_type_entities; + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[3]; + validTypes[0] = RealValuation.class.getSimpleName(); + validTypes[1] = IntegerValuation.class.getSimpleName(); + validTypes[2] = LinguisticValuation.class.getSimpleName(); + + boolean superClass = false; + ValuationTypeOperation valuationTypeOperator = new ValuationTypeOperation(valuationsEntity, validTypes, + valuations, superClass); + + ValidBLTSDomainOperation validBLTSDomainOperation = new ValidBLTSDomainOperation(fuzzysetDomainsEntity, + fuzzysetDomains); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains")//$NON-NLS-1$ + .custom(validBLTSDomainOperation) + .named("fuzzySetDomains")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, FuzzyValuation.ID); + return map; + } +} diff --git a/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/Messages.java b/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/Messages.java new file mode 100644 index 0000000..2feef7e --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/Messages.java @@ -0,0 +1,13 @@ +//This file has been auto-generated +package flintstones.method.dEvaluation.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Method_description; + +} diff --git a/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/messages.properties b/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/messages.properties new file mode 100644 index 0000000..088014e --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/messages.properties @@ -0,0 +1,2 @@ +Method_name=dEvaluation +Method_description= \ No newline at end of file diff --git a/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/messages_es.properties b/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/messages_es.properties new file mode 100644 index 0000000..088014e --- /dev/null +++ b/bundles/flintstones.method.dEvaluation/src/flintstones/method/dEvaluation/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_name=dEvaluation +Method_description= \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.classpath b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.polyglot.META-INF new file mode 100644 index 0000000..589e713 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.calculatedistances.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.project b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.project new file mode 100644 index 0000000..b3c3d33 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.calculatedistances.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362655 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0df2578 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.decision.common.phase.calculatedistances.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.calculatedistances.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.method.decision.common.phase.calculatedistances, + org.eclipse.swt, + flintstones.helper.ui, + javax.inject, + flintstones.entity.problemelement, + flintstones.entity.wvaluation, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/build.properties b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/plugin.xml b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/plugin.xml new file mode 100644 index 0000000..2537eea --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/src/flintstones/method/decision/common/phase/calculatedistances/ui/CalculateDistancesUI.java b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/src/flintstones/method/decision/common/phase/calculatedistances/ui/CalculateDistancesUI.java new file mode 100644 index 0000000..079ed50 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances.ui/src/flintstones/method/decision/common/phase/calculatedistances/ui/CalculateDistancesUI.java @@ -0,0 +1,183 @@ +package flintstones.method.decision.common.phase.calculatedistances.ui; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.method.decision.common.phase.calculatedistances.AlternativeCloseness; +import flintstones.method.decision.common.phase.calculatedistances.CalculateDistancesModel; +import flintstones.model.ui.service.UiService; + +public class CalculateDistancesUI extends PhaseMethodUI { + + CalculateDistancesModel model; + + + @Override + public void init() { + model = (CalculateDistancesModel) this.getModel(); + createControls(this.getBaseComposite()); + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return false; + } + + private void createControls(Composite parent) { + + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + + Composite topRow = new Composite(parent, 0); + UiService.setGridData(topRow, 9, 9, true, false); + UiService.setGridLayout(topRow, 2); + + createDistancesTable(topRow); + createClosenessTable(topRow); + + } + + + private void createDistancesTable(Composite parent) { + + Composite base = new Composite(parent,0); + UiService.setGridLayout(base, 1); + UiService.setGridData(base, 9, 9, true, true); + + Label title = new Label(base,0); + title.setText("Distances"); + UiService.setFont(title,UiService.FONT_SECTION_TITLE); + + TableViewer distancesTV = new TableViewer(base, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + UiService.setGridData(distancesTV.getTable(), 9, 9, true, true); + distancesTV.getTable().setHeaderVisible(true); + distancesTV.setContentProvider(new ArrayContentProvider()); + + TableViewerColumn alternativeColumn = new TableViewerColumn(distancesTV, 0); + alternativeColumn.getColumn().setText("Alternativa"); + alternativeColumn.getColumn().pack(); + alternativeColumn.getColumn().setResizable(false); + alternativeColumn.getColumn().setMoveable(false); + alternativeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + AlternativeCloseness data = (AlternativeCloseness) element; + return data.getAlternative().getName(); + } + }); + + + TableViewerColumn positiveColumn = new TableViewerColumn(distancesTV, SWT.NONE); + positiveColumn.getColumn().setText("Distancia positiva"); + positiveColumn.getColumn().setResizable(false); + positiveColumn.getColumn().setMoveable(false); + positiveColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + AlternativeCloseness data = (AlternativeCloseness) element; + return data.getIdealDistance()+""; + } + }); + + TableViewerColumn negativeColumn = new TableViewerColumn(distancesTV, SWT.NONE); + negativeColumn.getColumn().setText("Distancia negativa"); + negativeColumn.getColumn().setResizable(false); + negativeColumn.getColumn().setMoveable(false); + negativeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + AlternativeCloseness data = (AlternativeCloseness) element; + return data.getNoIdealDistance()+""; + } + }); + + Arrays.stream(distancesTV.getTable().getColumns()).forEach( k -> k.pack() ); + + + distancesTV.setInput(model.getAlternativesCloseness()); + + } + + private void createClosenessTable(Composite parent) { + + + Composite base = new Composite(parent,0); + UiService.setGridLayout(base, 1); + UiService.setGridData(base, 9, 9, true, true); + + Label title = new Label(base,0); + title.setText("Closeness"); + UiService.setFont(title,UiService.FONT_SECTION_TITLE); + + TableViewer distancesTV = new TableViewer(base, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + UiService.setGridData(distancesTV.getTable(), 9, 9, true, true); + distancesTV.getTable().setHeaderVisible(true); + distancesTV.setContentProvider(new ArrayContentProvider()); + + + TableViewerColumn alternativeColumn = new TableViewerColumn(distancesTV, 0); + alternativeColumn.getColumn().setText("Alternativa"); + alternativeColumn.getColumn().pack(); + alternativeColumn.getColumn().setResizable(false); + alternativeColumn.getColumn().setMoveable(false); + alternativeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + AlternativeCloseness data = (AlternativeCloseness) element; + return data.getAlternative().getName(); + } + }); + + + TableViewerColumn positiveColumn = new TableViewerColumn(distancesTV, SWT.NONE); + positiveColumn.getColumn().setText("Distancia positiva"); + positiveColumn.getColumn().setResizable(false); + positiveColumn.getColumn().setMoveable(false); + positiveColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + AlternativeCloseness data = (AlternativeCloseness) element; + return data.getCloseness()+""; + } + }); + + TableViewerColumn negativeColumn = new TableViewerColumn(distancesTV, SWT.NONE); + negativeColumn.getColumn().setText("RANKING"); + negativeColumn.getColumn().setResizable(false); + negativeColumn.getColumn().setMoveable(false); + negativeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + AlternativeCloseness data = (AlternativeCloseness) element; + return data.getCachedRanking()+""; + } + }); + + Arrays.stream(distancesTV.getTable().getColumns()).forEach( k -> k.pack() ); + + ArrayList acs = model.getAlternativesCloseness(); + Collections.sort( acs ); + for( int i = 0; i < acs.size(); i++ ) { + acs.get(i).setCachedRanking(i+1); + } + distancesTV.setInput( acs ); + + + } + + +} diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/.classpath b/bundles/flintstones.method.decision.common.phase.calculatedistances/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.calculatedistances/.polyglot.META-INF new file mode 100644 index 0000000..754bcb4 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.calculatedistances + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Calculatedistances + diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/.project b/bundles/flintstones.method.decision.common.phase.calculatedistances/.project new file mode 100644 index 0000000..8572466 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.calculatedistances + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362655 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.calculatedistances/META-INF/MANIFEST.MF new file mode 100644 index 0000000..41f6569 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Calculatedistances +Bundle-SymbolicName: flintstones.method.decision.common.phase.calculatedistances;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.calculatedistances +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.wvaluation, + flintstones.entity.ahp.decisionmatrix, + flintstones.valuation.numeric, + flintstones.valuation, + flintstones.entity.valuation, + flintstones.entity.method.phase +Export-Package: flintstones.method.decision.common.phase.calculatedistances diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/build.properties b/bundles/flintstones.method.decision.common.phase.calculatedistances/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/plugin.xml b/bundles/flintstones.method.decision.common.phase.calculatedistances/plugin.xml new file mode 100644 index 0000000..861ebee --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/src/flintstones/method/decision/common/phase/calculatedistances/AlternativeCloseness.java b/bundles/flintstones.method.decision.common.phase.calculatedistances/src/flintstones/method/decision/common/phase/calculatedistances/AlternativeCloseness.java new file mode 100644 index 0000000..e5f920f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/src/flintstones/method/decision/common/phase/calculatedistances/AlternativeCloseness.java @@ -0,0 +1,138 @@ +package flintstones.method.decision.common.phase.calculatedistances; + +import flintstones.entity.problemelement.entities.Alternative; + +/** + * The Class AlternativeCloseness. (Support Class) + */ +public class AlternativeCloseness implements Comparable{ + + /** The alternative. */ + private Alternative alternative; + + /** The ideal distance. */ + double idealDistance = 0.0; + + /** The no ideal distance. */ + double noIdealDistance = 0.0; + + /** The closeness. */ + double closeness = 0.0; + + /** The cached ranking. */ + int cachedRanking = -1; + + /** + * Instantiates a new alternative closeness. + * + * @param a the a + * @param idealD the ideal D + * @param noIdealD the no ideal D + */ + public AlternativeCloseness(Alternative a, double idealD, double noIdealD) { + this.alternative = a; + this.idealDistance = idealD; + this.noIdealDistance = noIdealD; + + this.closeness = noIdealD/(idealD + noIdealD); + } + + /** + * Gets the alternative. + * + * @return the alternative + */ + public Alternative getAlternative() { + return alternative; + } + + /** + * Sets the alternative. + * + * @param a the new alternative + */ + public void setAlternative(Alternative a) { + this.alternative = a; + } + + /** + * Gets the ideal distance. + * + * @return the ideal distance + */ + public double getIdealDistance() { + return idealDistance; + } + + /** + * Sets the ideal distance. + * + * @param idealDistance the new ideal distance + */ + public void setIdealDistance(double idealDistance) { + this.idealDistance = idealDistance; + } + + /** + * Gets the no ideal distance. + * + * @return the no ideal distance + */ + public double getNoIdealDistance() { + return noIdealDistance; + } + + /** + * Sets the no ideal distance. + * + * @param noIdealDistance the new no ideal distance + */ + public void setNoIdealDistance(double noIdealDistance) { + this.noIdealDistance = noIdealDistance; + } + + /** + * Gets the closeness. + * + * @return the closeness + */ + public double getCloseness() { + return closeness; + } + + /** + * Sets the closeness. + * + * @param closeness the new closeness + */ + public void setCloseness(double closeness) { + this.closeness = closeness; + } + + /** + * Gets the cached ranking. + * + * @return the cached ranking + */ + public int getCachedRanking() { + return cachedRanking; + } + + /** + * Sets the cached ranking. + * + * @param cachedRanking the new cached ranking + */ + public void setCachedRanking(int cachedRanking) { + this.cachedRanking = cachedRanking; + } + + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(AlternativeCloseness other) { + return this.getCloseness() > other.getCloseness() ? -1 : 1; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.calculatedistances/src/flintstones/method/decision/common/phase/calculatedistances/CalculateDistancesModel.java b/bundles/flintstones.method.decision.common.phase.calculatedistances/src/flintstones/method/decision/common/phase/calculatedistances/CalculateDistancesModel.java new file mode 100644 index 0000000..50455a4 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatedistances/src/flintstones/method/decision/common/phase/calculatedistances/CalculateDistancesModel.java @@ -0,0 +1,95 @@ +package flintstones.method.decision.common.phase.calculatedistances; + +import java.util.ArrayList; +import java.util.HashMap; + +import flintstones.entity.ahp.decisionmatrix.DecisionMatrix; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.wvaluation.WValuation; +import flintstones.valuation.numeric.NumericValuation; + +/** + * The Class CalculateDistancesModel. + */ +@SuppressWarnings("unchecked") +public class CalculateDistancesModel extends PhaseMethod { + + /** The alternatives closeness. */ + ArrayList alternativesCloseness = new ArrayList<>();; + + /* (non-Javadoc) + * @see flintstones.phasemethod.PhaseMethod#getName() + */ + @Override + public String getName() { + return "Calculate Distances"; + } + + /* (non-Javadoc) + * @see flintstones.phasemethod.PhaseMethod#getInfo() + */ + @Override + public String getInfo() { + return "Se calcula la distancia de cada elemento de la matriz de decisión respecto al valor ideal y no ideal de su columna (criterio)" + + "Se agrega esta información por filas ( por alternativas ) para obtener la separación de cada alternativa." + + " Finalmente se calcula el coeficiente de cercania."; + } + + /** + * Gets the alternatives closeness. + * + * @return the alternatives closeness + */ + public ArrayList getAlternativesCloseness() { + + if(!alternativesCloseness.isEmpty()) + return alternativesCloseness; + + // Cache the best and worst of each column + ArrayList pis = (ArrayList) importData("positiveIdealSolutions"); + HashMap hashPis = new HashMap<>(); + pis.stream().forEach( k -> hashPis.put( k.getPEK().getCriterion(), k)); + + ArrayList nis = (ArrayList) importData("negativeIdealSolutions"); + HashMap hashNis = new HashMap<>(); + nis.stream().forEach( k -> hashNis.put( k.getPEK().getCriterion(), k)); + + DecisionMatrix dm = (DecisionMatrix) importData("weightedDecisionMatrix"); + + Alternative[] alternatives = dm.getAlternatives(); + for(Alternative a : alternatives) { + + double rowSumPositive = 0.0; + double rowSumNegative = 0.0; + ArrayList row = dm.getRow(a); + for(WValuation item : row) { + NumericValuation current = (NumericValuation) item.getValuation(); + NumericValuation best = (NumericValuation) hashPis.get(item.getPEK().getCriterion()).getValuation(); + NumericValuation worst = (NumericValuation) hashNis.get(item.getPEK().getCriterion()).getValuation(); + + double positiveSeparation = best.getValue() - current.getValue(); + positiveSeparation = positiveSeparation*positiveSeparation; + rowSumPositive += positiveSeparation; + + double negativeSeparation = worst.getValue() - current.getValue(); + negativeSeparation = negativeSeparation*negativeSeparation; + rowSumNegative += negativeSeparation; + + } + + rowSumPositive = Math.sqrt(rowSumPositive); + rowSumNegative = Math.sqrt(rowSumNegative); + + AlternativeCloseness ac = new AlternativeCloseness(a, rowSumPositive, rowSumNegative); + alternativesCloseness.add(ac); + + } + + return alternativesCloseness; + } + + + +} diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.classpath b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.polyglot.META-INF new file mode 100644 index 0000000..462ecf5 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.calculatesolutions.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.project b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.project new file mode 100644 index 0000000..3b3de85 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.calculatesolutions.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362656 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..51495e6 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.decision.common.phase.calculatesolutions.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.calculatesolutions.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.ahp.decisionmatrix, + flintstones.method.decision.common.phase.calculatesolutions, + org.eclipse.swt, + flintstones.helper.ui, + javax.inject, + flintstones.helper.wtable, + flintstones.helper.data, + flintstones.valuation.twoTuple, + flintstones.entity.wvaluation, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/build.properties b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/plugin.xml b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/plugin.xml new file mode 100644 index 0000000..5655e6d --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/src/flintstones/method/decision/common/phase/calculatesolutions/ui/CalculateSolutionsUI.java b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/src/flintstones/method/decision/common/phase/calculatesolutions/ui/CalculateSolutionsUI.java new file mode 100644 index 0000000..0037300 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions.ui/src/flintstones/method/decision/common/phase/calculatesolutions/ui/CalculateSolutionsUI.java @@ -0,0 +1,176 @@ +package flintstones.method.decision.common.phase.calculatesolutions.ui; + +import java.util.Arrays; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.ahp.decisionmatrix.DecisionMatrix; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.wvaluation.WValuation; +import flintstones.helper.MatrixHelper; +import flintstones.helper.wtable.WTable; +import flintstones.helper.wtable.WTableModel; +import flintstones.method.decision.common.phase.calculatesolutions.CalculateSolutionsModel; +import flintstones.model.ui.service.UiService; + +public class CalculateSolutionsUI extends PhaseMethodUI { + + CalculateSolutionsModel model; + + WTableModel decisionMatrixModel; + WTable decisionMatrixTable; + + boolean transposed = true; + + private TableViewer idealSolutionTV; + private TableViewer negativeSolutionTV; + + @Override + public void init() { + model = (CalculateSolutionsModel)this.getModel(); + createControls(this.getBaseComposite()); + } + + @Override + public void refresh() { + + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + private void createControls(Composite parent) { + + UiService.setGridData(parent, 9, 9, true, true); + UiService.setGridLayout(parent, 1); + + Composite topRow = new Composite(parent,0); + UiService.setGridData(topRow, 9, 9, true, true); + UiService.setGridLayout(topRow, 1); + + createDecisionMatrixTable(topRow); + + Composite bottomRow = new Composite(parent,0); + UiService.setGridData(bottomRow, 9, 9, true, false); + UiService.setGridLayout(bottomRow, 2); + + idealSolutionTV = createIdealSolutionTable(bottomRow, idealSolutionTV, true ); + idealSolutionTV.setInput( model.getPositiveIdealSolution() ); + Arrays.stream(idealSolutionTV.getTable().getColumns()).forEach(k -> k.pack()); + + negativeSolutionTV = createIdealSolutionTable(bottomRow, negativeSolutionTV, false ); + negativeSolutionTV.setInput( model.getNegativeIdealSolution() ); + Arrays.stream(negativeSolutionTV.getTable().getColumns()).forEach(k -> k.pack()); + + } + + private TableViewer createIdealSolutionTable(Composite bottomRow, TableViewer solutionTV, boolean positive) { + + Composite base = new Composite(bottomRow, SWT.NONE); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Label titleLabel = new Label(base, SWT.NONE); + String title = positive ? "Positive" : "Negative"; + titleLabel.setText(title + " Ideal Solution"); + + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + UiService.setGridData(titleLabel, 0, -1, true, false); + + solutionTV = new TableViewer(base, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + solutionTV.getTable() + .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + solutionTV.getTable() + .setHeaderVisible(true); + + solutionTV.setContentProvider(new ArrayContentProvider()); + + TableViewerColumn criterionColumn = new TableViewerColumn(solutionTV, SWT.NONE); + criterionColumn.getColumn().setText("Criterion"); + criterionColumn.getColumn().setResizable(false); + criterionColumn.getColumn().setMoveable(false); + + criterionColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + WValuation item = (WValuation)element; + return item.getPEK().getCriterion().getCanonicalName(); + } + }); + + TableViewerColumn typeColumn = new TableViewerColumn(solutionTV, SWT.NONE); + typeColumn.getColumn().setText("Type"); + typeColumn.getColumn().setResizable(false); + typeColumn.getColumn().setMoveable(false); + + typeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return ""; //$NON-NLS-1$ + } + + @Override + public Image getImage(Object element) { + WValuation item = (WValuation)element; + + if( item.getPEK().getCriterion().isCost()) + return UiService.getIcon("cost.png").createImage(); + return UiService.getIcon("benefit.png").createImage(); + + } + }); + + TableViewerColumn valuationColumn = new TableViewerColumn(solutionTV, SWT.NONE); + valuationColumn.getColumn().setText("Valuation"); + valuationColumn.getColumn().setResizable(true); + valuationColumn.getColumn().setMoveable(true); + valuationColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + WValuation item = (WValuation)element; + return item.getValuation().changeFormatValuationToString(); + } + + }); + + return solutionTV; + + } + + private void createDecisionMatrixTable(Composite parent) { + Composite base = new Composite(parent, SWT.BORDER); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + base.setLayout(new FillLayout()); + decisionMatrixTable = new WTable(base,SWT.V_SCROLL); + decisionMatrixModel = new WTableModel(decisionMatrixTable); + + DecisionMatrix dm = model.getDecisionMatrix(); + + if(transposed) { + decisionMatrixModel.addContent(MatrixHelper.transpose(dm.getValues())); + decisionMatrixModel.setHorizontalHeaders(dm.getAlternativeHeader().toArray(new String[0])); + decisionMatrixModel.setVerticalHeaders(dm.getCriterionHeader().toArray(new String[0])); + } else { + decisionMatrixModel.addContent(dm.getValues()); + decisionMatrixModel.setHorizontalHeaders(dm.getCriterionHeader().toArray(new String[0])); + decisionMatrixModel.setVerticalHeaders(dm.getAlternativeHeader().toArray(new String[0])); + } + + decisionMatrixTable.setModel(decisionMatrixModel); + decisionMatrixModel.init(); + + } +} diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/.classpath b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.polyglot.META-INF new file mode 100644 index 0000000..5d7bcc2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.calculatesolutions + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Calculatesolutions + diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/.project b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.project new file mode 100644 index 0000000..954c0c1 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.calculatesolutions + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362656 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.calculatesolutions/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a1d9d07 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Calculatesolutions +Bundle-SymbolicName: flintstones.method.decision.common.phase.calculatesolutions;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.calculatesolutions +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.ahp.decisionmatrix, + flintstones.entity.problemelement, + flintstones.entity.wvaluation, + flintstones.valuation.numeric.real, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.operator, + javax.inject, + flintstones.operator.aggregation.min, + flintstones.operator.aggregation.max, + flintstones.entity.method.phase, + flintstones.entity.operator +Export-Package: flintstones.method.decision.common.phase.calculatesolutions diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/build.properties b/bundles/flintstones.method.decision.common.phase.calculatesolutions/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/plugin.xml b/bundles/flintstones.method.decision.common.phase.calculatesolutions/plugin.xml new file mode 100644 index 0000000..3650185 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.calculatesolutions/src/flintstones/method/decision/common/phase/calculatesolutions/CalculateSolutionsModel.java b/bundles/flintstones.method.decision.common.phase.calculatesolutions/src/flintstones/method/decision/common/phase/calculatesolutions/CalculateSolutionsModel.java new file mode 100644 index 0000000..2658775 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.calculatesolutions/src/flintstones/method/decision/common/phase/calculatesolutions/CalculateSolutionsModel.java @@ -0,0 +1,147 @@ +package flintstones.method.decision.common.phase.calculatesolutions; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.TreeMap; +import java.util.stream.Collectors; + +import javax.inject.Inject; + +import flintstones.entity.ahp.decisionmatrix.DecisionMatrix; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.entity.wvaluation.WValuation; +import flintstones.operator.aggregation.max.Max; +import flintstones.operator.aggregation.min.Min; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.numeric.real.RealValuation; + +@SuppressWarnings({ "unchecked", "javadoc" }) +public class CalculateSolutionsModel extends PhaseMethod { + + @Inject + IOperatorService operatorService; + + @Override + public String getName() { + return "Calculate Solutions"; + } + + DecisionMatrix weightedDm = null; + + public DecisionMatrix getDecisionMatrix() { + + if (weightedDm != null) + return weightedDm; + + DecisionMatrix dm = (DecisionMatrix) importData("decisionMatrix"); + HashMap weights = (HashMap) importData("criterionWeights"); + weightedDm = applyWeights(dm, weights); + + this.exportData("weightedDecisionMatrix", weightedDm); + + return weightedDm; + } + + private DecisionMatrix applyWeights(DecisionMatrix dm, HashMap weights) { + + DecisionMatrix weightedDm = (DecisionMatrix) dm.clone(); + + for (Criterion columnPE : weightedDm.getCriterions()) { + TreeMap waluations = weightedDm.getColumn(columnPE); + double weight = weights.get(columnPE); + + for (WValuation w : waluations.values()) { + RealValuation v = (RealValuation) w.getValuation(); + double value = v.getValue() * weight; + v.setValue(value); + weightedDm.set(w.getPEK().getCriterion(),w.getPEK().getAlternative(),v); + } + + } + + return weightedDm; + + } + + public ArrayList getPositiveIdealSolution() { + + ArrayList rows = new ArrayList<>(); + + for (Criterion columnPE : weightedDm.getCriterions()) { + TreeMap waluations = weightedDm.getColumn(columnPE); + ArrayList columnValuations = (ArrayList) waluations.values() + .stream() + .map(k -> k.getValuation()) + .collect(Collectors.toList()); + + WValuation anyW = waluations.values() + .iterator() + .next(); + + boolean isCost = anyW.getPEK() + .getCriterion() + .isCost(); + + Valuation finalValuation; + + if (isCost) { + AggregationOperator min = operatorService.getAggregationOperator(Min.class.getPackage().getName().toString(), columnValuations.get(0).getId()); + finalValuation = min.computeAggregation(columnValuations, null); + } else { + AggregationOperator max = operatorService.getAggregationOperator(Max.class.getPackage().getName().toString(), columnValuations.get(0).getId()); + finalValuation = max.computeAggregation(columnValuations, null); + } + + WValuation w = new WValuation(anyW.getPEK(), finalValuation); + rows.add(w); + + } + + this.exportData("positiveIdealSolutions", rows); + return rows; + + } + + public ArrayList getNegativeIdealSolution() { + ArrayList rows = new ArrayList<>(); + + for (Criterion columnPE : weightedDm.getCriterions()) { + TreeMap waluations = weightedDm.getColumn(columnPE); + + ArrayList columnValuations = (ArrayList) waluations.values() + .stream() + .map(k -> k.getValuation()) + .collect(Collectors.toList()); + + WValuation anyW = waluations.values() + .iterator() + .next(); + + boolean isCost = anyW.getPEK() + .getCriterion() + .isCost(); + + Valuation finalValuation; + if (isCost) { + AggregationOperator max = operatorService.getAggregationOperator(Max.class.getPackage().getName().toString(), columnValuations.get(0).getId()); + finalValuation = max.computeAggregation(columnValuations, null); + + } else { + AggregationOperator min = operatorService.getAggregationOperator(Min.class.getPackage().getName().toString(), columnValuations.get(0).getId()); + finalValuation = min.computeAggregation(columnValuations, null); + } + + WValuation w = new WValuation(anyW.getPEK(), finalValuation); + rows.add(w); + + } + + this.exportData("negativeIdealSolutions", rows); + return rows; + } + +} diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/.classpath b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.polyglot.META-INF new file mode 100644 index 0000000..ce110fd --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.collectweights.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/.project b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.project new file mode 100644 index 0000000..d607dad --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.collectweights.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362658 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.collectweights.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..16bac68 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.decision.common.phase.collectweights.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.collectweights.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.method.decision.common.phase.collectweights, + org.eclipse.swt, + flintstones.helper.ui, + javax.inject, + flintstones.helper.wtable, + flintstones.entity.problemelement, + flintstones.entity.ahp.decisionmatrix, + flintstones.model.problemelement.service, + flintstones.entity.domain, + flintstones.entity.domain.ui.chart, + flintstones.model.domain.ui.service, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui +Export-Package: flintstones.method.decision.common.phase.collectweights.ui.provider diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/build.properties b/bundles/flintstones.method.decision.common.phase.collectweights.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/plugin.xml b/bundles/flintstones.method.decision.common.phase.collectweights.ui/plugin.xml new file mode 100644 index 0000000..4dbc05f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/src/flintstones/method/decision/common/phase/collectweights/ui/CollectWeightsUI.java b/bundles/flintstones.method.decision.common.phase.collectweights.ui/src/flintstones/method/decision/common/phase/collectweights/ui/CollectWeightsUI.java new file mode 100644 index 0000000..c3e24ea --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/src/flintstones/method/decision/common/phase/collectweights/ui/CollectWeightsUI.java @@ -0,0 +1,140 @@ +package flintstones.method.decision.common.phase.collectweights.ui; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.domain.ui.chart.DomainChart; +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.helper.wtable.WTable; +import flintstones.helper.wtable.WTableModel; +import flintstones.helper.wtable.event.WTableCellModifiedListener; +import flintstones.method.decision.common.phase.collectweights.CollectWeightsModel; +import flintstones.method.decision.common.phase.collectweights.ui.provider.WeightCollectionTableCell; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class CollectWeightsUI extends PhaseMethodUI implements WTableCellModifiedListener { + + + @Inject + IProblemElementService problemService; + + @Inject + IDomainUIService uiDomainService; + + CollectWeightsModel model; + + ArrayList> cells; + WTableModel wtableModel; + WTable table; + + @Override + public void init() { + model = (CollectWeightsModel) this.getModel(); + createPartControls(this.getBaseComposite()); + compute(); + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + private void createPartControls(Composite parent) { + + UiService.setGridData(parent, 9, 9, true, true); + UiService.setGridLayout(parent, 1); + + createTable(parent); + createChart(parent); + + } + + private void createChart(Composite parent) { + + Composite base = new Composite(parent, SWT.BORDER); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + base.setBackground(UiService.getColor(0, 0, 100)); + base.setLayout(new FillLayout()); + + DomainChart chart = uiDomainService.createChart( model.getDomain().getType() ); + chart.initialize(model.getDomain(), base, 500, 500, SWT.BORDER); + + base.layout(true); + + } + + private void createTable(Composite parent) { + + Composite base = new Composite(parent, SWT.BORDER); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + base.setLayout(new FillLayout()); + + table = new WTable(base, 0); + table.setLayout(new FillLayout()); + wtableModel = new WTableModel(table); + + ArrayList experts = new ArrayList(Arrays.asList(problemService.getSubElements(Expert.Type))); + ArrayList criterions = new ArrayList(Arrays.asList(problemService.getSubElements(Criterion.Type))); + cells = new ArrayList<>(); + + for (ProblemElement c : criterions) { + ArrayList row = new ArrayList<>(); + for (ProblemElement e : experts) { + row.add(new WeightCollectionTableCell((Expert) e, (Criterion) c, 0.5)); + } + cells.add(row); + + } + + wtableModel.setHorizontalHeaders(criterions.stream() + .map(k -> k.getName()) + .toArray(String[]::new)); + + wtableModel.setVerticalHeaders(experts.stream() + .map(k -> k.getName()) + .toArray(String[]::new)); + + + wtableModel.addContent(cells); + wtableModel.addListener(this); + table.setModel(wtableModel); + // table.setBackground(UiService.getColor(100, 0, 0)); + wtableModel.init(); + + } + + @Override + public void cellModified(int col, int row, Object oldValue, Object newValue) { + compute(); + } + + private void compute() { + HashMap criterionWeights = new HashMap<>(); + for(ArrayList column : cells ) { + double avg = column.stream().mapToDouble( k -> k.getWeight() ).average().getAsDouble(); + criterionWeights.put(column.get(0).getCriterion(), avg); + } + + model.export(criterionWeights); + } + +} diff --git a/bundles/flintstones.method.decision.common.phase.collectweights.ui/src/flintstones/method/decision/common/phase/collectweights/ui/provider/WeightCollectionTableCell.java b/bundles/flintstones.method.decision.common.phase.collectweights.ui/src/flintstones/method/decision/common/phase/collectweights/ui/provider/WeightCollectionTableCell.java new file mode 100644 index 0000000..731d3e5 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights.ui/src/flintstones/method/decision/common/phase/collectweights/ui/provider/WeightCollectionTableCell.java @@ -0,0 +1,137 @@ +package flintstones.method.decision.common.phase.collectweights.ui.provider; + +import de.kupzog.ktable.KTableCellEditor; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.helper.wtable.cell.WTableCell; +import flintstones.helper.wtable.interfaces.IWTableCellContent; +import flintstones.helper.wtable.interfaces.IWTableCellEditor; +import flintstones.helper.wtable.interfaces.IWTableCellEventModified; +import flintstones.helper.wtable.wcelleditor.WCellEditorFloatingSpinner; + +/** + * The Class WeightCollectionTableCell. + */ +public class WeightCollectionTableCell extends WTableCell implements IWTableCellContent, IWTableCellEditor, IWTableCellEventModified { + + /** The weight. */ + double weight = 0.0; + + /** The editor. */ + WCellEditorFloatingSpinner editor; + + /** The e. */ + Expert e; + + /** The c. */ + Criterion c; + + /** + * Instantiates a new weight collection table cell. + * + * @param e the e + * @param c the c + * @param weight the weight + */ + public WeightCollectionTableCell(Expert e, Criterion c, double weight) { + this.e = e; + this.c = c; + this.weight = weight; + } + + /* (non-Javadoc) + * @see flintstones.helper.wtable.interfaces.IWTableCellContent#getContent(java.lang.Object) + */ + @Override + public Object getContent(Object cellContent) { + return weight; + } + + /* (non-Javadoc) + * @see flintstones.helper.wtable.interfaces.IWTableCellContent#shouldFireModifiedEvent() + */ + @Override + public boolean shouldFireModifiedEvent() { + return true; + } + + /* (non-Javadoc) + * @see flintstones.helper.wtable.interfaces.IWTableCellContent#shouldSetContent() + */ + @Override + public boolean shouldSetContent() { + return false; + } + + /* (non-Javadoc) + * @see flintstones.helper.wtable.interfaces.IWTableCellEditor#getCellEditor() + */ + @Override + public KTableCellEditor getCellEditor() { + if( editor == null ) { + editor = new WCellEditorFloatingSpinner(); + editor.setDigits(2); + } + return editor; + + } + + /** + * Gets the weight. + * + * @return the weight + */ + public double getWeight() { + return weight; + } + + /* (non-Javadoc) + * @see flintstones.helper.wtable.cell.WTableCell#toString() + */ + @Override + public String toString() { + return this.weight + ""; + } + + /* (non-Javadoc) + * @see flintstones.helper.wtable.interfaces.IWTableCellEventModified#cellModified(int, int, java.lang.Object, java.lang.Object) + */ + @Override + public void cellModified(int col, int row, Object oldContent, Object newContent) { + + String newContentS = (String)newContent; + // Value must be between 0 and 1. + // Format should be X.YY. + + // Fix 1, if format is X,YY + newContentS = newContentS.replace(",","."); + + // Current double value + double value = Double.parseDouble(newContentS); + + // Fix 2, if user input 1 we will write 0.1 as a shortcut. + // Also If the users imputs 55, we will write 0.55. Bigger integers will be ignored. + if( value > 1.00 ) // we allow 1.00 + if( value < 10.0 ) + value /= 10; + else if( value > 10.0 && value < 100.0 ) + value /= 100; + else + value = weight; + + this.weight = value; + } + + /** + * Gets the criterion. + * + * @return the criterion + */ + public Criterion getCriterion() { + return c; + } + + + + +} diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/.classpath b/bundles/flintstones.method.decision.common.phase.collectweights/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.collectweights/.polyglot.META-INF new file mode 100644 index 0000000..4cb7913 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.collectweights + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Collectweights + diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/.project b/bundles/flintstones.method.decision.common.phase.collectweights/.project new file mode 100644 index 0000000..d03c26c --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.collectweights + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362657 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.collectweights/META-INF/MANIFEST.MF new file mode 100644 index 0000000..67cdf07 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Collectweights +Bundle-SymbolicName: flintstones.method.decision.common.phase.collectweights;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.collectweights +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.domain, + javax.inject, + flintstones.model.domain.service, + flintstones.entity.method.phase, + flintstones.helper.data +Export-Package: flintstones.method.decision.common.phase.collectweights diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/build.properties b/bundles/flintstones.method.decision.common.phase.collectweights/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/plugin.xml b/bundles/flintstones.method.decision.common.phase.collectweights/plugin.xml new file mode 100644 index 0000000..9ee63cd --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.collectweights/src/flintstones/method/decision/common/phase/collectweights/CollectWeightsModel.java b/bundles/flintstones.method.decision.common.phase.collectweights/src/flintstones/method/decision/common/phase/collectweights/CollectWeightsModel.java new file mode 100644 index 0000000..8ed32b2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.collectweights/src/flintstones/method/decision/common/phase/collectweights/CollectWeightsModel.java @@ -0,0 +1,37 @@ +package flintstones.method.decision.common.phase.collectweights; + +import java.util.HashMap; + +import javax.inject.Inject; + +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.model.domain.service.IDomainService; + +public class CollectWeightsModel extends PhaseMethod { + + @Inject + IDomainService domainService; + + @Override + public String getName() { + return "Collect Weights"; + } + + @Override + public String getInfo() { + return "Se dan los pesos de cada experto para cada Criterio y se obtiene el peso medio para cada Criterio."; + } + + public Domain getDomain() { + return domainService.getAll()[0]; + } + + public void export(HashMap criterionWeights) { + this.exportData("criterionWeights", criterionWeights); + this.exportData("decisionMatrix", this.importData("decisionMatrix")); + } + + +} diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/.classpath b/bundles/flintstones.method.decision.common.phase.normalization.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.normalization.ui/.polyglot.META-INF new file mode 100644 index 0000000..dd442b0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.normalization.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/.project b/bundles/flintstones.method.decision.common.phase.normalization.ui/.project new file mode 100644 index 0000000..4e85dfe --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.normalization.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362660 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.normalization.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0878cf7 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.decision.common.phase.normalization.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.normalization.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.model.ui.service, + flintstones.helper.data, + org.eclipse.e4.core.contexts, + flintstones.helper.wtable, + flintstones.entity.problemelement, + flintstones.method.decision.common.phase.normalization, + javax.inject, + flintstones.helper.ui, + flintstones.application.perspective.framework.ui, + org.eclipse.swt, + flintstones.entity.ahp.decisionmatrix, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/build.properties b/bundles/flintstones.method.decision.common.phase.normalization.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/plugin.xml b/bundles/flintstones.method.decision.common.phase.normalization.ui/plugin.xml new file mode 100644 index 0000000..172037b --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.normalization.ui/src/flintstones/method/decision/common/phase/normalization/ui/NormalizationUI.java b/bundles/flintstones.method.decision.common.phase.normalization.ui/src/flintstones/method/decision/common/phase/normalization/ui/NormalizationUI.java new file mode 100644 index 0000000..cdb2819 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization.ui/src/flintstones/method/decision/common/phase/normalization/ui/NormalizationUI.java @@ -0,0 +1,178 @@ +package flintstones.method.decision.common.phase.normalization.ui; + +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +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.entity.ahp.decisionmatrix.DecisionMatrix; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.MatrixHelper; +import flintstones.helper.wtable.WTable; +import flintstones.helper.wtable.WTableModel; +import flintstones.method.decision.common.phase.normalization.NormalizationModel; +import flintstones.model.ui.service.UiService; + +public class NormalizationUI extends PhaseMethodUI { + + + @Inject + IEclipseContext context; + + NormalizationModel model; + + String selectedNormalization = ""; + + String selectedAggregation = ""; + + WTableModel wtableModel; + WTable table; + + boolean isTransposed = true; + + @Override + public void init() { + model = (NormalizationModel) this.getModel(); + model.init(); + createPartControls(this.getBaseComposite()); + + + drawDecisionMatrix(); + + } + + private void drawDecisionMatrix() { + DecisionMatrix dm = model.execute(selectedNormalization,selectedAggregation); + if( dm != null ) { + + if(!isTransposed) { + wtableModel.addContent(dm.getValues()); + wtableModel.setHorizontalHeaders(dm.getCriterionHeader().toArray(new String[0])); + wtableModel.setVerticalHeaders(dm.getAlternativeHeader().toArray(new String[0])); + table.setModel(wtableModel); + wtableModel.init(); + } else { + ArrayList> values = dm.getValues(); + wtableModel.addContent(MatrixHelper.transpose(values)); + wtableModel.setHorizontalHeaders(dm.getAlternativeHeader().toArray(new String[0])); + wtableModel.setVerticalHeaders(dm.getCriterionHeader().toArray(new String[0])); + table.setModel(wtableModel); + wtableModel.init(); + } + } + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + private void createPartControls(Composite parent) { + UiService.setGridData(parent, 9, 9, true, true); + UiService.setGridLayout(parent, 1); + + Composite top = new Composite(parent, 0); + UiService.setGridData(top, 9, 0, true, false); + UiService.setGridLayout(top, 3); + + createComboNormalization(top); + createComboAggregation(top); + createTransposeButton(top); + + Composite bottom = new Composite(parent, 0); + UiService.setGridData(bottom, 9, 9, true, true); + UiService.setGridLayout(bottom, 2); + + createTable(bottom); + + } + + private void createTransposeButton(Composite top) { + Button button = new Button(top, SWT.PUSH); + button.setImage(UiService.getImage("transpose.png").createImage()); + + button.addSelectionListener( new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent arg0) { + isTransposed = !isTransposed; + drawDecisionMatrix(); + } + }); + } + + private void createComboNormalization(Composite parent) { + + Composite base = new Composite(parent, 0); + UiService.setGridData(base, 9, 9, false, true); + UiService.setGridLayout(base, 2); + + Label l = new Label(base, 0); + l.setText("Operador de normalizacion"); + + Combo normalizationCombo = new Combo(base, SWT.DROP_DOWN | SWT.READ_ONLY); + String[] items = model.getNormalizationOperators(); + normalizationCombo.setItems(items); + + normalizationCombo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + selectedNormalization = normalizationCombo.getText(); + drawDecisionMatrix(); + } + }); + normalizationCombo.select(0); + selectedNormalization = normalizationCombo.getText(); + + } + + private void createComboAggregation(Composite parent) { + + Composite base = new Composite(parent, 0); + UiService.setGridData(base, 9, 9, false, true); + UiService.setGridLayout(base, 2); + + Label l = new Label(base, 0); + l.setText("Operador de aggregación"); + + Combo aggregationCombo = new Combo(base, SWT.DROP_DOWN | SWT.READ_ONLY); + String[] items = model.getAggregationOperators(); + aggregationCombo.setItems(items); + + aggregationCombo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + selectedAggregation = aggregationCombo.getText(); + drawDecisionMatrix(); + } + }); + aggregationCombo.select(0); + selectedAggregation = aggregationCombo.getText(); + + } + + private void createTable(Composite parent) { + + Composite base = new Composite(parent, SWT.BORDER); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + base.setLayout(new FillLayout()); + table = new WTable(base,0); + wtableModel = new WTableModel(table); +// table.setModel(wtableModel); + + } + + +} diff --git a/bundles/flintstones.method.decision.common.phase.normalization/.classpath b/bundles/flintstones.method.decision.common.phase.normalization/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.normalization/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.normalization/.polyglot.META-INF new file mode 100644 index 0000000..500a20a --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.normalization + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Normalization + diff --git a/bundles/flintstones.method.decision.common.phase.normalization/.project b/bundles/flintstones.method.decision.common.phase.normalization/.project new file mode 100644 index 0000000..ac7790e --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.normalization + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362658 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.normalization/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.normalization/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2a1d814 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Normalization +Bundle-SymbolicName: flintstones.method.decision.common.phase.normalization;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.normalization +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.valuation, + flintstones.model.valuation.service, + javax.inject, + flintstones.operator, + flintstones.entity.problemelement, + flintstones.entity.ahp.decisionmatrix, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.entity.wvaluation, + flintstones.model.problemelement.service, + flintstones.entity.operator, + flintstones.entity.method.phase +Export-Package: flintstones.method.decision.common.phase.normalization diff --git a/bundles/flintstones.method.decision.common.phase.normalization/build.properties b/bundles/flintstones.method.decision.common.phase.normalization/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.normalization/plugin.xml b/bundles/flintstones.method.decision.common.phase.normalization/plugin.xml new file mode 100644 index 0000000..8b6d7f7 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.normalization/src/flintstones/method/decision/common/phase/normalization/NormalizationModel.java b/bundles/flintstones.method.decision.common.phase.normalization/src/flintstones/method/decision/common/phase/normalization/NormalizationModel.java new file mode 100644 index 0000000..6e81060 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.normalization/src/flintstones/method/decision/common/phase/normalization/NormalizationModel.java @@ -0,0 +1,179 @@ +package flintstones.method.decision.common.phase.normalization; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.TreeMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.ahp.decisionmatrix.DecisionMatrix; +import flintstones.entity.method.phase.ImportedDataNotFoundException; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.NormalizationOperator; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.entity.wvaluation.WValuation; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; + +public class NormalizationModel extends PhaseMethod { + + @Inject + IValuationService valuationService; + + @Inject + IOperatorService operatorService; + + @Inject + IProblemElementService problemService; + + @Inject + IEclipseContext context; + + final HashMap expertsMatrix = new HashMap<>(); + + final HashMap normalizationOperators = new HashMap<>(); + + final HashMap aggregationOperators = new HashMap<>(); + + @Override + public String getName() { + return "Normalization"; + } + + @Override + public String getInfo() { + return "Se normalizan las valoraciones creando una matrix de decisión para cada experto.\n" + + "Normalizando por columnas esa matrix \n" + + "Y finalmente se agregan en una única matrix de decisión"; + } + + public void init() { + for( ProblemElement e : problemService.getSubElements(Expert.Type) ) { + DecisionMatrix dm = ContextInjectionFactory.make(DecisionMatrix.class, context); + HashMap valuations = valuationService.getAllValuationsKVWith(e); + dm.addContent(valuations); + expertsMatrix.put((Expert) e, dm); + } + } + + public String[] getNormalizationOperators() { + + NormalizationOperator[] operators = operatorService.getNormalizationOperatorsFor(valuationService.getAll()[0]); + ArrayList operatorNames = new ArrayList<>(); + + for( NormalizationOperator op : operators ) { + operatorNames.add(op.getName()); + normalizationOperators.put(op.getName(), op); + } + return operatorNames.stream().sorted().toArray( String[]::new ); + + } + + public String[] getAggregationOperators() { + + AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(valuationService.getAll()[0].getId(), checkWeightsExported()); + ArrayList operatorNames = new ArrayList<>(); + + for( AggregationOperator op : operators ) { + operatorNames.add(op.getName()); + aggregationOperators.put(op.getName(), op); + } + return operatorNames.stream().sorted().toArray( String[]::new ); + + } + + private boolean checkWeightsExported() { + try { + this.importData(("criterionWeights")); + return true; + } catch(ImportedDataNotFoundException e) {} + + try { + this.importData(("expertWeights")); + return true; + } catch(ImportedDataNotFoundException e) {} + + return false; + } + + public DecisionMatrix execute(String normalizationName, String aggregationName) { + + if(normalizationName.equals("") || aggregationName.equals("")) + return null; + + HashMap normalizedDecisionMatrix = normalize(normalizationName); + DecisionMatrix aggregatedDecisionMatrix = aggregate(aggregationName, normalizedDecisionMatrix); + + this.exportData("decisionMatrix", aggregatedDecisionMatrix); + + return aggregatedDecisionMatrix; + } + + private DecisionMatrix aggregate(String aggregationName, HashMap normalizedDecisionMatrix) { + AggregationOperator operator = this.aggregationOperators.get(aggregationName); + DecisionMatrix finalDM = (DecisionMatrix) normalizedDecisionMatrix.values().iterator().next().clone(); + + for( Alternative a : finalDM.getAlternatives() ) { + for( Criterion c : finalDM.getCriterions() ) { + ArrayList cellValuations = getEveryValuationFor(a, c, normalizedDecisionMatrix); + Valuation aggValuation = operator.computeAggregation(cellValuations, null); + finalDM.set(c, a, aggValuation); + } + + } + return finalDM; + } + + public ArrayList getEveryValuationFor(Alternative a, Criterion c, HashMap normalizedDecisionMatrix) { + + ArrayList valuations = new ArrayList<>(); + for( DecisionMatrix dm : normalizedDecisionMatrix.values() ) { + valuations.add(dm.getColumn(c).get(a).getValuation()); + } + return valuations; + + } + + private HashMap normalize(String normalizationName) { + + String normalizationId = this.normalizationOperators.get(normalizationName).getId(); + + HashMap normalizedDecisionMatrix = new HashMap<>(); + + // Foreach decision matrix + for( Entry entry : this.expertsMatrix.entrySet() ) { + + Expert e = entry.getKey(); + final DecisionMatrix dm = entry.getValue(); + DecisionMatrix normDm = (DecisionMatrix) dm.clone(); + + // Grab each column and normalize it + for( Criterion c : normDm.getCriterions() ) { + TreeMap column = normDm.getColumn(c); + + WValuation[] beforeValuations = column.values().stream().toArray(WValuation[]::new); + WValuation[] afterValuations = operatorService.normalize(normalizationId, Arrays.asList(beforeValuations)); + + Arrays.stream( afterValuations ).forEach( w -> normDm.set(w.getPEK().getCriterion(), w.getPEK().getAlternative(), w.getValuation())); + + } + + normalizedDecisionMatrix.put(e, normDm); + } + + return normalizedDecisionMatrix; + } + +} diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/.classpath b/bundles/flintstones.method.decision.common.phase.selection.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.selection.ui/.polyglot.META-INF new file mode 100644 index 0000000..e3809b8 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.selection.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/.project b/bundles/flintstones.method.decision.common.phase.selection.ui/.project new file mode 100644 index 0000000..e57d35d --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.selection.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362661 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.selection.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3123745 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/META-INF/MANIFEST.MF @@ -0,0 +1,33 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.decision.common.phase.selection.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Require-Bundle: flintstones.method.decision.common.phase.selection, + org.eclipse.swt, + flintstones.entity.problemelement, + javax.inject, + flintstones.valuation.twoTuple, + org.eclipse.jface, + flintstones.domain.fuzzyset.ui.dialog, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.services, + flintstones.helper.ui, + flintstones.model.problemelement.service, + de.kupzog.ktable, + org.eclipse.e4.core.di, + flintstones.entity.domain, + flintstones.entity.valuation, + flintstones.model.domain.ui.service, + flintstones.entity.domain.ui.chart, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui, + org.jfree.chart.jfreechart, + flintstones.domain.fuzzyset.ui.chart, + flintstones.helper.data, + org.eclipse.nebula.widgets.opal.notifier, + org.eclipse.e4.ui.model.workbench;bundle-version="2.1.0.v20180429-1333" +Automatic-Module-Name: flintstones.method.decision.common.phase.selection.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Export-Package: flintstones.method.decision.common.phase.selection.ui.handler diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/build.properties b/bundles/flintstones.method.decision.common.phase.selection.ui/build.properties new file mode 100644 index 0000000..3ea470d --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/build.properties @@ -0,0 +1,5 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml +source.. = src/ diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/plugin.xml b/bundles/flintstones.method.decision.common.phase.selection.ui/plugin.xml new file mode 100644 index 0000000..4423b24 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/plugin.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateDistancesUI.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateDistancesUI.java new file mode 100644 index 0000000..2f1f239 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateDistancesUI.java @@ -0,0 +1,517 @@ +package flintstones.method.decision.common.phase.selection.ui; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +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.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +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.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TableColumn; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.ui.chart.DomainChart; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.valuation.Valuation; +import flintstones.method.decision.common.phase.selection.CalculateDistancesSelectionModel; +import flintstones.method.decision.common.phase.selection.ui.messages.Messages; +import flintstones.method.decision.common.phase.selection.ui.provider.ClosenessCoefficientsTableViewerContentProvider; +import flintstones.method.decision.common.phase.selection.ui.provider.PositiveNegativeTableViewerContentProvider; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class CalculateDistancesUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + @Inject + IDomainUIService uiDomainService; + + @Inject + IProblemElementService problemElementService; + + // FS3 + private Composite parent; + private Composite informationPanel; + private Composite distanceEditorPanel; + private Composite chartView; + + private Combo retranslationCombo; + + private TableViewer tableViewerPositiveNegative; + private TableViewer tableViewerClosenessCoefficients; // X + + private ControlAdapter controlListener; + + private PositiveNegativeTableViewerContentProvider positiveNegativeProvider; + private ClosenessCoefficientsTableViewerContentProvider closenessCoefficientsProvider; + + private DomainChart chart; + + CalculateDistancesSelectionModel model; + + @Inject + @Translation + Messages messages; + + @Override + public void init() { + model = (CalculateDistancesSelectionModel) this.getModel(); + createPartControl(this.getBaseComposite()); + } + + @Override + public void refresh() { + model.execute(); + setInputDistancesTable(); + setInputCoefficientsTable(); + refreshChart(); + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + private static class DataComparator implements Comparator { + public int compare(Object[] d1, Object[] d2) { + Alternative a1 = (Alternative) d1[0]; + Alternative a2 = (Alternative) d2[0]; + return a1.compareTo(a2); + } + } + + public void createPartControl(Composite parent) { + model.execute(); + + this.parent = parent; + + UiService.setGridData(this.parent, 9, 9, true, true); + GridLayout layout = UiService.setGridLayout(this.parent, 1, true); + layout.horizontalSpacing = 15; + layout.verticalSpacing = 15; + + createContent(); + } + + private void createContent() { + distanceEditorPanel = new Composite(parent, SWT.NONE); + + GridLayout ratingEditorPanelLayout = UiService.setGridLayout(distanceEditorPanel, 1, false); + ratingEditorPanelLayout.marginRight = 0; + ratingEditorPanelLayout.verticalSpacing = 0; + ratingEditorPanelLayout.marginWidth = 10; + ratingEditorPanelLayout.marginHeight = 10; + UiService.setGridData(distanceEditorPanel, 9, 9, true, true); + + GridLayout informationLayout = new GridLayout(2, true); + informationLayout.marginWidth = 10; + informationLayout.marginHeight = 10; + + informationPanel = new Composite(distanceEditorPanel, SWT.NONE); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + informationPanel.setLayoutData(gridData); + informationPanel.setLayout(informationLayout); + + createDistancesTable(); + createClosenessCoefficientsTable(); + createChart(); + createRetranslationCombo(); + setSensitivityAnalysisData(); + } + + private void createDistancesTable() { + GridLayout positiveNegativeLayout = new GridLayout(1, true); + positiveNegativeLayout.marginWidth = 10; + positiveNegativeLayout.marginHeight = 10; + + Composite positveNegativePanel = new Composite(informationPanel, SWT.NONE); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + positveNegativePanel.setLayoutData(gridData); + positveNegativePanel.setLayout(positiveNegativeLayout); + + Label positiveNegativeLabel = new Label(positveNegativePanel, SWT.NONE); + positiveNegativeLabel.setText(messages.CalculateDistances_Ideal_solution); + UiService.setFont(positiveNegativeLabel, UiService.FONT_TEXT_BOLD); + gridData = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1); + positiveNegativeLabel.setLayoutData(gridData); + + tableViewerPositiveNegative = new TableViewer(positveNegativePanel, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + tableViewerPositiveNegative.getTable().setLayoutData(gridData); + tableViewerPositiveNegative.getTable().setHeaderVisible(true); + + positiveNegativeProvider = new PositiveNegativeTableViewerContentProvider(); + tableViewerPositiveNegative.setContentProvider(positiveNegativeProvider); + + TableViewerColumn alternativeColumn = new TableViewerColumn(tableViewerPositiveNegative, SWT.NONE); + alternativeColumn.getColumn().setText(messages.CalculateDistances_Alternative); + alternativeColumn.getColumn().pack(); + alternativeColumn.getColumn().setResizable(false); + alternativeColumn.getColumn().setMoveable(false); + alternativeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + return ((Alternative) data[0]).getName(); + } + }); + + TableViewerColumn positiveColumn = new TableViewerColumn(tableViewerPositiveNegative, SWT.NONE); + positiveColumn.getColumn().setText(messages.CalculateDistances_Positive_distance); + positiveColumn.getColumn().setResizable(false); + positiveColumn.getColumn().setMoveable(false); + positiveColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + TwoTupleValuation distance = (TwoTupleValuation) data[1]; + + String labelName = distance.getLabel().getName(); + String alpha = Double.toString(distance.getAlpha()); + + if(alpha.equals("-0.0") || alpha.equals("0.0")) { //$NON-NLS-1$ //$NON-NLS-2$ + 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$ + } + }); + + TableViewerColumn negativeColumn = new TableViewerColumn(tableViewerPositiveNegative, SWT.NONE); + negativeColumn.getColumn().setText(messages.CalculateDistances_Negative_distance); + negativeColumn.getColumn().setResizable(false); + negativeColumn.getColumn().setMoveable(false); + negativeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + TwoTupleValuation distance = (TwoTupleValuation) data[2]; + + String labelName = distance.getLabel().getName(); + String alpha = Double.toString(distance.getAlpha()); + + if(alpha.equals("-0.0") || alpha.equals("0.0")) { //$NON-NLS-1$ //$NON-NLS-2$ + 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$ + + } + }); + + setInputDistancesTable(); + } + + public void setInputDistancesTable() { + List distances = new LinkedList(); + List idealDistances = model.getIdealDistances(); + List noIdealDistances = model.getNoIdealDistances(); + for(int i = 0; i < model.getIdealDistances().size(); ++i) { + Object[] distanceData = new Object[3]; + distanceData[0] = problemElementService.getAll(Alternative.Type)[i]; + distanceData[1] = idealDistances.get(i); + distanceData[2] = noIdealDistances.get(i); + distances.add(distanceData); + } + + Collections.sort(distances, new DataComparator()); + + positiveNegativeProvider.setInput(distances); + tableViewerPositiveNegative.setInput(positiveNegativeProvider.getInput()); + for(TableColumn tc: tableViewerPositiveNegative.getTable().getColumns()) { + tc.pack(); + } + } + + private void createClosenessCoefficientsTable() { + GridLayout distanceIdealSolutionLayout = new GridLayout(1, false); + distanceIdealSolutionLayout.marginWidth = 10; + distanceIdealSolutionLayout.marginHeight = 10; + + Composite distanceIdealSolutionPanel = new Composite(informationPanel, SWT.NONE); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + distanceIdealSolutionPanel.setLayoutData(gridData); + distanceIdealSolutionPanel.setLayout(distanceIdealSolutionLayout); + + Label colLectiveValuationsLabel = new Label(distanceIdealSolutionPanel, SWT.NONE); + colLectiveValuationsLabel.setText(messages.CalculateDistances_Ideal_solution_distance); + UiService.setFont(colLectiveValuationsLabel, UiService.FONT_TEXT_BOLD); + gridData = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1); + colLectiveValuationsLabel.setLayoutData(gridData); + + tableViewerClosenessCoefficients = new TableViewer(distanceIdealSolutionPanel, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + + tableViewerClosenessCoefficients.getTable().setLayoutData(gridData); + tableViewerClosenessCoefficients.getTable().setHeaderVisible(true); + + closenessCoefficientsProvider = ContextInjectionFactory.make(ClosenessCoefficientsTableViewerContentProvider.class, context); + tableViewerClosenessCoefficients.setContentProvider(closenessCoefficientsProvider); + + TableViewerColumn alternativeColumn = new TableViewerColumn(tableViewerClosenessCoefficients, SWT.NONE); + alternativeColumn.getColumn().setText(messages.CalculateDistances_Alternative); + alternativeColumn.getColumn().setResizable(true); + alternativeColumn.getColumn().setMoveable(true); + alternativeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + return ((Alternative) data[0]).getName(); + } + }); + + TableViewerColumn closenessCoefficient = new TableViewerColumn(tableViewerClosenessCoefficients, SWT.NONE); + closenessCoefficient.getColumn().setText(messages.CalculateDistances_Closeness_coefficient); + closenessCoefficient.getColumn().setResizable(false); + closenessCoefficient.getColumn().setMoveable(false); + closenessCoefficient.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + TwoTupleValuation distance = (TwoTupleValuation) data[1]; + + String labelName = distance.getLabel().getName(); + String alpha = Double.toString(distance.getAlpha()); + + if(alpha.equals("-0.0") || alpha.equals("0.0")) { //$NON-NLS-1$ //$NON-NLS-2$ + 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$ + } + }); + + TableViewerColumn ranking = new TableViewerColumn(tableViewerClosenessCoefficients, SWT.NONE); + ranking.getColumn().setText(messages.CalculateDistances_Ranking); + ranking.getColumn().setResizable(false); + ranking.getColumn().setMoveable(false); + ranking.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + return (Integer.toString((int) data[2])); + } + }); + + setInputCoefficientsTable(); + + alternativeColumn.getColumn().pack(); + closenessCoefficient.getColumn().pack(); + ranking.getColumn().pack(); + } + + private void setInputCoefficientsTable() { + closenessCoefficientsProvider.setInput(model.getClosenessCoeficient()); + tableViewerClosenessCoefficients.setInput(closenessCoefficientsProvider.getInput()); + tableViewerClosenessCoefficients.refresh(true); + for(TableColumn tc: tableViewerClosenessCoefficients.getTable().getColumns()) { + tc.pack(); + } + } + + private void createChart() { + Composite chartViewParent = new Composite(distanceEditorPanel, SWT.NONE); + GridLayout layout = new GridLayout(1, false); + chartViewParent.setLayout(layout); + chartViewParent.setLayoutData(new GridData(GridData.FILL_BOTH)); + + chartView = new Composite(chartViewParent, SWT.NONE); + GridData gd = UiService.setGridData(chartView, 9, 9, true, true); + gd.heightHint = 200; + + setChart(model.getDistanceDomain()); + } + + private void setChart(FuzzySet distanceDomain) { + removeChart(); + + chart = uiDomainService.createChart(model.getDistanceDomain().getType()); + chart.initialize(distanceDomain, chartView, chartView.getSize().x, chartView.getSize().y, SWT.BORDER); + + if (controlListener == null) { + controlListener = new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + setChart(distanceDomain); + } + }; + chartView.addControlListener(controlListener); + } + + displayAlternatives(); + + } + + private void removeChart() { + if (chart != null) { + chart.getChartComposite().dispose(); + chartView.layout(); + } + } + + private void createRetranslationCombo() { + retranslationCombo = new Combo(distanceEditorPanel, SWT.NONE); + retranslationCombo.setLayoutData(new GridData(SWT.RIGHT, SWT.RIGHT, false, false, 1, 1)); + retranslationCombo.setItems(model.getDistanceDomainsIds()); + retranslationCombo.add(model.getDefaultDistanceDomain().getName(), 0); + retranslationCombo.select(0); + + retranslationCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String id = retranslationCombo.getText(); + FuzzySet selectedDomain = model.getDistanceDomain(id); + + if(selectedDomain == null) + selectedDomain = model.getDefaultDistanceDomain(); + + model.setDistanceDomain(selectedDomain); + model.retranslateResults(); + setChart(selectedDomain); + setInputCoefficientsTable(); + } + }); + } + + + private void displayAlternatives() { + Map closenessCoefficients = model.getClosenessCoeficient(); + + String[] alternatives = new String[closenessCoefficients.size()]; + int[] pos = new int[alternatives.length]; + double[] alpha = new double[alternatives.length]; + + int alt = 0; + for(Alternative a: closenessCoefficients.keySet()) { + alternatives[alt] = "a" + (Arrays.asList(problemElementService.getAll(Alternative.Type)).indexOf(a) + 1); + pos[alt] = model.getDistanceDomain().getLabelSet().getPos(((TwoTupleValuation) closenessCoefficients.get(a)).getLabel()); + alpha[alt] = ((TwoTupleValuation) closenessCoefficients.get(a)).getAlpha(); + alt++; + } + chart.displayAlternatives(alternatives, pos, alpha); + } + + private void setSensitivityAnalysisData() { + setDecisionMatrix(); + setWeights(); + setFinalPreferences(); + } + + private void setDecisionMatrix() { + Valuation[][] dm = model.getDecisionMatrix(); + Double[][] dmNumbers = new Double[dm.length][dm[0].length]; + for(int i = 0; i < dm.length; ++i) { + for(int j = 0; j < dm[i].length; ++j) { + dmNumbers[i][j] = (double) (Math.round(((TwoTupleValuation) dm[i][j]).calculateInverseDelta() * 100d) / 100d); + } + } + } + + public void setWeights() { + TwoTupleValuation[] weights = model.getCriteriaWeights(); + Double[] weightsNumber = new Double[weights.length]; + int wcont = 0; + double acum = 0; + for(TwoTupleValuation weight: weights) { + weightsNumber[wcont] = weight.calculateInverseDelta(); + acum += weightsNumber[wcont]; + wcont++; + } + + for(int i = 0; i < weightsNumber.length; ++i) { + weightsNumber[i] /= acum; + } + + } + + private void setFinalPreferences() { + Map coefficients = model.getClosenessCoeficient(); + Double[] preferences = new Double[coefficients.size()]; + int cont = 0; + for(Alternative a: coefficients.keySet()) { + preferences[cont] = ((TwoTupleValuation) coefficients.get(a)).calculateInverseDelta(); + cont++; + } + } + + private void refreshChart() { + disposeControlsChartComposite(); + + chart = uiDomainService.createChart(model.getDistanceDomain().getType()); + chart.initialize(model.getDistanceDomain(), chartView, chartView.getSize().x, chartView.getSize().y, SWT.BORDER); + + displayAlternatives(); + } + + private void disposeControlsChartComposite() { + for(Control c: chartView.getChildren()) { + c.dispose(); + } + } +} diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateSolutionsSelectionUI.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateSolutionsSelectionUI.java new file mode 100644 index 0000000..b431782 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateSolutionsSelectionUI.java @@ -0,0 +1,330 @@ +package flintstones.method.decision.common.phase.selection.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.nls.Translation; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TableColumn; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.valuation.Valuation; +import flintstones.method.decision.common.phase.selection.CalculateSolutionsSelectionModel; +import flintstones.method.decision.common.phase.selection.ui.messages.Messages; +import flintstones.method.decision.common.phase.selection.ui.provider.IdealSolutionTableViewerContentProvider; +import flintstones.method.decision.common.phase.selection.ui.provider.NoIdealSolutionTableViewerContentProvider; +import flintstones.method.decision.common.phase.selection.ui.table.DecisionMatrixTable; +import flintstones.model.ui.service.UiService; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +@SuppressWarnings("javadoc") +public class CalculateSolutionsSelectionUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + @Inject + @Translation + Messages messages; + + CalculateSolutionsSelectionModel model; + + private Composite parent; + private Composite solutionsComposite; + + private Combo expertsCombo; + + private TableViewer tableViewerIdealSolution; + private TableViewer tableViewerNoIdealSolution; + private DecisionMatrixTable decisionMatrixTable; + + private IdealSolutionTableViewerContentProvider idealSolutionProvider; + private NoIdealSolutionTableViewerContentProvider noIdealSolutionProvider; + + private Valuation[][] decisionMatrix; + + @Override + public void init() { + model = (CalculateSolutionsSelectionModel) this.getModel(); + Composite parent = this.getBaseComposite(); + createPartControl(parent); + } + + @Override + public void refresh() { + model.execute(decisionMatrix); + setInputTableCollective(); + setInputIdealSolutionTable(); + setInputNoIdealSolution(); + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + @Override + public boolean isSkippable() { + return false; + } + + public void createPartControl(Composite parent) { + decisionMatrix = model.getCollectiveDecisionMatrix(); + + model.execute(decisionMatrix); + + this.parent = parent; + + createContent(); + } + + private void createContent() { + UiService.setGridLayout(parent, 1, false); + UiService.setGridData(parent, 9, 9, true, true); + + createInfoByExpertCombo(); + createCollectiveValuationsTable(); + + solutionsComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(solutionsComposite, 2, true); + UiService.setGridData(solutionsComposite, 9, 9, true, true); + + createIdealSolutionTable(); + createNoIdealSolutionTable(); + } + + private void createInfoByExpertCombo() { + Composite comboComposite = new Composite(parent, SWT.NONE); + UiService.setGridData(comboComposite, 9, 9, true, false); + UiService.setGridLayout(comboComposite, 2, false); + + Label selectExpertLabel = new Label(comboComposite, SWT.NONE); + selectExpertLabel.setText("Select expert:"); + UiService.setFont(selectExpertLabel, UiService.FONT_TEXT_BOLD); + + expertsCombo = new Combo(comboComposite, SWT.NONE); + expertsCombo.setItems(model.getExpertsName()); + expertsCombo.add(messages.Collective, expertsCombo.getItemCount()); + expertsCombo.select(expertsCombo.getItemCount() - 1); + expertsCombo.addSelectionListener(changeInfoSelectionListener()); + } + + private SelectionListener changeInfoSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String selection = expertsCombo.getText(); + if(model.isExpert(selection)) + decisionMatrix = model.getExpertDecisionMatrix(selection); + else + decisionMatrix = model.getCollectiveDecisionMatrix(); + + refresh(); + } + }; + } + + private void createCollectiveValuationsTable() { + Composite decisionMatrixComposite = new Composite(parent, SWT.NONE); + UiService.setGridData(decisionMatrixComposite, 9, 9, true, true); + GridLayout layout = UiService.setGridLayout(decisionMatrixComposite, 1, true); + layout.horizontalSpacing = 15; + layout.verticalSpacing = 15; + + decisionMatrixTable = new DecisionMatrixTable(decisionMatrixComposite); + ContextInjectionFactory.inject(decisionMatrixTable, context); + UiService.setGridData(decisionMatrixTable, 9, 9, true, true); + decisionMatrixTable.setModel(decisionMatrix); + } + + private void setInputTableCollective() { + decisionMatrixTable.setModel(decisionMatrix); + decisionMatrixTable.redraw(); + } + + private void createIdealSolutionTable() { + Composite idealSolutionComposite = new Composite(solutionsComposite, SWT.NONE); + UiService.setGridLayout(idealSolutionComposite, 1, true); + UiService.setGridData(idealSolutionComposite, 9, 9, true, true); + + Label idealSolutionLabel = new Label(idealSolutionComposite, SWT.NONE); + idealSolutionLabel.setText(messages.calculate_solutions_Ideal_solution); + UiService.setFont(idealSolutionLabel, UiService.FONT_TEXT_BOLD); + UiService.setGridData(idealSolutionLabel, 0, 0, true, false); + + tableViewerIdealSolution = new TableViewer(idealSolutionComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + UiService.setGridData(tableViewerIdealSolution.getTable(), 9, 9, true, true); + tableViewerIdealSolution.getTable().setHeaderVisible(true); + + idealSolutionProvider = ContextInjectionFactory.make(IdealSolutionTableViewerContentProvider.class, context); + tableViewerIdealSolution.setContentProvider(idealSolutionProvider); + + createIdealSolutionTableColumns(); + setInputIdealSolutionTable(); + } + + private void createIdealSolutionTableColumns() { + TableViewerColumn criterionColumn = new TableViewerColumn(tableViewerIdealSolution, SWT.NONE); + criterionColumn.getColumn().setText(messages.calculate_solutions_Criterion); + criterionColumn.getColumn().pack(); + criterionColumn.getColumn().setResizable(false); + criterionColumn.getColumn().setMoveable(false); + criterionColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + return ((Criterion) data[0]).getName(); + } + }); + + TableViewerColumn typeColumn = new TableViewerColumn(tableViewerIdealSolution, SWT.NONE); + typeColumn.getColumn().setText(messages.calculate_solutions_Type); + typeColumn.getColumn().pack(); + typeColumn.getColumn().setResizable(false); + typeColumn.getColumn().setMoveable(false); + typeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return ""; //$NON-NLS-1$ + } + + @Override + public Image getImage(Object element) { + Object[] data = (Object[]) element; + if (((Criterion) data[0]).isCost()) { + return UiService.getIcon("cost.png").createImage(); //$NON-NLS-1$ + } + return UiService.getIcon("benefit.png").createImage(); //$NON-NLS-1$ + } + }); + + TableViewerColumn valuationColumn = new TableViewerColumn(tableViewerIdealSolution, SWT.NONE); + valuationColumn.getColumn().setText(messages.calculate_solutions_Valuation); + valuationColumn.getColumn().pack(); + valuationColumn.getColumn().setResizable(true); + valuationColumn.getColumn().setMoveable(true); + valuationColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + TwoTupleValuation valuation = (TwoTupleValuation) data[1]; + + String valuationString = valuation.prettyFormat(); + valuationString = valuationString.replace("(", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valuationString = valuationString.replace(")", ""); //$NON-NLS-1$ //$NON-NLS-2$ + String[] elements = valuationString.split(","); //$NON-NLS-1$ + + return "(" + elements[0] + ", " + elements[1] + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + } + + }); + } + + private void setInputIdealSolutionTable() { + idealSolutionProvider.setInput(model.getIdealSolution()); + tableViewerIdealSolution.setInput(idealSolutionProvider.getInput()); + + for (TableColumn tc : tableViewerIdealSolution.getTable().getColumns()) + tc.pack(); + } + + private void createNoIdealSolutionTable() { + Composite noIdealSolutionComposite = new Composite(solutionsComposite, SWT.NONE); + UiService.setGridLayout(noIdealSolutionComposite, 1, true); + UiService.setGridData(noIdealSolutionComposite, 9, 9, true, true); + + Label noIdealSolutionLabel = new Label(noIdealSolutionComposite, SWT.NONE); + noIdealSolutionLabel.setText(messages.calculate_solutions_No_ideal_solution); + UiService.setFont(noIdealSolutionLabel, UiService.FONT_TEXT_BOLD); + UiService.setGridData(noIdealSolutionLabel, 0, 0, true, false); + + tableViewerNoIdealSolution = new TableViewer(noIdealSolutionComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + UiService.setGridData(tableViewerNoIdealSolution.getTable(), 9, 9, true, true); + tableViewerNoIdealSolution.getTable().setHeaderVisible(true); + + noIdealSolutionProvider = ContextInjectionFactory.make(NoIdealSolutionTableViewerContentProvider.class, context); + tableViewerNoIdealSolution.setContentProvider(noIdealSolutionProvider); + + createNoIdealSolutionTableColumns(); + setInputNoIdealSolution(); + } + + private void createNoIdealSolutionTableColumns() { + TableViewerColumn criterionColumn = new TableViewerColumn(tableViewerNoIdealSolution, SWT.NONE); + criterionColumn.getColumn().setText(messages.calculate_solutions_Criterion); + criterionColumn.getColumn().pack(); + criterionColumn.getColumn().setResizable(false); + criterionColumn.getColumn().setMoveable(false); + criterionColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + return ((Criterion) data[0]).getName(); + } + }); + + TableViewerColumn typeColumn = new TableViewerColumn(tableViewerNoIdealSolution, SWT.NONE); + typeColumn.getColumn().setText(messages.calculate_solutions_Type); + typeColumn.getColumn().pack(); + typeColumn.getColumn().setResizable(false); + typeColumn.getColumn().setMoveable(false); + typeColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return ""; //$NON-NLS-1$ + } + + @Override + public Image getImage(Object element) { + Object[] data = (Object[]) element; + if (((Criterion) data[0]).isCost()) { + return UiService.getIcon("cost.png").createImage(); //$NON-NLS-1$ + } + return UiService.getIcon("benefit.png").createImage(); //$NON-NLS-1$ + } + }); + + TableViewerColumn valuationColumn = new TableViewerColumn(tableViewerNoIdealSolution, SWT.NONE); + valuationColumn.getColumn().setText(messages.calculate_solutions_Valuation); + valuationColumn.getColumn().pack(); + valuationColumn.getColumn().setResizable(true); + valuationColumn.getColumn().setMoveable(true); + valuationColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + Object[] data = (Object[]) element; + TwoTupleValuation valuation = (TwoTupleValuation) data[1]; + + String valuationString = valuation.prettyFormat(); + valuationString = valuationString.replace("(", ""); //$NON-NLS-1$ //$NON-NLS-2$ + valuationString = valuationString.replace(")", ""); //$NON-NLS-1$ //$NON-NLS-2$ + String[] elements = valuationString.split(","); //$NON-NLS-1$ + + return "(" + elements[0] + ", " + elements[1] + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + }); + } + + private void setInputNoIdealSolution() { + noIdealSolutionProvider.setInput(model.getNoIdealSolution()); + tableViewerNoIdealSolution.setInput(noIdealSolutionProvider.getInput()); + + for (TableColumn tc : tableViewerNoIdealSolution.getTable().getColumns()) + tc.pack(); + } +} diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateWeightsUI.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateWeightsUI.java new file mode 100644 index 0000000..9e1ba2b --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/CalculateWeightsUI.java @@ -0,0 +1,304 @@ +package flintstones.method.decision.common.phase.selection.ui; + +import java.util.Map; + +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.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.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.ui.chart.LinguisticDomainChart; +import flintstones.entity.domain.ui.chart.DomainChart; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.method.decision.common.phase.selection.CalculateWeightsSelectionModel; +import flintstones.method.decision.common.phase.selection.ui.handler.PasteWeightsHandler; +import flintstones.method.decision.common.phase.selection.ui.messages.Messages; +import flintstones.method.decision.common.phase.selection.ui.table.ExpertsWeightTable; +import flintstones.model.domain.ui.service.IDomainUIService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class CalculateWeightsUI extends PhaseMethodUI { + + //private static final String[] FILTER_NAMES = { "Text files (*.txt)" }; //$NON-NLS-1$ + //private static final String[] FILTER_EXTS = { "*.txt" }; //$NON-NLS-1$ + + @Inject + IProblemElementService problemService; + + @Inject + IEclipseContext context; + + @Inject + IDomainUIService uiDomainService; + + private Composite parent; + private Composite tableComposite; + private Composite chartView; + + private ControlAdapter controlListener; + + private Combo weightsDomainCombo; + + private ExpertsWeightTable expertsWeightTable; + + private DomainChart chart; + + private CalculateWeightsSelectionModel model; + + @Inject + @Translation + Messages messages; + + @Override + public void init() { + model = (CalculateWeightsSelectionModel) this.getModel(); + Composite parent = this.getBaseComposite(); + createPartControl(parent); + model.exportData(); + } + + @Override + public void refresh() { + model.execute(); + expertsWeightTable.redraw(); + setChart(); + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + @Override + public boolean isSkippable() { + return false; + } + + public void createPartControl(Composite parent) { + this.parent = parent; + + GridLayout layout = UiService.setGridLayout(this.parent, 1, true); + UiService.setGridData(this.parent, 9, 9, true, true); + layout.horizontalSpacing = 15; + layout.verticalSpacing = 15; + + createContent(); + + model.execute(); + } + + private void createContent() { + createTable(); + createButtonsFile(); + createChart(); + } + + private void createTable() { + tableComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(tableComposite, 1, true); + UiService.setGridData(tableComposite, 9, 9, true, true); + + expertsWeightTable = new ExpertsWeightTable(tableComposite); + ContextInjectionFactory.inject(expertsWeightTable, context); + UiService.setGridData(expertsWeightTable, 9, 9, true, true); + expertsWeightTable.setModel(model); + } + + private void createButtonsFile() { + Composite buttonsComposite = new Composite(tableComposite, SWT.NONE); + GridLayout layout = UiService.setGridLayout(buttonsComposite, 2, false); + UiService.setGridData(buttonsComposite, 1, 1, true, false); + layout.horizontalSpacing = 15; + layout.verticalSpacing = 15; + + /*Button exportWeights = new Button(buttonsComposite, SWT.NONE); + exportWeights.setText(messages.Export_weights); + UiService.setGridData(exportWeights, 1, 9, true, true); + exportWeights.addSelectionListener(createExportWeightsSelectionAdapter());*/ + + weightsDomainCombo = new Combo(buttonsComposite, SWT.NONE); + UiService.setGridData(weightsDomainCombo, 1, 9, true, true); + weightsDomainCombo.setItems(model.getWeightsDomainsIds()); + weightsDomainCombo.add(model.getDefaultWeightsDomain().getName(), 0); + weightsDomainCombo.addSelectionListener(createWeightDomainSelectionAdapter()); + weightsDomainCombo.select(0); + + Button importWeights = new Button(buttonsComposite, SWT.NONE); + importWeights.setText(messages.Import_weights); + UiService.setGridData(importWeights, 1, 9, true, true); + importWeights.addSelectionListener(createImportWeightsSelectionAdapter()); + } + + private SelectionListener createImportWeightsSelectionAdapter() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + PasteWeightsHandler handler = new PasteWeightsHandler(); + ContextInjectionFactory.inject(handler, context); + + Map expertsWeights = handler.execute(model.getCurrentWeightsDomain()); + if(expertsWeights != null) { + model.setExperstWeights(expertsWeights); + refresh(); + } + + /*FileDialog dlg = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN); + dlg.setFilterNames(FILTER_NAMES); + dlg.setFilterExtensions(FILTER_EXTS); + String fileName = dlg.open(); + + if(fileName != null) { + readFileContent(fileName); + }*/ + } + + /*private void readFileContent(String fileName) { + Map expertsWeights = new HashMap<>(); + + FileReader fr = null; + BufferedReader br = null; + try { + fr = new FileReader(fileName); + br = new BufferedReader(fr); + + String sCurrentLine; + while ((sCurrentLine = br.readLine()) != null) { + String[] info = sCurrentLine.split(":"); + Expert e = (Expert) problemService.getByName(Expert.Type, info[0]); + Criterion criterion = (Criterion) problemService.getByName(Criterion.Type, info[1]); + LabelLinguisticDomain weight = model.getWeightsDomain().getLabelSet().getLabel(info[2]); + + LabelLinguisticDomain[] weights; + if(expertsWeights.get(e) == null) { + weights = new LabelLinguisticDomain[(problemService.getSubElements(Criterion.Type).length)]; + expertsWeights.put(e, weights); + } else + weights = expertsWeights.get(e); + + weights[Arrays.asList(problemService.getSubElements(Criterion.Type)).indexOf(criterion)] = weight; + } + + model.setExperstWeights(expertsWeights); + refresh(); + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (br != null) + br.close(); + + if (fr != null) + fr.close(); + + } catch (IOException ex) { + ex.printStackTrace(); + } + } + }*/ + }; + } + + /*private SelectionListener createExportWeightsSelectionAdapter() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + FileDialog dlg = new FileDialog(Display.getDefault().getActiveShell(), SWT.SAVE); + dlg.setFilterNames(FILTER_NAMES); + dlg.setFilterExtensions(FILTER_EXTS); + String fileName = dlg.open(); + + if(fileName != null) + generateFileContent(fileName); + } + + private void generateFileContent(String fileName) { + StringBuilder content = new StringBuilder(); + for(ProblemElement e: problemService.getSubElements(Expert.Type)) { + for(ProblemElement c: problemService.getSubElements(Criterion.Type)) { + content.append(e.getName() + ":" + c.getName() + ":" + model.getExpertWeight((Expert) e, + Arrays.asList(problemService.getSubElements(Criterion.Type)).indexOf(c)).getName()); + content.append(System.getProperty("line.separator")); + } + } + + content.deleteCharAt(content.length() - 1); + content.deleteCharAt(content.length() - 1); + + PrintWriter writer; + try { + writer = new PrintWriter(fileName, "UTF-8"); + writer.println(content.toString()); + writer.close(); + } catch (FileNotFoundException | UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + } + }; + }*/ + + private SelectionListener createWeightDomainSelectionAdapter() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String selectedDomainId = weightsDomainCombo.getText(); + + FuzzySet selectedDomain = model.getWeightsDomain(selectedDomainId); + if(selectedDomain != null) + model.setWeightsDomain(selectedDomain); + else + model.createWeightsLabels(); + + refresh(); + } + }; + } + + private void createChart() { + chartView = new Composite(parent, SWT.NONE); + GridData gd = UiService.setGridData(chartView, 9, 9, true, true); + gd.heightHint = 200; + setChart(); + } + + private void setChart() { + removeChart(); + + chart = new LinguisticDomainChart(); + chart.initialize(model.getCurrentWeightsDomain(), chartView, chartView.getSize().x, chartView.getSize().y, SWT.BORDER); + + if (controlListener == null) { + controlListener = new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + setChart(); + } + }; + chartView.addControlListener(controlListener); + } + + } + + private void removeChart() { + if (chart != null) { + chart.getChartComposite().dispose(); + chartView.layout(); + } + } +} diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/handler/PasteWeightsHandler.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/handler/PasteWeightsHandler.java new file mode 100644 index 0000000..800e1b7 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/handler/PasteWeightsHandler.java @@ -0,0 +1,109 @@ + +package flintstones.method.decision.common.phase.selection.ui.handler; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.nebula.widgets.opal.notifier.NotifierColorsFactory.NotifierTheme; +import org.eclipse.nebula.widgets.opal.notifier.WNotifier; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.widgets.Display; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.MatrixHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.method.decision.common.phase.selection.ui.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; + +public class PasteWeightsHandler { + + Map criteriaWeightsByExperts = new HashMap(); + + @Inject + IProblemElementService problemService; + + @Inject + IEventBroker broker; + + @Inject + @Translation + Messages messages; + + @Execute + public Map execute(FuzzySet domain) { + + Clipboard clipboard = new Clipboard(Display.getCurrent()); + String plainText = (String) clipboard.getContents(TextTransfer.getInstance()); + + HashMatrix data = MatrixHelper.toHashMatrix(plainText, true); + + ProblemElement[] hHeaders = problemService.getSubElements(Expert.Type); + ProblemElement[] vHeaders = problemService.getSubElements(Criterion.Type); + + String crit, exp; + LabelLinguisticDomain weight; + LabelLinguisticDomain[] weights; + + boolean error = false; + + for (ProblemElement item1 : hHeaders) { + + exp = item1.getName(); + + weights = new LabelLinguisticDomain[vHeaders.length]; + + for (ProblemElement item2 : vHeaders) { + + crit = item2.getName(); + + try { + int pos = Integer.parseInt(data.get(exp, crit)); + weight = domain.getLabelSet().getLabel(pos); + } catch(NumberFormatException ex) { + weight = domain.getLabelSet().getLabel(data.get(exp, crit)); + } + + if(weight == null) { + new WNotifier("Error", messages.Incorrect_domain) //$NON-NLS-1$ + .withCloseOnClick(true) + .withTimeout(5) + .send(); + + error = true; + } else + weights[Arrays.asList(vHeaders).indexOf(item2)] = weight; + + + if(error) + break; + } + + criteriaWeightsByExperts.put((Expert) item1, weights); + + if(error) + break; + + } + + if(!error) { + new WNotifier(messages.Successfully_imported, messages.Weights_successfully_added, + NotifierTheme.BLUE_THEME) + .send(); + + return criteriaWeightsByExperts; + + } else + return null; + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/Messages.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/Messages.java new file mode 100644 index 0000000..9e75796 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/Messages.java @@ -0,0 +1,39 @@ +// This file has been auto-generated +package flintstones.method.decision.common.phase.selection.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String selection_Calculate_solutions; + public String calculate_solutions_Alternative; + public String calculate_solutions_Collective_valuation; + public String calculate_solutions_Collective_valuations; + public String calculate_solutions_Criterion; + public String calculate_solutions_Expert; + public String calculate_solutions_Ideal_solution; + public String calculate_solutions_No_ideal_solution; + public String calculate_solutions_Type; + public String calculate_solutions_Valuation; + public String CalculateDistances_Alternative; + public String CalculateDistances_Calculate_distances; + public String CalculateDistances_Closeness_coefficient; + public String CalculateDistances_Criterion; + public String CalculateDistances_Ideal_solution; + public String CalculateDistances_Ideal_solution_distance; + public String CalculateDistances_Negative_distance; + public String CalculateDistances_Positive_distance; + public String CalculateDistances_Ranking; + public String selection_Calculate_weights; + public String calculate_weights_Weight; + public String Domain_entity; + public String Collective; + public String Export_weights; + public String Import_weights; + public String Fix_error; + public String Weights_successfully_added; + public String Successfully_imported; + public String Incorrect_domain; +} diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/messages.properties b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/messages.properties new file mode 100644 index 0000000..f863142 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/messages.properties @@ -0,0 +1,28 @@ +selection_Calculate_solutions=Calculate solutions +calculate_solutions_Alternative=Alternative +calculate_solutions_Collective_valuation=Collective valuation +calculate_solutions_Collective_valuations=Collective valuations +calculate_solutions_Criterion=Criterion +calculate_solutions_Expert=Expert +calculate_solutions_Ideal_solution=Ideal solution +calculate_solutions_No_ideal_solution=No ideal solution +calculate_solutions_Type=Type +calculate_solutions_Valuation=Valuation +CalculateDistances_Alternative=Alternative +CalculateDistances_Calculate_distances=Calculate distances +CalculateDistances_Closeness_coefficient=Closeness coefficient +CalculateDistances_Criterion=Criterion +CalculateDistances_Ideal_solution=Ideal and no ideal distances +CalculateDistances_Ideal_solution_distance=Closeness coefficients +CalculateDistances_Negative_distance=No ideal distance +CalculateDistances_Positive_distance=Ideal distance +CalculateDistances_Ranking=Ranking +Collective=Collective* +selection_Calculate_weights=Select weights +calculate_weights_Weight=Weight +Export_weights = Export weights +Import_weights = Import weights +Fix_error=\n Fix the error and remove the data to try again +Weights_successfully_added=Weights successfully added +Successfully_imported=Successfully imported +Incorrect_domain=Incorrect domain \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/messages_es.properties b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/messages_es.properties new file mode 100644 index 0000000..a3c6866 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/messages/messages_es.properties @@ -0,0 +1,28 @@ +selection_Calculate_solutions=Calcular soluciones +calculate_solutions_Alternative=Alternative +calculate_solutions_Collective_valuation=Valoración collectiva +calculate_solutions_Collective_valuations=Valoraciones colectivas +calculate_solutions_Criterion=Criterio +calculate_solutions_Expert=Experto +calculate_solutions_Ideal_solution=Solución ideal +calculate_solutions_No_ideal_solution=Solución anti ideal +calculate_solutions_Type=Tipo +calculate_solutions_Valuation=Valoración +CalculateDistances_Alternative=Alternativa +CalculateDistances_Calculate_distances=Calcular distancias +CalculateDistances_Closeness_coefficient=Coeficiente de cercania +CalculateDistances_Criterion=Criterio +CalculateDistances_Ideal_solution=Distancia ideal y anti ideal +CalculateDistances_Ideal_solution_distance=Coeficiente de cercanía +CalculateDistances_Negative_distance=Distancia anti ideal +CalculateDistances_Positive_distance=Distancia ideal +CalculateDistances_Ranking=Ranking +Collective = Colectiva* +selection_Calculate_weights= Seleccionar pesos +calculate_weights_Wight = Importancia +Export_weights = Exportar pesos +Import_weights = Importar pesos +Fix_error=\n Corrige el error y elimina los datos para volver a intenarlo +Weights_successfully_added=Se han aadido los pesos correctamente +Successfully_imported=Importado con xito +Incorrect_domain=Dominio incorrecto \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/ClosenessCoefficientsTableViewerContentProvider.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/ClosenessCoefficientsTableViewerContentProvider.java new file mode 100644 index 0000000..98c74be --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/ClosenessCoefficientsTableViewerContentProvider.java @@ -0,0 +1,64 @@ +package flintstones.method.decision.common.phase.selection.ui.provider; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.valuation.Valuation; +import flintstones.model.problemelement.service.IProblemElementService; + +//CK +@SuppressWarnings("javadoc") +public class ClosenessCoefficientsTableViewerContentProvider implements IStructuredContentProvider { + + @Inject + IProblemElementService problemService; + + private List _closenessCoefficients; + + public ClosenessCoefficientsTableViewerContentProvider() { + _closenessCoefficients = new LinkedList(); + } + + public void setInput(Map closenessCoefficients) { + _closenessCoefficients.clear(); + Object[] data; + + int ranking = 1; + for(Alternative a: closenessCoefficients.keySet()) { + data = new Object[3]; + data[0] = a; + data[1] = closenessCoefficients.get(a); + data[2] = ranking; + + ranking++; + + _closenessCoefficients.add(data); + } + } + + public List getInput() { + return _closenessCoefficients; + } + + @Override + public void dispose() { + _closenessCoefficients.clear(); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + @SuppressWarnings("unchecked") + @Override + public Object[] getElements(Object inputElement) { + return ((List) inputElement).toArray(); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/DecisionMatrixContentProvider.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/DecisionMatrixContentProvider.java new file mode 100644 index 0000000..42521d9 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/DecisionMatrixContentProvider.java @@ -0,0 +1,188 @@ +package flintstones.method.decision.common.phase.selection.ui.provider; + +import javax.inject.Inject; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.valuation.Valuation; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +//CK +@SuppressWarnings("javadoc") +public class DecisionMatrixContentProvider extends KTableNoScrollModel { + + @Inject + IProblemElementService problemService; + + private KTable _table; + + private Valuation[][] decisionMatrix; + + private final FixedCellRenderer _fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer _fixedRendererInTable = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + private final FixedCellRenderer _editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public DecisionMatrixContentProvider(KTable table) { + super(table); + _table = table; + } + + public void initDecisionMatrixContentProvider(Valuation[][] decisionMatrix) { + this.decisionMatrix = decisionMatrix; + initialize(); + setDesign(); + } + + private void setDesign() { + _fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + _fixedRendererInTable.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); + + _editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + _editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int arg0, int arg1) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) { + return _fixedRenderer; + } else { + return _editableRenderer; + } + } + + @Override + public int doGetColumnCount() { + return problemService.getAll(Alternative.Type).length + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + if ((col == 0) && (row == 0)) { + return "Decision matrix"; //$NON-NLS-1$ + } + + Object content; + + try { + if (col == 0) { + content = criterionAbbreviation(row); + } else if (row == 0) { + content = alternativeAbbreviation(col); + } else { + content = ((TwoTupleValuation) decisionMatrix[row - 1][ col - 1]).prettyFormat(); + } + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + return problemService.getSubElements(Criterion.Type)[pos-1].getName(); + } + + private Object alternativeAbbreviation(int pos) { + return problemService.getAll(Alternative.Type)[pos-1].getName(); + } + + @Override + public int doGetRowCount() { + return problemService.getSubElements(Criterion.Type).length + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + _table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 30; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) { + return true; + } else if (row == 0) { + return true; + } + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) { + return ""; //$NON-NLS-1$ + } else if (col < getFixedColumnCount()) { + return problemService.getSubElements(Criterion.Type)[row-1].getName(); + } else if (row < getFixedRowCount()) { + return problemService.getAll(Alternative.Type)[col-1].getName(); + } else { + return ((Criterion) problemService.getSubElements(Criterion.Type)[row-1]).getName() + '/' + problemService.getAll(Alternative.Type)[col-1].getName(); + } + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/ExpertsWeightContentProvider.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/ExpertsWeightContentProvider.java new file mode 100644 index 0000000..d614d70 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/ExpertsWeightContentProvider.java @@ -0,0 +1,224 @@ +package flintstones.method.decision.common.phase.selection.ui.provider; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.editors.KTableCellEditorCombo; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.method.decision.common.phase.selection.CalculateWeightsSelectionModel; +import flintstones.model.problemelement.service.IProblemElementService; + +//CK +public class ExpertsWeightContentProvider extends KTableNoScrollModel { + + @Inject + IProblemElementService problemService; + + @Inject + IEclipseContext context; + + private KTable _table; + + private CalculateWeightsSelectionModel model; + + private final FixedCellRenderer _fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer _fixedRendererInTable = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + private final FixedCellRenderer _editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + private class MyOwnKTableCellEditorCombo extends KTableCellEditorCombo { + @Override + public int getActivationSignals() { + return SINGLECLICK; + } + } + + private MyOwnKTableCellEditorCombo kTableCombo = new MyOwnKTableCellEditorCombo(); + + public ExpertsWeightContentProvider(KTable table) { + super(table); + + } + + public void init(KTable table, CalculateWeightsSelectionModel selectionPhase) { + + _table = table; + model = selectionPhase; + + initialize(); + setDesign(); + } + + private void setDesign() { + _fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + _fixedRendererInTable.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); + + _editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + _editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + if (col != 0 && row != 0) { + kTableCombo = new MyOwnKTableCellEditorCombo(); + FuzzySet weightsDomain = model.getCurrentWeightsDomain(); + + String[] valuesString = new String[weightsDomain.getLabelSet().getCardinality()]; + for(int i = 0; i < valuesString.length; ++i) + valuesString[i] = weightsDomain.getLabelSet().getLabel(i).getName(); + + kTableCombo.setItems(valuesString); + + return kTableCombo; + } + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) { + return _fixedRenderer; + } else { + return _editableRenderer; + } + } + + @Override + public int doGetColumnCount() { + return problemService.getSubElements(Criterion.Type).length + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + if ((col == 0) && (row == 0)) { + return ""; //$NON-NLS-1$ + } + + Object content; + + try { + if (col == 0) { + content = expertAbbreviation(row); + } else if (row == 0) { + content = criterionAbbreviation(col); + } else { + content = model.getExpertWeight((Expert) problemService.getSubElements(Expert.Type)[row-1], col - 1); + } + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + return ProblemElementHelper.getAsUserOrdered(problemService.getSubElements(Criterion.Type))[pos - 1].getName(); + } + + private Object expertAbbreviation(int pos) { + return ProblemElementHelper.getAsUserOrdered(problemService.getSubElements(Expert.Type))[pos - 1].getName(); + } + + @Override + public int doGetRowCount() { + return problemService.getSubElements(Expert.Type).length + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + LabelLinguisticDomain oldWeight = model.getExpertWeight((Expert) problemService.getSubElements(Expert.Type)[row - 1], col - 1); + LabelLinguisticDomain newWeight = model.getCurrentWeightsDomain().getLabelSet().getLabel((String) value); + + if(!oldWeight.equals(newWeight)) { + model.setExpertWeight((Expert) problemService.getSubElements(Expert.Type)[row - 1], col - 1, newWeight); + _table.redraw(); + model.execute(); + } + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 30; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) { + return true; + } else if (row == 0) { + return true; + } + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) { + return ""; //$NON-NLS-1$ + } else if (col < getFixedColumnCount()) { + return problemService.getSubElements(Expert.Type)[row - 1].getName(); + } else if (row < getFixedRowCount()) { + return problemService.getSubElements(Criterion.Type)[col - 1].getName(); + } else { + return problemService.getSubElements(Expert.Type)[row - 1].getName() + '/' + problemService.getSubElements(Criterion.Type)[col - 1].getName(); + } + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/IdealSolutionTableViewerContentProvider.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/IdealSolutionTableViewerContentProvider.java new file mode 100644 index 0000000..41c6830 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/IdealSolutionTableViewerContentProvider.java @@ -0,0 +1,56 @@ +package flintstones.method.decision.common.phase.selection.ui.provider; + +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.valuation.Valuation; +import flintstones.model.problemelement.service.IProblemElementService; + +//CK +public class IdealSolutionTableViewerContentProvider implements IStructuredContentProvider { + + @Inject + IProblemElementService problemService; + + private List idealSolutionData; + + @Override + public void dispose() {} + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + public IdealSolutionTableViewerContentProvider() { + idealSolutionData = new LinkedList(); + } + + public void setInput(List noIdealSolution) { + + idealSolutionData.clear(); + + Object[] data; + for(int i = 0; i < noIdealSolution.size(); ++i) { + data = new Object[2]; + data[0] = problemService.getSubElements(Criterion.Type)[i]; + data[1] = noIdealSolution.get(i); + + idealSolutionData.add(data); + } + } + + public List getInput() { + return idealSolutionData; + } + + @SuppressWarnings("unchecked") + @Override + public Object[] getElements(Object inputElement) { + return ((List) inputElement).toArray(new Object[0]); + } +} diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/NoIdealSolutionTableViewerContentProvider.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/NoIdealSolutionTableViewerContentProvider.java new file mode 100644 index 0000000..f11dae7 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/NoIdealSolutionTableViewerContentProvider.java @@ -0,0 +1,58 @@ +package flintstones.method.decision.common.phase.selection.ui.provider; + +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.valuation.Valuation; +import flintstones.model.problemelement.service.IProblemElementService; + +//CK +public class NoIdealSolutionTableViewerContentProvider implements IStructuredContentProvider { + + @Inject + IProblemElementService problemService; + + private List noIdealSolutionData; + + @Override + public void dispose() {} + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + public NoIdealSolutionTableViewerContentProvider() { + noIdealSolutionData = new LinkedList(); + } + + public void setInput(List noIdealSolution) { + + noIdealSolutionData.clear(); + + Object[] data; + for(int i = 0; i < noIdealSolution.size(); ++i) { + data = new Object[2]; + data[0] = problemService.getSubElements(Criterion.Type)[i]; + data[1] = noIdealSolution.get(i); + + noIdealSolutionData.add(data); + } + } + + public List getInput() { + return noIdealSolutionData; + } + + @SuppressWarnings("unchecked") + @Override + public Object[] getElements(Object inputElement) { + return ((List) inputElement).toArray(new Object[0]); + } + + +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/PositiveNegativeTableViewerContentProvider.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/PositiveNegativeTableViewerContentProvider.java new file mode 100644 index 0000000..3dd2845 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/provider/PositiveNegativeTableViewerContentProvider.java @@ -0,0 +1,42 @@ +package flintstones.method.decision.common.phase.selection.ui.provider; + + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +//CK +@SuppressWarnings("javadoc") +public class PositiveNegativeTableViewerContentProvider implements IStructuredContentProvider { + + private List _positiveNegativeDistances; + + public PositiveNegativeTableViewerContentProvider() { + _positiveNegativeDistances = new LinkedList<>(); + } + + public List getInput() { + return _positiveNegativeDistances; + } + + public void setInput(List positiveNegativeDistances) { + _positiveNegativeDistances = positiveNegativeDistances; + } + + @Override + public void dispose() { + _positiveNegativeDistances.clear(); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + @SuppressWarnings("unchecked") + @Override + public Object[] getElements(Object inputElement) { + return ((List) inputElement).toArray(); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/table/DecisionMatrixTable.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/table/DecisionMatrixTable.java new file mode 100644 index 0000000..8da0e96 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/table/DecisionMatrixTable.java @@ -0,0 +1,42 @@ +package flintstones.method.decision.common.phase.selection.ui.table; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.entity.valuation.Valuation; +import flintstones.method.decision.common.phase.selection.ui.provider.DecisionMatrixContentProvider; + +public class DecisionMatrixTable extends KTable { + + @Inject + IEclipseContext context; + + private DecisionMatrixContentProvider _model; + + public DecisionMatrixTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + _model = null; + } + + public void setModel(Valuation[][] decisionMatrix) { + _model = new DecisionMatrixContentProvider(this); + ContextInjectionFactory.inject(_model, context); + _model.initDecisionMatrixContentProvider(decisionMatrix); + setModel(_model); + getParent().getParent() + .layout(); + } + + @Override + public void dispose() { + super.dispose(); + } +} diff --git a/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/table/ExpertsWeightTable.java b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/table/ExpertsWeightTable.java new file mode 100644 index 0000000..607f9f8 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection.ui/src/flintstones/method/decision/common/phase/selection/ui/table/ExpertsWeightTable.java @@ -0,0 +1,41 @@ +package flintstones.method.decision.common.phase.selection.ui.table; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.decision.common.phase.selection.CalculateWeightsSelectionModel; +import flintstones.method.decision.common.phase.selection.ui.provider.ExpertsWeightContentProvider; + +public class ExpertsWeightTable extends KTable { + + @Inject + IEclipseContext context; + + private ExpertsWeightContentProvider _model; + + public ExpertsWeightTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + _model = null; + } + + public void setModel(CalculateWeightsSelectionModel selectionPhase) { + _model = new ExpertsWeightContentProvider(this); + ContextInjectionFactory.inject(_model, context); + _model.init(this, selectionPhase); + + setModel(_model); + } + + @Override + public void dispose() { + super.dispose(); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.common.phase.selection/.classpath b/bundles/flintstones.method.decision.common.phase.selection/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.selection/.polyglot.META-INF b/bundles/flintstones.method.decision.common.phase.selection/.polyglot.META-INF new file mode 100644 index 0000000..3c393a1 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.common.phase.selection + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Selection + diff --git a/bundles/flintstones.method.decision.common.phase.selection/.project b/bundles/flintstones.method.decision.common.phase.selection/.project new file mode 100644 index 0000000..6f2814b --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.common.phase.selection + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362660 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.common.phase.selection/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.common.phase.selection/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b56f245 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Selection +Bundle-SymbolicName: flintstones.method.decision.common.phase.selection;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.common.phase.selection +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.twoTuple, + flintstones.domain.fuzzyset, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.operator, + javax.inject, + flintstones.operator.aggregation.min, + flintstones.operator.aggregation.max, + flintstones.model.problemelement.service, + flintstones.model.domain.service, + flintstones.entity.domain, + flintstones.entity.method.phase, + flintstones.method.common.model.retranslation, + flintstones.entity.operator +Export-Package: flintstones.method.decision.common.phase.selection, + flintstones.method.decision.common.phase.selection.interfaces diff --git a/bundles/flintstones.method.decision.common.phase.selection/build.properties b/bundles/flintstones.method.decision.common.phase.selection/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.common.phase.selection/plugin.xml b/bundles/flintstones.method.decision.common.phase.selection/plugin.xml new file mode 100644 index 0000000..e75eb3d --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateDistancesSelectionModel.java b/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateDistancesSelectionModel.java new file mode 100644 index 0000000..fa87fca --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateDistancesSelectionModel.java @@ -0,0 +1,239 @@ +package flintstones.method.decision.common.phase.selection; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +//import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.valuation.Valuation; +import flintstones.method.common.model.retranslation.RetranslationModel; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +@SuppressWarnings({ "unchecked", "javadoc" }) +public class CalculateDistancesSelectionModel extends PhaseMethod { + + @Inject + IDomainService domainService; + + @Inject + IProblemElementService problemService; + + private RetranslationModel retranslationModel; + + private FuzzySet _distanceDomain; + private FuzzySet _similarityDomain; + + private List _idealDistance = new ArrayList<>(); + private List _noIdealDistance = new ArrayList<>(); + private Map _closenessCoefficient; + + // Cache + private Valuation[][] _decisionMatrix; + private TwoTupleValuation[] _criteriaWeights; + + @Override + public String getName() { + return "Calculate Distances"; + } + + @Inject + IEclipseContext context; + + public Valuation[][] getDecisionMatrix() { + return (Valuation[][]) importData("decisionMatrix"); + } + + public FuzzySet getUnifiedDomain() { + return (FuzzySet) importData("unifiedDomain"); + } + + public TwoTupleValuation[] getCriteriaWeights() { + return this._criteriaWeights; + } + + public Map getClosenessCoeficient() { + return this._closenessCoefficient; + } + + public FuzzySet getDistanceDomain() { + return _distanceDomain; + } + + public void setDistanceDomain(FuzzySet distanceDomain) { + _distanceDomain = distanceDomain; + } + + public List getIdealDistances() { + return this._idealDistance; + } + + public List getNoIdealDistances() { + return this._noIdealDistance; + } + + public FuzzySet getDefaultDistanceDomain() { + createDistanceLabels(); + return _distanceDomain; + } + + public FuzzySet getDistanceDomain(String id) { + return (FuzzySet) domainService.getByName(id); + } + + public void retranslateResults() { + if(retranslationModel == null) + retranslationModel = ContextInjectionFactory.make(RetranslationModel.class, context); + + Map retranslatedClosenessCoefficient = + retranslationModel.retranslate(_closenessCoefficient, _distanceDomain); + orderCoefficients(retranslatedClosenessCoefficient); + } + + public void execute() { + // Cache + _decisionMatrix = (Valuation[][]) importData("decisionMatrix"); + _criteriaWeights = (TwoTupleValuation[]) importData("criteriaWeights"); + + createDistanceLabels(); + createSimilarityLabels(); + step7CalculateIdealEuclideanDistance(); + step7CalculateNoIdealEuclideanDistance(); + calculateClosenessCoefficient(); + } + + + private void createDistanceLabels() { + _distanceDomain = (FuzzySet) domainService.create(FuzzySet.ID); + _distanceDomain.setName("default"); + String[] labels = new String[]{"Equal", "Almost equal", "A bit close", "Neither close nor far", "A bit far", "Far", "Far away"}; + _distanceDomain.createTrapezoidalFunction(labels); + } + + private void createSimilarityLabels() { + _similarityDomain = ContextInjectionFactory.make(FuzzySet.class, context); + String[] labels = new String[]{"Total dissimilar", "Almost total dissimilar", "A bit dissimilar", + "Neither dissimilar nor dissimilar", "A bit similar", "Almost similar", "Completely similar"}; + _similarityDomain.createTrapezoidalFunction(labels); + } + + private void step7CalculateIdealEuclideanDistance() { + _idealDistance.clear(); + + TwoTupleValuation collective, idealSolution, distance = null; + + double acum = 0; + for(int i = 0; i < _decisionMatrix[0].length; ++i) { + acum = 0; + for(int j = 0; j < _decisionMatrix.length; ++j) { + collective = (TwoTupleValuation) _decisionMatrix[j][i]; + idealSolution = getIdealSolution().get(j); + distance = calculateDistanceBetweenTwoTuple(idealSolution, collective); + acum += distance.calculateInverseDelta(); + } + + acum /= _decisionMatrix.length; + + distance.calculateDelta(acum); + _idealDistance.add(distance); + } + } + + private TwoTupleValuation calculateDistanceBetweenTwoTuple(TwoTupleValuation t1, TwoTupleValuation t2) { + int t = getUnifiedDomain().getLabelSet().getCardinality() - 1; + int t_prima = _similarityDomain.getLabelSet().getCardinality() - 1; + int t_prima_prima = _distanceDomain.getLabelSet().getCardinality() - 1; + + double factor = (t_prima + 1) - (t_prima - ((Math.abs(t1.calculateInverseDelta() - t2.calculateInverseDelta()) * (t_prima_prima - 1)) / t)); + + TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context); + result.build(_distanceDomain); + result.calculateDelta(factor); + return result; + } + + private void step7CalculateNoIdealEuclideanDistance() { + _noIdealDistance.clear(); + + TwoTupleValuation collective, noIdealSolution; + TwoTupleValuation distance = null; + + double acum = 0; + for(int i = 0; i < _decisionMatrix[0].length; ++i) { + acum = 0; + for(int j = 0; j < _decisionMatrix.length; ++j) { + collective = (TwoTupleValuation) _decisionMatrix[j][i]; + noIdealSolution = getNoIdealSolution().get(j); + distance = calculateDistanceBetweenTwoTuple(noIdealSolution, collective); + acum += distance.calculateInverseDelta(); + } + + acum /= _decisionMatrix.length; + + distance.calculateDelta(acum); + _noIdealDistance.add(distance); + } + } + + private void calculateClosenessCoefficient() { + Map disorderedCoefficients = new HashMap<>(); + + int t_prima_prima = _distanceDomain.getLabelSet().getCardinality() - 1; + + TwoTupleValuation idealDistance, noIdealDistance, coefficient; + double closeness; + for(int i = 0; i < _decisionMatrix[0].length; ++i) { + idealDistance = _idealDistance.get(i); + noIdealDistance = _noIdealDistance.get(i); + closeness = ((noIdealDistance.calculateInverseDelta()) / ((idealDistance.calculateInverseDelta()) + (noIdealDistance.calculateInverseDelta()))) * t_prima_prima; + coefficient = ContextInjectionFactory.make(TwoTupleValuation.class, context); + coefficient.build(_distanceDomain); + coefficient.calculateDelta(closeness); + disorderedCoefficients.put((Alternative) problemService.getAll(Alternative.Type)[i], coefficient); + } + orderCoefficients(disorderedCoefficients); + } + + private void orderCoefficients(Map disorderedCoefficients) { + _closenessCoefficient = disorderedCoefficients + .entrySet() + .stream() + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) + .collect( + java.util.stream.Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, + LinkedHashMap::new)); + } + + private List getIdealSolution() { + return (List) importData("idealSolution"); + } + + private List getNoIdealSolution() { + return (List) importData("noIdealSolution"); + } + + public String[] getDistanceDomainsIds() { + Domain[] domains = domainService.getAll(); + + String[] domainsIds = new String[domains.length]; + for(int i = 0; i < domainsIds.length; ++i) + if(domains[i] instanceof FuzzySet) + domainsIds[i] = domains[i].getName(); + + return domainsIds; + } + +} diff --git a/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateSolutionsSelectionModel.java b/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateSolutionsSelectionModel.java new file mode 100644 index 0000000..c9ee090 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateSolutionsSelectionModel.java @@ -0,0 +1,154 @@ +package flintstones.method.decision.common.phase.selection; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.operator.aggregation.max.Max; +import flintstones.operator.aggregation.min.Min; +import flintstones.operator.service.IOperatorService; + +@SuppressWarnings("javadoc") +public class CalculateSolutionsSelectionModel extends PhaseMethod { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + @Inject + IOperatorService operatorService; + + private Valuation[][] decisionMatrix; + + List noIdealSolution = new LinkedList(); + List idealSolution = new LinkedList(); + + @Override + public String getName() { + return "Calculate Solutions"; + } + + @SuppressWarnings("unchecked") + public Valuation[][] getExpertDecisionMatrix(String expert) { + Map decisionMatrices = (Map) importData("decisionMatricesExperts"); + Valuation[][] decisionMatrix = decisionMatrices.get(problemService.getByName(Expert.Type, expert)); + exportData("decisionMatrix", decisionMatrix); + return decisionMatrix; + } + + public Valuation[][] getCollectiveDecisionMatrix() { + Valuation[][] decisionMatrix = (Valuation[][]) importData("decisionMatrix"); + exportData("decisionMatrix", decisionMatrix); + return decisionMatrix; + } + + public List getIdealSolution() { + return this.idealSolution; + } + + public List getNoIdealSolution() { + return this.noIdealSolution; + } + + private void exportData() { + exportData("idealSolution", this.idealSolution); + exportData("noIdealSolution", this.noIdealSolution); + exportData("unifiedDomain", importData("unifiedDomain")); + exportData("criteriaWeights", importData("criteriaWeights")); + } + + public void execute(Valuation[][] decisionMatrix) { + // Cache + this.decisionMatrix = decisionMatrix; + + step6CalculateIdealSolution(); + step6CalculateNoIdealSolution(); + + exportData(); + } + + private void step6CalculateIdealSolution() { + + idealSolution.clear(); + + Valuation idealSolutionValuation = null; + Criterion cri; + + for (int i = 0; i < decisionMatrix.length; ++i) { + List valuationsByCriterion = new ArrayList<>(); + + cri = (Criterion) problemService.getSubElements(Criterion.Type)[i]; + for (int j = 0; j < decisionMatrix[i].length; ++j) { + valuationsByCriterion.add(decisionMatrix[i][j]); + } + + if (cri.isCost()) { + AggregationOperator min = operatorService.getAggregationOperator(Min.class.getPackage().getName().toString(), valuationsByCriterion.get(0).getId()); + idealSolutionValuation = min.computeAggregation(valuationsByCriterion, null); + } else { + AggregationOperator max = operatorService.getAggregationOperator(Max.class.getPackage().getName().toString(), valuationsByCriterion.get(0).getId()); + idealSolutionValuation = max.computeAggregation(valuationsByCriterion, null); + } + + idealSolution.add(idealSolutionValuation); + } + } + + private void step6CalculateNoIdealSolution() { + + noIdealSolution.clear(); + + Valuation noIdealSolutionValuation = null; + Criterion cri; + + for (int i = 0; i < decisionMatrix.length; ++i) { + List valuationsByCriterion = new ArrayList<>(); + + cri = (Criterion) problemService.getSubElements(Criterion.Type)[i]; + for (int j = 0; j < decisionMatrix[i].length; ++j) { + valuationsByCriterion.add(decisionMatrix[i][j]); + } + + if (cri.isCost()) { + AggregationOperator max = operatorService.getAggregationOperator(Max.class.getPackage().getName().toString(), valuationsByCriterion.get(0).getId()); + noIdealSolutionValuation = max.computeAggregation(valuationsByCriterion, null); + } else { + AggregationOperator min = operatorService.getAggregationOperator(Min.class.getPackage().getName().toString(), valuationsByCriterion.get(0).getId()); + noIdealSolutionValuation = min.computeAggregation(valuationsByCriterion, null); + } + + + noIdealSolution.add(noIdealSolutionValuation); + } + } + + public String[] getExpertsName() { + ProblemElement[] experts = problemService.getSubElements(Expert.Type); + + String[] expertsName = new String[experts.length]; + for(int i = 0; i < experts.length; ++i) + expertsName[i] = experts[i].getName(); + + return expertsName; + } + + public boolean isExpert(String expert) { + if(problemService.getByName(Expert.Type, expert) != null) + return true; + return false; + } +} diff --git a/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateWeightsSelectionModel.java b/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateWeightsSelectionModel.java new file mode 100644 index 0000000..64e28c3 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/CalculateWeightsSelectionModel.java @@ -0,0 +1,259 @@ +package flintstones.method.decision.common.phase.selection; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.method.decision.common.phase.selection.interfaces.ICalculateWeightsSelectionModel; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +@SuppressWarnings("unchecked") +public class CalculateWeightsSelectionModel extends PhaseMethod implements ICalculateWeightsSelectionModel { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + private Map criteriaWeightsByExperts = new HashMap<>(); + private TwoTupleValuation[] criteriaWeights; + + private Map decisionMatricesExperts; + private Valuation[][] unweightedDecisionMatrix; + private Valuation[][] decisionMatrix; + + private FuzzySet unificationDomain; + private FuzzySet weightsDomain; + + @Override + public String getName() { + return "Calculate Weights"; + } + + @Override + public void exportData() { + exportData("decisionMatricesExperts", decisionMatricesExperts); + exportData("decisionMatrix", decisionMatrix); + exportData("criteriaWeights", this.criteriaWeights); + exportData("unifiedDomain", importData("unifiedDomain")); + } + + public Domain getUnifiedDomain() { + return (Domain) importData("unifiedDomain"); + } + + public void setUnifiedDomain(Domain domain) { + unificationDomain = (FuzzySet) domain; + } + + @Override + public FuzzySet getCurrentWeightsDomain() { + return weightsDomain; + } + + public void setWeightsDomain(FuzzySet weightsDomain) { + this.weightsDomain = weightsDomain; + initializeWeightsExperts(); + } + + public LabelLinguisticDomain getExpertWeight(Expert e, int crit) { + return criteriaWeightsByExperts.get(e)[crit]; + } + + public void setExpertWeight(Expert e, int crit, LabelLinguisticDomain weight) { + LabelLinguisticDomain[] weights = criteriaWeightsByExperts.get(e); + weights[crit] = weight; + criteriaWeightsByExperts.put(e, weights); + } + + public void setExperstWeights(Map criteriaWeightsByExpert) { + criteriaWeightsByExperts = criteriaWeightsByExpert; + } + + public String[] getWeightsDomainsIds() { + Domain[] domains = domainService.getAll(); + + List domainsIds = new LinkedList<>(); + for(Domain d: domains) + if(d instanceof FuzzySet) + domainsIds.add(d.getName()); + + return domainsIds.toArray(new String[0]); + } + + @Override + public void execute() { + calculateDecisionMatrix(); + exportData(); + } + + @Override + public void createWeightsLabels() { + weightsDomain = (FuzzySet) domainService.create(FuzzySet.ID); + weightsDomain.setName("default"); + String[] labels = new String[] { "Very low", "Low", "Medium low", "Medium", + "Medium high", "High", "Very high" }; + weightsDomain.createTrapezoidalFunction(labels); + initializeWeightsExperts(); + } + + private void calculateDecisionMatrix() { + + unificationDomain = (FuzzySet) getUnifiedDomain(); + + computeWeights(); + step3TransformExpertsMatricesInto2Tuple(); + step4ComputeUnweightedOverallDecisionMatrix(); + step5ComputeWeigthedOverallDecisionMatrix(); + } + + private void computeWeights() { + Map weightsTwoTuple = step1TransformWeightsIntoTwoTuple(); + step2ComputeCollectiveWeights(weightsTwoTuple); + } + + private Map step1TransformWeightsIntoTwoTuple() { + + Map result = new HashMap<>(); + for (Expert e : criteriaWeightsByExperts.keySet()) { + LabelLinguisticDomain[] weights = criteriaWeightsByExperts.get(e); + TwoTupleValuation[] weights2T = new TwoTupleValuation[weights.length]; + for (int i = 0; i < weights.length; ++i) { + weights2T[i] = ContextInjectionFactory.make(TwoTupleValuation.class, context); + weights2T[i].build(weightsDomain, weights[i]); + } + result.put(e, weights2T); + } + return result; + } + + private void initializeWeightsExperts() { + for (ProblemElement e : problemService.getSubElements(Expert.Type)) { + LabelLinguisticDomain[] weights = new LabelLinguisticDomain[problemService.getSubElements(Criterion.Type).length]; + for (int i = 0; i < weights.length; ++i) { + weights[i] = weightsDomain.getLabelSet() + .getLabel((weightsDomain.getLabelSet().getCardinality() - 1) / 2); + } + criteriaWeightsByExperts.put((Expert) e, weights); + } + } + + private void step2ComputeCollectiveWeights(Map weightsTwoTuple) { + + criteriaWeights = new TwoTupleValuation[problemService.getSubElements(Criterion.Type).length]; + + double acum; + for (int i = 0; i < problemService.getSubElements(Criterion.Type).length; ++i) { + acum = 0; + for (Expert e : weightsTwoTuple.keySet()) + acum += weightsTwoTuple.get(e)[i].calculateInverseDelta(); + + TwoTupleValuation weight = ContextInjectionFactory.make(TwoTupleValuation.class, context); + weight.build(weightsDomain); + weight.calculateDelta(acum / weightsTwoTuple.size()); + criteriaWeights[i] = weight; + } + } + + private void step3TransformExpertsMatricesInto2Tuple() { + decisionMatricesExperts = new HashMap(); + + ProblemElement[] experts = problemService.getSubElements(Expert.Type); + ProblemElement[] criteria = problemService.getSubElements(Criterion.Type); + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + + for (ProblemElement e : experts) { + Valuation[][] dm = new Valuation[criteria.length][alternatives.length]; + for (ProblemElement c : criteria) { + for (ProblemElement a : alternatives) { + TwoTupleValuation twoTuple = getTwoTupleValuations().get(new ProblemElementKey((Expert) e, (Alternative) a, (Criterion) c)); + dm[Arrays.asList(criteria).indexOf(c)][Arrays.asList(alternatives).indexOf(a)] = twoTuple; + } + } + decisionMatricesExperts.put((Expert) e, dm); + } + } + + private void step4ComputeUnweightedOverallDecisionMatrix() { + unweightedDecisionMatrix = new Valuation[problemService.getSubElements(Criterion.Type).length][problemService.getAll(Alternative.Type).length]; + + double acum = 0; + for (int i = 0; i < problemService.getSubElements(Criterion.Type).length; ++i) { + for (int j = 0; j < problemService.getAll(Alternative.Type).length; ++j) { + for (Expert e : decisionMatricesExperts.keySet()) { + Valuation[][] dm = decisionMatricesExperts.get(e); + acum += ((TwoTupleValuation) dm[i][j]).calculateInverseDelta(); + } + TwoTupleValuation collective = ContextInjectionFactory.make(TwoTupleValuation.class, context); + collective.build(unificationDomain); + collective.calculateDelta(acum / decisionMatricesExperts.size()); + unweightedDecisionMatrix[i][j] = collective; + acum = 0; + } + } + } + + private void step5ComputeWeigthedOverallDecisionMatrix() { + decisionMatrix = new Valuation[problemService.getSubElements(Criterion.Type).length][problemService.getAll(Alternative.Type).length]; + + TwoTupleValuation maxWeight = getMaxWeight(); + + for (int i = 0; i < unweightedDecisionMatrix.length; ++i) { + TwoTupleValuation weight = criteriaWeights[i]; + for (int j = 0; j < unweightedDecisionMatrix[i].length; ++j) { + TwoTupleValuation v = (TwoTupleValuation) unweightedDecisionMatrix[i][j]; + TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context); + result.build(unificationDomain); + result.calculateDelta(v.calculateInverseDelta() * (weight.calculateInverseDelta() / maxWeight.calculateInverseDelta())); + decisionMatrix[i][j] = result; + + } + } + } + + private TwoTupleValuation getMaxWeight() { + List auxWeights = new LinkedList(Arrays.asList(criteriaWeights)); + Collections.sort(auxWeights); + return auxWeights.get(auxWeights.size() - 1); + } + + private Map getTwoTupleValuations() { + Map twoTuple = (Map) importData( + "twoTupleUnifiedValuations"); + exportData("twoTupleValuations", twoTuple); + return twoTuple; + } + + public FuzzySet getWeightsDomain(String selectedDomainId) { + return (FuzzySet) domainService.getByName(selectedDomainId); + } + + public FuzzySet getDefaultWeightsDomain() { + this.createWeightsLabels(); + return this.weightsDomain; + } +} diff --git a/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/interfaces/ICalculateWeightsSelectionModel.java b/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/interfaces/ICalculateWeightsSelectionModel.java new file mode 100644 index 0000000..6292986 --- /dev/null +++ b/bundles/flintstones.method.decision.common.phase.selection/src/flintstones/method/decision/common/phase/selection/interfaces/ICalculateWeightsSelectionModel.java @@ -0,0 +1,15 @@ +package flintstones.method.decision.common.phase.selection.interfaces; + +import flintstones.domain.fuzzyset.FuzzySet; + +public interface ICalculateWeightsSelectionModel { + + void createWeightsLabels(); + + FuzzySet getCurrentWeightsDomain(); + + void exportData(); + + void execute(); + +} diff --git a/bundles/flintstones.method.decision.topsis.numeric/.classpath b/bundles/flintstones.method.decision.topsis.numeric/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.topsis.numeric/.polyglot.META-INF b/bundles/flintstones.method.decision.topsis.numeric/.polyglot.META-INF new file mode 100644 index 0000000..4854850 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.topsis.numeric + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Numeric + diff --git a/bundles/flintstones.method.decision.topsis.numeric/.project b/bundles/flintstones.method.decision.topsis.numeric/.project new file mode 100644 index 0000000..eb7a3de --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.topsis.numeric + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362662 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.topsis.numeric/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.topsis.numeric/META-INF/MANIFEST.MF new file mode 100644 index 0000000..de008f0 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Numeric +Bundle-SymbolicName: flintstones.method.decision.topsis.numeric;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.topsis.numeric +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric, + flintstones.helper.faq diff --git a/bundles/flintstones.method.decision.topsis.numeric/build.properties b/bundles/flintstones.method.decision.topsis.numeric/build.properties new file mode 100644 index 0000000..e9d79c5 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + faq/ diff --git a/bundles/flintstones.method.decision.topsis.numeric/faq/faq.en.md b/bundles/flintstones.method.decision.topsis.numeric/faq/faq.en.md new file mode 100644 index 0000000..6a4f3c7 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/faq/faq.en.md @@ -0,0 +1 @@ +The Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) is a multi-criteria decision analysis method, which was originally developed by Ching-Lai Hwang and Yoon in 1981 with further developments by Yoon in 1987 and Hwang, Lai and Liu in 1993. TOPSIS is based on the concept that the chosen alternative should have the shortest geometric distance from the positive ideal solution and the longest geometric distance from the negative ideal solution. \ No newline at end of file diff --git a/bundles/flintstones.method.decision.topsis.numeric/faq/faq.es.md b/bundles/flintstones.method.decision.topsis.numeric/faq/faq.es.md new file mode 100644 index 0000000..83f0be2 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/faq/faq.es.md @@ -0,0 +1 @@ +La Técnica de Orden de Preferencia por Similitud a la Solución Ideal (TOPSIS) es un método de análisis de decisiones multicriterio, que fue desarrollado originalmente por Ching-Lai Hwang y Yoon en 1981, con desarrollos posteriores por Yoon en 1987 y Hwang, Lai y Liu en 1993. El método TOPSIS se basa en el concepto de que la alternativa elegida debe tener la menor distancia geométrica respecto a la solución ideal positiva y la mayor distancia geométrica respecto a la solución ideal negativa. diff --git a/bundles/flintstones.method.decision.topsis.numeric/plugin.xml b/bundles/flintstones.method.decision.topsis.numeric/plugin.xml new file mode 100644 index 0000000..cc93705 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/plugin.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/NumericTopsisMethod.java b/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/NumericTopsisMethod.java new file mode 100644 index 0000000..744e242 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/NumericTopsisMethod.java @@ -0,0 +1,47 @@ +package flintstones.method.decision.topsis.numeric; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.decision.topsis.numeric.messages.Messages; +import flintstones.valuation.numeric.NumericValuation; + +public class NumericTopsisMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, NumericValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/Messages.java b/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/Messages.java new file mode 100644 index 0000000..5889dda --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/Messages.java @@ -0,0 +1,11 @@ +package flintstones.method.decision.topsis.numeric.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + +} \ No newline at end of file diff --git a/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/messages.properties b/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/messages.properties new file mode 100644 index 0000000..72ee4d9 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/messages.properties @@ -0,0 +1 @@ +Method_name=Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) diff --git a/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/messages_es.properties b/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/messages_es.properties new file mode 100644 index 0000000..c9f1cc4 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis.numeric/src/flintstones/method/decision/topsis/numeric/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_name=Tcnica para el orden de preferencia mediante cercania a la solucin ideal (informacin numrica) +method.name \ No newline at end of file diff --git a/bundles/flintstones.method.decision.topsis/.classpath b/bundles/flintstones.method.decision.topsis/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.decision.topsis/.polyglot.META-INF b/bundles/flintstones.method.decision.topsis/.polyglot.META-INF new file mode 100644 index 0000000..a5f4801 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.decision.topsis + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Topsis + diff --git a/bundles/flintstones.method.decision.topsis/.project b/bundles/flintstones.method.decision.topsis/.project new file mode 100644 index 0000000..0a9a33d --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/.project @@ -0,0 +1,45 @@ + + + flintstones.method.decision.topsis + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362661 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.decision.topsis/META-INF/MANIFEST.MF b/bundles/flintstones.method.decision.topsis/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0d7ff45 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Topsis +Bundle-SymbolicName: flintstones.method.decision.topsis;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.decision.topsis +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.linguistic, + flintstones.valuation.twoTuple diff --git a/bundles/flintstones.method.decision.topsis/build.properties b/bundles/flintstones.method.decision.topsis/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.decision.topsis/plugin.xml b/bundles/flintstones.method.decision.topsis/plugin.xml new file mode 100644 index 0000000..4941e52 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/plugin.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/Topsis.java b/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/Topsis.java new file mode 100644 index 0000000..7f3d5d4 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/Topsis.java @@ -0,0 +1,64 @@ +package flintstones.method.decision.topsis; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.decision.topsis.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class Topsis extends ValidatedMethod { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + int numDomains = domainService.getAll().length; + String numDomainEntity = messages.Number_of_domains; + String domainsEntity = domainMessages.Domain_entities; + String valuationsEntity = valuationMessages.Valuation_entity; + + ValidBLTSDomainOperation validBLTSDomainOperation = new ValidBLTSDomainOperation(domainsEntity, + domainService.getAll()); + + Valuation[] valuations = valuationService.getAll(); + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, LinguisticValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .greaterOrEqualsThan(numDomainEntity, numDomains, 1) + .named("numDomains") //$NON-NLS-1$ + .custom(validBLTSDomainOperation) + .named( "domains" )//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations"); //$NON-NLS-1$ + } + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + +} diff --git a/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/Messages.java b/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/Messages.java new file mode 100644 index 0000000..44b9f02 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/Messages.java @@ -0,0 +1,14 @@ +package flintstones.method.decision.topsis.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Number_of_domains; + public String Type_of_domain; + +} + diff --git a/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/messages.properties b/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/messages.properties new file mode 100644 index 0000000..4c93ac8 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/messages.properties @@ -0,0 +1,3 @@ +Method_name=Linguistic Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) +Number_of_domains=The number of domains +Type_of_domain=The type of domain \ No newline at end of file diff --git a/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/messages_es.properties b/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/messages_es.properties new file mode 100644 index 0000000..e08ca37 --- /dev/null +++ b/bundles/flintstones.method.decision.topsis/src/flintstones/method/decision/topsis/messages/messages_es.properties @@ -0,0 +1,3 @@ +Method_name=Tcnica para el orden de preferencia mediante cercania a la solucin ideal (informacin lingstica) +Number_of_domains=El nmero de dominios +Type_of_domain=El tipo del dominio diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.classpath b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.polyglot.META-INF b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.polyglot.META-INF new file mode 100644 index 0000000..a0373c2 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.electre.phase.destillation.gathering.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.project b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.project new file mode 100644 index 0000000..f2f6cd0 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.electre.phase.destillation.gathering.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362663 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f1bf461 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.electre.phase.destillation.gathering.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.electre.phase.destillation.gathering.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.contexts, + flintstones.entity.problemelement, + flintstones.helper.html, + flintstones.method.electre.phase.destillation.gathering, + flintstones.entity.method.phase.ui, + javax.inject, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.helper.data, + flintstones.entity.method.phase diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/build.properties b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/plugin.xml b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/plugin.xml new file mode 100644 index 0000000..8d9cdd3 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering.ui/src/flintstones/method/electre/phase/destillation/gathering/ui/DestillationUI.java b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/src/flintstones/method/electre/phase/destillation/gathering/ui/DestillationUI.java new file mode 100644 index 0000000..b509ecb --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering.ui/src/flintstones/method/electre/phase/destillation/gathering/ui/DestillationUI.java @@ -0,0 +1,309 @@ +package flintstones.method.electre.phase.destillation.gathering.ui; + +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.helper.DoubleHelper; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.electre.phase.destillation.gathering.DestillationModel; +import flintstones.model.ui.service.UiService; + +public class DestillationUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + DestillationModel destillationModel; + + Alternative[] alts; + double[][] fuzzyRelation; // Alternativas frente alternativas + + HtmlTextTable tableAsc; + HtmlTextTable tableFinalRanking; + HtmlTextTable tableDesc; + + Button checkButtonDefault; + Spinner spinnerAlfa; + Spinner spinnerBeta; + + Composite rowTables; + + //Listener for the UI components. + ModifyListener modifyComponent = new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + Spinner alf = (Spinner) e.getSource(); + Spinner bet = (Spinner) e.getSource(); + + String alfaText = alf.getText(); + String betaText = bet.getText(); + if(alfaText != null || betaText != null) + if(!alfaText.equals("") || !betaText.equals("")) + refreshTable(); + } + }; + + @Override + public void init() { + + destillationModel = (DestillationModel) this.getModel(); + destillationModel.importarDatos(); + + //Inicializar datos + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 0, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText("Fase datos umbrales Electre 3"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + //buttons destillation + createButtonDestillation(base); + + //Mostrar matriz final + alts = destillationModel.getAlternativas(); + + double alfa = DoubleHelper.ParseDouble(spinnerAlfa.getText()); + double beta = DoubleHelper.ParseDouble(spinnerBeta.getText()); + destillationModel.executeDestillation(alfa, beta); + + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9, 9, true, false); + UiService.setGridLayout(row2, 3, true); + + initTitleTables(row2); + + rowTables = new Composite(base, 0); + UiService.setGridData(rowTables, 9, 9, true, true); + UiService.setGridLayout(rowTables, 3, true); + + initBody(rowTables); + } + + private void initTitleTables(Composite base) { + Label titleAsc = new Label(base, SWT.NONE); + titleAsc.setText("Ranking Ascendente"); + UiService.setGridData(titleAsc, 0 ,9, true, false); + UiService.setFont(titleAsc, UiService.FONT_SECTION_TITLE); + + Label titleDes = new Label(base, SWT.NONE); + titleDes.setText("Ranking Descendente"); + UiService.setGridData(titleDes, 0 ,9, true, false); + UiService.setFont(titleDes, UiService.FONT_SECTION_TITLE); + + Label titleFinal = new Label(base, SWT.NONE); + titleFinal.setText("Ranking Final"); + UiService.setGridData(titleFinal, 0 ,9, true, false); + UiService.setFont(titleFinal, UiService.FONT_SECTION_TITLE); + } + + private void initBody(Composite base) { + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 9, true, true); + UiService.setGridLayout(row1, 1); + + createColDes(row1, destillationModel.getRankingDes(), destillationModel.getAlternativasNames()); + + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9, 9, true, true); + UiService.setGridLayout(row2, 1); + + createColAsc(row2, destillationModel.getRankingAsc(), destillationModel.getAlternativasNames()); + + Composite row3 = new Composite(base, 0); + UiService.setGridData(row3, 9, 9, true, true); + UiService.setGridLayout(row3, 1); + + createColFinal(row3, destillationModel.getFinalRanking(), destillationModel.getAlternativasNames()); + } + + private void createButtonDestillation(Composite base) { + Composite row = new Composite(base, 0); + UiService.setGridData(row, 0, 9, true, false); + UiService.setGridLayout(row, 1); + + //Check button Veto + Composite rowLabelCheckVeto = new Composite(row, 0); + UiService.setGridData(rowLabelCheckVeto, 0, 9, true, false); + UiService.setGridLayout(rowLabelCheckVeto, 1); + checkButtonDefault = new Button(rowLabelCheckVeto, SWT.CHECK); + checkButtonDefault.setText("Usar valores por defecto"); + checkButtonDefault.setSelection(true); + checkButtonDefault.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + Button btn = (Button) e.getSource(); + + spinnerAlfa.setEnabled(!btn.getSelection()); + spinnerBeta.setEnabled(!btn.getSelection()); + + if(btn.getSelection()) { + spinnerAlfa.setSelection(-15); + spinnerBeta.setSelection(30); + } + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + }); + + Composite row2 = new Composite(row, 0); + UiService.setGridData(row2, 0, 9, true, false); + UiService.setGridLayout(row2, 2, true); + + //Indiferencia (Q) + Composite rowLabelAlfa = new Composite(row2, 0); + UiService.setGridData(rowLabelAlfa, 9, 9, true, false); + UiService.setGridLayout(rowLabelAlfa, 2); + Label labelAlfa = new Label (rowLabelAlfa, SWT.NONE); + labelAlfa.setText("Alfa:"); + spinnerAlfa = new Spinner (rowLabelAlfa, SWT.BORDER); + spinnerAlfa.setDigits(2); + spinnerAlfa.setMinimum(Integer.MIN_VALUE); + spinnerAlfa.setMaximum(Integer.MAX_VALUE); + spinnerAlfa.setEnabled(false); + spinnerAlfa.setSelection(-15); + spinnerAlfa.addModifyListener(modifyComponent); + + //Preferencia (P) + Composite rowLabelBeta = new Composite(row2, 0); + UiService.setGridData(rowLabelBeta, 9, 9, true, false); + UiService.setGridLayout(rowLabelBeta, 2); + Label labelBeta = new Label (rowLabelBeta, SWT.NONE); + labelBeta.setText("Beta:"); + spinnerBeta = new Spinner (rowLabelBeta, SWT.BORDER); + spinnerBeta.setDigits(2); + spinnerBeta.setMinimum(Integer.MIN_VALUE); + spinnerBeta.setMaximum(Integer.MAX_VALUE); + spinnerBeta.setEnabled(false); + spinnerBeta.setSelection(30); + spinnerBeta.addModifyListener(modifyComponent); + } + + private void createColAsc(Composite base, int[] ranking, String[] alternativas) { + String[] rankingNames = new String [alternativas.length]; + String[] rankingNumber = new String [alternativas.length]; + int indiceRanking = 0; + int indiceArray = 0; + + while(indiceArray < alternativas.length) { + for(int j = 0; j < ranking.length; j++) { + if(ranking[j] == indiceRanking) { + rankingNames[indiceArray] = alternativas[j]; + rankingNumber[indiceArray] = Integer.toString(indiceRanking); + indiceArray++; + } + } + + indiceRanking++; + } + + tableAsc = new HtmlTextTable(base, rankingNames, rankingNumber, true); + tableAsc.render(); + } + + private void createColFinal(Composite base, int[] ranking, String[] alternativas) { + String[] rankingNames = new String [alternativas.length]; + String[] rankingNumber = new String [alternativas.length]; + int indiceRanking = 0; + int indiceArray = 0; + + while(indiceArray < alternativas.length) { + for(int j = 0; j < ranking.length; j++) { + if(ranking[j] == indiceRanking) { + rankingNames[indiceArray] = alternativas[j]; + rankingNumber[indiceArray] = Integer.toString(indiceRanking); + indiceArray++; + } + } + + indiceRanking++; + } + + tableFinalRanking = new HtmlTextTable(base, rankingNames, rankingNumber,true); + tableFinalRanking.render(); + } + + private void createColDes(Composite base, int[] ranking, String[] alternativas) { + String[] rankingNames = new String [alternativas.length]; + String[] rankingNumber = new String [alternativas.length]; + int indiceRanking = 0; + int indiceArray = 0; + + while(indiceArray < alternativas.length) { + for(int j = 0; j < ranking.length; j++) { + if(ranking[j] == indiceRanking) { + rankingNames[indiceArray] = alternativas[j]; + rankingNumber[indiceArray] = Integer.toString(indiceRanking); + indiceArray++; + } + } + + indiceRanking++; + } + + tableDesc = new HtmlTextTable(base, rankingNames, rankingNumber, true); + tableDesc.render(); + } + + private void refreshTable() { + if(rowTables == null) return; + + Arrays.stream(rowTables.getChildren()).forEach(k -> k.dispose()); + + destillationModel.importarDatos(); + + double alfa = DoubleHelper.ParseDouble(spinnerAlfa.getText()); + double beta = DoubleHelper.ParseDouble(spinnerBeta.getText()); + destillationModel.executeDestillation(alfa, beta); + + initBody(rowTables); + + tableAsc.render(); + tableFinalRanking.render(); + tableDesc.render(); + + rowTables.layout(); + } + + @Override + public void refresh() { + refreshTable(); + this.sendRefresh(); + } + + @Override + public boolean isSkippable() { + return false; + } + + @Override + public boolean isForwardEnabled() { + return false; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/.classpath b/bundles/flintstones.method.electre.phase.destillation.gathering/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/.polyglot.META-INF b/bundles/flintstones.method.electre.phase.destillation.gathering/.polyglot.META-INF new file mode 100644 index 0000000..44820e5 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.electre.phase.destillation.gathering + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Gathering + diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/.project b/bundles/flintstones.method.electre.phase.destillation.gathering/.project new file mode 100644 index 0000000..5becca1 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/.project @@ -0,0 +1,45 @@ + + + flintstones.method.electre.phase.destillation.gathering + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362663 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/META-INF/MANIFEST.MF b/bundles/flintstones.method.electre.phase.destillation.gathering/META-INF/MANIFEST.MF new file mode 100644 index 0000000..718a643 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Gathering +Bundle-SymbolicName: flintstones.method.electre.phase.destillation.gathering;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.electre.phase.destillation.gathering +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.method.electre.phase.destillation.gathering +Require-Bundle: org.eclipse.e4.core.contexts, + flintstones.entity.problemelement, + javax.inject, + flintstones.entity.method.phase diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/build.properties b/bundles/flintstones.method.electre.phase.destillation.gathering/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/plugin.xml b/bundles/flintstones.method.electre.phase.destillation.gathering/plugin.xml new file mode 100644 index 0000000..3c91928 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/src/flintstones/method/electre/phase/destillation/gathering/DestilationAlgorithm.java b/bundles/flintstones.method.electre.phase.destillation.gathering/src/flintstones/method/electre/phase/destillation/gathering/DestilationAlgorithm.java new file mode 100644 index 0000000..52a3c01 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/src/flintstones/method/electre/phase/destillation/gathering/DestilationAlgorithm.java @@ -0,0 +1,616 @@ +package flintstones.method.electre.phase.destillation.gathering; + +public class DestilationAlgorithm { + + double cut_k; + double alfa; + double beta; + + int[] A; //Set Ak={a1, a2, ..., am} Elements remain the credebility matrix. + int[] D; + int[] power; + int[] weakness; + int[] qualification; + + int[] posDis_asc; + int[] posDis_des; + int[] posTem; + int[] dif_des_asc; + int[] sum_medianPreorder; + int[] sum_incomparability; + int[] sum_equivalent; + int[] medianPreorder; + + //Variables importantes. + int elements_in_D; + int cardA; + + int nalternatives; + double [][]sigma_matrix; + int[][] crisp_OR; //crisp outranking relation aSb + + int []rankingAsc; + int []rankingDesc; + + public DestilationAlgorithm(double[][] sigma_matrix, int numAleternativas, double alfa, double beta){ + //Problem + this.sigma_matrix = sigma_matrix; + this.nalternatives = numAleternativas; + + this.alfa = alfa; + this.beta = beta; + } + + void inicializar() { + //initialize variables + this.A = new int[nalternatives]; + this.D = new int[nalternatives]; + crisp_OR = new int[nalternatives][nalternatives]; + + this.power = new int[nalternatives]; + this.weakness= new int[nalternatives]; + this.qualification= new int[nalternatives]; + + // Initially every element belongs to credibility matrix + for (int i=0; i < nalternatives; i++) + A[i] = 1; + } + + //Descending Distillation + //------------------------------------ + public void distillation_Des(double alpha, double betha) { + + double s_cut_k; + int i, posDistillation, count; + int count_outrankings; + + inicializar(); + + cardA = nalternatives; + + posDistillation = 1; + + while (cardA > 1) { + + D_equal_to_A(); + + cut_k = find_highest(); // lambda_0 + + s_cut_k = alpha * cut_k + betha; // lambda_1 + + // Se busca la relación mayor debajo de un valor de corte //lambda_1 + // Este corresponde al siguiente nivel de corte + // Max(aSb) < ( cut_k - s_cut_k ) + cut_k = find_distillation_threshold(cut_k - s_cut_k); // lambda_2 + + // Construye la matriz crisp con el nivel de corte cut_k + // aSB > cut_k && ( aSB < bSa + (alpha * aSb + betha) ) + count_outrankings = crisp_outranking_relation(alpha, betha); + if (count_outrankings > 0) { + calculate_qualification(); + obtain_maximum_qualification(); + } + + if (elements_in_D == 1 || cut_k == 0) { + + // take of elements from A which are in D + // A = A \ D + A_minus_C(); + + count = 0; + for (i = 0; i < nalternatives; i++) { + + if (D[i] == 1) { + posDis_des[i] = posDistillation; + count++; + } + } + + posDistillation += count; + + } else { + + while (elements_in_D > 1 && cut_k != 0) { + s_cut_k = alpha * cut_k + betha; + cut_k = find_distillation_threshold(cut_k - s_cut_k); + + count_outrankings = crisp_outranking_relation(alpha, betha); + + if (count_outrankings > 0) { + calculate_qualification(); + obtain_maximum_qualification(); + } + + if (elements_in_D == 1 || cut_k == 0) { + // take of elements from A which are in D + // A = A \ D + A_minus_C(); + + count = 0; + + for (i = 0; i < nalternatives; i++) { + + if (D[i] == 1) { + posDis_des[i] = posDistillation; + count++; + } + } + posDistillation += count; + } + } + } + + } // end while + + + if (cardA == 1) { + for (i = 0; i < nalternatives; i++) + if (A[i] == 1) + posDis_des[i] = posDistillation; + } + + } + + //Ascending Distillation + //------------------------------------ + public void distillation_Asc(double alpha, double betha) { + + double s_cut_k; + int posOrd, posAsc, count; + int count_outrankings; + + inicializar(); + + cardA = nalternatives; + + posOrd = 1; + + while (cardA > 1) { + + // Distilation 1 + // k=0 + D_equal_to_A(); + + cut_k = find_highest(); + + s_cut_k = alpha * cut_k + betha; + + cut_k = find_distillation_threshold(cut_k - s_cut_k); + + count_outrankings = crisp_outranking_relation(alpha, betha); + if (count_outrankings > 0) { + calculate_qualification(); + obtain_minimum_qualification(); + } + + if (elements_in_D == 1 || cut_k == 0) { + // take of elements from A which are in D + // A = A \ D + A_minus_C(); + + for (int i = 0; i < nalternatives; i++) + if (D[i] == 1) + posTem[i] = posOrd; + + posOrd++; + + } else { + + while (elements_in_D > 1 && cut_k != 0) { + s_cut_k = alpha * cut_k + betha; + cut_k = find_distillation_threshold(cut_k - s_cut_k); + + count_outrankings = crisp_outranking_relation(alpha, betha); + + if (count_outrankings > 0) { + calculate_qualification(); + obtain_minimum_qualification(); + } + + if (elements_in_D == 1 || cut_k == 0) { + // take of elements from A which are in D + // A = A \ D + A_minus_C(); + + for (int i = 0; i < nalternatives; i++) + if (D[i] == 1) + posTem[i] = posOrd; + + posOrd++; + } + } + } + + } // end while + + if (cardA == 1) { + // find the remaining alternative + for (int i = 0; i < nalternatives; i++) + if (A[i] == 1) + // assign remaining alternative the position of the pre-order + posTem[i] = posOrd; + + posOrd++; + + } + + // convert the temporal position to the final position in ascending pre-order + // as the ascending pre-order is in opposite side (down-up) + // we change the side to up-down, then best alternatives will be in top position + // on asc preorder + posAsc = 1; + for (; posOrd > 0; posOrd--) { + count = 0; + + for (int i = 0; i < nalternatives; i++) { + if (posTem[i] == posOrd) { + posDis_asc[i] = posAsc; + count++; + } + } + + posAsc += count; + } + + } + + //Intersect des and asc pre-orders (distillation results) + //count the strict preferences between alternatives from both pre-orders + public int[] median_preOrder(){ + int[] tot_preOrder = new int[nalternatives]; + int bucket=0; + int mayor, posMayor, vTemp, pTemp; + + //arrays for positions of alternatives for asc and des pre-orders + posDis_asc = new int[nalternatives]; + posDis_des = new int[nalternatives]; + posTem = new int[nalternatives]; + dif_des_asc = new int[nalternatives]; + + //array for counting the strict preferences between alternatives from both pre-orders + sum_medianPreorder = new int[nalternatives]; + sum_incomparability = new int[nalternatives]; + sum_equivalent = new int[nalternatives]; + medianPreorder = new int[nalternatives]; + + for (int j=0; j posDis_asc[j] ) { + dif_des_asc[j] = posDis_des[j] - posDis_asc[j]; + } else { + dif_des_asc[j] = posDis_asc[j] - posDis_des[j]; + } + } + + //instersection between pre-orders + for (int i=0; i posDis_asc[j]) || + (posDis_des[i] > posDis_des[j] && posDis_asc[i] < posDis_asc[j]) ){ + sum_incomparability[i]++; + } + + //find equivalent + if( posDis_des[i] == posDis_des[j] && posDis_asc[i] == posDis_asc[j] ){ + sum_equivalent[i]++; + } + + } + + } + + } + + //ordering alternatives + for (int i=0; i mayor){ + mayor= sum_medianPreorder[j]; + posMayor=j; + } + } + + vTemp=sum_medianPreorder[i]; + + sum_medianPreorder[i]= mayor; + sum_medianPreorder[posMayor]= vTemp; + + + pTemp=medianPreorder[i]; + medianPreorder[i] = medianPreorder[posMayor]; + medianPreorder[posMayor]= pTemp; + + } + + //distinguishing according to their rank difference + for (int j=0; j dif_des_asc[ medianPreorder[j+1] ] ){ + pTemp=medianPreorder[j]; + medianPreorder[j] = medianPreorder[j+1]; + medianPreorder[j+1] = pTemp; + } + } + } + } + + bucket = 0; + for (int j=0; j posDis_asc[j] ) + dif_des_asc[j] = posDis_des[j] - posDis_asc[j]; + else + dif_des_asc[j] = posDis_asc[j] - posDis_des[j]; + } + + + //instersection between pre-orders + for (int i=0; i 0 + P- -> 1 + R -> 2 + I -> 3 + */ + + //find the strict preferences + //a is better rank in one order and a is at least as good as b + if( (posDis_des[i] < posDis_des[j] && posDis_asc[i] <= posDis_asc[j]) || + (posDis_des[i] <= posDis_des[j] && posDis_asc[i] < posDis_asc[j]) ){ + + //printf("P\t"); + pp_matrix[i][j] = 0; + } + + //a is worse ranked in one order and a is at least as good as b + if( (posDis_des[i] > posDis_des[j] && posDis_asc[i] >= posDis_asc[j]) || + (posDis_des[i] >= posDis_des[j] && posDis_asc[i] > posDis_asc[j]) ){ + //printf("P-\t"); + pp_matrix[i][j] = 1; + } + + //find equivalent + if( posDis_des[i] == posDis_des[j] && posDis_asc[i] == posDis_asc[j] ) + pp_matrix[i][j] = 2; + + //find incomparability + if( (posDis_des[i] < posDis_des[j] && posDis_asc[i] > posDis_asc[j]) || + (posDis_des[i] > posDis_des[j] && posDis_asc[i] < posDis_asc[j]) ){ + pp_matrix[i][j] = 3; + } + + } else { + pp_matrix[i][j] = 2; + } + } + } + + } + + + public int[] getRankingAsc() { + return this.rankingAsc; + } + + public int[] getRankingDes() { + return this.rankingDesc; + } + + //----------------------------------------------------------------------------- + //Funciones privadas + //----------------------------------------------------------------------------- + + private double find_highest() { + double highest = 0; + + for (int i = 0; i < nalternatives; i++) { + + for (int j = 0; j < nalternatives; j++) { + + if (j != i) + if (sigma_matrix[i][j] > highest) + highest = sigma_matrix[i][j]; + } + } + + return highest; + + } + + private double find_distillation_threshold(double cut_level) { + // find the richest credibility degree lower than cut_level + double highest = 0; + + for (int i = 0; i < nalternatives; i++) { + + for (int j = 0; j < nalternatives; j++) { + + if (j != i) + if (sigma_matrix[i][j] < cut_level && sigma_matrix[i][j] > highest) + highest = sigma_matrix[i][j]; + } + + } + + return highest; + } + + private void D_equal_to_A() { + elements_in_D = 0; + + for (int i = 0; i < nalternatives; i++) { + D[i] = A[i]; + elements_in_D++; + } + + } + + private void A_minus_C() { + for (int i = 0; i < nalternatives; i++) { + // take of element from A which are in D + // A = A \ D + if (D[i] == 1) { + A[i] = 0; + cardA--; + } + } + } + + private void calculate_qualification() { + for (int i = 0; i < nalternatives; i++) { + power[i] = 0; + weakness[i] = 0; + qualification[i] = 0; + } + + for (int i = 0; i < nalternatives; i++) { + + for (int j = 0; j < nalternatives; j++) { + + if (j != i) { + if (crisp_OR[i][j] == 1) { + power[i]++; + weakness[j]++; + } + } + } + } + + for (int i = 0; i < nalternatives; i++) + qualification[i] = power[i] - weakness[i]; + + } + + private int crisp_outranking_relation(double alpha, double betha) { + int No_COR = 0; + + // initialize the matrix + for (int i = 0; i < nalternatives; i++) + for (int j = 0; j < nalternatives; j++) + crisp_OR[i][j] = 0; + + // find crisp relation + for (int i = 0; i < nalternatives; i++) { + for (int j = 0; j < nalternatives; j++) { + if (j != i) { + if (sigma_matrix[i][j] > cut_k) { + if (sigma_matrix[i][j] > sigma_matrix[j][i] + (alpha * sigma_matrix[i][j] + betha)) { + crisp_OR[i][j] = 1; + No_COR++; + } + } + } + } + + } + + return No_COR; + } + + void obtain_maximum_qualification() { + int maximum = qualification[0]; + + for (int i = 1; i < nalternatives; i++) + if (D[i] == 1) + if (qualification[i] > maximum) + maximum = qualification[i]; + + // initialize D to be obtained again + for (int i = 0; i < nalternatives; i++) + D[i] = 0; + + elements_in_D = 0; + // find the bests qualifications, Next D + for (int i = 0; i < nalternatives; i++) { + if (qualification[i] == maximum) { + D[i] = 1; + elements_in_D++; + } + } + } + + void obtain_minimum_qualification() { + int minimum = qualification[0]; + + for (int i = 1; i < nalternatives; i++) + if (D[i] == 1) + if (qualification[i] < minimum) + minimum = qualification[i]; + + // initialize D to be obtained again + for (int i = 0; i < nalternatives; i++) + D[i] = 0; + + elements_in_D = 0; + // find the bests qualifications, Next D + for (int i = 0; i < nalternatives; i++) { + if (qualification[i] == minimum) { + D[i] = 1; + elements_in_D++; + } + } + + } + +} diff --git a/bundles/flintstones.method.electre.phase.destillation.gathering/src/flintstones/method/electre/phase/destillation/gathering/DestillationModel.java b/bundles/flintstones.method.electre.phase.destillation.gathering/src/flintstones/method/electre/phase/destillation/gathering/DestillationModel.java new file mode 100644 index 0000000..b047176 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.destillation.gathering/src/flintstones/method/electre/phase/destillation/gathering/DestillationModel.java @@ -0,0 +1,68 @@ +package flintstones.method.electre.phase.destillation.gathering; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; + +public class DestillationModel extends PhaseMethod { + + @Inject + IEclipseContext context; + + int []rankingAsc; + int []rankingDesc; + int []rankingFinalRanking; + + Alternative[] allAlternativas; + double[][] fuzzyRelation; // Alternativas frente alternativas + + public DestillationModel() { + } + + @Override + public String getName() { + return "Electre 3: Destillation Result"; + } + + public void importarDatos() { + allAlternativas = (Alternative[]) this.importData("alternativas"); + fuzzyRelation = (double[][]) this.importData("fuzzyRelation"); + } + + public void executeDestillation(double alfa, double beta) { + DestilationAlgorithm dA = new DestilationAlgorithm(fuzzyRelation, allAlternativas.length, alfa, beta); + + rankingFinalRanking = dA.median_preOrder(); + rankingAsc = dA.getRankingAsc(); + rankingDesc = dA.getRankingDes(); + } + + public int[] getRankingAsc() { + return this.rankingAsc; + } + + public int[] getRankingDes() { + return this.rankingDesc; + } + + public int[] getFinalRanking() { + return this.rankingFinalRanking; + } + + public Alternative[] getAlternativas() { + return allAlternativas; + } + + public String[] getAlternativasNames() { + String[] str = new String[allAlternativas.length]; + + for(int i = 0; i < allAlternativas.length; i++) + str[i] = allAlternativas[i].getCanonicalName(); + + + return str; + } + +} diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/.classpath b/bundles/flintstones.method.electre.phase.gathering.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/.polyglot.META-INF b/bundles/flintstones.method.electre.phase.gathering.ui/.polyglot.META-INF new file mode 100644 index 0000000..bc79c61 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.electre.phase.gathering.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/.project b/bundles/flintstones.method.electre.phase.gathering.ui/.project new file mode 100644 index 0000000..14c2bbb --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.electre.phase.gathering.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362664 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.electre.phase.gathering.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..21cc62d --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.electre.phase.gathering.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.electre.phase.gathering.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Export-Package: flintstones.method.electre.phase.gathering.viewer +Require-Bundle: flintstones.model.ui.service, + org.eclipse.e4.core.contexts, + javax.inject, + flintstones.helper.data, + flintstones.model.problemelement.service, + flintstones.helper.html, + org.eclipse.swt, + org.eclipse.jface, + flintstones.entity.problemelement, + org.eclipse.e4.core.di, + flintstones.application.perspective.framework.ui, + flintstones.entity.method.phase.ui, + flintstones.entity.method.phase, + flintstones.method.electre.phase.gathering, + flintstones.model.method.phase.service, + flintstones.method.common.phase.aggregation diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/build.properties b/bundles/flintstones.method.electre.phase.gathering.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/plugin.xml b/bundles/flintstones.method.electre.phase.gathering.ui/plugin.xml new file mode 100644 index 0000000..6a3b59f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/provider/ProblemElementLabelProvider.java b/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/provider/ProblemElementLabelProvider.java new file mode 100644 index 0000000..6280b3d --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/provider/ProblemElementLabelProvider.java @@ -0,0 +1,76 @@ +package flintstones.method.electre.phase.gathering.provider; + +import javax.inject.Inject; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.ui.service.UiService; +import flintstones.model.ui.service.style.ForegroundStyler; + +public class ProblemElementLabelProvider extends LabelProvider implements IStyledLabelProvider { + + @Inject + IPhaseMethodService phaseService; + + /** The group image. */ + private final ImageDescriptor groupImage; + + /** The individual image. */ + private final ImageDescriptor individualImage; + + /** + * Instantiates a new problem element name label provider. + * + * @param individualImage the individual image + * @param groupImage the group image + */ + public ProblemElementLabelProvider(ImageDescriptor individualImage, ImageDescriptor groupImage) { + this.groupImage = groupImage; + this.individualImage = individualImage; + } + + @Override + public StyledString getStyledText(Object element) { + if (element instanceof ProblemElement) { + ProblemElement pe = (ProblemElement) element; + StyledString styledString; + styledString = paint(pe.getName(), ""); + + return styledString; + } + return null; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + if (element instanceof ProblemElement) { + if (((ProblemElement) element).hasChildren()) + return this.groupImage.createImage(); + + return this.individualImage.createImage(); + } + + return super.getImage(element); + } + + private StyledString paint(String leftText, String rightText) { + + Color foregroundColorLeft = UiService.COLOR_FG_NORMAL; + Color foregroundColorRight = UiService.COLOR_FG_SECONDARY; + + StyledString leftT = new StyledString(leftText, new ForegroundStyler(foregroundColorLeft)); + StyledString rightT = new StyledString(rightText, new ForegroundStyler(foregroundColorRight)); + return leftT.append(" ") + .append(rightT); + } +} diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/ui/ElectreUmbralComponentUI.java b/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/ui/ElectreUmbralComponentUI.java new file mode 100644 index 0000000..a3107d4 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/ui/ElectreUmbralComponentUI.java @@ -0,0 +1,205 @@ +package flintstones.method.electre.phase.gathering.ui; + + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; + +import flintstones.helper.DoubleHelper; +import flintstones.method.electre.phase.gathering.ParametersElectre; +import flintstones.model.ui.service.UiService; + +public class ElectreUmbralComponentUI { + + //Textos + Label labelIndiferencia; + Label labelPreferencia; + Label labelVeto; + + //Spinners + Spinner indiferencia; + Spinner prefrencia; + Spinner veto; + + //CheckButtons + Button checkButtonVeto; + + boolean changeWeight; + + public ElectreUmbralComponentUI(Composite composite) { + changeWeight = false; + + inicializarCompontentes(composite); + + } + + void inicializarCompontentes(Composite base) { + Composite row = new Composite(base, 0); + UiService.setGridData(row, 0, 9, true, true); + UiService.setGridLayout(row, 1); + + //Indiferencia (Q) + Composite rowLabelIndiferencia = new Composite(row, 0); + UiService.setGridData(rowLabelIndiferencia, 9, 9, true, false); + UiService.setGridLayout(rowLabelIndiferencia, 2, true); + labelIndiferencia = new Label (rowLabelIndiferencia, SWT.NONE); + labelIndiferencia.setText("Indiferencia:"); + indiferencia = new Spinner (rowLabelIndiferencia, SWT.BORDER); + indiferencia.setDigits(3); + indiferencia.setMinimum(Integer.MIN_VALUE); + indiferencia.setMaximum(Integer.MAX_VALUE); + + //Preferencia (P) + Composite rowLabelPreferencia = new Composite(row, 0); + UiService.setGridData(rowLabelPreferencia, 9, 9, true, false); + UiService.setGridLayout(rowLabelPreferencia, 2, true); + labelPreferencia = new Label (rowLabelPreferencia, SWT.NONE); + labelPreferencia.setText("Preferencia:"); + prefrencia = new Spinner (rowLabelPreferencia, SWT.BORDER); + prefrencia.setDigits(3); + prefrencia.setMinimum(Integer.MIN_VALUE); + prefrencia.setMaximum(Integer.MAX_VALUE); + + //Check button Veto + Composite rowLabelCheckVeto = new Composite(row, 0); + UiService.setGridData(rowLabelCheckVeto, 9, 9, true, false); + UiService.setGridLayout(rowLabelCheckVeto, 2, true); + checkButtonVeto = new Button(rowLabelCheckVeto, SWT.CHECK); + checkButtonVeto.setText("¿Usar veto?"); + checkButtonVeto.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + Button btn = (Button) e.getSource(); + + veto.setEnabled(btn.getSelection()); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + }); + + //Veto (V) + Composite rowLabelVeto = new Composite(row, 0); + UiService.setGridData(rowLabelVeto, 9, 9, true, false); + UiService.setGridLayout(rowLabelVeto, 2, true); + labelVeto = new Label (rowLabelVeto, SWT.NONE); + labelVeto.setText("Veto:"); + veto = new Spinner (rowLabelVeto, SWT.BORDER); + veto.setDigits(3); + veto.setMinimum(Integer.MIN_VALUE); + veto.setMaximum(Integer.MAX_VALUE); + veto.setEnabled(false); + } + + public void setParametersElectreUI(ParametersElectre dE) { + + //El spinner necesita un entero, entonces transformamos los números con decimales + //a numero sin decimales moviendo la coma. + + //Q + double oldNumber = dE.getIndiferencia(); + oldNumber *= Math.pow(10, indiferencia.getDigits()); + int newNumberWithDecimal = (int) oldNumber; + indiferencia.setSelection(newNumberWithDecimal); + + //P + oldNumber = dE.getPreferencia(); + oldNumber *= Math.pow(10, prefrencia.getDigits()); + newNumberWithDecimal = (int) oldNumber; + prefrencia.setSelection(newNumberWithDecimal); + + //CheckButtons + checkButtonVeto.setSelection(dE.getUsarVeto()); + veto.setEnabled(dE.getUsarVeto()); + oldNumber = dE.getVeto(); + oldNumber *= Math.pow(10, veto.getDigits()); + newNumberWithDecimal = (int) oldNumber; + veto.setSelection(newNumberWithDecimal); + } + + public ParametersElectre getParametersElectreUI() { + return new ParametersElectre( + this.getValorIndiferencia(), + this.getValorPrefrencia(), + null, //Direccion + 0.0, //Peso + this.getSiUsarVeto(), + this.getValorVeto() + ); + } + + public void addCheckListener(ModifyListener modifyComponent) { + //TO-DO + } + + public boolean getIsChangeWeight() { + return changeWeight; + } + + public Label getLabelIndiferencia() { + return labelIndiferencia; + } + + public Label getLabelPreferencia() { + return labelPreferencia; + } + + public Label getLabelVeto() { + return labelVeto; + } + + public Spinner getIndiferencia() { + return indiferencia; + } + + public Spinner getPrefrencia() { + return prefrencia; + } + + public Spinner getVeto() { + return veto; + } + + public Double getValorIndiferencia() { + return DoubleHelper.ParseDouble(indiferencia.getText()); + } + + public Double getValorPrefrencia() { + return DoubleHelper.ParseDouble(prefrencia.getText()); + } + + public Double getValorVeto() { + return DoubleHelper.ParseDouble(veto.getText()); + } + + public Button getCheckButtonVeto() { + return checkButtonVeto; + } + + public boolean getSiUsarVeto() { + return checkButtonVeto.getSelection(); + } + + public void setTextoIndiferencia(Label labelIndiferencia) { + this.labelIndiferencia = labelIndiferencia; + } + + public void setTextoPreferencia(String labelPreferencia) { + this.labelPreferencia.setText(labelPreferencia); + } + + public void setTextoVeto(String labelVeto) { + this.labelVeto.setText(labelVeto); + } + +} diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/ui/PhaseElectreUI.java b/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/ui/PhaseElectreUI.java new file mode 100644 index 0000000..9689849 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/ui/PhaseElectreUI.java @@ -0,0 +1,359 @@ +package flintstones.method.electre.phase.gathering.ui; + +import java.util.ArrayList; +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +import flintstones.application.perspective.framework.ui.interfaces.IProblemElementViewerOnSingleClick; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewer; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.common.phase.aggregation.provider.ProblemElementAggregationCheckStateProvider; +import flintstones.method.electre.phase.gathering.ParametersElectre; +import flintstones.method.electre.phase.gathering.Electre3Method; +import flintstones.method.electre.phase.gathering.viewer.ProblemElementViewerLabel; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class PhaseElectreUI extends PhaseMethodUI implements IProblemElementViewerOnSingleClick, ICheckStateListener { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + Electre3Method electre; + + //Component parameters ui + int selectedIndex; + ArrayList parametersElectre; + ElectreUmbralComponentUI electreComponent; + boolean isExecutableElectre; + ArrayList excuteElectre; + + HtmlTextTable tableValuesAlternative; + Label titleLabelParametersCriterion; + + ProblemElementViewer criterionViewer; + ProblemElementAggregationCheckStateProvider checkProvider; + + //Parameters electre + Expert expertProblem; + String selectedCriterion; + + Button btnPasarFase; + + //Listener for the UI components. + ModifyListener modifyP = new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + parametersElectre.get(selectedIndex).setPeso(electreComponent.getValorPrefrencia()); + //Cambiamos la col1 + criterionViewer.updateViewer(Criterion.Type); + } + }; + + ModifyListener modifyQ = new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + parametersElectre.get(selectedIndex).setPreferencia(electreComponent.getValorPrefrencia()); + //Cambiamos la col1 + criterionViewer.updateViewer(Criterion.Type); + } + }; + + ModifyListener modifyS = new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + parametersElectre.get(selectedIndex).setPeso(electreComponent.getValorPrefrencia()); + //Cambiamos la col1 + criterionViewer.updateViewer(Criterion.Type); + } + }; + + @Override + public void init() { + isExecutableElectre = false; + electre = (Electre3Method) this.getModel(); + electre.inicializar(); + + //Inicializar datos + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 0, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText("Fase datos umbrales Electre 3"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + //BODY + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9,9, true, true); + UiService.setGridLayout(row2, 3, true); + + expertProblem = electre.getExperts()[0]; + selectedCriterion = electre.getCriterion()[0].getCanonicalName(); + initBodyUI(row2); + + //Button + Composite row3 = new Composite(base, 0); + UiService.setGridData(row3, 0,9, true, true); + UiService.setGridLayout(row3, 1); + + btnPasarFase = new Button(row3, 0); + btnPasarFase.setText("Obtener resultados"); + btnPasarFase.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + saveParameters(); + + //q <= p <= v ?? + for(int i = 0; i < parametersElectre.size(); i++) { + if(parametersElectre.get(i).getIndiferencia() > parametersElectre.get(i).getPreferencia() || + (parametersElectre.get(i).getPreferencia() > parametersElectre.get(i).getVeto() && parametersElectre.get(i).getUsarVeto())) { + pushProblemDialog("Se debe cumplir que: indiferencia <= preferencia <= veto"); + return; + } + } + + executeElectre(); + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + }); + + } + + private void initBodyUI(Composite base) { + parametersElectre = new ArrayList(); + excuteElectre = new ArrayList(); + initArrayDatosElectre(); + selectedIndex = 0; + + createColTreeView(base); + + createColParametersElectre(base); + + createColTableAlternative(base); + + //electreComponent.addCheckListener(modifyComponent); + } + + private void createColTreeView(Composite base) { + + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + Label titleLabel = new Label(row, SWT.NONE); + titleLabel.setText("Criterios"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + //Criterion tree + criterionViewer = getViewer(row, Criterion.Type, true); + } + + private void createColParametersElectre(Composite base) { + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + titleLabelParametersCriterion = new Label(row, SWT.NONE); + titleLabelParametersCriterion.setText("Umbrales de " + selectedCriterion); + UiService.setGridData(titleLabelParametersCriterion, 9 ,9, true, false); + UiService.setFont(titleLabelParametersCriterion, UiService.FONT_SECTION_TITLE); + + Composite row1 = new Composite(row, SWT.BORDER); + UiService.setGridData(row1, 9, 9, true, true); + UiService.setGridLayout(row1, 1); + + electreComponent = new ElectreUmbralComponentUI(row1); + electreComponent.setParametersElectreUI( parametersElectre.get(selectedIndex) ); + + } + + private void createColTableAlternative(Composite base) { + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + Label titleLabel = new Label(row, SWT.NONE); + titleLabel.setText("Datos alternativa"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + Composite row1 = new Composite(row, SWT.BORDER); + UiService.setGridData(row1, 9, 9, true, true); + UiService.setGridLayout(row1, 1); + + initTableAlternative(row1, electre.getAlernativesNames(), electre.getCriterionNames()); + } + + private void initTableAlternative(Composite base, String[] alternativesNames, String[] criterions) { + String[][] valuesCriterionAlternatives = new String[alternativesNames.length][1]; + String[] nameCriterion = new String[1]; + nameCriterion[0] = selectedCriterion; + + int indexCriterion = -1; + for(int i = 0; i < criterions.length; i++) { + if( criterions[i].equals(selectedCriterion) ){ + indexCriterion = i; + break; + } + } + + double[][] values = electre.getValuations(expertProblem); + for(int i = 0; i < values.length; i++) { + valuesCriterionAlternatives [i][0] = Double.toString(values[i][indexCriterion]); + } + + this.tableValuesAlternative = new HtmlTextTable(base, valuesCriterionAlternatives, nameCriterion, alternativesNames); + this.tableValuesAlternative.render(); + } + + private void initArrayDatosElectre() { + for(int i = 0; i < electre.getCriterion().length; i++) { + parametersElectre.add( new ParametersElectre(0.0, 0.0, ParametersElectre.Direccion.maximizar, 0.0, false, 0.0) ); + excuteElectre.add(false); + } + + } + + private void executeElectre() { + for(int i = 0; i < parametersElectre.size(); i++) { + ParametersElectre pE = parametersElectre.get(i); + pE.setCriterion(electre.getCriterion()[i]); + electre.addDatoEntrada(pE); + } + + electre.executeMethod(electre.getExperts()[0]); + isExecutableElectre = true; + refreshUI(); + } + + //Métodos para el Tree View + private ProblemElementViewer getViewer(Composite parent, String type, boolean addParent) { + + ProblemElementViewerLabel viewer = ContextInjectionFactory.make(ProblemElementViewerLabel.class, this.context); + + if (addParent) { + FakeProblemElement fakePE = new FakeProblemElement(""); + fakePE.as(type); + viewer.useGlobalParent(fakePE); + } + + viewer.createControls(type, parent); + viewer.addListener(this); + viewer.loadListeners(); + + UiService.setGridLayout(viewer.getTree().getTree(), 1); + UiService.setGridData(viewer.getTree().getTree(), 9, 9, true, true); + + return viewer; + } + + public void problemElementViewerOnSingleClick(ProblemElement item) { + //Seleccionado el fake parent. + if(item.getCanonicalName().equals("")) + return; + + //Guardamos + saveParameters(); + + selectedCriterion = item.getCanonicalName(); + titleLabelParametersCriterion.setText("Umbrales de " + selectedCriterion); + + //Cambiamos col 2 + for(int i = 0; i < electre.getCriterion().length; i++) { + if( electre.getCriterion()[i].getCanonicalName().equals(selectedCriterion) ){ + selectedIndex = i; + break; + } + } + + electreComponent.setParametersElectreUI( parametersElectre.get(selectedIndex) ); + + //Cambiamos col3 + refreshValuesAlternative(); + } + + public void checkStateChanged(CheckStateChangedEvent event) { + refreshUI(); + } + + private void saveParameters() { + //Actualizarmos el valor. + parametersElectre.get(selectedIndex).setIndiferencia(electreComponent.getValorIndiferencia()); + parametersElectre.get(selectedIndex).setPreferencia(electreComponent.getValorPrefrencia()); + parametersElectre.get(selectedIndex).setUsarVeto(electreComponent.getSiUsarVeto()); + parametersElectre.get(selectedIndex).setVeto(electreComponent.getValorVeto()); + } + + private void refreshValuesAlternative() { + + if(tableValuesAlternative == null) return; + + Composite row = tableValuesAlternative.getParent(); + Arrays.stream(row.getChildren()).forEach(k -> k.dispose()); + + initTableAlternative(row, electre.getAlernativesNames(), electre.getCriterionNames()); + + tableValuesAlternative.render(); + row.layout(); + } + + private void pushProblemDialog(String msg) { + Shell newShell = new Shell(); + UiService.centerShell(newShell, true); + MessageDialog.openError(newShell, "Error", msg); + } + + public void refreshUI() { + this.sendRefresh(); + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + if(isExecutableElectre) + return true; + return false; + } + +} diff --git a/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/viewer/ProblemElementViewerLabel.java b/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/viewer/ProblemElementViewerLabel.java new file mode 100644 index 0000000..4400c1b --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering.ui/src/flintstones/method/electre/phase/gathering/viewer/ProblemElementViewerLabel.java @@ -0,0 +1,35 @@ +package flintstones.method.electre.phase.gathering.viewer; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; + +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewer; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.method.electre.phase.gathering.provider.ProblemElementLabelProvider; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class ProblemElementViewerLabel extends ProblemElementViewer { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + @Override + protected IStyledLabelProvider getLabelProvider(String type) { + + ImageDescriptor individualImage = UiService.getIcon(ProblemElementHelper.getImage(type, false)); + ImageDescriptor groupImage = UiService.getIcon(ProblemElementHelper.getImage(type, true)); + + ProblemElementLabelProvider provider = new ProblemElementLabelProvider(individualImage, groupImage); + ContextInjectionFactory.inject(provider, context); + return provider; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.electre.phase.gathering/.classpath b/bundles/flintstones.method.electre.phase.gathering/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.gathering/.polyglot.META-INF b/bundles/flintstones.method.electre.phase.gathering/.polyglot.META-INF new file mode 100644 index 0000000..f7f2c51 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.electre.phase.gathering + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Gathering + diff --git a/bundles/flintstones.method.electre.phase.gathering/.project b/bundles/flintstones.method.electre.phase.gathering/.project new file mode 100644 index 0000000..d9e2a5f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/.project @@ -0,0 +1,45 @@ + + + flintstones.method.electre.phase.gathering + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362664 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.electre.phase.gathering/META-INF/MANIFEST.MF b/bundles/flintstones.method.electre.phase.gathering/META-INF/MANIFEST.MF new file mode 100644 index 0000000..41075f7 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Gathering +Bundle-SymbolicName: flintstones.method.electre.phase.gathering;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.electre.phase.gathering +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.contexts, + javax.inject, + flintstones.model.valuation.service, + flintstones.model.domain.service, + flintstones.valuation, + flintstones.valuation.numeric, + flintstones.helper.ui, + flintstones.helper.data, + flintstones.helper.debug, + flintstones.entity.problemelement, + flintstones.model.problemelement.service, + flintstones.application.perspective.framework.ui, + flintstones.entity.method.phase, + flintstones.entity.valuation +Export-Package: flintstones.method.electre.phase.gathering diff --git a/bundles/flintstones.method.electre.phase.gathering/build.properties b/bundles/flintstones.method.electre.phase.gathering/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.electre.phase.gathering/plugin.xml b/bundles/flintstones.method.electre.phase.gathering/plugin.xml new file mode 100644 index 0000000..e98d833 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.gathering/src/flintstones/method/electre/phase/gathering/Electre3Method.java b/bundles/flintstones.method.electre.phase.gathering/src/flintstones/method/electre/phase/gathering/Electre3Method.java new file mode 100644 index 0000000..c046a21 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/src/flintstones/method/electre/phase/gathering/Electre3Method.java @@ -0,0 +1,314 @@ +package flintstones.method.electre.phase.gathering; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; +import javax.inject.Inject; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.debug.DH; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.numeric.NumericValuation; + +public class Electre3Method extends PhaseMethod { + + @Inject + IEclipseContext context; + + @Inject + IValuationService valuationService; + + @Inject + IDomainService domainService; + + @Inject + IProblemElementService problemService; + + // Atributos + HashMap mapVAluations; + Alternative[] allAlternatives; + Criterion[] allCriterion; + Expert[] allexperts; + + double alfa; + double beta; + + // Datos para Electre + double[][] matrizDesempe; // Alternativas frente criterios + double[][] fuzzyRelation; // Alternativas frente alternativas + int[] ranking; + ArrayList datosUmbralesPesos; + HashMatrix hmWeights; + + public Electre3Method() { + } + + @Override + public String getName() { + return "Electre 3"; + } + + @SuppressWarnings("unchecked") + public void inicializar() { + DH.out("electre","Init Electre 3"); + datosUmbralesPesos = new ArrayList<>(); + + ProblemElement[] pes = problemService.getAll(Alternative.Type); + allAlternatives = ProblemElementHelper.asAlternatives(pes); + + pes = problemService.getAll(Criterion.Type); + allCriterion = ProblemElementHelper.asCriterions(pes); + + pes = problemService.getAll(Expert.Type); + allexperts = ProblemElementHelper.asExperts(pes); + + fuzzyRelation = new double[allAlternatives.length][allAlternatives.length]; + hmWeights = (HashMatrix) this.importData("criterionWeights"); + } + + public void executeMethod(Expert e) { + this.matrizDesempe = this.getValuations(e); + + electrealgorithm(); + + //Exportamos los datos para la UI resultados. + this.exportData("fuzzyRelation", fuzzyRelation); + this.exportData("alternativas", allAlternatives); + } + + public void addDatoEntrada(ParametersElectre pE) { + ParametersElectre.Direccion dir = ( pE.getCriterion().isCost()) ? ParametersElectre.Direccion.minimizar : ParametersElectre.Direccion.maximizar; + double weight = hmWeights.get(allexperts[0], pE.getCriterion()); + + ParametersElectre dE = new ParametersElectre(pE.getIndiferencia(), pE.getPreferencia(), dir, weight, pE.getUsarVeto(), pE.getVeto()); + datosUmbralesPesos.add(dE); + } + + public String[] getAlernativesNames() { + String[] names = new String[allAlternatives.length]; + + for (int i = 0; i < names.length; i++) + names[i] = allAlternatives[i].getCanonicalName(); + + return names; + } + + public Alternative[] getAlternatives() { + ProblemElement[] pes = problemService.getAll(Alternative.Type); + return ProblemElementHelper.asAlternatives(pes); + } + + public Criterion[] getCriterion() { + ProblemElement[] pes = problemService.getAll(Criterion.Type); + return ProblemElementHelper.asCriterions(pes); + } + + public Expert[] getExperts() { + ProblemElement[] pes = problemService.getAll(Expert.Type); + return ProblemElementHelper.asExperts(pes); + } + + public void reiniciarDatos() { + datosUmbralesPesos.clear(); + } + + public HashMap getMapValuations(Expert e) { + ProblemElement pE = problemService.getByCanonicalName(Expert.Type, e.getCanonicalName()); + mapVAluations = valuationService.getAllValuationsKVWith(pE); + return mapVAluations; + } + + public double[][] getValuations(Expert e) { + + double[][] valuation = new double[allAlternatives.length][allCriterion.length]; + + //Obtenemos el hashmap + ProblemElement pE = problemService.getByCanonicalName(Expert.Type, e.getCanonicalName()); + mapVAluations = valuationService.getAllValuationsKVWith(pE); + + //Para cada elemento, introducirlo ordenado en el array + int a = 0, b = 0; + for(Entry entry : mapVAluations.entrySet()){ + NumericValuation nV = (NumericValuation) entry.getValue(); + + for(int i = 0; i < allAlternatives.length; i++) + if(entry.getKey().getAlternative().getCanonicalName().equals( allAlternatives[i].getCanonicalName() )) { + a = i; + break; + } + + for(int i = 0; i < allCriterion.length; i++) + if(entry.getKey().getCriterion().getCanonicalName().equals( allCriterion[i].getCanonicalName() )) { + b = i; + break; + } + + valuation[a][b] = Double.valueOf(nV.getValue()); + a = 0; + b = 0; + } + + return valuation; + } + + public String[] getCriterionNames() { + String[] names = new String[allCriterion.length]; + + for (int i = 0; i < names.length; i++) + names[i] = allCriterion[i].getCanonicalName(); + + return names; + } + + public void establecerAlfaBeta(double alfa, double beta) { + this.alfa = alfa; + this.beta = beta; + } + + // -------------------------------------------------------------------- + private void electrealgorithm() { + fuzzyRelation = new double[allAlternatives.length][allAlternatives.length]; + + for (int i = 0; i < allAlternatives.length; i++) { + for (int j = 0; j < allAlternatives.length; j++) { + if (j == i) + fuzzyRelation[i][j] = 1; + else + fuzzyRelation[i][j] = sigma(matrizDesempe[i], matrizDesempe[j], this.datosUmbralesPesos); + } + } + } + + private double sigma(double[] A, double[] B, ArrayList datosUmbralesPesos) { + double sig = 0; + double d = 0, discordancia, c = 0, concordancia = 0, valDis; + + for (int k = 0; k < allCriterion.length; k++) { + + if (datosUmbralesPesos.get(k).getDireccion() == ParametersElectre.Direccion.maximizar) { + if (B[k] <= (A[k] + datosUmbralesPesos.get(k).getIndiferencia())) { // aSb + c = 1; + } else { + + if (B[k] > (A[k] + datosUmbralesPesos.get(k).getPreferencia())) { + c = 0; + } else { + if ((A[k] + datosUmbralesPesos.get(k).getIndiferencia()) < B[k] && B[k] <= (A[k] + datosUmbralesPesos.get(k).getPreferencia())) { + + c = (datosUmbralesPesos.get(k).getPreferencia() - (B[k] - A[k])) + / (datosUmbralesPesos.get(k).getPreferencia() - datosUmbralesPesos.get(k).getIndiferencia()); + } + } + } + } else { // minimizar + if (((A[k] - B[k]) <= datosUmbralesPesos.get(k).getIndiferencia()) || (A[k] <= B[k])) { // aSb + c = 1; + } else { + if ((A[k] - B[k]) > datosUmbralesPesos.get(k).getPreferencia()) { + c = 0; + } else { + if (datosUmbralesPesos.get(k).getIndiferencia() < (A[k] - B[k]) && (A[k] - B[k]) <= datosUmbralesPesos.get(k).getPreferencia()) { + + c = (datosUmbralesPesos.get(k).getPreferencia() - (A[k] - B[k])) + / (datosUmbralesPesos.get(k).getPreferencia() - datosUmbralesPesos.get(k).getIndiferencia()); + + } + } + } + } + + concordancia += c * datosUmbralesPesos.get(k).getPeso(); + } + + // discordancia + // ----------------------------- + + discordancia = 0; + for (int k = 0; k < allCriterion.length; k++) { + + d = 0; + + if (datosUmbralesPesos.get(k).getUsarVeto()) { // Va usar veto (v) + + d = -1; // para problar si esta entrando a las condiciones + + if (datosUmbralesPesos.get(k).getDireccion() == ParametersElectre.Direccion.maximizar) { + if ((B[k] - A[k]) <= datosUmbralesPesos.get(k).getPreferencia()) { + d = 0; + } else { + if (datosUmbralesPesos.get(k).getPreferencia() < (B[k] - A[k]) && (B[k] - A[k]) < datosUmbralesPesos.get(k).getVeto()) { + + d = ((B[k] - A[k]) - datosUmbralesPesos.get(k).getPreferencia()) + / (datosUmbralesPesos.get(k).getVeto() - datosUmbralesPesos.get(k).getPreferencia()); + + } else { + if ((B[k] - A[k]) >= datosUmbralesPesos.get(k).getPreferencia()) { + d = 1; + } + + } + + } + } else { // minimizar + + if ((A[k] - B[k]) <= datosUmbralesPesos.get(k).getPreferencia()) { + d = 0; + } else { + if (datosUmbralesPesos.get(k).getPreferencia() < (A[k] - B[k]) && (A[k] - B[k] < datosUmbralesPesos.get(k).getVeto())) { + + d = (A[k] - datosUmbralesPesos.get(k).getPreferencia() - B[k]) + / (datosUmbralesPesos.get(k).getVeto() - datosUmbralesPesos.get(k).getPreferencia()); + + } else { + if (A[k] - B[k] >= datosUmbralesPesos.get(k).getVeto()) { + d = 1; + } + } + + } + + } + + } + + if (d == 1) { + valDis = 1; + discordancia = 1; // esto veta al resto de criterios + } else { + if (d > concordancia && discordancia != 1) { + valDis = (1 - d) / (1 - concordancia); + if (discordancia == 0) + discordancia = valDis; + else + discordancia *= valDis; + } else { + valDis = 0; + } + } + } + + if (discordancia > 0) { + if (discordancia == 1) + sig = 0; + else + sig = concordancia * discordancia; + } else + sig = concordancia; + + return sig; + + } + +} diff --git a/bundles/flintstones.method.electre.phase.gathering/src/flintstones/method/electre/phase/gathering/ParametersElectre.java b/bundles/flintstones.method.electre.phase.gathering/src/flintstones/method/electre/phase/gathering/ParametersElectre.java new file mode 100644 index 0000000..f6d8f47 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.gathering/src/flintstones/method/electre/phase/gathering/ParametersElectre.java @@ -0,0 +1,98 @@ +package flintstones.method.electre.phase.gathering; + +import flintstones.entity.problemelement.entities.Criterion; + +public class ParametersElectre { + + public enum Direccion {maximizar, minimizar} + double indiferencia; + double preferencia; + + boolean usarVeto; + double veto; //Opcional + Direccion direccion; + + double peso; + + Criterion c; + + public ParametersElectre(double indiferencia, double preferencia, Direccion direccion, double peso, boolean usarVeto, double veto){ + this.indiferencia = indiferencia; + this.preferencia = preferencia; + this.direccion = direccion; + this.peso = peso; + + this.usarVeto = usarVeto; + this.veto = veto; + } + + public Criterion getCriterion() { + return c; + } + + public void setCriterion(Criterion c) { + this.c = c; + } + + public double getIndiferencia() { + return indiferencia; + } + + public double getPreferencia() { + return preferencia; + } + + public boolean getUsarVeto() { + return usarVeto; + } + + public double getVeto() { + return veto; + } + + public Direccion getDireccion() { + return direccion; + } + + public double getPeso() { + return peso; + } + + public void setIndiferencia(double value) { + indiferencia = value; + } + + public void setPreferencia(double value) { + preferencia = value; + } + + public void setUsarVeto(boolean value) { + usarVeto = value; + } + + public void setVeto(double value) { + veto = value; + } + + public void setDireccion(Direccion value) { + direccion = value; + } + + public void setPeso(double value) { + peso = value; + } + + @Override + public String toString() { + String str = "Datos: "; + str += "Q: " + indiferencia; + str += " | P: " + preferencia; + str += " | ¿Usar veto?: " + usarVeto; + str += " | V: " + veto; + str += " | Direccion: " + direccion; + str += " | Peso: " + peso; + return str; + } + + +} diff --git a/bundles/flintstones.method.electre.phase.result.ui/.classpath b/bundles/flintstones.method.electre.phase.result.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.result.ui/.polyglot.META-INF b/bundles/flintstones.method.electre.phase.result.ui/.polyglot.META-INF new file mode 100644 index 0000000..a362d8f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.electre.phase.result.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.electre.phase.result.ui/.project b/bundles/flintstones.method.electre.phase.result.ui/.project new file mode 100644 index 0000000..78c84a8 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.electre.phase.result.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362666 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.electre.phase.result.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.electre.phase.result.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..fb1f025 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.electre.phase.result.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.electre.phase.result.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.ui, + org.eclipse.e4.core.contexts, + flintstones.entity.problemelement, + flintstones.helper.html, + flintstones.method.electre.phase.result, + flintstones.model.ui.service, + flintstones.entity.method.phase.ui, + javax.inject, + flintstones.entity.method.phase diff --git a/bundles/flintstones.method.electre.phase.result.ui/build.properties b/bundles/flintstones.method.electre.phase.result.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.electre.phase.result.ui/plugin.xml b/bundles/flintstones.method.electre.phase.result.ui/plugin.xml new file mode 100644 index 0000000..ea17d66 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.result.ui/src/flintstones/method/electre/phase/result/ui/ElectreResultUI.java b/bundles/flintstones.method.electre.phase.result.ui/src/flintstones/method/electre/phase/result/ui/ElectreResultUI.java new file mode 100644 index 0000000..91bd77c --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result.ui/src/flintstones/method/electre/phase/result/ui/ElectreResultUI.java @@ -0,0 +1,104 @@ +package flintstones.method.electre.phase.result.ui; + +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.electre.phase.result.ElectreResultModel; +import flintstones.model.ui.service.UiService; + +public class ElectreResultUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + Alternative[] alts; + double[][] fuzzyRelation; // Alternativas frente alternativas + + ElectreResultModel electreResultModel; + HtmlTextTable tableFuzzyRelation; + + @Override + public void init() { + + electreResultModel = (ElectreResultModel) this.getModel(); + electreResultModel.importarDatos(); + + //Inicializar datos + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, SWT.NONE); + UiService.setGridData(row1, 9, 0, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText("Resultados de Electre 3"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9, 9, true, true); + UiService.setGridLayout(row2, 1); + + //Mostrar matriz final + fuzzyRelation = electreResultModel.getFuzzyRelation(); + alts = electreResultModel.getAlternativas(); + + mostrarMatrizAltAlt(row2, fuzzyRelation, electreResultModel.getAlternativasNames(), electreResultModel.getAlternativasNames()); + + + } + + private void mostrarMatrizAltAlt(Composite base, double[][] values, String[] itemRow, String[] itemCol) { + String[][] matrix = new String[itemRow.length][itemCol.length]; + + for(int i = 0; i < values.length; i++) { + for (int j = 0; j < values[i].length; j++) { + matrix [i][j] = String.format("%.2f", values[i][j]); + } + } + + this.tableFuzzyRelation = new HtmlTextTable(base, matrix, itemCol, itemRow); + this.tableFuzzyRelation.render(); + } + + @Override + public void refresh() { + refreshTable(); + this.sendRefresh(); + } + + private void refreshTable() { + if(tableFuzzyRelation == null) return; + + Composite rowFuzzy = tableFuzzyRelation.getParent(); + Arrays.stream(rowFuzzy.getChildren()).forEach(k -> k.dispose()); + + electreResultModel.importarDatos(); + + mostrarMatrizAltAlt(rowFuzzy, fuzzyRelation, electreResultModel.getAlternativasNames(), electreResultModel.getAlternativasNames()); + + tableFuzzyRelation.render(); + rowFuzzy.layout(); + } + + @Override + public boolean isSkippable() { + return true; + } + + @Override + public boolean isForwardEnabled() { + return true; + } + +} diff --git a/bundles/flintstones.method.electre.phase.result/.classpath b/bundles/flintstones.method.electre.phase.result/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.result/.polyglot.META-INF b/bundles/flintstones.method.electre.phase.result/.polyglot.META-INF new file mode 100644 index 0000000..920c087 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.electre.phase.result + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Result + diff --git a/bundles/flintstones.method.electre.phase.result/.project b/bundles/flintstones.method.electre.phase.result/.project new file mode 100644 index 0000000..26ae39e --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/.project @@ -0,0 +1,45 @@ + + + flintstones.method.electre.phase.result + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362665 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.electre.phase.result/META-INF/MANIFEST.MF b/bundles/flintstones.method.electre.phase.result/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8a9f8f4 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Result +Bundle-SymbolicName: flintstones.method.electre.phase.result;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.electre.phase.result +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.contexts, + flintstones.entity.problemelement, + javax.inject, + flintstones.entity.method.phase +Export-Package: flintstones.method.electre.phase.result diff --git a/bundles/flintstones.method.electre.phase.result/build.properties b/bundles/flintstones.method.electre.phase.result/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.electre.phase.result/plugin.xml b/bundles/flintstones.method.electre.phase.result/plugin.xml new file mode 100644 index 0000000..28a259d --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.electre.phase.result/src/flintstones/method/electre/phase/result/ElectreResultModel.java b/bundles/flintstones.method.electre.phase.result/src/flintstones/method/electre/phase/result/ElectreResultModel.java new file mode 100644 index 0000000..b902790 --- /dev/null +++ b/bundles/flintstones.method.electre.phase.result/src/flintstones/method/electre/phase/result/ElectreResultModel.java @@ -0,0 +1,52 @@ +package flintstones.method.electre.phase.result; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; + +public class ElectreResultModel extends PhaseMethod { + + @Inject + IEclipseContext context; + + Alternative[] allAlternatives; + double[][] fuzzyRelation; // Alternativas frente alternativas + + public ElectreResultModel() { + } + + @Override + public String getName() { + return "Electre 3: Result"; + } + + public void importarDatos() { + allAlternatives = (Alternative[]) this.importData("alternativas"); + fuzzyRelation = (double[][]) this.importData("fuzzyRelation"); + + this.exportData("fuzzyRelation", fuzzyRelation); + this.exportData("alternativas", allAlternatives); + } + + public double[][] getFuzzyRelation() { + return fuzzyRelation; + } + + public Alternative[] getAlternativas() { + return allAlternatives; + } + + public String[] getAlternativasNames() { + String[] str = new String[allAlternatives.length]; + + for(int i = 0; i < allAlternatives.length; i++) + str[i] = allAlternatives[i].getCanonicalName(); + + + return str; + } + +} diff --git a/bundles/flintstones.method.electre/.classpath b/bundles/flintstones.method.electre/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.electre/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.electre/.polyglot.META-INF b/bundles/flintstones.method.electre/.polyglot.META-INF new file mode 100644 index 0000000..b7a3079 --- /dev/null +++ b/bundles/flintstones.method.electre/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.electre + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Electre + diff --git a/bundles/flintstones.method.electre/.project b/bundles/flintstones.method.electre/.project new file mode 100644 index 0000000..fe08600 --- /dev/null +++ b/bundles/flintstones.method.electre/.project @@ -0,0 +1,45 @@ + + + flintstones.method.electre + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362662 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.electre/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.electre/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.electre/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.electre/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.electre/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..fb1077b --- /dev/null +++ b/bundles/flintstones.method.electre/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +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.release=enabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/flintstones.method.electre/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.electre/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.electre/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.electre/META-INF/MANIFEST.MF b/bundles/flintstones.method.electre/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f23f4d9 --- /dev/null +++ b/bundles/flintstones.method.electre/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.electre;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.electre +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric diff --git a/bundles/flintstones.method.electre/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.electre/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..65590cf --- /dev/null +++ b/bundles/flintstones.method.electre/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.electre +Bundle-Name = Electre \ No newline at end of file diff --git a/bundles/flintstones.method.electre/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.electre/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..76ccbb8 --- /dev/null +++ b/bundles/flintstones.method.electre/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.electre +Bundle-Name = ElectreIII \ No newline at end of file diff --git a/bundles/flintstones.method.electre/build.properties b/bundles/flintstones.method.electre/build.properties new file mode 100644 index 0000000..3e5f9ad --- /dev/null +++ b/bundles/flintstones.method.electre/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/ diff --git a/bundles/flintstones.method.electre/plugin.xml b/bundles/flintstones.method.electre/plugin.xml new file mode 100644 index 0000000..622b58a --- /dev/null +++ b/bundles/flintstones.method.electre/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.electre/src/flintstones/method/electre/ElectreMethod.java b/bundles/flintstones.method.electre/src/flintstones/method/electre/ElectreMethod.java new file mode 100644 index 0000000..ac64e00 --- /dev/null +++ b/bundles/flintstones.method.electre/src/flintstones/method/electre/ElectreMethod.java @@ -0,0 +1,41 @@ +package flintstones.method.electre; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.electre.messages.Messages; +import flintstones.valuation.numeric.NumericValuation; + +public class ElectreMethod extends ValidatedMethod { + + @Inject + @Translation + Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, NumericValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/Messages.java b/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/Messages.java new file mode 100644 index 0000000..8adc78d --- /dev/null +++ b/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/Messages.java @@ -0,0 +1,13 @@ +//This file has been auto-generated +package flintstones.method.electre.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Method_description; + +} diff --git a/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/messages.properties b/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/messages.properties new file mode 100644 index 0000000..9ab2d79 --- /dev/null +++ b/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/messages.properties @@ -0,0 +1,2 @@ +Method_name=ELimination and Choice Expressing REality III (ELECTRE III) +Method_description=Method electre \ No newline at end of file diff --git a/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/messages_es.properties b/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/messages_es.properties new file mode 100644 index 0000000..9a8a1f6 --- /dev/null +++ b/bundles/flintstones.method.electre/src/flintstones/method/electre/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_name=Eliminacin y Eleccion Expresando Realidad III (ELECTRE III) +Method_description=Mtodo electre \ No newline at end of file diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.classpath b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.polyglot.META-INF b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.polyglot.META-INF new file mode 100644 index 0000000..09d01de --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort.phase.alternativeinformation.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.project b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.project new file mode 100644 index 0000000..7bd4ee2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort.phase.alternativeinformation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362668 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8c1f654 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.flowsort.phase.alternativeinformation.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort.phase.alternativeinformation.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.method.flowsort.phase.alternativeinformation, + flintstones.entity.method.phase, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.helper.html, + flintstones.entity.problemelement.ui, + flintstones.entity.problemelement, + flintstones.method.flowsort.phase.result, + flintstones.helper.data, + org.apache.commons.lang diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/build.properties b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/plugin.xml b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/plugin.xml new file mode 100644 index 0000000..135b327 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/src/flintstones/method/flowsort/phase/alternativeinformation/ui/AlternativeFlowsortInformationUI.java b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/src/flintstones/method/flowsort/phase/alternativeinformation/ui/AlternativeFlowsortInformationUI.java new file mode 100644 index 0000000..1ba4189 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation.ui/src/flintstones/method/flowsort/phase/alternativeinformation/ui/AlternativeFlowsortInformationUI.java @@ -0,0 +1,170 @@ +package flintstones.method.flowsort.phase.alternativeinformation.ui; + +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Alternative; +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.html.svg.Svg; +import flintstones.helper.html.svg.Svg.LineStroke; +import flintstones.helper.html.svg.chart.SvgChart; +import flintstones.helper.html.svg.SvgBrowser; +import flintstones.helper.html.svg.Tag; +import flintstones.method.flowsort.phase.alternativeinformation.AlternativeFlowsortInformationModel; +import flintstones.method.flowsort.phase.result.AlternativeFlow; +import flintstones.model.ui.service.UiService; + +public class AlternativeFlowsortInformationUI extends PhaseMethodUI { + + AlternativeFlowsortInformationModel model; + + SvgBrowser browser; + + @Override + public void init() { + + model = (AlternativeFlowsortInformationModel) this.getModel(); + model.execute(); + + Composite parent = getBaseComposite(); + UiService.setGridLayout(parent, 1); + UiService.setGridDataAuto(parent); + create(parent); + + } + + private void create(Composite base) { + + Composite a = new Composite(base,0); + UiService.setGridLayout(a, 1); + UiService.setGridData(a, 9, 0, true, false); + + ProblemElementSelector combo = new ProblemElementSelector(a, model.getAlternatives()); + combo.setListener(new IProblemElementChangedListener() { + + @Override + public void problemElementChanged(ProblemElement pe) { + drawChartFor((Alternative) pe); + + } + }); + + Composite b = new Composite(base,0); + UiService.setGridLayout(b, 1); + UiService.setGridDataAuto(b); + + browser = new SvgBrowser(b); + drawChartFor((Alternative)combo.getSelectedElement()); + + } + + private void drawChartFor(Alternative al) { + + SortingClass[] classes = model.getClasses(); + + AlternativeFlow flow = model.getFlowFor(al); + double[] pFlowX = flow.getPositiveFlows(); +// pFlowX = ArrayUtils.add(pFlowX,0.0); + + double[] nFlowY = flow.getNegativeFlows(); +// double[] nFlowY0 = new double[] {0.0}; +// nFlowY = ArrayUtils.addAll(nFlowY,nFlowY0); + + double maxX = Double.MIN_VALUE; + double maxY = Double.MIN_VALUE; + + for(int i = 0 ; i < pFlowX.length; i++) { + double a = pFlowX[i]; + double b = nFlowY[i]; + + if(maxX < a) + maxX = a; + if(maxY < b) + maxY = b; + + } + + maxX = maxX > flow.getPositiveFlow() ? maxX : flow.getPositiveFlow(); + maxY = maxY > flow.getNegativeFlow() ? maxY : flow.getNegativeFlow(); +// maxX = 1; +// maxY = 1; + + SvgChart chart = new SvgChart(1666, 1000, maxX, maxY); + browser.setCanvas(chart); + +// chart.drawMarkers(true, true, 0.1); + + // Draw vertical lines with markers + for(double val : pFlowX) { + Tag tag = (Tag) chart.drawVerticalLine(val) // + .attr("stroke","#0000ff") + .attr("fill","#0000ff"); + Svg.addStroke(tag, 20, LineStroke.Dashed); + + String valS = DoubleHelper.Draw(val); + chart.drawBottonMarker(val, valS); + } + + // Horizontal + for(double val : nFlowY) { + Tag tag = (Tag) chart.drawHorizontalLine(val) + .attr("stroke","#0000ff") + .attr("fill","#0000ff"); + Svg.addStroke(tag, 20, LineStroke.Dashed); + + String valS = DoubleHelper.Draw(val); + chart.drawLeftMarker(val, valS); + } + + Double x = null; + Double y = null; + for(int i = 0; i < pFlowX.length; i++) { + + double ny = nFlowY[i]; + double nx = pFlowX[i]; + + if(x != null && y != null) { +// double sx = (nx+x)/2; +// double sy = (ny+y)/2; + + chart.drawBox(nx, ny, x, y) + .attr("style","opacity:0.5; fill: blue"); + } + + if(i != pFlowX.length -1) + chart.drawText(nx, ny, 0, classes[i].getName()); + + x = nx; + y = ny; + + } + + // Star + chart.drawStar(flow.getPositiveFlow(), flow.getNegativeFlow()); + String px = DoubleHelper.Draw(flow.getPositiveFlow()); + String py = DoubleHelper.Draw(flow.getNegativeFlow()); + chart.drawText(flow.getPositiveFlow(), flow.getNegativeFlow(), 2, px + "|" + py ); + + browser.render(); + + System.out.println(flow); + + } + + @Override + public void refresh() { + // TODO Auto-generated method stub + + } + + @Override + protected boolean isForwardEnabled() { + // TODO Auto-generated method stub + return true; + } + +} diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/.classpath b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/.polyglot.META-INF b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.polyglot.META-INF new file mode 100644 index 0000000..a715501 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort.phase.alternativeinformation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Alternativeinformation + diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/.project b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.project new file mode 100644 index 0000000..0e6b680 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort.phase.alternativeinformation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362667 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort.phase.alternativeinformation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e826a97 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Alternativeinformation +Bundle-SymbolicName: flintstones.method.flowsort.phase.alternativeinformation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort.phase.alternativeinformation +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.method.flowsort.phase.result, + flintstones.model.problemelement.service, + javax.inject, + flintstones.entity.problemelement, + flintstones.model.domain.service, + flintstones.entity.domain, + org.apache.commons.lang, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment, + flintstones.helper.data, + flintstones.valuation.numeric.real, + flintstones.model.valuation.service +Export-Package: flintstones.method.flowsort.phase.alternativeinformation diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/build.properties b/bundles/flintstones.method.flowsort.phase.alternativeinformation/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/plugin.xml b/bundles/flintstones.method.flowsort.phase.alternativeinformation/plugin.xml new file mode 100644 index 0000000..a6b7fc0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.alternativeinformation/src/flintstones/method/flowsort/phase/alternativeinformation/AlternativeFlowsortInformationModel.java b/bundles/flintstones.method.flowsort.phase.alternativeinformation/src/flintstones/method/flowsort/phase/alternativeinformation/AlternativeFlowsortInformationModel.java new file mode 100644 index 0000000..9773529 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.alternativeinformation/src/flintstones/method/flowsort/phase/alternativeinformation/AlternativeFlowsortInformationModel.java @@ -0,0 +1,137 @@ +package flintstones.method.flowsort.phase.alternativeinformation; + +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.helper.data.HashMatrix; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +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.flowsort.phase.result.AlternativeFlow; +import flintstones.method.flowsort.phase.result.Flowsort; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.numeric.real.RealValuation; + +import java.util.Arrays; +import java.util.HashMap; + +import javax.inject.Inject; +import org.apache.commons.lang.ArrayUtils; + +public class AlternativeFlowsortInformationModel extends PhaseMethod { + + Flowsort flowSort; + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + @Inject + IProfileAssignmentService assignmentService; + + @Inject + IDomainService domainService; + + Alternative[] alternatives; + Criterion[] criterions; + Expert[] experts; + + @Override + public String getName() { + return "Alternative Information"; + } + + public void execute() { + alternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + criterions = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + + int classNumber = getClasses().length; + int profileNumber = assignmentService.get(experts[0], criterions[0]).getAllProfiles().size(); + + boolean isCentralProfile = classNumber == profileNumber; + this.flowSort = new Flowsort(alternatives, criterions, getClasses(), isCentralProfile ); + + float[] p = (float[]) this.importData("arrayP"); + float[] q = (float[]) this.importData("arrayQ"); + float[] s = (float[]) this.importData("arrayS"); + float[] w = (float[]) this.importData("arrayWeights"); + int[] MinMax = (int[]) this.importData("arrayMinMax"); + int[] typeFunc = (int[]) this.importData("arrayTypeFunc"); + + this.flowSort.Execute(getValuations(experts[0]), loadLimitMatrix(), w, MinMax, typeFunc, p, q, s); + + exportData("flowsort",flowSort, true); + } + + private HashMatrix loadLimitMatrix(){ + HashMap hm = assignmentService.get(experts[0]); + +// float[][] limitMatrix = new float[allCriterion.length][hm.get(allCriterion[0]).getAllProfiles().size()]; + HashMatrix limitMatrix = new HashMatrix<>(); + +// int i = 0; + int j = 0; + for(Criterion crit: criterions) { + ProfileAssignment pa = hm.get(crit); + + for(SortingProfile profile :pa.getAllProfiles()) { + Float value = (float) profile.getValue(); + limitMatrix.put(crit, j, value); +// limitMatrix[i][j] = (float) profile.getValue(); + j++; + } +// i++; + j = 0; + } + + return limitMatrix; + } + + public HashMatrix getValuations(Expert e) { + + HashMatrix initMatrix = new HashMatrix<>(); + + for(Alternative a : alternatives) { + for(Criterion c : criterions) { + ProblemElementKey pek = new ProblemElementKey(e, a, c); + RealValuation v = (RealValuation) valuationService.getValuationFor(pek); + Float val = (float) v.getValue(); + + initMatrix.put(a, c, val ); + + } + } + return initMatrix; + } + + public Alternative[] getAlternatives() { + Alternative[] alternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + return alternatives; + + } + + public AlternativeFlow getFlowFor(Alternative a) { + return flowSort.getFlow(a); + } + + public SortingClass[] getClasses() { + + SortingClass[] classes = Arrays // + .stream(problemService.getAll(SortingClass.Type)) // + .map(k -> (SortingClass)k).toArray(SortingClass[]::new); + ArrayUtils.reverse(classes); + + return classes; + } + + +} diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/.classpath b/bundles/flintstones.method.flowsort.phase.gathering.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/.polyglot.META-INF b/bundles/flintstones.method.flowsort.phase.gathering.ui/.polyglot.META-INF new file mode 100644 index 0000000..235bdeb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort.phase.gathering.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/.project b/bundles/flintstones.method.flowsort.phase.gathering.ui/.project new file mode 100644 index 0000000..cb28f41 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort.phase.gathering.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362670 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort.phase.gathering.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..faaa9ef --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.flowsort.phase.gathering.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort.phase.gathering.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.contexts, + flintstones.model.problemelement.service, + org.eclipse.jface, + flintstones.helper.data, + flintstones.model.method.phase.service, + flintstones.entity.problemelement, + flintstones.model.ui.service, + javax.inject, + flintstones.application.perspective.framework.ui, + flintstones.entity.method.phase.ui, + flintstones.entity.method.phase, + flintstones.method.flowsort.phase.gathering, + flintstones.method.electre.phase.gathering.ui diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/build.properties b/bundles/flintstones.method.flowsort.phase.gathering.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/plugin.xml b/bundles/flintstones.method.flowsort.phase.gathering.ui/plugin.xml new file mode 100644 index 0000000..fb6c7be --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/provider/ProblemElementLabelProvider.java b/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/provider/ProblemElementLabelProvider.java new file mode 100644 index 0000000..4d5c320 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/provider/ProblemElementLabelProvider.java @@ -0,0 +1,77 @@ +package flintstones.method.flowsort.phase.gathering.provider; + +import javax.inject.Inject; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.ui.service.UiService; +import flintstones.model.ui.service.style.ForegroundStyler; + +public class ProblemElementLabelProvider extends LabelProvider implements IStyledLabelProvider { + + @Inject + IPhaseMethodService phaseService; + + /** The group image. */ + private final ImageDescriptor groupImage; + + /** The individual image. */ + private final ImageDescriptor individualImage; + + /** + * Instantiates a new problem element name label provider. + * + * @param individualImage the individual image + * @param groupImage the group image + */ + public ProblemElementLabelProvider(ImageDescriptor individualImage, ImageDescriptor groupImage) { + this.groupImage = groupImage; + this.individualImage = individualImage; + } + + @Override + public StyledString getStyledText(Object element) { + if (element instanceof ProblemElement) { + ProblemElement pe = (ProblemElement) element; + StyledString styledString; + styledString = paint(pe.getName(), ""); + + return styledString; + } + return null; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + if (element instanceof ProblemElement) { + if (((ProblemElement) element).hasChildren()) + return this.groupImage.createImage(); + + return this.individualImage.createImage(); + } + + return super.getImage(element); + } + + private StyledString paint(String leftText, String rightText) { + + Color foregroundColorLeft = UiService.COLOR_FG_NORMAL; + Color foregroundColorRight = UiService.COLOR_FG_SECONDARY; + + StyledString leftT = new StyledString(leftText, new ForegroundStyler(foregroundColorLeft)); + StyledString rightT = new StyledString(rightText, new ForegroundStyler(foregroundColorRight)); + return leftT.append(" ") + .append(rightT); + } + +} diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/ui/FlowSortData.java b/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/ui/FlowSortData.java new file mode 100644 index 0000000..f794b2d --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/ui/FlowSortData.java @@ -0,0 +1,61 @@ +package flintstones.method.flowsort.phase.gathering.ui; + +public class FlowSortData { + + int typeFunc; + int MinMax; + double p; + double q; + double s; + + public FlowSortData() { + this.p = 0.0; + this.q = 0.0; + this.s = 0.0; + this.typeFunc = 1; + } + + public int getTypeFunc() { + return typeFunc; + } + + public void setTypeFunc(int typeFunc) { + this.typeFunc = typeFunc; + this.p = 0.0; + this.q = 0.0; + this.s = 0.0; + } + + public int getMinMax() { + return MinMax; + } + + public void setMinMax(int minmax) { + this.MinMax = minmax; + } + + public double getP() { + return p; + } + + public void setP(double p) { + this.p = p; + } + + public double getQ() { + return q; + } + + public void setQ(double q) { + this.q = q; + } + + public double getS() { + return s; + } + + public void setS(double s) { + this.s = s; + } + +} diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/ui/FlowSortGatheringUI.java b/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/ui/FlowSortGatheringUI.java new file mode 100644 index 0000000..b601266 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/ui/FlowSortGatheringUI.java @@ -0,0 +1,512 @@ +package flintstones.method.flowsort.phase.gathering.ui; + +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; + +import flintstones.application.perspective.framework.ui.interfaces.IProblemElementViewerOnSingleClick; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewer; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.helper.DoubleHelper; +import flintstones.method.flowsort.phase.gathering.FlowSortGathering; +import flintstones.method.flowsort.phase.gathering.viewer.ProblemElementViewerLabel; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class FlowSortGatheringUI extends PhaseMethodUI +implements IProblemElementViewerOnSingleClick, ICheckStateListener { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + ProblemElementViewer criterionViewer; + Label titleLabelParametersCriterion; + Spinner spinnerQ; + Spinner spinnerP; + Spinner spinnerS; + + Composite rowLabelPp; + Composite rowLabelQq; + Composite rowLabelS; + + Combo comboBox; + + Composite rowTypeData; + int selectedIndex; + boolean nextPhase; + + ArrayList flowSortData; + FlowSortGathering model; + + @Override + public void init() { + model = (FlowSortGathering) this.getModel(); + model.loadData(); + + initData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 0, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText("PROMETHEE GATHERING"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9, 9, true, true); + UiService.setGridLayout(row2, 1); + + createRowImages(row2); + + initBody(row2); + + nextPhase(); + + } + + public void initData() { + selectedIndex = 0; + nextPhase = true; + flowSortData = new ArrayList(); + for (int i = 0; i < model.numberCriterions(); i++) + flowSortData.add(new FlowSortData()); + } + + public void createRowImages(Composite base) { + Composite fotoRow = new Composite(base, 0); + UiService.setGridData(fotoRow, 9, 9, true, true); + UiService.setGridLayout(fotoRow, 6, true); + + Label foto1 = new Label(fotoRow, 0); + foto1.setImage(UiService.getIcon("promethee\\promethee_type1").createImage()); + UiService.setGridData(foto1, 9, 9, true, false); + + Label foto2 = new Label(fotoRow, 0); + foto2.setImage(UiService.getIcon("promethee\\promethee_type2").createImage()); + UiService.setGridData(foto2, 9, 9, true, false); + + Label foto3 = new Label(fotoRow, 0); + foto3.setImage(UiService.getIcon("promethee\\promethee_type3").createImage()); + UiService.setGridData(foto3, 9, 9, true, false); + + Label foto4 = new Label(fotoRow, 0); + foto4.setImage(UiService.getIcon("promethee\\promethee_type4").createImage()); + UiService.setGridData(foto4, 9, 9, true, false); + + Label foto5 = new Label(fotoRow, 0); + foto5.setImage(UiService.getIcon("promethee\\promethee_type5").createImage()); + UiService.setGridData(foto5, 9, 9, true, false); + + Label foto6 = new Label(fotoRow, 0); + foto6.setImage(UiService.getIcon("promethee\\promethee_type6").createImage()); + UiService.setGridData(foto6, 9, 9, true, false); + + createTitleImages(fotoRow); + } + + public void createTitleImages(Composite base) { + + Label title1Label = new Label(base, SWT.NONE); + title1Label.setText("Type 1"); + UiService.setGridData(title1Label, 0, 9, false, false); + UiService.setFont(title1Label, UiService.FONT_SECTION_TITLE); + + Label title2Label = new Label(base, SWT.NONE); + title2Label.setText("Type 2"); + UiService.setGridData(title2Label, 0, 9, false, false); + UiService.setFont(title2Label, UiService.FONT_SECTION_TITLE); + + Label title3Label = new Label(base, SWT.NONE); + title3Label.setText("Type 3"); + UiService.setGridData(title3Label, 0, 9, false, false); + UiService.setFont(title3Label, UiService.FONT_SECTION_TITLE); + + Label title4Label = new Label(base, SWT.NONE); + title4Label.setText("Type 4"); + UiService.setGridData(title4Label, 0, 9, false, false); + UiService.setFont(title4Label, UiService.FONT_SECTION_TITLE); + + Label title5Label = new Label(base, SWT.NONE); + title5Label.setText("Type 5"); + UiService.setGridData(title5Label, 0, 9, false, false); + UiService.setFont(title5Label, UiService.FONT_SECTION_TITLE); + + Label title6Label = new Label(base, SWT.NONE); + title6Label.setText("Type 6"); + UiService.setGridData(title6Label, 0, 9, false, false); + UiService.setFont(title6Label, UiService.FONT_SECTION_TITLE); + } + + public void initBody(Composite base) { + // La otra mitad + Composite rowMitadAbajo = new Composite(base, 0); + UiService.setGridData(rowMitadAbajo, 9, 0, true, true); + UiService.setGridLayout(rowMitadAbajo, 2); + + // Criterions y datos. + createColTreeView(rowMitadAbajo); + + createColParametersFlowSort(rowMitadAbajo); + } + + // Métodos para el Tree View + private void createColTreeView(Composite base) { + + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + Label titleLabel = new Label(row, SWT.NONE); + titleLabel.setText("Criterios"); + UiService.setGridData(titleLabel, 9, 9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + // Criterion tree + criterionViewer = getViewer(row, Criterion.Type, true); + } + + // Crea los botones y spinner para poder introducir los datos del problema + private void createColParametersFlowSort(Composite base) { + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + titleLabelParametersCriterion = new Label(row, SWT.NONE); + titleLabelParametersCriterion.setText("Parametros de --------"); + UiService.setGridData(titleLabelParametersCriterion, 9, 9, true, false); + UiService.setFont(titleLabelParametersCriterion, UiService.FONT_SECTION_TITLE); + + Composite row1 = new Composite(row, SWT.BORDER); + UiService.setGridData(row1, 9, 9, true, true); + UiService.setGridLayout(row1, 1); + + comboBox = new Combo(row1, 0); + UiService.setGridData(comboBox, -1, 9, false, false); + comboBox.add("Type One"); + comboBox.add("Type Two"); + comboBox.add("Type three"); + comboBox.add("Type Four"); + comboBox.add("Type Five"); + comboBox.add("Type Six"); + comboBox.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + Combo comboBox = (Combo) e.getSource(); + + //Arrays.stream(rowTypeData.getChildren()).forEach(k -> k.dispose()); + //CreateComponentType(rowTypeData, comboBox.getSelectionIndex() + 1); + //rowTypeData.layout(); + switch(comboBox.getSelectionIndex()) { + case 0: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + break; + case 1: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(true); + rowLabelS.setVisible(false); + break; + case 2: + rowLabelPp.setVisible(true); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + break; + case 3: + case 4: + rowLabelPp.setVisible(true); + rowLabelQq.setVisible(true); + rowLabelS.setVisible(false); + break; + case 5: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(true); + break; + } + + flowSortData.get(selectedIndex).setTypeFunc(comboBox.getSelectionIndex() + 1); + setParametersSelected(); + refreshUI(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + } + }); + + rowTypeData = new Composite(row1, SWT.NONE); + UiService.setGridData(rowTypeData, 9, 9, true, true); + UiService.setGridLayout(rowTypeData, 1); + CreateComponentType(rowTypeData, 1); + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + } + + private void CreateComponentType(Composite base, int type) { + // P + rowLabelPp = new Composite(base, 0); + UiService.setGridData(rowLabelPp, 9, 9, true, false); + UiService.setGridLayout(rowLabelPp, 2, true); + Label labelPp = new Label(rowLabelPp, SWT.NONE); + labelPp.setText("P:"); + spinnerP = new Spinner(rowLabelPp, SWT.BORDER); + spinnerP.setDigits(3); + spinnerP.setMinimum(Integer.MIN_VALUE); + spinnerP.setMaximum(Integer.MAX_VALUE); + //spinnerP.addModifyListener(mdfListener); + spinnerP.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + //saveParameters(); + switch (comboBox.getSelectionIndex()) { + case 0: + flowSortData.get(selectedIndex).setP(0); + break; + default: + flowSortData.get(selectedIndex).setP(DoubleHelper.ParseDouble(spinnerP.getText())); + } + nextPhase(); + + } + }); + + // Q + rowLabelQq = new Composite(base, 0); + UiService.setGridData(rowLabelQq, 9, 9, true, false); + UiService.setGridLayout(rowLabelQq, 2, true); + Label labelQq = new Label(rowLabelQq, SWT.NONE); + labelQq.setText("Q:"); + spinnerQ = new Spinner(rowLabelQq, SWT.BORDER); + spinnerQ.setDigits(3); + spinnerQ.setMinimum(Integer.MIN_VALUE); + spinnerQ.setMaximum(Integer.MAX_VALUE); + //spinnerQ.addModifyListener(mdfListener); + spinnerQ.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + //saveParameters(); + switch (comboBox.getSelectionIndex()) { + case 0: + flowSortData.get(selectedIndex).setQ(0); + break; + default: + flowSortData.get(selectedIndex).setQ(DoubleHelper.ParseDouble(spinnerQ.getText())); + } + nextPhase(); + + } + }); + + // S + rowLabelS = new Composite(base, 0); + UiService.setGridData(rowLabelS, 9, 9, true, false); + UiService.setGridLayout(rowLabelS, 2, true); + Label labelS = new Label(rowLabelS, SWT.NONE); + labelS.setText("S:"); + spinnerS = new Spinner(rowLabelS, SWT.BORDER); + spinnerS.setDigits(3); + spinnerS.setMinimum(Integer.MIN_VALUE); + spinnerS.setMaximum(Integer.MAX_VALUE); + spinnerS.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + //saveParameters(); + switch (comboBox.getSelectionIndex()) { + case 0: + flowSortData.get(selectedIndex).setS(0); + break; + default: + flowSortData.get(selectedIndex).setS(DoubleHelper.ParseDouble(spinnerS.getText())); + } + nextPhase(); + + } + }); + } + + // Funión que nos devuelve el Viewer con los criterios + private ProblemElementViewer getViewer(Composite parent, String type, boolean addParent) { + + ProblemElementViewerLabel viewer = ContextInjectionFactory.make(ProblemElementViewerLabel.class, this.context); + + if (addParent) { + FakeProblemElement fakePE = (FakeProblemElement) ProblemElementHelper.create("", + FakeProblemElement.class.getSimpleName()); + + fakePE.as(type); + viewer.useGlobalParent(fakePE); + } + + viewer.createControls(type, parent); + viewer.addListener((IProblemElementViewerOnSingleClick) this); + viewer.loadListeners(); + + UiService.setGridLayout(viewer.getTree().getTree(), 1); + UiService.setGridData(viewer.getTree().getTree(), 9, 9, true, true); + + return viewer; + } + + // Función con la que podemos controlar el funcionamiento del click en el Viewer + public void problemElementViewerOnSingleClick(ProblemElement item) { + // Seleccionado el fake parent. + if (item.getCanonicalName().equals("")) + return; + + // Saving + saveParameters(); + + String selectedCriterion = item.getName(); + titleLabelParametersCriterion.setText("Parametros de " + selectedCriterion); + + for (int i = 0; i < model.numberCriterions(); i++) { + if (model.getCriterionNames()[i].equals(selectedCriterion)) { + selectedIndex = i; + break; + } + } + + //Changing the spinner parameters. + setParametersSelected(); + + refreshUI(); + } + + public void saveParameters() { + flowSortData.get(selectedIndex).setTypeFunc(comboBox.getSelectionIndex() + 1); + + switch (comboBox.getSelectionIndex()) { + case 0: + flowSortData.get(selectedIndex).setP(0); + flowSortData.get(selectedIndex).setQ(0); + case 1: + flowSortData.get(selectedIndex).setQ(DoubleHelper.ParseDouble(spinnerQ.getText())); + break; + case 2: + flowSortData.get(selectedIndex).setP(DoubleHelper.ParseDouble(spinnerP.getText())); + break; + case 3: + case 4: + flowSortData.get(selectedIndex).setP(DoubleHelper.ParseDouble(spinnerP.getText())); + flowSortData.get(selectedIndex).setQ(DoubleHelper.ParseDouble(spinnerQ.getText())); + break; + case 5: + flowSortData.get(selectedIndex).setS(DoubleHelper.ParseDouble(spinnerS.getText())); + break; + } + } + + private void setParametersSelected() { + comboBox.select( flowSortData.get(selectedIndex).getTypeFunc() - 1); + + spinnerP.setSelection( ChangeDoubleToInt(flowSortData.get(selectedIndex).getP(),spinnerP) ); + spinnerQ.setSelection( ChangeDoubleToInt(flowSortData.get(selectedIndex).getQ(),spinnerQ) ); + spinnerS.setSelection( ChangeDoubleToInt(flowSortData.get(selectedIndex).getS(),spinnerS) ); + + switch(comboBox.getSelectionIndex()) { + case 0: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + break; + case 1: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(true); + rowLabelS.setVisible(false); + break; + case 2: + rowLabelPp.setVisible(true); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + break; + case 3: + case 4: + rowLabelPp.setVisible(true); + rowLabelQq.setVisible(true); + rowLabelS.setVisible(false); + break; + case 5: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(true); + break; + } + } + + private int ChangeDoubleToInt(double number, Spinner spinner) { + double newNumber = number; + newNumber *= Math.pow(10, spinner.getDigits()); + return (int) newNumber; + } + + private void nextPhase() { + float[] p = new float[model.getCriterionNames().length]; + float[] q = new float[model.getCriterionNames().length]; + float[] s = new float[model.getCriterionNames().length]; + + int[] typeFunc = new int[model.getCriterionNames().length]; + + for(int i = 0; i < flowSortData.size(); i++) { + p[i] = (float) flowSortData.get(i).getP(); + q[i] = (float) flowSortData.get(i).getQ(); + s[i] = (float) flowSortData.get(i).getS(); + + typeFunc[i] = flowSortData.get(i).getTypeFunc(); + } + model.nextPhase(p, q, s, typeFunc); + + } + + public void checkStateChanged(CheckStateChangedEvent event) { + refreshUI(); + } + + public void refreshUI() { + model.loadData(); + this.sendRefresh(); + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return nextPhase; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/viewer/ProblemElementViewerLabel.java b/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/viewer/ProblemElementViewerLabel.java new file mode 100644 index 0000000..ccf6262 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering.ui/src/flintstones/method/flowsort/phase/gathering/viewer/ProblemElementViewerLabel.java @@ -0,0 +1,33 @@ +package flintstones.method.flowsort.phase.gathering.viewer; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; + +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewer; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.method.flowsort.phase.gathering.provider.ProblemElementLabelProvider; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class ProblemElementViewerLabel extends ProblemElementViewer{ + + @Inject + IProblemElementService pService; + + @Inject + IEclipseContext context; + + @Override + protected IStyledLabelProvider getLabelProvider(String type) { + ImageDescriptor individualImage = UiService.getIcon(ProblemElementHelper.getImage(type, false)); + ImageDescriptor groupImage = UiService.getIcon(ProblemElementHelper.getImage(type, false)); + + ProblemElementLabelProvider provider = new ProblemElementLabelProvider(individualImage,groupImage); + ContextInjectionFactory.inject(provider, context); + return provider; + } +} diff --git a/bundles/flintstones.method.flowsort.phase.gathering/.classpath b/bundles/flintstones.method.flowsort.phase.gathering/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.gathering/.polyglot.META-INF b/bundles/flintstones.method.flowsort.phase.gathering/.polyglot.META-INF new file mode 100644 index 0000000..cf628d7 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort.phase.gathering + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Gathering + diff --git a/bundles/flintstones.method.flowsort.phase.gathering/.project b/bundles/flintstones.method.flowsort.phase.gathering/.project new file mode 100644 index 0000000..4462df9 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort.phase.gathering + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362669 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort.phase.gathering/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort.phase.gathering/META-INF/MANIFEST.MF new file mode 100644 index 0000000..86ec1b6 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Gathering +Bundle-SymbolicName: flintstones.method.flowsort.phase.gathering;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort.phase.gathering +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.model.problemelement.service, + flintstones.entity.problemelement, + flintstones.helper.data, + javax.inject, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment +Export-Package: flintstones.method.flowsort.phase.gathering diff --git a/bundles/flintstones.method.flowsort.phase.gathering/build.properties b/bundles/flintstones.method.flowsort.phase.gathering/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort.phase.gathering/plugin.xml b/bundles/flintstones.method.flowsort.phase.gathering/plugin.xml new file mode 100644 index 0000000..de33f81 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.gathering/src/flintstones/method/flowsort/phase/gathering/FlowSortGathering.java b/bundles/flintstones.method.flowsort.phase.gathering/src/flintstones/method/flowsort/phase/gathering/FlowSortGathering.java new file mode 100644 index 0000000..94c883b --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.gathering/src/flintstones/method/flowsort/phase/gathering/FlowSortGathering.java @@ -0,0 +1,99 @@ +package flintstones.method.flowsort.phase.gathering; + +import javax.inject.Inject; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public class FlowSortGathering extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + Alternative[] allAlternatives; + Criterion[] allCriterion; + Expert[] Allexperts; + + float[] p; + float[] q; + float[] s; + int[] typeFunc; + + HashMatrix weights; + + public FlowSortGathering() { + } + + @Override + public String getName() { + return "Phase FlowSort Gathering"; + } + + @SuppressWarnings("unchecked") + public void loadData() { + ProblemElement[] pes = problemService.getAll(Alternative.Type); + allAlternatives = ProblemElementHelper.asAlternatives(pes); + + pes = problemService.getAll(Criterion.Type); + allCriterion = ProblemElementHelper.asCriterions(pes); + + pes = problemService.getAll(Expert.Type); + Allexperts = ProblemElementHelper.asExperts(pes); + + weights = (HashMatrix) this.importData("criterionWeights"); + } + + public void nextPhase(float[] p, float[] q, float[] s, int[] typeFunc) { + //Export the data. + int[] MinMax = new int[allCriterion.length]; + float[] ws = new float[allCriterion.length]; + double w; + + for(int i = 0; i < allCriterion.length; i++) { + MinMax[i] = (allCriterion[i].isCost()) ? 0 : 1; + w = weights.get(Allexperts[0], allCriterion[i]); + ws[i] = (float) w; + } + + this.p = p; + this.q = q; + this.s = s; + this.typeFunc = typeFunc; + + this.exportData("arrayP", this.p); + this.exportData("arrayQ", this.q); + this.exportData("arrayS", this.s); + this.exportData("arrayWeights", ws); + this.exportData("arrayMinMax", MinMax); + this.exportData("arrayTypeFunc", this.typeFunc); + } + + public String[] getAlternativesNames() { + String[] str = new String[allAlternatives.length]; + + for(int i = 0; i < allAlternatives.length; i++) + str[i] = allAlternatives[i].getName(); + + return str; + } + + public String[] getCriterionNames() { + String[] str = new String[allCriterion.length]; + + for(int i = 0; i < allCriterion.length; i++) + str[i] = allCriterion[i].getName(); + + + return str; + } + + public int numberCriterions() { + return allCriterion.length; + } + +} diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/.classpath b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/.polyglot.META-INF b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.polyglot.META-INF new file mode 100644 index 0000000..ae0f61a --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort.phase.globalresult.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/.project b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.project new file mode 100644 index 0000000..888740d --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort.phase.globalresult.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362671 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort.phase.globalresult.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c9abbb3 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.flowsort.phase.globalresult.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort.phase.globalresult.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.method.flowsort.phase.globalresult, + flintstones.entity.method.phase, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.helper.html diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/build.properties b/bundles/flintstones.method.flowsort.phase.globalresult.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/plugin.xml b/bundles/flintstones.method.flowsort.phase.globalresult.ui/plugin.xml new file mode 100644 index 0000000..6b75909 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.globalresult.ui/src/flintstones/method/flowsort/phase/globalresult/ui/FlowsortGlobalResultUI.java b/bundles/flintstones.method.flowsort.phase.globalresult.ui/src/flintstones/method/flowsort/phase/globalresult/ui/FlowsortGlobalResultUI.java new file mode 100644 index 0000000..25fe2d6 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult.ui/src/flintstones/method/flowsort/phase/globalresult/ui/FlowsortGlobalResultUI.java @@ -0,0 +1,47 @@ +package flintstones.method.flowsort.phase.globalresult.ui; + + import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.flowsort.phase.globalresult.FlowsortGlobalResultModel; +import flintstones.model.ui.service.UiService; +import org.eclipse.swt.widgets.Composite; + +public class FlowsortGlobalResultUI extends PhaseMethodUI { + + FlowsortGlobalResultModel model; + + @Override + public void init() { + + model = (FlowsortGlobalResultModel) getModel(); + model.execute(); + + Composite parent = getBaseComposite(); + UiService.setGridLayout(parent, 1); + UiService.setGridDataAuto(parent); + create(parent); + } + + private void create(Composite base) { + + String[] hHeaders = new String[] {"Alternative","class", "+","-","="}; + String[][] tableContent = model.getTable(); + + HtmlTextTable table = new HtmlTextTable(base, tableContent, hHeaders); + table.render(); + + } + + @Override + public void refresh() { + // TODO Auto-generated method stub + + } + + @Override + protected boolean isForwardEnabled() { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/.classpath b/bundles/flintstones.method.flowsort.phase.globalresult/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/.polyglot.META-INF b/bundles/flintstones.method.flowsort.phase.globalresult/.polyglot.META-INF new file mode 100644 index 0000000..d9a073f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort.phase.globalresult + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Globalresult + diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/.project b/bundles/flintstones.method.flowsort.phase.globalresult/.project new file mode 100644 index 0000000..5624e3e --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort.phase.globalresult + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362671 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort.phase.globalresult/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b2c9f2e --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Globalresult +Bundle-SymbolicName: flintstones.method.flowsort.phase.globalresult;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort.phase.globalresult +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.method.flowsort.phase.result, + flintstones.model.problemelement.service, + javax.inject, + flintstones.entity.problemelement, + flintstones.helper.data +Export-Package: flintstones.method.flowsort.phase.globalresult diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/build.properties b/bundles/flintstones.method.flowsort.phase.globalresult/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/plugin.xml b/bundles/flintstones.method.flowsort.phase.globalresult/plugin.xml new file mode 100644 index 0000000..84cb1b6 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.globalresult/src/flintstones/method/flowsort/phase/globalresult/FlowsortGlobalResultModel.java b/bundles/flintstones.method.flowsort.phase.globalresult/src/flintstones/method/flowsort/phase/globalresult/FlowsortGlobalResultModel.java new file mode 100644 index 0000000..cd076c9 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.globalresult/src/flintstones/method/flowsort/phase/globalresult/FlowsortGlobalResultModel.java @@ -0,0 +1,72 @@ +package flintstones.method.flowsort.phase.globalresult; + +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.helper.DoubleHelper; +import flintstones.method.flowsort.phase.result.AlternativeFlow; +import flintstones.method.flowsort.phase.result.Flowsort; +import flintstones.model.problemelement.service.IProblemElementService; + +public class FlowsortGlobalResultModel extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + Flowsort flowSort; + + HashMap alternativesFlows = new HashMap<>(); + + + @Override + public String getName() { + return "Global Result"; + } + + public void execute() { + + flowSort = (Flowsort) importData("flowsort"); + alternativesFlows = flowSort.getFlows(); + +// String[] alternativeNames = (String[]) importData("alternativeNames"); +// String[] criterionNames = (String[]) importData("criterionNames"); +// +// for(int i = 0; i < alternativeNames.length; i++) +// alternativeIndexCache.put(alternativeNames[i],i); +// +// for(int i = 0; i < criterionNames.length; i++) +// criterionIndexCache.put(criterionNames[i],i); + + } + + public String[][] getTable(){ + + String[][] tableContent = new String[alternativesFlows.keySet().size()][5]; + + int row = 0; + for(Entry entry : alternativesFlows.entrySet()) { + + tableContent[row][0] = entry.getKey().getName(); + tableContent[row][1] = entry.getValue().getClassFlow(); + tableContent[row][2] = DoubleHelper.Draw(entry.getValue().getPositiveFlow()); + tableContent[row][3] = DoubleHelper.Draw(entry.getValue().getNegativeFlow()); + tableContent[row][4] = DoubleHelper.Draw(entry.getValue().getNeutralFlow()); + row++; + } + + return tableContent; + + } + + +// public float getPositiveFlow(String a) { +// +// int index = alternativeIndexCache.get(a); +// return flowSort.getMatrixFlowPositive(index); +// } + +} diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/.classpath b/bundles/flintstones.method.flowsort.phase.result.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/.polyglot.META-INF b/bundles/flintstones.method.flowsort.phase.result.ui/.polyglot.META-INF new file mode 100644 index 0000000..e4900f4 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort.phase.result.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/.project b/bundles/flintstones.method.flowsort.phase.result.ui/.project new file mode 100644 index 0000000..b35d7f0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort.phase.result.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362672 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort.phase.result.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0cc09d7 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.flowsort.phase.result.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort.phase.result.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.swt, + flintstones.helper.html, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.method.flowsort.phase.result, + org.jfree.chart.jfreechart, + flintstones.entity.problemelement, + flintstones.entity.problemelement.ui diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/build.properties b/bundles/flintstones.method.flowsort.phase.result.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/plugin.xml b/bundles/flintstones.method.flowsort.phase.result.ui/plugin.xml new file mode 100644 index 0000000..c93a1b2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.result.ui/src/flintstones/method/flowsort/phase/result/ui/FlowSortResultUI.java b/bundles/flintstones.method.flowsort.phase.result.ui/src/flintstones/method/flowsort/phase/result/ui/FlowSortResultUI.java new file mode 100644 index 0000000..8816498 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result.ui/src/flintstones/method/flowsort/phase/result/ui/FlowSortResultUI.java @@ -0,0 +1,227 @@ +package flintstones.method.flowsort.phase.result.ui; + +import java.awt.Color; +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.plot.XYPlot; +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.chart.swt.ChartComposite; +import org.jfree.data.xy.XYDataset; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.ui.widget.ProblemElementSelector; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.flowsort.phase.result.FlowSortResult; +import flintstones.model.ui.service.UiService; + +public class FlowSortResultUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + Composite rowTable; + Composite rowMitadAbajo; + HtmlTextTable table; + ProblemElementSelector comboBox; +// Combo comboBox; + + Alternative alternativeSelected; + + FlowSortResult model; + String[] rowHeaderResult; + + public void init() { + model = (FlowSortResult) this.getModel(); + model.cargarDatos(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 9, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText("PROMETHEE RESULT"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9, 9, true, false); + UiService.setGridLayout(row2, 1); + + Alternative[] alternativeNames = model.getAlternatives(); + + comboBox = new ProblemElementSelector(row2, alternativeNames); + comboBox.setListener(new IProblemElementChangedListener() { + + @Override + public void problemElementChanged(ProblemElement pe) { + alternativeSelected = (Alternative) pe; + refreshUI(); + } + }); + +// UiService.setGridData(comboBox, -1, 9, false, false); +// for(int i = 0; i < alternativeNames.length; i++) +// comboBox.add(alternativeNames[i]); + +// comboBox.select(0); +// comboBox.addSelectionListener(new SelectionListener() { +// +// @Override +// public void widgetSelected(SelectionEvent e) { +// Combo combo = (Combo)e.getSource(); +// alternativeSelected = combo.getSelectionIndex(); +// refreshUI(); +// } +// +// @Override +// public void widgetDefaultSelected(SelectionEvent e) { +// // TODO Auto-generated method stub +// } +// }); + + rowTable = new Composite(row2, 0); + UiService.setGridData(rowTable, 9, 9, true, true); + UiService.setGridLayout(rowTable, 1); + + //tableRender(rowTable, model.get, model.getAlternativesNames(), model.getRowHeaderFlowSort()); + + rowMitadAbajo = new Composite(base, 0); + UiService.setGridData(rowMitadAbajo, 9, 9, true, true); + UiService.setGridLayout(rowMitadAbajo, 1); + + alternativeSelected = (Alternative) comboBox.getSelectedElement(); + charRender(rowMitadAbajo); + + } + + void charRender(Composite row) { + final XYDataset dataset = createDataset(alternativeSelected); + final JFreeChart chart = createChart(dataset, Color.white); + ChartComposite chartComposite = new ChartComposite(row, 1, chart); + UiService.setGridData(chartComposite, 9, 9, true, true); + } + + //Tabla con el resultado final + public void tableRender(Composite base, float[][] values, String[] colHeader, String[] rowHeader) { + String[][] valuesSTR = new String [colHeader.length][rowHeader.length]; + + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) { + valuesSTR[i][j] = "" + values[i][j]; + } + } + + table = new HtmlTextTable(base, valuesSTR, rowHeader, colHeader); + table.render(); + } + + public void refreshUI() { + Arrays.stream(rowMitadAbajo.getChildren()).forEach(k -> k.dispose()); + model.cargarDatos(); + + charRender(rowMitadAbajo); + + //table.render(); + rowMitadAbajo.layout(); + this.sendRefresh(); + } + + @Override + public void refresh() { + refreshUI(); + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + //--------------------------------------------- + //Funciones para JFreeChar + private XYDataset createDataset(Alternative alternative) { + + final XYSeriesCollection dataset = new XYSeriesCollection(); + + final XYSeries alt = new XYSeries("Perfiles límite"); + + Float[] positive = model.getMatrixFlowPositive(alternative); + Float[] negative = model.getMatrixFlowNegative(alternative); + for(int i = 0; i < positive.length; i++){ + alt.add(positive[i], negative[i]); + } + /*alt.add(1.0, 0.0); + alt.add(0.8, 0.2); + alt.add(0.48, 0.52); + alt.add(0.24, 0.76); + alt.add(0.0, 1.0);*/ + + final XYSeries alt1 = new XYSeries("Alternativa"); + float[] value = model.getValueAlternative(alternative); + alt1.add(value[0], value[1]); + //alt1.add(0.0, 0.0); + //alt1.add(0.48, 0.52); + + dataset.addSeries(alt1); + dataset.addSeries(alt); + + return dataset; + } + + private JFreeChart createChart(final XYDataset dataset, Color backgroundColor) { + + // create the chart... + final JFreeChart chart = ChartFactory.createXYLineChart( + "", // chart title + "Theta", // x axis label + "Position", // y axis label + dataset, // data + PlotOrientation.VERTICAL, + true, // include legend + false, // tooltips + false // urls + ); + + // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... + chart.setBackgroundPaint(backgroundColor); + + //get a reference to the plot for further customisation... + final XYPlot plot = chart.getXYPlot(); + plot.setBackgroundPaint(Color.white); + plot.setDomainGridlinePaint(Color.black); + plot.setRangeGridlinePaint(Color.black); + + + final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); + plot.setRenderer(renderer); + renderer.setSeriesLinesVisible(0, false); + renderer.setSeriesLinesVisible(1, true); + + // change the auto tick unit selection to integer units only... + final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); + rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); + // OPTIONAL CUSTOMISATION COMPLETED. + + return chart; + } + +} + diff --git a/bundles/flintstones.method.flowsort.phase.result/.classpath b/bundles/flintstones.method.flowsort.phase.result/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.result/.polyglot.META-INF b/bundles/flintstones.method.flowsort.phase.result/.polyglot.META-INF new file mode 100644 index 0000000..a2b409f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort.phase.result + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Result + diff --git a/bundles/flintstones.method.flowsort.phase.result/.project b/bundles/flintstones.method.flowsort.phase.result/.project new file mode 100644 index 0000000..7964ad8 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort.phase.result + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362672 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort.phase.result/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort.phase.result/META-INF/MANIFEST.MF new file mode 100644 index 0000000..15a3c4e --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Result +Bundle-SymbolicName: flintstones.method.flowsort.phase.result;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort.phase.result +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.model.problemelement.service, + flintstones.model.valuation.service, + flintstones.entity.valuation, + flintstones.entity.problemelement, + flintstones.valuation.numeric, + javax.inject, + flintstones.valuation.numeric.real, + flintstones.entity.ahpsort.profileassignment, + flintstones.model.ahpsort.profileassignment.service, + javax.annotation, + flintstones.helper.data, + flintstones.model.domain.service, + org.apache.commons.lang, + flintstones.helper.data, + flintstones.model.domain.service, + org.apache.commons.lang +Export-Package: flintstones.method.flowsort.phase.result diff --git a/bundles/flintstones.method.flowsort.phase.result/build.properties b/bundles/flintstones.method.flowsort.phase.result/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort.phase.result/plugin.xml b/bundles/flintstones.method.flowsort.phase.result/plugin.xml new file mode 100644 index 0000000..14685aa --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/AlternativeFlow.java b/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/AlternativeFlow.java new file mode 100644 index 0000000..0f2adc0 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/AlternativeFlow.java @@ -0,0 +1,52 @@ +package flintstones.method.flowsort.phase.result; + +import java.util.Arrays; + +import flintstones.entity.problemelement.entities.Alternative; + +public class AlternativeFlow { + + Alternative alternative; + + double[] positiveFlows; + double[] negativeFlows; + + double positiveFlow; + double negativeFlow; + String classFlow; + + public AlternativeFlow(Alternative a, String classFlow, Float[] positiveFlows, Float[] negativeFlows, float[] alternativeFlow) { + + this.alternative = a; + this.positiveFlows = Arrays.stream(positiveFlows).mapToDouble(Float::doubleValue).toArray(); + this.negativeFlows = Arrays.stream(negativeFlows).mapToDouble(Float::doubleValue).toArray(); + + positiveFlow = Arrays.stream(positiveFlows).mapToDouble(Float::doubleValue).sum(); + negativeFlow = Arrays.stream(negativeFlows).mapToDouble(Float::doubleValue).sum(); + positiveFlow = alternativeFlow[0]; + negativeFlow = alternativeFlow[1]; + this.classFlow = classFlow; + } + + public double getPositiveFlow() { return positiveFlow; } + public double getNegativeFlow() { return negativeFlow; } + public double getNeutralFlow() { return positiveFlow - negativeFlow; } + public String getClassFlow() { return classFlow; } + public double[] getPositiveFlows() { return positiveFlows; } + public double[] getNegativeFlows() { return negativeFlows; } + + public Alternative getAlternative() {return alternative;} + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + String a = alternative.getName() + " +"+positiveFlow+" -"+negativeFlow+" ="+getNeutralFlow(); + String b = Arrays.toString(positiveFlows); + String c = Arrays.toString(negativeFlows); + + sb.append(a).append("\n").append(b).append("\n").append(c); + return sb.toString(); + } + +} diff --git a/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/FlowSortResult.java b/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/FlowSortResult.java new file mode 100644 index 0000000..dd51bdd --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/FlowSortResult.java @@ -0,0 +1,186 @@ +package flintstones.method.flowsort.phase.result; + +import java.util.Arrays; +import java.util.HashMap; +import javax.inject.Inject; + +import org.apache.commons.lang.ArrayUtils; + +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +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.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.numeric.real.RealValuation; + +public class FlowSortResult extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + @Inject + IProfileAssignmentService assignmentService; + + @Inject + IDomainService domainService; + + // Atributos + HashMap mapVAluations; + Alternative[] alternatives; + Criterion[] criterions; + Expert[] experts; + String[] rowHeaderFlowSortResult; + + Flowsort flowsort; + float[] weights; +// float[][] vaslues; + int[] MinMax; + + public FlowSortResult() { + } + + @Override + public String getName() { + return "Phase FlowSort Result"; + } + + //------------------------------- GETS AND SETTERS --------------------------------- + public void cargarDatos() { + rowHeaderFlowSortResult = new String[3]; + rowHeaderFlowSortResult[0] = "Positive Flow"; + rowHeaderFlowSortResult[1] = "Negative Flow"; + rowHeaderFlowSortResult[2] = "Neto Flow"; + + alternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + criterions = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + experts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + +// AHPSortIIDomain domain = (AHPSortIIDomain) domainService.getAll()[0]; + int classNumber = getClasses().length; + int profileNumber = assignmentService.get(experts[0], criterions[0]).getAllProfiles().size(); + + boolean isCentralProfile = classNumber == profileNumber; + flowsort = new Flowsort(alternatives, criterions, getClasses(), isCentralProfile ); + + float[] p = (float[]) this.importData("arrayP"); + float[] q = (float[]) this.importData("arrayQ"); + float[] s = (float[]) this.importData("arrayS"); + float[] w = (float[]) this.importData("arrayWeights"); + int[] MinMax = (int[]) this.importData("arrayMinMax"); + int[] typeFunc = (int[]) this.importData("arrayTypeFunc"); + + this.flowsort.Execute(getValuations(experts[0]), loadLimitMatrix(), w, MinMax, typeFunc, p, q, s); + + exportData("flowsort",flowsort, true); + + } + + private HashMatrix loadLimitMatrix(){ + HashMap hm = assignmentService.get(experts[0]); + +// float[][] limitMatrix = new float[allCriterion.length][hm.get(allCriterion[0]).getAllProfiles().size()]; + HashMatrix limitMatrix = new HashMatrix<>(); + +// int i = 0; + int j = 0; + for(Criterion crit: criterions) { + ProfileAssignment pa = hm.get(crit); + + for(SortingProfile profile :pa.getAllProfiles()) { + Float value = (float) profile.getValue(); + limitMatrix.put(crit, j, value); +// limitMatrix[i][j] = (float) profile.getValue(); + j++; + } +// i++; + j = 0; + } + + return limitMatrix; + } + + public HashMatrix getValuations(Expert e) { + + HashMatrix initMatrix = new HashMatrix<>(); + + for(Alternative a : alternatives) { + for(Criterion c : criterions) { + ProblemElementKey pek = new ProblemElementKey(e, a, c); + RealValuation v = (RealValuation) valuationService.getValuationFor(pek); + Float val = (float) v.getValue(); + + initMatrix.put(a, c, val ); + + } + } + return initMatrix; + } + + public SortingClass[] getClasses() { + + SortingClass[] classes = Arrays // + .stream(problemService.getAll(SortingClass.Type)) // + .map(k -> (SortingClass)k).toArray(SortingClass[]::new); + + ArrayUtils.reverse(classes); + return classes; + } + + public float[] getValueAlternative(Alternative alternative) { + return flowsort.getValueAlternative(alternative); + } + + public Float[] getMatrixFlowPositive(Alternative alternative){ + return flowsort.getMatrixFlowPositive(alternative); + } + + public Float[] getMatrixFlowNegative(Alternative alternative){ + return flowsort.getMatrixFlowNegative(alternative); + } + + + public String[] getRowHeaderFlowSort() { + return rowHeaderFlowSortResult; + } + + public Alternative[] getAlternatives() { + return alternatives; + } + + public String[] getAlternativesNames() { + String[] str = new String[alternatives.length]; + + for(int i = 0; i < alternatives.length; i++) + str[i] = alternatives[i].getName(); + + return str; + } + + public String[] getCriterionNames() { + String[] str = new String[criterions.length]; + + for(int i = 0; i < criterions.length; i++) { + str[i] = criterions[i].getName(); + } + + return str; + } + + public int numberCriterions() { + return criterions.length; + } +} + diff --git a/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/Flowsort.java b/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/Flowsort.java new file mode 100644 index 0000000..5f9b654 --- /dev/null +++ b/bundles/flintstones.method.flowsort.phase.result/src/flintstones/method/flowsort/phase/result/Flowsort.java @@ -0,0 +1,375 @@ +package flintstones.method.flowsort.phase.result; + +import java.util.HashMap; + +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.helper.data.HashMatrix; + +public class Flowsort { + + //----------------- DATOS INICIALES DEL PROBLEMA ---------------------- + HashMatrix initMatrix; + HashMatrix limitMatrix; + int[] MinMax; //0 --> Min || 1 --> Max + float[] weights; + int[] typeFunc; + + Alternative[] alternatives; + Criterion[] criterions; + SortingClass[] classFlow; + + boolean isCentralClass = false; + + float[] p; + float[] q; + float[] s; + + //--------------------- VARIABLES INTERNAS ---------------------------- + HashMatrix preferencesDegreesPositive; + HashMatrix preferencesDegreesNegative; + + HashMap flowMatrixPositive; + HashMap flowMatrixNegative; + + float[][] globalFlowMatrix; + + // CACHE + HashMap alternativeFlows = new HashMap<>(); + + public Flowsort(Alternative[] alternatives, Criterion[] criterions, SortingClass[] classFlow, boolean isCentralClass) { + this.alternatives = alternatives; + this.criterions = criterions; + this.classFlow = classFlow; + this.isCentralClass = isCentralClass; + } + + public Float[] getMatrixFlowPositive(Alternative indexCriterion){ + return flowMatrixPositive.get(indexCriterion); + } + + public Float[] getMatrixFlowNegative(Alternative indexCriterion){ + return flowMatrixNegative.get(indexCriterion); + } + + public float[] getValueAlternative(Alternative index) { + float[] value = new float[2]; + value[0] = 0.0f; + value[1] = 0.0f; + + float positive = 0.0f; + float negative = 0.0f; + + for(int r = 0; r < preferencesDegreesPositive.get(index).size(); r++) { + + for(int i = 0; i < preferencesDegreesPositive.get(index).get(r).length; i++) { + + positive += preferencesDegreesPositive.get(index).get(r)[i][0]; + negative += preferencesDegreesNegative.get(index).get(r)[i][0]; + } + + value[1] += negative / preferencesDegreesPositive.get(index).size(); + value[0] += positive / preferencesDegreesNegative.get(index).size(); + + positive = 0.0f; + negative = 0.0f; + } + + return value; + } + + //Classify values + public String getClassFlow(Alternative alt, double positive, double negative) { + int indexPositive = -1, indexNegative = -1, indexNeutral = -1; + Float[] flowPositive = flowMatrixPositive.get(alt); + Float[] flowNegative = flowMatrixNegative.get(alt); + + if(isCentralClass) { + //Flow positive + for(int i = 1; i < flowPositive.length - 1; i++) { + if(((flowPositive[i] + flowPositive[i + 1] / 2)) < positive + && positive <= ((flowPositive[i] + flowPositive[i - 1] / 2))) { + indexPositive = i; + break; + } + } + + //Flow negative + for(int i = 1; i < flowNegative.length - 1; i++) { + if(((flowNegative[i] + flowNegative[i + 1] / 2)) >= positive + && positive > ((flowNegative[i] + flowNegative[i - 1] / 2))) { + indexNegative = i; + break; + } + } + + if(indexPositive == -1) indexPositive = flowPositive.length - 1; + if(indexNegative == -1) indexNegative = flowNegative.length - 1; + + }else { + //Flow positive + for(int i = 0; i < flowPositive.length - 1; i++) { + if(flowPositive[i] >= positive && positive > flowPositive[i + 1]) { + indexPositive = i; + break; + } + } + + //Flow negative + for(int i = 0; i < flowNegative.length - 1; i++) { + if(flowNegative[i] < positive && positive <= flowNegative[i + 1]) { + indexNegative = i; + break; + } + } + + if(indexPositive == -1) indexPositive = flowPositive.length - 1; + if(indexNegative == -1) indexNegative = flowNegative.length - 1; + + } + + //We use the neutral values. + if(indexPositive != indexNegative) { + + double neutral = positive - negative; + for(int i = 0; i < flowNegative.length - 1; i++) { + if((flowPositive[i] - flowNegative[i]) >= neutral && neutral > (flowPositive[i + 1] - flowNegative[i + 1])) { + indexNeutral = i; + break; + } + } + + if(indexNeutral == -1) indexNeutral = flowPositive.length - 1; + + return classFlow[(classFlow.length - 1) - indexNeutral].getName(); + } + + //Return the class. + return classFlow[(classFlow.length - 1) - indexPositive].getName(); + } + + public float[][] getGlobalFLow(){ + return globalFlowMatrix; + } + + public void init() { + + preferencesDegreesPositive = new HashMatrix<>(); + preferencesDegreesNegative = new HashMatrix<>(); + + flowMatrixPositive = new HashMap<>(); + flowMatrixNegative = new HashMap<>(); + + for (int i = 0; i < alternatives.length; i++) { + + Alternative alternative = alternatives[i]; + int size = limitMatrix.size(); + int innerSize = limitMatrix.innerSize(); + + flowMatrixPositive.put(alternative, new Float[innerSize] ); + flowMatrixNegative.put(alternative, new Float[innerSize] ); + + //Inicializamos el vector de matrices para cada criterio enfrentando alternativas con alternativas. + for (int j = 0; j < innerSize; j++) { + preferencesDegreesPositive.put(alternative, j, new Float[size][innerSize]); + preferencesDegreesNegative.put(alternative, j, new Float[size][innerSize]); + } + + + } + } + + public void Execute( + HashMatrix initMatrix, // Valuations + HashMatrix limitMatrix, // ?? + float[] weights, + int[] MinMax, + int[] typeFunc, float[] p, float[] q, float[] s) { + this.typeFunc = typeFunc; + this.initMatrix = initMatrix; + this.limitMatrix = limitMatrix; + this.weights = weights; + this.MinMax = MinMax; + + init(); + //Iniciamos los valores + this.p = p; + this.q = q; + this.s = s; + + //Calculamos las matrices. + calculatePreferencesPositive(); + + /* + System.out.println(); + System.out.println(); + System.out.println(); + for (int R = 0; R < preferencesDegreesPositive.size(); R++) { + Alternative aR = alternatives[R]; + for (int iCriterion = 0; iCriterion < preferencesDegreesPositive.get(aR).size(); iCriterion++) { + System.out.println(); + System.out.println("---------------------- R " + (iCriterion + 1) + "------------------------"); + for (int iAlternative = 0; iAlternative < preferencesDegreesPositive.get(aR).get(iCriterion).length; iAlternative++) { + for (int jAlternative = 0; jAlternative < preferencesDegreesPositive.get(aR).get(iCriterion)[iAlternative].length; jAlternative++) { + System.out.print(preferencesDegreesPositive.get(aR).get(iCriterion)[iAlternative][jAlternative] + " "); + } + System.out.println(); + } + System.out.println("----------------------------------------------"); + System.out.println(); + } + } + + + System.out.println(); + System.out.println("---------------------- R Flows Positive------------------------"); + for (int i = 0; i < flowMatrixPositive.size(); i++) { + Alternative ai = alternatives[i]; + + for (int j = 0; j < flowMatrixPositive.get(ai).length; j++) { + System.out.print(flowMatrixPositive.get(ai)[j] + " "); + } + System.out.println(); + } + System.out.println("----------------------------------------------"); + System.out.println(); + + System.out.println(); + System.out.println("---------------------- R Flows Negative------------------------"); + for (int i = 0; i < flowMatrixNegative.size(); i++) { + Alternative ai = alternatives[i]; + + for (int j = 0; j < flowMatrixNegative.get(ai).length; j++) { + System.out.print(flowMatrixNegative.get(ai)[j] + " "); + } + System.out.println(); + } + System.out.println("----------------------------------------------"); + System.out.println(); + */ + + + // CACHE + alternativeFlows.clear(); + for (int i = 0; i < flowMatrixNegative.size(); i++) { + Alternative ai = alternatives[i]; + String flowClass = getClassFlow(ai, getValueAlternative(ai)[0], getValueAlternative(ai)[1]); + AlternativeFlow aflow = new AlternativeFlow(ai, flowClass, flowMatrixPositive.get(ai), flowMatrixNegative.get(ai), getValueAlternative(ai)); + alternativeFlows.put(ai, aflow); + } + } + + public AlternativeFlow getFlow(Alternative a) {return alternativeFlows.get(a);} + public HashMap getFlows(){return alternativeFlows;} + + //Calcula las matrices de preferencia según la función especificada. + private void calculatePreferencesPositive() { + float dPositive = 0.0f; + float dNegative = 0.0f; + int indexri = 0; + int indexJ = 0; + float colFlowPositive = 0.0f; + float rowFlowPositive = 0.0f; + float colFlowNegative = 0.0f; + float rowFlowNegative = 0.0f; + + for (int R = 0; R < preferencesDegreesPositive.size(); R++) { + Alternative aR = alternatives[R]; + + System.out.println("R "+ R); + //Nos recorremos los criteros para calcular cada matriz + for (int r = 0; r < preferencesDegreesPositive.get(aR).size(); r++) { + + System.out.println("r " + r); + if(r == 5) { + System.out.println("r " + r); + } + //Enfrentamos las alternativas según el criterio (iCriterion) que estamos calculando. + for (int i = 0; i < preferencesDegreesPositive.get(aR).get(r).length; i++) { + Criterion ci = criterions[i]; + + for (int j = 0; j < preferencesDegreesPositive.get(aR).get(r)[i].length; j++) { + + if (j == 0) { + dPositive = limitMatrix.get(ci, r) - initMatrix.get(aR,ci); + dNegative = initMatrix.get(aR,ci) - limitMatrix.get(ci, r); + + } else { + if (indexri == indexJ) { + indexJ++; + } + + dPositive = limitMatrix.get(ci,r) - limitMatrix.get(ci, indexJ); + dNegative = limitMatrix.get(ci, indexJ) - limitMatrix.get(ci,r); + + indexJ++; + } + + //preferencesDegreesPositive.get(R).get(r)[i][j] = getResultFunction(dPositive, i); + //preferencesDegreesNegative.get(R).get(r)[i][j] = getResultFunction(dNegative, i); + preferencesDegreesPositive.get(aR).get(r)[i][j] = getResultFunction(dPositive, i) * weights[i]; //Equation: 1.a + preferencesDegreesNegative.get(aR).get(r)[i][j] = getResultFunction(dNegative, i) * weights[i]; //Equation: 1.b + colFlowPositive += preferencesDegreesPositive.get(aR).get(r)[i][j]; + colFlowNegative += preferencesDegreesNegative.get(aR).get(r)[i][j]; + + } + indexJ = 0; + rowFlowPositive += colFlowPositive / preferencesDegreesPositive.get(aR).size(); + rowFlowNegative += colFlowNegative / preferencesDegreesNegative.get(aR).size(); + //rowFlowPositive += colFlowPositive; + //rowFlowNegative += colFlowNegative; + colFlowPositive = 0.0f; + colFlowNegative = 0.0f; + } + indexri++; + +// flowMatrixPositive.get(aR)[r] = rowFlowPositive / preferencesDegreesPositive.get(aR).size(); //Equation: 2 +// flowMatrixNegative.get(aR)[r] = rowFlowNegative / preferencesDegreesNegative.get(aR).size(); //Equation: 3 + flowMatrixPositive.get(aR)[r] = rowFlowPositive; //Equation: 2 + flowMatrixNegative.get(aR)[r] = rowFlowNegative; //Equation: 3 + rowFlowPositive = 0.0f; + rowFlowNegative = 0.0f; + } + indexri = 0; + } + } + + //Según la función especificada, te devuelve el valor P(d) correspondiente + private float getResultFunction(float d, int iCriterion) { + switch (typeFunc[iCriterion]) { + case 1: + if(d > 0 ) return 1; + else return 0; + case 2: + if(d > q[iCriterion] ) return 1; + else return 0; + case 3: + if(d > p[iCriterion] ) return 1; + else if (d <= 0) return 0; + else return d / p[iCriterion]; + case 4: + if(d > p[iCriterion] ) return 1; + else if (d <= q[iCriterion]) return 0; + else return 1/2; + case 5: + if (d <= q[iCriterion]) { + return 0.0f; + } else if (d > p[iCriterion]) { + return 1.0f; + } else { + return ((d - q[iCriterion]) / (p[iCriterion] - q[iCriterion])); + } + case 6: + if(d <= 0 ) return 0; + else { + float exponentialFunc = (float) java.lang.Math.exp((-1) * (Math.pow(d, 2) / (2 * Math.pow(s[iCriterion], 2)))); + return 1 - exponentialFunc; + } + } + + return -1; + } + +} + diff --git a/bundles/flintstones.method.flowsort/.classpath b/bundles/flintstones.method.flowsort/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.flowsort/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.flowsort/.polyglot.META-INF b/bundles/flintstones.method.flowsort/.polyglot.META-INF new file mode 100644 index 0000000..2f2455d --- /dev/null +++ b/bundles/flintstones.method.flowsort/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.flowsort + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Flowsort + diff --git a/bundles/flintstones.method.flowsort/.project b/bundles/flintstones.method.flowsort/.project new file mode 100644 index 0000000..ddaf564 --- /dev/null +++ b/bundles/flintstones.method.flowsort/.project @@ -0,0 +1,45 @@ + + + flintstones.method.flowsort + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362666 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.flowsort/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.flowsort/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.flowsort/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.flowsort/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.flowsort/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.flowsort/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.flowsort/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.flowsort/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.flowsort/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.flowsort/META-INF/MANIFEST.MF b/bundles/flintstones.method.flowsort/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8ca2e30 --- /dev/null +++ b/bundles/flintstones.method.flowsort/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Flowsort +Bundle-SymbolicName: flintstones.method.flowsort;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.flowsort +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric diff --git a/bundles/flintstones.method.flowsort/build.properties b/bundles/flintstones.method.flowsort/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.flowsort/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.flowsort/plugin.xml b/bundles/flintstones.method.flowsort/plugin.xml new file mode 100644 index 0000000..03bbe67 --- /dev/null +++ b/bundles/flintstones.method.flowsort/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort/problem/FlowSortExample.flintstones b/bundles/flintstones.method.flowsort/problem/FlowSortExample.flintstones new file mode 100644 index 0000000..d1677ef --- /dev/null +++ b/bundles/flintstones.method.flowsort/problem/FlowSortExample.flintstones @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/FlowSortMethod.java b/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/FlowSortMethod.java new file mode 100644 index 0000000..ac4d0b2 --- /dev/null +++ b/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/FlowSortMethod.java @@ -0,0 +1,62 @@ +package flintstones.method.flowsort; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.SortingClass; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.flowsort.messages.Messages; +import flintstones.valuation.numeric.NumericValuation; + +public class FlowSortMethod extends ValidatedMethod { + + @Inject + @Translation Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + String numProfileEntity = problemMessages.Profile_count; + String numSortingClassEntity = problemMessages.SortingClass_count; + + int numProfiles = getProfilesByExpert(); + int numSortingClasses = problemService.getAll(SortingClass.Type).length; + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, NumericValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .greaterThan(numSortingClassEntity, numSortingClasses, 0).named("numSortingClasses") //$NON-NLS-1$ + .greaterThan(numProfileEntity, numProfiles, 0).named("numProfiles")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + + private int getProfilesByExpert() { + int totalNumProfiles = problemService.getAll(SortingProfile.Type).length; + int numExperts = problemService.getAll(Expert.Type).length; + int numCriteria = problemService.getAll(Criterion.Type).length; + + if(numExperts > 0 && numCriteria > 0) + return totalNumProfiles / (numExperts + numCriteria); + else + return totalNumProfiles; + } + +} diff --git a/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/Messages.java b/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/Messages.java new file mode 100644 index 0000000..6988981 --- /dev/null +++ b/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/Messages.java @@ -0,0 +1,5 @@ +package flintstones.method.flowsort.messages; + +public class Messages { + public String Method_name; +} diff --git a/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/messages.properties b/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/messages.properties new file mode 100644 index 0000000..815b927 --- /dev/null +++ b/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/messages.properties @@ -0,0 +1 @@ +Method_name=A flow-based sorting method with limiting or central profiles (FlowSort) diff --git a/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/messages_es.properties b/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/messages_es.properties new file mode 100644 index 0000000..26e3806 --- /dev/null +++ b/bundles/flintstones.method.flowsort/src/flintstones/method/flowsort/messages/messages_es.properties @@ -0,0 +1 @@ +Method_name=FlowSort: Un mtodo de clasificacin basado en flujos con perfiles lmite y centrales diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.classpath b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.polyglot.META-INF b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.polyglot.META-INF new file mode 100644 index 0000000..8271c24 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.fuzzy.common.phase.aggregation.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.project b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.project new file mode 100644 index 0000000..a569401 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.fuzzy.common.phase.aggregation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362673 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..470acbc --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.fuzzy.common.phase.aggregation.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.fuzzy.common.phase.aggregation.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + javax.inject, + flintstones.entity.method.phase.ui, + flintstones.model.valuation.service, + flintstones.operator, + org.eclipse.swt, + flintstones.helper.html, + flintstones.entity.method.phase, + flintstones.method.fuzzy.common.phase.aggregation, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.domain.fuzzyset, + flintstones.entity.operator, + flintstones.valuation.fuzzy diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/build.properties b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/plugin.xml b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/plugin.xml new file mode 100644 index 0000000..6bf2b46 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/FuzzyAggregationUI.java b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/FuzzyAggregationUI.java new file mode 100644 index 0000000..f8bbd05 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/FuzzyAggregationUI.java @@ -0,0 +1,482 @@ +package flintstones.method.fuzzy.common.phase.aggregation.ui; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +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.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.fuzzy.common.phase.aggregation.FuzzyAggregation; +import flintstones.method.fuzzy.common.phase.aggregation.ui.messages.Messages; +import flintstones.model.ui.service.UiService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class FuzzyAggregationUI extends PhaseMethodUI{ + + @Inject + IValuationService valuationService; + + @Inject + IOperatorService operatorService; + + @Inject + @Translation + Messages msg; + + /** + * Class model implementation + */ + FuzzyAggregation model; + + /** + * Left side composite + */ + Composite compLeft; + + /** + * Right side composite + */ + Composite compRight; + + /** + * Combo for expert selection + */ + Combo expertsCombo; + + /** + * Aggregation operator selector for valuations + */ + Combo comboValuations; + + /** + * Aggregation operator selector for criteria weights + */ + Combo comboWeights; + + /** + * Selected aggregation operator for valuations + */ + AggregationOperator operatorValuations; + + /** + * Selected aggregation operator for criteria weights + */ + AggregationOperator operatorWeights; + + /** + * Left table (initial experts valuations) + */ + HtmlTextTable initialTable; + + /** + * Initial weights table + */ + HtmlTextTable initialWeTable; + + /** + * Expert selected index + */ + int selectedExpert; + + /** + * Right table (aggregation result) + */ + HtmlTextTable resultTable; + + /** + * Aggregated weights table + */ + HtmlTextTable resultWeigthsTable; + + /** + * Button to enable tag name view + */ + Button nameOrValue; + + /** + * Inits interface + */ + @Override + public void init() { + model = (FuzzyAggregation) this.getModel(); + model.loadData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 3); + + Composite leftTable = new Composite(base, SWT.BORDER); + UiService.setGridData(leftTable, 9, 9, true, true); + UiService.setGridLayout(leftTable, 1); + + Composite comboComposite = new Composite(leftTable, SWT.NONE); + UiService.setGridData(comboComposite, 0, 1, true, false); + UiService.setGridLayout(comboComposite, 2); + +// <--------Make expert selector--------> + Label labelExpertTable = new Label(comboComposite, SWT.NONE); + UiService.setGridData(labelExpertTable, 9, 0, false, false); + labelExpertTable.setText(msg.expert_select); + + createExpertCombo(comboComposite); + createExpertValuationTable(leftTable); + createExpertWeightsTable(leftTable); + +// <--------Make operator selectors--------> + Composite selectOperators = new Composite(base, SWT.BORDER); + UiService.setGridData(selectOperators, 0, 0, false, true); + UiService.setGridLayout(selectOperators, 1); + + Label selectOperatorValuationLabel = new Label(selectOperators, SWT.NONE); + selectOperatorValuationLabel.setText("Select operator for aggregation"); + + Composite comboBase = new Composite(selectOperators, SWT.NONE); + UiService.setGridData(comboBase, 0, 0, true, true); + UiService.setGridLayout(comboBase, 1); + + Label selectOperatorWeightLabel = new Label(selectOperators, SWT.NONE); + selectOperatorWeightLabel.setText("Select operator for weights aggregation"); + + Composite comboBase2 = new Composite(selectOperators, SWT.NONE); + UiService.setGridData(comboBase2, 0, 0, true, true); + UiService.setGridLayout(comboBase2, 1); + +// <--------Make final composite--------> + Composite tablaDer = new Composite(base, SWT.BORDER); + UiService.setGridData(tablaDer, 9, 9, true, true); + UiService.setGridLayout(tablaDer, 1); + + Label aggrLabel = new Label(tablaDer, SWT.NONE); + aggrLabel.setText(msg.agg_values); + UiService.setGridData(aggrLabel, 0, 0, false, false); + +// <--------Make operator selectors--------> + comboValuations = new Combo(comboBase, SWT.NONE); + comboWeights = new Combo(comboBase2, SWT.NONE); + + if (model.getExperts().length == 1) {//One expert + comboValuations.setEnabled(false); + comboWeights.setEnabled(false); + + createExpertValuationTable(tablaDer); + + Label aggrWeightsLabel = new Label(tablaDer, SWT.NONE); + aggrWeightsLabel.setText(msg.aggWeTag); + UiService.setGridData(aggrWeightsLabel, 0, 0, false, false); + + createExpertWeightsTable(tablaDer); + + } else { // Several experts + +// <--------Get aggregation operators--------> + AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(FuzzyValuation.ID, true); + String[] operatorsName = new String[operators.length]; + + for (int i = 0; i < operators.length; ++i) + operatorsName[i] = operators[i].getName(); + + comboValuations.setItems(operatorsName); + comboValuations.select(0); + operatorValuations = operators[0]; + + comboValuations.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + for (int i = 0; i < operators.length; i++) { + if (comboValuations.getText().equals(operators[i].getName())) { + operatorValuations = operators[i]; + i = operators.length; + } + } + + refreshCollectiveData(); + + model.exportData(); + } + }); + + comboWeights.setItems(operatorsName); + comboWeights.select(0); + operatorWeights = operators[0]; + + comboWeights.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + for (int i = 0; i < operators.length; i++) { + if (comboWeights.getText().equals(operators[i].getName())) { + operatorWeights = operators[i]; + i = operators.length; + } + } + + refreshCollectiveData(); + + model.exportData(); + } + }); + + createAggregatedValuationsTable(tablaDer); + + Label aggrWeightsLabel = new Label(tablaDer, SWT.NONE); + aggrWeightsLabel.setText(msg.aggWeTag); + UiService.setGridData(aggrWeightsLabel, 0, 0, false, false); + + createAggregatedWeightsTable(tablaDer); + } + + model.exportData(); + } + + /** + * Makes expert selector + * @param comboComposite + */ + private void createExpertCombo(Composite comboComposite) { + expertsCombo = new Combo(comboComposite, SWT.NONE); + UiService.setGridData(expertsCombo, 0, 0, false, false); + + for (int i = 0; i < model.getExperts().length; i++) + expertsCombo.add(model.getExperts()[i].getName()); + + expertsCombo.select(0); + expertsCombo.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + refreshIndividualData(); + } + }); + } + + /** + * Makes inital data table with first expert + * + * @param base Table composite + */ + void createExpertValuationTable(Composite base) { + + String[] alternatives = new String[model.getAlternatives().length]; + String[] criteria = new String[model.getCriteria().length]; + + for (int i = 0; i < alternatives.length; i++) + alternatives[i] = model.getAlternatives()[i].toString(); + + for (int i = 0; i < criteria.length; i++) + criteria[i] = model.getCriteria()[i].toString(); + + String[][] valuations = getExpertValuations(alternatives.length, criteria.length, expertsCombo.getSelectionIndex()); + + Composite compositeTable = new Composite(base, SWT.NONE); + UiService.setGridData(compositeTable, 9, 9, true, true); + UiService.setGridLayout(compositeTable, 1); + + initialTable = new HtmlTextTable(compositeTable, valuations, criteria, alternatives); + initialTable.render(); + } + + /** + * @param rows Number of alternatives + * @param cols Numer of criteria + * @param expertIndex Index of the expert + * @return Expert collected valuations as String array matrix + */ + private String[][] getExpertValuations(int rows, int cols, int expertIndex) { + String[][] valuations = new String[rows][cols]; + + for (int i = 0; i < valuations.length; i++) { + for (int j = 0; j < valuations[i].length; j++) + valuations[i][j] = model.getStringExpertValuation(expertIndex, i, j); + } + + return valuations; + } + + /** + * Make collected weights table + * + * @param base Table composite + */ + private void createExpertWeightsTable(Composite base) { + String[] criteria = new String[model.getCriteria().length]; + String[] weights = new String[model.getCriteria().length]; + + int index = expertsCombo.getSelectionIndex(); + TrapezoidalFunction[] expertWeights = model.getExpertWeights(index); + + Criterion crit; + for (int i = 0; i < criteria.length; i++) { + crit = model.getCriteria()[i]; + criteria[i] = crit.toString(); + weights[i] = expertWeights[i].toString(); + } + + Composite compositeTable = new Composite(base, SWT.NONE); + UiService.setGridData(compositeTable, 9, 9, true, true); + UiService.setGridLayout(compositeTable, 1); + + initialWeTable = new HtmlTextTable(compositeTable, weights, criteria, false); + initialWeTable.render(); + } + + /** + * Makes aggregated valuations table + * + * @param base Table composite + */ + void createAggregatedValuationsTable(Composite base) { + model.computeAggregatedMatrix(operatorValuations); + + Alternative[] alternatives = model.getAlternatives(); + String[] alternatives_names = new String[model.getAlternatives().length]; + + Criterion[] criteria = model.getCriteria(); + String[] criteria_names = new String[model.getCriteria().length]; + + String[][] valuations = new String[alternatives.length][criteria.length]; + + for (int i = 0; i < alternatives.length; i++) + alternatives_names[i] = alternatives[i].toString(); + + for (int i = 0; i < criteria.length; i++) + criteria_names[i] = criteria[i].toString(); + + for (int i = 0; i < valuations.length; i++) { + for (int j = 0; j < valuations[i].length; j++) + valuations[i][j] = model.getAggregatedValuation(alternatives[i], criteria[j]).toString(); + } + + Composite tabla = new Composite(base, SWT.NONE); + UiService.setGridData(tabla, 9, 9, true, true); + UiService.setGridLayout(tabla, 1); + + resultTable = new HtmlTextTable(tabla, valuations, criteria_names, alternatives_names); + resultTable.render(); + } + + /** + * Makes aggregated weights table + * + * @param base Table composite + */ + void createAggregatedWeightsTable(Composite base) { + model.computeAggregatedWeights(operatorWeights); + + Criterion[] criteria = model.getCriteria(); + String[] criteria_names = new String[model.getCriteria().length]; + for (int i = 0; i < criteria.length; i++) + criteria_names[i] = criteria[i].toString(); + + String[] weights = new String[model.getCriteria().length]; + + for (int i = 0; i < criteria.length; i++) + weights[i] = model.getAggregatedWeight(i).toString(); + + Composite tabla = new Composite(base, SWT.NONE); + UiService.setGridData(tabla, 9, 9, true, true); + UiService.setGridLayout(tabla, 1); + + resultWeigthsTable = new HtmlTextTable(tabla, weights, criteria_names, false); + resultWeigthsTable.render(); + } + + /** + * Reload initial data and weights tables + */ + private void refreshIndividualData() { + refreshExpertValuationTable(); + refreshExpertWeightTable(); + } + + /** + * Reload aggregated valuations and weights tables + */ + private void refreshCollectiveData() { + refreshCollectionValuationTable(); + refreshCollectiveWeightTable(); + } + + /** + * Reloads phase tables + */ + @Override + public void refresh() { + refreshIndividualData(); + refreshCollectiveData(); + this.sendRefresh(); + } + + /** + * Updates initial table data + */ + private void refreshExpertValuationTable() { + String[][] valuations = getExpertValuations(model.getAlternatives().length, model.getCriteria().length, expertsCombo.getSelectionIndex()); + initialTable.refresh(valuations); + initialTable.render(); + } + + /** + * Updates criterion weights table + */ + private void refreshExpertWeightTable() { + TrapezoidalFunction[] expertWeights = model.getExpertWeights(expertsCombo.getSelectionIndex()); + + String[] weights = new String[model.getCriteria().length]; + for (int i = 0; i < model.getCriteria().length; i++) + weights[i] = expertWeights[i].toString(); + + initialWeTable.refresh(weights); + initialWeTable.render(); + } + + /** + * Updates aggregated valuations table + */ + private void refreshCollectionValuationTable() { + model.computeAggregatedMatrix(operatorValuations); + + Alternative[] alternatives = model.getAlternatives(); + Criterion[] criteria = model.getCriteria(); + + String[][] valuations = new String[model.getAlternatives().length][model.getCriteria().length]; + for (int i = 0; i < model.getAlternatives().length; i++) { + for (int j = 0; j < model.getCriteria().length; j++) + valuations[i][j] = model.getAggregatedValuation(alternatives[i], criteria[j]).toString(); + } + + resultTable.refresh(valuations); + resultTable.render(); + } + + /** + * Updates aggregated weights table + */ + private void refreshCollectiveWeightTable() { + model.computeAggregatedWeights(operatorWeights); + + String[] weights = new String[model.getCriteria().length]; + + for (int i = 0; i < model.getCriteria().length; i++) + weights[i] = model.getAggregatedWeight(i).toString(); + + resultWeigthsTable.refresh(weights); + resultWeigthsTable.render(); + } + + @Override + public boolean isForwardEnabled() { + return true; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/Messages.java b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/Messages.java new file mode 100644 index 0000000..3b2875e --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/Messages.java @@ -0,0 +1,12 @@ +package flintstones.method.fuzzy.common.phase.aggregation.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String expert_select; + public String show_alt_names; + public String agg_values; + public String iniWeTag; + public String aggWeTag; +} diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/messages.properties b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/messages.properties new file mode 100644 index 0000000..6f5d486 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/messages.properties @@ -0,0 +1,5 @@ +expert_select=Select expert +show_alt_names=Show names +agg_values=Aggregated valuations +iniWeTag=Initial weights +aggWeTag=Aggregated weights \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/messages_es.properties b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/messages_es.properties new file mode 100644 index 0000000..424e9ed --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation.ui/src/flintstones/method/fuzzy/common/phase/aggregation/ui/messages/messages_es.properties @@ -0,0 +1,5 @@ +expert_select=Seleccionar experto +show_alt_names=Ver nombres +agg_values=Valoraciones agregadas +iniWeTag=Pesos iniciales +aggWeTag=Pesos agregados \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/.classpath b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/.polyglot.META-INF b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.polyglot.META-INF new file mode 100644 index 0000000..f04892e --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.fuzzy.common.phase.aggregation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/.project b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.project new file mode 100644 index 0000000..17baba2 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.project @@ -0,0 +1,45 @@ + + + flintstones.method.fuzzy.common.phase.aggregation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362673 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/META-INF/MANIFEST.MF b/bundles/flintstones.method.fuzzy.common.phase.aggregation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..662c1c8 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.fuzzy.common.phase.aggregation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.fuzzy.common.phase.aggregation +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase, + javax.inject, + flintstones.model.problemelement.service, + flintstones.model.valuation.service, + flintstones.domain.fuzzyset, + flintstones.helper.data, + flintstones.model.domain.service, + flintstones.operator, + flintstones.valuation.fuzzy, + flintstones.entity.operator +Export-Package: flintstones.method.fuzzy.common.phase.aggregation diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/build.properties b/bundles/flintstones.method.fuzzy.common.phase.aggregation/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/plugin.xml b/bundles/flintstones.method.fuzzy.common.phase.aggregation/plugin.xml new file mode 100644 index 0000000..a2c9413 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/FuzzyAggregation.java b/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/FuzzyAggregation.java new file mode 100644 index 0000000..2b2084a --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/FuzzyAggregation.java @@ -0,0 +1,254 @@ +package flintstones.method.fuzzy.common.phase.aggregation; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.ImportedDataNotFoundException; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.method.fuzzy.common.phase.aggregation.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.fuzzy.FuzzyValuation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; + +import javax.inject.Inject; + +/** + * Common phase for fuzzy valuation aggregation + * @author jcfer + * + */ +public class FuzzyAggregation extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + IOperatorService operatorService; + + @Inject + IValuationService valuationService; + + @Inject + @Translation + Messages msg; + + /** + * Experts' valuations + */ + HashMap valuations; + + /** + * Experts weights + */ + HashMap expWeights; + + /** + * Criteria weights + */ + HashMatrix criWeights; + + /** + * Aggregated criteria weights + */ + ArrayList aggCriWeights; + + /** + * All the alternatives + */ + Alternative[] allAlternatives; + + /** + * All the criteria + */ + Criterion[] allCriteria; + + /** + * All the experts + */ + Expert[] allExperts; + + /** + * Experts' valuations + */ + Valuation[][][] initialValues; + + /** + * Aggregated decision matrix + */ + HashMatrix aggregatedValues; + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * Export data + */ + public void exportData() { + exportData("aggregatedValues", aggregatedValues); + exportData("aggregatedWeights", aggCriWeights); + } + + /** + * @return Experts of the problem + */ + public Expert[] getExperts() { + return allExperts; + } + + /** + * @return Criteria of the problem + */ + public Criterion[] getCriteria() { + return allCriteria; + } + + /** + * @return Alternatives of the problem + */ + public Alternative[] getAlternatives() { + return allAlternatives; + } + + /** + * Load data from previous phase and compute aggregated decision matrix + */ + @SuppressWarnings("unchecked") + public void loadData() { + // Problem data + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + allCriteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + allExperts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + + // Gathering data + expWeights = (HashMap) getPreviousPhase().importData("expertsWeights"); + criWeights = (HashMatrix) importData("criterionsWeights"); + + try { + valuations = (HashMap) importData("twoTupleUnifiedValuations");//unification phase before + } catch(ImportedDataNotFoundException e) { + valuations = valuationService.getAllKV(); + } + + // Object creation + initialValues = new Valuation[allExperts.length][allAlternatives.length][allCriteria.length]; + aggregatedValues = new HashMatrix<>(); + + // For each combination of expert, alternative and criterion, add the valuation to array + ProblemElementKey key; + for (int i = 0; i < allExperts.length; i++) { + for (int j = 0; j < allAlternatives.length; j++) { + for (int k = 0; k < allCriteria.length; k++) { + key = new ProblemElementKey(allExperts[i], allAlternatives[j], allCriteria[k]); + initialValues[i][j][k] = valuations.get(key); + } + } + } + } + + /** + * @param Index of expert + * @return Valuations of the expert + */ + public String getStringExpertValuation(int e, int a, int c) { + return initialValues[e][a][c].toString(); + } + + /** + * @param e Index of expert + * @return Criterion weights of the expert + */ + public TrapezoidalFunction[] getExpertWeights(int e) { + Object[] temp = criWeights.get(allExperts[e]).values().toArray(); + TrapezoidalFunction[] crits = new TrapezoidalFunction[temp.length]; + for(int i = 0; i < temp.length; i++) { + crits[i] = (TrapezoidalFunction) temp[i]; + } + return crits; + } + + /** + * Calculate aggregated valuations + * + * @param operatorId ID for aggregation operator + */ + public void computeAggregatedMatrix(AggregationOperator operator) { + aggregatedValues = new HashMatrix(); + + LinkedList valuations = new LinkedList<>(); + + for (int a = 0; a < allAlternatives.length; a++) { + for (int c = 0; c < allCriteria.length; c++) { + for (int e = 0; e < allExperts.length; e++) { + valuations.add(initialValues[e][a][c]); + } + + // Aggregates each valuation [alternative][criterion] for each expert + Valuation aggregated = operator.computeAggregation(valuations, new ArrayList(expWeights.values())); + aggregatedValues.put(allAlternatives[a], allCriteria[c], ((FuzzyValuation) aggregated).getFuzzyNumber()); + valuations.clear(); + } + } + } + + /** + * Calculate aggregated weights + * + * @param operatorId ID for aggregation operator + */ + public void computeAggregatedWeights(AggregationOperator operator) { + aggCriWeights = new ArrayList(); + + ArrayList wTemp = new ArrayList<>(); + FuzzyValuation temp; + + for (int c = 0; c < allCriteria.length; c++) { + for (int e = 0; e < allExperts.length; e++) { + temp = new FuzzyValuation(); + temp.setFuzzyNumber(criWeights.get(allExperts[e], allCriteria[c])); + wTemp.add(temp); + } + + temp = (FuzzyValuation) operator.computeAggregation(wTemp, new ArrayList(expWeights.values())); + aggCriWeights.add(temp.getFuzzyNumber()); + + wTemp.clear(); + } + } + + /** + * @param c Criterion + * @param a Alternative + * @return Aggregated valuation + */ + public TrapezoidalFunction getAggregatedValuation(Alternative a, Criterion c) { + return aggregatedValues.get(a, c); + } + + /** + * @param c Index of criterion + * @return Aggregated weight + */ + public TrapezoidalFunction getAggregatedWeight(int c) { + return aggCriWeights.get(c); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/Messages.java b/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/Messages.java new file mode 100644 index 0000000..9d31fcc --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.fuzzy.common.phase.aggregation.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; +} diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/messages.properties b/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/messages.properties new file mode 100644 index 0000000..104620f --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/messages.properties @@ -0,0 +1 @@ +phase_name=Aggregation \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/messages_es.properties b/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/messages_es.properties new file mode 100644 index 0000000..4a05b32 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.aggregation/src/flintstones/method/fuzzy/common/phase/aggregation/messages/messages_es.properties @@ -0,0 +1 @@ +phase_name=Agregacin \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.classpath b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.polyglot.META-INF b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.polyglot.META-INF new file mode 100644 index 0000000..c6e90c1 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.fuzzy.common.phase.collectweights.criterion.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.project b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.project new file mode 100644 index 0000000..eb727ed --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.fuzzy.common.phase.collectweights.criterion.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362674 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..630c84c --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/build.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/plugin.xml b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/plugin.xml new file mode 100644 index 0000000..c5e6b42 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/FuzzyCollectWeightsCriterionUI.java b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/FuzzyCollectWeightsCriterionUI.java new file mode 100644 index 0000000..3bd54b3 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/FuzzyCollectWeightsCriterionUI.java @@ -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 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(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 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 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(); + } + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/Messages.java b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/Messages.java new file mode 100644 index 0000000..46f4a3d --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/Messages.java @@ -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; + +} diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/messages.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/messages.properties new file mode 100644 index 0000000..07f7622 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/messages.properties @@ -0,0 +1,2 @@ +selectTag=Select valuation for next weight +buttonTag=Add \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/messages_es.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/messages_es.properties new file mode 100644 index 0000000..a448d92 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion.ui/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/ui/messages/messages_es.properties @@ -0,0 +1,2 @@ +selectTag=Seleccionar valoracin para el siguiente peso +buttonTag=Aadir \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.classpath b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.polyglot.META-INF b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.polyglot.META-INF new file mode 100644 index 0000000..709e9cf --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.fuzzy.common.phase.collectweights.criterion + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.project b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.project new file mode 100644 index 0000000..9d9bb0d --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.project @@ -0,0 +1,45 @@ + + + flintstones.method.fuzzy.common.phase.collectweights.criterion + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362674 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/META-INF/MANIFEST.MF b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a33a2eb --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.fuzzy.common.phase.collectweights.criterion;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.fuzzy.common.phase.collectweights.criterion +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase, + javax.inject, + flintstones.model.problemelement.service, + flintstones.helper.data, + flintstones.domain.fuzzyset, + flintstones.helper.faq +Export-Package: flintstones.method.fuzzy.common.phase.collectweights.criterion diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/build.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/plugin.xml b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/plugin.xml new file mode 100644 index 0000000..3660ff7 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/FuzzyCollectWeightsCriterion.java b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/FuzzyCollectWeightsCriterion.java new file mode 100644 index 0000000..b6d5ee1 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/FuzzyCollectWeightsCriterion.java @@ -0,0 +1,98 @@ +package flintstones.method.fuzzy.common.phase.collectweights.criterion; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.HashMatrix; +import flintstones.helper.faq.interfaces.ITextFAQ; +import flintstones.method.fuzzy.common.phase.collectweights.criterion.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; + +import javax.inject.Inject; + +public class FuzzyCollectWeightsCriterion extends PhaseMethod implements ITextFAQ{ + + @Inject + IProblemElementService problemService; + + /** + * Collected weights + */ + HashMatrix weights = new HashMatrix<>(); + + @Inject + @Translation + Messages msg; + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * @return all the experts + */ + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + /** + * @return all the criteria + */ + public ProblemElement[] getCriteria() { + return problemService.getAll(Criterion.Type); + } + + /** + * Exporta data + */ + private void exportData() { + exportData("criterionsWeights", weights); + } + + /** + * Add new fuzzy weight + * + * @param expert Expert + * @param criterion Criterion + * @param weight Fuzzy weight + */ + public void addWeight(ProblemElement expert, ProblemElement criterion, TrapezoidalFunction weight) { + weights.put(expert, criterion, weight); + exportData(); + } + + /** + * @param expert Expert + * @param criterion Criterion + */ + public TrapezoidalFunction getWeight(ProblemElement expert, ProblemElement criterion) { + return weights.get(expert, criterion); + } + + /** + * @return true if all weights are assigned, otherwise false + */ + public boolean isFilled() { + for (ProblemElement expert : getExperts()) { + for (ProblemElement criterion : getCriteria()) { + + if (weights.get(expert, criterion) == null) + return false; + } + } + return true; + } + + @Override + public String getFAQ() { + return msg.usageInfo; + } +} diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/Messages.java b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/Messages.java new file mode 100644 index 0000000..f17fac4 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.fuzzy.common.phase.collectweights.criterion.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; + public String usageInfo; +} diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/messages.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/messages.properties new file mode 100644 index 0000000..5f8b622 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/messages.properties @@ -0,0 +1,2 @@ +phase_name=Criterion weights +usageInfo=Assign weights by value or using domain tags \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/messages_es.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/messages_es.properties new file mode 100644 index 0000000..e649592 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.criterion/src/flintstones/method/fuzzy/common/phase/collectweights/criterion/messages/messages_es.properties @@ -0,0 +1,2 @@ +phase_name=Pesos de criterios +usageInfo=Asignacin de pesos numricamente o mediante las etiquetas del dominio \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.classpath b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.polyglot.META-INF b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.polyglot.META-INF new file mode 100644 index 0000000..9a92285 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.fuzzy.common.phase.collectweights.experts.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.project b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.project new file mode 100644 index 0000000..8d7ae2f --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.fuzzy.common.phase.collectweights.experts.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362675 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..de8386c --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.fuzzy.common.phase.collectweights.experts.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.fuzzy.common.phase.collectweights.experts.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase.ui, + org.eclipse.e4.core.services, + javax.inject, + flintstones.method.fuzzy.common.phase.collectweights.experts, + flintstones.model.valuation.service, + flintstones.helper.ui, + flintstones.entity.problemelement.ui, + flintstones.entity.method.phase, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.domain.fuzzyset, + flintstones.valuation.linguistic, + flintstones.helper.data, + flintstones.helper.faq diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/build.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/plugin.xml b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/plugin.xml new file mode 100644 index 0000000..615f6e4 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/FuzzyCollectWeightsExpertsUI.java b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/FuzzyCollectWeightsExpertsUI.java new file mode 100644 index 0000000..0bc9eaf --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/FuzzyCollectWeightsExpertsUI.java @@ -0,0 +1,311 @@ +package flintstones.method.fuzzy.common.phase.collectweights.experts.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.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +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.experts.FuzzyCollectWeightsExperts; +import flintstones.method.fuzzy.common.phase.collectweights.experts.ui.messages.Messages; +import flintstones.model.ui.service.UiService; +import flintstones.model.valuation.service.IValuationService; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.inject.Inject; + +public class FuzzyCollectWeightsExpertsUI extends PhaseMethodUI + implements WItemBeforeOperation, WItemChanged, IProblemElementChangedListener { + + @Inject + IValuationService valuationService; + + // Model implementation + FuzzyCollectWeightsExperts model; + + // Weights collector table + WCollector collector; + + // Select expert + ProblemElementSelector selector; + + // Select linguistic domain + Combo domainSelector; + + // Select linguistic label + Combo labelSelector; + + // Messages class containing localised strings + @Inject + @Translation + Messages msg; + + /** + * Init interface + */ + @Override + public void init() { + model = (FuzzyCollectWeightsExperts) this.getModel(); + + Composite base = this.getBaseComposite(); + UiService.setGridDataAuto(base); + UiService.setGridLayout(base, 1); + +//<--- TOP COMPOSITE ---> + + Composite topRow = new Composite(base, SWT.BORDER); + UiService.setGridData(topRow, 0, -1, true, false); + UiService.setGridLayout(topRow, 1, false); + + //Expert selector + Composite expComp = new Composite(topRow, SWT.NONE); + UiService.setGridData(expComp, 0, 0, false, false); + UiService.setGridLayout(expComp, 2, false); + + selector = new ProblemElementSelector(expComp, model.getExperts()); + selector.setText(Expert.Type); + selector.setListener(this); + + + String[] linguisticDomainsNames = model.getLinguisticDomainsName(); + if(linguisticDomainsNames.length != 0) //Linguistic label for weight selector + createLinguisticDomainSelector(topRow, linguisticDomainsNames); + +//<--- CENTRAL COMPOSITE ---> + Composite midRow = new Composite(base, SWT.NONE); + UiService.setGridLayout(midRow, 1, true); + UiService.setGridData(midRow, 9, 9, true, true); + + // Data collector + String[] fuzzy = new String[] { "l", "m", "r" }; + collector = new WCollector(midRow); + 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)); + } + }); + } + + private void createLinguisticDomainSelector(Composite topRow, String[] linguisticDomainsNames) { + Composite tagComp = new Composite(topRow, SWT.NONE); + UiService.setGridLayout(tagComp, 3, false); + UiService.setGridData(tagComp, 0, 0, false, false); + + createComboDomain(tagComp, linguisticDomainsNames); + createComboLabel(tagComp); + createAddLabelButton(tagComp); + } + + private void createAddLabelButton(Composite tagComp) { + // Add tag button + Button tagAdd = new Button(tagComp, SWT.NONE); + tagAdd.setText(msg.buttonTag); + tagAdd.addSelectionListener(new SelectionAdapter() { + /** + * Assigns the selected label value to next weight + */ + @Override + public void widgetSelected(SelectionEvent e) { + List labels = model.getLabelsFromDomainName(domainSelector.getText()); + + String[] newData = new String[3]; + TrapezoidalFunction selected = (TrapezoidalFunction) labels.get(labelSelector.getSelectionIndex()).getSemantic(); + newData[0] = Double.toString(selected.getA()); + newData[1] = Double.toString(selected.getB()); + newData[2] = Double.toString(selected.getD()); + + collector.setValues(new ArrayList(Arrays.asList(newData))); + selector.setStatus(selector.getSelectedElement(), true); + + saveWeigths(newData); + } + }); + } + + private void createComboDomain(Composite tagComp, String[] linguisticDomainsNames) { + Composite linguisticDomainSelectionComposite = new Composite(tagComp, SWT.NONE); + UiService.setGridLayout(linguisticDomainSelectionComposite, 2, false); + UiService.setGridData(linguisticDomainSelectionComposite, 0, 0, false, false); + + Label label_domain = new Label(linguisticDomainSelectionComposite, SWT.NONE); + label_domain.setText(msg.selectLingDomain); + domainSelector = new Combo(linguisticDomainSelectionComposite, SWT.NONE); + + for (String name : linguisticDomainsNames) + domainSelector.add(name); + + domainSelector.select(0); + + domainSelector.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setLabelsToLabelCombo(); + } + }); + } + + private void createComboLabel(Composite tagComp) { + Composite labelSelectionComposite = new Composite(tagComp, SWT.NONE); + UiService.setGridLayout(labelSelectionComposite, 2, false); + UiService.setGridData(labelSelectionComposite, 0, 0, false, false); + + Label label = new Label(labelSelectionComposite, SWT.NONE); + label.setText(msg.selectTag); + labelSelector = new Combo(labelSelectionComposite, SWT.NONE); + + setLabelsToLabelCombo(); + } + + private void setLabelsToLabelCombo() { + labelSelector.removeAll(); + + List labels = model.getLabelsFromDomainName(domainSelector.getText()); + + for (LabelLinguisticDomain lb : labels) + labelSelector.add(lb.getName()); + + labelSelector.select(0); + } + + @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 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 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) { + saveWeigths(data); + + selector.setStatus(selector.getSelectedElement(), true); + } else { + selector.setStatus(selector.getSelectedElement(), false); + } + } + + /** + * Saves weigths for the next phase + * + * @param data Weigths to save + */ + private void saveWeigths(String[] data) { + double[] fuzzyNumber = new double[data.length]; + for (int i = 0; i < data.length; i++) + fuzzyNumber[i] = DoubleHelper.ParseDouble(data[i]); + + model.addWeight(selector.getSelectedElement(), new TrapezoidalFunction(fuzzyNumber)); + sendRefresh(); + } + + /** + * Called when changing selected expert + */ + @Override + public void problemElementChanged(ProblemElement pe) { + ArrayList dt = new ArrayList<>(); + + TrapezoidalFunction weight = model.getWeight(pe); + // 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); + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/Messages.java b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/Messages.java new file mode 100644 index 0000000..1c01cbd --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/Messages.java @@ -0,0 +1,10 @@ +package flintstones.method.fuzzy.common.phase.collectweights.experts.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String selectLingDomain; + public String selectTag; + public String buttonTag; +} diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/messages.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/messages.properties new file mode 100644 index 0000000..f6bf694 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/messages.properties @@ -0,0 +1,3 @@ +selectLingDomain=Select domain +selectTag=Select label for weight +buttonTag=Add \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/messages_es.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/messages_es.properties new file mode 100644 index 0000000..a1a46f7 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts.ui/src/flintstones/method/fuzzy/common/phase/collectweights/experts/ui/messages/messages_es.properties @@ -0,0 +1,3 @@ +selectLingDomain=Selecciona dominio +selectTag=Selecciona etiqueta para el peso +buttonTag=Aadir \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.classpath b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.polyglot.META-INF b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.polyglot.META-INF new file mode 100644 index 0000000..27b3f0a --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.fuzzy.common.phase.collectweights.experts + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.project b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.project new file mode 100644 index 0000000..6df0588 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.project @@ -0,0 +1,45 @@ + + + flintstones.method.fuzzy.common.phase.collectweights.experts + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362675 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/META-INF/MANIFEST.MF b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/META-INF/MANIFEST.MF new file mode 100644 index 0000000..de3c82b --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.fuzzy.common.phase.collectweights.experts;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.fuzzy.common.phase.collectweights.experts +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase, + org.eclipse.e4.core.services, + javax.inject, + flintstones.model.problemelement.service, + flintstones.domain.fuzzyset, + flintstones.helper.faq, + flintstones.model.domain.service +Export-Package: flintstones.method.fuzzy.common.phase.collectweights.experts diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/build.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/plugin.xml b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/plugin.xml new file mode 100644 index 0000000..585ba36 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/FuzzyCollectWeightsExperts.java b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/FuzzyCollectWeightsExperts.java new file mode 100644 index 0000000..14fa5a1 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/FuzzyCollectWeightsExperts.java @@ -0,0 +1,146 @@ +package flintstones.method.fuzzy.common.phase.collectweights.experts; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.faq.interfaces.ITextFAQ; +import flintstones.method.fuzzy.common.phase.collectweights.experts.messages.Messages; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import javax.inject.Inject; + +public class FuzzyCollectWeightsExperts extends PhaseMethod implements ITextFAQ { + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + /** + * Collected weights + */ + HashMap weigths = new HashMap<>(); + + @Inject + @Translation + Messages msg; + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * @return all the experts + */ + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + /** + * @return all the experts' names + */ + public String[] getExpertsName() { + ProblemElement[] experts = this.getExperts(); + + String[] names = new String[experts.length]; + for (int i = 0; i < names.length; ++i) + names[i] = experts[i].getName(); + + return names; + } + + public FuzzySet[] getLinguisticDomains() { + List linguistic_domains = new ArrayList(); + + Domain[] domains = domainService.getAll(); + for(Domain domain: domains) { + if(domain instanceof FuzzySet) + linguistic_domains.add((FuzzySet) domain); + } + + return linguistic_domains.toArray(new FuzzySet[0]); + } + + public String[] getLinguisticDomainsName() { + FuzzySet[] linguistic_domains = this.getLinguisticDomains(); + + String[] names = new String[linguistic_domains.length]; + for(int i = 0; i < linguistic_domains.length; ++i) + names[i] = linguistic_domains[i].getName(); + + return names; + } + + public List getLabelsFromDomainName(String name) { + FuzzySet[] domains = this.getLinguisticDomains(); + + for(FuzzySet domain: domains) { + if(domain.getName().equals(name)) + return domain.getLabelSet().getLabels(); + } + + return null; + } + + /** + * Export weights + */ + private void exportData() { + exportData("expertsWeights", weigths); + } + + /** + * Add new weight + * + * @param expert Expert + * @param weight Fuzzy weight + */ + public void addWeight(ProblemElement expert, TrapezoidalFunction weight) { + weigths.put(expert, weight); + exportData(); + } + + /** + * @param expert Expert + * @return fuzzy weight + */ + public TrapezoidalFunction getWeight(ProblemElement expert) { + return weigths.get(expert); + } + + /** + * @return true if all weights are assigned, otherwise false + */ + public boolean isFilled() { + for (ProblemElement expert : getExperts()) { + for (int i = 0; i < 3; i++) { + if (weigths.get(expert) == null) + return false; + } + } + return true; + } + + @Override + public String getFAQ() { + String faq = msg.usageInfo; + return faq; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/Messages.java b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/Messages.java new file mode 100644 index 0000000..1be086b --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.fuzzy.common.phase.collectweights.experts.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; + public String usageInfo; +} diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/messages.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/messages.properties new file mode 100644 index 0000000..a0bd507 --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/messages.properties @@ -0,0 +1,2 @@ +phase_name=Experts weights gathering +usageInfo=Assign weights by value or using domain tags. The total sum must be 1 \ No newline at end of file diff --git a/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/messages_es.properties b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/messages_es.properties new file mode 100644 index 0000000..6992b6b --- /dev/null +++ b/bundles/flintstones.method.fuzzy.common.phase.collectweights.experts/src/flintstones/method/fuzzy/common/phase/collectweights/experts/messages/messages_es.properties @@ -0,0 +1,2 @@ +phase_name=Recolecta de pesos para expertos +usageInfo=Asignacin de pesos numricamente o mediante las etiquetas del dominio. Todos los pesos deben sumar 1. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.elicit/.classpath b/bundles/flintstones.method.linguistic.elicit/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.elicit/.polyglot.META-INF b/bundles/flintstones.method.linguistic.elicit/.polyglot.META-INF new file mode 100644 index 0000000..b965030 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.elicit + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] ELICIT + diff --git a/bundles/flintstones.method.linguistic.elicit/.project b/bundles/flintstones.method.linguistic.elicit/.project new file mode 100644 index 0000000..33b16a5 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.elicit + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362676 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.elicit/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.elicit/META-INF/MANIFEST.MF new file mode 100644 index 0000000..06740a8 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.linguistic.elicit;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.linguistic.twotuple +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.elicit, + flintstones.valuation.hesitant, + flintstones.helper.faq diff --git a/bundles/flintstones.method.linguistic.elicit/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.linguistic.elicit/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..56ccd8d --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.hesitant.twotuple +Bundle-Name = ELICIT \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.elicit/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.linguistic.elicit/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..56ccd8d --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.hesitant.twotuple +Bundle-Name = ELICIT \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.elicit/build.properties b/bundles/flintstones.method.linguistic.elicit/build.properties new file mode 100644 index 0000000..388b652 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ + diff --git a/bundles/flintstones.method.linguistic.elicit/faq/faq.en.md b/bundles/flintstones.method.linguistic.elicit/faq/faq.en.md new file mode 100644 index 0000000..dcb5a24 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/faq/faq.en.md @@ -0,0 +1 @@ +Many real-world decision making problems present changing contexts in which uncertainty or vagueness appear. Such uncertainty has been often modeled based on linguistic information by using single linguistic terms. Dealing with linguistic information in decision making demands processes of computing with words whose main characteristic is to emulate human beings reasoning processes to obtain linguistic outputs from linguistic inputs. However, often single linguistic terms are limited or do not express properly the expert's knowledge, being necessary to elaborate richer linguistic expressions easy to understand and able to express greater amount of knowledge, as it is the case of the comparative linguistic expressions based on hesitant fuzzy linguistic terms sets. Nevertheless, current computational models for comparative linguistic expressions present limitations both from understandibility and precision points of view. The 2-tuple linguistic representation model stands out in these aspects because of its accuracy and interpretability dealing with linguistic terms, both related to the use of the symbolic translation, although 2-tuple linguistic values are still limited by the use of single linguistic terms. Therefore, the aim of this paper is to present a new fuzzy linguistic representation model for comparative linguistic expressions that takes advantage of the goodness of the 2-tuple linguistic representation model and improve the interpretability and accuracy of the results in computing with words processes, resulting the so-called Extended Comparative Linguistic Expressions with Symbolic Translation (ELICIT). Taking into account the proposed model, a new computing with words approach is presented and then applied to a decision making case study to show its performance and advantages in a real case by comparing with other linguistic decision approaches. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.elicit/faq/faq.es.md b/bundles/flintstones.method.linguistic.elicit/faq/faq.es.md new file mode 100644 index 0000000..9de3c17 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/faq/faq.es.md @@ -0,0 +1,3 @@ +# ELICIT Representation Model + +Many real-world decision making problems present changing contexts in which uncertainty or vagueness appear. Such uncertainty has been often modeled based on linguistic information by using single linguistic terms. Dealing with linguistic information in decision making demands processes of computing with words whose main characteristic is to emulate human beings reasoning processes to obtain linguistic outputs from linguistic inputs. However, often single linguistic terms are limited or do not express properly the expert's knowledge, being necessary to elaborate richer linguistic expressions easy to understand and able to express greater amount of knowledge, as it is the case of the comparative linguistic expressions based on hesitant fuzzy linguistic terms sets. Nevertheless, current computational models for comparative linguistic expressions present limitations both from understandibility and precision points of view. The 2-tuple linguistic representation model stands out in these aspects because of its accuracy and interpretability dealing with linguistic terms, both related to the use of the symbolic translation, although 2-tuple linguistic values are still limited by the use of single linguistic terms. Therefore, the aim of this paper is to present a new fuzzy linguistic representation model for comparative linguistic expressions that takes advantage of the goodness of the 2-tuple linguistic representation model and improve the interpretability and accuracy of the results in computing with words processes, resulting the so-called Extended Comparative Linguistic Expressions with Symbolic Translation (ELICIT). Taking into account the proposed model, a new computing with words approach is presented and then applied to a decision making case study to show its performance and advantages in a real case by comparing with other linguistic decision approaches. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.elicit/plugin.xml b/bundles/flintstones.method.linguistic.elicit/plugin.xml new file mode 100644 index 0000000..f1fb668 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/plugin.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/ELICITMethod.java b/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/ELICITMethod.java new file mode 100644 index 0000000..eefa371 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/ELICITMethod.java @@ -0,0 +1,64 @@ + +package flintstones.method.linguistic.elicit; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.elicit.messages.Messages; +import flintstones.valuation.elicit.ELICIT; +import flintstones.valuation.hesitant.HesitantValuation; + +public class ELICITMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + int numDomains = domainService.getAll().length; + String numDomainEntity = domainMessages.Domain_count; + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, HesitantValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, ELICIT.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } +} diff --git a/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/Messages.java b/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/Messages.java new file mode 100644 index 0000000..ffcdec0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/Messages.java @@ -0,0 +1,11 @@ +//This file has been auto-generated +package flintstones.method.linguistic.elicit.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + public String Method_name; + public String Method_description; +} diff --git a/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/messages.properties b/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/messages.properties new file mode 100644 index 0000000..b085840 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/messages.properties @@ -0,0 +1,2 @@ +Method_name=ELICIT computational model +Method_description=Method which uses hesitant complex terms which are represented by means of 2-tuple diff --git a/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/messages_es.properties b/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/messages_es.properties new file mode 100644 index 0000000..5aa65c2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.elicit/src/flintstones/method/linguistic/elicit/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_name=Modelo computacional ELICIT +Method_description=Method which uses hesitant complex terms which are represented by means of 2-tuple diff --git a/bundles/flintstones.method.linguistic.hesitant/.classpath b/bundles/flintstones.method.linguistic.hesitant/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.hesitant/.polyglot.META-INF b/bundles/flintstones.method.linguistic.hesitant/.polyglot.META-INF new file mode 100644 index 0000000..60ade73 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.hesitant + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Hesitant + diff --git a/bundles/flintstones.method.linguistic.hesitant/.project b/bundles/flintstones.method.linguistic.hesitant/.project new file mode 100644 index 0000000..58d1c74 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.hesitant + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362676 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.hesitant/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.hesitant/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c48bc22 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Hesitant +Bundle-SymbolicName: flintstones.method.linguistic.hesitant;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.linguistic.hflts +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.hesitant, + flintstones.valuation.twoTuple, + flintstones.helper.faq diff --git a/bundles/flintstones.method.linguistic.hesitant/build.properties b/bundles/flintstones.method.linguistic.hesitant/build.properties new file mode 100644 index 0000000..e9d79c5 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + faq/ diff --git a/bundles/flintstones.method.linguistic.hesitant/faq/faq.en.md b/bundles/flintstones.method.linguistic.hesitant/faq/faq.en.md new file mode 100644 index 0000000..8d9facd --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/faq/faq.en.md @@ -0,0 +1 @@ +In real world there are many decision making problems in which the alternatives are defined by multiple criteria. There are different multicriteria decision making models that deal with comparative linguistic expressions and single linguistic terms, but they do not consider the retranslation process of the computing with words scheme to obtain linguistic results easily understood by human beings. Therefore, a multicriteria decision making model that deals with comparative linguistic expressions and uses the 2-tuple linguistic model to carry out the computing with words processes obtaining linguistic results comprehensible by experts involved in the problem was proposed. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hesitant/faq/faq.es.md b/bundles/flintstones.method.linguistic.hesitant/faq/faq.es.md new file mode 100644 index 0000000..8d9facd --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/faq/faq.es.md @@ -0,0 +1 @@ +In real world there are many decision making problems in which the alternatives are defined by multiple criteria. There are different multicriteria decision making models that deal with comparative linguistic expressions and single linguistic terms, but they do not consider the retranslation process of the computing with words scheme to obtain linguistic results easily understood by human beings. Therefore, a multicriteria decision making model that deals with comparative linguistic expressions and uses the 2-tuple linguistic model to carry out the computing with words processes obtaining linguistic results comprehensible by experts involved in the problem was proposed. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hesitant/plugin.xml b/bundles/flintstones.method.linguistic.hesitant/plugin.xml new file mode 100644 index 0000000..e77218c --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/plugin.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/HesitantMethod.java b/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/HesitantMethod.java new file mode 100644 index 0000000..35f6b8c --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/HesitantMethod.java @@ -0,0 +1,70 @@ +package flintstones.method.linguistic.hesitant; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.hesitant.messages.Messages; +import flintstones.valuation.hesitant.HesitantValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class HesitantMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; //$NON-NLS-1$ + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + int numDomains = domainService.getAll().length; + String numDomainEntity = messages.Numbers_of_domains; //$NON-NLS-1$ + String domainsEntity = domainMessages.Domain_entities; + + ValidBLTSDomainOperation validBLTSDomainOperation = new ValidBLTSDomainOperation(domainsEntity, + domainService.getAll()); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = new ValuationTypeOperation(valuationsEntity, + HesitantValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .equals(numDomainEntity, numDomains, 1) + .named("numDomains") //$NON-NLS-1$ + .named("domains")//$NON-NLS-1$ + .custom(validBLTSDomainOperation) + .named("domains")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations"); //$NON-NLS-1$ + } + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } +} diff --git a/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/Messages.java b/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/Messages.java new file mode 100644 index 0000000..56f9fc6 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/Messages.java @@ -0,0 +1,16 @@ +//This file has been auto-generated +package flintstones.method.linguistic.hesitant.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Method_category; + public String Method_description; + public String Numbers_of_domains; + public String Type_of_domain; + +} diff --git a/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/messages.properties b/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/messages.properties new file mode 100644 index 0000000..410c6c6 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/messages.properties @@ -0,0 +1,4 @@ +Numbers_of_domains=The number of domains +Type_of_domain=The type of domain +Method_name=Hesitant fuzzy linguistic information 2-tuple +Method_description=Method which uses hesitant complex terms \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/messages_es.properties b/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/messages_es.properties new file mode 100644 index 0000000..f051691 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hesitant/src/flintstones/method/linguistic/hesitant/messages/messages_es.properties @@ -0,0 +1,4 @@ +Numbers_of_domains=El nmero de dominios +Type_of_domain=El tipo del dominio +Method_name=Informacin Lingstica Difusa Dudosa 2-tuplas +Method_description=Mtodo que usa valoraciones hesitant \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/.classpath b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/.polyglot.META-INF b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.polyglot.META-INF new file mode 100644 index 0000000..9805096 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.heterogeneous.fusion + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] HeterogeneousFusion + diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/.project b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.project new file mode 100644 index 0000000..b6bd531 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.heterogeneous.fusion + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362677 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.heterogeneous.fusion/META-INF/MANIFEST.MF new file mode 100644 index 0000000..72ec609 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.linguistic.heterogeneous.fusion;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.heterogeneous.fusion +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.twoTuple, + flintstones.helper.faq, + flintstones.valuation.numeric.real, + flintstones.valuation.numeric.integer, + flintstones.valuation.numeric.real.interval, + flintstones.valuation.numeric.integer.interval diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.linguistic.heterogeneous.fusion/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..37626cd --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.heterogeneous.fusion +Bundle-Name = HeterogeneousFusion \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.linguistic.heterogeneous.fusion/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..37626cd --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.heterogeneous.fusion +Bundle-Name = HeterogeneousFusion \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/build.properties b/bundles/flintstones.method.linguistic.heterogeneous.fusion/build.properties new file mode 100644 index 0000000..4abcbd2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/faq/faq.en.md b/bundles/flintstones.method.linguistic.heterogeneous.fusion/faq/faq.en.md new file mode 100644 index 0000000..02b7eb5 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/faq/faq.en.md @@ -0,0 +1 @@ +In decision making may occur when experts elicit their knowledge with nonhomegenous information such as numerical, linguistic, interval-valued and so on. In decision problems with multiple experts or criteria this is not a rare situation. For this type of framework a 2-tuple linguistic based model was introduced to manage and operate with such type of information. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/faq/faq.es.md b/bundles/flintstones.method.linguistic.heterogeneous.fusion/faq/faq.es.md new file mode 100644 index 0000000..02b7eb5 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/faq/faq.es.md @@ -0,0 +1 @@ +In decision making may occur when experts elicit their knowledge with nonhomegenous information such as numerical, linguistic, interval-valued and so on. In decision problems with multiple experts or criteria this is not a rare situation. For this type of framework a 2-tuple linguistic based model was introduced to manage and operate with such type of information. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/plugin.xml b/bundles/flintstones.method.linguistic.heterogeneous.fusion/plugin.xml new file mode 100644 index 0000000..1ae91e4 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/plugin.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/problem/ejemplo_libro.flintstones b/bundles/flintstones.method.linguistic.heterogeneous.fusion/problem/ejemplo_libro.flintstones new file mode 100644 index 0000000..6cf03cf --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/problem/ejemplo_libro.flintstones @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/HeterogeneousFusionMethod.java b/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/HeterogeneousFusionMethod.java new file mode 100644 index 0000000..cfdaed5 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/HeterogeneousFusionMethod.java @@ -0,0 +1,92 @@ + +package flintstones.method.linguistic.heterogeneous.fusion; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.heterogeneous.fusion.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.numeric.integer.IntegerValuation; +import flintstones.valuation.numeric.integer.interval.IntegerIntervalValuation; +import flintstones.valuation.numeric.real.RealValuation; +import flintstones.valuation.numeric.real.interval.RealIntervalValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class HeterogeneousFusionMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private flintstones.entity.domain.messages.Messages domainMessages; + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_Name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + int numDomains = domainService.getAll().length; + String numDomainEntity = domainMessages.Domain_count; + + Domain[] fuzzysetDomains = domainService.getAll(FuzzySet.ID); + String fuzzysetDomainsEntity = domainMessages.Domain_type_entities; + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[5]; + validTypes[0] = RealValuation.class.getSimpleName(); + validTypes[1] = IntegerValuation.class.getSimpleName(); + validTypes[2] = RealIntervalValuation.class.getSimpleName(); + validTypes[3] = IntegerIntervalValuation.class.getSimpleName(); + validTypes[4] = LinguisticValuation.class.getSimpleName(); + + boolean superClass = false; + ValuationTypeOperation valuationTypeOperator = new ValuationTypeOperation(valuationsEntity, validTypes, + valuations, superClass); + + ValidBLTSDomainOperation validBLTSDomainOperation = new ValidBLTSDomainOperation(fuzzysetDomainsEntity, + fuzzysetDomains); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains")//$NON-NLS-1$ + .custom(validBLTSDomainOperation) + .named("fuzzySetDomains")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } +} diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/Messages.java b/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/Messages.java new file mode 100644 index 0000000..5208b6e --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/Messages.java @@ -0,0 +1,12 @@ +package flintstones.method.linguistic.heterogeneous.fusion.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_Name; + public String Method_Description; + +} diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/messages.properties b/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/messages.properties new file mode 100644 index 0000000..247de90 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/messages.properties @@ -0,0 +1,2 @@ +Method_Name=Fusion approach for managing heterogeneous information +Method_Description=F. Herrera, L. Martnez, P.J. Snchez, Managing non-homogeneous information in group decision making. European Journal of Operational Research, vol. 166, issue 1, pp. 115-132, 2005. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/messages_es.properties b/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/messages_es.properties new file mode 100644 index 0000000..5489318 --- /dev/null +++ b/bundles/flintstones.method.linguistic.heterogeneous.fusion/src/flintstones/method/linguistic/heterogeneous/fusion/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_Name=Enfoque de fusin para el manejo de informacin heterognea +Method_Description=F. Herrera, L. Martnez, P.J. Snchez, Managing non-homogeneous information in group decision making. European Journal of Operational Research, vol. 166, issue 1, pp. 115-132, 2005. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hflts/.classpath b/bundles/flintstones.method.linguistic.hflts/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.hflts/.polyglot.META-INF b/bundles/flintstones.method.linguistic.hflts/.polyglot.META-INF new file mode 100644 index 0000000..e189355 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.hflts + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] HFLTS + diff --git a/bundles/flintstones.method.linguistic.hflts/.project b/bundles/flintstones.method.linguistic.hflts/.project new file mode 100644 index 0000000..2755eb8 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.hflts + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362677 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.hflts/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.hflts/META-INF/MANIFEST.MF new file mode 100644 index 0000000..263bc9b --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.linguistic.hflts;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.linguistic.hflts +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.hesitant, + flintstones.helper.faq diff --git a/bundles/flintstones.method.linguistic.hflts/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.linguistic.hflts/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..8ce9b1d --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.hflts +Bundle-Name = HFLTS \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hflts/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.linguistic.hflts/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..8ce9b1d --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.hflts +Bundle-Name = HFLTS \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hflts/build.properties b/bundles/flintstones.method.linguistic.hflts/build.properties new file mode 100644 index 0000000..4abcbd2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.linguistic.hflts/faq/faq.en.md b/bundles/flintstones.method.linguistic.hflts/faq/faq.en.md new file mode 100644 index 0000000..fb9d858 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/faq/faq.en.md @@ -0,0 +1 @@ +It might happen that experts hesitate among several linguistic terms to assess a linguistic variable because they do not have enough knowledge or information to provide their assessments using only one linguistic term. In such hesitant decision situations, experts hesitate among different linguistic terms and they would like to use more complex linguistic expressions which cannot be built by the classical approaches. This limitation is due to the use of linguistic terms defined a priori and because most of linguistic approaches model the information by using only one linguistic term. In order to overcome this limitation the concept of hesitant fuzzy linguistic term set based on the fuzzy linguistic approach was introduced. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hflts/faq/faq.es.md b/bundles/flintstones.method.linguistic.hflts/faq/faq.es.md new file mode 100644 index 0000000..fb9d858 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/faq/faq.es.md @@ -0,0 +1 @@ +It might happen that experts hesitate among several linguistic terms to assess a linguistic variable because they do not have enough knowledge or information to provide their assessments using only one linguistic term. In such hesitant decision situations, experts hesitate among different linguistic terms and they would like to use more complex linguistic expressions which cannot be built by the classical approaches. This limitation is due to the use of linguistic terms defined a priori and because most of linguistic approaches model the information by using only one linguistic term. In order to overcome this limitation the concept of hesitant fuzzy linguistic term set based on the fuzzy linguistic approach was introduced. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hflts/plugin.xml b/bundles/flintstones.method.linguistic.hflts/plugin.xml new file mode 100644 index 0000000..74f4e3e --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/plugin.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/HFLTS.java b/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/HFLTS.java new file mode 100644 index 0000000..0aff46c --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/HFLTS.java @@ -0,0 +1,76 @@ +package flintstones.method.linguistic.hflts; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.method.Method; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.hflts.messages.Messages; +import flintstones.valuation.hesitant.HesitantValuation; + +public class HFLTS extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + int numExperts = problemService.getAll(Expert.Type).length; + String numExpertEntity = messages.Number_of_experts; + + int numDomains = domainService.getAll().length; + String numDomainEntity = messages.Number_of_domains; + String domainsEntity = domainMessages.Domain_entities; + + ValidBLTSDomainOperation validBLTSDomainOperation = new ValidBLTSDomainOperation(domainsEntity, + domainService.getAll()); + ContextInjectionFactory.inject(validBLTSDomainOperation, context); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = new ValuationTypeOperation(valuationsEntity, + HesitantValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .equals(numExpertEntity, numExperts, 1) + .named("numExperts") //$NON-NLS-1$ + .equals(numDomainEntity, numDomains, 1) + .named("numDomains") //$NON-NLS-1$ + .custom(validBLTSDomainOperation) + .named("domains")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations"); //$NON-NLS-1$ + + } + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, HesitantValuation.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } +} diff --git a/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/Messages.java b/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/Messages.java new file mode 100644 index 0000000..ead2789 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/Messages.java @@ -0,0 +1,16 @@ +//This file has been auto-generated +package flintstones.method.linguistic.hflts.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Method_description; + public String Number_of_experts; + public String Number_of_domains; + public String Type_of_domain; + +} diff --git a/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/messages.properties b/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/messages.properties new file mode 100644 index 0000000..d29e27f --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/messages.properties @@ -0,0 +1,7 @@ +Number_of_domains=Number of domains +Number_of_experts=Number of experts +Type_of_domain=The type of domain +Method_name=Hesitant Fuzzy Linguistic Term Set (HFLTS) +Method_description=R.M. Rodrguez, L. Martnez, F. Herrera, Hesitant Fuzzy Linguistic Term Sets for Decision Making. IEEE Transactions on Fuzzy Systems, vol. 20, issue 1, pp. 109-119, 2012. +SecondPhase_name=Overview +SecondPhase_name=Results \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/messages_es.properties b/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/messages_es.properties new file mode 100644 index 0000000..f9f3c62 --- /dev/null +++ b/bundles/flintstones.method.linguistic.hflts/src/flintstones/method/linguistic/hflts/messages/messages_es.properties @@ -0,0 +1,7 @@ +Number_of_domains=El nmero de dominios +Number_of_experts=El nmero de expertos +Type_of_domain=El tipo del dominio +Method_name=Conjunto de trminos lingsticos difusos dudosos (HFLTS) +Method_description=R.M. Rodrguez, L. Martnez, F. Herrera, Hesitant Fuzzy Linguistic Term Sets for Decision Making. IEEE Transactions on Fuzzy Systems, vol. 20, issue 1, pp. 109-119, 2012. +FirstPhase_name=Visualizacin +SecondPhase_name=Resultados \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/.classpath b/bundles/flintstones.method.linguistic.multigranular.elh/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/.polyglot.META-INF b/bundles/flintstones.method.linguistic.multigranular.elh/.polyglot.META-INF new file mode 100644 index 0000000..b3d539e --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.multigranular.elh + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] ELH + diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/.project b/bundles/flintstones.method.linguistic.multigranular.elh/.project new file mode 100644 index 0000000..e0166a8 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.multigranular.elh + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362678 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.multigranular.elh/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3564cab --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.linguistic.multigranular.elh;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.multigranular.elh +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.domain.fuzzyset, + flintstones.valuation.twoTuple, + flintstones.helper.faq diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.linguistic.multigranular.elh/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..1950480 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.multigranular.elh +Bundle-Name = ELH \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.linguistic.multigranular.elh/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..1950480 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.multigranular.elh +Bundle-Name = ELH \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/build.properties b/bundles/flintstones.method.linguistic.multigranular.elh/build.properties new file mode 100644 index 0000000..4abcbd2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/faq/faq.en.md b/bundles/flintstones.method.linguistic.multigranular.elh/faq/faq.en.md new file mode 100644 index 0000000..ff23a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/faq/faq.en.md @@ -0,0 +1 @@ +Linguistic hierarchies provides accuracy for computing with multigranular linguistic information, however, it still presents an important limitation regarding the linguistic term sets that can be used in the framework that the fusion approach did not present. In order to overcome such a limitation, an extended model was proposed that builds a structure, the extended linguistic hierarchy. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/faq/faq.es.md b/bundles/flintstones.method.linguistic.multigranular.elh/faq/faq.es.md new file mode 100644 index 0000000..ff23a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/faq/faq.es.md @@ -0,0 +1 @@ +Linguistic hierarchies provides accuracy for computing with multigranular linguistic information, however, it still presents an important limitation regarding the linguistic term sets that can be used in the framework that the fusion approach did not present. In order to overcome such a limitation, an extended model was proposed that builds a structure, the extended linguistic hierarchy. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/plugin.xml b/bundles/flintstones.method.linguistic.multigranular.elh/plugin.xml new file mode 100644 index 0000000..24301ab --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/plugin.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/problem/ejemplo_libro.flintstones b/bundles/flintstones.method.linguistic.multigranular.elh/problem/ejemplo_libro.flintstones new file mode 100644 index 0000000..dd971c9 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/problem/ejemplo_libro.flintstones @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/ExtendedLinguisticHerarchiesMethod.java b/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/ExtendedLinguisticHerarchiesMethod.java new file mode 100644 index 0000000..d6b0514 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/ExtendedLinguisticHerarchiesMethod.java @@ -0,0 +1,83 @@ +package flintstones.method.linguistic.multigranular.elh; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.CompatibleCardinalitiesOperation; +import flintstones.helper.chainvalidator.operation.method.DomainTypeOperation; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.multigranular.elh.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class ExtendedLinguisticHerarchiesMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Domain[] domains = domainService.getAll(); + int numDomains = domains.length; + Valuation[] valuations = valuationService.getAll(); + + String domainsEntity = domainMessages.Domain_entities; + String numDomainEntity = domainMessages.Domain_count; + String valuationsEntity = valuationMessages.Valuation_entity; + + DomainTypeOperation domainTypeOperation = new DomainTypeOperation(domainsEntity, FuzzySet.class.getSimpleName(), domains); + + ValidBLTSDomainOperation validBLTSDomainOperator = new ValidBLTSDomainOperation(domainsEntity, domains); + + CompatibleCardinalitiesOperation compatibleCardinalitiesOperation = new CompatibleCardinalitiesOperation(domainsEntity, domains); + + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, LinguisticValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains")//$NON-NLS-1$ + .custom(domainTypeOperation) + .named("domainType", "domains")//$NON-NLS-1$ $NON-NLS-2$ + .custom(validBLTSDomainOperator) + .named("domains")//$NON-NLS-1$ + .custom(compatibleCardinalitiesOperation) + .named("domains")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } +} diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/Messages.java b/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/Messages.java new file mode 100644 index 0000000..b9529db --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/Messages.java @@ -0,0 +1,12 @@ +package flintstones.method.linguistic.multigranular.elh.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Method_Description; + +} diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/messages.properties b/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/messages.properties new file mode 100644 index 0000000..592953e --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/messages.properties @@ -0,0 +1,2 @@ +Method_name=Extended Linguistic Hierarchies +Method_Description=[flintstones.method.multigranular.lh.messages] \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/messages_es.properties b/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/messages_es.properties new file mode 100644 index 0000000..96b1fe5 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.elh/src/flintstones/method/linguistic/multigranular/elh/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_name=Jerarquas Lingsticas Extendidas +Method_Description=xxxx \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/.classpath b/bundles/flintstones.method.linguistic.multigranular.fusion/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/.polyglot.META-INF b/bundles/flintstones.method.linguistic.multigranular.fusion/.polyglot.META-INF new file mode 100644 index 0000000..d002450 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.multigranular.fusion + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Multi-granular fusion + + Sinbad2 + + diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/.project b/bundles/flintstones.method.linguistic.multigranular.fusion/.project new file mode 100644 index 0000000..8fc4034 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.multigranular.fusion + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362678 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.multigranular.fusion/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b792334 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.linguistic.multigranular.fusion;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: %Bundle-Vendor +Automatic-Module-Name: flintstones.method.multigranular.fusion +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.domain.fuzzyset, + flintstones.valuation.twoTuple, + flintstones.helper.faq diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.linguistic.multigranular.fusion/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..cde1955 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,3 @@ +#Properties file for flintstones.method.linguistic.multigranular.fusion +Bundle-Vendor = Sinbad2 +Bundle-Name = Multi-granular fusion \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.linguistic.multigranular.fusion/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..cde1955 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,3 @@ +#Properties file for flintstones.method.linguistic.multigranular.fusion +Bundle-Vendor = Sinbad2 +Bundle-Name = Multi-granular fusion \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/build.properties b/bundles/flintstones.method.linguistic.multigranular.fusion/build.properties new file mode 100644 index 0000000..4abcbd2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/faq/faq.en.md b/bundles/flintstones.method.linguistic.multigranular.fusion/faq/faq.en.md new file mode 100644 index 0000000..154fd64 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/faq/faq.en.md @@ -0,0 +1 @@ +This approach deals with decision frameworks in which the linguistic information would be assessed in multiple linguistic scales without any constraint. It uses the extension principle, the 2-tuple linguistic model, and its computing model. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/faq/faq.es.md b/bundles/flintstones.method.linguistic.multigranular.fusion/faq/faq.es.md new file mode 100644 index 0000000..154fd64 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/faq/faq.es.md @@ -0,0 +1 @@ +This approach deals with decision frameworks in which the linguistic information would be assessed in multiple linguistic scales without any constraint. It uses the extension principle, the 2-tuple linguistic model, and its computing model. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/plugin.xml b/bundles/flintstones.method.linguistic.multigranular.fusion/plugin.xml new file mode 100644 index 0000000..e1bea66 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/problem/ejemplo_libro.flintstones b/bundles/flintstones.method.linguistic.multigranular.fusion/problem/ejemplo_libro.flintstones new file mode 100644 index 0000000..89fed68 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/problem/ejemplo_libro.flintstones @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/MultigranularFusionMethod.java b/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/MultigranularFusionMethod.java new file mode 100644 index 0000000..f552d7c --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/MultigranularFusionMethod.java @@ -0,0 +1,80 @@ + +package flintstones.method.linguistic.multigranular.fusion; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.DomainTypeOperation; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.multigranular.fusion.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class MultigranularFusionMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Domain[] domains = domainService.getAll(); + int numDomains = domains.length; + Valuation[] valuations = valuationService.getAll(); + + String domainsEntity = domainMessages.Domain_entities; + String numDomainEntity = domainMessages.Domain_count; + String valuationsEntity = valuationMessages.Valuation_entity; + + DomainTypeOperation domainTypeOperation = new DomainTypeOperation(domainsEntity, FuzzySet.class.getSimpleName(), domains); + + ValidBLTSDomainOperation validBLTSDomainOperation = new ValidBLTSDomainOperation(domainsEntity, domains); + + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, LinguisticValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains") //$NON-NLS-1$ + .custom(domainTypeOperation) + .named("domainType", "domains")//$NON-NLS-1$ $NON-NLS-2$ + .custom(validBLTSDomainOperation) + .named("domains")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } + +} diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/Messages.java b/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/Messages.java new file mode 100644 index 0000000..309a597 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/Messages.java @@ -0,0 +1,12 @@ +package flintstones.method.linguistic.multigranular.fusion.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Method_Description; + +} diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/messages.properties b/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/messages.properties new file mode 100644 index 0000000..4b91352 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/messages.properties @@ -0,0 +1,2 @@ +Method_name=Fusion approach for managing multi-granular linguistic information +Method_Description=F. Herrera, E. Herrera-Viedma, L. Mart�nez, A Fusion Approach for Managing Multi-Granularity Linguistic Term Sets in Decision Making. Fuzzy Sets and Systems, vol. 114, issue 1, pp. 43-58, 2000. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/messages_es.properties b/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/messages_es.properties new file mode 100644 index 0000000..7565863 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.fusion/src/flintstones/method/linguistic/multigranular/fusion/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_name=Enfoque de fusin para la manipulacin de informacin lingstica multigranular +Method_Description=F. Herrera, E. Herrera-Viedma, L. Martnez, A Fusion Approach for Managing Multi-Granularity Linguistic Term Sets in Decision Making. Fuzzy Sets and Systems, vol. 114, issue 1, pp. 43-58, 2000. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/.classpath b/bundles/flintstones.method.linguistic.multigranular.lh/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/.polyglot.META-INF b/bundles/flintstones.method.linguistic.multigranular.lh/.polyglot.META-INF new file mode 100644 index 0000000..63da1b8 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.multigranular.lh + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] LH + diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/.project b/bundles/flintstones.method.linguistic.multigranular.lh/.project new file mode 100644 index 0000000..e73e47a --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.multigranular.lh + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362679 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.multigranular.lh/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0581235 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.linguistic.multigranular.lh;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.multigranular.lh +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.domain.fuzzyset, + flintstones.valuation.twoTuple, + flintstones.helper.faq diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.linguistic.multigranular.lh/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..17fdfee --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.multigranular.lh +Bundle-Name = LH \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.linguistic.multigranular.lh/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..17fdfee --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.multigranular.lh +Bundle-Name = LH \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/build.properties b/bundles/flintstones.method.linguistic.multigranular.lh/build.properties new file mode 100644 index 0000000..4abcbd2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/faq/faq.en.md b/bundles/flintstones.method.linguistic.multigranular.lh/faq/faq.en.md new file mode 100644 index 0000000..2be690a --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/faq/faq.en.md @@ -0,0 +1 @@ +This approach improves accuracy in the transformation from fuzzy set to linguistic values in the unification phase to deal with multigranular linguistic information in a symbolic a precise way. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/faq/faq.es.md b/bundles/flintstones.method.linguistic.multigranular.lh/faq/faq.es.md new file mode 100644 index 0000000..2be690a --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/faq/faq.es.md @@ -0,0 +1 @@ +This approach improves accuracy in the transformation from fuzzy set to linguistic values in the unification phase to deal with multigranular linguistic information in a symbolic a precise way. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/plugin.xml b/bundles/flintstones.method.linguistic.multigranular.lh/plugin.xml new file mode 100644 index 0000000..e0c1731 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/problem/ejemplo_libro.flintstones b/bundles/flintstones.method.linguistic.multigranular.lh/problem/ejemplo_libro.flintstones new file mode 100644 index 0000000..08d121d --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/problem/ejemplo_libro.flintstones @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/LinguisticHierarchiesMethod.java b/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/LinguisticHierarchiesMethod.java new file mode 100644 index 0000000..2adb08f --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/LinguisticHierarchiesMethod.java @@ -0,0 +1,90 @@ +package flintstones.method.linguistic.multigranular.lh; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.BuildableLinguisticHierarchyOperation; +import flintstones.helper.chainvalidator.operation.method.CompatibleCardinalitiesOperation; +import flintstones.helper.chainvalidator.operation.method.DomainTypeOperation; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.multigranular.lh.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class LinguisticHierarchiesMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Domain[] domains = domainService.getAll(); + int numDomains = domains.length; + Valuation[] valuations = valuationService.getAll(); + + String numDomainEntity = domainMessages.Domain_count; + String domainsEntity = domainMessages.Domain_entities; + String valuationsEntity = valuationMessages.Valuation_entity; + + DomainTypeOperation domainTypeOperation = new DomainTypeOperation(domainsEntity, + FuzzySet.class.getSimpleName(), domains); + + ValidBLTSDomainOperation validBLTSDomainOperator = new ValidBLTSDomainOperation(domainsEntity, domains); + + CompatibleCardinalitiesOperation compatibleCardinalitiesOperation = + new CompatibleCardinalitiesOperation(domainsEntity, domains); + + BuildableLinguisticHierarchyOperation buildableLinguisticHierarchyOperation = + new BuildableLinguisticHierarchyOperation(domainsEntity, domains); + + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, LinguisticValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains")//$NON-NLS-1$ + .custom(domainTypeOperation) + .named("domainType", "domains")//$NON-NLS-1$ $NON-NLS-2$ + .custom(validBLTSDomainOperator) + .named( "domains" )//$NON-NLS-1$ + .custom(compatibleCardinalitiesOperation) + .named("domains")//$NON-NLS-1$ + .custom(buildableLinguisticHierarchyOperation) + .named("domains")//$NON-NLS-1$ + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + } + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } +} diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/Messages.java b/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/Messages.java new file mode 100644 index 0000000..56a5567 --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/Messages.java @@ -0,0 +1,12 @@ +package flintstones.method.linguistic.multigranular.lh.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Method_Description; + +} diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/messages.properties b/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/messages.properties new file mode 100644 index 0000000..d2561da --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/messages.properties @@ -0,0 +1,2 @@ +Method_name=Linguistic Hierarchies +Method_Description=F. Herrera, L. Martnez, A model based on linguistic 2-tuples for dealing with multigranularity hierarchical linguistic contexts in Multiexpert Decision-Making. IEEE Transactions on Systems, Man and Cybernetics. Part B: Cybernetics, vol. 31, issue 2, pp. 227-234, 2001. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/messages_es.properties b/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/messages_es.properties new file mode 100644 index 0000000..1a3987c --- /dev/null +++ b/bundles/flintstones.method.linguistic.multigranular.lh/src/flintstones/method/linguistic/multigranular/lh/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_name=Jerarquas Lingsticas +Method_Description=F. Herrera, L. Martnez, A model based on linguistic 2-tuples for dealing with multigranularity hierarchical linguistic contexts in Multiexpert Decision-Making. IEEE Transactions on Systems, Man and Cybernetics. Part B: Cybernetics, vol. 31, issue 2, pp. 227-234, 2001. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.classpath b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.polyglot.META-INF b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.polyglot.META-INF new file mode 100644 index 0000000..93ac091 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.topsis.phase.collective.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Collective phase UI + + Sinbad2 + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.project b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.project new file mode 100644 index 0000000..769ad53 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.topsis.phase.collective.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362681 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..df169a1 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Collective phase UI +Bundle-SymbolicName: flintstones.method.linguistic.topsis.phase.collective.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.linguistic.topsis.phase.collective.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.method.linguistic.topsis.phase.collective, + flintstones.entity.method.phase, + org.eclipse.swt, + flintstones.model.ui.service, + de.kupzog.ktable diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/build.properties b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/plugin.xml b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/plugin.xml new file mode 100644 index 0000000..3960632 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/CollectiveInfoUI.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/CollectiveInfoUI.java new file mode 100644 index 0000000..0d5b44a --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/CollectiveInfoUI.java @@ -0,0 +1,223 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.CollectiveClosenessCoefficientTable; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.CollectiveDistanceNegativeIdealSolutionTable; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.CollectiveDistancePositiveIdealSolutionTable; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.CollectiveDistanceSolutionsTable; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.CollectiveNegativeIdealSolutionTable; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.CollectivePositiveIdealSolutionTable; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.DecisionMatrixTable; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.ExpertWeightsTable; +import flintstones.model.ui.service.UiService; + +public class CollectiveInfoUI extends PhaseMethodUI { + + private CollectiveInfo model; + + private DecisionMatrixTable decisionMatrixTable; + private ExpertWeightsTable weightsTable; + private CollectivePositiveIdealSolutionTable positiveIdealSolutionTable; + private CollectiveNegativeIdealSolutionTable negativeIdealSolutionTable; + private CollectiveDistancePositiveIdealSolutionTable distancePositiveIdealSolutionTable; + private CollectiveDistanceNegativeIdealSolutionTable distanceNegativeIdealSolutionTable; + private CollectiveDistanceSolutionsTable distanceSolutionsTable; + private CollectiveClosenessCoefficientTable closenessCoefficientTable; + + @Override + public void init() { + model = (CollectiveInfo) this.getModel(); + + Composite parent = this.getBaseComposite(); + GridLayout layout = UiService.setGridLayout(parent, 1, true); + UiService.setGridData(parent, 9, 9, true, true); + layout.horizontalSpacing = 15; + layout.verticalSpacing = 15; + + createPartControl(parent); + + model.execute(); + } + + private void createPartControl(Composite parent) { + createWeightedInfoTables(parent); + createSolutionsInfoTables(parent); + createDistancesSolutionInfo(parent); + createGlobalSolutionInfo(parent); + //createSolutionDomainCombo(parent); + } + + private void createWeightedInfoTables(Composite parent) { + Composite tablesComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(tablesComposite, 2, true); + UiService.setGridData(tablesComposite, 9, 9, true, false); + + createExpertWeightsTable(tablesComposite); + createWeightedDecisionMatrixTable(tablesComposite); + } + + private void createExpertWeightsTable(Composite tablesComposite) { + Composite weightsComposite = new Composite(tablesComposite, SWT.NONE); + UiService.setGridLayout(weightsComposite, 1, true); + UiService.setGridData(weightsComposite, 9, 9, true, false); + + weightsTable = new ExpertWeightsTable(weightsComposite); + UiService.setGridData(weightsTable, 9, 9, true, true); + weightsTable.setModel(model); + + createDomainWeightsCombo(weightsComposite); + } + + private void createDomainWeightsCombo(Composite weightsComposite) { + Composite selectUnificationComboComposite = new Composite(weightsComposite, SWT.NONE); + UiService.setGridLayout(selectUnificationComboComposite, 2, false); + UiService.setGridData(selectUnificationComboComposite, -1, 9, true, true); + + Label label = new Label(selectUnificationComboComposite, SWT.NONE); + UiService.setGridData(label, -1, -1, false, true); + label.setText("Select the domain for experts' weights:"); + + Combo selectUnificationDomainCombo = new Combo(selectUnificationComboComposite, SWT.BORDER); + GridData grid = UiService.setGridData(selectUnificationDomainCombo, -1, -1, false, true); + grid.verticalIndent = 15; + selectUnificationDomainCombo.setItems(model.getLinguisticDomainNames()); + selectUnificationDomainCombo.select(0); + model.setDomainWeights(selectUnificationDomainCombo.getText()); + + selectUnificationDomainCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.setDomainWeights(selectUnificationDomainCombo.getText()); + model.execute(); + refresh(); + } + }); + } + + private void createWeightedDecisionMatrixTable(Composite tablesComposite) { + Composite decisionMatrixComposite = new Composite(tablesComposite, SWT.NONE); + UiService.setGridLayout(decisionMatrixComposite, 1, true); + UiService.setGridData(decisionMatrixComposite, 9, 9, true, true); + + decisionMatrixTable = new DecisionMatrixTable(decisionMatrixComposite); + UiService.setGridData(decisionMatrixTable, 9, 9, true, true); + decisionMatrixTable.setModel(model); + weightsTable.setDecisionMatrixTable(decisionMatrixTable);//To update the table when weights change + } + + private void createSolutionsInfoTables(Composite parent) { + Composite solutionsTablesComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(solutionsTablesComposite, 2, true); + UiService.setGridData(solutionsTablesComposite, 9, 1, true, false); + + createPositiveIdealSolutionTable(solutionsTablesComposite); + createNegativeIdealSolutionTable(solutionsTablesComposite); + } + + private void createPositiveIdealSolutionTable(Composite solutionsTablesComposite) { + positiveIdealSolutionTable = new CollectivePositiveIdealSolutionTable(solutionsTablesComposite); + UiService.setGridData(positiveIdealSolutionTable, 9, 9, true, true); + positiveIdealSolutionTable.setModel(model); + } + + private void createNegativeIdealSolutionTable(Composite solutionsTablesComposite) { + negativeIdealSolutionTable = new CollectiveNegativeIdealSolutionTable(solutionsTablesComposite); + UiService.setGridData(negativeIdealSolutionTable, 9, 9, true, true); + negativeIdealSolutionTable.setModel(model); + } + + private void createDistancesSolutionInfo(Composite parent) { + Composite distanceSolutionsTablesComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(distanceSolutionsTablesComposite, 2, true); + GridData gd = UiService.setGridData(distanceSolutionsTablesComposite, 9, 9, true, true); + gd.heightHint = 25; + + createDistancePositiveIdealSolutionTable(distanceSolutionsTablesComposite); + createDistanceNegativeIdealSolutionTable(distanceSolutionsTablesComposite); + } + + private void createDistancePositiveIdealSolutionTable(Composite distanceSolutionsTablesComposite) { + distancePositiveIdealSolutionTable = new CollectiveDistancePositiveIdealSolutionTable(distanceSolutionsTablesComposite); + UiService.setGridData(distancePositiveIdealSolutionTable, 9, 9, true, true); + distancePositiveIdealSolutionTable.setModel(model); + } + + private void createDistanceNegativeIdealSolutionTable(Composite distanceSolutionsTablesComposite) { + distanceNegativeIdealSolutionTable = new CollectiveDistanceNegativeIdealSolutionTable(distanceSolutionsTablesComposite); + UiService.setGridData(distanceNegativeIdealSolutionTable, 9, 9, true, true); + distanceNegativeIdealSolutionTable.setModel(model); + } + + private void createGlobalSolutionInfo(Composite parent) { + Composite globalSolutionsComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(globalSolutionsComposite, 2, true); + GridData gd = UiService.setGridData(globalSolutionsComposite, 9, 9, true, true); + gd.heightHint = 25; + + createGlobalDistanceSolutionTable(globalSolutionsComposite); + createClosenessCoefficientTable(globalSolutionsComposite); + } + + private void createGlobalDistanceSolutionTable(Composite globalSolutionsComposite) { + distanceSolutionsTable = new CollectiveDistanceSolutionsTable(globalSolutionsComposite); + UiService.setGridData(distanceSolutionsTable, 9, 9, true, true); + distanceSolutionsTable.setModel(model); + } + + private void createClosenessCoefficientTable(Composite globalSolutionsComposite) { + closenessCoefficientTable = new CollectiveClosenessCoefficientTable(globalSolutionsComposite); + UiService.setGridData(closenessCoefficientTable, 9, 9, true, true); + closenessCoefficientTable.setModel(model); + } + + /*private void createSolutionDomainCombo(Composite parent) { + Composite resultsDomainComposite = new Composite(parent, SWT.BORDER); + UiService.setGridLayout(resultsDomainComposite, 1, true); + UiService.setGridData(resultsDomainComposite, 1, 1, false, false); + + Combo resultsDomainCombo = new Combo(resultsDomainComposite, SWT.NONE); + UiService.setGridData(resultsDomainCombo, -1, -1, false, true); + resultsDomainCombo.setItems(model.getLinguisticDomainNames()); + resultsDomainCombo.select(0); + + resultsDomainCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.setClosenessCoefficientsDomain(resultsDomainCombo.getText()); + closenessCoefficientTable.redraw(); + } + }); + }*/ + + @Override + public void refresh() { + + if(model.distanceDomainChanged() || model.valuationDomainChanged()) + model.execute(); + + weightsTable.redraw(); + decisionMatrixTable.redraw(); + positiveIdealSolutionTable.redraw(); + negativeIdealSolutionTable.redraw(); + distancePositiveIdealSolutionTable.redraw(); + distanceNegativeIdealSolutionTable.redraw(); + distanceSolutionsTable.redraw(); + closenessCoefficientTable.redraw(); + } + + @Override + protected boolean isForwardEnabled() { + return false; + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveAntiIdealSolutionContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveAntiIdealSolutionContentProvider.java new file mode 100644 index 0000000..c14b51d --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveAntiIdealSolutionContentProvider.java @@ -0,0 +1,170 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; + +public class CollectiveAntiIdealSolutionContentProvider extends KTableNoScrollModel { + + private KTable table; + + private CollectiveInfo model; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public CollectiveAntiIdealSolutionContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, CollectiveInfo model) { + this.table = table; + this.model = model; + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberExperts() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Negative ideal solution"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = "Valuation"; + else if (row == 0) + content = expertAbbreviation(col); + else + content = model.getStringNegativeIdealSolutionExpert(col - 1); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object expertAbbreviation(int pos) { + return "E" + pos; + } + + @Override + public int doGetRowCount() { + return 1 + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if(col == 0 && row == 0) { + return ""; + } else if (row < getFixedRowCount()) { + return model.getExpertName(col - 1); + } else { + return model.getStringNegativeIdealSolutionExpert(col - 1); + } + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveClosenessCoefficientContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveClosenessCoefficientContentProvider.java new file mode 100644 index 0000000..219ee1e --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveClosenessCoefficientContentProvider.java @@ -0,0 +1,182 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; + +public class CollectiveClosenessCoefficientContentProvider extends KTableNoScrollModel { + + private KTable table; + + private CollectiveInfo model; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public CollectiveClosenessCoefficientContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, CollectiveInfo model) { + this.table = table; + this.model = model; + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return 2 + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Closeness coefficient"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + if(col == 1) + content = "Coefficient"; + else if(col == 2) + content = "Ranking"; + else + content = ""; + else { + if(col == 1) + content = model.getStringCollectiveClosenessCoefficient(row - 1); + else if (col == 2) + content = model.getStringRankingPositionAlternative(row - 1); + else + content = ""; + } + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return ""; + else + return (String) doGetContentAt(col, row); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceIAntiIdealSolutionContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceIAntiIdealSolutionContentProvider.java new file mode 100644 index 0000000..1320e9e --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceIAntiIdealSolutionContentProvider.java @@ -0,0 +1,175 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; + +public class CollectiveDistanceIAntiIdealSolutionContentProvider extends KTableNoScrollModel { + + private KTable table; + + private CollectiveInfo model; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public CollectiveDistanceIAntiIdealSolutionContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, CollectiveInfo model) { + this.table = table; + this.model = model; + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberExperts() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Dist (-)"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + content = expertAbbreviation(col); + else + content = model.getStringCollectiveDistanceNegativeIdealSolutionValuation(col - 1, row - 1); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object expertAbbreviation(int pos) { + return "E" + pos; + } + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return model.getExpertName(col - 1); + else + return (String) doGetContentAt(col, row); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceIdealSolutionContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceIdealSolutionContentProvider.java new file mode 100644 index 0000000..b63a255 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceIdealSolutionContentProvider.java @@ -0,0 +1,175 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; + +public class CollectiveDistanceIdealSolutionContentProvider extends KTableNoScrollModel { + + private KTable table; + + private CollectiveInfo model; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public CollectiveDistanceIdealSolutionContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, CollectiveInfo model) { + this.table = table; + this.model = model; + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberExperts() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Dist (+)"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + content = expertAbbreviation(col); + else + content = model.getStringCollectiveDistancePositiveIdealSolutionValuation(col - 1, row - 1); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object expertAbbreviation(int pos) { + return "E" + pos; + } + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return model.getExpertName(col - 1); + else + return (String) doGetContentAt(col, row); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceSolutionsContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceSolutionsContentProvider.java new file mode 100644 index 0000000..4d35a97 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveDistanceSolutionsContentProvider.java @@ -0,0 +1,184 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; + +public class CollectiveDistanceSolutionsContentProvider extends KTableNoScrollModel { + + private KTable table; + + private CollectiveInfo model; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public CollectiveDistanceSolutionsContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, CollectiveInfo model) { + this.table = table; + this.model = model; + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return 2 + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Distances"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + if(col == 1) + content = "Dist (+)"; + else if(col == 2) + content = "Dist (-)"; + else + content = ""; + else { + if(col == 1) + content = model.getStringCollectiveGlobalDistancePositiveIdealSolutionValuation(row - 1); + else if (col == 2) + content = model.getStringCollectiveGlobalDistanceNegativeIdealSolutionValuation(row - 1); + else + content = ""; + } + + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return ""; + else + return (String) doGetContentAt(col, row); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveIdealSolutionContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveIdealSolutionContentProvider.java new file mode 100644 index 0000000..75b019f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/CollectiveIdealSolutionContentProvider.java @@ -0,0 +1,172 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; + +public class CollectiveIdealSolutionContentProvider extends KTableNoScrollModel { + + private KTable table; + + private CollectiveInfo model; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public CollectiveIdealSolutionContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, CollectiveInfo model) { + this.table = table; + this.model = model; + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberExperts() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Positive ideal solution"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = "Valuation"; + else if (row == 0) + content = expertAbbreviation(col); + else + content = model.getStringPositiveIdealSolutionExpert(col - 1); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object expertAbbreviation(int pos) { + return "E" + pos; + } + + @Override + public int doGetRowCount() { + return 1 + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return ""; + } else if (row < getFixedRowCount()) { + return model.getExpertName(col - 1); + } else { + return model.getStringPositiveIdealSolutionExpert(col - 1); + } + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/DecisionMatrixContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/DecisionMatrixContentProvider.java new file mode 100644 index 0000000..2f22838 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/DecisionMatrixContentProvider.java @@ -0,0 +1,176 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; + +public class DecisionMatrixContentProvider extends KTableNoScrollModel { + + private KTable table; + + private CollectiveInfo model; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public DecisionMatrixContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, CollectiveInfo model) { + this.table = table; + this.model = model; + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberExperts() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Decision Matrix"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + content = expertAbbreviation(col); + else + content = model.getStringDecisionMatrixValuation(col - 1, row - 1); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object expertAbbreviation(int pos) { + return "E" + pos; + } + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return ""; + } else if (row < getFixedRowCount()) { + return model.getExpertName(col - 1); + } else { + return model.getStringNegativeIdealSolutionExpert(col - 1); + } + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/ExpertWeightsContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/ExpertWeightsContentProvider.java new file mode 100644 index 0000000..b8ca51a --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/provider/ExpertWeightsContentProvider.java @@ -0,0 +1,203 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.editors.KTableCellEditorCombo; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.table.DecisionMatrixTable; + +public class ExpertWeightsContentProvider extends KTableNoScrollModel { + + private KTable table; + private KTable decisionMatrixTable; + + private CollectiveInfo model; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + private class TableCellEditorCombo extends KTableCellEditorCombo { + @Override + protected void onKeyPressed(KeyEvent e) { + if(e.keyCode == 13) + this.close(true); + } + + @Override + public int getActivationSignals() { + return SINGLECLICK; + } + } + + private TableCellEditorCombo combo; + + public ExpertWeightsContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, CollectiveInfo model) { + this.table = table; + this.model = model; + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + public void setDecisionMatrixTable(DecisionMatrixTable decisionMatrixTable) { + this.decisionMatrixTable = decisionMatrixTable; + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + + if (col != 0 && row != 0) { + combo = new TableCellEditorCombo(); + combo.setItems(model.getLinguisticLabelsNameDomain()); + return combo; + } + + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberExperts() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Weights"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = "Weight"; + else if (row == 0) + content = expertAbbreviation(col - 1); + else + content = model.getStringExpertWeight(col - 1); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object expertAbbreviation(int pos) { + return "E" + (pos + 1); + } + + @Override + public int doGetRowCount() { + return getFixedRowCount() + 1; + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + model.setExpertWeight(col - 1, (String) value); + model.execute(); + table.redraw(); + decisionMatrixTable.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return ""; + } else if (row < getFixedRowCount()) + return model.getExpertName(col - 1); + else + return model.getExpertName(col - 1) + " / " + model.getStringExpertWeight(col - 1); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveClosenessCoefficientTable.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveClosenessCoefficientTable.java new file mode 100644 index 0000000..5f2c9a5 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveClosenessCoefficientTable.java @@ -0,0 +1,34 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.provider.CollectiveClosenessCoefficientContentProvider; + +public class CollectiveClosenessCoefficientTable extends KTable { + + CollectiveClosenessCoefficientContentProvider provider; + + public CollectiveClosenessCoefficientTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(CollectiveInfo phase) { + provider = new CollectiveClosenessCoefficientContentProvider(this); + provider.init(this, phase); + + setModel(provider); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistanceNegativeIdealSolutionTable.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistanceNegativeIdealSolutionTable.java new file mode 100644 index 0000000..387523c --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistanceNegativeIdealSolutionTable.java @@ -0,0 +1,34 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.provider.CollectiveDistanceIAntiIdealSolutionContentProvider; + +public class CollectiveDistanceNegativeIdealSolutionTable extends KTable { + + CollectiveDistanceIAntiIdealSolutionContentProvider provider; + + public CollectiveDistanceNegativeIdealSolutionTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(CollectiveInfo phase) { + provider = new CollectiveDistanceIAntiIdealSolutionContentProvider(this); + provider.init(this, phase); + + setModel(provider); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistancePositiveIdealSolutionTable.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistancePositiveIdealSolutionTable.java new file mode 100644 index 0000000..f60c486 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistancePositiveIdealSolutionTable.java @@ -0,0 +1,34 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.provider.CollectiveDistanceIdealSolutionContentProvider; + +public class CollectiveDistancePositiveIdealSolutionTable extends KTable { + + CollectiveDistanceIdealSolutionContentProvider provider; + + public CollectiveDistancePositiveIdealSolutionTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(CollectiveInfo phase) { + provider = new CollectiveDistanceIdealSolutionContentProvider(this); + provider.init(this, phase); + + setModel(provider); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistanceSolutionsTable.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistanceSolutionsTable.java new file mode 100644 index 0000000..7545841 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveDistanceSolutionsTable.java @@ -0,0 +1,34 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.provider.CollectiveDistanceSolutionsContentProvider; + +public class CollectiveDistanceSolutionsTable extends KTable { + + CollectiveDistanceSolutionsContentProvider provider; + + public CollectiveDistanceSolutionsTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(CollectiveInfo phase) { + provider = new CollectiveDistanceSolutionsContentProvider(this); + provider.init(this, phase); + + setModel(provider); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveNegativeIdealSolutionTable.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveNegativeIdealSolutionTable.java new file mode 100644 index 0000000..6da5a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectiveNegativeIdealSolutionTable.java @@ -0,0 +1,34 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.provider.CollectiveAntiIdealSolutionContentProvider; + +public class CollectiveNegativeIdealSolutionTable extends KTable { + + private CollectiveAntiIdealSolutionContentProvider provider; + + public CollectiveNegativeIdealSolutionTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(CollectiveInfo phase) { + provider = new CollectiveAntiIdealSolutionContentProvider(this); + provider.init(this, phase); + + setModel(provider); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectivePositiveIdealSolutionTable.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectivePositiveIdealSolutionTable.java new file mode 100644 index 0000000..2bf2e0a --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/CollectivePositiveIdealSolutionTable.java @@ -0,0 +1,33 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.provider.CollectiveIdealSolutionContentProvider; + +public class CollectivePositiveIdealSolutionTable extends KTable { + + private CollectiveIdealSolutionContentProvider provider; + + public CollectivePositiveIdealSolutionTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(CollectiveInfo phase) { + provider = new CollectiveIdealSolutionContentProvider(this); + provider.init(this, phase); + + setModel(provider); + } + + @Override + public void dispose() { + super.dispose(); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/DecisionMatrixTable.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/DecisionMatrixTable.java new file mode 100644 index 0000000..c7ee391 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/DecisionMatrixTable.java @@ -0,0 +1,35 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.SWTX; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.provider.DecisionMatrixContentProvider; + +public class DecisionMatrixTable extends KTable { + + DecisionMatrixContentProvider provider; + + public DecisionMatrixTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | 50 | SWTX.AUTO_SCROLL ); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(CollectiveInfo phase) { + provider = new DecisionMatrixContentProvider(this); + provider.init(this, phase); + + setModel(provider); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/ExpertWeightsTable.java b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/ExpertWeightsTable.java new file mode 100644 index 0000000..608a71d --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective.ui/src/flintstones/method/linguistic/topsis/phase/collective/ui/table/ExpertWeightsTable.java @@ -0,0 +1,37 @@ +package flintstones.method.linguistic.topsis.phase.collective.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.collective.CollectiveInfo; +import flintstones.method.linguistic.topsis.phase.collective.ui.provider.ExpertWeightsContentProvider; + +public class ExpertWeightsTable extends KTable { + + private ExpertWeightsContentProvider provider; + + public ExpertWeightsTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(CollectiveInfo phase) { + provider = new ExpertWeightsContentProvider(this); + provider.init(this, phase); + + setModel(provider); + } + + @Override + public void dispose() { + super.dispose(); + } + + public void setDecisionMatrixTable(DecisionMatrixTable weigthedDecisionMatrixTable) { + provider.setDecisionMatrixTable(weigthedDecisionMatrixTable); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/.classpath b/bundles/flintstones.method.linguistic.topsis.phase.collective/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/.polyglot.META-INF b/bundles/flintstones.method.linguistic.topsis.phase.collective/.polyglot.META-INF new file mode 100644 index 0000000..fab915b --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.topsis.phase.collective + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Collective phase + + Sinbad2 + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/.project b/bundles/flintstones.method.linguistic.topsis.phase.collective/.project new file mode 100644 index 0000000..3c7cb66 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.topsis.phase.collective + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362681 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.topsis.phase.collective/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6242ce0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Collective phase +Bundle-SymbolicName: flintstones.method.linguistic.topsis.phase.collective;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.linguistic.topsis.phase.collective +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.model.problemelement.service, + flintstones.valuation.twoTuple, + flintstones.model.domain.service, + org.eclipse.e4.core.services, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.operator.unification +Export-Package: flintstones.method.linguistic.topsis.phase.collective diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/build.properties b/bundles/flintstones.method.linguistic.topsis.phase.collective/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/plugin.xml b/bundles/flintstones.method.linguistic.topsis.phase.collective/plugin.xml new file mode 100644 index 0000000..e3c0b8d --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/CollectiveInfo.java b/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/CollectiveInfo.java new file mode 100644 index 0000000..c46aefe --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/CollectiveInfo.java @@ -0,0 +1,396 @@ +package flintstones.method.linguistic.topsis.phase.collective; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.method.linguistic.topsis.phase.collective.messages.Messages; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class CollectiveInfo extends PhaseMethod { + + private FuzzySet domainWeights; + private FuzzySet valuationDomain; + private FuzzySet distanceDomain; + + private Map closenessCoefficientsExperts = new HashMap(); + private Map weights = new HashMap(); + private Valuation[][] decisionMatrix; + private Valuation[][] distancesPositiveIdealSolution; + private Valuation[][] distancesNegativeIdealSolution; + private Valuation[] positiveIdealSolution; + private Valuation[] negativeIdealSolution; + private Valuation[] globalDistancesPositiveIdealSolution; + private Valuation[] globalDistancesNegativeIdealSolution; + private Valuation[] closenessCoefficients; + + @Inject + IEclipseContext context; + + @Inject + @Translation + private Messages messages; + + @Inject + private IProblemElementService problemService; + + @Inject + private IDomainService domainService; + + @Override + public String getName() { + return messages.Phase_Name; + } + + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + public int getNumberExperts() { + return getExperts().length; + } + + public String getExpertName(int pos) { + return getExperts()[pos].getName(); + } + + public int getNumberAlternatives() { + return getAlternatives().length; + } + + public ProblemElement[] getAlternatives() { + return problemService.getAll(Alternative.Type); + } + + public String getAlternativeName(int pos) { + return getAlternatives()[pos].getName(); + } + + public String[] getLinguisticDomainNames() { + ArrayList names = new ArrayList(); + + Domain[] domains = domainService.getAll(); + for(Domain domain: domains) { + if(domain instanceof FuzzySet) + names.add(domain.getName()); + } + + return names.toArray(new String[0]); + } + + public String[] getLinguisticLabelsNameDomain() { + String[] labels = new String[domainWeights.getLabelSet().getCardinality()]; + + for(int i = 0; i < labels.length; ++i) + labels[i] = domainWeights.getLabelSet().getLabel(i).getName(); + + return labels; + } + + public void setDomainWeights(String domainName) { + this.domainWeights = (FuzzySet) domainService.getByName(domainName); + + if(weights.get(domainWeights) == null) + initializeWeights(); + } + + public void initializeWeights() { + LabelLinguisticDomain[] weights = new LabelLinguisticDomain[getNumberExperts()]; + + LabelLinguisticDomain maxLabel = domainWeights.getLabelSet().getLabel(domainWeights.getLabelSet().getCardinality() - 1); + for(int i = 0; i < weights.length; ++i) + weights[i] = maxLabel; + + this.weights.put(domainWeights, weights); + } + + public void execute() { + setValuationDomain(); + setDistanceDomain(); + setClosenessCoefficientExperts(); + + buildCollectiveDecisionMatrix(); + computeSolutions(); + computeDistanceSolutions(); + computeGlobalDistancesIdealSolutions(); + computeClosenessCoefficients(); + } + + private void setValuationDomain() { + this.valuationDomain = (FuzzySet) importData("valuationDomain"); + } + + private void setDistanceDomain() { + this.distanceDomain = (FuzzySet) importData("distanceDomain"); + } + + @SuppressWarnings("unchecked") + private void setClosenessCoefficientExperts() { + this.closenessCoefficientsExperts = (Map) importData("coefficients"); + } + + private void buildCollectiveDecisionMatrix() { + decisionMatrix = new Valuation[getNumberAlternatives()][getNumberExperts()]; + + ProblemElement[] experts = getExperts(); + + LabelLinguisticDomain maxLabel = domainWeights.getLabelSet().getLabel(domainWeights.getLabelSet().getCardinality() - 1); + TwoTupleValuation maxLabelTwoTuple = new TwoTupleValuation(domainWeights, maxLabel); + + Valuation[] coefficients; + TwoTupleValuation coef, weight, weightedValuation; + for(int i = 0; i < closenessCoefficientsExperts.size(); ++i) { + coefficients = closenessCoefficientsExperts.get(experts[i]); + weight = new TwoTupleValuation(domainWeights, weights.get(domainWeights)[i]); + for(int j = 0; j < coefficients.length; ++j) { + coef = (TwoTupleValuation) coefficients[j]; + weightedValuation = new TwoTupleValuation(distanceDomain); + weightedValuation.calculateDelta(coef.calculateInverseDelta() * (weight.calculateInverseDelta() / maxLabelTwoTuple.calculateInverseDelta())); + + decisionMatrix[j][i] = weightedValuation; + } + } + } + + private void computeSolutions() { + computePositiveIdealSolution(); + computeNegativeIdealSolution(); + } + + private void computePositiveIdealSolution() { + positiveIdealSolution = new Valuation[getNumberExperts()]; + + List valuationsExpert; + + for (int exp = 0; exp < getNumberExperts(); ++exp) { + + valuationsExpert = getValuationsExpert(exp); + + Collections.sort(valuationsExpert); + + positiveIdealSolution[exp] = valuationsExpert.get(valuationsExpert.size() - 1); + } + } + + private List getValuationsExpert(int exp) { + List valuations = new ArrayList<>(); + + for(int alt = 0; alt < getNumberAlternatives(); ++alt) + valuations.add(decisionMatrix[alt][exp]); + + return valuations; + } + + private void computeNegativeIdealSolution() { + negativeIdealSolution = new Valuation[getNumberExperts()]; + + List valuationsExpert; + + for (int exp = 0; exp < getNumberExperts(); ++exp) { + + valuationsExpert = getValuationsExpert(exp); + + Collections.sort(valuationsExpert); + + negativeIdealSolution[exp] = valuationsExpert.get(0); + } + } + + private void computeDistanceSolutions() { + computeDistanceIdealPositiveSolution(); + computeDistanceIdealNegativeSolution(); + } + + private void computeDistanceIdealPositiveSolution() { + distancesPositiveIdealSolution = new Valuation[getNumberAlternatives()][getNumberExperts()]; + + TwoTupleValuation distance; + + double dist; + for(int i = 0; i < decisionMatrix.length; ++i) { + for(int j = 0; j < decisionMatrix[i].length; ++j) { + dist = computeDistanceTwoTuple(decisionMatrix[i][j], positiveIdealSolution[j]); + + distance = new TwoTupleValuation(distanceDomain); + distance.calculateDelta(dist); + + distancesPositiveIdealSolution[i][j] = distance; + } + } + } + + private Float computeDistanceTwoTuple(Valuation valuation1, Valuation valuation2) { + return (float) Math.abs(((TwoTupleValuation) valuation1).calculateInverseDelta() - ((TwoTupleValuation) valuation2).calculateInverseDelta()); + } + + private void computeDistanceIdealNegativeSolution() { + distancesNegativeIdealSolution = new Valuation[getNumberAlternatives()][getNumberExperts()]; + + TwoTupleValuation distance; + + double dist; + for(int i = 0; i < decisionMatrix.length; ++i) { + for(int j = 0; j < decisionMatrix[i].length; ++j) { + dist = computeDistanceTwoTuple(decisionMatrix[i][j], negativeIdealSolution[j]); + + distance = new TwoTupleValuation(distanceDomain); + distance.calculateDelta(dist); + + distancesNegativeIdealSolution[i][j] = distance; + } + } + } + + private void computeGlobalDistancesIdealSolutions() { + computeGlobalPositiveIdealSolutionDistances(); + computeGlobalNegativeIdealSolutionDistances(); + } + + private void computeGlobalPositiveIdealSolutionDistances() { + globalDistancesPositiveIdealSolution = new Valuation[getNumberAlternatives()]; + + TwoTupleValuation distance; + + double acum; + for(int i = 0; i < distancesPositiveIdealSolution.length; ++i) { + acum = 0; + for(int j = 0; j < distancesPositiveIdealSolution[i].length; ++j) + acum += ((TwoTupleValuation) distancesPositiveIdealSolution[i][j]).calculateInverseDelta(); + + distance = new TwoTupleValuation(distanceDomain); + distance.calculateDelta(acum /distancesPositiveIdealSolution[i].length); + + globalDistancesPositiveIdealSolution[i] = distance; + } + } + + private void computeGlobalNegativeIdealSolutionDistances() { + globalDistancesNegativeIdealSolution = new Valuation[getNumberAlternatives()]; + + TwoTupleValuation distance; + + double acum; + for(int i = 0; i < distancesNegativeIdealSolution.length; ++i) { + acum = 0; + for(int j = 0; j < distancesNegativeIdealSolution[i].length; ++j) + acum += ((TwoTupleValuation) distancesNegativeIdealSolution[i][j]).calculateInverseDelta(); + + distance = new TwoTupleValuation(distanceDomain); + distance.calculateDelta(acum / distancesNegativeIdealSolution[i].length); + + globalDistancesNegativeIdealSolution[i] = distance; + } + } + + private void computeClosenessCoefficients() { + closenessCoefficients = new Valuation[getNumberAlternatives()]; + + TwoTupleValuation closeness; + + double posDist, negDist, coeff; + for(int i = 0; i < globalDistancesPositiveIdealSolution.length; ++i) { + posDist = ((TwoTupleValuation) globalDistancesPositiveIdealSolution[i]).calculateInverseDelta(); + negDist = ((TwoTupleValuation) globalDistancesNegativeIdealSolution[i]).calculateInverseDelta(); + coeff = (distanceDomain.getLabelSet().getCardinality() - 1) * (negDist / (posDist + negDist)); + + closeness = new TwoTupleValuation(distanceDomain); + closeness.calculateDelta(coeff); + closenessCoefficients[i] = closeness; + } + } + + public void setExpertWeight(int posExpert, String labelName) { + weights.get(domainWeights)[posExpert] = domainWeights.getLabelSet().getLabel(labelName); + } + + public boolean distanceDomainChanged() { + FuzzySet oldDomain = (FuzzySet) this.distanceDomain.clone(); + setDistanceDomain(); + return (!oldDomain.equals(this.distanceDomain)) ? true:false; + } + + public boolean valuationDomainChanged() { + FuzzySet oldDomain = (FuzzySet) this.valuationDomain.clone(); + setValuationDomain(); + return (!oldDomain.equals(this.valuationDomain)) ? true:false; + } + + public String getStringExpertWeight(int posExpert) { + return weights.get(domainWeights)[posExpert].getName(); + } + + public String getStringDecisionMatrixValuation(int posExp, int posAlt) { + TwoTupleValuation v = (TwoTupleValuation) decisionMatrix[posAlt][posExp]; + return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringPositiveIdealSolutionExpert(int posExp) { + TwoTupleValuation v = (TwoTupleValuation) positiveIdealSolution[posExp]; + return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringNegativeIdealSolutionExpert(int posExp) { + TwoTupleValuation v = (TwoTupleValuation) negativeIdealSolution[posExp]; + return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringCollectiveDistancePositiveIdealSolutionValuation(int posExpert, int posAlt) { + TwoTupleValuation v = (TwoTupleValuation) distancesPositiveIdealSolution[posAlt][posExpert]; + return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringCollectiveDistanceNegativeIdealSolutionValuation(int posExpert, int posAlt) { + TwoTupleValuation v = (TwoTupleValuation) distancesNegativeIdealSolution[posAlt][posExpert]; + return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringCollectiveGlobalDistancePositiveIdealSolutionValuation(int posAlt) { + TwoTupleValuation v = (TwoTupleValuation) globalDistancesPositiveIdealSolution[posAlt]; + return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringCollectiveGlobalDistanceNegativeIdealSolutionValuation(int posAlt) { + TwoTupleValuation v = (TwoTupleValuation) globalDistancesNegativeIdealSolution[posAlt]; + return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringCollectiveClosenessCoefficient(int posAlt) { + TwoTupleValuation v = (TwoTupleValuation) closenessCoefficients[posAlt]; + return v.changeFormatValuationToString() + "(" + Math.round(v.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringRankingPositionAlternative(int posAlt) { + double[] values = new double[closenessCoefficients.length]; + for(int i = 0; i < values.length; ++i) + values[i] = ((TwoTupleValuation) closenessCoefficients[i]).calculateInverseDelta(); + + return Integer.toString(findRank(values)[posAlt] + 1); + } + + private int[] findRank(double[] inp) { + int[] outp = new int[inp.length]; + for(int i = 0; i < inp.length; i++) { + for(int k = 0; k < inp.length; k++) { + if(inp[k] > inp[i]) outp[i]++; + } + } + return outp; + } +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/Messages.java b/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/Messages.java new file mode 100644 index 0000000..744326e --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/Messages.java @@ -0,0 +1,10 @@ +package flintstones.method.linguistic.topsis.phase.collective.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + + public String Phase_Name; + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/messages.properties b/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/messages.properties new file mode 100644 index 0000000..1ab208b --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/messages.properties @@ -0,0 +1 @@ +Phase_Name=Collective TOPSIS \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/messages_es.properties b/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/messages_es.properties new file mode 100644 index 0000000..14edc47 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.collective/src/flintstones/method/linguistic/topsis/phase/collective/messages/messages_es.properties @@ -0,0 +1 @@ +Phase_Name=TOPSIS colectiva \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.classpath b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.polyglot.META-INF b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.polyglot.META-INF new file mode 100644 index 0000000..b73ab0a --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.topsis.phase.experts.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Linguistic TOPSIS experts ui + + Sinbad2 + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.project b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.project new file mode 100644 index 0000000..f1ee1db --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.topsis.phase.experts.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362682 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d4c552f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Linguistic TOPSIS experts ui +Bundle-SymbolicName: flintstones.method.linguistic.topsis.phase.experts.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.linguistic.topsis.phase.experts.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.model.ui.service, + flintstones.entity.method.phase.ui, + flintstones.entity.method.phase, + flintstones.method.linguistic.topsis.phase.experts, + org.eclipse.swt, + de.kupzog.ktable +Export-Package: flintstones.method.linguistic.topsis.phase.experts.ui.table diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/build.properties b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/plugin.xml b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/plugin.xml new file mode 100644 index 0000000..415360c --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/ExpertsInfoUI.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/ExpertsInfoUI.java new file mode 100644 index 0000000..5ca4ad6 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/ExpertsInfoUI.java @@ -0,0 +1,291 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.ClosenessCoefficientTable; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.DistanceNegativeIdealSolutionTable; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.DistancePositiveIdealSolutionTable; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.DistanceSolutionsTable; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.ExpertWeightsTable; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.NegativeIdealSolutionTable; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.PositiveIdealSolutionTable; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.WeightedDecisionMatrixTable; +import flintstones.model.ui.service.UiService; + +public class ExpertsInfoUI extends PhaseMethodUI { + + private ExpertsInfo model; + + private ExpertWeightsTable weightsTable; + private WeightedDecisionMatrixTable weigthedDecisionMatrixTable; + private PositiveIdealSolutionTable positiveIdealSolutionTable; + private NegativeIdealSolutionTable negativeIdealSolutionTable; + private DistancePositiveIdealSolutionTable distancePositiveIdealSolutionTable; + private DistanceNegativeIdealSolutionTable distanceNegativeIdealSolutionTable; + private DistanceSolutionsTable distanceSolutionsTable; + private ClosenessCoefficientTable closenessCoefficientTable; + private Combo selectExpertCombo; + + @Override + public void init() { + model = (ExpertsInfo) this.getModel(); + + Composite parent = this.getBaseComposite(); + GridLayout layout = UiService.setGridLayout(parent, 1, true); + UiService.setGridData(parent, 9, 9, true, true); + layout.horizontalSpacing = 15; + layout.verticalSpacing = 15; + + createPartControl(parent); + + model.initializeDefaultWeights(); + model.executeForAllExperts(); + } + + private void createPartControl(Composite parent) { + createCombos(parent); + createWeightedInfoTables(parent); + createSolutionsInfoTables(parent); + createDistancesSolutionInfo(parent); + createGlobalSolutionInfo(parent); + } + + private void createCombos(Composite parent) { + Composite combosComposite = new Composite(parent, SWT.BORDER); + UiService.setGridLayout(combosComposite, 2, false); + UiService.setGridData(combosComposite, 0, 0, true, false); + + createSelectionExpertCombo(combosComposite); + createUnificationDomainDistancesCombo(combosComposite); + } + + private void createSelectionExpertCombo(Composite combosComposite) { + /*Composite selectExpertComboComposite = new Composite(combosComposite, SWT.NONE); + UiService.setGridLayout(selectExpertComboComposite, 1, true); + UiService.setGridData(selectExpertComboComposite, -1, 1, false, false);*/ + + selectExpertCombo = new Combo(combosComposite, SWT.NONE); + UiService.setGridData(selectExpertCombo, 0, 1, true, true); + selectExpertCombo.setItems(model.getExpertsNames()); + selectExpertCombo.select(0); + + selectExpertCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + refresh(); + } + }); + } + + private void createUnificationDomainDistancesCombo(Composite combosComposite) { + /*Composite distanceSolutionsComboComposite = new Composite(combosComposite, SWT.NONE); + UiService.setGridLayout(distanceSolutionsComboComposite, 1, false); + UiService.setGridData(distanceSolutionsComboComposite, -1, 1, false, false);*/ + + /*Label label = new Label(distanceSolutionsComboComposite, SWT.NONE); + UiService.setGridData(label, 9, 9, false, true); + label.setText("Select the domain for distances (all experts):");*/ + + Combo selectUnificationDomainCombo = new Combo(combosComposite, SWT.NONE); + UiService.setGridData(selectUnificationDomainCombo, 9, 9, false, true); + selectUnificationDomainCombo.setItems(model.getLinguisticDomainNames()); + selectUnificationDomainCombo.select(0); + model.setUnificationDomainDistances(selectUnificationDomainCombo.getText()); + + selectUnificationDomainCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.setUnificationDomainDistances(selectUnificationDomainCombo.getText()); + model.executeForAllExperts(); + refresh(); + } + }); + } + + private void createWeightedInfoTables(Composite parent) { + Composite tablesComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(tablesComposite, 2, true); + UiService.setGridData(tablesComposite, 9, 9, true, false); + + createWeightsTable(tablesComposite); + createWeightedDecisionMatrixTable(tablesComposite); + } + + private void createWeightsTable(Composite tablesComposite) { + Composite weightsComposite = new Composite(tablesComposite, SWT.NONE); + UiService.setGridLayout(weightsComposite, 1, true); + UiService.setGridData(weightsComposite, 9, 9, true, false); + + weightsTable = new ExpertWeightsTable(weightsComposite); + UiService.setGridData(weightsTable, 9, 9, true, true); + weightsTable.setModel(model, selectExpertCombo.getSelectionIndex()); + + Composite weightsCombosComposite = new Composite(weightsComposite, SWT.NONE); + UiService.setGridLayout(weightsCombosComposite, 2, false); + UiService.setGridData(weightsCombosComposite, 9, 9, true, false); + + createDomainWeightsCombo(weightsCombosComposite); + createUnificationDomainWeightsCombo(weightsCombosComposite); + } + + private void createDomainWeightsCombo(Composite weightsComposite) { + Composite selectWeightsComboComposite = new Composite(weightsComposite, SWT.BORDER); + UiService.setGridLayout(selectWeightsComboComposite, 2, false); + UiService.setGridData(selectWeightsComboComposite, -1, 9, false, true); + + Label label = new Label(selectWeightsComboComposite, SWT.NONE); + UiService.setGridData(label, -1, -1, false, true); + label.setText("Domain for weights:"); + + Combo selectDomainCombo = new Combo(selectWeightsComboComposite, SWT.NONE); + GridData grid = UiService.setGridData(selectDomainCombo, -1, -1, false, true); + grid.verticalIndent = 15; + selectDomainCombo.setItems(model.getDomainNames()); + selectDomainCombo.select(0); + model.setWeightsDomain(selectDomainCombo.getText()); + + selectDomainCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.setWeightsDomain(selectDomainCombo.getText()); + model.execute(selectExpertCombo.getSelectionIndex()); + refresh(); + } + }); + } + + private void createUnificationDomainWeightsCombo(Composite weightComposite) { + Composite selectUnificationComboComposite = new Composite(weightComposite, SWT.BORDER); + UiService.setGridLayout(selectUnificationComboComposite, 2, false); + UiService.setGridData(selectUnificationComboComposite, -1, 9, false, true); + + Label label = new Label(selectUnificationComboComposite, SWT.NONE); + UiService.setGridData(label, -1, -1, false, true); + label.setText("Unification domain for weights:"); + + Combo selectUnificationDomainCombo = new Combo(selectUnificationComboComposite, SWT.BORDER); + GridData grid = UiService.setGridData(selectUnificationDomainCombo, -1, -1, false, true); + grid.verticalIndent = 15; + selectUnificationDomainCombo.setItems(model.getLinguisticDomainNames()); + selectUnificationDomainCombo.select(0); + model.setUnificationDomainWeights(selectUnificationDomainCombo.getText()); + + selectUnificationDomainCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + model.setUnificationDomainWeights(selectUnificationDomainCombo.getText()); + model.execute(selectExpertCombo.getSelectionIndex()); + refresh(); + } + }); + } + + private void createWeightedDecisionMatrixTable(Composite tablesComposite) { + Composite decisionMatrixComposite = new Composite(tablesComposite, SWT.NONE); + UiService.setGridLayout(decisionMatrixComposite, 1, true); + UiService.setGridData(decisionMatrixComposite, 9, 9, true, true); + + weigthedDecisionMatrixTable = new WeightedDecisionMatrixTable(decisionMatrixComposite); + UiService.setGridData(weigthedDecisionMatrixTable, 9, 9, true, true); + weigthedDecisionMatrixTable.setModel(model, selectExpertCombo.getSelectionIndex()); + + weightsTable.setWeightedDecisionMatrixTable(weigthedDecisionMatrixTable);//To update the table when weights change + } + + private void createSolutionsInfoTables(Composite parent) { + Composite solutionsTablesComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(solutionsTablesComposite, 2, true); + UiService.setGridData(solutionsTablesComposite, 9, 1, true, false); + + createPositiveIdealSolutionTable(solutionsTablesComposite); + createNegativeIdealSolutionTable(solutionsTablesComposite); + } + + private void createPositiveIdealSolutionTable(Composite solutionsTablesComposite) { + positiveIdealSolutionTable = new PositiveIdealSolutionTable(solutionsTablesComposite); + UiService.setGridData(positiveIdealSolutionTable, 9, 9, true, true); + positiveIdealSolutionTable.setModel(model, selectExpertCombo.getSelectionIndex()); + } + + private void createNegativeIdealSolutionTable(Composite solutionsTablesComposite) { + negativeIdealSolutionTable = new NegativeIdealSolutionTable(solutionsTablesComposite); + UiService.setGridData(negativeIdealSolutionTable, 9, 9, true, true); + negativeIdealSolutionTable.setModel(model, selectExpertCombo.getSelectionIndex()); + } + + private void createDistancesSolutionInfo(Composite parent) { + Composite distanceSolutionsTablesComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(distanceSolutionsTablesComposite, 2, true); + GridData gd = UiService.setGridData(distanceSolutionsTablesComposite, 9, 9, true, true); + gd.heightHint = 25; + + createDistancePositiveIdealSolutionTable(distanceSolutionsTablesComposite); + createDistanceNegativeIdealSolutionTable(distanceSolutionsTablesComposite); + } + + private void createDistancePositiveIdealSolutionTable(Composite distanceSolutionsTablesComposite) { + distancePositiveIdealSolutionTable = new DistancePositiveIdealSolutionTable(distanceSolutionsTablesComposite); + UiService.setGridData(distancePositiveIdealSolutionTable, 9, 9, true, true); + distancePositiveIdealSolutionTable.setModel(model, selectExpertCombo.getSelectionIndex()); + } + + private void createDistanceNegativeIdealSolutionTable(Composite distanceSolutionsTablesComposite) { + distanceNegativeIdealSolutionTable = new DistanceNegativeIdealSolutionTable(distanceSolutionsTablesComposite); + UiService.setGridData(distanceNegativeIdealSolutionTable, 9, 9, true, true); + distanceNegativeIdealSolutionTable.setModel(model, selectExpertCombo.getSelectionIndex()); + } + + private void createGlobalSolutionInfo(Composite parent) { + Composite globalSolutionsComposite = new Composite(parent, SWT.NONE); + UiService.setGridLayout(globalSolutionsComposite, 2, true); + GridData gd = UiService.setGridData(globalSolutionsComposite, 9, 9, true, true); + gd.heightHint = 25; + + createGlobalDistanceSolutionTable(globalSolutionsComposite); + createClosenessCoefficientTable(globalSolutionsComposite); + } + + private void createGlobalDistanceSolutionTable(Composite globalSolutionsComposite) { + distanceSolutionsTable = new DistanceSolutionsTable(globalSolutionsComposite); + UiService.setGridData(distanceSolutionsTable, 9, 9, true, true); + distanceSolutionsTable.setModel(model, selectExpertCombo.getSelectionIndex()); + } + + private void createClosenessCoefficientTable(Composite globalSolutionsComposite) { + closenessCoefficientTable = new ClosenessCoefficientTable(globalSolutionsComposite); + UiService.setGridData(closenessCoefficientTable, 9, 9, true, true); + closenessCoefficientTable.setModel(model, selectExpertCombo.getSelectionIndex()); + } + + @Override + public void refresh() { + + if(model.unificationDomainChanged()) + model.executeForAllExperts(); + + int posExpert = selectExpertCombo.getSelectionIndex(); + //Refresh tables + weightsTable.setExpert(posExpert); + weigthedDecisionMatrixTable.setExpert(posExpert); + positiveIdealSolutionTable.setExpert(posExpert); + negativeIdealSolutionTable.setExpert(posExpert); + distancePositiveIdealSolutionTable.setExpert(posExpert); + distanceNegativeIdealSolutionTable.setExpert(posExpert); + distanceSolutionsTable.setExpert(posExpert); + closenessCoefficientTable.setExpert(posExpert); + } + + @Override + protected boolean isForwardEnabled() { + return model.isFinished(); + } +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/AntiIdealSolutionContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/AntiIdealSolutionContentProvider.java new file mode 100644 index 0000000..e01bccb --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/AntiIdealSolutionContentProvider.java @@ -0,0 +1,177 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; + +public class AntiIdealSolutionContentProvider extends KTableNoScrollModel { + + private KTable table; + + private ExpertsInfo model; + + private int expert; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public AntiIdealSolutionContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ExpertsInfo model, int posExpert) { + this.table = table; + this.model = model; + this.expert = posExpert; + + initialize(); + setDesign(); + } + + public void setExpert(int posExpert) { + this.expert = posExpert; + this.table.redraw(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberCriteria() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Negative ideal solution"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = "Valuation"; + else if (row == 0) + content = criterionAbbreviation(col); + else + content = model.getStringNegativeIdealSolutionCriterion(col - 1, expert); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + return "C" + pos; + } + + @Override + public int doGetRowCount() { + return 1 + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if(col == 0 && row == 0) { + return ""; + } else if (row < getFixedRowCount()) + return model.getCriterionName(col - 1); + else + return ""; //$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/ClosenessCoefficientContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/ClosenessCoefficientContentProvider.java new file mode 100644 index 0000000..df61f08 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/ClosenessCoefficientContentProvider.java @@ -0,0 +1,179 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; + +public class ClosenessCoefficientContentProvider extends KTableNoScrollModel { + + private KTable table; + + private ExpertsInfo model; + + private int expert; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public ClosenessCoefficientContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ExpertsInfo model, int posExpert) { + this.table = table; + this.model = model; + this.expert = posExpert; + + initialize(); + setDesign(); + } + + public void setExpert(int posExpert) { + this.expert = posExpert; + this.table.redraw(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return 1 + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Closeness coefficient"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + content = "Closeness"; + else + content = model.getStringClosenessCoefficient(row - 1, expert); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return ""; + else + return (String) doGetContentAt(col, row); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceIAntiIdealSolutionContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceIAntiIdealSolutionContentProvider.java new file mode 100644 index 0000000..5c4ed2a --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceIAntiIdealSolutionContentProvider.java @@ -0,0 +1,183 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; + +public class DistanceIAntiIdealSolutionContentProvider extends KTableNoScrollModel { + + private KTable table; + + private ExpertsInfo model; + + private int expert; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public DistanceIAntiIdealSolutionContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ExpertsInfo model, int posExpert) { + this.table = table; + this.model = model; + this.expert = posExpert; + + initialize(); + setDesign(); + } + + public void setExpert(int posExpert) { + this.expert = posExpert; + this.table.redraw(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberCriteria() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Dist (-)"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + content = criterionAbbreviation(col); + else + content = model.getStringDistanceNegativeIdealSolutionValuation(col - 1, row - 1, expert); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + return "C" + pos; + } + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return model.getCriterionName(col - 1); + else + return (String) doGetContentAt(col, row); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceIdealSolutionContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceIdealSolutionContentProvider.java new file mode 100644 index 0000000..d7d9e8c --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceIdealSolutionContentProvider.java @@ -0,0 +1,183 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; + +public class DistanceIdealSolutionContentProvider extends KTableNoScrollModel { + + private KTable table; + + private ExpertsInfo model; + + private int expert; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public DistanceIdealSolutionContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ExpertsInfo model, int posExpert) { + this.table = table; + this.model = model; + this.expert = posExpert; + + initialize(); + setDesign(); + } + + public void setExpert(int posExpert) { + this.expert = posExpert; + this.table.redraw(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberCriteria() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Dist (+)"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + content = criterionAbbreviation(col); + else + content = model.getStringDistancePositiveIdealSolutionValuation(col - 1, row - 1, expert); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + return "C" + pos; + } + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return model.getCriterionName(col - 1); + else + return (String) doGetContentAt(col, row); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceSolutionsContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceSolutionsContentProvider.java new file mode 100644 index 0000000..787aa29 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/DistanceSolutionsContentProvider.java @@ -0,0 +1,192 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; + +public class DistanceSolutionsContentProvider extends KTableNoScrollModel { + + private KTable table; + + private ExpertsInfo model; + + private int expert; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public DistanceSolutionsContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ExpertsInfo model, int posExpert) { + this.table = table; + this.model = model; + this.expert = posExpert; + + initialize(); + setDesign(); + } + + public void setExpert(int posExpert) { + this.expert = posExpert; + this.table.redraw(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return 2 + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Distances"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + if(col == 1) + content = "Dist (+)"; + else if(col == 2) + content = "Dist (-)"; + else + content = ""; + else { + if(col == 1) + content = model.getStringGlobalDistancePositiveIdealSolutionValuation(row - 1, expert); + else if (col == 2) + content = model.getStringGlobalDistanceNegativeIdealSolutionValuation(row - 1, expert); + else + content = ""; + } + + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return ""; + else + return (String) doGetContentAt(col, row); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/ExpertWeightsContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/ExpertWeightsContentProvider.java new file mode 100644 index 0000000..5d8adbb --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/ExpertWeightsContentProvider.java @@ -0,0 +1,235 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.editors.KTableCellEditorCombo; +import de.kupzog.ktable.editors.KTableCellEditorText; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.table.WeightedDecisionMatrixTable; + +public class ExpertWeightsContentProvider extends KTableNoScrollModel { + + private KTable table; + private KTable decisionMatrixTable; + + private ExpertsInfo model; + + private int expert; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + private class TableCellEditorText extends KTableCellEditorText { + @Override + protected void onKeyPressed(KeyEvent e) { + if(e.keyCode == 13) + this.close(true); + } + + @Override + public int getActivationSignals() { + return SINGLECLICK; + } + } + + private TableCellEditorText text; + + private class TableCellEditorCombo extends KTableCellEditorCombo { + @Override + protected void onKeyPressed(KeyEvent e) { + if(e.keyCode == 13) + this.close(true); + } + + @Override + public int getActivationSignals() { + return SINGLECLICK; + } + } + + private TableCellEditorCombo combo; + + public ExpertWeightsContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ExpertsInfo model, int posExpert) { + this.table = table; + this.model = model; + this.expert = posExpert; + + initialize(); + setDesign(); + } + + public void setExpert(int posExpert) { + this.expert = posExpert; + this.table.redraw(); + } + + public void setWeightedDecisionMatrixTable(WeightedDecisionMatrixTable weigthedDecisionMatrixTable) { + this.decisionMatrixTable = weigthedDecisionMatrixTable; + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + + if (col != 0 && row != 0) { + if(model.domainWeightsIsFuzzySet(expert)) { + combo = new TableCellEditorCombo(); + combo.setItems(model.getLabelsNameDomainWeightsExpert(expert)); + return combo; + } else { + text = new TableCellEditorText(); + return text; + } + } + + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberCriteria() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Weights"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = expertAbbreviation(row); + else if (row == 0) + content = criterionAbbreviation(col); + else + content = model.getStringExpertWeight(col - 1, expert); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + return "C" + pos; + } + + private Object expertAbbreviation(int pos) { + return "E" + (expert + 1); + } + + @Override + public int doGetRowCount() { + return getFixedRowCount() + 1; + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + model.setExpertWeight(col - 1, expert, (String) value); + model.execute(expert); + table.redraw(); + decisionMatrixTable.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getExpertName(expert); + } else if (row < getFixedRowCount()) + return model.getCriterionName(col - 1); + else + return model.getExpertName(row - 1) + " / " + model.getCriterionName(col - 1); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/IdealSolutionContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/IdealSolutionContentProvider.java new file mode 100644 index 0000000..6f21559 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/IdealSolutionContentProvider.java @@ -0,0 +1,177 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; + +public class IdealSolutionContentProvider extends KTableNoScrollModel { + + private KTable table; + + private ExpertsInfo model; + + private int expert; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public IdealSolutionContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ExpertsInfo model, int posExpert) { + this.table = table; + this.model = model; + this.expert = posExpert; + + initialize(); + setDesign(); + } + + public void setExpert(int posExpert) { + this.expert = posExpert; + this.table.redraw(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberCriteria() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Positive ideal solution"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = "Valuation"; + else if (row == 0) + content = criterionAbbreviation(col); + else + content = model.getStringPositiveIdealSolutionCriterion(col - 1, expert); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + return "C" + pos; + } + + @Override + public int doGetRowCount() { + return 1 + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if(col == 0 && row == 0) { + return ""; + } else if (row < getFixedRowCount()) + return model.getCriterionName(col - 1); + else + return ""; //$NON-NLS-1$ + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/WeightedDecisionMatrixContentProvider.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/WeightedDecisionMatrixContentProvider.java new file mode 100644 index 0000000..951c92a --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/provider/WeightedDecisionMatrixContentProvider.java @@ -0,0 +1,183 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.provider; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; + +public class WeightedDecisionMatrixContentProvider extends KTableNoScrollModel { + + private KTable table; + + private ExpertsInfo model; + + private int expert; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + + public WeightedDecisionMatrixContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ExpertsInfo model, int posExpert) { + this.table = table; + this.model = model; + this.expert = posExpert; + + initialize(); + setDesign(); + } + + public void setExpert(int posExpert) { + this.expert = posExpert; + this.table.redraw(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return model.getNumberCriteria() + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Decision Matrix (W)"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = alternativeAbbreviation(row); + else if (row == 0) + content = criterionAbbreviation(col); + else + content = model.getStringWeightedValuation(col - 1, row - 1, expert); + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + return "C" + pos; + } + + private Object alternativeAbbreviation(int pos) { + return "R" + pos; + } + + @Override + public int doGetRowCount() { + return model.getNumberAlternatives() + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + table.redraw(); + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return model.getAlternativeName(row - 1); + } else if (row < getFixedRowCount()) + return model.getCriterionName(col - 1); + else + return model.getAlternativeName(row - 1) + " / " + model.getCriterionName(col - 1); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/ClosenessCoefficientTable.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/ClosenessCoefficientTable.java new file mode 100644 index 0000000..9f51a9f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/ClosenessCoefficientTable.java @@ -0,0 +1,38 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.provider.ClosenessCoefficientContentProvider; + +public class ClosenessCoefficientTable extends KTable { + + ClosenessCoefficientContentProvider provider; + + public ClosenessCoefficientTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ExpertsInfo phase, int posExpert) { + provider = new ClosenessCoefficientContentProvider(this); + provider.init(this, phase, posExpert); + + setModel(provider); + } + + public void setExpert(int posExpert) { + provider.setExpert(posExpert); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistanceNegativeIdealSolutionTable.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistanceNegativeIdealSolutionTable.java new file mode 100644 index 0000000..ab3a61c --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistanceNegativeIdealSolutionTable.java @@ -0,0 +1,38 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.provider.DistanceIAntiIdealSolutionContentProvider; + +public class DistanceNegativeIdealSolutionTable extends KTable { + + DistanceIAntiIdealSolutionContentProvider provider; + + public DistanceNegativeIdealSolutionTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ExpertsInfo phase, int posExpert) { + provider = new DistanceIAntiIdealSolutionContentProvider(this); + provider.init(this, phase, posExpert); + + setModel(provider); + } + + public void setExpert(int posExpert) { + provider.setExpert(posExpert); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistancePositiveIdealSolutionTable.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistancePositiveIdealSolutionTable.java new file mode 100644 index 0000000..9825024 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistancePositiveIdealSolutionTable.java @@ -0,0 +1,38 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.provider.DistanceIdealSolutionContentProvider; + +public class DistancePositiveIdealSolutionTable extends KTable { + + DistanceIdealSolutionContentProvider provider; + + public DistancePositiveIdealSolutionTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ExpertsInfo phase, int posExpert) { + provider = new DistanceIdealSolutionContentProvider(this); + provider.init(this, phase, posExpert); + + setModel(provider); + } + + public void setExpert(int posExpert) { + provider.setExpert(posExpert); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistanceSolutionsTable.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistanceSolutionsTable.java new file mode 100644 index 0000000..88be5d6 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/DistanceSolutionsTable.java @@ -0,0 +1,38 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.provider.DistanceSolutionsContentProvider; + +public class DistanceSolutionsTable extends KTable { + + DistanceSolutionsContentProvider provider; + + public DistanceSolutionsTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ExpertsInfo phase, int posExpert) { + provider = new DistanceSolutionsContentProvider(this); + provider.init(this, phase, posExpert); + + setModel(provider); + } + + public void setExpert(int posExpert) { + provider.setExpert(posExpert); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/ExpertWeightsTable.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/ExpertWeightsTable.java new file mode 100644 index 0000000..82db443 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/ExpertWeightsTable.java @@ -0,0 +1,41 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.provider.ExpertWeightsContentProvider; + +public class ExpertWeightsTable extends KTable { + + private ExpertWeightsContentProvider provider; + + public ExpertWeightsTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ExpertsInfo phase, int posExpert) { + provider = new ExpertWeightsContentProvider(this); + provider.init(this, phase, posExpert); + + setModel(provider); + } + + public void setExpert(int posExpert) { + provider.setExpert(posExpert); + } + + public void setWeightedDecisionMatrixTable(WeightedDecisionMatrixTable weigthedDecisionMatrixTable) { + provider.setWeightedDecisionMatrixTable(weigthedDecisionMatrixTable); + } + + @Override + public void dispose() { + super.dispose(); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/NegativeIdealSolutionTable.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/NegativeIdealSolutionTable.java new file mode 100644 index 0000000..acc0a96 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/NegativeIdealSolutionTable.java @@ -0,0 +1,38 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.provider.AntiIdealSolutionContentProvider; + +public class NegativeIdealSolutionTable extends KTable { + + private AntiIdealSolutionContentProvider provider; + + public NegativeIdealSolutionTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ExpertsInfo phase, int posExpert) { + provider = new AntiIdealSolutionContentProvider(this); + provider.init(this, phase, posExpert); + + setModel(provider); + } + + public void setExpert(int posExpert) { + provider.setExpert(posExpert); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/PositiveIdealSolutionTable.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/PositiveIdealSolutionTable.java new file mode 100644 index 0000000..cbe7407 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/PositiveIdealSolutionTable.java @@ -0,0 +1,37 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.provider.IdealSolutionContentProvider; + +public class PositiveIdealSolutionTable extends KTable { + + private IdealSolutionContentProvider provider; + + public PositiveIdealSolutionTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ExpertsInfo phase, int posExpert) { + provider = new IdealSolutionContentProvider(this); + provider.init(this, phase, posExpert); + + setModel(provider); + } + + public void setExpert(int posExpert) { + provider.setExpert(posExpert); + } + + @Override + public void dispose() { + super.dispose(); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/WeightedDecisionMatrixTable.java b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/WeightedDecisionMatrixTable.java new file mode 100644 index 0000000..822f25f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts.ui/src/flintstones/method/linguistic/topsis/phase/experts/ui/table/WeightedDecisionMatrixTable.java @@ -0,0 +1,38 @@ +package flintstones.method.linguistic.topsis.phase.experts.ui.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.method.linguistic.topsis.phase.experts.ExpertsInfo; +import flintstones.method.linguistic.topsis.phase.experts.ui.provider.WeightedDecisionMatrixContentProvider; + +public class WeightedDecisionMatrixTable extends KTable { + + WeightedDecisionMatrixContentProvider provider; + + public WeightedDecisionMatrixTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ExpertsInfo phase, int posExpert) { + provider = new WeightedDecisionMatrixContentProvider(this); + provider.init(this, phase, posExpert); + + setModel(provider); + } + + public void setExpert(int posExpert) { + provider.setExpert(posExpert); + } + + @Override + public void dispose() { + super.dispose(); + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/.classpath b/bundles/flintstones.method.linguistic.topsis.phase.experts/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/.polyglot.META-INF b/bundles/flintstones.method.linguistic.topsis.phase.experts/.polyglot.META-INF new file mode 100644 index 0000000..0d5bfcd --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.topsis.phase.experts + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Linguistic TOPSIS experts information + + Sinbad2 + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/.project b/bundles/flintstones.method.linguistic.topsis.phase.experts/.project new file mode 100644 index 0000000..7f266af --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.topsis.phase.experts + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362682 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.topsis.phase.experts/META-INF/MANIFEST.MF new file mode 100644 index 0000000..efd8e01 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Linguistic TOPSIS experts information +Bundle-SymbolicName: flintstones.method.linguistic.topsis.phase.experts;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.linguistic.topsis.phase.weights +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.model.problemelement.service, + flintstones.model.valuation.service, + flintstones.valuation.numeric.real, + flintstones.valuation.numeric.integer, + flintstones.valuation.linguistic, + org.eclipse.e4.core.services, + javax.inject, + flintstones.operator.unification, + flintstones.model.domain.service, + flintstones.valuation.twoTuple, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.valuation.numeric.real.interval, + flintstones.valuation.numeric.integer.interval +Export-Package: flintstones.method.linguistic.topsis.phase.experts diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/build.properties b/bundles/flintstones.method.linguistic.topsis.phase.experts/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/plugin.xml b/bundles/flintstones.method.linguistic.topsis.phase.experts/plugin.xml new file mode 100644 index 0000000..cbae95e --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/ExpertsInfo.java b/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/ExpertsInfo.java new file mode 100644 index 0000000..97d0073 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/ExpertsInfo.java @@ -0,0 +1,755 @@ +package flintstones.method.linguistic.topsis.phase.experts; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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 flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.numeric.NumericDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.method.linguistic.topsis.phase.experts.messages.Messages; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.unification.service.IUnificationOperatorService; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.numeric.NumericIntervalarValuation; +import flintstones.valuation.numeric.NumericValuation; +import flintstones.valuation.numeric.integer.IntegerValuation; +import flintstones.valuation.numeric.integer.interval.IntegerIntervalValuation; +import flintstones.valuation.numeric.real.RealValuation; +import flintstones.valuation.numeric.real.interval.RealIntervalValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class ExpertsInfo extends PhaseMethod { + + private Map> weights = new HashMap>(); + private Map positiveIdealSolution = new HashMap(); + private Map negativeIdealSolution = new HashMap(); + private Map globalPositiveIdealSolutionDistance = new HashMap(); + private Map globalNegativeIdealSolutionDistance = new HashMap(); + private Map closenessCoefficients = new HashMap(); + private Map weightedDecisionMatrices = new HashMap(); + private Map distancePositiveIdealSolutionMatrices = new HashMap(); + private Map distanceNegativeIdealSolutionMatrices = new HashMap(); + + private Domain weightsDomain; + private FuzzySet unificationDomainValuations; + private FuzzySet unificationDomainWeights; + private FuzzySet unificationDomainDistances; + + @Inject + IEclipseContext context; + + @Inject + @Translation + private Messages messages; + + @Inject + private IProblemElementService problemService; + + @Inject + private IValuationService valuationService; + + @Inject + private IDomainService domainService; + + @Inject + private IUnificationOperatorService unificationService; + + @Override + public String getName() { + return messages.Phase_Name; + } + + public FuzzySet getUnificationDomainValuations() { + return this.unificationDomainValuations; + } + + public void setWeightsDomain(String domainName) { + this.weightsDomain = domainService.getByName(domainName); + } + + private void setUnificationDomainValuations() { + this.unificationDomainValuations = (FuzzySet) importData("unifiedDomain"); + } + + public void setUnificationDomainWeights(String domainName) { + this.unificationDomainWeights = (FuzzySet) domainService.getByName(domainName); + } + + public void setUnificationDomainDistances(String domainName) { + this.unificationDomainDistances = (FuzzySet) domainService.getByName(domainName); + } + + public ProblemElement[] getExperts() { + return problemService.getAll(Expert.Type); + } + + public int getNumberExperts() { + return getExperts().length; + } + + public String getExpertName(int pos) { + return getExperts()[pos].getName(); + } + + public String[] getExpertsNames() { + ProblemElement[] experts = getExperts(); + + String[] names = new String[experts.length]; + for(int i = 0; i < experts.length; ++i) + names[i] = experts[i].getName(); + + return names; + } + + public ProblemElement[] getCriteria() { + return problemService.getAll(Criterion.Type); + } + + public String getCriterionName(int pos) { + return getCriteria()[pos].getName(); + } + + public int getNumberCriteria() { + return getCriteria().length; + } + + public int getNumberAlternatives() { + return getAlternatives().length; + } + + public ProblemElement[] getAlternatives() { + return problemService.getAll(Alternative.Type); + } + + public String getAlternativeName(int pos) { + return getAlternatives()[pos].getName(); + } + + public String[] getLinguisticDomainNames() { + ArrayList names = new ArrayList(); + + Domain[] domains = domainService.getAll(); + for(Domain domain: domains) { + if(domain instanceof FuzzySet) + names.add(domain.getName()); + } + + return names.toArray(new String[0]); + } + + public String[] getDomainNames() { + Domain[] domains = domainService.getAll(); + + String[] names = new String[domains.length]; + + for(int i = 0; i < names.length; ++i) { + names[i] = domains[i].getName(); + } + + return names; + } + + public String[] getLabelsNameDomainWeightsExpert(int posExpert) { + ArrayList names = new ArrayList<>(); + + FuzzySet domain = (FuzzySet) weightsDomain; + List labels = domain.getLabelSet().getLabels(); + for(LabelLinguisticDomain label: labels) + names.add(label.getName()); + + return names.toArray(new String[0]); + } + + public boolean domainWeightsIsFuzzySet(int posExpert) { + if(weightsDomain instanceof FuzzySet) + return true; + return false; + } + + public Valuation getValuation(int posCriterion, int posExpert, int posAlternative) { + return valuationService.getAllKV().get(new ProblemElementKey(getExperts()[posExpert], + getCriteria()[posCriterion], getAlternatives()[posAlternative])); + } + + public String getStringWeightedValuation(int posCriterion, int posAlternative, int posExpert) { + if(weightedDecisionMatrices.get(getExperts()[posExpert]) != null) { + Valuation[][] weigthedDecisionMatrix = weightedDecisionMatrices.get((getExperts()[posExpert])); + return weigthedDecisionMatrix[posAlternative][posCriterion].changeFormatValuationToString(); + } + + return ""; + } + + public Valuation getExpertWeight(int posCriterion, int posExpert) { + ProblemElement expert = getExperts()[posExpert]; + + Valuation[] weights = getWeightsByDomain(expert); + + return weights[posCriterion]; + } + + private Valuation[] getWeightsByDomain(ProblemElement expert) { + HashMap weightsForDomains = weights.get(expert); + return weightsForDomains.get(weightsDomain); + } + + public String getStringExpertWeight(int posCriterion, int posExpert) { + return getExpertWeight(posCriterion, posExpert).changeFormatValuationToString(); + } + + public void setExpertWeight(int posCriterion, int posExpert, String weight) { + String valuationId = valuationService.getExtensionIdFor(weightsDomain.getType()); + + Valuation v; + if(valuationId.equals(IntegerIntervalValuation.ID)) { + String format = weight.replace("(", ""); + format = format.replace(")", ""); + format = format.replace("[", ""); + format = format.replace("]", ""); + String[] values = format.split(","); + + v = ContextInjectionFactory.make(IntegerIntervalValuation.class, context); + v.setDomain(weightsDomain); + ((NumericIntervalarValuation) v).setMinMax(Double.parseDouble(values[0]), Double.parseDouble(values[1])); + } else if(valuationId.equals(RealIntervalValuation.ID)) { + String format = weight.replace("(", ""); + format = format.replace(")", ""); + format = format.replace("[", ""); + format = format.replace("]", ""); + String[] values = format.split(","); + + v = ContextInjectionFactory.make(RealIntervalValuation.class, context); + v.setDomain(weightsDomain); + ((NumericIntervalarValuation) v).setMinMax(Double.parseDouble(values[0]), Double.parseDouble(values[1])); + } else if (valuationId.equals(IntegerValuation.ID)) { + v = ContextInjectionFactory.make(IntegerValuation.class, context); + v.setDomain(weightsDomain); + double w = Double.parseDouble(weight); + ((NumericValuation) v).setValue(w); + } else if(valuationId.equals(RealValuation.ID)) { + v = ContextInjectionFactory.make(RealValuation.class, context); + v.setDomain(weightsDomain); + double w = Double.parseDouble(weight); + ((NumericValuation) v).setValue(w); + } else { + v = ContextInjectionFactory.make(LinguisticValuation.class, context); + v.setDomain(weightsDomain); + ((LinguisticValuation) v).setLabel(weight); + } + + Valuation[] expertWeights; + ProblemElement expert = getExperts()[posExpert]; + HashMap weightsForDomain = weights.get(expert); + + if(weights.get(expert) != null) { + if(weightsForDomain != null) { + expertWeights = weightsForDomain.get(weightsDomain); + expertWeights[posCriterion] = v; + } else { + weightsForDomain = new HashMap(); + expertWeights = new Valuation[getNumberCriteria()]; + expertWeights[posCriterion] = v; + weightsForDomain.put(weightsDomain, expertWeights); + } + } else { + weightsForDomain = new HashMap(); + expertWeights = new Valuation[getNumberCriteria()]; + expertWeights[posCriterion] = v; + weightsForDomain.put(weightsDomain, expertWeights); + weights.put((Expert) expert, weightsForDomain); + } + } + + public void execute(int posExpert) { + setUnificationDomainValuations(); + computeWeightedDecisionMatrixExpert(posExpert); + computeSolutions(posExpert); + computeDistanceSolutions(posExpert); + computeGlobalDistancesIdealSolutions(posExpert); + computeClosenessCoefficients(posExpert); + exportInfoToNextStep(); + } + + private void computeWeightedDecisionMatrixExpert(int posExpert) { + Valuation[] expertUnifiedWeights = unifyWeights(posExpert); + + if(expertUnifiedWeights != null && expertUnifiedWeights.length == getCriteria().length) { + TwoTupleValuation[][] expertDecisionMatrix = getExpertDecisionMatrix(posExpert); + TwoTupleValuation[][] expertWeightedDecisionmMatrix = computeWeightedDecisionMatrix(expertDecisionMatrix, expertUnifiedWeights); + weightedDecisionMatrices.put((Expert) getExperts()[posExpert], expertWeightedDecisionmMatrix); + } + } + + private Valuation[] unifyWeights(int posExpert) { + ProblemElement expert = getExperts()[posExpert]; + + Valuation[] expertWeights = weights.get(expert).get(weightsDomain); + Valuation[] expertUnifiedWeights = new Valuation[expertWeights.length]; + + String methodId = (String) this.importDataFromMethod("methodId"), finalValuationId = (String) this.importDataFromMethod("finalValuationId"); + for(int i = 0; i < expertWeights.length; ++i) { + if(expertWeights[i] != null) { + expertUnifiedWeights[i] = unificationService.unify(unificationDomainWeights, expertWeights[i], finalValuationId, methodId); + } else + return null; + } + + return expertUnifiedWeights; + } + + private TwoTupleValuation[][] getExpertDecisionMatrix(int posExpert) { + ProblemElement[] alternatives = getAlternatives(), criteria = getCriteria(); + + TwoTupleValuation[][] decisionMatrix = new TwoTupleValuation[alternatives.length][criteria.length]; + + Map expertUnifiedValuations = getTwoTupleValuations(); + + for (int i = 0; i < alternatives.length; ++i) { + for (int j = 0; j < criteria.length; ++j) { + decisionMatrix[i][j] = expertUnifiedValuations.get(new ProblemElementKey(getExperts()[posExpert], criteria[j], alternatives[i])); + } + } + + return decisionMatrix; + } + + @SuppressWarnings("unchecked") + private Map getTwoTupleValuations() { + Map twoTuple = (Map) importData( + "twoTupleUnifiedValuations"); + exportData("twoTupleValuations", twoTuple); + return twoTuple; + } + + private TwoTupleValuation[][] computeWeightedDecisionMatrix(TwoTupleValuation[][] expertDecisionMatrix, + Valuation[] expertUnifiedWeights) { + + ProblemElement[] alternatives = getAlternatives(), criteria = getCriteria(); + + TwoTupleValuation[][] weightedDecisionMatrix = new TwoTupleValuation[alternatives.length][criteria.length]; + + LabelLinguisticDomain maxLabel = unificationDomainWeights.getLabelSet().getLabel(unificationDomainWeights.getLabelSet().getCardinality() - 1); + TwoTupleValuation maxLabelTwoTuple = new TwoTupleValuation(unificationDomainWeights, maxLabel); + + TwoTupleValuation weight, valuation, weightedValuation; + for (int i = 0; i < expertDecisionMatrix.length; ++i) { + for (int j = 0; j < expertDecisionMatrix[i].length; ++j) { + weight = (TwoTupleValuation) expertUnifiedWeights[j]; + valuation = (TwoTupleValuation) expertDecisionMatrix[i][j]; + weightedValuation = new TwoTupleValuation(unificationDomainValuations); + weightedValuation.calculateDelta(valuation.calculateInverseDelta() * (weight.calculateInverseDelta() / maxLabelTwoTuple.calculateInverseDelta())); + weightedDecisionMatrix[i][j] = weightedValuation; + } + } + + return weightedDecisionMatrix; + } + + private void computeSolutions(int posExpert) { + computePositiveIdealSolution(posExpert); + computeNegativeIdealSolution(posExpert); + } + + private void computePositiveIdealSolution(int posExpert) { + Valuation[] idealSolution = new Valuation[getNumberCriteria()]; + + List valuationsCriterion; + + boolean isCost; + + for (int crit = 0; crit < getNumberCriteria(); ++crit) { + + valuationsCriterion = getValuationsExpertByCriterion(posExpert, crit); + + isCost = ((Criterion) getCriteria()[crit]).isCost(); + + Collections.sort(valuationsCriterion); + + if (isCost) + idealSolution[crit] = valuationsCriterion.get(0); + else + idealSolution[crit] = valuationsCriterion.get(valuationsCriterion.size() - 1); + } + + this.positiveIdealSolution.put((Expert) getExperts()[posExpert], idealSolution); + } + + private List getValuationsExpertByCriterion(int posExpert, int crit) { + List criterionValuations = new ArrayList(); + + Valuation[][] valuations = weightedDecisionMatrices.get(getExperts()[posExpert]); + for(int i = 0; i < valuations.length; ++i) + criterionValuations.add(valuations[i][crit]); + + return criterionValuations; + } + + private void computeNegativeIdealSolution(int posExpert) { + Valuation[] antiIdealSolution = new Valuation[getNumberCriteria()]; + + List valuationsCriterion; + + boolean isCost; + + for (int crit = 0; crit < getNumberCriteria(); ++crit) { + + valuationsCriterion = getValuationsExpertByCriterion(posExpert, crit); + + isCost = ((Criterion) getCriteria()[crit]).isCost(); + + Collections.sort(valuationsCriterion); + + if (isCost) + antiIdealSolution[crit] = valuationsCriterion.get(valuationsCriterion.size() - 1); + else + antiIdealSolution[crit] = valuationsCriterion.get(0); + } + + this.negativeIdealSolution.put((Expert) getExperts()[posExpert], antiIdealSolution); + } + + private void computeDistanceSolutions(int posExpert) { + computeDistanceIdealPositiveSolution(posExpert); + computeDistanceIdealNegativeSolution(posExpert); + } + + private void computeDistanceIdealPositiveSolution(int posExpert) { + Valuation[][] distances = new Valuation[getNumberAlternatives()][getNumberCriteria()]; + + TwoTupleValuation distance; + + ProblemElement[] experts = getExperts(); + + Valuation[] positiveIdealSolution = this.positiveIdealSolution.get(experts[posExpert]); + Valuation[][] weigthedDecisionMatrix = this.weightedDecisionMatrices.get(experts[posExpert]); + + double dist; + for(int i = 0; i < weigthedDecisionMatrix.length; ++i) { + for(int j = 0; j < weigthedDecisionMatrix[i].length; ++j) { + dist = (unificationDomainDistances.getLabelSet().getCardinality() - 1) * + computeDistanceTwoTuple(weigthedDecisionMatrix[i][j], positiveIdealSolution[j]) / (unificationDomainValuations.getLabelSet().getCardinality() - 1); + + distance = new TwoTupleValuation(unificationDomainDistances); + distance.calculateDelta(dist); + + distances[i][j] = distance; + } + } + + this.distancePositiveIdealSolutionMatrices.put((Expert) experts[posExpert], distances); + + } + + private Float computeDistanceTwoTuple(Valuation valuation1, Valuation valuation2) { + return (float) Math.abs(((TwoTupleValuation) valuation1).calculateInverseDelta() - ((TwoTupleValuation) valuation2).calculateInverseDelta()); + } + + private void computeDistanceIdealNegativeSolution(int posExpert) { + Valuation[][] distances = new Valuation[getNumberAlternatives()][getNumberCriteria()]; + + TwoTupleValuation distance; + + ProblemElement[] experts = getExperts(); + + Valuation[] negativeIdealSolution = this.negativeIdealSolution.get(experts[posExpert]); + Valuation[][] weigthedDecisionMatrix = this.weightedDecisionMatrices.get(experts[posExpert]); + + double dist; + for(int i = 0; i < weigthedDecisionMatrix.length; ++i) { + for(int j = 0; j < weigthedDecisionMatrix[i].length; ++j) { + dist = (unificationDomainDistances.getLabelSet().getCardinality() - 1) * + computeDistanceTwoTuple(weigthedDecisionMatrix[i][j], negativeIdealSolution[j]) / (unificationDomainValuations.getLabelSet().getCardinality() - 1); + + distance = new TwoTupleValuation(unificationDomainDistances); + distance.calculateDelta(dist); + + distances[i][j] = distance; + } + } + + this.distanceNegativeIdealSolutionMatrices.put((Expert) experts[posExpert], distances); + } + + private void computeGlobalDistancesIdealSolutions(int posExpert) { + computeGlobalPositiveIdealSolutionDistances(posExpert); + computeGlobalNegativeIdealSolutionDistances(posExpert); + } + + private void computeGlobalPositiveIdealSolutionDistances(int posExpert) { + Valuation[] globalDistances = new Valuation[getNumberAlternatives()]; + + TwoTupleValuation distance; + + Valuation[][] distancesPositiveIdealSolution = distancePositiveIdealSolutionMatrices.get(getExperts()[posExpert]); + + double acum; + for(int i = 0; i < distancesPositiveIdealSolution.length; ++i) { + acum = 0; + for(int j = 0; j < distancesPositiveIdealSolution[i].length; ++j) + acum += ((TwoTupleValuation) distancesPositiveIdealSolution[i][j]).calculateInverseDelta(); + + distance = new TwoTupleValuation(unificationDomainDistances); + distance.calculateDelta(acum /distancesPositiveIdealSolution[i].length); + globalDistances[i] = distance; + } + + this.globalPositiveIdealSolutionDistance.put((Expert) getExperts()[posExpert], globalDistances); + } + + private void computeGlobalNegativeIdealSolutionDistances(int posExpert) { + Valuation[] globalDistances = new Valuation[getNumberAlternatives()]; + + TwoTupleValuation distance; + + Valuation[][] distancesNegativeIdealSolution = distanceNegativeIdealSolutionMatrices.get(getExperts()[posExpert]); + + double acum; + for(int i = 0; i < distancesNegativeIdealSolution.length; ++i) { + acum = 0; + for(int j = 0; j < distancesNegativeIdealSolution[i].length; ++j) + acum += ((TwoTupleValuation) distancesNegativeIdealSolution[i][j]).calculateInverseDelta(); + + distance = new TwoTupleValuation(unificationDomainDistances); + distance.calculateDelta(acum / distancesNegativeIdealSolution[i].length); + globalDistances[i] = distance; + } + + this.globalNegativeIdealSolutionDistance.put((Expert) getExperts()[posExpert], globalDistances); + } + + private void computeClosenessCoefficients(int posExpert) { + Valuation[] closenessCoefficients = new Valuation[getNumberAlternatives()]; + + TwoTupleValuation closeness; + + Valuation[] globalPositiveIdealDistance = globalPositiveIdealSolutionDistance.get(getExperts()[posExpert]); + Valuation[] globalNegativeIdealDistance = globalNegativeIdealSolutionDistance.get(getExperts()[posExpert]); + + double posDist, negDist, coeff; + for(int i = 0; i < globalPositiveIdealDistance.length; ++i) { + posDist = ((TwoTupleValuation) globalPositiveIdealDistance[i]).calculateInverseDelta(); + negDist = ((TwoTupleValuation) globalNegativeIdealDistance[i]).calculateInverseDelta(); + coeff = (unificationDomainDistances.getLabelSet().getCardinality() - 1) * (negDist / (posDist + negDist)); + + closeness = new TwoTupleValuation(unificationDomainDistances); + closeness.calculateDelta(coeff); + closenessCoefficients[i] = closeness; + } + + this.closenessCoefficients.put((Expert) getExperts()[posExpert], closenessCoefficients); + } + + public void executeForAllExperts() { + for(int exp = 0; exp < getNumberExperts(); ++exp) + execute(exp); + } + + public String getStringPositiveIdealSolutionCriterion(int posCriterion, int posExpert) { + return positiveIdealSolution.get(getExperts()[posExpert])[posCriterion].changeFormatValuationToString(); + } + + public String getStringNegativeIdealSolutionCriterion(int posCriterion, int posExpert) { + return negativeIdealSolution.get(getExperts()[posExpert])[posCriterion].changeFormatValuationToString(); + } + + public String getStringDistancePositiveIdealSolutionValuation(int posCriterion, int posAlternative, int posExpert) { + TwoTupleValuation distance = (TwoTupleValuation) distancePositiveIdealSolutionMatrices.get(getExperts()[posExpert])[posAlternative][posCriterion]; + return distance.changeFormatValuationToString() + " " + "(" + Math.round(distance.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringDistanceNegativeIdealSolutionValuation(int posCriterion, int posAlternative, int posExpert) { + TwoTupleValuation distance = (TwoTupleValuation) distanceNegativeIdealSolutionMatrices.get(getExperts()[posExpert])[posAlternative][posCriterion]; + return distance.changeFormatValuationToString() + " " + "(" + Math.round(distance.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringGlobalDistancePositiveIdealSolutionValuation(int posAlternative, int posExpert) { + TwoTupleValuation distance = (TwoTupleValuation) globalPositiveIdealSolutionDistance.get(getExperts()[posExpert])[posAlternative]; + return distance.changeFormatValuationToString() + " " + "(" + Math.round(distance.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public String getStringGlobalDistanceNegativeIdealSolutionValuation(int posAlternative, int posExpert) { + TwoTupleValuation distance = (TwoTupleValuation) globalNegativeIdealSolutionDistance.get(getExperts()[posExpert])[posAlternative]; + return distance.changeFormatValuationToString() + " " + "(" + Math.round(distance.calculateInverseDelta()* 1000d) / 1000d + ")"; + } + + public String getStringClosenessCoefficient(int posAlternative, int posExpert) { + TwoTupleValuation coefficient = (TwoTupleValuation) closenessCoefficients.get(getExperts()[posExpert])[posAlternative]; + return coefficient.changeFormatValuationToString() + " " + "(" + Math.round(coefficient.calculateInverseDelta() * 1000d) / 1000d + ")"; + } + + public void initializeDefaultWeights() { + ProblemElement expert; + + for(Domain domain: domainService.getAll()) { + + String valuationId = valuationService.getExtensionIdFor(domain.getType()); + + if(valuationId.equals(IntegerIntervalValuation.ID)) { + + NumericDomain numeric = (NumericDomain) domain; + IntegerIntervalValuation wVal; + + Valuation[] weights; + for(int exp = 0; exp < getExperts().length; ++exp) { + weights = new Valuation[getCriteria().length]; + for(int crit = 0; crit < weights.length; ++crit) { + wVal = ContextInjectionFactory.make(IntegerIntervalValuation.class, context); + wVal.setDomain(numeric); + wVal.setMinMax(numeric.getMin(), numeric.getMax()); + weights[crit] = wVal; + } + + expert = (Expert) getExperts()[exp]; + if(this.weights.get(expert) != null) { + HashMap weightsForDomain = this.weights.get(expert); + weightsForDomain.put(domain, weights); + } else { + HashMap weightsForDomain = new HashMap(); + weightsForDomain.put(domain, weights); + this.weights.put((Expert) expert, weightsForDomain); + } + } + + } else if(valuationId.equals(RealIntervalValuation.ID)) { + + NumericDomain numeric = (NumericDomain) domain; + RealIntervalValuation wVal; + + Valuation[] weights; + for(int exp = 0; exp < getExperts().length; ++exp) { + weights = new Valuation[getCriteria().length]; + for(int crit = 0; crit < weights.length; ++crit) { + wVal = ContextInjectionFactory.make(RealIntervalValuation.class, context); + wVal.setDomain(numeric); + wVal.setMinMax(numeric.getMin(), numeric.getMax()); + weights[crit] = wVal; + } + + expert = (Expert) getExperts()[exp]; + if(this.weights.get(expert) != null) { + HashMap weightsForDomain = this.weights.get(expert); + weightsForDomain.put(domain, weights); + } else { + HashMap weightsForDomain = new HashMap(); + weightsForDomain.put(domain, weights); + this.weights.put((Expert) expert, weightsForDomain); + } + } + + } else if (valuationId.equals(IntegerValuation.ID)) { + + NumericDomain numeric = (NumericDomain) domain; + IntegerValuation wVal; + + Valuation[] weights; + for(int exp = 0; exp < getExperts().length; ++exp) { + weights = new Valuation[getCriteria().length]; + for(int crit = 0; crit < weights.length; ++crit) { + wVal = ContextInjectionFactory.make(IntegerValuation.class, context); + wVal.setDomain(domain); + wVal.setValue((double) Math.round((numeric.getMin() + numeric.getMax()) / 2)); + weights[crit] = wVal; + } + + expert = (Expert) getExperts()[exp]; + if(this.weights.get(expert) != null) { + HashMap weightsForDomain = this.weights.get(expert); + weightsForDomain.put(domain, weights); + } else { + HashMap weightsForDomain = new HashMap(); + weightsForDomain.put(domain, weights); + this.weights.put((Expert) expert, weightsForDomain); + } + } + + } else if(valuationId.equals(RealValuation.ID)) { + + NumericDomain numeric = (NumericDomain) domain; + RealValuation wVal; + + Valuation[] weights; + for(int exp = 0; exp < getExperts().length; ++exp) { + weights = new Valuation[getCriteria().length]; + for(int crit = 0; crit < weights.length; ++crit) { + wVal = ContextInjectionFactory.make(RealValuation.class, context); + wVal.setDomain(domain); + wVal.setValue((numeric.getMin() + numeric.getMax()) / 2); + weights[crit] = wVal; + } + + expert = (Expert) getExperts()[exp]; + if(this.weights.get(expert) != null) { + HashMap weightsForDomain = this.weights.get(expert); + weightsForDomain.put(domain, weights); + } else { + HashMap weightsForDomain = new HashMap(); + weightsForDomain.put(domain, weights); + this.weights.put((Expert) expert, weightsForDomain); + } + } + + } else { + + FuzzySet fuzzySet = (FuzzySet) domain; + LinguisticValuation wVal; + + Valuation[] weights; + + for(int exp = 0; exp < getExperts().length; ++exp) { + weights = new Valuation[getCriteria().length]; + for(int crit = 0; crit < weights.length; ++crit) { + wVal = ContextInjectionFactory.make(LinguisticValuation.class, context); + wVal.setDomain(domain); + wVal.setLabel(fuzzySet.getLabelSet().getLabel((int) fuzzySet.getLabelSet().getCardinality() / 2)); + weights[crit] = wVal; + } + + expert = (Expert) getExperts()[exp]; + if(this.weights.get(expert) != null) { + HashMap weightsForDomain = this.weights.get(expert); + weightsForDomain.put(domain, weights); + } else { + HashMap weightsForDomain = new HashMap(); + weightsForDomain.put(domain, weights); + this.weights.put((Expert) expert, weightsForDomain); + } + } + } + } + } + + public boolean unificationDomainChanged() { + FuzzySet oldDomain = (FuzzySet) this.unificationDomainValuations.clone(); + setUnificationDomainValuations(); + return (!oldDomain.equals(this.unificationDomainValuations)) ? true: false; + } + + public boolean isFinished() { + return (closenessCoefficients.size() == getNumberExperts()) ? true:false; + } + + private void exportInfoToNextStep() { + exportData("valuationDomain", unificationDomainValuations); + exportData("distanceDomain", unificationDomainDistances); + exportData("coefficients", closenessCoefficients); + } +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/Messages.java b/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/Messages.java new file mode 100644 index 0000000..3973f46 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/Messages.java @@ -0,0 +1,11 @@ +package flintstones.method.linguistic.topsis.phase.experts.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Phase_Name; + +} diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/messages.properties b/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/messages.properties new file mode 100644 index 0000000..dad66be --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/messages.properties @@ -0,0 +1 @@ +Phase_Name=Expert TOPSIS \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/messages_es.properties b/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/messages_es.properties new file mode 100644 index 0000000..ea2ec08 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis.phase.experts/src/flintstones/method/linguistic/topsis/phase/experts/messages/messages_es.properties @@ -0,0 +1 @@ +Phase_Name=TOPSIS experto \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis/.classpath b/bundles/flintstones.method.linguistic.topsis/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis/.polyglot.META-INF b/bundles/flintstones.method.linguistic.topsis/.polyglot.META-INF new file mode 100644 index 0000000..1234b0e --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.topsis + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Linguistic TOPSIS + + Sinbad2 + + diff --git a/bundles/flintstones.method.linguistic.topsis/.project b/bundles/flintstones.method.linguistic.topsis/.project new file mode 100644 index 0000000..7347db7 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.topsis + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362680 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.topsis/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.topsis/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b782e09 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Linguistic TOPSIS +Bundle-SymbolicName: flintstones.method.linguistic.topsis;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.method.linguistic.topsis +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method, + flintstones.entity.validatedmethod, + flintstones.helper.faq, + flintstones.domain.fuzzyset, + flintstones.valuation.twoTuple diff --git a/bundles/flintstones.method.linguistic.topsis/build.properties b/bundles/flintstones.method.linguistic.topsis/build.properties new file mode 100644 index 0000000..6b51e48 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + faq/ diff --git a/bundles/flintstones.method.linguistic.topsis/faq/faq.en.md b/bundles/flintstones.method.linguistic.topsis/faq/faq.en.md new file mode 100644 index 0000000..72c20ec --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/faq/faq.en.md @@ -0,0 +1 @@ +This a version of the 2-tuple TOPSIS approach introduced in O. Sohaib, M. Naderpour, W. Hussain, L. Martinez, Cloud computing model selection for e-commerce enterprises using a new 2-tuple fuzzy linguistic decision-making method, Comput. Ind. Eng. 132 (2019), 47–58, which makes use of the 2-tuple linguistic model and a new distance function that allows to obtain more precise and interpretable results than other models. However, instead of aggregating the initial input from the experts using average values and then perform the 2-tuple TOPSIS, here it is followed the methodology established by Krohling and Campanharo where the fuzzy TOPSIS was used in the experts' preference to create a global model and then another round of fuzzy TOPSIS was performed to acquire the global solution with the experts' individual solutions acting as the criteria. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis/faq/faq.es.md b/bundles/flintstones.method.linguistic.topsis/faq/faq.es.md new file mode 100644 index 0000000..24a8576 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/faq/faq.es.md @@ -0,0 +1 @@ +Se trata de una versión del enfoque TOPSIS 2-tuplas introducido en O. Sohaib, M. Naderpour, W. Hussain, L. Martinez, Cloud computing model selection for e-commerce enterprises using a new 2-tuple fuzzy linguistic decision-making method, Comput. Ind. Eng. 132 (2019), 47-58, que hace uso del modelo lingüístico de 2-tuplas y de una nueva función de distancia que permite obtener resultados más precisos e interpretables que otros modelos. Sin embargo, en lugar de agregar la entrada inicial de los expertos utilizando valores promedio y luego realizar el TOPSIS 2-tuplas, aquí se sigue la metodología establecida por Krohling y Campanharo donde se utilizó el TOPSIS difuso en la preferencia de los expertos para crear un modelo global y luego se realizó otra ronda de TOPSIS difuso para adquirir la solución global con las soluciones individuales de los expertos actuando como criterio. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis/plugin.xml b/bundles/flintstones.method.linguistic.topsis/plugin.xml new file mode 100644 index 0000000..4db2be1 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/LinguisticTOPSIS.java b/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/LinguisticTOPSIS.java new file mode 100644 index 0000000..70c1daf --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/LinguisticTOPSIS.java @@ -0,0 +1,63 @@ +package flintstones.method.linguistic.topsis; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.topsis.messages.Messages; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class LinguisticTOPSIS extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_Name; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } + + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + int numDomains = domainService.getAll().length; + String numDomainEntity = domainMessages.Domain_count; + + Domain[] fuzzysetDomains = domainService.getAll(FuzzySet.ID); + String fuzzysetDomainsEntity = domainMessages.Domain_type_entities; + + ValidBLTSDomainOperation validBLTSDomainOperation = new ValidBLTSDomainOperation(fuzzysetDomainsEntity, + fuzzysetDomains); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains")//$NON-NLS-1$ + .custom(validBLTSDomainOperation) + .named("fuzzySetDomains");//$NON-NLS-1$ + } + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + +} diff --git a/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/Messages.java b/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/Messages.java new file mode 100644 index 0000000..45ce39b --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/Messages.java @@ -0,0 +1,11 @@ +package flintstones.method.linguistic.topsis.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_Name; + +} diff --git a/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/messages.properties b/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/messages.properties new file mode 100644 index 0000000..2dceb96 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/messages.properties @@ -0,0 +1 @@ +Method_Name=Linguistic Technique for Order of Preference by Similarity to Ideal Solution (APOLLO) \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/messages_es.properties b/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/messages_es.properties new file mode 100644 index 0000000..c327869 --- /dev/null +++ b/bundles/flintstones.method.linguistic.topsis/src/flintstones/method/linguistic/topsis/messages/messages_es.properties @@ -0,0 +1 @@ +Method_Name=Tcnica para el orden de preferencia mediante cercania a la solucin ideal (APOLLO) \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.classpath b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.polyglot.META-INF b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.polyglot.META-INF new file mode 100644 index 0000000..1e9ed0b --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.project b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.project new file mode 100644 index 0000000..34a3989 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362684 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b1a8a32 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.unbalanced.phase.calculaterepresentation.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Import-Package: flintstones.method.linguistic.unbalanced.phase.calculaterepresentation +Require-Bundle: org.eclipse.swt, + flintstones.helper.ui, + javax.inject, + flintstones.domain.fuzzyset.unbalanced, + flintstones.domain.numeric.real, + flintstones.domain.fuzzyset.ui.dialog, + flintstones.domain.fuzzyset.unbalanced.ui.dialog, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.domain.fuzzyset.ui.chart, + flintstones.domain.fuzzyset.unbalanced.ui.chart, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/build.properties b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/plugin.xml b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/plugin.xml new file mode 100644 index 0000000..b65c224 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/src/flintstones/method/linguistic/unbalanced/phase/calculaterepresentation/ui/CalculateRepresentationUI.java b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/src/flintstones/method/linguistic/unbalanced/phase/calculaterepresentation/ui/CalculateRepresentationUI.java new file mode 100644 index 0000000..db545f5 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui/src/flintstones/method/linguistic/unbalanced/phase/calculaterepresentation/ui/CalculateRepresentationUI.java @@ -0,0 +1,330 @@ +package flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.ui; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +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.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.graphics.Color; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import flintstones.domain.fuzzyset.ui.chart.PlainFuzzySetChart; +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.domain.fuzzyset.unbalanced.ui.chart.LHChart; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.method.linguistic.unbalanced.phase.calculaterepresentation.CalculateRepresentationModel; +import flintstones.model.ui.service.UiService; + +public class CalculateRepresentationUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + + CalculateRepresentationModel phaseMethod; + + // FS3 + private Composite _parent; + private Composite _representationPanel; + private Composite _chartPanel; + + private TableViewer _representationViewer; + + private TableViewerColumn _colorColumn; + private TableViewerColumn _labelColumn; + private TableViewerColumn _lhColumn; + private TableViewerColumn _bridColumn; + + private LHChart _chart; + + private ControlAdapter _controlListener; + + private int _selectionPos; + + private Unbalanced _domain; + + private int[] _lh; + + + + + @Override + public void init() { + phaseMethod = (CalculateRepresentationModel) this.getModel(); + + Composite parent = this.getBaseComposite(); + createPartControl(parent); + activate(); + + } + + @Override + public void refresh() { + activate(); + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + public void createPartControl(Composite parent) { + + _parent = parent; + + UiService.setGridLayout(_parent, 2, true); + UiService.setGridData(_parent, 9, 9, true, true); + + + Composite left = new Composite(_parent, SWT.NONE); + UiService.setGridLayout(left, 1); + UiService.setGridData(left, 9, 9, true, true); + + createRepresentationInfo(left); + + + Composite right = new Composite(_parent, SWT.BORDER); + UiService.setGridLayout(right, 1); + UiService.setGridData(right, 9, 9, true, true); + + createChart(right); + + } + + private void createRepresentationInfo(Composite left) { + _representationPanel = left; +// _representationPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 6, 1)); +// GridLayout layout = new GridLayout(1, false); +// layout.marginBottom = 0; +// layout.marginTop = 0; +// layout.verticalSpacing = 0; +// layout.marginHeight = 0; +// layout.marginWidth = 0; +// layout.horizontalSpacing = 0; +// _representationPanel.setLayout(layout); + + _representationViewer = new TableViewer(_representationPanel, SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + gridData.verticalIndent = 0; + _representationViewer.getTable().setLayoutData(gridData); + _representationViewer.getTable().setHeaderVisible(true); + _representationViewer.setContentProvider(new IStructuredContentProvider() { + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + + @Override + public void dispose() {} + + @Override + public Object[] getElements(Object inputElement) { + Unbalanced domain = (Unbalanced) inputElement; + + Object[] result = new Object[domain.getLabelSet().getCardinality()]; + Object[] element; + int r, g, b; + for(int i = 0; i < result.length; i++) { + element = new Object[4]; + java.awt.Color color = PlainFuzzySetChart.getColor(i); + r = color.getRed(); + g = color.getGreen(); + b = color.getBlue(); + element[0] = new Color(Display.getCurrent(), r, g, b); + element[1] = domain.getLabelSet().getLabel(i).getName(); + StringBuilder LHS = null; + boolean brid = false; + int other = -1; + boolean find; + int t; + + for(Integer pos : domain.getLabel(i).keySet()) { + find = false; + t = 0; + do { + if(pos == _lh[t]) { + find = true; + } else { + t++; + } + } while (!find); + t++; + + if(LHS == null) { + brid = false; + LHS = new StringBuilder("s" + domain.getLabel(i).get(pos) + " l(" + t + "," + pos + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + other = pos; + } else { + brid = true; + NumericRealDomain center = _domain.getLabelSet().getLabel(i).getSemantic().getCenter(); + NumericRealDomain coverage = _domain.getLabelSet().getLabel(i).getSemantic().getCoverage(); + + double left = center.getMin() - coverage.getMin(); + double right = coverage.getMax() - center.getMax(); + + if(((left > right) && (other < pos)) || ((left < right) && (other > pos))) { + LHS.append(" " + "or" + " s" + domain.getLabel(i).get(pos) + " l(" + t + "," + pos + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + } else { + String aux = LHS.toString(); + LHS = new StringBuilder("s" + domain.getLabel(i).get(pos) + " l(" + t + "," + pos + ") " + "or" + " " + aux); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + } + } + } + element[2] = LHS.toString(); + element[3] = Boolean.toString(brid); + result[i] = element; + } + return result; + } + }); + + _colorColumn = new TableViewerColumn(_representationViewer, SWT.NONE); + _colorColumn.getColumn().setWidth(25); + _colorColumn.getColumn().setResizable(false); + _colorColumn.getColumn().setMoveable(false); + _colorColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return ""; //$NON-NLS-1$ + } + + @Override + public Color getBackground(Object element) { + return (Color) ((Object[]) element)[0]; + } + }); + + _labelColumn = new TableViewerColumn(_representationViewer, SWT.NONE); + _labelColumn.getColumn().setWidth(100); + _labelColumn.getColumn().setText("S"); //$NON-NLS-1$ + _labelColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return (String) ((Object[]) element)[1]; + } + }); + + _lhColumn = new TableViewerColumn(_representationViewer, SWT.NONE); + _lhColumn.getColumn().setWidth(100); + _lhColumn.getColumn().setText("LH_S"); //$NON-NLS-1$ + _lhColumn.getColumn().setAlignment(SWT.CENTER); + _lhColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return (String) ((Object[]) element)[2]; + } + }); + + _bridColumn = new TableViewerColumn(_representationViewer, SWT.NONE); + _bridColumn.getColumn().setWidth(100); + _bridColumn.getColumn().setText("Brid"); //$NON-NLS-1$ + _bridColumn.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + return ((String) ((Object[]) element)[3]).toUpperCase(); + } + }); + + _representationViewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + ISelection selection = _representationViewer.getSelection(); + String selectLabel = (String) ((Object[]) ((IStructuredSelection) selection).getFirstElement())[1]; + _selectionPos = _domain.getLabelSet().getPos(selectLabel); + _chart.select(_selectionPos); + } + }); + } + + + private void createChart(Composite right) { + _chartPanel = right; +// GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 8, 1); +// _chartPanel.setLayoutData(gridData); + } + + + private void calculateRepresentation() { + + if(_domain == null) { + _domain = phaseMethod.getFinalUnifiedDomain(); + } + if(_lh == null) { + generateLH(); + } + + _representationViewer.setInput(_domain); + + _labelColumn.getColumn().pack(); + _labelColumn.getColumn().setWidth(_labelColumn.getColumn().getWidth() + 10); + _lhColumn.getColumn().pack(); + _lhColumn.getColumn().setWidth(_lhColumn.getColumn().getWidth() + 10); + _bridColumn.getColumn().pack(); + _bridColumn.getColumn().setWidth(_bridColumn.getColumn().getWidth() + 10); + + String representation = _domain.getInfo(); + + if (representation != null) { + // TODO Quizás es necesario para limitar el paso a la siguiente fase + boolean _completed = true; + _completed = !_completed; + _completed = !_completed; + } else { + _domain = null; + _selectionPos = -1; + } + } + + private void generateLH() { + _lh = _domain.getLh(); + + if(_lh != null) { + _chart = ContextInjectionFactory.make(LHChart.class, context); + _chart.initLHChart(_lh, _chartPanel, _chartPanel.getSize().x, _chartPanel.getSize().y - 1, _domain); + if(_controlListener == null) { + _controlListener = new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + _chart.dispose(); + generateLH(); + } + }; + _chartPanel.addControlListener(_controlListener); + } + if(_selectionPos != -1) { + _chart.select(_selectionPos); + } + } else { + if(_chart != null) { + _chart.dispose(); + _chart = null; + _selectionPos = -1; + } + } + } + + public void activate() { + if(_domain == null) { + calculateRepresentation(); + } + _representationPanel.layout(); + _chartPanel.layout(); +// phaseMethod.setFinalUnifiedDomain(_domain); + } + + + +} diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.classpath b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.polyglot.META-INF b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.polyglot.META-INF new file mode 100644 index 0000000..251dac1 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.unbalanced.phase.calculaterepresentation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Calculaterepresentation + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.project b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.project new file mode 100644 index 0000000..d85f5e1 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.unbalanced.phase.calculaterepresentation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362683 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4a4be9c --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Calculaterepresentation +Bundle-SymbolicName: flintstones.method.linguistic.unbalanced.phase.calculaterepresentation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.unbalanced.phase.calculaterepresentation +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.method.linguistic.unbalanced.phase.calculaterepresentation +Require-Bundle: flintstones.domain.fuzzyset.unbalanced, + flintstones.operator, + flintstones.model.domain.service, + javax.inject, + flintstones.entity.domain, + flintstones.entity.method.phase diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/build.properties b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/plugin.xml b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/plugin.xml new file mode 100644 index 0000000..3db3111 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/src/flintstones/method/linguistic/unbalanced/phase/calculaterepresentation/CalculateRepresentationModel.java b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/src/flintstones/method/linguistic/unbalanced/phase/calculaterepresentation/CalculateRepresentationModel.java new file mode 100644 index 0000000..a343815 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.calculaterepresentation/src/flintstones/method/linguistic/unbalanced/phase/calculaterepresentation/CalculateRepresentationModel.java @@ -0,0 +1,26 @@ +package flintstones.method.linguistic.unbalanced.phase.calculaterepresentation; + +import javax.inject.Inject; + +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.model.domain.service.IDomainService; + +public class CalculateRepresentationModel extends PhaseMethod { + + @Inject + IDomainService domainService; + + @Override + public String getName() { + return "Calculate Representation"; + } + + // Este es un falso dominio unificado que se corresponde con el único dominio unbalance que entra. + // Se mantiene el nombre por ser el nombre que se usaba en FS3. El unificado real es "finalUnifiedDomain" + public Unbalanced getFinalUnifiedDomain() { + Unbalanced unifiedDomain = (Unbalanced) domainService.getAll()[0]; + this.exportData("unifiedDomain", unifiedDomain); + return unifiedDomain; + } +} diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.classpath b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.polyglot.META-INF b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.polyglot.META-INF new file mode 100644 index 0000000..c838c0a --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.unbalanced.phase.generatelh.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.project b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.project new file mode 100644 index 0000000..e0ec0f9 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.unbalanced.phase.generatelh.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362685 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2cd1206 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.linguistic.unbalanced.phase.generatelh.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.unbalanced.phase.generatelh.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.swt, + javax.inject, + flintstones.helper.ui, + flintstones.domain.fuzzyset.unbalanced.ui.dialog, + org.eclipse.wb.swt, + flintstones.domain.fuzzyset.unbalanced, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.domain.fuzzyset.unbalanced.ui.chart, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.entity.method.phase.ui +Import-Package: flintstones.method.linguistic.unbalanced.phase.generatelh diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/build.properties b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/plugin.xml b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/plugin.xml new file mode 100644 index 0000000..b619bd9 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/src/flintstones/method/linguistic/unbalanced/phase/generatelh/ui/GenerateLinguisticHierarchyUI.java b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/src/flintstones/method/linguistic/unbalanced/phase/generatelh/ui/GenerateLinguisticHierarchyUI.java new file mode 100644 index 0000000..9dc1c1d --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh.ui/src/flintstones/method/linguistic/unbalanced/phase/generatelh/ui/GenerateLinguisticHierarchyUI.java @@ -0,0 +1,145 @@ +package flintstones.method.linguistic.unbalanced.phase.generatelh.ui; + + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.wb.swt.SWTResourceManager; + +import flintstones.domain.fuzzyset.unbalanced.ui.chart.LHChart; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.method.linguistic.unbalanced.phase.generatelh.GenerateLinguisticHierarchyModel; +import flintstones.model.ui.service.UiService; + +public class GenerateLinguisticHierarchyUI extends PhaseMethodUI { + + + @Inject + IEclipseContext context; + + GenerateLinguisticHierarchyModel phaseModel; + Composite parent; + + // FS3 + private Composite _infoPanel; + private Composite _chartPanel; + private Label _lhLabel; + private LHChart _chart; + private int[] _lh; + private ControlListener _controlListener; + + @Override + public void init() { + phaseModel = (GenerateLinguisticHierarchyModel) this.getModel(); + createPartControl(this.getBaseComposite()); + } + + @Override + public void refresh() { + + } + + @Override + public boolean isForwardEnabled() { + return true; + } + + public void createPartControl(Composite base) { + parent = base; + + UiService.setGridLayout(base, 1); + UiService.setGridData(base, 9, 9, true, true); + + Composite chartBase = new Composite(base, SWT.NONE); + UiService.setGridLayout(chartBase, 1); + UiService.setGridData(chartBase, 9, 9, true, true); + + Display.getCurrent().syncExec(new Runnable() { + @Override + public void run() { + createChart(chartBase); + } + }); + + activate(); + + } + + private void createChart(Composite _parent) { + + _infoPanel = new Composite(_parent, SWT.NONE); + _infoPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); + _infoPanel.setLayout(new GridLayout(2, false)); + + Label lh = new Label(_infoPanel, SWT.NONE); + lh.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.BOLD)); //$NON-NLS-1$ + lh.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); + lh.setText("LH"); //$NON-NLS-1$ + + _lhLabel = new Label(_infoPanel, SWT.NONE); + _lhLabel.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.NONE)); //$NON-NLS-1$ + _lhLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); + _lhLabel.setText("Messages.GenerateLH_Empty_value"); + + _chartPanel = new Composite(_parent, SWT.BORDER); + GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1); + _chartPanel.setLayoutData(gridData); + } + + + private void generateLH() { + _lh = phaseModel.getUnifiedDomain().getLh(); + if(_lh != null) { + StringBuilder description = new StringBuilder("["); //$NON-NLS-1$ + for(int i = 0; i < _lh.length; i++) { + description.append(_lh[i]); + if(i < (_lh.length - 1)) { + description.append(", "); //$NON-NLS-1$ + } else { + description.append("]"); //$NON-NLS-1$ + _lhLabel.setText(description.toString()); + } + } + + _chart = ContextInjectionFactory.make(LHChart.class, this.context); + _chart.initLHChart(_lh, _chartPanel, _chartPanel.getSize().x, _chartPanel.getSize().y - 1); + + if(_controlListener == null) { + _controlListener = new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + _chart.dispose(); + generateLH(); + } + }; + _chartPanel.addControlListener(_controlListener); + } + } else { + if (_chart != null) { + _chart.dispose(); + _chart = null; + _lhLabel.setText("Messages.GenerateLH_Empty_value"); + } + } + } + + public void activate() { + if(_lh == null) { + generateLH(); + _chartPanel.layout(); + } + } + + + +} diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.classpath b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.polyglot.META-INF b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.polyglot.META-INF new file mode 100644 index 0000000..65828a2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.unbalanced.phase.generatelh + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Generatelh + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.project b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.project new file mode 100644 index 0000000..cb5d5ea --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.unbalanced.phase.generatelh + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362684 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9ca1654 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Generatelh +Bundle-SymbolicName: flintstones.method.linguistic.unbalanced.phase.generatelh;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.unbalanced.phase.generatelh +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.method.linguistic.unbalanced.phase.generatelh +Require-Bundle: flintstones.domain.fuzzyset.unbalanced, + javax.inject, + flintstones.model.domain.service, + flintstones.entity.domain, + flintstones.entity.method.phase diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/build.properties b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/plugin.xml b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/plugin.xml new file mode 100644 index 0000000..7bdc737 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/src/flintstones/method/linguistic/unbalanced/phase/generatelh/GenerateLinguisticHierarchyModel.java b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/src/flintstones/method/linguistic/unbalanced/phase/generatelh/GenerateLinguisticHierarchyModel.java new file mode 100644 index 0000000..6c54b67 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced.phase.generatelh/src/flintstones/method/linguistic/unbalanced/phase/generatelh/GenerateLinguisticHierarchyModel.java @@ -0,0 +1,25 @@ +package flintstones.method.linguistic.unbalanced.phase.generatelh; + +import javax.inject.Inject; + +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.model.domain.service.IDomainService; + +public class GenerateLinguisticHierarchyModel extends PhaseMethod { + + @Inject + IDomainService domainService; + + public GenerateLinguisticHierarchyModel() {} + + @Override + public String getName() { + return "GenerateLH"; + } + + public Unbalanced getUnifiedDomain() { + return (Unbalanced) domainService.getAll()[0]; + } + +} diff --git a/bundles/flintstones.method.linguistic.unbalanced/.classpath b/bundles/flintstones.method.linguistic.unbalanced/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced/.polyglot.META-INF b/bundles/flintstones.method.linguistic.unbalanced/.polyglot.META-INF new file mode 100644 index 0000000..ccdfbd9 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.linguistic.unbalanced + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Unbalanced + diff --git a/bundles/flintstones.method.linguistic.unbalanced/.project b/bundles/flintstones.method.linguistic.unbalanced/.project new file mode 100644 index 0000000..e4ee9bd --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/.project @@ -0,0 +1,45 @@ + + + flintstones.method.linguistic.unbalanced + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362683 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.linguistic.unbalanced/META-INF/MANIFEST.MF b/bundles/flintstones.method.linguistic.unbalanced/META-INF/MANIFEST.MF new file mode 100644 index 0000000..525357c --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.linguistic.unbalanced;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.unbalanced +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.domain.fuzzyset.unbalanced, + flintstones.valuation.twoTuple, + flintstones.valuation.unbalanced, + flintstones.helper.faq diff --git a/bundles/flintstones.method.linguistic.unbalanced/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.linguistic.unbalanced/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..235fbbb --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.unbalanced +Bundle-Name = Unbalanced \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.unbalanced/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.linguistic.unbalanced/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..235fbbb --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.linguistic.unbalanced +Bundle-Name = Unbalanced \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.unbalanced/build.properties b/bundles/flintstones.method.linguistic.unbalanced/build.properties new file mode 100644 index 0000000..4abcbd2 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.linguistic.unbalanced/faq/faq.en.md b/bundles/flintstones.method.linguistic.unbalanced/faq/faq.en.md new file mode 100644 index 0000000..3683cc0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/faq/faq.en.md @@ -0,0 +1,2 @@ +Most linguistic decision problems model information with linguistic variables assessed in linguistic term sets whose terms are uniform and symmetrically distributed, because it is enough to obtain satisfactory results. It might raise the necessity in linguistic decision problems of modelling linguistic assessments by means of linguistic information not uniformly distributed which belongs to linguistic term sets. This necessity may be due to the nature of the linguistic variables that participate in the problem or because the preferences need a greater granularity on one side of the scale than on the other. +A new methodology to deal with unabalanced linguistic information that develops a fuzzy representation method for unbalanced linguistic term sets and also introduces a computational model to accomplish processes of computing with words without loss of information by using the 2-tuple linguistic model. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.unbalanced/faq/faq.es.md b/bundles/flintstones.method.linguistic.unbalanced/faq/faq.es.md new file mode 100644 index 0000000..f8c32cb --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/faq/faq.es.md @@ -0,0 +1,2 @@ +Most linguistic decision problems model information with linguistic variables assessed in linguistic term sets whose terms are uniform and symmetrically distributed, because it is enough to obtain satisfactory results. It might raise the necessity in linguistic decision problems of modelling linguistic assessments by means of linguistic information not uniformly distributed which belongs to linguistic term sets. This necessity may be due to the nature of the linguistic variables that participate in the problem or because the preferences need a greater granularity on one side of the scale than on the other. +A new methodology to deal with unabalanced linguistic information that develops a fuzzy representation method for unbalanced linguistic term sets and also introduces a computational model to accomplish processes of computing with words without loss of information by using the 2-tuple linguistic model. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.unbalanced/plugin.xml b/bundles/flintstones.method.linguistic.unbalanced/plugin.xml new file mode 100644 index 0000000..dece8fa --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/plugin.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.linguistic.unbalanced/problem/ejemplo_libro.flintstones b/bundles/flintstones.method.linguistic.unbalanced/problem/ejemplo_libro.flintstones new file mode 100644 index 0000000..dd971c9 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/problem/ejemplo_libro.flintstones @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/UnbalancedMethod.java b/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/UnbalancedMethod.java new file mode 100644 index 0000000..ec09131 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/UnbalancedMethod.java @@ -0,0 +1,76 @@ +package flintstones.method.linguistic.unbalanced; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.entity.domain.Domain; +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.DomainTypeOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.linguistic.unbalanced.messages.Messages; +import flintstones.valuation.twoTuple.TwoTupleValuation; +import flintstones.valuation.unbalanced.UnbalancedValuation; + +public class UnbalancedMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.Method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Domain[] domains = domainService.getAll(); + int numDomains = domains.length; + Valuation[] valuations = valuationService.getAll(); + + String numDomainEntity = domainMessages.Domain_count; + String domainsEntity = domainMessages.Domain_entities; + String valuationsEntity = valuationMessages.Valuation_entity; + + DomainTypeOperation typeOperator = new DomainTypeOperation(domainsEntity, + Unbalanced.class.getSimpleName(), domains); + + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, UnbalancedValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains")//$NON-NLS-1$; + .custom(typeOperator) + .named("domainType", "domains")//$NON-NLS-1$ $NON-NLS-2$; + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$; + + } + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } + +} + diff --git a/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/Messages.java b/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/Messages.java new file mode 100644 index 0000000..489fe7d --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/Messages.java @@ -0,0 +1,13 @@ +//This file has been auto-generated +package flintstones.method.linguistic.unbalanced.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String Method_name; + public String Method_description; + +} diff --git a/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/messages.properties b/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/messages.properties new file mode 100644 index 0000000..8151fe0 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/messages.properties @@ -0,0 +1,3 @@ +Method_name=Methodology to deal with unbalanced linguistic term sets +Method_category=Unbalanced linguistic framework +Method_description=F. Herrera, E. Herrera-Viedma, L. Martnez, A Fuzzy Linguistic Methodology To Deal With Unbalanced Linguistic Term Sets. IEEE Transactions on Fuzzy Systems, vol. 16, issue 2, pp. 354-370, 2008. \ No newline at end of file diff --git a/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/messages_es.properties b/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/messages_es.properties new file mode 100644 index 0000000..f005200 --- /dev/null +++ b/bundles/flintstones.method.linguistic.unbalanced/src/flintstones/method/linguistic/unbalanced/messages/messages_es.properties @@ -0,0 +1,2 @@ +Method_name=Metodologa para tratar con conjuntos de trminos lingsticos no balanceados +Method_description=F. Herrera, E. Herrera-Viedma, L. Martnez, A Fuzzy Linguistic Methodology To Deal With Unbalanced Linguistic Term Sets. IEEE Transactions on Fuzzy Systems, vol. 16, issue 2, pp. 354-370, 2008. \ No newline at end of file diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/.classpath b/bundles/flintstones.method.mmoora.phase.results.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/.polyglot.META-INF b/bundles/flintstones.method.mmoora.phase.results.ui/.polyglot.META-INF new file mode 100644 index 0000000..842ce9a --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.mmoora.phase.results.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/.project b/bundles/flintstones.method.mmoora.phase.results.ui/.project new file mode 100644 index 0000000..6d9467b --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.mmoora.phase.results.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362687 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.mmoora.phase.results.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..23a8a58 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.mmoora.phase.results.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.mmoora.phase.results.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase.ui, + javax.inject, + flintstones.method.mmoora.phase.results, + flintstones.helper.html, + flintstones.entity.method.phase, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.engine.R, + flintstones.entity.problemelement diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/build.properties b/bundles/flintstones.method.mmoora.phase.results.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/plugin.xml b/bundles/flintstones.method.mmoora.phase.results.ui/plugin.xml new file mode 100644 index 0000000..4703747 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/MMOORAResultsUI.java b/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/MMOORAResultsUI.java new file mode 100644 index 0000000..70ad771 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/MMOORAResultsUI.java @@ -0,0 +1,99 @@ +package flintstones.method.mmoora.phase.results.ui; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.RVector; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.mmoora.phase.results.MMOORAResults; +import flintstones.method.mmoora.phase.results.ui.messages.Messages; +import flintstones.model.ui.service.UiService; + +public class MMOORAResultsUI extends PhaseMethodUI { + + @Inject + @Translation + Messages msg; + + /** + * Phase model implementation + */ + MMOORAResults model; + + /** + * Results table + */ + HtmlTextTable results; + + @Override + public void init() { + model = (MMOORAResults) this.getModel(); + model.loadData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + createResultTable(base); + } + + /** + * Creates method results table + * + * @param base Composite + */ + private void createResultTable(Composite base) { + REXP rexp = model.executeR(); + + int[] alts = (int[]) ((REXP) ((RVector) rexp.getContent()).get(0)).getContent(); + String[] rHeaders = new String[alts.length]; + for (int a = 0; a < alts.length; a++) { + rHeaders[a] = model.allAlternatives()[alts[a] - 1].getName(); + } + // Makes table data based on R-gui result table + String[] cHeaders = msg.headers.split(","); + String[][] values = new String[alts.length][cHeaders.length]; + double[] r_syst = (double[]) ((REXP) ((RVector) rexp.getContent()).get(1)).getContent(); + int[] ranks = (int[]) ((REXP) ((RVector) rexp.getContent()).get(2)).getContent(); + double[] ref_pt = (double[]) ((REXP) ((RVector) rexp.getContent()).get(3)).getContent(); + int[] ranks1 = (int[]) ((REXP) ((RVector) rexp.getContent()).get(4)).getContent(); + double[] mult_form = (double[]) ((REXP) ((RVector) rexp.getContent()).get(5)).getContent(); + int[] ranks2 = (int[]) ((REXP) ((RVector) rexp.getContent()).get(6)).getContent(); + double[] ranksMM = (double[]) ((REXP) ((RVector) rexp.getContent()).get(7)).getContent(); + + for(int i = 0; i < rHeaders.length; i++) { + values[i][0] = Double.toString(r_syst[i]); + values[i][1] = Integer.toString(ranks[i]); + values[i][2] = Double.toString(ref_pt[i]); + values[i][3] = Integer.toString(ranks1[i]); + values[i][4] = Double.toString(mult_form[i]); + values[i][5] = Integer.toString(ranks2[i]); + values[i][6] = Double.toString(ranksMM[i]); + } + + if (results != null) { + results.dispose(); + } + results = new HtmlTextTable(base, values, cHeaders, rHeaders); + results.render(); + } + + /** + * Reloads phase view + */ + @Override + public void refresh() { + sendRefresh(); + } + + /** + * @return false, last phase + */ + @Override + protected boolean isForwardEnabled() { + return false; + } + +} diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/Messages.java b/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/Messages.java new file mode 100644 index 0000000..56e5c52 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.mmoora.phase.results.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String headers; +} diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/messages.properties b/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/messages.properties new file mode 100644 index 0000000..09f162d --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/messages.properties @@ -0,0 +1 @@ +headers=Ratio System, Ranking, Reference Point, Ranking.1, Multiplicative Form, Ranking.2, MultiMOORA Ranking \ No newline at end of file diff --git a/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/messages_es.properties b/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/messages_es.properties new file mode 100644 index 0000000..45fcb07 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results.ui/src/flintstones/method/mmoora/phase/results/ui/messages/messages_es.properties @@ -0,0 +1 @@ +headers=Sistema de proporcin, Clasificacin, Punto de referencia, Clasificacin.1, Forma Multiplicativa, Clasificacin.2, Clasificacin MultiMOORA \ No newline at end of file diff --git a/bundles/flintstones.method.mmoora.phase.results/.classpath b/bundles/flintstones.method.mmoora.phase.results/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.mmoora.phase.results/.polyglot.META-INF b/bundles/flintstones.method.mmoora.phase.results/.polyglot.META-INF new file mode 100644 index 0000000..ce3746b --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.mmoora.phase.results + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.mmoora.phase.results/.project b/bundles/flintstones.method.mmoora.phase.results/.project new file mode 100644 index 0000000..3313f4d --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/.project @@ -0,0 +1,45 @@ + + + flintstones.method.mmoora.phase.results + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362686 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.mmoora.phase.results/META-INF/MANIFEST.MF b/bundles/flintstones.method.mmoora.phase.results/META-INF/MANIFEST.MF new file mode 100644 index 0000000..801e00f --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.mmoora.phase.results;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.mmoora.phase.results +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase, + javax.inject, + flintstones.model.problemelement.service, + flintstones.engine.R, + flintstones.entity.valuation, + flintstones.helper.data +Import-Package: flintstones.valuation.numeric +Export-Package: flintstones.method.mmoora.phase.results diff --git a/bundles/flintstones.method.mmoora.phase.results/build.properties b/bundles/flintstones.method.mmoora.phase.results/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.mmoora.phase.results/plugin.xml b/bundles/flintstones.method.mmoora.phase.results/plugin.xml new file mode 100644 index 0000000..f443a51 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/MMOORAResults.java b/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/MMOORAResults.java new file mode 100644 index 0000000..efa1a41 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/MMOORAResults.java @@ -0,0 +1,141 @@ +package flintstones.method.mmoora.phase.results; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.Rengine; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.method.mmoora.phase.results.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.valuation.numeric.NumericValuation; + +public class MMOORAResults extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + @Translation + Messages msg; + + /** + * Problem criteria + */ + Criterion[] allCriteria; + + /** + * Problem alternatives + */ + Alternative[] allAlternatives; + + /** + * R execution engine + */ + Rengine eng; + + /** + * Criteria weights + */ + HashMap aggCriWeights; + + /** + * Aggregated valuations + */ + HashMatrix aggregatedValues; + + /** + * @return Problem criteria + */ + public Criterion[] allCriteria() { + return allCriteria; + } + + /** + * @return Problem alternatives + */ + public Alternative[] allAlternatives() { + return allAlternatives; + } + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * Loads problem data from previous phases and creates R engine + */ + @SuppressWarnings("unchecked") + public void loadData() { + eng = Rengine.getMainEngine(); + if (eng == null) + eng = new Rengine(new String[] { "--no-save" }, false, null); + + allCriteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + + aggCriWeights = (HashMap) importData("criterionWeights"); + aggregatedValues = (HashMatrix) importData("decisionmatrix"); + + } + + /** + * Executes FuzzyMMOORA function from R engine + * + * @return R expression with results + */ + public REXP executeR() { + // Start library + eng.eval("library(MCDM)"); + + // Valuation matrix: decision <- matrix(c(...), nrow, ncol) + StringBuilder sb = new StringBuilder("decision <- matrix(c("); + NumericValuation temp; + for (int c = 0; c < allCriteria.length; c++) { + for (int a = 0; a < allAlternatives.length; a++) { + temp = (NumericValuation) aggregatedValues.get(allAlternatives[a], allCriteria[c]); + sb.append(Double.toString(temp.getValue()) + ","); + } + } + sb.deleteCharAt(sb.length() - 1); + sb.append("),nrow = " + allAlternatives.length + ",ncol = " + allCriteria.length + ")"); + eng.eval(sb.toString()); + + // Criterion weights: we <- c(...) + sb = new StringBuilder("we <- c("); + for (int c = 0; c < allCriteria.length; c++) { + sb.append(Double.toString(aggCriWeights.get(allCriteria[c])) + ","); + } + sb.deleteCharAt(sb.length() - 1); + sb.append(")"); + eng.eval(sb.toString()); + + // Type of criteria (cost/benefit) + sb = new StringBuilder("cb <- c("); + for (int c = 0; c < allCriteria.length; c++) { + if (allCriteria[c].isCost()) { + sb.append("\"min\","); + } else { + sb.append("\"max\","); + } + } + sb.deleteCharAt(sb.length() - 1); + sb.append(")"); + eng.eval(sb.toString()); + + return eng.eval("MCDM::MMOORA(decision, we, cb)"); + } +} diff --git a/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/Messages.java b/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/Messages.java new file mode 100644 index 0000000..62eceb7 --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.mmoora.phase.results.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; +} diff --git a/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/messages.properties b/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/messages.properties new file mode 100644 index 0000000..4a0ba3d --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/messages.properties @@ -0,0 +1 @@ +phase_name=Results \ No newline at end of file diff --git a/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/messages_es.properties b/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/messages_es.properties new file mode 100644 index 0000000..8aafffa --- /dev/null +++ b/bundles/flintstones.method.mmoora.phase.results/src/flintstones/method/mmoora/phase/results/messages/messages_es.properties @@ -0,0 +1 @@ +phase_name=Resultados \ No newline at end of file diff --git a/bundles/flintstones.method.mmoora/.classpath b/bundles/flintstones.method.mmoora/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.mmoora/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.mmoora/.polyglot.META-INF b/bundles/flintstones.method.mmoora/.polyglot.META-INF new file mode 100644 index 0000000..d69abb2 --- /dev/null +++ b/bundles/flintstones.method.mmoora/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.mmoora + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.mmoora/.project b/bundles/flintstones.method.mmoora/.project new file mode 100644 index 0000000..af29419 --- /dev/null +++ b/bundles/flintstones.method.mmoora/.project @@ -0,0 +1,45 @@ + + + flintstones.method.mmoora + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362685 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.mmoora/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.mmoora/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.mmoora/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.mmoora/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.mmoora/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.mmoora/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.mmoora/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.mmoora/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.mmoora/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.mmoora/META-INF/MANIFEST.MF b/bundles/flintstones.method.mmoora/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7eba021 --- /dev/null +++ b/bundles/flintstones.method.mmoora/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.mmoora;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.mmoora +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.validatedmethod, + flintstones.valuation.numeric, + flintstones.valuation.linguistic diff --git a/bundles/flintstones.method.mmoora/build.properties b/bundles/flintstones.method.mmoora/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.mmoora/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.mmoora/plugin.xml b/bundles/flintstones.method.mmoora/plugin.xml new file mode 100644 index 0000000..1f7e6de --- /dev/null +++ b/bundles/flintstones.method.mmoora/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/MMOORAMethod.java b/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/MMOORAMethod.java new file mode 100644 index 0000000..094b359 --- /dev/null +++ b/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/MMOORAMethod.java @@ -0,0 +1,54 @@ +package flintstones.method.mmoora; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.RLibTestOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.mmoora.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.numeric.NumericValuation; + +/** + * MMOORA method validation + * @author jcfer + * + */ +public class MMOORAMethod extends ValidatedMethod{ + + @Inject + @Translation + Messages msg; + + /** + * @return Method name + */ + @Override + public String getName() { + return "Multi-Objetive Optimization by Ration Analysis (MMOORA)"; + } + + /** + * Tests if method is applicable + */ + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String vEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[2]; + validTypes[0] = NumericValuation.class.getSimpleName(); + validTypes[1] = LinguisticValuation.class.getSimpleName(); + ValuationTypeOperation vto = new ValuationTypeOperation(vEntity, validTypes, valuations); + + validator.setReturn(this.getName()).custom(vto).named("valuations").custom(new RLibTestOperation("RLibTest", "MCDM")).named("MCDM"); + } + +} diff --git a/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/Messages.java b/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/Messages.java new file mode 100644 index 0000000..55daced --- /dev/null +++ b/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.mmoora.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + + public String method_name; +} diff --git a/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/messages.properties b/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/messages.properties new file mode 100644 index 0000000..c5201eb --- /dev/null +++ b/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/messages.properties @@ -0,0 +1 @@ +method_name=Multi-Objetive Optimization by Ration Analysis (MMOORA) \ No newline at end of file diff --git a/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/messages_es.properties b/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/messages_es.properties new file mode 100644 index 0000000..f6bcc9b --- /dev/null +++ b/bundles/flintstones.method.mmoora/src/flintstones/method/mmoora/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Optimizacin multiobjectivo por anlisis de raciones (MMOORA) \ No newline at end of file diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/.classpath b/bundles/flintstones.method.mmooraFuzzy.result.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/.polyglot.META-INF b/bundles/flintstones.method.mmooraFuzzy.result.ui/.polyglot.META-INF new file mode 100644 index 0000000..00f55d6 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.mmooraFuzzy.result.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/.project b/bundles/flintstones.method.mmooraFuzzy.result.ui/.project new file mode 100644 index 0000000..832a3e8 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.mmooraFuzzy.result.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362688 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.mmooraFuzzy.result.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d781bf4 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.mmooraFuzzy.result.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.mmooraFuzzy.result.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.method.mmooraFuzzy.result, + flintstones.helper.html, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.engine.R, + flintstones.entity.problemelement, + flintstones.entity.method.phase.ui, + flintstones.entity.method.phase, + org.eclipse.e4.core.services, + javax.inject diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/build.properties b/bundles/flintstones.method.mmooraFuzzy.result.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/plugin.xml b/bundles/flintstones.method.mmooraFuzzy.result.ui/plugin.xml new file mode 100644 index 0000000..5193688 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/MMOORAFuzzyResultsUI.java b/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/MMOORAFuzzyResultsUI.java new file mode 100644 index 0000000..3615472 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/MMOORAFuzzyResultsUI.java @@ -0,0 +1,98 @@ +package flintstones.method.mmooraFuzzy.result.ui; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.widgets.Composite; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.RVector; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.mmooraFuzzy.result.MMOORAFuzzyResults; +import flintstones.method.mmooraFuzzy.result.ui.messages.Messages; +import flintstones.model.ui.service.UiService; +import javax.inject.Inject; + +public class MMOORAFuzzyResultsUI extends PhaseMethodUI { + + @Inject + @Translation + Messages msg; + + /** + * Phase model implementation + */ + MMOORAFuzzyResults model; + + /** + * Results table + */ + HtmlTextTable results; + + @Override + public void init() { + model = (MMOORAFuzzyResults) this.getModel(); + model.loadData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + createResultTable(base); + } + + /** + * Creates method results table + * + * @param base Composite + */ + private void createResultTable(Composite base) { + REXP rexp = model.executeR(); + + int[] alts = (int[]) ((REXP) ((RVector) rexp.getContent()).get(0)).getContent(); + String[] rHeaders = new String[alts.length]; + for (int a = 0; a < alts.length; a++) { + rHeaders[a] = model.allAlternatives()[alts[a] - 1].getName(); + } + // Makes table data based on R-gui result table + String[] cHeaders = msg.headers.split(","); + String[][] values = new String[alts.length][cHeaders.length]; + double[] r_syst = (double[]) ((REXP) ((RVector) rexp.getContent()).get(1)).getContent(); + int[] ranks = (int[]) ((REXP) ((RVector) rexp.getContent()).get(2)).getContent(); + double[] ref_pt = (double[]) ((REXP) ((RVector) rexp.getContent()).get(3)).getContent(); + int[] ranks1 = (int[]) ((REXP) ((RVector) rexp.getContent()).get(4)).getContent(); + double[] mult_form = (double[]) ((REXP) ((RVector) rexp.getContent()).get(5)).getContent(); + int[] ranks2 = (int[]) ((REXP) ((RVector) rexp.getContent()).get(6)).getContent(); + double[] ranksMM = (double[]) ((REXP) ((RVector) rexp.getContent()).get(7)).getContent(); + + for(int i = 0; i < rHeaders.length; i++) { + values[i][0] = Double.toString(r_syst[i]); + values[i][1] = Integer.toString(ranks[i]); + values[i][2] = Double.toString(ref_pt[i]); + values[i][3] = Integer.toString(ranks1[i]); + values[i][4] = Double.toString(mult_form[i]); + values[i][5] = Integer.toString(ranks2[i]); + values[i][6] = Double.toString(ranksMM[i]); + } + + if (results != null) { + results.dispose(); + } + results = new HtmlTextTable(base, values, cHeaders, rHeaders); + results.render(); + } + + /** + * Reloads phase view + */ + @Override + public void refresh() { + sendRefresh(); + } + + /** + * @return false, last phase + */ + @Override + protected boolean isForwardEnabled() { + return false; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/Messages.java b/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/Messages.java new file mode 100644 index 0000000..e3b21b9 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.mmooraFuzzy.result.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String headers; +} diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/messages.properties b/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/messages.properties new file mode 100644 index 0000000..09f162d --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/messages.properties @@ -0,0 +1 @@ +headers=Ratio System, Ranking, Reference Point, Ranking.1, Multiplicative Form, Ranking.2, MultiMOORA Ranking \ No newline at end of file diff --git a/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/messages_es.properties b/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/messages_es.properties new file mode 100644 index 0000000..45fcb07 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result.ui/src/flintstones/method/mmooraFuzzy/result/ui/messages/messages_es.properties @@ -0,0 +1 @@ +headers=Sistema de proporcin, Clasificacin, Punto de referencia, Clasificacin.1, Forma Multiplicativa, Clasificacin.2, Clasificacin MultiMOORA \ No newline at end of file diff --git a/bundles/flintstones.method.mmooraFuzzy.result/.classpath b/bundles/flintstones.method.mmooraFuzzy.result/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy.result/.polyglot.META-INF b/bundles/flintstones.method.mmooraFuzzy.result/.polyglot.META-INF new file mode 100644 index 0000000..a0f9613 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.mmooraFuzzy.result + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.mmooraFuzzy.result/.project b/bundles/flintstones.method.mmooraFuzzy.result/.project new file mode 100644 index 0000000..8f730df --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/.project @@ -0,0 +1,45 @@ + + + flintstones.method.mmooraFuzzy.result + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362688 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.mmooraFuzzy.result/META-INF/MANIFEST.MF b/bundles/flintstones.method.mmooraFuzzy.result/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b7537a8 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.mmooraFuzzy.result;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.mmooraFuzzy.result +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase, + javax.inject, + flintstones.model.problemelement.service, + flintstones.domain.fuzzyset, + flintstones.helper.data, + flintstones.engine.R +Export-Package: flintstones.method.mmooraFuzzy.result diff --git a/bundles/flintstones.method.mmooraFuzzy.result/build.properties b/bundles/flintstones.method.mmooraFuzzy.result/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.mmooraFuzzy.result/plugin.xml b/bundles/flintstones.method.mmooraFuzzy.result/plugin.xml new file mode 100644 index 0000000..fd807db --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/MMOORAFuzzyResults.java b/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/MMOORAFuzzyResults.java new file mode 100644 index 0000000..4cbd43c --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/MMOORAFuzzyResults.java @@ -0,0 +1,153 @@ +package flintstones.method.mmooraFuzzy.result; + +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.Rengine; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.method.mmooraFuzzy.result.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * Results phase for the Fuzzy MMOORA method + * @author jcfer + * + */ +public class MMOORAFuzzyResults extends PhaseMethod{ + + @Inject + IProblemElementService problemService; + + @Inject + @Translation + Messages msg; + + /** + * Problem criteria + */ + Criterion[] allCriteria; + + /** + * Problem alternatives + */ + Alternative[] allAlternatives; + + /** + * R execution engine + */ + Rengine eng; + + /** + * Criteria weights + */ + ArrayList aggCriWeights; + + /** + * Aggregated valuations + */ + HashMatrix aggregatedValues; + + /** + * @return Problem criteria + */ + public Criterion[] allCriteria() { + return allCriteria; + } + + /** + * @return Problem alternatives + */ + public Alternative[] allAlternatives() { + return allAlternatives; + } + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * Loads problem data from previous phases and creates R engine + */ + @SuppressWarnings("unchecked") + public void loadData() { + eng = Rengine.getMainEngine(); + if(eng == null) + eng = new Rengine(new String[] { "--no-save" }, false, null); + + allCriteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + + aggCriWeights = (ArrayList) importData("aggregatedWeights"); + aggregatedValues = (HashMatrix) importData( + "aggregatedValues"); + } + + /** + * Executes FuzzyMMOORA function from R engine + * @return R expression with results + */ + public REXP executeR() { + //Start library + eng.eval("library(FuzzyMCDM)"); + + //Valuation matrix: decision <- matrix(c(...), nrow, ncol) + StringBuilder sb = new StringBuilder("decision <- matrix(c("); + TrapezoidalFunction temp; + for(int c = 0; c < allCriteria.length; c++) { + for(int v = 0; v < 3; v++) { + for(int a = 0; a < allAlternatives.length; a++) { + temp = aggregatedValues.get(allAlternatives[a], allCriteria[c]); + if(v==0) { + sb.append(temp.getA() + ","); + }else if(v==1) { + sb.append(temp.getB() + ","); + }else { + sb.append(temp.getD() + ","); + } + } + } + } + sb.deleteCharAt(sb.length()-1); + sb.append("),nrow = " + allAlternatives.length + ",ncol = " + allCriteria.length*3 + ")"); + eng.eval(sb.toString()); + + //Criterion weights: we <- c(...) + sb = new StringBuilder("we <- c("); + for(int c = 0; c < allCriteria.length; c++) { + temp = aggCriWeights.get(c); + sb.append(temp.getA() + "," + temp.getB() + "," + temp.getD() + ","); + } + sb.deleteCharAt(sb.length()-1); + sb.append(")"); + eng.eval(sb.toString()); + + //Type of criteria (cost/benefit) + sb = new StringBuilder("cb <- c("); + for(int c = 0; c < allCriteria.length; c++) { + if(allCriteria[c].isCost()) { + sb.append("\"min\","); + }else { + sb.append("\"max\","); + } + } + sb.deleteCharAt(sb.length()-1); + sb.append(")"); + eng.eval(sb.toString()); + + return eng.eval("FuzzyMCDM::FuzzyMMOORA(decision, we, cb)"); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/Messages.java b/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/Messages.java new file mode 100644 index 0000000..740cc7f --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.mmooraFuzzy.result.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; +} diff --git a/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/messages.properties b/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/messages.properties new file mode 100644 index 0000000..4a0ba3d --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/messages.properties @@ -0,0 +1 @@ +phase_name=Results \ No newline at end of file diff --git a/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/messages_es.properties b/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/messages_es.properties new file mode 100644 index 0000000..8aafffa --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy.result/src/flintstones/method/mmooraFuzzy/result/messages/messages_es.properties @@ -0,0 +1 @@ +phase_name=Resultados \ No newline at end of file diff --git a/bundles/flintstones.method.mmooraFuzzy/.classpath b/bundles/flintstones.method.mmooraFuzzy/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy/.polyglot.META-INF b/bundles/flintstones.method.mmooraFuzzy/.polyglot.META-INF new file mode 100644 index 0000000..2433510 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.mmooraFuzzy + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.mmooraFuzzy/.project b/bundles/flintstones.method.mmooraFuzzy/.project new file mode 100644 index 0000000..2c5654d --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/.project @@ -0,0 +1,45 @@ + + + flintstones.method.mmooraFuzzy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362687 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.mmooraFuzzy/META-INF/MANIFEST.MF b/bundles/flintstones.method.mmooraFuzzy/META-INF/MANIFEST.MF new file mode 100644 index 0000000..943a4dd --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.mmooraFuzzy;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.mmooraFuzzy +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.linguistic diff --git a/bundles/flintstones.method.mmooraFuzzy/build.properties b/bundles/flintstones.method.mmooraFuzzy/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.mmooraFuzzy/plugin.xml b/bundles/flintstones.method.mmooraFuzzy/plugin.xml new file mode 100644 index 0000000..c3f8cce --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/FuzzyMMOORAMethod.java b/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/FuzzyMMOORAMethod.java new file mode 100644 index 0000000..d2983b7 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/FuzzyMMOORAMethod.java @@ -0,0 +1,47 @@ +package flintstones.method.mmooraFuzzy; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.RLibTestOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.mmooraFuzzy.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; + +public class FuzzyMMOORAMethod extends ValidatedMethod{ + + @Inject + @Translation + Messages msg; + + /** + * @return Method name + */ + @Override + public String getName() { + return "Fuzzy Multi-Objetive Optimization by Ration Analysis (Fuzzy MMOORA)"; + } + + /** + * Tests if method is applicable + */ + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String vEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[1]; + validTypes[0] = LinguisticValuation.class.getSimpleName(); + ValuationTypeOperation vto = new ValuationTypeOperation(vEntity, validTypes, valuations); + + validator.setReturn(this.getName()).custom(vto).named("valuations").custom(new RLibTestOperation("RLibTest", "FuzzyMCDM")).named("FuzzyMCDM"); + } + +} diff --git a/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/Messages.java b/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/Messages.java new file mode 100644 index 0000000..855b29a --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.mmooraFuzzy.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + + public String method_name; +} diff --git a/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/messages.properties b/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/messages.properties new file mode 100644 index 0000000..0318a44 --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/messages.properties @@ -0,0 +1 @@ +method_name=Fuzzy Multi-Objetive Optimization by Ration Analysis (Fuzzy MMOORA) \ No newline at end of file diff --git a/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/messages_es.properties b/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/messages_es.properties new file mode 100644 index 0000000..187302a --- /dev/null +++ b/bundles/flintstones.method.mmooraFuzzy/src/flintstones/method/mmooraFuzzy/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Optimizacin difusa multiobjectivo por anlisis de raciones (Fuzzy MMOORA) \ No newline at end of file diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/.classpath b/bundles/flintstones.method.numeric.common.aggregation.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/.polyglot.META-INF b/bundles/flintstones.method.numeric.common.aggregation.ui/.polyglot.META-INF new file mode 100644 index 0000000..3dc7d65 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.numeric.common.aggregation.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/.project b/bundles/flintstones.method.numeric.common.aggregation.ui/.project new file mode 100644 index 0000000..a8b380d --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.numeric.common.aggregation.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362690 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.numeric.common.aggregation.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1d1581f --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.numeric.common.aggregation.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.numeric.common.aggregation.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase.ui, + javax.inject, + org.eclipse.e4.core.contexts, + flintstones.operator, + flintstones.model.valuation.service, + flintstones.method.numeric.common.aggregation, + org.eclipse.swt, + flintstones.helper.html, + flintstones.entity.method.phase, + flintstones.model.ui.service, + flintstones.entity.operator, + flintstones.valuation.numeric.real, + flintstones.entity.problemelement diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/build.properties b/bundles/flintstones.method.numeric.common.aggregation.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/plugin.xml b/bundles/flintstones.method.numeric.common.aggregation.ui/plugin.xml new file mode 100644 index 0000000..7fb3e88 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/NumericAggregationUI.java b/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/NumericAggregationUI.java new file mode 100644 index 0000000..dc0b7c8 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/NumericAggregationUI.java @@ -0,0 +1,459 @@ +package flintstones.method.numeric.common.aggregation.ui; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.numeric.common.aggregation.NumericAggregation; +import flintstones.method.numeric.common.aggregation.ui.messages.Messages; +import flintstones.model.ui.service.UiService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.numeric.real.RealValuation; + +public class NumericAggregationUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + @Inject + IOperatorService operatorService; + + @Inject + IValuationService valuationService; + + /** + * Phase model + */ + NumericAggregation model; + + /** + * Expert selector + */ + Combo expertCombo; + + /** + * Aggregation operator selector for valuations + */ + Combo comboValuations; + + /** + * Aggregation operator selector for criteria weights + */ + Combo comboWeights; + + /** + * Selected aggregation operator for valuations + */ + AggregationOperator operatorValuations; + + /** + * Selected aggregation operator for criteria weights + */ + AggregationOperator operatorWeights; + + /** + * Expert collected data table + */ + HtmlTextTable initialTable; + + /** + * Expert collected criteria weights table + */ + HtmlTextTable initialWeightsTable; + + /** + * Aggregated valuations table + */ + HtmlTextTable aggregatedTable; + + /** + * Aggregated criteria weights table + */ + HtmlTextTable aggregatedWeightsTable; + + + @Inject + @Translation + private Messages messages; + + + /** + * Inits interface + */ + @Override + public void init() { + model = (NumericAggregation) this.getModel(); + model.loadData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 3); + + Composite leftTable = new Composite(base, SWT.BORDER); + UiService.setGridData(leftTable, 9, 9, true, true); + UiService.setGridLayout(leftTable, 1); + + Composite comboComposite = new Composite(leftTable, SWT.NONE); + UiService.setGridData(comboComposite, 0, 1, true, false); + UiService.setGridLayout(comboComposite, 2); + +// <--------Make expert selector--------> + Label labelExpertTable = new Label(comboComposite, SWT.NONE); + UiService.setGridData(labelExpertTable, 9, 0, false, false); + labelExpertTable.setText(messages.expert_selection); + + createExpertCombo(comboComposite); + createExpertValuationTable(leftTable); + createExpertWeightsTable(leftTable); + +// <--------Make operator selectors--------> + Composite selectOperators = new Composite(base, SWT.BORDER); + UiService.setGridData(selectOperators, 0, 0, false, true); + UiService.setGridLayout(selectOperators, 1); + + Label selectOperatorValuationLabel = new Label(selectOperators, SWT.NONE); + selectOperatorValuationLabel.setText(messages.operator_selection); + + Composite comboBase = new Composite(selectOperators, SWT.NONE); + UiService.setGridData(comboBase, 0, 0, true, true); + UiService.setGridLayout(comboBase, 1); + + Label selectOperatorWeightLabel = new Label(selectOperators, SWT.NONE); + selectOperatorWeightLabel.setText(messages.weights_operator_selection); + + Composite comboBase2 = new Composite(selectOperators, SWT.NONE); + UiService.setGridData(comboBase2, 0, 0, true, true); + UiService.setGridLayout(comboBase2, 1); + +// <--------Make final composite--------> + Composite tablaDer = new Composite(base, SWT.BORDER); + UiService.setGridData(tablaDer, 9, 9, true, true); + UiService.setGridLayout(tablaDer, 1); + + Label aggrLabel = new Label(tablaDer, SWT.NONE); + aggrLabel.setText(messages.aggr_matrix); + UiService.setGridData(aggrLabel, 0, 0, false, false); + +// <--------Make operator selectors--------> + comboValuations = new Combo(comboBase, SWT.NONE); + comboWeights = new Combo(comboBase2, SWT.NONE); + + if (model.getExpertsNames().length == 1) {//One expert + comboValuations.setEnabled(false); + comboWeights.setEnabled(false); + + createExpertValuationTable(tablaDer); + + Label aggrWeightsLabel = new Label(tablaDer, SWT.NONE); + aggrWeightsLabel.setText(messages.aggr_weights); + UiService.setGridData(aggrWeightsLabel, 0, 0, false, false); + + createExpertWeightsTable(tablaDer); + + } else { // Several experts + +// <--------Get aggregation operators--------> + AggregationOperator[] operators = operatorService.getAggregationOperatorsFor(RealValuation.ID, true); + String[] operatorsName = new String[operators.length]; + + for (int i = 0; i < operators.length; ++i) + operatorsName[i] = operators[i].getName(); + + comboValuations.setItems(operatorsName); + comboValuations.select(0); + operatorValuations = operators[0]; + + comboValuations.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + for (int i = 0; i < operators.length; i++) { + if (comboValuations.getText().equals(operators[i].getName())) { + operatorValuations = operators[i]; + i = operators.length; + } + } + + refreshCollectionValuationTable(); + + model.exportData(); + } + }); + + comboWeights.setItems(operatorsName); + comboWeights.select(0); + operatorWeights = operators[0]; + + comboWeights.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + for (int i = 0; i < operators.length; i++) { + if (comboWeights.getText().equals(operators[i].getName())) { + operatorWeights = operators[i]; + i = operators.length; + } + } + + refreshCollectiveWeightTable(); + + model.exportData(); + } + }); + + createAggregatedValuationsTable(tablaDer); + + Label aggrWeightsLabel = new Label(tablaDer, SWT.NONE); + aggrWeightsLabel.setText(messages.aggr_weights); + UiService.setGridData(aggrWeightsLabel, 0, 0, false, false); + + createAggregatedWeightsTable(tablaDer); + } + + model.exportData(); + } + + /** + * Makes expert selector + * @param comboComposite + */ + private void createExpertCombo(Composite comboComposite) { + expertCombo = new Combo(comboComposite, SWT.NONE); + UiService.setGridData(expertCombo, 0, 0, false, false); + + for (int i = 0; i < model.getExpertsNames().length; i++) + expertCombo.add(model.getExpertsNames()[i]); + + expertCombo.select(0); + expertCombo.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + refreshIndividualData(); + } + }); + } + + /** + * Makes inital data table with first expert + * + * @param base Table composite + */ + void createExpertValuationTable(Composite base) { + + String[] alternatives = new String[model.getAlternatives().length]; + String[] criteria = new String[model.getCriteria().length]; + + for (int i = 0; i < alternatives.length; i++) + alternatives[i] = model.getAlternatives()[i].toString(); + + for (int i = 0; i < criteria.length; i++) + criteria[i] = model.getCriteria()[i].toString(); + + String[][] valuations = getExpertValuations(alternatives.length, criteria.length, expertCombo.getSelectionIndex()); + + Composite compositeTable = new Composite(base, SWT.NONE); + UiService.setGridData(compositeTable, 9, 9, true, true); + UiService.setGridLayout(compositeTable, 1); + + initialTable = new HtmlTextTable(compositeTable, valuations, criteria, alternatives); + initialTable.render(); + } + + /** + * @param rows Number of alternatives + * @param cols Numer of criteria + * @param expertIndex Index of the expert + * @return Expert collected valuations as String array matrix + */ + private String[][] getExpertValuations(int rows, int cols, int expertIndex) { + String[][] valuations = new String[rows][cols]; + + for (int i = 0; i < valuations.length; i++) { + for (int j = 0; j < valuations[i].length; j++) + valuations[i][j] = Double.toString(model.getInitialData(expertIndex, i, j)); + } + + return valuations; + } + + /** + * Make collected weights table + * + * @param base Table composite + */ + private void createExpertWeightsTable(Composite base) { + String[] criteria = new String[model.getCriteria().length]; + String[] weights = new String[model.getCriteria().length]; + + int index = expertCombo.getSelectionIndex(); + HashMap expertWeights = model.getValuationWeights(index); + + Criterion crit; + for (int i = 0; i < criteria.length; i++) { + crit = model.getCriteria()[i]; + criteria[i] = crit.toString(); + weights[i] = Double.toString(expertWeights.get(crit)); + } + + Composite compositeTable = new Composite(base, SWT.NONE); + UiService.setGridData(compositeTable, 9, 9, true, true); + UiService.setGridLayout(compositeTable, 1); + + initialWeightsTable = new HtmlTextTable(compositeTable, weights, criteria, false); + initialWeightsTable.render(); + } + + /** + * Makes aggregated valuations table + * + * @param base Table composite + */ + void createAggregatedValuationsTable(Composite base) { + model.computeAggregatedMatrix(operatorValuations); + + String[] alternatives = new String[model.getAlternatives().length]; + String[] criteria = new String[model.getCriteria().length]; + String[][] valuations = new String[alternatives.length][criteria.length]; + + for (int i = 0; i < alternatives.length; i++) + alternatives[i] = model.getAlternatives()[i].toString(); + + for (int i = 0; i < criteria.length; i++) + criteria[i] = model.getCriteria()[i].toString(); + + for (int i = 0; i < valuations.length; i++) { + for (int j = 0; j < valuations[i].length; j++) + valuations[i][j] = Double.toString(model.getAggregatedData(i, j)); + } + + Composite tabla = new Composite(base, SWT.NONE); + UiService.setGridData(tabla, 9, 9, true, true); + UiService.setGridLayout(tabla, 1); + + aggregatedTable = new HtmlTextTable(tabla, valuations, criteria, alternatives); + aggregatedTable.render(); + } + + /** + * Makes aggregated weights table + * + * @param base Table composite + */ + void createAggregatedWeightsTable(Composite base) { + model.computeAggregatedWeights(operatorWeights); + + String[] criteria = model.getCriteriaNames(); + String[] weights = new String[model.getCriteria().length]; + + for (int i = 0; i < criteria.length; i++) { + weights[i] = Double.toString(model.getAggCritWeight(i)); + } + + Composite tabla = new Composite(base, SWT.NONE); + UiService.setGridData(tabla, 9, 9, true, true); + UiService.setGridLayout(tabla, 1); + + aggregatedWeightsTable = new HtmlTextTable(tabla, weights, criteria, false); + aggregatedWeightsTable.render(); + } + + /** + * Reload initial data and weights tables + */ + private void refreshIndividualData() { + refreshExpertValuationTable(); + refreshExpertWeightTable(); + } + + /** + * Reloads phase tables + */ + @Override + public void refresh() { + refreshIndividualData(); + refreshCollectiveData(); + this.sendRefresh(); + } + + /** + * Reload aggregated valuations and weights tables + */ + private void refreshCollectiveData() { + refreshCollectionValuationTable(); + refreshCollectiveWeightTable(); + } + + /** + * Updates initial table data + */ + private void refreshExpertValuationTable() { + String[][] valuations = getExpertValuations(model.getAlternatives().length, model.getCriteria().length, expertCombo.getSelectionIndex()); + initialTable.refresh(valuations); + initialTable.render(); + } + + /** + * Updates criterion weights table + */ + private void refreshExpertWeightTable() { + HashMap expertWeights = model.getValuationWeights(expertCombo.getSelectionIndex()); + + Criterion crit; + String[] weights = new String[model.getCriteria().length]; + for (int i = 0; i < model.getCriteria().length; i++) { + crit = model.getCriteria()[i]; + weights[i] = Double.toString(expertWeights.get(crit)); + } + + initialWeightsTable.refresh(weights); + initialWeightsTable.render(); + } + + /** + * Updates aggregated valuations table + */ + private void refreshCollectionValuationTable() { + model.computeAggregatedMatrix(operatorValuations); + + String[][] valuations = new String[model.getAlternatives().length][model.getCriteria().length]; + for (int i = 0; i < valuations.length; i++) { + for (int j = 0; j < valuations[i].length; j++) + valuations[i][j] = Double.toString(model.getAggregatedData(i, j)); + } + + aggregatedTable.refresh(valuations); + aggregatedTable.render(); + } + + /** + * Updates aggregated weights table + */ + private void refreshCollectiveWeightTable() { + model.computeAggregatedWeights(operatorWeights); + + String[] weights = new String[model.getCriteria().length]; + + for (int i = 0; i < model.getCriteria().length; i++) + weights[i] = Double.toString(model.getAggCritWeight(i)); + + aggregatedWeightsTable.refresh(weights); + aggregatedWeightsTable.render(); + } + + @Override + public boolean isForwardEnabled() { + return true; + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/Messages.java b/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/Messages.java new file mode 100644 index 0000000..2e24ee0 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/Messages.java @@ -0,0 +1,14 @@ +package flintstones.method.numeric.common.aggregation.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; + public String expert_selection; + public String aggr_matrix; + public String aggr_weights; + public String operator_selection; + public String weights_operator_selection; + +} diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/messages.properties b/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/messages.properties new file mode 100644 index 0000000..b3226f4 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/messages.properties @@ -0,0 +1,6 @@ +phase_name=Aggregation +expert_selection=Select expert to visualize: +aggr_matrix=Aggregated matrix +aggr_weights=Aggregated weights +operator_selection=Select operator for aggregation: +weights_operator_selection=Select operator for weights aggregation: diff --git a/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/messages_es.properties b/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/messages_es.properties new file mode 100644 index 0000000..5ee2cf2 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation.ui/src/flintstones/method/numeric/common/aggregation/ui/messages/messages_es.properties @@ -0,0 +1,6 @@ +phase_name=Agregacin +expert_selection=Elegir experto a visualizar: +aggr_matrix=Matriz agregada +aggr_weights=Pesos agregados +operator_selection=Elegir operador de agregacin: +weights_operator_selection=Elegir operador de agregacin para los pesos: diff --git a/bundles/flintstones.method.numeric.common.aggregation/.classpath b/bundles/flintstones.method.numeric.common.aggregation/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.numeric.common.aggregation/.polyglot.META-INF b/bundles/flintstones.method.numeric.common.aggregation/.polyglot.META-INF new file mode 100644 index 0000000..332590e --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.numeric.common.aggregation + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.numeric.common.aggregation/.project b/bundles/flintstones.method.numeric.common.aggregation/.project new file mode 100644 index 0000000..14fc7fb --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/.project @@ -0,0 +1,45 @@ + + + flintstones.method.numeric.common.aggregation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362689 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.numeric.common.aggregation/META-INF/MANIFEST.MF b/bundles/flintstones.method.numeric.common.aggregation/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a7fef03 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.numeric.common.aggregation;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.numeric.common.aggregation +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase, + javax.inject, + flintstones.model.problemelement.service, + flintstones.operator, + flintstones.model.valuation.service, + flintstones.valuation.numeric, + flintstones.helper.data, + flintstones.valuation.numeric.real, + flintstones.domain.fuzzyset, + flintstones.valuation.linguistic, + flintstones.entity.operator +Export-Package: flintstones.method.numeric.common.aggregation diff --git a/bundles/flintstones.method.numeric.common.aggregation/build.properties b/bundles/flintstones.method.numeric.common.aggregation/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.numeric.common.aggregation/plugin.xml b/bundles/flintstones.method.numeric.common.aggregation/plugin.xml new file mode 100644 index 0000000..6131af6 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/NumericAggregation.java b/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/NumericAggregation.java new file mode 100644 index 0000000..58efb3f --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/NumericAggregation.java @@ -0,0 +1,334 @@ +package flintstones.method.numeric.common.aggregation; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.numeric.NumericDomain; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.method.phase.ImportedDataNotFoundException; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.method.numeric.common.aggregation.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.numeric.NumericValuation; +import flintstones.valuation.numeric.real.RealValuation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; + +import javax.inject.Inject; + +public class NumericAggregation extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + IOperatorService operatorService; + + @Inject + IValuationService valuationService; + + @Inject + @Translation + Messages msg; + + /** + * Problem alternatives + */ + Alternative[] allAlternatives; + + /** + * Problem criteria + */ + Criterion[] allCriteria; + + /** + * Problem experts + */ + Expert[] allExperts; + + /** + * Collected valuations for [expert][alternative][criterion] + */ + NumericValuation[][][] initialValuations; + + /** + * Expert given criteria weights + */ + HashMatrix initialCritWeights; + + /** + * Experts weights + */ + HashMap expertsWeights; + + /** + * Aggregated valuations + */ + HashMatrix aggregatedValuations; + + /** + * Aggregated criteria weights + */ + HashMap aggregatedCriteriaWeights; + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * Get data from previous phases and initial valuations + */ + @SuppressWarnings("unchecked") + public void loadData() { + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + allCriteria = ProblemElementHelper.asCriterions(problemService.getSubElements(Criterion.Type)); + allExperts = ProblemElementHelper.asExperts(problemService.getSubElements(Expert.Type)); + + try { + initialCritWeights = (HashMatrix) this.getPreviousPhase().importData("criterionWeights"); + expertsWeights = (HashMap) importData("expertWeights"); + } catch (ImportedDataNotFoundException e) { + initialCritWeights = (HashMatrix) importData("criterionWeights"); + expertsWeights = (HashMap) this.getPreviousPhase().importData("expertWeights"); + } + + if(allExperts.length == 1) + aggregatedCriteriaWeights = new LinkedHashMap<>(initialCritWeights.get(allExperts[0])); + else + aggregatedCriteriaWeights = new LinkedHashMap(); + + initialValuations = new NumericValuation[allExperts.length][allAlternatives.length][allCriteria.length]; + aggregatedValuations = new HashMatrix(); + + loadValuations(); + } + + /** + * Gets initial valuations casted to NumericValuation + */ + private void loadValuations() { + ProblemElementKey key; + Valuation auxValuation; + ArrayList labels; + NumericRealDomain auxDomain; + for (int e = 0; e < allExperts.length; e++) { + for (int a = 0; a < allAlternatives.length; a++) { + for (int c = 0; c < allCriteria.length; c++) { + // Find every valuation + key = new ProblemElementKey(allExperts[e], allAlternatives[a], allCriteria[c]); + auxValuation = valuationService.getValuationFor(key); + + // if not real number valuation + if (!auxValuation.getDomain().getType().equals("flintstones.domain.numeric.real")) { + double value; + double dMax, dMin; + // if linguistic + if (auxValuation.getDomain().getType().equals("flintstones.domain.linguistic")) { + labels = ((FuzzySet) auxValuation.getDomain()).getLabelSet().getLabelsName(); + // use label index as value + value = labels.indexOf(((LinguisticValuation) auxValuation).getLabel().getName()); + dMin = 0; + dMax = labels.size(); + } else { // other numeric type + value = ((NumericValuation) auxValuation).getValue(); + NumericDomain temp = (NumericDomain) auxValuation.getDomain(); + dMin = temp.getMin(); + dMax = temp.getMax(); + } + + auxDomain = new NumericRealDomain(); + auxDomain.setMinMax(dMin, dMax); + auxDomain.setInRange(true); + + auxValuation = new RealValuation(); + auxValuation.setDomain(auxDomain); + auxValuation.setValueFromString(Double.toString(value)); + } + + if (e == 0) { + aggregatedValuations.put(allAlternatives[a], allCriteria[c], auxValuation); + } + + initialValuations[e][a][c] = (NumericValuation) auxValuation; + } + } + } + } + + /** + * Calculate aggregated valuations + * + * @param operatorId ID for aggregation operator + */ + public void computeAggregatedMatrix(AggregationOperator operator) { + LinkedList valuations = new LinkedList<>(); + + for (int a = 0; a < allAlternatives.length; a++) { + for (int c = 0; c < allCriteria.length; c++) { + for (int e = 0; e < allExperts.length; e++) + valuations.add(initialValuations[e][a][c]); + + Valuation aggregated = (NumericValuation) operator.computeAggregation(valuations, new ArrayList(expertsWeights.values())); + aggregatedValuations.put(allAlternatives[a], allCriteria[c], aggregated); + valuations.clear(); + } + } + } + + /** + * Calculate aggregated weights + * + * @param operatorId ID for aggregation operator + */ + public void computeAggregatedWeights(AggregationOperator operator) { + + ArrayList wTemp = new ArrayList<>(); + NumericValuation temp; + NumericRealDomain dTemp = new NumericRealDomain(); + dTemp.setInRange(true); + dTemp.setMinMax(0.0, 1.0); + + for (int c = 0; c < allCriteria.length; c++) { + for (int e = 0; e < allExperts.length; e++) { + temp = new RealValuation(); + temp.setDomain(dTemp); + temp.setValue(initialCritWeights.get(allExperts[e], allCriteria[c])); + wTemp.add(temp); + } + + temp = (NumericValuation) operator.computeAggregation(wTemp, new ArrayList(expertsWeights.values())); + aggregatedCriteriaWeights.put(allCriteria[c], Math.round(temp.getValue() * 1000d) / 1000d); + + wTemp.clear(); + } + } + + /** + * Exports aggregated data for next phases + */ + public void exportData() { + this.exportData("criterionWeights", aggregatedCriteriaWeights, true); + this.exportData("decisionmatrix", aggregatedValuations, true); + } + + /** + * @return Problem alternatives + */ + public Alternative[] getAlternatives() { + return allAlternatives; + } + + /** + * @return Problem criteria + */ + public Criterion[] getCriteria() { + return allCriteria; + } + + /** + * @return All alternatives names as array + */ + public String[] getAlternativesNames() { + String[] str = new String[allAlternatives.length]; + + for (int i = 0; i < allAlternatives.length; i++) + str[i] = problemService.getByName(Alternative.Type, allAlternatives[i].getName()).getName(); + + return str; + } + + /** + * @return All criteria names as array + */ + public String[] getCriteriaNames() { + String[] str = new String[allCriteria.length]; + + for (int i = 0; i < allCriteria.length; i++) + str[i] = problemService.getByName(Criterion.Type, allCriteria[i].getName()).getName(); + + return str; + } + + /** + * @return All expert names as array + */ + public String[] getExpertsNames() { + String[] str = new String[allExperts.length]; + + for (int i = 0; i < allExperts.length; i++) + str[i] = problemService.getByName(Expert.Type, allExperts[i].getName()).getName(); + + return str; + } + + /** + * @return Number of criteria + */ + public int numberCriteria() { + return allCriteria.length; + } + + /** + * @return Number of experts + */ + public int numberExperts() { + return allExperts.length; + } + + /** + * @param expert Expert index + * @param alternative Alternative index + * @param criterion Criterion index + * @return Collected valuation value + */ + public double getInitialData(int expert, int alternative, int criterion) { + return initialValuations[expert][alternative][criterion].getValue(); + } + + /** + * @param alternative Alternative index + * @param criterion Criterion index + * @return Aggregated valuation value + */ + public double getAggregatedData(int alternative, int criterion) { + return Math.round( + ((NumericValuation) aggregatedValuations.get(allAlternatives[alternative], allCriteria[criterion])) + .getValue() * 1000d) + / 1000d; + } + + /** + * @param expertIndex Expert index + * @return Criteria weights for the expert + */ + public HashMap getValuationWeights(int expertIndex) { + return initialCritWeights.get(allExperts[expertIndex]); + } + + /** + * @param c Criterion index + * @return Aggregated criterion weight + */ + public double getAggCritWeight(int c) { + return aggregatedCriteriaWeights.get(allCriteria[c]); + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/Messages.java b/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/Messages.java new file mode 100644 index 0000000..5c9ccfb --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.numeric.common.aggregation.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; +} diff --git a/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/messages.properties b/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/messages.properties new file mode 100644 index 0000000..104620f --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/messages.properties @@ -0,0 +1 @@ +phase_name=Aggregation \ No newline at end of file diff --git a/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/messages_es.properties b/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/messages_es.properties new file mode 100644 index 0000000..4a05b32 --- /dev/null +++ b/bundles/flintstones.method.numeric.common.aggregation/src/flintstones/method/numeric/common/aggregation/messages/messages_es.properties @@ -0,0 +1 @@ +phase_name=Agregacin \ No newline at end of file diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/.classpath b/bundles/flintstones.method.promethee.phase.gathering.ui/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/.polyglot.META-INF b/bundles/flintstones.method.promethee.phase.gathering.ui/.polyglot.META-INF new file mode 100644 index 0000000..215fab7 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.promethee.phase.gathering.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/.project b/bundles/flintstones.method.promethee.phase.gathering.ui/.project new file mode 100644 index 0000000..1fb23cd --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.promethee.phase.gathering.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362693 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.promethee.phase.gathering.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a500671 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.promethee.phase.gathering.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.promethee.phase.gathering.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.contexts, + flintstones.model.problemelement.service, + flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + org.eclipse.jface, + flintstones.model.method.phase.service, + flintstones.helper.data, + javax.inject, + flintstones.entity.problemelement, + flintstones.application.perspective.framework.ui, + flintstones.method.promethee.phase.gathering, + flintstones.entity.method.phase +Export-Package: flintstones.method.promethee.phase.gathering.ui diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/build.properties b/bundles/flintstones.method.promethee.phase.gathering.ui/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/plugin.xml b/bundles/flintstones.method.promethee.phase.gathering.ui/plugin.xml new file mode 100644 index 0000000..21b7eea --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/provider/ProblemElementLabelProvider.java b/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/provider/ProblemElementLabelProvider.java new file mode 100644 index 0000000..f62f2e1 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/provider/ProblemElementLabelProvider.java @@ -0,0 +1,76 @@ +package flintstones.method.promethee.phase.gathering.provider; + +import javax.inject.Inject; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.ui.service.UiService; +import flintstones.model.ui.service.style.ForegroundStyler; + +public class ProblemElementLabelProvider extends LabelProvider implements IStyledLabelProvider { + + @Inject + IPhaseMethodService phaseService; + + /** The group image. */ + private final ImageDescriptor groupImage; + + /** The individual image. */ + private final ImageDescriptor individualImage; + + /** + * Instantiates a new problem element name label provider. + * + * @param individualImage the individual image + * @param groupImage the group image + */ + public ProblemElementLabelProvider(ImageDescriptor individualImage, ImageDescriptor groupImage) { + this.groupImage = groupImage; + this.individualImage = individualImage; + } + + @Override + public StyledString getStyledText(Object element) { + if (element instanceof ProblemElement) { + ProblemElement pe = (ProblemElement) element; + StyledString styledString; + styledString = paint(pe.getName(), ""); + + return styledString; + } + return null; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + if (element instanceof ProblemElement) { + if (((ProblemElement) element).hasChildren()) + return this.groupImage.createImage(); + + return this.individualImage.createImage(); + } + + return super.getImage(element); + } + + private StyledString paint(String leftText, String rightText) { + + Color foregroundColorLeft = UiService.COLOR_FG_NORMAL; + Color foregroundColorRight = UiService.COLOR_FG_SECONDARY; + + StyledString leftT = new StyledString(leftText, new ForegroundStyler(foregroundColorLeft)); + StyledString rightT = new StyledString(rightText, new ForegroundStyler(foregroundColorRight)); + return leftT.append(" ") + .append(rightT); + } +} diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/ui/PrometheeData.java b/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/ui/PrometheeData.java new file mode 100644 index 0000000..072ed4e --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/ui/PrometheeData.java @@ -0,0 +1,61 @@ +package flintstones.method.promethee.phase.gathering.ui; + +public class PrometheeData { + + int typeFunc; + int MinMax; + double p; + double q; + double s; + + public PrometheeData() { + this.p = 0.0; + this.q = 0.0; + this.s = 0.0; + this.typeFunc = 1; + } + + public int getTypeFunc() { + return typeFunc; + } + + public void setTypeFunc(int typeFunc) { + this.typeFunc = typeFunc; + this.p = 0.0; + this.q = 0.0; + this.s = 0.0; + } + + public int getMinMax() { + return MinMax; + } + + public void setMinMax(int minmax) { + this.MinMax = minmax; + } + + public double getP() { + return p; + } + + public void setP(double p) { + this.p = p; + } + + public double getQ() { + return q; + } + + public void setQ(double q) { + this.q = q; + } + + public double getS() { + return s; + } + + public void setS(double s) { + this.s = s; + } + +} diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/ui/PrometheeGatheringUI.java b/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/ui/PrometheeGatheringUI.java new file mode 100644 index 0000000..d98733b --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/ui/PrometheeGatheringUI.java @@ -0,0 +1,511 @@ +package flintstones.method.promethee.phase.gathering.ui; + +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +//import org.rosuda.JRI.Rengine; + +import flintstones.application.perspective.framework.ui.interfaces.IProblemElementViewerOnSingleClick; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewer; +//import flintstones.engine.R.R; +//import flintstones.engine.R.provider.internal.REngineDefaultProvider; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; +import flintstones.method.promethee.phase.gathering.PrometheeGathering; +import flintstones.method.promethee.phase.gathering.viewer.ProblemElementViewerLabel; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class PrometheeGatheringUI extends PhaseMethodUI + implements IProblemElementViewerOnSingleClick, ICheckStateListener { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + ProblemElementViewer criterionViewer; + Label titleLabelParametersCriterion; + Spinner spinnerQ; + Spinner spinnerP; + Spinner spinnerS; + + Composite rowLabelPp; + Composite rowLabelQq; + Composite rowLabelS; + + Combo comboBox; + + Composite rowTypeData; + int selectedIndex; + boolean nextPhase; + + ArrayList prometheeData; + PrometheeGathering model; + + @Override + public void init() { + model = (PrometheeGathering) this.getModel(); + model.loadData(); + + initData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 0, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText("PROMETHEE GATHERING"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9, 9, true, true); + UiService.setGridLayout(row2, 1); + + createRowImages(row2); + + initBody(row2); + + nextPhase(); + + } + + public void initData() { + selectedIndex = 0; + nextPhase = true; + prometheeData = new ArrayList(); + for (int i = 0; i < model.numberCriterions(); i++) + prometheeData.add(new PrometheeData()); + } + + public void createRowImages(Composite base) { + Composite fotoRow = new Composite(base, 0); + UiService.setGridData(fotoRow, 9, 9, true, true); + UiService.setGridLayout(fotoRow, 6, true); + + Label foto1 = new Label(fotoRow, 0); + foto1.setImage(UiService.getIcon("promethee\\promethee_type1").createImage()); + UiService.setGridData(foto1, 9, 9, true, false); + + Label foto2 = new Label(fotoRow, 0); + foto2.setImage(UiService.getIcon("promethee\\promethee_type2").createImage()); + UiService.setGridData(foto2, 9, 9, true, false); + + Label foto3 = new Label(fotoRow, 0); + foto3.setImage(UiService.getIcon("promethee\\promethee_type3").createImage()); + UiService.setGridData(foto3, 9, 9, true, false); + + Label foto4 = new Label(fotoRow, 0); + foto4.setImage(UiService.getIcon("promethee\\promethee_type4").createImage()); + UiService.setGridData(foto4, 9, 9, true, false); + + Label foto5 = new Label(fotoRow, 0); + foto5.setImage(UiService.getIcon("promethee\\promethee_type5").createImage()); + UiService.setGridData(foto5, 9, 9, true, false); + + Label foto6 = new Label(fotoRow, 0); + foto6.setImage(UiService.getIcon("promethee\\promethee_type6").createImage()); + UiService.setGridData(foto6, 9, 9, true, false); + + createTitleImages(fotoRow); + } + + public void createTitleImages(Composite base) { + + Label title1Label = new Label(base, SWT.NONE); + title1Label.setText("Type 1"); + UiService.setGridData(title1Label, 0, 9, false, false); + UiService.setFont(title1Label, UiService.FONT_SECTION_TITLE); + + Label title2Label = new Label(base, SWT.NONE); + title2Label.setText("Type 2"); + UiService.setGridData(title2Label, 0, 9, false, false); + UiService.setFont(title2Label, UiService.FONT_SECTION_TITLE); + + Label title3Label = new Label(base, SWT.NONE); + title3Label.setText("Type 3"); + UiService.setGridData(title3Label, 0, 9, false, false); + UiService.setFont(title3Label, UiService.FONT_SECTION_TITLE); + + Label title4Label = new Label(base, SWT.NONE); + title4Label.setText("Type 4"); + UiService.setGridData(title4Label, 0, 9, false, false); + UiService.setFont(title4Label, UiService.FONT_SECTION_TITLE); + + Label title5Label = new Label(base, SWT.NONE); + title5Label.setText("Type 5"); + UiService.setGridData(title5Label, 0, 9, false, false); + UiService.setFont(title5Label, UiService.FONT_SECTION_TITLE); + + Label title6Label = new Label(base, SWT.NONE); + title6Label.setText("Type 6"); + UiService.setGridData(title6Label, 0, 9, false, false); + UiService.setFont(title6Label, UiService.FONT_SECTION_TITLE); + } + + public void initBody(Composite base) { + // La otra mitad + Composite rowMitadAbajo = new Composite(base, 0); + UiService.setGridData(rowMitadAbajo, 9, 0, true, true); + UiService.setGridLayout(rowMitadAbajo, 2); + + // Criterions y datos. + createColTreeView(rowMitadAbajo); + + createColParametersPromethee(rowMitadAbajo); + } + + // Métodos para el Tree View + private void createColTreeView(Composite base) { + + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + Label titleLabel = new Label(row, SWT.NONE); + titleLabel.setText("Criterios"); + UiService.setGridData(titleLabel, 9, 9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + // Criterion tree + criterionViewer = getViewer(row, Criterion.Type, true); + } + + // Crea los botones y spinner para poder introducir los datos del problema + private void createColParametersPromethee(Composite base) { + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + titleLabelParametersCriterion = new Label(row, SWT.NONE); + titleLabelParametersCriterion.setText("Parametros de --------"); + UiService.setGridData(titleLabelParametersCriterion, 9, 9, true, false); + UiService.setFont(titleLabelParametersCriterion, UiService.FONT_SECTION_TITLE); + + Composite row1 = new Composite(row, SWT.BORDER); + UiService.setGridData(row1, 9, 9, true, true); + UiService.setGridLayout(row1, 1); + + comboBox = new Combo(row1, 0); + UiService.setGridData(comboBox, -1, 9, false, false); + comboBox.add("Type One"); + comboBox.add("Type Two"); + comboBox.add("Type three"); + comboBox.add("Type Four"); + comboBox.add("Type Five"); + comboBox.add("Type Six"); + comboBox.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + Combo comboBox = (Combo) e.getSource(); + + //Arrays.stream(rowTypeData.getChildren()).forEach(k -> k.dispose()); + //CreateComponentType(rowTypeData, comboBox.getSelectionIndex() + 1); + //rowTypeData.layout(); + switch(comboBox.getSelectionIndex()) { + case 0: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + break; + case 1: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(true); + rowLabelS.setVisible(false); + break; + case 2: + rowLabelPp.setVisible(true); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + break; + case 3: + case 4: + rowLabelPp.setVisible(true); + rowLabelQq.setVisible(true); + rowLabelS.setVisible(false); + break; + case 5: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(true); + break; + } + + prometheeData.get(selectedIndex).setTypeFunc(comboBox.getSelectionIndex() + 1); + setParametersSelected(); + refreshUI(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + } + }); + + rowTypeData = new Composite(row1, SWT.NONE); + UiService.setGridData(rowTypeData, 9, 9, true, true); + UiService.setGridLayout(rowTypeData, 1); + CreateComponentType(rowTypeData, 1); + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + } + + private void CreateComponentType(Composite base, int type) { + // P + rowLabelPp = new Composite(base, 0); + UiService.setGridData(rowLabelPp, 9, 9, true, false); + UiService.setGridLayout(rowLabelPp, 2, true); + Label labelPp = new Label(rowLabelPp, SWT.NONE); + labelPp.setText("P:"); + spinnerP = new Spinner(rowLabelPp, SWT.BORDER); + spinnerP.setDigits(3); + spinnerP.setMinimum(Integer.MIN_VALUE); + spinnerP.setMaximum(Integer.MAX_VALUE); + //spinnerP.addModifyListener(mdfListener); + spinnerP.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + //saveParameters(); + switch (comboBox.getSelectionIndex()) { + case 0: + prometheeData.get(selectedIndex).setP(0); + break; + default: + prometheeData.get(selectedIndex).setP(DoubleHelper.ParseDouble(spinnerP.getText())); + } + nextPhase(); + + } + }); + + // Q + rowLabelQq = new Composite(base, 0); + UiService.setGridData(rowLabelQq, 9, 9, true, false); + UiService.setGridLayout(rowLabelQq, 2, true); + Label labelQq = new Label(rowLabelQq, SWT.NONE); + labelQq.setText("Q:"); + spinnerQ = new Spinner(rowLabelQq, SWT.BORDER); + spinnerQ.setDigits(3); + spinnerQ.setMinimum(Integer.MIN_VALUE); + spinnerQ.setMaximum(Integer.MAX_VALUE); + //spinnerQ.addModifyListener(mdfListener); + spinnerQ.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + //saveParameters(); + switch (comboBox.getSelectionIndex()) { + case 0: + prometheeData.get(selectedIndex).setQ(0); + break; + default: + prometheeData.get(selectedIndex).setQ(DoubleHelper.ParseDouble(spinnerQ.getText())); + } + nextPhase(); + + } + }); + + // S + rowLabelS = new Composite(base, 0); + UiService.setGridData(rowLabelS, 9, 9, true, false); + UiService.setGridLayout(rowLabelS, 2, true); + Label labelS = new Label(rowLabelS, SWT.NONE); + labelS.setText("S:"); + spinnerS = new Spinner(rowLabelS, SWT.BORDER); + spinnerS.setDigits(3); + spinnerS.setMinimum(Integer.MIN_VALUE); + spinnerS.setMaximum(Integer.MAX_VALUE); + spinnerS.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + //saveParameters(); + switch (comboBox.getSelectionIndex()) { + case 0: + prometheeData.get(selectedIndex).setS(0); + break; + default: + prometheeData.get(selectedIndex).setS(DoubleHelper.ParseDouble(spinnerS.getText())); + } + nextPhase(); + + } + }); + } + + // Funión que nos devuelve el Viewer con los criterios + private ProblemElementViewer getViewer(Composite parent, String type, boolean addParent) { + + ProblemElementViewerLabel viewer = ContextInjectionFactory.make(ProblemElementViewerLabel.class, this.context); + + if (addParent) { + FakeProblemElement fakePE = new FakeProblemElement(""); + fakePE.as(type); + viewer.useGlobalParent(fakePE); + } + + viewer.createControls(type, parent); + viewer.addListener((IProblemElementViewerOnSingleClick) this); + viewer.loadListeners(); + + UiService.setGridLayout(viewer.getTree().getTree(), 1); + UiService.setGridData(viewer.getTree().getTree(), 9, 9, true, true); + + return viewer; + } + + // Función con la que podemos controlar el funcionamiento del click en el Viewer + public void problemElementViewerOnSingleClick(ProblemElement item) { + // Seleccionado el fake parent. + if (item.getCanonicalName().equals("")) + return; + + // Saving + saveParameters(); + + String selectedCriterion = item.getName(); + titleLabelParametersCriterion.setText("Parametros de " + selectedCriterion); + + for (int i = 0; i < model.numberCriterions(); i++) { + if (model.getCriterionNames()[i].equals(selectedCriterion)) { + selectedIndex = i; + break; + } + } + + //Changing the spinner parameters. + setParametersSelected(); + + refreshUI(); + } + + public void saveParameters() { + prometheeData.get(selectedIndex).setTypeFunc(comboBox.getSelectionIndex() + 1); + + switch (comboBox.getSelectionIndex()) { + case 0: + prometheeData.get(selectedIndex).setP(0); + prometheeData.get(selectedIndex).setQ(0); + case 1: + prometheeData.get(selectedIndex).setQ(DoubleHelper.ParseDouble(spinnerQ.getText())); + break; + case 2: + prometheeData.get(selectedIndex).setP(DoubleHelper.ParseDouble(spinnerP.getText())); + break; + case 3: + case 4: + prometheeData.get(selectedIndex).setP(DoubleHelper.ParseDouble(spinnerP.getText())); + prometheeData.get(selectedIndex).setQ(DoubleHelper.ParseDouble(spinnerQ.getText())); + break; + case 5: + prometheeData.get(selectedIndex).setS(DoubleHelper.ParseDouble(spinnerS.getText())); + break; + } + } + + private void setParametersSelected() { + comboBox.select( prometheeData.get(selectedIndex).getTypeFunc() - 1); + + spinnerP.setSelection( ChangeDoubleToInt(prometheeData.get(selectedIndex).getP(),spinnerP) ); + spinnerQ.setSelection( ChangeDoubleToInt(prometheeData.get(selectedIndex).getQ(),spinnerQ) ); + spinnerS.setSelection( ChangeDoubleToInt(prometheeData.get(selectedIndex).getS(),spinnerS) ); + + switch(comboBox.getSelectionIndex()) { + case 0: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + break; + case 1: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(true); + rowLabelS.setVisible(false); + break; + case 2: + rowLabelPp.setVisible(true); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(false); + break; + case 3: + case 4: + rowLabelPp.setVisible(true); + rowLabelQq.setVisible(true); + rowLabelS.setVisible(false); + break; + case 5: + rowLabelPp.setVisible(false); + rowLabelQq.setVisible(false); + rowLabelS.setVisible(true); + break; + } + } + + private int ChangeDoubleToInt(double number, Spinner spinner) { + double newNumber = number; + newNumber *= Math.pow(10, spinner.getDigits()); + return (int) newNumber; + } + + private void nextPhase() { + float[] p = new float[model.getCriterionNames().length]; + float[] q = new float[model.getCriterionNames().length]; + float[] s = new float[model.getCriterionNames().length]; + + int[] typeFunc = new int[model.getCriterionNames().length]; + + for(int i = 0; i < prometheeData.size(); i++) { + p[i] = (float) prometheeData.get(i).getP(); + q[i] = (float) prometheeData.get(i).getQ(); + s[i] = (float) prometheeData.get(i).getS(); + + typeFunc[i] = prometheeData.get(i).getTypeFunc(); + } + model.nextPhase(p, q, s, typeFunc); + + } + + public void checkStateChanged(CheckStateChangedEvent event) { + refreshUI(); + } + + public void refreshUI() { + this.sendRefresh(); + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return nextPhase; + } + +} diff --git a/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/viewer/ProblemElementViewerLabel.java b/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/viewer/ProblemElementViewerLabel.java new file mode 100644 index 0000000..f08aaa7 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering.ui/src/flintstones/method/promethee/phase/gathering/viewer/ProblemElementViewerLabel.java @@ -0,0 +1,33 @@ +package flintstones.method.promethee.phase.gathering.viewer; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; + +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewer; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.method.promethee.phase.gathering.provider.ProblemElementLabelProvider; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class ProblemElementViewerLabel extends ProblemElementViewer{ + + @Inject + IProblemElementService pService; + + @Inject + IEclipseContext context; + + @Override + protected IStyledLabelProvider getLabelProvider(String type) { + ImageDescriptor individualImage = UiService.getIcon(ProblemElementHelper.getImage(type, false)); + ImageDescriptor groupImage = UiService.getIcon(ProblemElementHelper.getImage(type, true)); + + ProblemElementLabelProvider provider = new ProblemElementLabelProvider(individualImage,groupImage); + ContextInjectionFactory.inject(provider, context); + return provider; + } +} diff --git a/bundles/flintstones.method.promethee.phase.gathering/.classpath b/bundles/flintstones.method.promethee.phase.gathering/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.promethee.phase.gathering/.polyglot.META-INF b/bundles/flintstones.method.promethee.phase.gathering/.polyglot.META-INF new file mode 100644 index 0000000..4af570c --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.promethee.phase.gathering + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Gathering + diff --git a/bundles/flintstones.method.promethee.phase.gathering/.project b/bundles/flintstones.method.promethee.phase.gathering/.project new file mode 100644 index 0000000..f42bb2f --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/.project @@ -0,0 +1,45 @@ + + + flintstones.method.promethee.phase.gathering + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362692 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.promethee.phase.gathering/META-INF/MANIFEST.MF b/bundles/flintstones.method.promethee.phase.gathering/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5370956 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Gathering +Bundle-SymbolicName: flintstones.method.promethee.phase.gathering;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.promethee.phase.gathering +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.entity.problemelement, + flintstones.model.problemelement.service, + javax.inject, + flintstones.helper.data +Export-Package: flintstones.method.promethee.phase.gathering diff --git a/bundles/flintstones.method.promethee.phase.gathering/build.properties b/bundles/flintstones.method.promethee.phase.gathering/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.promethee.phase.gathering/plugin.xml b/bundles/flintstones.method.promethee.phase.gathering/plugin.xml new file mode 100644 index 0000000..0275e6a --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.promethee.phase.gathering/src/flintstones/method/promethee/phase/gathering/PrometheeGathering.java b/bundles/flintstones.method.promethee.phase.gathering/src/flintstones/method/promethee/phase/gathering/PrometheeGathering.java new file mode 100644 index 0000000..b4ea85a --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.gathering/src/flintstones/method/promethee/phase/gathering/PrometheeGathering.java @@ -0,0 +1,95 @@ +package flintstones.method.promethee.phase.gathering; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +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.helper.data.HashMatrix; +import flintstones.model.problemelement.service.IProblemElementService; + +public class PrometheeGathering extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + Alternative[] allAlternatives; + Criterion[] allCriterion; + Expert[] Allexperts; + + float[] p; + float[] q; + float[] s; + int[] typeFunc; + + HashMatrix weights; + + public PrometheeGathering() { + } + + @Override + public String getName() { + return "Phase Promethee Gathering"; + } + + @SuppressWarnings("unchecked") + public void loadData() { + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + allCriterion = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + Allexperts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + + //criterionWeights => HashMatrix + weights = (HashMatrix) this.importData("criterionWeights"); + } + + public void nextPhase(float[] p, float[] q, float[] s, int[] typeFunc) { + //Export the data. + int[] MinMax = new int[allCriterion.length]; + float[] ws = new float[allCriterion.length]; + double w; + + for(int i = 0; i < allCriterion.length; i++) { + MinMax[i] = (allCriterion[i].isCost()) ? 0 : 1; + w = weights.get(Allexperts[0], allCriterion[i]); + ws[i] = (float) w; + } + + this.p = p; + this.q = q; + this.s = s; + this.typeFunc = typeFunc; + + this.exportData("arrayP", this.p); + this.exportData("arrayQ", this.q); + this.exportData("arrayS", this.s); + this.exportData("arrayWeights", ws); + this.exportData("arrayMinMax", MinMax); + this.exportData("arrayTypeFunc", this.typeFunc); + } + + public String[] getAlternativesNames() { + String[] str = new String[allAlternatives.length]; + + for(int i = 0; i < allAlternatives.length; i++) + str[i] = problemService.getByName(Alternative.Type, allAlternatives[i].getName()).getName(); + + return str; + } + + public String[] getCriterionNames() { + String[] str = new String[allCriterion.length]; + + for(int i = 0; i < allCriterion.length; i++) + str[i] = problemService.getByName(Criterion.Type, allCriterion[i].getName()).getName(); + + + return str; + } + + public int numberCriterions() { + return allCriterion.length; + } + +} diff --git a/bundles/flintstones.method.promethee.phase.result.ui/.classpath b/bundles/flintstones.method.promethee.phase.result.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.promethee.phase.result.ui/.polyglot.META-INF b/bundles/flintstones.method.promethee.phase.result.ui/.polyglot.META-INF new file mode 100644 index 0000000..7bef48c --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.promethee.phase.result.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.promethee.phase.result.ui/.project b/bundles/flintstones.method.promethee.phase.result.ui/.project new file mode 100644 index 0000000..9277da0 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.promethee.phase.result.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362694 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.promethee.phase.result.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.promethee.phase.result.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0a3c80d --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.promethee.phase.result.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.promethee.phase.result.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + org.eclipse.e4.core.contexts, + javax.inject, + flintstones.helper.html, + flintstones.entity.method.phase, + flintstones.method.promethee.phase.result diff --git a/bundles/flintstones.method.promethee.phase.result.ui/build.properties b/bundles/flintstones.method.promethee.phase.result.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.promethee.phase.result.ui/plugin.xml b/bundles/flintstones.method.promethee.phase.result.ui/plugin.xml new file mode 100644 index 0000000..6533d28 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.promethee.phase.result.ui/src/flintstones/method/promethee/phase/result/ui/PrometheeResultUI.java b/bundles/flintstones.method.promethee.phase.result.ui/src/flintstones/method/promethee/phase/result/ui/PrometheeResultUI.java new file mode 100644 index 0000000..548ac1c --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result.ui/src/flintstones/method/promethee/phase/result/ui/PrometheeResultUI.java @@ -0,0 +1,123 @@ +package flintstones.method.promethee.phase.result.ui; + +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.promethee.phase.result.PrometheeResult; +import flintstones.model.ui.service.UiService; + +public class PrometheeResultUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + Composite rowTable; + HtmlTextTable table; + Combo comboBox; + + PrometheeResult model; + String[] rowHeaderResult; + + public void init() { + model = (PrometheeResult) this.getModel(); + model.cargarDatos(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 9, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText("PROMETHEE RESULT"); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9, 9, true, true); + UiService.setGridLayout(row2, 1); + + comboBox = new Combo(row2, 0); + UiService.setGridData(comboBox, -1, 9, false, false); + comboBox.add("Ranking"); + String[] criterionNames = model.getCriterionNames(); + for(int i = 0; i < criterionNames.length; i++) + comboBox.add(criterionNames[i]); + + comboBox.select(0); + comboBox.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + refreshUI(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + } + }); + + rowTable = new Composite(row2, 0); + UiService.setGridData(rowTable, 9, 9, true, true); + UiService.setGridLayout(rowTable, 1); + + tableRender(rowTable, model.getResult(), model.getAlternativesNames(), model.getRowHeaderPromethee()); + + } + + //Tabla con el resultado final + public void tableRender(Composite base, float[][] values, String[] colHeader, String[] rowHeader) { + String[][] valuesSTR = new String [colHeader.length][rowHeader.length]; + + for(int i = 0; i < valuesSTR.length; i++) { + for(int j = 0; j < valuesSTR[i].length; j++) { + valuesSTR[i][j] = "" + values[i][j]; + } + } + + table = new HtmlTextTable(base, valuesSTR, rowHeader, colHeader); + table.render(); + } + + public void refreshUI() { + Arrays.stream(rowTable.getChildren()).forEach(k -> k.dispose()); + + model.cargarDatos(); + + //0 -> Result + if(comboBox.getSelectionIndex() == 0) { + tableRender(rowTable, model.getResult(), model.getAlternativesNames(), model.getRowHeaderPromethee()); + }else { + tableRender(rowTable, model.getCriterionMatrixFlow(comboBox.getSelectionIndex() - 1), + model.getAlternativesNames(), model.getRowHeaderPromethee()); + } + + table.render(); + rowTable.layout(); + this.sendRefresh(); + } + + @Override + public void refresh() { + refreshUI(); + } + + @Override + public boolean isForwardEnabled() { + return false; + } + +} diff --git a/bundles/flintstones.method.promethee.phase.result/.classpath b/bundles/flintstones.method.promethee.phase.result/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.promethee.phase.result/.polyglot.META-INF b/bundles/flintstones.method.promethee.phase.result/.polyglot.META-INF new file mode 100644 index 0000000..b24fe5f --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.promethee.phase.result + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Result + diff --git a/bundles/flintstones.method.promethee.phase.result/.project b/bundles/flintstones.method.promethee.phase.result/.project new file mode 100644 index 0000000..3b72f8b --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/.project @@ -0,0 +1,45 @@ + + + flintstones.method.promethee.phase.result + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362693 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.promethee.phase.result/META-INF/MANIFEST.MF b/bundles/flintstones.method.promethee.phase.result/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4fabc2c --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Result +Bundle-SymbolicName: flintstones.method.promethee.phase.result;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.promethee.phase.result +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.method.phase, + flintstones.entity.problemelement, + javax.inject, + flintstones.model.problemelement.service, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric +Export-Package: flintstones.method.promethee.phase.result diff --git a/bundles/flintstones.method.promethee.phase.result/build.properties b/bundles/flintstones.method.promethee.phase.result/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.promethee.phase.result/plugin.xml b/bundles/flintstones.method.promethee.phase.result/plugin.xml new file mode 100644 index 0000000..aea8917 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.promethee.phase.result/src/flintstones/method/promethee/phase/result/Promethee.java b/bundles/flintstones.method.promethee.phase.result/src/flintstones/method/promethee/phase/result/Promethee.java new file mode 100644 index 0000000..8429003 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/src/flintstones/method/promethee/phase/result/Promethee.java @@ -0,0 +1,178 @@ +package flintstones.method.promethee.phase.result; + +import java.util.ArrayList; + +/** + * @author Alex + */ + +public class Promethee { + + //----------------- DATOS INICIALES DEL PROBLEMA ---------------------- + float[][] initMatrix; + int[] MinMax; //0 --> Min || 1 --> Max + float[] weights; + int[] typeFunc; + + String[] alternatives; + String[] criteria; + //--------------------- VARIABLES INTERNAS ---------------------------- + ArrayList preferencesDegrees; + ArrayList flowMatrix; + float[][] globalFlowMatrix; + float[] p; + float[] q; + float[] s; + + public Promethee(String[] alternatives, String[] criterions) { + this.alternatives = alternatives; + this.criteria = criterions; + } + + //-------------------- GETTERS AND SETTERS --------------------------- + public float[][] getMAtrixFlow(int indexCriterion){ + return flowMatrix.get(indexCriterion); + } + + public float[][] getGlobalFLow(){ + return globalFlowMatrix; + } + + //-------------------- PROMETHEE FUNCTIONS --------------------------- + + public void init() { + preferencesDegrees = new ArrayList(); + flowMatrix = new ArrayList(); + globalFlowMatrix = new float[alternatives.length][3]; + + //Inicializamos el vector de matrices para cada criterio enfrentando alternativas con alternativas. + for (int i = 0; i < criteria.length; ++i) { + preferencesDegrees.add(new float[alternatives.length][alternatives.length]); + flowMatrix.add(new float[alternatives.length][3]); + } + } + + public void Execute(float[][] initMatrix, float[] weights, int[] MinMax, int[] typeFunc, float[] p, float[] q, float[] s) { + //Iniciamos los valores + this.initMatrix = initMatrix; + this.weights = weights; + this.MinMax = MinMax; + this.typeFunc = typeFunc; + this.p = p; + this.q = q; + this.s = s; + + init(); + + //Calculamos las matrices. + calculatePreferences(); + + //Calculamos el flujo + calculateFlow(); + + //Calculamos el flujo global según sus pesos. + calculateGlobalsFlow(); + } + + //Calcula las matrices de preferencia según la función especificada. + private void calculatePreferences() { + float d = 0.0f; + //Nos recorremos los criteros para calcular cada matriz + for (int iCriterion = 0; iCriterion < criteria.length; iCriterion++) { + + //Enfrentamos las alternativas según el criterio (iCriterion) que estamos calculando. + for (int iAlternative = 0; iAlternative < alternatives.length; iAlternative++) { + + for (int jAlternative = 0; jAlternative < alternatives.length; jAlternative++) { + + if (iAlternative != jAlternative) { + //Comprobamos si es de beneficio o de coste. + d = (MinMax[iCriterion] == 0) + ? -(initMatrix[iAlternative][iCriterion] - initMatrix[jAlternative][iCriterion]) + : (initMatrix[iAlternative][iCriterion] - initMatrix[jAlternative][iCriterion]); + + preferencesDegrees.get(iCriterion)[iAlternative][jAlternative] = getResultFunction(d, iCriterion); + + } else { + preferencesDegrees.get(iCriterion)[iAlternative][jAlternative] = 0.0f; + } + } + } + } + } + + //Calculamos el flujo positivo y negativo de cada matriz según sus criterios. + private void calculateFlow() { + float positive = 0, negative = 0; + for (int i = 0; i < preferencesDegrees.size(); i++) { + + //Caculamos el flujo positivo, negativo y neto. + for (int iAlt = 0; iAlt < alternatives.length; iAlt++) { + for (int jAlternative = 0; jAlternative < alternatives.length; jAlternative++) { + positive += preferencesDegrees.get(i)[iAlt][jAlternative]; + negative += preferencesDegrees.get(i)[jAlternative][iAlt]; + } + flowMatrix.get(i)[iAlt][0] = positive / (alternatives.length - 1); + flowMatrix.get(i)[iAlt][1] = negative / (alternatives.length - 1); + flowMatrix.get(i)[iAlt][2] = flowMatrix.get(i)[iAlt][0] - flowMatrix.get(i)[iAlt][1]; + positive = 0; + negative = 0; + } + } + } + + //Calculamos el flujo positivo y negativo de cada matriz según sus criterios. + private void calculateGlobalsFlow() { + float positive = 0, negative = 0; + + //Caculamos el flujo global positivo, negativo y neto. + for (int iAlt = 0; iAlt < alternatives.length; iAlt++) { + + for (int j = 0; j < flowMatrix.size(); j++) { + positive += flowMatrix.get(j)[iAlt][0] * weights[j]; + negative += flowMatrix.get(j)[iAlt][1] * weights[j]; + } + globalFlowMatrix[iAlt][0] = positive; + globalFlowMatrix[iAlt][1] = negative; + globalFlowMatrix[iAlt][2] = positive - negative; + positive = 0; + negative = 0; + } + } + + //Según la función especificada, te devuelve el valor P(d) correspondiente + private float getResultFunction(float d, int iCriterion) { + switch (typeFunc[iCriterion]) { + case 1: + if(d > 0 ) return 1; + else return 0; + case 2: + if(d > q[iCriterion] ) return 1; + else return 0; + case 3: + if(d > p[iCriterion] ) return 1; + else if (d <= 0) return 0; + else return d / p[iCriterion]; + case 4: + if(d > p[iCriterion] ) return 1; + else if (d <= q[iCriterion]) return 0; + else return 1/2; + case 5: + if (d <= q[iCriterion]) { + return 0.0f; + } else if (d > p[iCriterion]) { + return 1.0f; + } else { + return ((d - q[iCriterion]) / (p[iCriterion] - q[iCriterion])); + } + case 6: + if(d <= 0 ) return 0; + else { + float exponentialFunc = (float) java.lang.Math.exp((-1) * (Math.pow(d, 2) / (2 * Math.pow(s[iCriterion], 2)))); + return 1 - exponentialFunc; + } + } + + return -1; + } +} diff --git a/bundles/flintstones.method.promethee.phase.result/src/flintstones/method/promethee/phase/result/PrometheeResult.java b/bundles/flintstones.method.promethee.phase.result/src/flintstones/method/promethee/phase/result/PrometheeResult.java new file mode 100644 index 0000000..ef5e533 --- /dev/null +++ b/bundles/flintstones.method.promethee.phase.result/src/flintstones/method/promethee/phase/result/PrometheeResult.java @@ -0,0 +1,148 @@ +package flintstones.method.promethee.phase.result; + +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.numeric.NumericValuation; + +public class PrometheeResult extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + IValuationService valuationService; + + // Atributos + HashMap mapVAluations; + Alternative[] allAlternatives; + Criterion[] allCriterion; + Expert[] Allexperts; + String[] rowHeaderPromethee; + + Promethee promethee; + float[] weights; + float[][] values; + int[] MinMax; + + public PrometheeResult() { + } + + @Override + public String getName() { + return "Phase Promethee Result"; + } + + //------------------------------- GETS AND SETTERS --------------------------------- + public void cargarDatos() { + rowHeaderPromethee = new String[3]; + rowHeaderPromethee[0] = "Positive Flow"; + rowHeaderPromethee[1] = "Negative Flow"; + rowHeaderPromethee[2] = "Neto Flow"; + + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + allCriterion = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + Allexperts = ProblemElementHelper.asExperts(problemService.getAll(Expert.Type)); + + promethee = new Promethee(getAlternativesNames(), getCriterionNames()); + + values = this.getValuations(Allexperts[0]); + + float[] p = (float[]) this.importData("arrayP"); + float[] q = (float[]) this.importData("arrayQ"); + float[] s = (float[]) this.importData("arrayS"); + float[] w = (float[]) this.importData("arrayWeights"); + int[] MinMax = (int[]) this.importData("arrayMinMax"); + int[] typeFunc = (int[]) this.importData("arrayTypeFunc"); + + this.promethee.Execute(this.values, w, MinMax, typeFunc, p, q, s); + } + + public float[][] getValuations(Expert e) { + String[] alternatives = getAlternativesNames(); + String[] criterions = getCriterionNames(); + float[][] valuation = new float[allAlternatives.length][allCriterion.length]; + + //Obtenemos el hashmap + ProblemElement pE = problemService.getByCanonicalName(Expert.Type, e.getCanonicalName()); + mapVAluations = valuationService.getAllValuationsKVWith(pE); + + //Para cada elemento, introducirlo ordenado en el array + int a = 0, b = 0; + for(Entry entry : mapVAluations.entrySet()){ + NumericValuation nV = (NumericValuation) entry.getValue(); + + for(int i = 0; i < allAlternatives.length; i++) { + if(entry.getKey().getAlternative().getName().equals( alternatives[i] )) { + a = i; + break; + } + } + + for(int i = 0; i < allCriterion.length; i++) { + if(entry.getKey().getCriterion().getName().equals( criterions[i])) { + b = i; + break; + } + } + + double number = Double.valueOf(nV.getValue()); + valuation[a][b] = (float) number; + a = 0; + b = 0; + } + + return valuation; + } + + public float[][] getResult() { + return promethee.getGlobalFLow(); + } + + public float[][] getCriterionMatrixFlow(int indexCriterion){ + return promethee.getMAtrixFlow(indexCriterion); + } + + public void executePromethee() { + + } + + public String[] getRowHeaderPromethee() { + return rowHeaderPromethee; + } + + public String[] getAlternativesNames() { + String[] str = new String[allAlternatives.length]; + + for(int i = 0; i < allAlternatives.length; i++) + str[i] = allAlternatives[i].getName(); + + return str; + } + + public String[] getCriterionNames() { + String[] str = new String[allCriterion.length]; + + for(int i = 0; i < allCriterion.length; i++) { + str[i] = allCriterion[i].getName(); + } + + return str; + } + + public int numberCriterions() { + return allCriterion.length; + } +} diff --git a/bundles/flintstones.method.promethee/.classpath b/bundles/flintstones.method.promethee/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.method.promethee/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.promethee/.polyglot.META-INF b/bundles/flintstones.method.promethee/.polyglot.META-INF new file mode 100644 index 0000000..46ff214 --- /dev/null +++ b/bundles/flintstones.method.promethee/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.promethee + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Promethee + diff --git a/bundles/flintstones.method.promethee/.project b/bundles/flintstones.method.promethee/.project new file mode 100644 index 0000000..bfe3689 --- /dev/null +++ b/bundles/flintstones.method.promethee/.project @@ -0,0 +1,45 @@ + + + flintstones.method.promethee + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362691 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.promethee/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.promethee/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.promethee/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.promethee/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.promethee/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.method.promethee/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.promethee/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.promethee/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.promethee/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.promethee/META-INF/MANIFEST.MF b/bundles/flintstones.method.promethee/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5987a55 --- /dev/null +++ b/bundles/flintstones.method.promethee/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Promethee +Bundle-SymbolicName: flintstones.method.promethee;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.promethee +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric diff --git a/bundles/flintstones.method.promethee/build.properties b/bundles/flintstones.method.promethee/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.method.promethee/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.promethee/plugin.xml b/bundles/flintstones.method.promethee/plugin.xml new file mode 100644 index 0000000..a1efba5 --- /dev/null +++ b/bundles/flintstones.method.promethee/plugin.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.promethee/src/flintstones/method/promethee/PrometheeMethod.java b/bundles/flintstones.method.promethee/src/flintstones/method/promethee/PrometheeMethod.java new file mode 100644 index 0000000..b1fde1d --- /dev/null +++ b/bundles/flintstones.method.promethee/src/flintstones/method/promethee/PrometheeMethod.java @@ -0,0 +1,49 @@ +package flintstones.method.promethee; + +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 flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.promethee.messages.Messages; +import flintstones.model.domain.service.IDomainService; +import flintstones.valuation.numeric.NumericValuation; + +public class PrometheeMethod extends ValidatedMethod { + + @Inject + IEclipseContext context; + + @Inject + IDomainService domainService; + + @Inject + @Translation + Messages messages; + + @Override + public String getName() { + return messages.method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, NumericValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + + } +} diff --git a/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/Messages.java b/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/Messages.java new file mode 100644 index 0000000..5c3bfb1 --- /dev/null +++ b/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/Messages.java @@ -0,0 +1,6 @@ +package flintstones.method.promethee.messages; + +public class Messages { + public String method_name; +} + diff --git a/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/messages.properties b/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/messages.properties new file mode 100644 index 0000000..b8118f5 --- /dev/null +++ b/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/messages.properties @@ -0,0 +1 @@ +method_name=A Preference Ranking Organization Method (PROMETHEE) diff --git a/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/messages_es.properties b/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/messages_es.properties new file mode 100644 index 0000000..2c21709 --- /dev/null +++ b/bundles/flintstones.method.promethee/src/flintstones/method/promethee/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Un mtodo de organizacin por orden de preferencia (PROMETHEE) diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/.classpath b/bundles/flintstones.method.sorting.phase.alternativealternative/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/.polyglot.META-INF b/bundles/flintstones.method.sorting.phase.alternativealternative/.polyglot.META-INF new file mode 100644 index 0000000..6533268 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.sorting.phase.alternativealternative + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Alternativealternative + diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/.project b/bundles/flintstones.method.sorting.phase.alternativealternative/.project new file mode 100644 index 0000000..8291285 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/.project @@ -0,0 +1,45 @@ + + + flintstones.method.sorting.phase.alternativealternative + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362694 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/META-INF/MANIFEST.MF b/bundles/flintstones.method.sorting.phase.alternativealternative/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8034bb5 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Alternativealternative +Bundle-SymbolicName: flintstones.method.sorting.phase.alternativealternative;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.sorting.phase.alternativealternative +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: javax.inject, + flintstones.model.problemelement.service, + flintstones.model.ahppreferences.service, + org.eclipse.e4.core.contexts, + flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.entity.ahppreferences, + org.eclipse.e4.core.di, + flintstones.entity.preferences.preferencecollection, + flintstones.entity.method.phase, + flintstones.entity.ahp.ui, + flintstones.valuation.ahp.ui diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/build.properties b/bundles/flintstones.method.sorting.phase.alternativealternative/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/plugin.xml b/bundles/flintstones.method.sorting.phase.alternativealternative/plugin.xml new file mode 100644 index 0000000..f51fe67 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/src/flintstones/method/sorting/phase/alternativealternative/SortingAlternativeAlternativeModel.java b/bundles/flintstones.method.sorting.phase.alternativealternative/src/flintstones/method/sorting/phase/alternativealternative/SortingAlternativeAlternativeModel.java new file mode 100644 index 0000000..3c4f0e8 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/src/flintstones/method/sorting/phase/alternativealternative/SortingAlternativeAlternativeModel.java @@ -0,0 +1,12 @@ +package flintstones.method.sorting.phase.alternativealternative; + +import flintstones.entity.method.phase.PhaseMethod; + +public class SortingAlternativeAlternativeModel extends PhaseMethod { + + @Override + public String getName() { + return "Sorting Alternative-Alternative"; + } + +} diff --git a/bundles/flintstones.method.sorting.phase.alternativealternative/src/flintstones/method/sorting/phase/alternativealternative/SortingAlternativeAlternativeUI.java b/bundles/flintstones.method.sorting.phase.alternativealternative/src/flintstones/method/sorting/phase/alternativealternative/SortingAlternativeAlternativeUI.java new file mode 100644 index 0000000..af9653a --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativealternative/src/flintstones/method/sorting/phase/alternativealternative/SortingAlternativeAlternativeUI.java @@ -0,0 +1,108 @@ +package flintstones.method.sorting.phase.alternativealternative; + +import java.util.ArrayList; +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.ahp.ui.PreferencesRatingPart; +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +/** + * The Class AHPAlternativeRatingPart. + */ +public class SortingAlternativeAlternativeUI extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + @Inject + IEclipseContext context; + + @Inject + IProblemPreferencesService ppreferenceService; + + PreferencesRatingPart preferencesPart; + Composite parent; + + @Override + public void init() { + + parent = getBaseComposite(); + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + + build(); + } + + /** + * Builds the PreferenceRatingPart. + */ + private void build() { + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + ArrayList builds = getBuilds(); + + preferencesPart = ContextInjectionFactory.make(PreferencesRatingPart.class, context); + preferencesPart.initPreferencesRatingPart(parent, builds.toArray(new PreferenceBuild[0])); + + } + + /** + * Gets the data builds. + * + * @return the builds + */ + private ArrayList getBuilds() { + + ProblemElement[] mainPe = problemService.getAll(Expert.Type); + ProblemElement[] otherPe = problemService.getAll(Criterion.Type); + ProblemElement[] leftPe = problemService.getAll(Alternative.Type);; + ProblemElement[] rightPe = problemService.getAll(Alternative.Type); + + PreferenceCollection pc = ppreferenceService.get(mainPe[0].getType(), otherPe[0].getType(), leftPe[0].getType(), + rightPe[0].getType()); + + // Import PreferenceBuild + if (pc != null) + return pc.getBuilds(); + + // Create PreferenceBuild + ArrayList builds = new ArrayList<>(); + for (int i = 0; i < mainPe.length; i++) { + for (int j = 0; j < otherPe.length; j++) { + PreferenceBuild build = new PreferenceBuild( mainPe[i], otherPe[j], leftPe, rightPe); + ContextInjectionFactory.inject(build, context); + builds.add(build); + } + } + + return builds; + } + + @Override + public void refresh() { + //build(); + } + + @Override + protected boolean isForwardEnabled() { + return true; + } + + +} diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/.classpath b/bundles/flintstones.method.sorting.phase.alternativeprofile/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/.polyglot.META-INF b/bundles/flintstones.method.sorting.phase.alternativeprofile/.polyglot.META-INF new file mode 100644 index 0000000..c30427d --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.sorting.phase.alternativeprofile + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Alternativeprofile + diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/.project b/bundles/flintstones.method.sorting.phase.alternativeprofile/.project new file mode 100644 index 0000000..f811d0e --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/.project @@ -0,0 +1,45 @@ + + + flintstones.method.sorting.phase.alternativeprofile + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362695 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/META-INF/MANIFEST.MF b/bundles/flintstones.method.sorting.phase.alternativeprofile/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e104648 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Alternativeprofile +Bundle-SymbolicName: flintstones.method.sorting.phase.alternativeprofile;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.sorting.phase.alternativeprofile +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: javax.inject, + flintstones.model.problemelement.service, + flintstones.model.ahppreferences.service, + org.eclipse.e4.core.contexts, + flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.entity.ahppreferences, + org.eclipse.e4.core.di, + flintstones.entity.preferences.preferencecollection, + flintstones.entity.method.phase, + flintstones.entity.ahp.ui, + flintstones.valuation.ahp.ui, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/build.properties b/bundles/flintstones.method.sorting.phase.alternativeprofile/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/plugin.xml b/bundles/flintstones.method.sorting.phase.alternativeprofile/plugin.xml new file mode 100644 index 0000000..3cca3f4 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/src/flintstones/method/sorting/phase/alternativeprofile/SortingAlternativeProfileModel.java b/bundles/flintstones.method.sorting.phase.alternativeprofile/src/flintstones/method/sorting/phase/alternativeprofile/SortingAlternativeProfileModel.java new file mode 100644 index 0000000..84e9986 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/src/flintstones/method/sorting/phase/alternativeprofile/SortingAlternativeProfileModel.java @@ -0,0 +1,12 @@ +package flintstones.method.sorting.phase.alternativeprofile; + +import flintstones.entity.method.phase.PhaseMethod; + +public class SortingAlternativeProfileModel extends PhaseMethod { + + @Override + public String getName() { + return "Sorting Alternative-Profile"; + } + +} diff --git a/bundles/flintstones.method.sorting.phase.alternativeprofile/src/flintstones/method/sorting/phase/alternativeprofile/SortingAlternativeProfileUI.java b/bundles/flintstones.method.sorting.phase.alternativeprofile/src/flintstones/method/sorting/phase/alternativeprofile/SortingAlternativeProfileUI.java new file mode 100644 index 0000000..9cc45ae --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.alternativeprofile/src/flintstones/method/sorting/phase/alternativeprofile/SortingAlternativeProfileUI.java @@ -0,0 +1,94 @@ +package flintstones.method.sorting.phase.alternativeprofile; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.ahp.ui.PreferencesRatingPart; +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +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.ProblemElement; +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +/** + * The Class AhpSortAlternativeProfilePart. + */ +public class SortingAlternativeProfileUI extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + /** The context. */ + @Inject + IEclipseContext context; + + @Inject + IProfileAssignmentService profileService; + + PreferencesRatingPart preferencesPart; + Composite parent; + + @Override + public void init() { + + this.parent = getBaseComposite(); + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + build(); + } + + /** + * Builds the part. + */ + private void build() { + + ProblemElement[] mainPe = problemService.getAll(Expert.Type); + ProblemElement[] otherPe = problemService.getAll(Criterion.Type); + ProblemElement[] leftPe = problemService.getAll(Alternative.Type); + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + // Create PreferenceBuild + ArrayList builds = new ArrayList<>(); + for (int i = 0; i < mainPe.length; i++) { + for (int j = 0; j < otherPe.length; j++) { + + ProfileAssignment pe = profileService.get((Expert) mainPe[i], (Criterion) otherPe[j]); + LinkedList rightPe = pe.getAllProfiles(); + + PreferenceBuild build = new PreferenceBuild(mainPe[i], otherPe[j], leftPe, + rightPe.toArray(new SortingProfile[0])); + ContextInjectionFactory.inject(build, context); + builds.add(build); + } + } + + preferencesPart = ContextInjectionFactory.make(PreferencesRatingPart.class, context); + preferencesPart.initPreferencesRatingPart(parent, builds.toArray(new PreferenceBuild[0])); + + } + + @Override + public void refresh() { + // build(); + } + + @Override + protected boolean isForwardEnabled() { + return true; + } + +} diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/.classpath b/bundles/flintstones.method.sorting.phase.criterioncriterion/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/.polyglot.META-INF b/bundles/flintstones.method.sorting.phase.criterioncriterion/.polyglot.META-INF new file mode 100644 index 0000000..aa60226 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.sorting.phase.criterioncriterion + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Criterioncriterion + diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/.project b/bundles/flintstones.method.sorting.phase.criterioncriterion/.project new file mode 100644 index 0000000..f4ec219 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/.project @@ -0,0 +1,45 @@ + + + flintstones.method.sorting.phase.criterioncriterion + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362695 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/META-INF/MANIFEST.MF b/bundles/flintstones.method.sorting.phase.criterioncriterion/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1fae234 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Criterioncriterion +Bundle-SymbolicName: flintstones.method.sorting.phase.criterioncriterion;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.sorting.phase.criterioncriterion +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: javax.inject, + flintstones.model.problemelement.service, + flintstones.model.ahppreferences.service, + org.eclipse.e4.core.contexts, + flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.entity.ahppreferences, + org.eclipse.e4.core.di, + flintstones.entity.preferences.preferencecollection, + flintstones.entity.method.phase, + flintstones.entity.ahp.ui, + flintstones.valuation.ahp.ui diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/build.properties b/bundles/flintstones.method.sorting.phase.criterioncriterion/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/plugin.xml b/bundles/flintstones.method.sorting.phase.criterioncriterion/plugin.xml new file mode 100644 index 0000000..785070a --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/src/flintstones/method/sorting/phase/criterioncriterion/SortingCriterionCriterionModel.java b/bundles/flintstones.method.sorting.phase.criterioncriterion/src/flintstones/method/sorting/phase/criterioncriterion/SortingCriterionCriterionModel.java new file mode 100644 index 0000000..6ca2cc1 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/src/flintstones/method/sorting/phase/criterioncriterion/SortingCriterionCriterionModel.java @@ -0,0 +1,12 @@ +package flintstones.method.sorting.phase.criterioncriterion; + +import flintstones.entity.method.phase.PhaseMethod; + +public class SortingCriterionCriterionModel extends PhaseMethod { + + @Override + public String getName() { + return "Sorting Criterion-Criterion"; + } + +} diff --git a/bundles/flintstones.method.sorting.phase.criterioncriterion/src/flintstones/method/sorting/phase/criterioncriterion/SortingCriterionCriterionUI.java b/bundles/flintstones.method.sorting.phase.criterioncriterion/src/flintstones/method/sorting/phase/criterioncriterion/SortingCriterionCriterionUI.java new file mode 100644 index 0000000..46aba53 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.criterioncriterion/src/flintstones/method/sorting/phase/criterioncriterion/SortingCriterionCriterionUI.java @@ -0,0 +1,107 @@ +package flintstones.method.sorting.phase.criterioncriterion; + +import java.util.ArrayList; +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.ahp.ui.PreferencesRatingPart; +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +/** + * The Class AHPCriterionRatingPart. + */ +public class SortingCriterionCriterionUI extends PhaseMethodUI { + + @Inject + IProblemElementService problemService; + + @Inject + IEclipseContext context; + + @Inject + IProblemPreferencesService ppreferenceService; + + PreferencesRatingPart preferencesPart; + Composite parent; + + @Override + public void init() { + + this.parent = getBaseComposite(); + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + + build(); + + parent.layout(); + } + + /** + * Builds the. + */ + private void build() { + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + // Create PreferenceBuild - BASIC, NO MAIN + ArrayList builds = getBuilds(); + + preferencesPart = ContextInjectionFactory.make(PreferencesRatingPart.class, context); + preferencesPart.initPreferencesRatingPart(parent, builds.toArray(new PreferenceBuild[0])); + + } + + /** + * Gets the builds. + * + * @return the builds + */ + private ArrayList getBuilds() { + + ProblemElement[] otherPe = problemService.getAll(Expert.Type); + ProblemElement[] leftPe = problemService.getAll(Criterion.Type); + ProblemElement[] rightPe = problemService.getAll(Criterion.Type); + + PreferenceCollection pc = ppreferenceService.get(null, otherPe[0].getType(), leftPe[0].getType(), + rightPe[0].getType()); + + // Import PreferenceBuild + if (pc != null) + return pc.getBuilds(); + + // Create PreferenceBuild + ArrayList builds = new ArrayList<>(); + for (int j = 0; j < otherPe.length; j++) { + PreferenceBuild build = new PreferenceBuild(null, otherPe[j], leftPe, rightPe); + ContextInjectionFactory.inject(build, context); + builds.add(build); + } + + return builds; + } + + @Override + public void refresh() { +// build(); + } + + @Override + protected boolean isForwardEnabled() { + return true; + } + + +} diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.classpath b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.polyglot.META-INF b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.polyglot.META-INF new file mode 100644 index 0000000..811ad95 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.sorting.phase.gatheringreferencepoint + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Gatheringreferencepoint + diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.project b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.project new file mode 100644 index 0000000..d3a799d --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.project @@ -0,0 +1,45 @@ + + + flintstones.method.sorting.phase.gatheringreferencepoint + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362696 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/META-INF/MANIFEST.MF b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6597fa4 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Gatheringreferencepoint +Bundle-SymbolicName: flintstones.method.sorting.phase.gatheringreferencepoint;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.sorting.phase.gatheringreferencepoint +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.problemelement.ui, + flintstones.helper.ui, + flintstones.model.problemelement.service, + javax.inject, + flintstones.model.domain.service, + flintstones.model.valuation.service, + flintstones.operator, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.helper.data, + flintstones.model.ahp.referencepoint.service, + flintstones.entity.valuation, + flintstones.valuation.numeric.real, + flintstones.operator.aggregation.min, + org.apache.commons.lang, + flintstones.operator.aggregation.max, + flintstones.entity.method.phase.ui, + flintstones.entity.method.phase, + flintstones.entity.operator diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/build.properties b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/plugin.xml b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/plugin.xml new file mode 100644 index 0000000..82fba34 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/src/flintstones/method/sorting/phase/gatheringreferencepoint/ReferencePointGatheringModel.java b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/src/flintstones/method/sorting/phase/gatheringreferencepoint/ReferencePointGatheringModel.java new file mode 100644 index 0000000..822e29c --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/src/flintstones/method/sorting/phase/gatheringreferencepoint/ReferencePointGatheringModel.java @@ -0,0 +1,12 @@ +package flintstones.method.sorting.phase.gatheringreferencepoint; + +import flintstones.entity.method.phase.PhaseMethod; + +public class ReferencePointGatheringModel extends PhaseMethod { + + @Override + public String getName() { + return "RP Gathering"; + } + +} diff --git a/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/src/flintstones/method/sorting/phase/gatheringreferencepoint/ReferencePointGatheringUI.java b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/src/flintstones/method/sorting/phase/gatheringreferencepoint/ReferencePointGatheringUI.java new file mode 100644 index 0000000..80f5bdf --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.gatheringreferencepoint/src/flintstones/method/sorting/phase/gatheringreferencepoint/ReferencePointGatheringUI.java @@ -0,0 +1,232 @@ +package flintstones.method.sorting.phase.gatheringreferencepoint; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import javax.inject.Inject; + +import org.apache.commons.lang.ArrayUtils; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.ui.widget.ProblemElementSelector; +import flintstones.entity.problemelement.ui.widget.listener.IProblemElementChangedListener; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.DoubleHelper; +import flintstones.helper.data.HashMapList; +import flintstones.helper.ui.components.SliderCollector; +import flintstones.helper.ui.components.listeners.WEvent; +import flintstones.helper.ui.components.listeners.WItemBeforeOperation; +import flintstones.helper.ui.components.listeners.WItemChanged; +import flintstones.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.aggregation.max.Max; +import flintstones.operator.aggregation.min.Min; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.numeric.real.RealValuation; + +public class ReferencePointGatheringUI extends PhaseMethodUI + implements IProblemElementChangedListener, WItemChanged, WItemBeforeOperation { + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + @Inject + IValuationService valuationService; + + @Inject + IOperatorService operatorService; + + @Inject + IReferencePointService referencePointService; + + private ProblemElementSelector criterionCombo; + + private Label rangeLabel; + SliderCollector collector; + + private HashMapList data = new HashMapList<>(); + private HashMap mins = new HashMap<>(); + private HashMap maxs = new HashMap<>(); + ProblemElement[] criterions; + + int numberOfCutsx = 6; + + + @Override + public void init() { + createControls(getBaseComposite()); + } + + private void createControls(Composite base) { + + UiService.setGridLayout(base, 1, true); + UiService.setGridDataAuto(base); + + Composite row1 = new Composite(base, 0); + UiService.setGridLayout(row1, 3, false); + UiService.setGridData(row1, 9, 0, true, false); + + criterions = problemService.getAll(Criterion.Type); + + criterionCombo = new ProblemElementSelector(row1, criterions); + + for (ProblemElement criterion : criterions) { + Double[] values = getReferencePoints(criterion); + data.put(criterion, new ArrayList(Arrays.asList(values))); + save(criterion); + } + + Double[] currentData = getCurrentData(); + double min = currentData.length > 0 ? currentData[0] : Double.MIN_VALUE; + double max = currentData.length > 0 ? currentData[currentData.length - 1] : Double.MAX_VALUE; + rangeLabel = new Label(row1, 0); + UiService.setGridDataAuto(rangeLabel); + + collector = new SliderCollector(base, min, max, 2); + + collector.setHeaders(getHeaders()); + collector.setValues(currentData); + + refreshRange(criterions[0]); + + collector.setBeforeOperationListener(this); + collector.setChangeListener(this); + criterionCombo.setListener(this); + + } + + public ProblemElement getCurrentCriterion() { + return criterionCombo.getSelectedElement(); + } + + private Double[] getReferencePoints(ProblemElement criterion) { + + // Compute min-max for each criterion + + Valuation[] valuations = valuationService.getAllValuationsWith(criterion); + valuations = Arrays.stream(valuations) // + .map(k -> ((RealValuation) k)) // + .toArray(Valuation[]::new); + + AggregationOperator max = operatorService.getAggregationOperator(Max.class.getPackage().getName(), valuations[0].getId()); + AggregationOperator min = operatorService.getAggregationOperator(Min.class.getPackage().getName(), valuations[0].getId()); + Valuation maxV = max.computeAggregation(Arrays.asList(valuations), null); + Valuation minV = min.computeAggregation(Arrays.asList(valuations), null); + + double minValue = ((RealValuation) minV).getValue(); + double maxValue = ((RealValuation) maxV).getValue(); + + mins.put(criterion, minValue); + maxs.put(criterion, maxValue); + + // Try to load the items from memory + Double[] items = referencePointService.getAsRange((Criterion) criterion); + if (items.length == 0) { + // If it is not possible, do the cuts by hand + int numberOfCuts = numberOfCutsx; + + double[] parts = DoubleHelper.ToRange(minValue, maxValue, numberOfCuts - 1, true); + + items = ArrayUtils.toObject(parts); + } + + criterionCombo.setStatus(criterion, items.length == numberOfCutsx); + return items; + + } + + private String[] getCurrentDataS() { + return Arrays.stream(getCurrentData()).map(k -> k + "").toArray(String[]::new); + } + + private Double[] getCurrentData() { + return data.getSafe(getCurrentCriterion()).toArray(new Double[0]); + } + + @Override + public void problemElementChanged(ProblemElement pe) { + Double[] values = Arrays.stream(getCurrentDataS()).map(k -> Double.parseDouble(k)).toArray(Double[]::new); + + refreshRange(pe); + + collector.setValues(values); + + } + + private void refreshRange(ProblemElement pe) { + Double min = mins.get(pe); + Double max = maxs.get(pe); + + rangeLabel.setText("[" + DoubleHelper.Draw(min) + " - " + DoubleHelper.Draw(max) + "]"); + + collector.reSet(min, max, 2); + } + + @Override + public void onWidgetChange() { + Double[] dataArr = collector.getData(); + Arrays.sort(dataArr); + + collector.setValues(dataArr); + data.put(getCurrentCriterion(), new ArrayList(Arrays.asList(dataArr))); + criterionCombo.setStatus(getCurrentCriterion(), dataArr.length == numberOfCutsx); + + save(getCurrentCriterion()); + } + + private void save(ProblemElement c) { + + Double[] values = data.get(c).toArray(new Double[0]); + referencePointService.addOrUpdate((Criterion) c, values); + + } + + @Override + public boolean shouldBeExecuted(WEvent operationType, String before, String after) { + + if (operationType.equals(WEvent.ADD)) { + Double[] data = collector.getData(); + Double newValue = DoubleHelper.ParseDouble(before); + + if (data.length >= numberOfCutsx) + return false; + + if (Arrays.asList(data).contains(newValue)) + return false; + } + + return true; + } + + private String[] getHeaders() { + String[] headers = new String[numberOfCutsx]; + for (int i = 0; i < numberOfCutsx; i++) + headers[i] = "R.P." + (i + 1); + return headers; + } + + public SliderCollector getCollector() { + return collector; + } + + @Override + public void refresh() { + System.out.println("IDK"); + } + + @Override + protected boolean isForwardEnabled() { + return true; + } +} diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/.classpath b/bundles/flintstones.method.sorting.phase.profileprofile/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/.polyglot.META-INF b/bundles/flintstones.method.sorting.phase.profileprofile/.polyglot.META-INF new file mode 100644 index 0000000..374b379 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.sorting.phase.profileprofile + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Profileprofile + diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/.project b/bundles/flintstones.method.sorting.phase.profileprofile/.project new file mode 100644 index 0000000..e3d0ac5 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/.project @@ -0,0 +1,45 @@ + + + flintstones.method.sorting.phase.profileprofile + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362697 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/META-INF/MANIFEST.MF b/bundles/flintstones.method.sorting.phase.profileprofile/META-INF/MANIFEST.MF new file mode 100644 index 0000000..84c96a9 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Profileprofile +Bundle-SymbolicName: flintstones.method.sorting.phase.profileprofile;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.sorting.phase.profileprofile +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: javax.inject, + flintstones.model.problemelement.service, + flintstones.model.ahppreferences.service, + org.eclipse.e4.core.contexts, + flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.entity.ahppreferences, + org.eclipse.e4.core.di, + flintstones.entity.preferences.preferencecollection, + flintstones.entity.method.phase, + flintstones.entity.ahp.ui, + flintstones.valuation.ahp.ui, + flintstones.model.ahpsort.profileassignment.service, + flintstones.model.ahp.referencepoint.service, + flintstones.entity.ahpsort.profileassignment diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/build.properties b/bundles/flintstones.method.sorting.phase.profileprofile/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/plugin.xml b/bundles/flintstones.method.sorting.phase.profileprofile/plugin.xml new file mode 100644 index 0000000..9fa6d1f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/src/flintstones/method/sorting/phase/profileprofile/SortingProfileProfileModel.java b/bundles/flintstones.method.sorting.phase.profileprofile/src/flintstones/method/sorting/phase/profileprofile/SortingProfileProfileModel.java new file mode 100644 index 0000000..d9cd5c5 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/src/flintstones/method/sorting/phase/profileprofile/SortingProfileProfileModel.java @@ -0,0 +1,12 @@ +package flintstones.method.sorting.phase.profileprofile; + +import flintstones.entity.method.phase.PhaseMethod; + +public class SortingProfileProfileModel extends PhaseMethod { + + @Override + public String getName() { + return "Sorting Profile-Profile"; + } + +} diff --git a/bundles/flintstones.method.sorting.phase.profileprofile/src/flintstones/method/sorting/phase/profileprofile/SortingProfileProfileUI.java b/bundles/flintstones.method.sorting.phase.profileprofile/src/flintstones/method/sorting/phase/profileprofile/SortingProfileProfileUI.java new file mode 100644 index 0000000..cd1d3f8 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.profileprofile/src/flintstones/method/sorting/phase/profileprofile/SortingProfileProfileUI.java @@ -0,0 +1,90 @@ +package flintstones.method.sorting.phase.profileprofile; + +import java.util.ArrayList; +import java.util.Arrays; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.ahp.ui.PreferencesRatingPart; +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +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.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class SortingProfileProfileUI extends PhaseMethodUI { + + @Inject + IProfileAssignmentService profileService; + + @Inject + IProblemElementService problemService; + + @Inject + IReferencePointService referencePointsService; + + @Inject + IEclipseContext context; + + PreferencesRatingPart preferencesPart; + Composite parent; + + @Override + public void init() { + + this.parent = getBaseComposite(); + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + + build(); + } + + private void build() { + + ProblemElement[] otherPe = problemService.getAll(Criterion.Type); + ProblemElement[] mainPe = problemService.getAll(Expert.Type); + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + // Create PreferenceBuild - BASIC, NO MAIN + ArrayList builds = new ArrayList<>(); + for (int i = 0; i < mainPe.length; i++) { + for (int j = 0; j < otherPe.length; j++) { + + // RIGHT + ProfileAssignment pe = profileService.get((Expert) mainPe[i], (Criterion) otherPe[j]); + ProblemElement[] rightPe = pe.getAllProfiles().toArray(new ProblemElement[0]); + + // LEFT + ProblemElement[] leftPe = rightPe; + + PreferenceBuild build = new PreferenceBuild(mainPe[i], otherPe[j], leftPe, rightPe); + ContextInjectionFactory.inject(build, context); + builds.add(build); + } + } + + preferencesPart = ContextInjectionFactory.make(PreferencesRatingPart.class, context); + preferencesPart.initPreferencesRatingPart(parent, builds.toArray(new PreferenceBuild[0])); + + } + + @Override + public void refresh() { + + } + + @Override + protected boolean isForwardEnabled() { + return true; + } +} diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/.classpath b/bundles/flintstones.method.sorting.phase.referencepointprofile/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/.polyglot.META-INF b/bundles/flintstones.method.sorting.phase.referencepointprofile/.polyglot.META-INF new file mode 100644 index 0000000..f5b9264 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.sorting.phase.referencepointprofile + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Referencepointprofile + diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/.project b/bundles/flintstones.method.sorting.phase.referencepointprofile/.project new file mode 100644 index 0000000..30dc8ac --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/.project @@ -0,0 +1,45 @@ + + + flintstones.method.sorting.phase.referencepointprofile + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362697 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/META-INF/MANIFEST.MF b/bundles/flintstones.method.sorting.phase.referencepointprofile/META-INF/MANIFEST.MF new file mode 100644 index 0000000..eaaf1fa --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Referencepointprofile +Bundle-SymbolicName: flintstones.method.sorting.phase.referencepointprofile;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.sorting.phase.referencepointprofile +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: javax.inject, + flintstones.model.problemelement.service, + flintstones.model.ahppreferences.service, + org.eclipse.e4.core.contexts, + flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.entity.ahppreferences, + org.eclipse.e4.core.di, + flintstones.entity.preferences.preferencecollection, + flintstones.entity.method.phase, + flintstones.entity.ahp.ui, + flintstones.valuation.ahp.ui, + flintstones.model.ahp.referencepoint.service, + flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.ahpsort.profileassignment, + flintstones.entity.ahpsort.referencepoint diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/build.properties b/bundles/flintstones.method.sorting.phase.referencepointprofile/build.properties new file mode 100644 index 0000000..ae532eb --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml +jre.compilation.profile = JavaSE-1.8 diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/plugin.xml b/bundles/flintstones.method.sorting.phase.referencepointprofile/plugin.xml new file mode 100644 index 0000000..f383ddd --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/src/flintstones/method/sorting/phase/referencepointprofile/SortingReferencepointProfileModel.java b/bundles/flintstones.method.sorting.phase.referencepointprofile/src/flintstones/method/sorting/phase/referencepointprofile/SortingReferencepointProfileModel.java new file mode 100644 index 0000000..1b510ae --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/src/flintstones/method/sorting/phase/referencepointprofile/SortingReferencepointProfileModel.java @@ -0,0 +1,12 @@ +package flintstones.method.sorting.phase.referencepointprofile; + +import flintstones.entity.method.phase.PhaseMethod; + +public class SortingReferencepointProfileModel extends PhaseMethod { + + @Override + public String getName() { + return "Sorting Reference_Points-Profiles"; + } + +} diff --git a/bundles/flintstones.method.sorting.phase.referencepointprofile/src/flintstones/method/sorting/phase/referencepointprofile/SortingReferencepointProfileUI.java b/bundles/flintstones.method.sorting.phase.referencepointprofile/src/flintstones/method/sorting/phase/referencepointprofile/SortingReferencepointProfileUI.java new file mode 100644 index 0000000..9e7e3d3 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencepointprofile/src/flintstones/method/sorting/phase/referencepointprofile/SortingReferencepointProfileUI.java @@ -0,0 +1,102 @@ +package flintstones.method.sorting.phase.referencepointprofile; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.swt.widgets.Composite; + +import flintstones.entity.ahp.ui.PreferencesRatingPart; +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +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.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class SortingReferencepointProfileUI extends PhaseMethodUI { + + @Inject + IProfileAssignmentService profileService; + + @Inject + IProblemElementService problemService; + + @Inject + IReferencePointService referencePointsService; + + @Inject + IEclipseContext context; + + PreferencesRatingPart preferencesPart; + Composite parent; + + /** + * Inits the part. + * + * @param parent the parent + */ + @Override + public void init() { + + this.parent = getBaseComposite(); + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + + + build(); + } + + private void build() { + + ProblemElement[] mainPe = problemService.getAll(Expert.Type); + ProblemElement[] otherPe = problemService.getAll(Criterion.Type); + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + // Create PreferenceBuild - BASIC, NO MAIN + ArrayList builds = new ArrayList<>(); + for (int i = 0; i < mainPe.length; i++) { + for (int j = 0; j < otherPe.length; j++) { + + // RIGHT + ProfileAssignment pe = profileService.get((Expert)mainPe[i], (Criterion)otherPe[j]); + ProblemElement[] rightPe = pe.getAllProfiles().toArray(new ProblemElement[0]); + + // LEFT + LinkedList points = referencePointsService.get( (Criterion) otherPe[j] ); + Collections.sort(points); + ProblemElement[] leftPe = points.toArray(new AHPSortReferencencePoint[0]); + + PreferenceBuild build = new PreferenceBuild(mainPe[i], otherPe[j], leftPe, rightPe); + ContextInjectionFactory.inject(build, context); + builds.add(build); + } + } + + preferencesPart = ContextInjectionFactory.make(PreferencesRatingPart.class, context); + preferencesPart.initPreferencesRatingPart(parent, builds.toArray(new PreferenceBuild[0])); + + } + + @Override + public void refresh() { + // build(); + + } + + @Override + protected boolean isForwardEnabled() { + return true; + } +} diff --git a/bundles/flintstones.method.sorting.phase.referencereference/.classpath b/bundles/flintstones.method.sorting.phase.referencereference/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.referencereference/.polyglot.META-INF b/bundles/flintstones.method.sorting.phase.referencereference/.polyglot.META-INF new file mode 100644 index 0000000..1a01c9c --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.sorting.phase.referencereference + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Referencereference + diff --git a/bundles/flintstones.method.sorting.phase.referencereference/.project b/bundles/flintstones.method.sorting.phase.referencereference/.project new file mode 100644 index 0000000..e288fef --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/.project @@ -0,0 +1,45 @@ + + + flintstones.method.sorting.phase.referencereference + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362698 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.sorting.phase.referencereference/META-INF/MANIFEST.MF b/bundles/flintstones.method.sorting.phase.referencereference/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8ccb73f --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Referencereference +Bundle-SymbolicName: flintstones.method.sorting.phase.referencereference;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.sorting.phase.referencereference +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: javax.inject, + flintstones.model.problemelement.service, + flintstones.model.ahppreferences.service, + org.eclipse.e4.core.contexts, + flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.entity.problemelement, + flintstones.entity.ahppreferences, + org.eclipse.e4.core.di, + flintstones.entity.preferences.preferencecollection, + flintstones.entity.method.phase, + flintstones.entity.ahp.ui, + flintstones.valuation.ahp.ui, + flintstones.model.ahpsort.profileassignment.service, + flintstones.model.ahp.referencepoint.service, + flintstones.entity.ahpsort.referencepoint diff --git a/bundles/flintstones.method.sorting.phase.referencereference/build.properties b/bundles/flintstones.method.sorting.phase.referencereference/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.sorting.phase.referencereference/plugin.xml b/bundles/flintstones.method.sorting.phase.referencereference/plugin.xml new file mode 100644 index 0000000..c653ab1 --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.sorting.phase.referencereference/src/flintstones/method/sorting/phase/referencereference/SortingReferencepointReferencePointModel.java b/bundles/flintstones.method.sorting.phase.referencereference/src/flintstones/method/sorting/phase/referencereference/SortingReferencepointReferencePointModel.java new file mode 100644 index 0000000..7b77faa --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/src/flintstones/method/sorting/phase/referencereference/SortingReferencepointReferencePointModel.java @@ -0,0 +1,12 @@ +package flintstones.method.sorting.phase.referencereference; + +import flintstones.entity.method.phase.PhaseMethod; + +public class SortingReferencepointReferencePointModel extends PhaseMethod { + + @Override + public String getName() { + return "Sorting Reference_Point-Reference-Point"; + } + +} diff --git a/bundles/flintstones.method.sorting.phase.referencereference/src/flintstones/method/sorting/phase/referencereference/SortingReferencepointReferencepointUI.java b/bundles/flintstones.method.sorting.phase.referencereference/src/flintstones/method/sorting/phase/referencereference/SortingReferencepointReferencepointUI.java new file mode 100644 index 0000000..82a93dd --- /dev/null +++ b/bundles/flintstones.method.sorting.phase.referencereference/src/flintstones/method/sorting/phase/referencereference/SortingReferencepointReferencepointUI.java @@ -0,0 +1,99 @@ +package flintstones.method.sorting.phase.referencereference; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +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.swt.widgets.Composite; + +import flintstones.entity.ahp.ui.PreferencesRatingPart; +import flintstones.entity.ahppreferences.PreferenceBuild; +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +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.model.ahp.referencepoint.service.IReferencePointService; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class SortingReferencepointReferencepointUI extends PhaseMethodUI { + + @Inject + IProfileAssignmentService profileService; + + @Inject + IProblemElementService problemService; + + @Inject + IReferencePointService referencePointsService; + + @Inject + IEclipseContext context; + + PreferencesRatingPart preferencesPart; + + Composite parent; + + /** + * Inits the part. + * + * @param parent the parent + */ + @Override + public void init() { + + this.parent = getBaseComposite(); + UiService.setGridLayout(parent, 1); + UiService.setGridData(parent, 9, 9, true, true); + + build(); + } + + private void build() { + + ProblemElement[] otherPe = problemService.getAll(Criterion.Type); + ProblemElement[] mainPe = problemService.getAll(Expert.Type); + + Arrays.stream(parent.getChildren()).forEach(k -> k.dispose()); + + // Create PreferenceBuild - BASIC, NO MAIN + ArrayList builds = new ArrayList<>(); + for(int i = 0; i < mainPe.length; ++i) { + for (int j = 0; j < otherPe.length; j++) { + + List listLeftPe = referencePointsService.get((Criterion) otherPe[j]); + Collections.sort(listLeftPe); + + ProblemElement[] leftPe = listLeftPe.toArray(new ProblemElement[0]); + ProblemElement[] rightPe = leftPe; + + PreferenceBuild build = new PreferenceBuild(mainPe[i], otherPe[j], leftPe, rightPe); + ContextInjectionFactory.inject(build, context); + builds.add(build); + + } + } + + preferencesPart = ContextInjectionFactory.make(PreferencesRatingPart.class, context); + preferencesPart.initPreferencesRatingPart(parent, builds.toArray(new PreferenceBuild[0])); + + } + + @Override + public void refresh() { + // build(); + + } + + @Override + protected boolean isForwardEnabled() { + return true; + } +} diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/.classpath b/bundles/flintstones.method.todim.phase.gathering.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/.polyglot.META-INF b/bundles/flintstones.method.todim.phase.gathering.ui/.polyglot.META-INF new file mode 100644 index 0000000..7b6e883 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.todim.phase.gathering.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/.project b/bundles/flintstones.method.todim.phase.gathering.ui/.project new file mode 100644 index 0000000..29fe630 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.todim.phase.gathering.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362700 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.todim.phase.gathering.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ea87383 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.todim.phase.gathering.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.todim.phase.gathering.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.swt, + flintstones.model.ui.service, + flintstones.helper.html, + org.eclipse.jface, + javax.inject, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.services, + flintstones.entity.method.phase.ui, + flintstones.model.problemelement.service, + flintstones.application.perspective.framework.ui, + flintstones.method.todim.phase.gathering, + flintstones.entity.method.phase, + flintstones.entity.problemelement, + flintstones.model.method.phase.service diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/build.properties b/bundles/flintstones.method.todim.phase.gathering.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/plugin.xml b/bundles/flintstones.method.todim.phase.gathering.ui/plugin.xml new file mode 100644 index 0000000..d4b9b27 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/provider/ProblemElementLabelProvider.java b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/provider/ProblemElementLabelProvider.java new file mode 100644 index 0000000..0832a78 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/provider/ProblemElementLabelProvider.java @@ -0,0 +1,77 @@ +package flintstones.method.todim.phase.gathering.provider; + +import javax.inject.Inject; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.ui.service.UiService; +import flintstones.model.ui.service.style.ForegroundStyler; + +public class ProblemElementLabelProvider extends LabelProvider implements IStyledLabelProvider { + + @Inject + IPhaseMethodService phaseService; + + /** The group image. */ + private final ImageDescriptor groupImage; + + /** The individual image. */ + private final ImageDescriptor individualImage; + + + /** + * Instantiates a new problem element name label provider. + * + * @param individualImage the individual image + * @param groupImage the group image + */ + public ProblemElementLabelProvider(ImageDescriptor individualImage, ImageDescriptor groupImage) { + this.groupImage = groupImage; + this.individualImage = individualImage; + } + + @Override + public StyledString getStyledText(Object element) { + if (element instanceof ProblemElement) { + ProblemElement pe = (ProblemElement) element; + StyledString styledString; + styledString = paint(pe.getName(), ""); + + return styledString; + } + return null; + } + + /* (non-Javadoc) + * + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ + @Override + public Image getImage(Object element) { + if (element instanceof ProblemElement) { + if (((ProblemElement) element).hasChildren()) + return this.groupImage.createImage(); + + return this.individualImage.createImage(); + } + + return super.getImage(element); + } + + private StyledString paint(String leftText, String rightText) { + + Color foregroundColorLeft = UiService.COLOR_FG_NORMAL; + Color foregroundColorRight = UiService.COLOR_FG_SECONDARY; + + StyledString leftT = new StyledString(leftText, new ForegroundStyler(foregroundColorLeft)); + StyledString rightT = new StyledString(rightText, new ForegroundStyler(foregroundColorRight)); + return leftT.append(" ") + .append(rightT); + } +} diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/TODIMPhaseUI.java b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/TODIMPhaseUI.java new file mode 100644 index 0000000..0350c04 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/TODIMPhaseUI.java @@ -0,0 +1,250 @@ +package flintstones.method.todim.phase.gathering.ui; + +import flintstones.application.perspective.framework.ui.interfaces.IProblemElementViewerOnSingleClick; +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewer; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.todim.phase.gathering.phaseTodim; +import flintstones.method.todim.phase.gathering.ui.messages.Messages; +import flintstones.method.todim.phase.gathering.viewer.ProblemElementViewerLabel; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; +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.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; + + +public class TODIMPhaseUI extends PhaseMethodUI implements IProblemElementViewerOnSingleClick, ICheckStateListener{ + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + @Inject + @Translation + Messages messages; + + phaseTodim todim; + + ProblemElementViewer criterionViewer; + String selectedCriterion; + + Label titleLabelParametersCriterion; + Spinner spinnerScale; + + double[] scale; + int selectedIndex; + + @Override + public void init() { + todim = (phaseTodim) this.getModel(); + todim.initialize(); + + scale = new double[todim.getCriteria().length]; + for(int i = 0; i < scale.length; i++) + scale[i] = 1.0f; + + selectedIndex = 0; + + selectedCriterion = problemService.getAll(Criterion.Type)[0].getCanonicalName(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 0, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText(messages.TODIM_phase); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + Composite row2 = new Composite(base, 0); + UiService.setGridData(row2, 9, 9, true, true); + UiService.setGridLayout(row2, 1); + + initBody(row2); + + titleLabelParametersCriterion.setText(messages.Thresholds_of + selectedCriterion); + + todim.executeMethod((Expert) problemService.getAll(Expert.Type)[0], scale); + } + + public void initBody(Composite base) { + //Primera mitad + Composite rowMitadArriba = new Composite(base, SWT.BORDER); + GridData gd = UiService.setGridData(rowMitadArriba, 9, 9, true, true); + gd.heightHint = 350; + UiService.setGridLayout(rowMitadArriba, 1); + + Expert expert = (Expert) problemService.getAll(Expert.Type)[0]; + tableInitialProblem(rowMitadArriba, + todim.getValuations(expert), + todim.getAlternativesNames(), + todim.getCriterionNames()); + + //La otra mitad + Composite rowMitadAbajo = new Composite(base, 0); + UiService.setGridData(rowMitadAbajo, 9, 9, true, true); + UiService.setGridLayout(rowMitadAbajo, 2); + + //Criterions y datos. + createColTreeView(rowMitadAbajo); + + createColParametersTodim(rowMitadAbajo); + + } + + public void tableInitialProblem(Composite base, double[][] values, String[] itemRow, String[] itemCol) { + String[][] matrix = new String[itemRow.length][itemCol.length]; + + for(int i = 0; i < values.length; i++) { + for (int j = 0; j < values[i].length; j++) { + matrix [i][j] = String.format("%.2f", values[i][j]); //$NON-NLS-1$ + } + } + + HtmlTextTable tableDelta = new HtmlTextTable(base, matrix, itemCol, itemRow); + tableDelta.render(); + } + + //Crea los botones y spinner para poder introducir los datos del problema + private void createColParametersTodim(Composite base) { + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + titleLabelParametersCriterion = new Label(row, SWT.NONE); + UiService.setGridData(titleLabelParametersCriterion, 9 ,9, true, false); + UiService.setFont(titleLabelParametersCriterion, UiService.FONT_SECTION_TITLE); + + Composite row1 = new Composite(row, SWT.BORDER); + UiService.setGridData(row1, 9, 9, true, true); + UiService.setGridLayout(row1, 1); + + //Scale + Composite rowLabelScale = new Composite(row1, 0); + UiService.setGridData(rowLabelScale, 9, 9, true, false); + UiService.setGridLayout(rowLabelScale, 1, true); + spinnerScale = new Spinner (rowLabelScale, SWT.BORDER); + spinnerScale.setDigits(3); + spinnerScale.setMinimum(1); + spinnerScale.setMaximum(Integer.MAX_VALUE); + spinnerScale.setSelection((int) (scale[0] * Math.pow(10, spinnerScale.getDigits()))); + spinnerScale.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + saveParameters(); + todim.executeMethod((Expert) problemService.getSubElements(Expert.Type)[0], scale); + } + }); + } + + //Métodos para el Tree View + private void createColTreeView(Composite base) { + + Composite row = new Composite(base, 0); + UiService.setGridData(row, 9, 9, true, true); + UiService.setGridLayout(row, 1); + + Label titleLabel = new Label(row, SWT.NONE); + titleLabel.setText(messages.Criteria); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + //Criterion tree + criterionViewer = getViewer(row, Criterion.Type, true); + } + + //Funión que nos devuelve el Viewer con los criterios + private ProblemElementViewer getViewer(Composite parent, String type, boolean addParent) { + + ProblemElementViewerLabel viewer = ContextInjectionFactory.make(ProblemElementViewerLabel.class, this.context); + + if (addParent) { + FakeProblemElement fakePE = new FakeProblemElement(""); //$NON-NLS-1$ + fakePE.as(type); + viewer.useGlobalParent(fakePE); + } + + viewer.createControls(type, parent); + viewer.addListener(this); + viewer.loadListeners(); + + UiService.setGridLayout(viewer.getTree().getTree(), 1); + UiService.setGridData(viewer.getTree().getTree(), 9, 9, true, true); + + return viewer; + } + + public void problemElementViewerOnSingleClick(ProblemElement item) { + + if(item.getCanonicalName().equals("")) //$NON-NLS-1$ + return; + + saveParameters(); + + selectedCriterion = item.getCanonicalName(); + titleLabelParametersCriterion.setText(messages.Thresholds_of + selectedCriterion); + + for(int i = 0; i < todim.getCriteria().length; i++) { + if( todim.getCriteria()[i].getCanonicalName().equals(selectedCriterion) ){ + selectedIndex = i; + break; + } + } + + setParametersSelected(); + + criterionViewer.updateViewer(Criterion.Type); + } + + private void setParametersSelected() { + double oldNumber = scale[selectedIndex]; + oldNumber *= Math.pow(10, spinnerScale.getDigits()); + int newNumberWithDecimal = (int) oldNumber; + spinnerScale.setSelection(newNumberWithDecimal); + } + + public void saveParameters() { + double scal = DoubleHelper.ParseDouble(spinnerScale.getText()); + scale[selectedIndex] = (float) scal; + } + + public void checkStateChanged(CheckStateChangedEvent event) { + refreshUI(); + } + + public void refreshUI() { + this.sendRefresh(); + } + + @Override + public void refresh() { + } + + @Override + public boolean isForwardEnabled() { + return true; + } +} diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/Messages.java b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/Messages.java new file mode 100644 index 0000000..52b47d5 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/Messages.java @@ -0,0 +1,10 @@ +package flintstones.method.todim.phase.gathering.ui.messages; + +public class Messages { + + public String Criteria; + public String Scale; + public String Thresholds_of; + public String TODIM_phase; + +} diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/messages.properties b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/messages.properties new file mode 100644 index 0000000..730a8ae --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/messages.properties @@ -0,0 +1,4 @@ +Criteria=Criteria +Scale=Scale: +Thresholds_of=Scale of +TODIM_phase=TODIM PHASE diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/messages_es.properties b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/messages_es.properties new file mode 100644 index 0000000..799ea7a --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/ui/messages/messages_es.properties @@ -0,0 +1,4 @@ +Criteria=Criterios +phaseTodimUI_Scale=Escala: +phaseTodimUI_Thresholds_of=Escala de +phaseTodimUI_TODIM_phase=Fase TODIM diff --git a/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/viewer/ProblemElementViewerLabel.java b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/viewer/ProblemElementViewerLabel.java new file mode 100644 index 0000000..b24d4f8 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering.ui/src/flintstones/method/todim/phase/gathering/viewer/ProblemElementViewerLabel.java @@ -0,0 +1,35 @@ +package flintstones.method.todim.phase.gathering.viewer; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; + +import flintstones.application.perspective.framework.ui.viewer.ProblemElementViewer; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.method.todim.phase.gathering.provider.ProblemElementLabelProvider; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.ui.service.UiService; + +public class ProblemElementViewerLabel extends ProblemElementViewer { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + @Override + protected IStyledLabelProvider getLabelProvider(String type) { + + ImageDescriptor individualImage = UiService.getIcon(ProblemElementHelper.getImage(type, false)); + ImageDescriptor groupImage = UiService.getIcon(ProblemElementHelper.getImage(type, true)); + + ProblemElementLabelProvider provider = new ProblemElementLabelProvider(individualImage, groupImage); + ContextInjectionFactory.inject(provider, context); + return provider; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.todim.phase.gathering/.classpath b/bundles/flintstones.method.todim.phase.gathering/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.todim.phase.gathering/.polyglot.META-INF b/bundles/flintstones.method.todim.phase.gathering/.polyglot.META-INF new file mode 100644 index 0000000..e4e6da7 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.todim.phase.gathering + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Gathering + diff --git a/bundles/flintstones.method.todim.phase.gathering/.project b/bundles/flintstones.method.todim.phase.gathering/.project new file mode 100644 index 0000000..7441245 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/.project @@ -0,0 +1,45 @@ + + + flintstones.method.todim.phase.gathering + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362699 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.todim.phase.gathering/META-INF/MANIFEST.MF b/bundles/flintstones.method.todim.phase.gathering/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a82749f --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Gathering +Bundle-SymbolicName: flintstones.method.todim.phase.gathering;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.todim.phase.gathering +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.contexts, + flintstones.valuation, + flintstones.model.problemelement.service, + flintstones.entity.problemelement, + flintstones.valuation.numeric, + flintstones.helper.ui, + flintstones.entity.method.phase, + javax.inject, + flintstones.model.valuation.service, + flintstones.model.domain.service, + flintstones.entity.valuation, + flintstones.helper.data +Export-Package: flintstones.method.todim.phase.gathering diff --git a/bundles/flintstones.method.todim.phase.gathering/build.properties b/bundles/flintstones.method.todim.phase.gathering/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.todim.phase.gathering/plugin.xml b/bundles/flintstones.method.todim.phase.gathering/plugin.xml new file mode 100644 index 0000000..67308bb --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.todim.phase.gathering/src/flintstones/method/todim/phase/gathering/phaseTodim.java b/bundles/flintstones.method.todim.phase.gathering/src/flintstones/method/todim/phase/gathering/phaseTodim.java new file mode 100644 index 0000000..191fdf7 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.gathering/src/flintstones/method/todim/phase/gathering/phaseTodim.java @@ -0,0 +1,191 @@ +package flintstones.method.todim.phase.gathering; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.numeric.NumericValuation; + +public class phaseTodim extends PhaseMethod { + + @Inject + IEclipseContext context; + + @Inject + IValuationService valuationService; + + @Inject + IDomainService domainService; + + @Inject + IProblemElementService problemService; + + // Atributos + HashMap mapVAluations; + HashMatrix hmWeights; + Alternative[] allAlternatives; + Criterion[] allCriterion; + Expert[] allexperts; + + double[][] initialMatrix; + double[][] normalizeMatrix; + double[] weights; + double[] relativeWeights; + double[] scaleNormalization; + + double maxWeight; + double totalRelativeWeight; + + public phaseTodim() { + } + + @Override + public String getName() { + return "TODIM"; + } + + @SuppressWarnings("unchecked") + public void initialize() { + ProblemElement[] pes = problemService.getAll(Alternative.Type); + allAlternatives = ProblemElementHelper.asAlternatives(pes); + + pes = problemService.getAll(Criterion.Type); + allCriterion = ProblemElementHelper.asCriterions(pes); + + pes = problemService.getAll(Expert.Type); + allexperts = ProblemElementHelper.asExperts(pes); + + hmWeights = (HashMatrix) this.importData("criterionWeights"); + + this.weights = getWeights(); + } + + public Criterion[] getCriteria() { + return this.allCriterion; + } + + public Alternative[] getAlternatives() { + return this.allAlternatives; + } + + public String[] getAlternativesNames() { + String[] str = new String[allAlternatives.length]; + + for (int i = 0; i < allAlternatives.length; i++) + str[i] = allAlternatives[i].getCanonicalName(); + + return str; + } + + public String[] getCriterionNames() { + String[] str = new String[allCriterion.length]; + + for (int i = 0; i < allCriterion.length; i++) + str[i] = allCriterion[i].getCanonicalName(); + + return str; + } + + public void executeMethod(Expert e, double[] scaleNormalization) { + this.scaleNormalization = scaleNormalization; + + this.initialMatrix = this.getValuations(e); + + normalize(); + + getRelativeWeight(); + + // exportamos los datos a la ventana de resultados. + this.exportData("normalizeMatrix", normalizeMatrix); + this.exportData("relativeWeights", relativeWeights); + this.exportData("maxWeight", maxWeight); + this.exportData("totalRelativeWeight", totalRelativeWeight); + + } + + public HashMap getMapValuations(Expert e) { + ProblemElement pE = problemService.getByCanonicalName(Expert.Type, e.getCanonicalName()); + mapVAluations = valuationService.getAllValuationsKVWith(pE); + return mapVAluations; + } + + public double[][] getValuations(Expert e) { + + double[][] valuation = new double[allAlternatives.length][allCriterion.length]; + + ProblemElement pE = problemService.getByCanonicalName(Expert.Type, e.getCanonicalName()); + mapVAluations = valuationService.getAllValuationsKVWith(pE); + + int a = 0, b = 0; + for (Entry entry : mapVAluations.entrySet()) { + NumericValuation nV = (NumericValuation) entry.getValue(); + + for (int i = 0; i < allAlternatives.length; i++) + if (entry.getKey().getAlternative().getId().equals(allAlternatives[i].getId())) { + a = i; + break; + } + + for (int i = 0; i < allCriterion.length; i++) + if (entry.getKey().getCriterion().getId().equals(allCriterion[i].getId())) { + b = i; + break; + } + + valuation[a][b] = Double.valueOf(nV.getValue()); + a = 0; + b = 0; + } + + return valuation; + } + + private double[] getWeights() { + double[] ws = new double[allCriterion.length]; + double w; + + for (int i = 0; i < allCriterion.length; i++) { + w = hmWeights.get(allexperts[0], allCriterion[i]); + ws[i] = w; + } + + return ws; + } + + private void normalize() { + normalizeMatrix = new double[allAlternatives.length][allCriterion.length]; + for (int i = 0; i < initialMatrix.length; i++) + for (int j = 0; j < initialMatrix[i].length; j++) + normalizeMatrix[i][j] = initialMatrix[i][j] / scaleNormalization[j]; + } + + private void getRelativeWeight() { + + maxWeight = Arrays.stream(weights).max().getAsDouble(); + + relativeWeights = new double[allCriterion.length]; + for (int i = 0; i < relativeWeights.length; i++) + relativeWeights[i] = weights[i] / maxWeight; + + + totalRelativeWeight = 0.0f; + for (int i = 0; i < relativeWeights.length; i++) + totalRelativeWeight += relativeWeights[i]; + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.todim.phase.result.ui/.classpath b/bundles/flintstones.method.todim.phase.result.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.todim.phase.result.ui/.polyglot.META-INF b/bundles/flintstones.method.todim.phase.result.ui/.polyglot.META-INF new file mode 100644 index 0000000..5cd734f --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.todim.phase.result.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.todim.phase.result.ui/.project b/bundles/flintstones.method.todim.phase.result.ui/.project new file mode 100644 index 0000000..be6c6b7 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.todim.phase.result.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362701 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.todim.phase.result.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.todim.phase.result.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f82bd0d --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: flintstones.method.todim.phase.result.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.todim.phase.result.ui +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.ui, + org.eclipse.e4.core.contexts, + flintstones.method.todim.phase.result, + flintstones.helper.html, + javax.inject, + flintstones.helper.data, + flintstones.entity.method.phase.ui, + flintstones.model.ui.service, + flintstones.entity.method.phase, + org.jfree.chart.jfreechart, + org.eclipse.e4.core.services, + flintstones.entity.problemelement diff --git a/bundles/flintstones.method.todim.phase.result.ui/build.properties b/bundles/flintstones.method.todim.phase.result.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.todim.phase.result.ui/plugin.xml b/bundles/flintstones.method.todim.phase.result.ui/plugin.xml new file mode 100644 index 0000000..a64b970 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/TODIMResultUI.java b/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/TODIMResultUI.java new file mode 100644 index 0000000..e9e34a4 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/TODIMResultUI.java @@ -0,0 +1,303 @@ +package flintstones.method.todim.phase.result.ui; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +import org.jfree.chart.swt.ChartComposite; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.data.Pair; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.todim.phase.result.TODIMResult; +import flintstones.method.todim.phase.result.ui.messages.Messages; +import flintstones.model.ui.service.UiService; + +public class TODIMResultUI extends PhaseMethodUI { + + @Inject + IEclipseContext context; + + @Inject + @Translation + Messages messages; + + TODIMResult model; + + Spinner spinnerTheta; + + Composite rowMitadArriba; + Composite rowMitadAbajo; + ChartComposite chartComposite; + + HtmlTextTable tablePhi; + HtmlTextTable tableDelta; + HtmlTextTable tableFinalRanking; + + @Override + public void init() { + + model = (TODIMResult) this.getModel(); + model.loadData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite row1 = new Composite(base, 0); + UiService.setGridData(row1, 9, 0, true, false); + UiService.setGridLayout(row1, 1); + + Label titleLabel = new Label(row1, SWT.NONE); + titleLabel.setText(messages.TODIM_result); + UiService.setGridData(titleLabel, 9 ,9, true, false); + UiService.setFont(titleLabel, UiService.FONT_SECTION_TITLE); + + model.calculateData(1.0f); + + Composite row2 = new Composite(row1, SWT.BORDER); + GridData gd = UiService.setGridData(row2, 9, 9, true, true); + gd.heightHint = 250; + UiService.setGridLayout(row2, 1); + + tableInitialProblem(row2, + model.getNormalizedMatrix(), + model.getAlternativesNames(), + model.getCriterionNames()); + + Composite row3 = new Composite(row1, 0); + UiService.setGridData(row3, 9, 9, true, true); + UiService.setGridLayout(row3, 1); + + initSpinner(row3); + + Composite rowLabel = new Composite(base, 0); + UiService.setGridData(rowLabel, 9, 9, true, false); + UiService.setGridLayout(rowLabel, 3, true); + + Label titleAsc = new Label(rowLabel, SWT.NONE); + titleAsc.setText(messages.Phi_table); + UiService.setGridData(titleAsc, 0 ,9, true, false); + UiService.setFont(titleAsc, UiService.FONT_SECTION_TITLE); + + Label titleDes = new Label(rowLabel, SWT.NONE); + titleDes.setText(messages.Delta_table); + UiService.setGridData(titleDes, 0 ,9, true, false); + UiService.setFont(titleDes, UiService.FONT_SECTION_TITLE); + + Label titleRanking = new Label(rowLabel, SWT.NONE); + titleRanking.setText(messages.Ranking); + UiService.setGridData(titleRanking, 0 ,9, true, false); + UiService.setFont(titleRanking, UiService.FONT_SECTION_TITLE); + + Composite rowBody = new Composite(base, 0); + UiService.setGridData(rowBody, 9, 9, true, true); + UiService.setGridLayout(rowBody, 1); + + initBody(rowBody); + } + + public void tableInitialProblem(Composite base, double[][] values, String[] itemRow, String[] itemCol) { + String[][] matrix = new String[itemRow.length][itemCol.length]; + + for(int i = 0; i < values.length; i++) { + for (int j = 0; j < values[i].length; j++) { + matrix [i][j] = String.format("%.2f", values[i][j]); //$NON-NLS-1$ + } + } + + HtmlTextTable tableDelta = new HtmlTextTable(base, matrix, itemCol, itemRow); + tableDelta.render(); + } + + public void initSpinner(Composite base) { + Composite row = new Composite(base, 0); + UiService.setGridData(row, 0, 9, true, true); + UiService.setGridLayout(row, 1); + + Composite rowLabelTheta = new Composite(row, 0); + UiService.setGridData(rowLabelTheta, 9, 9, true, false); + UiService.setGridLayout(rowLabelTheta, 2, false); + Label labelTheta = new Label (rowLabelTheta, SWT.NONE); + labelTheta.setText("Theta"); //$NON-NLS-1$ + + spinnerTheta = new Spinner (rowLabelTheta, SWT.BORDER); + spinnerTheta.setDigits(2); + spinnerTheta.setMinimum(Integer.MIN_VALUE); + spinnerTheta.setMaximum(Integer.MAX_VALUE); + spinnerTheta.setSelection(100); + spinnerTheta.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + Spinner th = (Spinner) e.getSource(); + + String thetaText = th.getText(); + if(thetaText != null) + if(!thetaText.equals("")) //$NON-NLS-1$ + refreshTable(); + + } + }); + } + + public void initBody(Composite base) { + rowMitadArriba = new Composite(base, 0); + UiService.setGridData(rowMitadArriba, 9, 9, true, true); + UiService.setGridLayout(rowMitadArriba, 3); + + rowTablesPhiDelta(rowMitadArriba); + } + + public void rowTablesPhiDelta(Composite base) { + Composite compPhi = new Composite(base, 0); + UiService.setGridData(compPhi, 9, 9, true, true); + UiService.setGridLayout(compPhi, 1); + + tablePhi(compPhi, model.getPhiMatrix(), model.getPairAlternativesNames(), model.getCriterionNames()); + + Composite compDelta = new Composite(base, 0); + UiService.setGridData(compDelta, 9, 9, true, true); + UiService.setGridLayout(compDelta, 1); + + tableDelta(compDelta, model.getDeltaMatrix(), model.getPairAlternativesNames()); + + Composite compRanking = new Composite(base, 0); + UiService.setGridData(compRanking, 9, 9, true, true); + UiService.setGridLayout(compRanking, 1); + + tableRanking(compRanking, model.getEtaRanking()); + + } + + public void tablePhi(Composite base, LinkedHashMap, Double>>> values, + String[] itemRow, String[] itemCol) { + + List alternatives = Arrays.asList(model.getAlternatives()); + List criteria = Arrays.asList(model.getCriteria()); + + String[][] matrix = new String[itemRow.length][itemCol.length]; + + List, Double>> pairs; + + int n, cont; + for(ProblemElement crit: criteria) { + + n = criteria.indexOf(crit); + + cont = 0; + + for(ProblemElement alt_i: alternatives) { + + for(ProblemElement alt_k: alternatives) { + + if(!alt_i.getId().equals(alt_k.getId())) { + + pairs = values.get(crit); + + for(LinkedHashMap, Double> pair: pairs) { + + if(pair.containsKey(new Pair(alt_i, alt_k))) { + + matrix[cont][n] = Double.toString(Math.round( + pair.get(new Pair(alt_i, alt_k)) * 1000d) / 1000d); //$NON-NLS-1 + + break; + } + } + + cont++; + } + } + } + } + + tablePhi = new HtmlTextTable(base, matrix, itemCol, itemRow); + tablePhi.render(); + } + + public void tableDelta(Composite base, LinkedHashMap, Double> values, String[] itemRow) { + + ProblemElement[] alternatives = model.getAlternatives(); + + String[][] matrix = new String[itemRow.length][1]; + String[] itemCol = {"Delta"}; //$NON-NLS-1$ + + int cont = 0; + for(ProblemElement alt_i: alternatives) { + + for(ProblemElement alt_k: alternatives) { + + if(!alt_i.getId().equals(alt_k.getId())) { + + matrix[cont][0] = Double.toString(Math.round(values.get(new Pair(alt_i, alt_k))* 1000d) / 1000d); //$NON-NLS-1$ + + cont++; + } + } + } + + tableDelta = new HtmlTextTable(base, matrix, itemCol, itemRow); + tableDelta.render(); + } + + public void tableRanking(Composite base, LinkedHashMap etaRanking) { + String[] rankingNames = new String [etaRanking.size()]; + String[] rankingNumber = new String [etaRanking.size()]; + + int rank = 0; + for(ProblemElement alt: etaRanking.keySet()) { + rankingNames[rank] = alt.getCanonicalName(); + rankingNumber[rank] = Double.toString(Math.round(etaRanking.get(alt) * 1000d) / 1000d); + rank++; + } + + tableFinalRanking = new HtmlTextTable(base, rankingNames, rankingNumber, true); + tableFinalRanking.render(); + } + + @Override + public void refresh() { + refreshTable(); + this.sendRefresh(); + } + + public void refreshTable() { + + if(rowMitadArriba == null) return; + + model.loadData(); + + Arrays.stream(rowMitadArriba.getChildren()).forEach(k -> k.dispose()); + + String theta = spinnerTheta.getText(); + theta = theta.replaceAll(",", "."); + model.calculateData(Float.parseFloat(theta)); + + //todimR.calculateSensitiveData(thetaNumber, 11); + + rowTablesPhiDelta(rowMitadArriba); + + tablePhi.render(); + tableDelta.render(); + tableFinalRanking.render(); + rowMitadArriba.layout(); + } + + @Override + public boolean isForwardEnabled() { + return false; + } + +} diff --git a/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/Messages.java b/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/Messages.java new file mode 100644 index 0000000..e96d781 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.todim.phase.result.ui.messages; + +public class Messages { + + public String Delta_table; + public String Phi_table; + public String Ranking; + public String TODIM_result; +} diff --git a/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/messages.properties b/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/messages.properties new file mode 100644 index 0000000..7f610ed --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/messages.properties @@ -0,0 +1,4 @@ +Delta_table=Delta table +Phi_table=Phi table +Ranking=Ranking +TODIM_result=TODIM Result diff --git a/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/messages_es.properties b/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/messages_es.properties new file mode 100644 index 0000000..a3f013c --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result.ui/src/flintstones/method/todim/phase/result/ui/messages/messages_es.properties @@ -0,0 +1,4 @@ +Delta_table=Tabla delta +Phi_table=Tabla Phi +Ranking=Ranking +TODIM_result=Resultados TODIM diff --git a/bundles/flintstones.method.todim.phase.result/.classpath b/bundles/flintstones.method.todim.phase.result/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.todim.phase.result/.polyglot.META-INF b/bundles/flintstones.method.todim.phase.result/.polyglot.META-INF new file mode 100644 index 0000000..0122158 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.todim.phase.result + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Result + diff --git a/bundles/flintstones.method.todim.phase.result/.project b/bundles/flintstones.method.todim.phase.result/.project new file mode 100644 index 0000000..9b2938e --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/.project @@ -0,0 +1,45 @@ + + + flintstones.method.todim.phase.result + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362701 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.todim.phase.result/META-INF/MANIFEST.MF b/bundles/flintstones.method.todim.phase.result/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1f36b57 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Result +Bundle-SymbolicName: flintstones.method.todim.phase.result;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.todim.phase.result +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.contexts, + flintstones.model.problemelement.service, + flintstones.entity.problemelement, + flintstones.model.domain.service, + javax.inject, + flintstones.entity.method.phase, + flintstones.helper.data +Export-Package: flintstones.method.todim.phase.result diff --git a/bundles/flintstones.method.todim.phase.result/build.properties b/bundles/flintstones.method.todim.phase.result/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.todim.phase.result/plugin.xml b/bundles/flintstones.method.todim.phase.result/plugin.xml new file mode 100644 index 0000000..8979be2 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.todim.phase.result/src/flintstones/method/todim/phase/result/TODIMResult.java b/bundles/flintstones.method.todim.phase.result/src/flintstones/method/todim/phase/result/TODIMResult.java new file mode 100644 index 0000000..d79c882 --- /dev/null +++ b/bundles/flintstones.method.todim.phase.result/src/flintstones/method/todim/phase/result/TODIMResult.java @@ -0,0 +1,300 @@ +package flintstones.method.todim.phase.result; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.helper.data.Pair; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; + +public class TODIMResult extends PhaseMethod { + + @Inject + IEclipseContext context; + + @Inject + IDomainService domainService; + + @Inject + IProblemElementService problemService; + + Alternative[] allAlternatives; + Criterion[] allCriteria; + Expert[] allexperts; + + double[][] normalizeMatrix; + + double maxWeight; + double totalRelativeWeight; + double[] relativeWeights; + + String[] pairAlternatives; + + LinkedHashMap, Double>>> phiMatrix; + LinkedHashMap, Double> deltaMatrix; + LinkedHashMap etaRanking; + + double deltaSumMax; + double deltaSumMin; + + float theta; + + ArrayList< float[] > sensitiveData; + + + public TODIMResult() { + } + + @Override + public String getName() { + return "TODIM Result"; + } + + //------------------------------- GETS AND SETTERS --------------------------------- + public void loadData() { + ProblemElement[] pes = problemService.getAll(Alternative.Type); + allAlternatives = ProblemElementHelper.asAlternatives(pes); + + pes = problemService.getAll(Criterion.Type); + allCriteria = ProblemElementHelper.asCriterions(pes); + + pes = problemService.getAll(Expert.Type); + allexperts = ProblemElementHelper.asExperts(pes); + + normalizeMatrix = (double[][]) this.importData("normalizeMatrix"); + relativeWeights = (double[]) this.importData("relativeWeights"); + totalRelativeWeight = (double) this.importData("totalRelativeWeight"); + + pairAlternatives = new String[allAlternatives.length * (allAlternatives.length - 1)]; + + int cont = 0; + for(int i = 0; i < allAlternatives.length; ++i) { + for(int j = 0; j < allAlternatives.length; ++j) { + if(i != j) { + pairAlternatives[cont] = allAlternatives[i].getCanonicalName() + " > " + allAlternatives[j].getCanonicalName(); + cont++; + } + } + } + } + + public double[][] getNormalizedMatrix() { + return normalizeMatrix; + } + + public LinkedHashMap, Double>>> getPhiMatrix(){ + return phiMatrix; + } + + public LinkedHashMap, Double> getDeltaMatrix(){ + return deltaMatrix; + } + + public LinkedHashMap getEtaRanking() { + return etaRanking; + } + + public ProblemElement[] getAlternatives() { + return allAlternatives; + } + + public ProblemElement[] getCriteria() { + return allCriteria; + } + + public String[] getPairAlternativesNames() { + return pairAlternatives; + } + + public String[] getAlternativesNames() { + String[] str = new String[allAlternatives.length]; + + for(int i = 0; i < allAlternatives.length; i++) + str[i] = allAlternatives[i].getCanonicalName(); + + + return str; + } + + public String[] getCriterionNames() { + String[] str = new String[allCriteria.length]; + + for(int i = 0; i < allCriteria.length; i++) + str[i] = allCriteria[i].getCanonicalName(); + + + return str; + } + + public ArrayList getSensitiveData() { + return this.sensitiveData; + } + + public void calculateData(float thetaNumber) { + theta = thetaNumber; + + calculatePhi(); + calculateDelta(); + calculateOverallDominance(); + } + + /*public void calculateSensitiveData(float thetaNumber, int repetitions) { + sensitiveData = new ArrayList(); + float n = thetaNumber / repetitions; + + for(float t = 0; t < thetaNumber; t += n) { + theta = t; + calculatePhi(); + calculateDelta(); + calculateOverallDominance(); + + sensitiveData.add(this.etaRanking); + } + }*/ + + private void calculatePhi() { + phiMatrix = new LinkedHashMap, Double>>>(); + + double x_in, x_kn; + + List, Double>> pairs = new ArrayList<>(); + LinkedHashMap, Double> pairAlternatives = new LinkedHashMap<>(); + + for(int n = 0; n < allCriteria.length; n++) { + + pairs = new ArrayList<>(); + + for(int i = 0; i < allAlternatives.length; i++ ) { + + for(int k = 0; k < allAlternatives.length; k++ ) { + + if(i != k) { + + pairAlternatives = new LinkedHashMap<>(); + + x_in = normalizeMatrix[i][n]; + x_kn = normalizeMatrix[k][n]; + + if(x_in - x_kn < 0) //losses + pairAlternatives.put(new Pair(allAlternatives[i], allAlternatives[k]), + (-1 / theta) * (Math.sqrt( Math.abs((x_kn - x_in)) * totalRelativeWeight / relativeWeights[n]))); + else //gains + pairAlternatives.put(new Pair(allAlternatives[i], allAlternatives[k]), + Math.sqrt( (x_in - x_kn) * relativeWeights[n] / totalRelativeWeight)); + + pairs.add(pairAlternatives); + + } + + phiMatrix.put(allCriteria[n], pairs); + } + } + } + } + + private void calculateDelta() { + deltaMatrix = new LinkedHashMap, Double>(); + + double acum; + for(ProblemElement i: allAlternatives) { + + for(ProblemElement k: allAlternatives) { + + acum = 0; + + if(!i.getId().equals(k.getId())) { + + for(ProblemElement n: allCriteria) { + + List, Double>> pairsCriterion = phiMatrix.get(n); + + for(LinkedHashMap, Double> pair: pairsCriterion) { + + if(pair.containsKey(new Pair(i, k))) { + acum += pair.get(new Pair(i, k)); + break; + } + + } + + } + + deltaMatrix.put(new Pair(i, k), acum); + } + } + } + } + + private void calculateOverallDominance() { + LinkedHashMap disorderedEtaRanking = new LinkedHashMap(); + + computeDeltaSumAlternatives(); + + for(ProblemElement alt: allAlternatives) + disorderedEtaRanking.put(alt, (computeDeltaSumAlternative(alt) - deltaSumMin) / (deltaSumMax - deltaSumMin)); + + etaRanking = disorderedEtaRanking + .entrySet() + .stream() + .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (e1, e2) -> e2, + LinkedHashMap::new)); + } + + private void computeDeltaSumAlternatives() { + + double[] dominanceDegrees = new double[allAlternatives.length]; + double acum; + + int cont = 0; + for(ProblemElement i: allAlternatives) { + + acum = 0; + + for(ProblemElement k: allAlternatives) { + + if(!i.getId().equals(k.getId())) + + acum += deltaMatrix.get(new Pair(i, k)); + + } + + dominanceDegrees[cont] = acum; + + cont++; + } + + deltaSumMax = Arrays.stream(dominanceDegrees).max().getAsDouble(); + deltaSumMin = Arrays.stream(dominanceDegrees).min().getAsDouble(); + } + + + private double computeDeltaSumAlternative(ProblemElement alt) { + + double acum = 0; + + for(ProblemElement k: allAlternatives) { + + if(!alt.getId().equals(k.getId())) + + acum += deltaMatrix.get(new Pair(alt, k)); + } + + return acum; + } +} diff --git a/bundles/flintstones.method.todim/.classpath b/bundles/flintstones.method.todim/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.todim/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.todim/.polyglot.META-INF b/bundles/flintstones.method.todim/.polyglot.META-INF new file mode 100644 index 0000000..8b1ec88 --- /dev/null +++ b/bundles/flintstones.method.todim/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.todim + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] TODIM + diff --git a/bundles/flintstones.method.todim/.project b/bundles/flintstones.method.todim/.project new file mode 100644 index 0000000..27120a9 --- /dev/null +++ b/bundles/flintstones.method.todim/.project @@ -0,0 +1,45 @@ + + + flintstones.method.todim + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362698 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.todim/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.todim/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.todim/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.todim/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.todim/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.todim/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.todim/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.todim/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.todim/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.todim/META-INF/MANIFEST.MF b/bundles/flintstones.method.todim/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5cf2f41 --- /dev/null +++ b/bundles/flintstones.method.todim/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.todim;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.todim +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.numeric diff --git a/bundles/flintstones.method.todim/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.todim/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..23953c2 --- /dev/null +++ b/bundles/flintstones.method.todim/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.todim +Bundle-Name = TODIM \ No newline at end of file diff --git a/bundles/flintstones.method.todim/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.todim/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..23953c2 --- /dev/null +++ b/bundles/flintstones.method.todim/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.todim +Bundle-Name = TODIM \ No newline at end of file diff --git a/bundles/flintstones.method.todim/build.properties b/bundles/flintstones.method.todim/build.properties new file mode 100644 index 0000000..3e5f9ad --- /dev/null +++ b/bundles/flintstones.method.todim/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/ diff --git a/bundles/flintstones.method.todim/plugin.xml b/bundles/flintstones.method.todim/plugin.xml new file mode 100644 index 0000000..2544a32 --- /dev/null +++ b/bundles/flintstones.method.todim/plugin.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.todim/problem/TODIM.flintstones b/bundles/flintstones.method.todim/problem/TODIM.flintstones new file mode 100644 index 0000000..88c0a70 --- /dev/null +++ b/bundles/flintstones.method.todim/problem/TODIM.flintstones @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/Messages.java b/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/Messages.java new file mode 100644 index 0000000..1bec2fc --- /dev/null +++ b/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/Messages.java @@ -0,0 +1,12 @@ +package flintstones.method.todim.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String method_name; + +} + diff --git a/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/messages.properties b/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/messages.properties new file mode 100644 index 0000000..01d8d91 --- /dev/null +++ b/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/messages.properties @@ -0,0 +1 @@ +method_name=Interactive and Multicriteria Decision Making (TODIM) diff --git a/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/messages_es.properties b/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/messages_es.properties new file mode 100644 index 0000000..fd02b71 --- /dev/null +++ b/bundles/flintstones.method.todim/src/flintstones/method/todim/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Mtodo de toma de decisin multicriterio interactivo (TODIM) diff --git a/bundles/flintstones.method.todim/src/flintstones/method/todim/todimMethod.java b/bundles/flintstones.method.todim/src/flintstones/method/todim/todimMethod.java new file mode 100644 index 0000000..e1bbe7a --- /dev/null +++ b/bundles/flintstones.method.todim/src/flintstones/method/todim/todimMethod.java @@ -0,0 +1,41 @@ +package flintstones.method.todim; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.todim.messages.Messages; +import flintstones.valuation.numeric.NumericValuation; + +public class todimMethod extends ValidatedMethod { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.method_name; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, NumericValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .custom(valuationTypeOperator) + .named("valuations");//$NON-NLS-1$ + + } +} diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.classpath b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.polyglot.META-INF b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.polyglot.META-INF new file mode 100644 index 0000000..d79b4d7 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.topsisFuzzy.phase.results.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.project b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.project new file mode 100644 index 0000000..c99b0bc --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.topsisFuzzy.phase.results.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362705 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a8d80bd --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.topsisFuzzy.phase.results.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.topsisFuzzy.phase.results.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.method.topsisFuzzy.phase.results, + flintstones.entity.method.phase, + org.eclipse.swt, + flintstones.model.ui.service, + org.eclipse.e4.core.services, + javax.inject, + flintstones.helper.html, + flintstones.engine.R, + flintstones.entity.problemelement diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/build.properties b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/plugin.xml b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/plugin.xml new file mode 100644 index 0000000..10d45e3 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/TOPSISFuzzyResultsUI.java b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/TOPSISFuzzyResultsUI.java new file mode 100644 index 0000000..2b42746 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/TOPSISFuzzyResultsUI.java @@ -0,0 +1,156 @@ +package flintstones.method.topsisFuzzy.phase.results.ui; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.RVector; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.topsisFuzzy.phase.results.TOPSISFuzzyResults; +import flintstones.method.topsisFuzzy.phase.results.ui.messages.Messages; +import flintstones.model.ui.service.UiService; +import javax.inject.Inject; + +/** + * User interface for FuzzyTOPSIS results phase + * + * @author jcfer + * + */ +public class TOPSISFuzzyResultsUI extends PhaseMethodUI { + + @Inject + @Translation + Messages msg; + + /** + * Phase model implementation + */ + TOPSISFuzzyResults model; + + /** + * Results table + */ + HtmlTextTable results; + + /** + * Type selector + */ + Combo topSelector; + + @Override + public void init() { + model = (TOPSISFuzzyResults) this.getModel(); + model.loadData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 0, 0, true, true); + UiService.setGridLayout(base, 1); + +//<---- TOP ROW COMPOSITE ----> + Composite topRow = new Composite(base, SWT.BORDER); + UiService.setGridData(topRow, 0, 1, true, true); + UiService.setGridLayout(topRow, 2); + + Label infoTopSelector = new Label(topRow, SWT.NONE); + infoTopSelector.setText(msg.selector_info); + + topSelector = new Combo(topRow, SWT.NONE); + for (String norm : msg.norm_types.split(",")) { + topSelector.add(norm); + } + +//<---- LOWER ROW COMPOSITE ----> + Composite lowRow = new Composite(base, SWT.NONE); + UiService.setGridData(lowRow, 9, 9, true, true); + UiService.setGridLayout(lowRow, 1); + + topSelector.addModifyListener(new ModifyListener() { + /** + * On type selection + */ + @Override + public void modifyText(ModifyEvent e) { + createResultTable(lowRow); + } + }); + + } + + /** + * Creates method results table + * + * @param base Composite + */ + private void createResultTable(Composite base) { + REXP rexp = model.executeR(topSelector.getSelectionIndex() == 0); + + int[] alts = (int[]) ((REXP) ((RVector) rexp.getContent()).get(0)).getContent(); + String[] rHeaders = new String[alts.length]; + for (int a = 0; a < alts.length; a++) { + rHeaders[a] = model.allAlternatives()[alts[a] - 1].getName(); + } + + String[] cHeaders; + String[][] values; + // Makes table data based on type selected (same as R-gui result table) + if (topSelector.getSelectionIndex() == 0) { + double[] r_vals = (double[]) ((REXP) ((RVector) rexp.getContent()).get(1)).getContent(); + int[] ranks = (int[]) ((REXP) ((RVector) rexp.getContent()).get(2)).getContent(); + + cHeaders = msg.headers_linear.split(","); + + values = new String[alts.length][cHeaders.length]; + for (int r = 0; r < alts.length; r++) { + values[r][0] = Double.toString(r_vals[r]); + values[r][1] = Integer.toString(ranks[r]); + } + } else { + double[] r1 = (double[]) ((REXP) ((RVector) rexp.getContent()).get(1)).getContent(); + double[] r2 = (double[]) ((REXP) ((RVector) rexp.getContent()).get(2)).getContent(); + double[] r3 = (double[]) ((REXP) ((RVector) rexp.getContent()).get(3)).getContent(); + double[] defR = (double[]) ((REXP) ((RVector) rexp.getContent()).get(4)).getContent(); + int[] ranks = (int[]) ((REXP) ((RVector) rexp.getContent()).get(5)).getContent(); + + cHeaders = msg.headers_vector.split(","); + + values = new String[alts.length][cHeaders.length]; + for (int r = 0; r < alts.length; r++) { + values[r][0] = Double.toString(r1[r]); + values[r][1] = Double.toString(r2[r]); + values[r][2] = Double.toString(r3[r]); + values[r][3] = Double.toString(defR[r]); + values[r][4] = Double.toString(ranks[r]); + } + } + + if (results != null) { + results.dispose(); + } + results = new HtmlTextTable(base, values, cHeaders, rHeaders); + results.render(); + } + + /** + * Reloads phase view + */ + @Override + public void refresh() { + sendRefresh(); + } + + /** + * @return false, last phase + */ + @Override + protected boolean isForwardEnabled() { + return true; + } + +} diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/Messages.java b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/Messages.java new file mode 100644 index 0000000..f926544 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/Messages.java @@ -0,0 +1,11 @@ +package flintstones.method.topsisFuzzy.phase.results.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String selector_info; + public String norm_types; + public String headers_linear; + public String headers_vector; +} diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/messages.properties b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/messages.properties new file mode 100644 index 0000000..974dee8 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/messages.properties @@ -0,0 +1,4 @@ +selector_info=Select normalization method: +norm_types=Linear,Vector +headers_linear=R, Ranking +headers_vector=R.1, R.2, R.3, Def_R, Ranking \ No newline at end of file diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/messages_es.properties b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/messages_es.properties new file mode 100644 index 0000000..a8265bd --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results.ui/src/flintstones/method/topsisFuzzy/phase/results/ui/messages/messages_es.properties @@ -0,0 +1,4 @@ +selector_info=Seleccionar mtodo de normalizacin: +norm_types=Lineal,Vector +headers_linear=R, Clasificacin +headers_vector=R.1, R.2, R.3, Def_R, Clasificacin \ No newline at end of file diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/.classpath b/bundles/flintstones.method.topsisFuzzy.phase.results/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/.polyglot.META-INF b/bundles/flintstones.method.topsisFuzzy.phase.results/.polyglot.META-INF new file mode 100644 index 0000000..0fa70b7 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.topsisFuzzy.phase.results + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/.project b/bundles/flintstones.method.topsisFuzzy.phase.results/.project new file mode 100644 index 0000000..dcb6801 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/.project @@ -0,0 +1,45 @@ + + + flintstones.method.topsisFuzzy.phase.results + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362702 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/META-INF/MANIFEST.MF b/bundles/flintstones.method.topsisFuzzy.phase.results/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0796e3a --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.topsisFuzzy.phase.results;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.topsisFuzzy.phase.results +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase, + org.eclipse.e4.core.services, + javax.inject, + flintstones.engine.R, + flintstones.model.problemelement.service, + flintstones.helper.data, + flintstones.domain.fuzzyset +Export-Package: flintstones.method.topsisFuzzy.phase.results diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/build.properties b/bundles/flintstones.method.topsisFuzzy.phase.results/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/plugin.xml b/bundles/flintstones.method.topsisFuzzy.phase.results/plugin.xml new file mode 100644 index 0000000..5995de9 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/TOPSISFuzzyResults.java b/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/TOPSISFuzzyResults.java new file mode 100644 index 0000000..d8eb7e1 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/TOPSISFuzzyResults.java @@ -0,0 +1,158 @@ +package flintstones.method.topsisFuzzy.phase.results; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.method.topsisFuzzy.phase.results.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; + +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.Rengine; + +/** + * Results phase for Fuzzy TOPSIS method + * @author jcfer + * + */ +public class TOPSISFuzzyResults extends PhaseMethod{ + + @Inject + IProblemElementService problemService; + + @Inject + @Translation + Messages msg; + + /** + * Problem criteria + */ + Criterion[] allCriteria; + + /** + * Problem alternatives + */ + Alternative[] allAlternatives; + + /** + * R execution engine + */ + Rengine eng; + + /** + * Criteria weights + */ + ArrayList aggCriWeights; + + /** + * Aggregated valuations + */ + HashMatrix aggregatedValues; + + /** + * @return Problem criteria + */ + public Criterion[] allCriteria() { + return allCriteria; + } + + /** + * @return Problem alternatives + */ + public Alternative[] allAlternatives() { + return allAlternatives; + } + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * Loads problem data from previous phases and creates R engine + */ + @SuppressWarnings("unchecked") + public void loadData() { + eng = Rengine.getMainEngine(); + if(eng == null) + eng = new Rengine(new String[] { "--no-save" }, false, null); + + allCriteria = ProblemElementHelper.asCriterions(problemService.getMainElements(Criterion.Type)); + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + + aggCriWeights = (ArrayList) importData("aggregatedWeights"); + aggregatedValues = (HashMatrix) importData( + "aggregatedValues"); + + + } + + /** + * Executes FuzzyTOPSIS function from R engine + * @param linear Use FuzzyTOPSISLinear + * @return R expression with results + */ + public REXP executeR(boolean linear) { + //Start library + eng.eval("library(FuzzyMCDM)"); + + //Valuation matrix: decision <- matrix(c(...), nrow, ncol) + StringBuilder sb = new StringBuilder("decision <- matrix(c("); + TrapezoidalFunction temp; + for(int c = 0; c < allCriteria.length; c++) { + for(int v = 0; v < 3; v++) { + for(int a = 0; a < allAlternatives.length; a++) { + temp = aggregatedValues.get(allAlternatives[a], allCriteria[c]); + if(v==0) { + sb.append(temp.getA() + ","); + }else if(v==1) { + sb.append(temp.getB() + ","); + }else { + sb.append(temp.getD() + ","); + } + } + } + } + sb.deleteCharAt(sb.length()-1); + sb.append("),nrow = " + allAlternatives.length + ",ncol = " + allCriteria.length*3 + ")"); + eng.eval(sb.toString()); + + //Criterion weights: we <- c(...) + sb = new StringBuilder("we <- c("); + for(int c = 0; c < allCriteria.length; c++) { + temp = aggCriWeights.get(c); + sb.append(temp.getA() + "," + temp.getB() + "," + temp.getD() + ","); + } + sb.deleteCharAt(sb.length()-1); + sb.append(")"); + eng.eval(sb.toString()); + + //Type of criteria (cost/benefit) + sb = new StringBuilder("cb <- c("); + for(int c = 0; c < allCriteria.length; c++) { + if(allCriteria[c].isCost()) { + sb.append("\"min\","); + }else { + sb.append("\"max\","); + } + } + sb.deleteCharAt(sb.length()-1); + sb.append(")"); + eng.eval(sb.toString()); + + if(linear) + return eng.eval("FuzzyMCDM::FuzzyTOPSISLinear(decision, we, cb)"); + return eng.eval("FuzzyMCDM::FuzzyTOPSISVector(decision, we, cb)"); + } +} diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/Messages.java b/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/Messages.java new file mode 100644 index 0000000..b65b6c2 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.topsisFuzzy.phase.results.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; +} diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/messages.properties b/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/messages.properties new file mode 100644 index 0000000..4a0ba3d --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/messages.properties @@ -0,0 +1 @@ +phase_name=Results \ No newline at end of file diff --git a/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/messages_es.properties b/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/messages_es.properties new file mode 100644 index 0000000..8aafffa --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy.phase.results/src/flintstones/method/topsisFuzzy/phase/results/messages/messages_es.properties @@ -0,0 +1 @@ +phase_name=Resultados \ No newline at end of file diff --git a/bundles/flintstones.method.topsisFuzzy/.classpath b/bundles/flintstones.method.topsisFuzzy/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.topsisFuzzy/.polyglot.META-INF b/bundles/flintstones.method.topsisFuzzy/.polyglot.META-INF new file mode 100644 index 0000000..5c87ec8 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.topsisFuzzy + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.topsisFuzzy/.project b/bundles/flintstones.method.topsisFuzzy/.project new file mode 100644 index 0000000..81dfd7f --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/.project @@ -0,0 +1,45 @@ + + + flintstones.method.topsisFuzzy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362702 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.topsisFuzzy/META-INF/MANIFEST.MF b/bundles/flintstones.method.topsisFuzzy/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9f2a7c5 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.topsisFuzzy;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.topsisFuzzy +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.validatedmethod;bundle-version="1.0.0", + flintstones.valuation.linguistic diff --git a/bundles/flintstones.method.topsisFuzzy/build.properties b/bundles/flintstones.method.topsisFuzzy/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.topsisFuzzy/plugin.xml b/bundles/flintstones.method.topsisFuzzy/plugin.xml new file mode 100644 index 0000000..3719046 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/FuzzyTOPSISMethod.java b/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/FuzzyTOPSISMethod.java new file mode 100644 index 0000000..f790c9e --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/FuzzyTOPSISMethod.java @@ -0,0 +1,52 @@ +package flintstones.method.topsisFuzzy; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.RLibTestOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.topsisFuzzy.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; + +/** + * Fuzzy TOPSIS method for multicriteria decision + * @author jcfer + * + */ +public class FuzzyTOPSISMethod extends ValidatedMethod{ + + @Inject + @Translation + private Messages msg; + + /** + * @return Method name + */ + @Override + public String getName() { + return "Fuzzy Technique for Order of Preference by Similarity to Ideal Solution (Fuzzy TOPSIS)"; + } + + /** + * Tests if method is applicable + */ + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String vEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[1]; + validTypes[0] = LinguisticValuation.class.getSimpleName(); + ValuationTypeOperation vto = new ValuationTypeOperation(vEntity, validTypes, valuations); + + validator.setReturn(this.getName()).custom(vto).named("valuations").custom(new RLibTestOperation("RLibTest", "FuzzyMCDM")).named("FuzzyMCDM"); + } + +} diff --git a/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/Messages.java b/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/Messages.java new file mode 100644 index 0000000..a16dc23 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.topsisFuzzy.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + + public String method_name; +} diff --git a/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/messages.properties b/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/messages.properties new file mode 100644 index 0000000..9e1403a --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/messages.properties @@ -0,0 +1 @@ +method_name=Fuzzy Technique for Order of Preference by Similarity to Ideal Solution (Fuzzy TOPSIS) \ No newline at end of file diff --git a/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/messages_es.properties b/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/messages_es.properties new file mode 100644 index 0000000..9effbc2 --- /dev/null +++ b/bundles/flintstones.method.topsisFuzzy/src/flintstones/method/topsisFuzzy/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Tcnica difusa para el orden de preferencia mediante cercana a la solucin ideal (Fuzzy TOPSIS) \ No newline at end of file diff --git a/bundles/flintstones.method.twoTuple/.classpath b/bundles/flintstones.method.twoTuple/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.twoTuple/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.twoTuple/.polyglot.META-INF b/bundles/flintstones.method.twoTuple/.polyglot.META-INF new file mode 100644 index 0000000..af1c980 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.twoTuple + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] 2-tuple + diff --git a/bundles/flintstones.method.twoTuple/.project b/bundles/flintstones.method.twoTuple/.project new file mode 100644 index 0000000..ab58173 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/.project @@ -0,0 +1,45 @@ + + + flintstones.method.twoTuple + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362706 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.twoTuple/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.twoTuple/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.twoTuple/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.twoTuple/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.twoTuple/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.twoTuple/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.twoTuple/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.twoTuple/META-INF/MANIFEST.MF b/bundles/flintstones.method.twoTuple/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2036e05 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.twoTuple;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.twoTuple +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.twoTuple, + flintstones.helper.faq diff --git a/bundles/flintstones.method.twoTuple/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.twoTuple/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..830a8ab --- /dev/null +++ b/bundles/flintstones.method.twoTuple/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.twoTuple +Bundle-Name = 2-tuple \ No newline at end of file diff --git a/bundles/flintstones.method.twoTuple/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.twoTuple/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..830a8ab --- /dev/null +++ b/bundles/flintstones.method.twoTuple/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.twoTuple +Bundle-Name = 2-tuple \ No newline at end of file diff --git a/bundles/flintstones.method.twoTuple/build.properties b/bundles/flintstones.method.twoTuple/build.properties new file mode 100644 index 0000000..4abcbd2 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.twoTuple/faq/faq.en.md b/bundles/flintstones.method.twoTuple/faq/faq.en.md new file mode 100644 index 0000000..95eff7e --- /dev/null +++ b/bundles/flintstones.method.twoTuple/faq/faq.en.md @@ -0,0 +1 @@ +The fuzzy linguistic approach has been applied successfully to many problems. However, there is a limitation of this approach imposed by its information representation model and the computation methods used when fusion processes are performed on linguistic values. This limitation is the loss of information; this loss of information implies a lack of precision in the final results from the fusion of linguistic information. The 2-tuple linguistic model overcomes this limitation by representing the linguistic information by 2-tuples, which are composed of a linguistic term and a numeric value assessed in (-0.5, 0.5). This model allows a continuous representation of the linguistic information on its domain, therefore, it can represent any counting of information obtained in a aggregation process. \ No newline at end of file diff --git a/bundles/flintstones.method.twoTuple/faq/faq.es.md b/bundles/flintstones.method.twoTuple/faq/faq.es.md new file mode 100644 index 0000000..95eff7e --- /dev/null +++ b/bundles/flintstones.method.twoTuple/faq/faq.es.md @@ -0,0 +1 @@ +The fuzzy linguistic approach has been applied successfully to many problems. However, there is a limitation of this approach imposed by its information representation model and the computation methods used when fusion processes are performed on linguistic values. This limitation is the loss of information; this loss of information implies a lack of precision in the final results from the fusion of linguistic information. The 2-tuple linguistic model overcomes this limitation by representing the linguistic information by 2-tuples, which are composed of a linguistic term and a numeric value assessed in (-0.5, 0.5). This model allows a continuous representation of the linguistic information on its domain, therefore, it can represent any counting of information obtained in a aggregation process. \ No newline at end of file diff --git a/bundles/flintstones.method.twoTuple/plugin.xml b/bundles/flintstones.method.twoTuple/plugin.xml new file mode 100644 index 0000000..4897068 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/TwoTupleMethod.java b/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/TwoTupleMethod.java new file mode 100644 index 0000000..a53c746 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/TwoTupleMethod.java @@ -0,0 +1,71 @@ +package flintstones.method.twoTuple; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.domain.Domain; +import flintstones.entity.method.Method; +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValidBLTSDomainOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.twoTuple.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class TwoTupleMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return "2-tuple linguistic computational model"; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + int numDomains = domainService.getAll().length; + String numDomainEntity = domainMessages.Domain_count; + + Domain[] domains = domainService.getAll(); + String domainsEntity = domainMessages.Domain_entities; + + ValidBLTSDomainOperation validBLTSDomainOperation = new ValidBLTSDomainOperation(domainsEntity, domains); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + ValuationTypeOperation valuationTypeOperator = + new ValuationTypeOperation(valuationsEntity, LinguisticValuation.class.getSimpleName(), valuations); + + validator.setReturn(this.getName()) + .greaterThan(numDomainEntity, numDomains, 0) + .named("numDomains") + .custom(validBLTSDomainOperation) + .named("domains") + .custom(valuationTypeOperator) + .named("valuations"); + } + + @Override + protected HashMap exportData() { + HashMap map = new HashMap(); + map.put(Method.TYPE_OF_VALUATION, TwoTupleValuation.ID); + return map; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } +} diff --git a/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/Messages.java b/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/Messages.java new file mode 100644 index 0000000..03daac0 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/Messages.java @@ -0,0 +1,10 @@ +//This file has been auto-generated +package flintstones.method.twoTuple.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + public String Method_name; +} diff --git a/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/messages.properties b/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/messages.properties new file mode 100644 index 0000000..4fa0846 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/messages.properties @@ -0,0 +1,4 @@ +Method_name=2-tuple linguistic computational model +Method_description=F. Herrera, L. Martnez, A 2-tuple Fuzzy Linguistic Representation Model for Computing with Words. IEEE Transactions on Fuzzy Systems, vol. 8, issue 6, pp. 746-752, 2000. +FirstPhase_name=Overview +SecondPhase_name=Results \ No newline at end of file diff --git a/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/messages_es.properties b/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/messages_es.properties new file mode 100644 index 0000000..35c9ea8 --- /dev/null +++ b/bundles/flintstones.method.twoTuple/src/flintstones/method/twoTuple/messages/messages_es.properties @@ -0,0 +1,4 @@ +Method_name=Modelo computacional 2-tuplas +Method_description=F. Herrera, L. Martnez, A 2-tuple Fuzzy Linguistic Representation Model for Computing with Words. IEEE Transactions on Fuzzy Systems, vol. 8, issue 6, pp. 746-752, 2000. +FirstPhase_name=Visualizacin +SecondPhase_name=Resultados \ No newline at end of file diff --git a/bundles/flintstones.method.vikor.phase.result.ui/.classpath b/bundles/flintstones.method.vikor.phase.result.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.vikor.phase.result.ui/.polyglot.META-INF b/bundles/flintstones.method.vikor.phase.result.ui/.polyglot.META-INF new file mode 100644 index 0000000..49ece94 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.vikor.phase.result.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.method.vikor.phase.result.ui/.project b/bundles/flintstones.method.vikor.phase.result.ui/.project new file mode 100644 index 0000000..d9ef372 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.vikor.phase.result.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362707 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.vikor.phase.result.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.vikor.phase.result.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..192f179 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.vikor.phase.result.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.vikor.phase.result.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.contexts, + org.eclipse.e4.core.services, + flintstones.model.problemelement.service, + flintstones.entity.method.phase.ui, + org.eclipse.swt, + flintstones.model.ui.service, + org.eclipse.jface, + flintstones.helper.html, + flintstones.valuation.numeric, + flintstones.model.method.phase.service, + flintstones.helper.data, + javax.inject, + flintstones.entity.problemelement, + flintstones.application.perspective.framework.ui, + flintstones.entity.method.phase, + flintstones.method.vikor.phase.result diff --git a/bundles/flintstones.method.vikor.phase.result.ui/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.vikor.phase.result.ui/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..695e5cf --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.vikor.phase.result.ui +Bundle-Name = Ui \ No newline at end of file diff --git a/bundles/flintstones.method.vikor.phase.result.ui/build.properties b/bundles/flintstones.method.vikor.phase.result.ui/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.method.vikor.phase.result.ui/plugin.xml b/bundles/flintstones.method.vikor.phase.result.ui/plugin.xml new file mode 100644 index 0000000..9810d97 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/VikorResultUI.java b/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/VikorResultUI.java new file mode 100644 index 0000000..f00cf6b --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/VikorResultUI.java @@ -0,0 +1,369 @@ +package flintstones.method.vikor.phase.result.ui; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; + +import flintstones.application.perspective.framework.ui.interfaces.IProblemElementViewerOnSingleClick; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.helper.DoubleHelper; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.vikor.phase.result.VikorResult; +import flintstones.method.vikor.phase.result.ui.messages.Messages; +import flintstones.model.ui.service.UiService; + +/** + * Interfaz para la fase de resultados del metodo VIKOR + */ +public class VikorResultUI extends PhaseMethodUI implements IProblemElementViewerOnSingleClick { + + /** + * Implementacion del metodo + */ + VikorResult model; + + /** + * Tabla para valoraciones agregadas + */ + HtmlTextTable tableAggregatedMatrix; + + /** + * Tabla para la primera fase del metodo + */ + HtmlTextTable tableNormalizedMatrix; + + /** + * Tabla para los valores usados en el metodo + */ + HtmlTextTable tableMethodMatrix; + + /** + * Tabla para la solucion + */ + HtmlTextTable tablaResultados; + + /** + * Nombre de cada criterio + */ + String[] criterios; + + /** + * Selector del valor Q + */ + Spinner spinnerQ; + + /** + * Selector del tipo de ranking + */ + Combo comboRanking; + + /** + * Specific composites + */ + Composite filaSuperiorIzq; + Composite filaSuperiorDer; + Composite filaInferiorIzq; + Composite filaInferiorDer; + + int solValue; + + @Inject + @Translation + private Messages messages; + + @Override + public void init() { + this.model = (VikorResult) this.getModel(); + model.LoadData(); + solValue = model.calcular(); + + Composite base = this.getBaseComposite(); // Contenedor general + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + Composite filaSuperior = new Composite(base, SWT.BORDER); // Contenedor de la mitad superior + UiService.setGridData(filaSuperior, 9, 9, true, true); + UiService.setGridLayout(filaSuperior, 2); + + filaSuperiorIzq = new Composite(filaSuperior, SWT.BORDER); // Contenedor del cuadrante superior izquierdo + UiService.setGridData(filaSuperiorIzq, 9, 9, true, true); + UiService.setGridLayout(filaSuperiorIzq, 1); + + filaSuperiorDer = new Composite(filaSuperior, SWT.BORDER); // Contenedro del cuadrante superior derecho + UiService.setGridData(filaSuperiorDer, 9, 9, true, true); + UiService.setGridLayout(filaSuperiorDer, 1); + + Composite filaInferior = new Composite(base, SWT.NONE); // Contenedor de la mitad inferior + UiService.setGridData(filaInferior, 9, 9, true, true); + UiService.setGridLayout(filaInferior, 2, true); + + filaInferiorIzq = new Composite(filaInferior, SWT.BORDER); // Contenedor del cuadrante inferior izquierdo + UiService.setGridData(filaInferiorIzq, 9, 9, true, true); + UiService.setGridLayout(filaInferiorIzq, 1); + + filaInferiorDer = new Composite(filaInferior, SWT.BORDER); // Contenedor del cuadrante inferior derecho + UiService.setGridData(filaInferiorDer, 9, 9, true, false); + UiService.setGridLayout(filaInferiorDer, 1, false); + + Composite compQspn = new Composite(filaInferiorDer, SWT.NONE); // Contenedor para los selectores + UiService.setGridData(compQspn, -1, 1, false, false); + UiService.setGridLayout(compQspn, 2, true); + + + //Llena las tablas con los datos calculados del problema + crearTablaInicial(filaSuperiorIzq); + crearTablaNormalizada(filaSuperiorDer); + crearTablaCalculos(filaInferiorIzq); + crearTablaSolucion(filaInferiorDer, solValue); + + Label labelQq = new Label(compQspn, SWT.NONE); + labelQq.setText("Q:"); + spinnerQ = new Spinner(compQspn, SWT.BORDER); + spinnerQ.setDigits(3); + spinnerQ.setMinimum(0); + spinnerQ.setMaximum(1000); + spinnerQ.setValues(ChangeDoubleToInt(model.q, spinnerQ), 0, 1000, 3, 1, 1); + spinnerQ.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + //Al modificar el valor Q, recalcula la solucion + model.q = DoubleHelper.ParseDouble(spinnerQ.getText()); + refresh(); + } + }); + + Label labelRankings = new Label(compQspn, SWT.NONE); + labelRankings.setText(messages.choose + " "); + comboRanking = new Combo(compQspn, SWT.NONE); + comboRanking.add("Ranking Q"); + comboRanking.add("Ranking S"); + comboRanking.add("Ranking R"); + comboRanking.select(0); + comboRanking.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + //Al modificar el ranking a usar, recalcula la solucion + switch (comboRanking.getSelectionIndex()) { + case 0: + model.tipo = 'Q'; + break; + case 1: + model.tipo = 'S'; + break; + default: + model.tipo = 'R'; + break; + } + int sol = model.calcular(); + crearTablaSolucion(filaInferiorDer, sol); + sendRefresh(); + } + }); + } + + /** + * Crea o actualiza la tabla inicial, mostrando la matriz de valoraciones agregadas + * @param base Contenedor para la tabla + */ + private void crearTablaInicial(Composite base) { + String[] alternativas = new String[model.getAlternatives().length + 2]; + criterios = new String[model.getCriterions().length]; + String[][] valuations = new String[alternativas.length][criterios.length]; + + for (int i = 0; i < (alternativas.length - 2); i++) { + alternativas[i] = model.getAlternatives()[i].toString(); + } + alternativas[alternativas.length - 2] = messages.best; + alternativas[alternativas.length - 1] = messages.worst; + + for (int i = 0; i < criterios.length; i++) { + criterios[i] = model.getCriterions()[i].toString(); + } + + for (int i = 0; i < (valuations.length - 2); i++) { // Alternatives + for (int j = 0; j < valuations[i].length; j++) { // Criteria + valuations[i][j] = Double.toString(model.getValuation(i, j)); + } + } + + for (int j = 0; j < valuations[0].length; j++) { + valuations[valuations.length - 2][j] = Double.toString(model.getBestValuations()[j]); + valuations[valuations.length - 1][j] = Double.toString(model.getWorstValuations()[j]); + } + + if(tableAggregatedMatrix == null) + tableAggregatedMatrix = new HtmlTextTable(base, valuations, criterios, alternativas); + else + tableAggregatedMatrix.refresh(valuations); + tableAggregatedMatrix.render(); + } + + /** + * Crea o actualiza la tabla para la primera fase del metodo + * @param base Contenedor para la tabla + */ + private void crearTablaNormalizada(Composite base) { + String[] alternativas = new String[model.getAlternatives().length]; + String[][] valuations = new String[alternativas.length][criterios.length]; + + for (int i = 0; i < alternativas.length; i++) { + alternativas[i] = model.getAlternatives()[i].toString(); + } + + for (int i = 0; i < valuations.length; i++) { + for (int j = 0; j < valuations[i].length; j++) { + valuations[i][j] = String.format("%.5f", model.getValueMatrizFase1(i, j)); + } + } + + if(tableNormalizedMatrix == null) + tableNormalizedMatrix = new HtmlTextTable(base, valuations, criterios, alternativas); + else + tableNormalizedMatrix.refresh(valuations); + tableNormalizedMatrix.render(); + } + + /** + * Crea o actualiza la tabla de los valores usados en el metodo + * @param base Contenedor para la tabla + */ + private void crearTablaCalculos(Composite base) { + String[] alternativas = new String[model.getAlternatives().length]; + String[] cabecera = new String[6]; + cabecera[0] = "Si"; + cabecera[1] = "Ri"; + cabecera[2] = "Qi"; + cabecera[3] = "RankingS"; + cabecera[4] = "RankingR"; + cabecera[5] = "RankingQ"; + String[][] valores = new String[alternativas.length][6]; + + for (int i = 0; i < alternativas.length; i++) { + valores[i][0] = String.format("%.5f", model.getSValues()[i]); + valores[i][1] = String.format("%.5f", model.getRValues()[i]); + if (model.getQValues()[i] < 0) + valores[i][2] = "-"; + else + valores[i][2] = String.format("%.5f", model.getQValues()[i]); + alternativas[i] = model.getAlternatives()[i].toString(); + } + + if(model.getRankingS().size() == 0 || model.getRankingR().size() == 0 || model.getRankingQ().size() == 0) { + for (int i = 0; i < alternativas.length; i++) { + valores[i][3] = "-"; + valores[i][4] = "-"; + valores[i][5] = "-"; + } + }else { + for (int i = 0; i < alternativas.length; i++) { + valores[model.getRankSArray()[i]][3] = Integer.toString(i + 1); + valores[model.getRankRArray()[i]][4] = Integer.toString(i + 1); + if (model.getQValues()[i] < 0) + valores[model.getRankQArray()[i]][5] = "-"; + else + valores[model.getRankQArray()[i]][5] = Integer.toString(i + 1); + } + } + + if(tableMethodMatrix == null) + tableMethodMatrix = new HtmlTextTable(base, valores, cabecera, alternativas); + else + tableMethodMatrix.refresh(valores); + tableMethodMatrix.render(); + + } + + /** + * Crea o actualiza la tabla de resultados + * @param base Contenedor para la tabla + * @param sol Indice de la ultima alternativa que forma parte de la solucion + */ + private void crearTablaSolucion(Composite base, int sol) { + String[] solucion = new String[1]; + solucion[0] = "
    "; + String[] texto = new String[1]; + texto[0] = "
    " + messages.solution + "
    "; + if (model.getRankingSeleccionado().size() == 0) { + solucion[0] += messages.no_solution + " (" + messages.best + " = " + messages.worst + ")"; + } else { + int i = 0; + while(i <= sol) { + if (i != 0) + solucion[0] += String.format("%.5f", model.getRankingSeleccionado().get(i).value) + " - " + + String.format("%.5f", model.getRankingSeleccionado().get(0).value) + " = " + + String.format("%.5f", + (model.getRankingSeleccionado().get(i).value + - model.getRankingSeleccionado().get(0).value)) + + " < " + model.getDQ() + " : "; + solucion[0] += model.getAlternatives()[model.getRankingSeleccionado().get(i).key] + " ✔"; + solucion[0] += "
    "; + i++; + } + if(i < model.getRankingSeleccionado().size()) { + solucion[0] += String.format("%.5f", model.getRankingSeleccionado().get(i).value) + " - " + + String.format("%.5f", model.getRankingSeleccionado().get(0).value) + " = " + + String.format("%.5f", (model.getRankingSeleccionado().get(i).value + - model.getRankingSeleccionado().get(0).value)) + + " < " + model.getDQ() + " : " + + model.getAlternatives()[model.getRankingSeleccionado().get(i).key] + " X"; + } + } + solucion[0] += "
    "; + + Composite aux = new Composite(base, SWT.NONE); + UiService.setGridData(aux, 9, 9, true, true); + UiService.setGridLayout(aux, 1); + + if (tablaResultados == null) + tablaResultados = new HtmlTextTable(aux, solucion, texto, false); + else + tablaResultados.refresh(solucion); + tablaResultados.render(); + } + + // Funcion con la que podemos controlar el funcionamiento del click en el + // Viewer + @Override + public void problemElementViewerOnSingleClick(ProblemElement item) { + + // Saving + model.q = DoubleHelper.ParseDouble(spinnerQ.getText()); + + // Changing the spinner parameters. + spinnerQ.setSelection(ChangeDoubleToInt(model.q, spinnerQ)); + } + + private int ChangeDoubleToInt(double number, Spinner spinner) { + double newNumber = number; + newNumber *= Math.pow(10, spinner.getDigits()); + return (int) newNumber; + } + + /** + * Called on phase re-view (after first init) + */ + @Override + public void refresh() { + solValue = model.calcular(); + crearTablaInicial(filaSuperiorIzq); + crearTablaNormalizada(filaSuperiorDer); + crearTablaCalculos(filaInferiorIzq); + crearTablaSolucion(filaInferiorDer, solValue); + this.sendRefresh(); + } + + @Override + protected boolean isForwardEnabled() { + return true; + } + +} diff --git a/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/Messages.java b/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/Messages.java new file mode 100644 index 0000000..fc133be --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/Messages.java @@ -0,0 +1,16 @@ +package flintstones.method.vikor.phase.result.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String method_name; + public String best; + public String worst; + public String solution; + public String choose; + public String no_solution; + +} \ No newline at end of file diff --git a/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/messages.properties b/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/messages.properties new file mode 100644 index 0000000..1775fed --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/messages.properties @@ -0,0 +1,6 @@ +method_name=VIKOR Result +best=Best +worst=Worst +solution=Solution +choose=Choose ranking: +no_solution=No proposed solution \ No newline at end of file diff --git a/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/messages_es.properties b/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/messages_es.properties new file mode 100644 index 0000000..1face42 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result.ui/src/flintstones/method/vikor/phase/result/ui/messages/messages_es.properties @@ -0,0 +1,6 @@ +method_name=VIKOR Resultado +best=Mejor +worst=Peor +solution=Solucin +choose=Elegir ranking: +no_solution=No hay solucin propuesta \ No newline at end of file diff --git a/bundles/flintstones.method.vikor.phase.result/.classpath b/bundles/flintstones.method.vikor.phase.result/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.vikor.phase.result/.polyglot.META-INF b/bundles/flintstones.method.vikor.phase.result/.polyglot.META-INF new file mode 100644 index 0000000..0527cb1 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.vikor.phase.result + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Result + diff --git a/bundles/flintstones.method.vikor.phase.result/.project b/bundles/flintstones.method.vikor.phase.result/.project new file mode 100644 index 0000000..7e59054 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/.project @@ -0,0 +1,45 @@ + + + flintstones.method.vikor.phase.result + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362707 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.vikor.phase.result/META-INF/MANIFEST.MF b/bundles/flintstones.method.vikor.phase.result/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a868d99 --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.vikor.phase.result;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.vikor.phase.result +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.contexts, + javax.inject, + flintstones.model.valuation.service, + flintstones.model.problemelement.service, + flintstones.entity.problemelement, + flintstones.model.domain.service, + flintstones.entity.method.phase, + flintstones.helper.data, + flintstones.operator, + flintstones.valuation.numeric, + flintstones.valuation.linguistic, + flintstones.model.domain.provider, + flintstones.entity.valuation +Export-Package: flintstones.method.vikor.phase.result diff --git a/bundles/flintstones.method.vikor.phase.result/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.vikor.phase.result/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..d78684c --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.vikor.phase.result +Bundle-Name = Result \ No newline at end of file diff --git a/bundles/flintstones.method.vikor.phase.result/build.properties b/bundles/flintstones.method.vikor.phase.result/build.properties new file mode 100644 index 0000000..99abb1a --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/ diff --git a/bundles/flintstones.method.vikor.phase.result/plugin.xml b/bundles/flintstones.method.vikor.phase.result/plugin.xml new file mode 100644 index 0000000..8473dde --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.vikor.phase.result/src/flintstones/method/vikor/phase/result/VikorResult.java b/bundles/flintstones.method.vikor.phase.result/src/flintstones/method/vikor/phase/result/VikorResult.java new file mode 100644 index 0000000..35a5bca --- /dev/null +++ b/bundles/flintstones.method.vikor.phase.result/src/flintstones/method/vikor/phase/result/VikorResult.java @@ -0,0 +1,413 @@ +package flintstones.method.vikor.phase.result; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +import javax.inject.Inject; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.numeric.NumericValuation; + +/** + * Fase de resultados para el metodo VIKOR + */ +public class VikorResult extends PhaseMethod { + @Inject + IProblemElementService problemService; + + @Inject + IOperatorService operatorService; + + @Inject + IValuationService valuationService; + + @Inject + IDomainService domainService; + + /** + * @param Clave del par + * @param Valor del par usada para comparar + */ + public class Pair> implements Comparable> { + public K key; + public V value; + + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + @Override + public int compareTo(Pair o) { + return value.compareTo((V) o.value); + } + } + + /** + * Valor Q del problema + */ + public double q = 0.5; + + /** + * Tipo de ranking para la solucion + */ + public char tipo = 'Q'; + + /** + * Todas las alternativas en el problema + */ + Alternative[] allAlternatives; + + /** + * Todos los criterios en el problema + */ + Criterion[] allCriterion; + + /** + * Valoraciones agregadas de cada alternativa y criterio + */ + HashMatrix matriz; + + /** + * Pesos de cada criterio agregados + */ + HashMap aggregatedWeights; + + /** + * Mejores y peores valoraciones de cada criterio + */ + double[] bestValuation, worstValuation; + + // Variables empleadas en el procedimiento del metodo + NumericValuation[][] matrizFase1; + double[] Si, Ri, Qi; + double minS = Double.MAX_VALUE, minR = Double.MAX_VALUE, maxS = Double.MIN_VALUE, maxR = Double.MIN_VALUE; + double DQ; + + /** + * Ranking de cada alternativa basada en su valor Qi + */ + ArrayList> rankingQ; + + /** + * Ranking de cada alternativa basada en su valor Si + */ + ArrayList> rankingS; + + /** + * Ranking de cada alternativa basada en su valor Ri + */ + ArrayList> rankingR; + + @Override + public String getName() { + return "VIKOR result"; + } + + /** + * Carga los datos del problema y de la fase anterior + */ + @SuppressWarnings("unchecked") + public void LoadData() { + + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + allCriterion = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + + aggregatedWeights = (HashMap) importData("criterionWeights"); + matriz = (HashMatrix) importData("decisionmatrix"); + + + matrizFase1 = new NumericValuation[allAlternatives.length][allCriterion.length]; + + bestValuation = new double[allCriterion.length]; + worstValuation = new double[allCriterion.length]; + + Si = new double[allAlternatives.length]; + Ri = new double[allAlternatives.length]; + Qi = new double[allAlternatives.length]; + rankingQ = new ArrayList<>(); + rankingS = new ArrayList<>(); + rankingR = new ArrayList<>(); + } + + /** + * Aplica las diferentes fases del metodo + * + * @return Indice de la ultima alternativa del ranking que forma parte de la + * solucion + */ + public int calcular() { + rankingQ.clear(); + rankingR.clear(); + rankingS.clear(); + if (calculoFase1() == -1) { + return -2; + } + calculoFase2(); + return calculoFinal(); + } + + /** + * Primera fase del metodo. Calcula mejores y peores valoraciones, y los valores + * Si y Ri de cada alternativa + */ + private int calculoFase1() { + + // Calculo de los mejores y los peores + for (int c = 0; c < matrizFase1[0].length; c++) { + if (!allCriterion[c].isCost()) { + bestValuation[c] = Double.MIN_VALUE; + worstValuation[c] = Double.MAX_VALUE; + } else { + bestValuation[c] = Double.MAX_VALUE; + worstValuation[c] = Double.MIN_VALUE; + } + for (int a = 0; a < matrizFase1.length; a++) { + if (!allCriterion[c].isCost()) {// Maximizar + double tempVal = ((NumericValuation) matriz.get(allAlternatives[a], allCriterion[c])).getValue(); + if (bestValuation[c] < tempVal) { + bestValuation[c] = tempVal; + } + if (worstValuation[c] > tempVal) { + worstValuation[c] = tempVal; + } + } else {// Minimizar + double tempVal = ((NumericValuation) matriz.get(allAlternatives[a], allCriterion[c])).getValue(); + if (bestValuation[c] > tempVal) { + bestValuation[c] = tempVal; + } + if (worstValuation[c] < tempVal) { + worstValuation[c] = tempVal; + } + } + } + } + // Para cada alternativa + for (int a = 0; a < matrizFase1.length; a++) { + Si[a] = 0; + Ri[a] = Double.MIN_VALUE; + // Para cada criterio + for (int c = 0; c < matrizFase1[0].length; c++) { + matrizFase1[a][c] = (NumericValuation) matriz.get(allAlternatives[a], allCriterion[c]).clone(); + double temp = ((NumericValuation) matriz.get(allAlternatives[a], allCriterion[c])).getValue(); + double t1 = bestValuation[c] - temp; + double t2 = bestValuation[c] - worstValuation[c]; + + temp = t1 / t2; + if (t2 == 0) + return -1; + temp *= aggregatedWeights.get(allCriterion[c]); + + // Calcula el valor y se guarda en las estructuras correspondientes + matrizFase1[a][c].setValue(temp); + Si[a] += temp; + if (temp > Ri[a]) { + Ri[a] = temp; + } + } + } + return 0; + } + + /** + * Segunda fase del metodo. Calcula valores Qi y rankings + */ + private void calculoFase2() { + + // Obtiene los mejores y peores valores Si y Ri + for (int i = 0; i < allAlternatives.length; i++) { + if (Si[i] < minS) { + minS = Si[i]; + } + if (Si[i] > maxS) { + maxS = Si[i]; + } + if (Ri[i] < minR) { + minR = Ri[i]; + } + if (Ri[i] > maxR) { + maxR = Ri[i]; + } + } + + // A�ade cada alternativa a su ranking + for (int i = 0; i < allAlternatives.length; i++) { + double temp1 = this.q * ((Si[i] - minS) / (maxS - minS)); + double temp2 = (1 - this.q) * ((Ri[i] - minR) / (maxR - minR)); + Qi[i] = temp1 + temp2; + + rankingQ.add(new Pair(i, Qi[i])); + rankingR.add(new Pair(i, Ri[i])); + rankingS.add(new Pair(i, Si[i])); + + } + // Ordena los rankings de menor a mayor valor + Collections.sort(rankingQ); + Collections.sort(rankingR); + Collections.sort(rankingS); + + } + + /** + * Calculo final. Obtiene el indice de la ultima alternativa que forma parte de + * la solucion + * + * @return Indice de la alternativa + */ + private int calculoFinal() { + List> ranking; + switch (tipo) { + case 'S': + ranking = rankingS; + break; + case 'R': + ranking = rankingR; + break; + default: + ranking = rankingQ; + break; + } + + if (ranking.get(0).value < 0) { + return -1; + } + DQ = (1.0 / ((double) allAlternatives.length - 1.0)); + // C1: Si la alternativa de mejor rango tiene ventaja aceptable + if ((ranking.get(1).value - ranking.get(0).value) >= DQ) { + // C2: Si esa alternativa tiene estabilidad aceptable + if (minS == Si[ranking.get(0).key] || minR == Ri[ranking.get(0).key]) { + // A1 es la solucion + return 0; + } else { + // A1 y A2 es la solucion + return 1; + } + } + + // Si C1 no se cumple, comprueba las siguientes alternativas + int i = 1; + while (i < ranking.size()) { + // La alternativa que no entre en la solucion sera aquella que no tiene ventaja + // aceptable + if ((ranking.get(i).value - ranking.get(0).value) >= DQ) { + return i - 1; + } + i++; + } + return i - 1; + } + + public ArrayList> getRankingQ() { + return rankingQ; + } + + public ArrayList> getRankingR() { + return rankingR; + } + + public ArrayList> getRankingS() { + return rankingS; + } + + /** + * @return Ranking seleccionado para el calculo de la solucion + */ + public ArrayList> getRankingSeleccionado() { + if (tipo == 'Q') { + return rankingQ; + } else if (tipo == 'S') { + return rankingS; + } else { + return rankingR; + } + } + + public Alternative[] getAlternatives() { + return allAlternatives; + }; + + public double getValuation(int a, int c) { + return ((NumericValuation) matriz.get(allAlternatives[a], allCriterion[c])).getValue(); + } + + public Criterion[] getCriterions() { + return allCriterion; + } + + public double[] getBestValuations() { + return bestValuation; + } + + public double[] getWorstValuations() { + return worstValuation; + } + + public double getValueMatrizFase1(int a, int c) { + try { + return matrizFase1[a][c].getValue(); + } catch (NullPointerException e) { + return Double.NaN; + } + } + + public double[] getSValues() { + return Si; + } + + public double[] getRValues() { + return Ri; + } + + public double[] getQValues() { + return Qi; + } + + public double getDQ() { + return DQ; + } + + /** + * @return Ranking Q como array de enteros + */ + public int[] getRankQArray() { + int[] temp = new int[rankingQ.size()]; + for (int i = 0; i < rankingQ.size(); i++) { + temp[i] = rankingQ.get(i).key; + } + return temp; + } + + /** + * @return Ranking S como array de enteros + */ + public int[] getRankSArray() { + int[] temp = new int[rankingS.size()]; + for (int i = 0; i < rankingS.size(); i++) { + temp[i] = rankingS.get(i).key; + } + return temp; + } + + /** + * @return Ranking R como array de enteros + */ + public int[] getRankRArray() { + int[] temp = new int[rankingR.size()]; + for (int i = 0; i < rankingR.size(); i++) { + temp[i] = rankingR.get(i).key; + } + return temp; + } +} \ No newline at end of file diff --git a/bundles/flintstones.method.vikor/.classpath b/bundles/flintstones.method.vikor/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.method.vikor/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.vikor/.polyglot.META-INF b/bundles/flintstones.method.vikor/.polyglot.META-INF new file mode 100644 index 0000000..9ec7b68 --- /dev/null +++ b/bundles/flintstones.method.vikor/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.vikor + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Vikor + diff --git a/bundles/flintstones.method.vikor/.project b/bundles/flintstones.method.vikor/.project new file mode 100644 index 0000000..38a0a51 --- /dev/null +++ b/bundles/flintstones.method.vikor/.project @@ -0,0 +1,45 @@ + + + flintstones.method.vikor + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362706 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.vikor/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.vikor/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.vikor/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.vikor/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.vikor/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.method.vikor/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.vikor/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.vikor/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.vikor/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.vikor/META-INF/MANIFEST.MF b/bundles/flintstones.method.vikor/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ab48417 --- /dev/null +++ b/bundles/flintstones.method.vikor/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.vikor;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.todim +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.linguistic, + flintstones.valuation.numeric.real, + flintstones.helper.faq diff --git a/bundles/flintstones.method.vikor/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.vikor/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..a6be789 --- /dev/null +++ b/bundles/flintstones.method.vikor/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.todim +Bundle-Name = Vikor \ No newline at end of file diff --git a/bundles/flintstones.method.vikor/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.vikor/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..a6be789 --- /dev/null +++ b/bundles/flintstones.method.vikor/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.todim +Bundle-Name = Vikor \ No newline at end of file diff --git a/bundles/flintstones.method.vikor/build.properties b/bundles/flintstones.method.vikor/build.properties new file mode 100644 index 0000000..4abcbd2 --- /dev/null +++ b/bundles/flintstones.method.vikor/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.vikor/faq/faq.en.md b/bundles/flintstones.method.vikor/faq/faq.en.md new file mode 100644 index 0000000..c2b4476 --- /dev/null +++ b/bundles/flintstones.method.vikor/faq/faq.en.md @@ -0,0 +1 @@ +The VIKOR method is a multi-criteria decision making method. It was originally developed by Serafim Opricovic to solve decision problems with conflicting and noncommensurable (different units) criteria, assuming that compromise is acceptable for conflict resolution, the decision maker wants a solution that is the closest to the ideal, and the alternatives are evaluated according to all established criteria. VIKOR ranks alternatives and determines the solution named compromise that is the closest to the ideal. \ No newline at end of file diff --git a/bundles/flintstones.method.vikor/faq/faq.es.md b/bundles/flintstones.method.vikor/faq/faq.es.md new file mode 100644 index 0000000..c662809 --- /dev/null +++ b/bundles/flintstones.method.vikor/faq/faq.es.md @@ -0,0 +1,2 @@ +El método VIKOR es un método de toma de decisiones multicriterio. Fue desarrollado originalmente por Serafim Opricovic para resolver problemas de decisión con criterios conflictivos y unidades diferentes, asumiendo que el compromiso es aceptable para la resolución de conflictos, el decisor quiere una solución que sea la más cercana al ideal, y las alternativas se evalúan según todos los criterios establecidos. VIKOR clasifica las alternativas y determina la solución denominada de compromiso que más se acerca al la ideal. + diff --git a/bundles/flintstones.method.vikor/plugin.xml b/bundles/flintstones.method.vikor/plugin.xml new file mode 100644 index 0000000..d8e497f --- /dev/null +++ b/bundles/flintstones.method.vikor/plugin.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.vikor/src/flintstones/method/vikor/VikorMethod.java b/bundles/flintstones.method.vikor/src/flintstones/method/vikor/VikorMethod.java new file mode 100644 index 0000000..d6a5dc5 --- /dev/null +++ b/bundles/flintstones.method.vikor/src/flintstones/method/vikor/VikorMethod.java @@ -0,0 +1,50 @@ +package flintstones.method.vikor; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.RLibTestOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.vikor.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.numeric.real.RealValuation; + +public class VikorMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return messages.method_name; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[2]; + validTypes[0] = RealValuation.class.getSimpleName(); + validTypes[1] = LinguisticValuation.class.getSimpleName(); + ValuationTypeOperation valuationTypeOperator = new ValuationTypeOperation(valuationsEntity, validTypes, + valuations); + + validator.setReturn(this.getName()).custom(valuationTypeOperator).named("valuations").custom(new RLibTestOperation("RLibTest", "MCDM")).named("MCDM");; + } +} diff --git a/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/Messages.java b/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/Messages.java new file mode 100644 index 0000000..8796f77 --- /dev/null +++ b/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/Messages.java @@ -0,0 +1,12 @@ +package flintstones.method.vikor.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String method_name; + +} + diff --git a/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/messages.properties b/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/messages.properties new file mode 100644 index 0000000..0d4bb66 --- /dev/null +++ b/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/messages.properties @@ -0,0 +1 @@ +method_name=Multicriteria Optimization and Compromise Solution (VIKOR) \ No newline at end of file diff --git a/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/messages_es.properties b/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/messages_es.properties new file mode 100644 index 0000000..4290ccf --- /dev/null +++ b/bundles/flintstones.method.vikor/src/flintstones/method/vikor/messages/messages_es.properties @@ -0,0 +1 @@ +method_name= Optimizacin multicriterio y solucin de compromiso (VIKOR) \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.classpath b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.polyglot.META-INF b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.polyglot.META-INF new file mode 100644 index 0000000..eb598e1 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.vikorFuzzy.phase.result.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-name + diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.project b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.project new file mode 100644 index 0000000..4bff914 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.vikorFuzzy.phase.result.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362710 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e7300db --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-name +Bundle-SymbolicName: flintstones.method.vikorFuzzy.phase.result.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.vikorFuzzy.phase.result.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.method.vikorFuzzy.phase.result, + flintstones.entity.method.phase, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.helper.html, + flintstones.entity.problemelement, + flintstones.domain.fuzzyset, + javax.inject, + org.eclipse.e4.core.services diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/build.properties b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/plugin.xml b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/plugin.xml new file mode 100644 index 0000000..82d5a0a --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/FuzzyVikorResultUI.java b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/FuzzyVikorResultUI.java new file mode 100644 index 0000000..6e54ca0 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/FuzzyVikorResultUI.java @@ -0,0 +1,397 @@ +package flintstones.method.vikorFuzzy.phase.result.ui; + +import javax.inject.Inject; + +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.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.vikorFuzzy.phase.result.FuzzyVikorResult; +import flintstones.method.vikorFuzzy.phase.result.ui.messages.Messages; +import flintstones.model.ui.service.UiService; + +/** + * Interface for results + * + * @author jcfp + * + */ +public class FuzzyVikorResultUI extends PhaseMethodUI { + + FuzzyVikorResult model; + + @Inject + @Translation + Messages msg; + + /** + * Initial data table composite + */ + Composite initialTableSub; + + /** + * Normalized difference table composite + */ + Composite difTableSub; + + /** + * Crisp method values table composite + */ + Composite crispTableSub; + + /** + * Method values table composite + */ + Composite valueTableSub; + + /** + * Main ranking table composite + */ + Composite rankingTableSub; + + /** + * Proposed solutions table composite + */ + Composite resultTableSub; + + /** + * Inital data table + */ + HtmlTextTable initialTable; + + /** + * Normalized difference table + */ + HtmlTextTable difTable; + + /** + * Crisp method values table + */ + HtmlTextTable crispTable; + + /** + * Method values table + */ + HtmlTextTable valuesTable; + + /** + * Main ranking table + */ + HtmlTextTable rankingTable; + + /** + * Proposed solutions table + */ + HtmlTextTable resultTable; + + /** + * Init interface + */ + @Override + public void init() { + model = (FuzzyVikorResult) this.getModel(); + model.loadData(); + +// <-------COMPOSITE INIT-------> + Composite base = this.getBaseComposite(); + UiService.setGridDataAuto(base); + UiService.setGridLayout(base, 2); + + Composite supIzq = new Composite(base, SWT.BORDER); + UiService.setGridData(supIzq, 9, 9, true, true); + UiService.setGridLayout(supIzq, 1); + Composite supDer = new Composite(base, SWT.BORDER); + UiService.setGridData(supDer, 9, 9, true, true); + UiService.setGridLayout(supDer, 1); + Composite infIzq = new Composite(base, SWT.NONE); + UiService.setGridData(infIzq, 9, 9, true, true); + UiService.setGridLayout(infIzq, 1); + Composite infDer = new Composite(base, SWT.NONE); + UiService.setGridData(infDer, 9, 9, true, true); + UiService.setGridLayout(infDer, 1); + + initialTableSub = new Composite(supIzq, SWT.NONE); + UiService.setGridData(initialTableSub, 9, 9, true, true); + UiService.setGridLayout(initialTableSub, 1); + +// <--------UI CONTROLLERS INIT--------> + Composite vBase = new Composite(supIzq, SWT.NONE); + UiService.setGridData(vBase, 9, 9, true, false); + UiService.setGridLayout(vBase, 3); + Label vLabel = new Label(vBase, SWT.NONE); + vLabel.setText(msg.v_selector + ": "); + Spinner vSelector = new Spinner(vBase, SWT.NONE); + vSelector.setValues(0, 0, 1000, 3, 1, 1); + vSelector.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + super.widgetSelected(e); + String value = vSelector.getText(); + value = value.replace(",", "."); + model.setVValue(Double.parseDouble(value)); + } + }); + Button btnCalculate = new Button(vBase, SWT.NONE); + btnCalculate.setText(msg.calculate_button); + btnCalculate.addSelectionListener(new SelectionAdapter() { + /** + * Al pulsar, recalcula los rankings + */ + @Override + public void widgetSelected(SelectionEvent e) { + super.widgetSelected(e); + model.calculateSRQ(); + model.computeRankings(); + createAll(model.calculateSolution()); + } + }); + + Label difLabel = new Label(supIzq, SWT.NONE); + difLabel.setText(msg.dif_title); +// <--------TABLE INITS--------> + difTableSub = new Composite(supIzq, SWT.NONE); + UiService.setGridData(difTableSub, 9, 9, true, true); + UiService.setGridLayout(difTableSub, 1); + + Label crispLabel = new Label(supDer, SWT.NONE); + crispLabel.setText(msg.crisp_title); + crispTableSub = new Composite(supDer, SWT.NONE); + UiService.setGridData(crispTableSub, 9, 9, true, true); + UiService.setGridLayout(crispTableSub, 1); + + Label valLabel = new Label(supDer, SWT.NONE); + valLabel.setText(msg.values_title); + valueTableSub = new Composite(supDer, SWT.NONE); + UiService.setGridData(valueTableSub, 9, 9, true, true); + UiService.setGridLayout(valueTableSub, 1); + + Label rankLabel = new Label(infIzq, SWT.NONE); + rankLabel.setText(msg.rank_title); + rankingTableSub = new Composite(infIzq, SWT.NONE); + UiService.setGridData(rankingTableSub, 9, 9, true, true); + UiService.setGridLayout(rankingTableSub, 1); + + Label resultLabel = new Label(infDer, SWT.NONE); + resultLabel.setText(msg.result_title); + resultTableSub = new Composite(infDer, SWT.NONE); + UiService.setGridData(resultTableSub, 9, 9, true, true); + UiService.setGridLayout(resultTableSub, 1); + + model.calculateBestWorst(); + model.calculateDifference(); + createInitialTable(initialTableSub); + createDifferenceTable(difTableSub); + } + + + /** + * Makes, or refresh all tables + * + * @param last Last proposed alternative + */ + private void createAll(int last) { + createCrispTable(crispTableSub); + createValuesTable(valueTableSub); + createRankingTable(rankingTableSub); + createResultTable(resultTableSub, last); + } + + + /** + * Makes results table + * + * @param base Table composite + * @param last Last proposed alternative + */ + private void createResultTable(Composite base, int last) { + String[] data; + + if(last == -1) { + data = new String[1]; + data[0] = msg.all_alt_tag; + }else { + data = new String[last + 1]; + for(int i = 0; i <= last; i++) { + data[i] = model.getAlternatives()[model.rankCrispQ.get(i)].getName(); + } + } + + if (resultTable == null) + resultTable = new HtmlTextTable(base, data, true); + else { + resultTable.refresh(data); + } + resultTable.render(); + } + + + /** + * Makes ranking table + * + * @param base Table composite + */ + private void createRankingTable(Composite base) { + String[] rowHeaders = new String[model.getAlternatives().length]; + String[] colHeaders = new String[] { "Core ranking", "Fuzzy ranking", "Crisp ranking S", "Crisp ranking R", "Crisp ranking Q"}; + String[][] data = new String[rowHeaders.length][colHeaders.length]; + + for (int a = 0; a < rowHeaders.length; a++) { + rowHeaders[a] = model.getAlternatives()[a].getName(); + + data[a][0] = Integer.toString(model.coreRanking.indexOf(a) + 1); + if(model.fuzzyRanking.get(model.coreRanking.indexOf(a))) { + data[a][1] = Integer.toString(model.coreRanking.indexOf(a) + 1); + }else { + data[a][1] = "-"; + } + data[a][2] = Integer.toString(model.rankCrispS.indexOf(a) + 1); + data[a][3] = Integer.toString(model.rankCrispR.indexOf(a) + 1); + data[a][4] = Integer.toString(model.rankCrispQ.indexOf(a) + 1); + } + + if (rankingTable == null) + rankingTable = new HtmlTextTable(base, data, colHeaders, rowHeaders); + else { + rankingTable.refresh(data); + } + rankingTable.render(); + } + + + /** + * Makes method values table + * + * @param base Table composite + */ + private void createValuesTable(Composite base) { + String[] headers = new String[] { "S*", "Sor", "R*", "Ror" }; + String[] data = new String[] { model.Sstar.toString(), Double.toString(model.Sor), model.Rstar.toString(), + Double.toString(model.Ror) }; + + if (valuesTable == null) + valuesTable = new HtmlTextTable(base, data, headers, false); + else { + valuesTable.refresh(data); + } + valuesTable.render(); + } + + + /** + * Makes crisp values table + * + * @param base Table composite + */ + private void createCrispTable(Composite base) { + String[] rowHeaders = new String[model.getAlternatives().length]; + String[] colHeaders = new String[] { "Sj", "Crisp(Sj)", "Rj", "Crisp(Rj)", "Qj", "Crisp(Qj)" }; + String[][] data = new String[rowHeaders.length][colHeaders.length]; + + for (int a = 0; a < rowHeaders.length; a++) { + rowHeaders[a] = model.getAlternatives()[a].getName(); + + data[a][0] = model.Sj[a].toString(); + data[a][1] = String.format("%.3f", model.crispS[a]); + data[a][2] = model.Rj[a].toString(); + data[a][3] = String.format("%.3f", model.crispR[a]); + data[a][4] = model.Qj[a].toString(); + data[a][5] = String.format("%.3f", model.crispQ[a]); + } + + if (crispTable == null) + crispTable = new HtmlTextTable(base, data, colHeaders, rowHeaders); + else { + crispTable.refresh(data); + } + crispTable.render(); + } + + + /** + * Makes normalized difference table + * + * @param base Table composite + */ + private void createDifferenceTable(Composite base) { + String[] rowHeaders = new String[model.getAlternatives().length]; + String[] colHeaders = new String[model.getCriteria().length]; + String[][] data = new String[rowHeaders.length][colHeaders.length]; + for (int i = 0; i < rowHeaders.length; i++) { + rowHeaders[i] = model.getAlternatives()[i].getName(); + } + for (int i = 0; i < colHeaders.length; i++) { + colHeaders[i] = model.getCriteria()[i].getName(); + } + + for (int c = 0; c < model.getCriteria().length; c++) { + for (int a = 0; a < model.getAlternatives().length; a++) { + data[a][c] = model.getDifference(a, c).toString(); + } + } + + if (difTable == null) + difTable = new HtmlTextTable(base, data, colHeaders, rowHeaders); + else { + difTable.refresh(data); + } + difTable.render(); + } + + /** + * Makes initial data table and best/worst values + * + * @param base Table composite + */ + private void createInitialTable(Composite base) { + String[] rowHeaders = new String[model.getAlternatives().length + 2]; + String[] colHeaders = new String[model.getCriteria().length]; + String[][] data = new String[rowHeaders.length][colHeaders.length]; + for (int i = 0; i < rowHeaders.length - 2; i++) { + rowHeaders[i] = model.getAlternatives()[i].getName(); + } + rowHeaders[rowHeaders.length - 2] = msg.best_tag; + rowHeaders[rowHeaders.length - 1] = msg.worst_tag; + for (int i = 0; i < colHeaders.length; i++) { + colHeaders[i] = model.getCriteria()[i].getName(); + } + + TrapezoidalFunction[] best = model.getBestValues(); + TrapezoidalFunction[] worst = model.getWorstValues(); + + for (int c = 0; c < model.getCriteria().length; c++) { + for (int a = 0; a < model.getAlternatives().length; a++) { + data[a][c] = model.getInitialValuation(model.getAlternatives()[a], model.getCriteria()[c]).toString(); + } + data[model.getAlternatives().length][c] = best[c].toString(); + data[model.getAlternatives().length + 1][c] = worst[c].toString(); + } + + if (initialTable == null) + initialTable = new HtmlTextTable(base, data, colHeaders, rowHeaders); + else + initialTable.refresh(data); + initialTable.render(); + + } + + @Override + public void refresh() { + } + + /** + * @return true always enable next phase + */ + @Override + protected boolean isForwardEnabled() { + return true; + } + +} diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/Messages.java b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/Messages.java new file mode 100644 index 0000000..55507b5 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/Messages.java @@ -0,0 +1,19 @@ +package flintstones.method.vikorFuzzy.phase.result.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String v_selector; + public String calculate_button; + public String solution_tag; + public String all_alt_tag; + public String best_tag; + public String worst_tag; + + public String dif_title; + public String crisp_title; + public String values_title; + public String rank_title; + public String result_title; +} diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/messages.properties b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/messages.properties new file mode 100644 index 0000000..0a2f0ac --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/messages.properties @@ -0,0 +1,11 @@ +v_selector=V value +calculate_button=Calculate +solution_tag=Solution +all_alt_tag=All alternatives +best_tag=Best +worst_tag=Worst +dif_title=Normalized difference +crisp_title=Crisp values +values_title=Method values +rank_title=Ranking +result_title=Proposed solutions \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/messages_es.properties b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/messages_es.properties new file mode 100644 index 0000000..51771c5 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result.ui/src/flintstones/method/vikorFuzzy/phase/result/ui/messages/messages_es.properties @@ -0,0 +1,11 @@ +v_selector=Valor V +calculate_button=Calcular +solution_tag=Solucin +all_alt_tag=Todas las alternativas +best_tag=Mejor +worst_tag=Peor +dif_title=Diferencia normalizada +crisp_title=Valores crisp +values_title=Valores del mtodo +rank_title=Clasificacin +result_title=Soluciones propuestas \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/.classpath b/bundles/flintstones.method.vikorFuzzy.phase.result/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/.polyglot.META-INF b/bundles/flintstones.method.vikorFuzzy.phase.result/.polyglot.META-INF new file mode 100644 index 0000000..b1d8151 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.vikorFuzzy.phase.result + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-name + diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/.project b/bundles/flintstones.method.vikorFuzzy.phase.result/.project new file mode 100644 index 0000000..2c8d9b7 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/.project @@ -0,0 +1,45 @@ + + + flintstones.method.vikorFuzzy.phase.result + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362709 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/META-INF/MANIFEST.MF b/bundles/flintstones.method.vikorFuzzy.phase.result/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ac58d8c --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-name +Bundle-SymbolicName: flintstones.method.vikorFuzzy.phase.result;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.vikorFuzzy.phase.result +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.method.phase, + flintstones.helper.data, + flintstones.entity.problemelement, + flintstones.domain.fuzzyset, + flintstones.model.problemelement.service +Export-Package: flintstones.method.vikorFuzzy.phase.result +Import-Package: javax.inject diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/build.properties b/bundles/flintstones.method.vikorFuzzy.phase.result/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/plugin.xml b/bundles/flintstones.method.vikorFuzzy.phase.result/plugin.xml new file mode 100644 index 0000000..e7d57b2 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/FuzzyVikorResult.java b/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/FuzzyVikorResult.java new file mode 100644 index 0000000..a070f6a --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/FuzzyVikorResult.java @@ -0,0 +1,497 @@ +package flintstones.method.vikorFuzzy.phase.result; + +import java.util.ArrayList; +import java.util.Collections; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.method.vikorFuzzy.phase.result.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * Ranking for Fuzzy Vikor + * + * @author jcfp + * + */ +public class FuzzyVikorResult extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + @Translation + Messages msg; + + /** + * Aggregated criteria weights + */ + ArrayList aggCriWeights; + + /** + * Aggregated valuations + */ + HashMatrix aggregatedValues; + + /** + * All the alternatives + */ + Alternative[] allAlternatives; + + /** + * All the criteria + */ + Criterion[] allCriteria; + + /** + * Value v for rankings + */ + double vValue; + + /** + * Best values for each criterion + */ + TrapezoidalFunction[] bestValues; + + /** + * Worst values for each criterion + */ + TrapezoidalFunction[] worstValues; + + /** + * Normalized matrix + */ + TrapezoidalFunction[][] normalizedDifference; + + /** + * Parameters + */ + public TrapezoidalFunction[] Sj; + public TrapezoidalFunction[] Rj; + public double Sor; + public double Ror; + public TrapezoidalFunction Sstar; + public TrapezoidalFunction Rstar; + public TrapezoidalFunction[] Qj; + + /** + * Central ranking + */ + public ArrayList coreRanking; + + /** + * Core ranking + */ + public ArrayList fuzzyRanking; + + /** + * Defuzzification + */ + public double[] crispS; + public double[] crispR; + public double[] crispQ; + + /** + * Rankings defuzzification + */ + public ArrayList rankCrispS; + public ArrayList rankCrispR; + public ArrayList rankCrispQ; + + @Override + public String getName() { + return msg.phase_name; + } + + /** + * @return All the criteria + */ + public Criterion[] getCriteria() { + return allCriteria; + } + + /** + * @return All the alternatives + */ + public Alternative[] getAlternatives() { + return allAlternatives; + } + + /** + * Load data from previous phases + */ + @SuppressWarnings("unchecked") + public void loadData() { + aggCriWeights = (ArrayList) importData("aggregatedWeights"); + aggregatedValues = (HashMatrix) importData( + "aggregatedValues"); + + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + allCriteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + } + + /** + * Set value for parameter v + * @param v New value + */ + public void setVValue(double v) { + vValue = v; + } + + /** + * @param a Alternative + * @param c Criterion + * @return Aggregated fuzzy valuation + */ + public TrapezoidalFunction getInitialValuation(Alternative a, Criterion c) { + return aggregatedValues.get(a, c); + } + + /** + * @return Best fuzzy values + */ + public TrapezoidalFunction[] getBestValues() { + return bestValues; + } + + /** + * @return Worst fuzzy values + */ + public TrapezoidalFunction[] getWorstValues() { + return worstValues; + } + + /** + * @param a index of alternative + * @param c index of criterion + * @return Associated normalized fuzzy number + */ + public TrapezoidalFunction getDifference(int a, int c) { + return normalizedDifference[a][c]; + } + + /** + * Compute best and worst values for each criterion + */ + public void calculateBestWorst() { + bestValues = new TrapezoidalFunction[allCriteria.length]; + worstValues = new TrapezoidalFunction[allCriteria.length]; + + TrapezoidalFunction currentTPF; + ArrayList fuzzy_a = new ArrayList(); + ArrayList fuzzy_b = new ArrayList(); + ArrayList fuzzy_d = new ArrayList(); + + for (int c = 0; c < allCriteria.length; c++) { + // Reset local best/worst + fuzzy_a.clear(); + fuzzy_b.clear(); + fuzzy_d.clear(); + + for (int a = 0; a < allAlternatives.length; a++) { + + currentTPF = aggregatedValues.get(allAlternatives[a], allCriteria[c]); + + fuzzy_a.add(currentTPF.getA()); + fuzzy_b.add(currentTPF.getB()); + fuzzy_d.add(currentTPF.getD()); + } + + + if (allCriteria[c].isCost()) { // Mejor = Menor + bestValues[c] = new TrapezoidalFunction(Collections.min(fuzzy_a), Collections.min(fuzzy_b), Collections.min(fuzzy_b), Collections.min(fuzzy_d)); + worstValues[c] = new TrapezoidalFunction(Collections.max(fuzzy_a), Collections.max(fuzzy_b), Collections.max(fuzzy_b), Collections.max(fuzzy_d)); + } else { // Mejor = Mayor + bestValues[c] = new TrapezoidalFunction(Collections.max(fuzzy_a), Collections.max(fuzzy_b), Collections.max(fuzzy_b), Collections.max(fuzzy_d)); + worstValues[c] = new TrapezoidalFunction(Collections.min(fuzzy_a), Collections.min(fuzzy_b), Collections.min(fuzzy_b), Collections.min(fuzzy_d)); + } + } + } + + /** + * Compute normalized decision matrix + */ + public void calculateDifference() { + normalizedDifference = new TrapezoidalFunction[allAlternatives.length][allCriteria.length]; + + TrapezoidalFunction tpf; + double n_a, n_b, n_d; + for (int a = 0; a < normalizedDifference.length; a++) { + for (int c = 0; c < normalizedDifference[a].length; c++) { + + tpf = aggregatedValues.get(allAlternatives[a], allCriteria[c]); + + if (allCriteria[c].isCost()) { + n_a = (tpf.getA() - bestValues[c].getD()) / (worstValues[c].getD() - bestValues[c].getA()); + n_b = (tpf.getB() - bestValues[c].getB()) / (worstValues[c].getD() - bestValues[c].getA()); + n_d = (tpf.getD() - bestValues[c].getA()) / (worstValues[c].getD() - bestValues[c].getA()); + } else { + n_a = (bestValues[c].getA() - tpf.getD()) / (bestValues[c].getD() - worstValues[c].getA()); + n_b = (bestValues[c].getB() - tpf.getB()) / (bestValues[c].getD() - worstValues[c].getA()); + n_d = (bestValues[c].getD() - tpf.getA()) / (bestValues[c].getD() - worstValues[c].getA()); + } + + normalizedDifference[a][c] = new TrapezoidalFunction(n_a, n_b, n_b, n_d); + } + } + } + + /** + * Compute Sj, Rj y Qj values for each alternative and the values Sor and Ror + */ + public void calculateSRQ() { + Sj = new TrapezoidalFunction[allAlternatives.length]; + Rj = new TrapezoidalFunction[allAlternatives.length]; + + TrapezoidalFunction temp, critW; + + ArrayList s_j_a_values = new ArrayList(), + s_j_b_values = new ArrayList(), + s_j_d_values = new ArrayList(); + + ArrayList s_j_star_a_values = new ArrayList(), + s_j_star_b_values = new ArrayList(), + s_j_star_d_values = new ArrayList(); + + ArrayList r_j_a_values = new ArrayList(), + r_j_b_values = new ArrayList(), + r_j_d_values = new ArrayList(); + + double sum_a, sum_b, sum_d; + + for (int a = 0; a < allAlternatives.length; a++) { + + s_j_a_values.clear(); + s_j_b_values.clear(); + s_j_d_values.clear(); + + for (int c = 0; c < allCriteria.length; c++) { + + critW = aggCriWeights.get(c); + temp = normalizedDifference[a][c]; + + s_j_a_values.add(critW.getA() * temp.getA()); + s_j_b_values.add(critW.getB() * temp.getB()); + s_j_d_values.add(critW.getD() * temp.getD()); + } + + sum_a = s_j_a_values.stream().mapToDouble(Double::doubleValue).sum(); + sum_b = s_j_b_values.stream().mapToDouble(Double::doubleValue).sum(); + sum_d = s_j_d_values.stream().mapToDouble(Double::doubleValue).sum(); + + Sj[a] = new TrapezoidalFunction(sum_a, sum_b, sum_b, sum_d); + + s_j_star_a_values.add(sum_a); + s_j_star_b_values.add(sum_b); + s_j_star_d_values.add(sum_d); + + Rj[a] = new TrapezoidalFunction(Collections.max(s_j_a_values), Collections.max(s_j_b_values), + Collections.max(s_j_b_values), Collections.max(s_j_d_values)); + + r_j_a_values.add(Rj[a].getA()); + r_j_b_values.add(Rj[a].getB()); + r_j_d_values.add(Rj[a].getD()); + } + + Sstar = new TrapezoidalFunction(Collections.min(s_j_star_a_values), Collections.min(s_j_star_b_values), + Collections.min(s_j_star_b_values), Collections.min(s_j_star_d_values)); + + Rstar = new TrapezoidalFunction(Collections.min(r_j_a_values), Collections.min(r_j_b_values), + Collections.min(r_j_b_values), Collections.min(r_j_d_values)); + + Sor = Collections.max(s_j_star_d_values); + Ror = Collections.max(r_j_d_values); + + computeQj(); + } + + private void computeQj() { + Qj = new TrapezoidalFunction[allAlternatives.length]; + + double q_a, q_b, q_d; + for (int a = 0; a < allAlternatives.length; a++) { + q_a = vValue * (Sj[a].getA() - Sstar.getD()) / (Sor - Sstar.getA()) + ((1 - vValue) * (Rj[a].getA() - Rstar.getD()) / (Ror - Rstar.getA())); + q_b = vValue * (Sj[a].getB() - Sstar.getB()) / (Sor - Sstar.getA()) + ((1 - vValue) * (Rj[a].getB() - Rstar.getB()) / (Ror - Rstar.getA())); + q_d = vValue * (Sj[a].getD() - Sstar.getA()) / (Sor - Sstar.getA()) + ((1 - vValue) * (Rj[a].getD() - Rstar.getA()) / (Ror - Rstar.getA())); + + Qj[a] = new TrapezoidalFunction(q_a, q_b, q_b, q_d); + } + } + + /** + * Compute rankings + */ + public void computeRankings() { + computeCoreRanking(); + computeFuzzyRanking(); + computeRankingCrispS(); + computeRankingCrispR(); + computeRankingCrispQ(); + } + + private void computeCoreRanking() { + coreRanking = new ArrayList<>(); + + int i; + boolean assigned; + for (int a = 0; a < allAlternatives.length; a++) { + + i = 0; + assigned = false; + + while (i < coreRanking.size() && !assigned) { + if (Qj[a].getB() < Qj[coreRanking.get(i)].getB()) { + coreRanking.add(i, a); + assigned = true; + } + + i++; + } + + if (!assigned) + coreRanking.add(a); + } + } + + private void computeFuzzyRanking() { + fuzzyRanking = new ArrayList<>(); + + boolean confirmed; + int j; + for (int i = 0; i < coreRanking.size(); i++) { + + confirmed = true; + j = i + 1; + + while (j < coreRanking.size() && confirmed) { + // Si no es el mínimo en los 3 valores, no se garantiza + if (Qj[coreRanking.get(i)].getA() > Qj[coreRanking.get(j)].getA() + || Qj[coreRanking.get(i)].getB() >= Qj[coreRanking.get(j)].getB() + || Qj[coreRanking.get(i)].getD() > Qj[coreRanking.get(j)].getD()) { + confirmed = false; + } + j++; + } + fuzzyRanking.add(confirmed); + } + } + + private void computeRankingCrispS() { + TrapezoidalFunction temp; + + crispS = new double[Sj.length]; + rankCrispS = new ArrayList<>(); + + int i; + boolean asigned; + for (int s = 0; s < crispS.length; s++) { + temp = Sj[s]; + crispS[s] = (2 * temp.getB() + temp.getA() + temp.getD()) / 4; + + i = 0; + asigned = false; + + while(i < rankCrispS.size() && !asigned) { + if(crispS[s] < crispS[rankCrispS.get(i)]) { + rankCrispS.add(i, s); + asigned = true; + } + i++; + } + + if(!asigned) + rankCrispS.add(s); + } + } + + private void computeRankingCrispR() { + TrapezoidalFunction temp; + + crispR = new double[Rj.length]; + rankCrispR = new ArrayList<>(); + + int i; + boolean assigned; + for (int r = 0; r < crispR.length; r++) { + + temp = Rj[r]; + crispR[r] = (2d * temp.getB() + temp.getA() + temp.getD()) / 4d; + + i = 0; + assigned = false; + + while(i < rankCrispR.size() && !assigned) { + if(crispR[r] < crispR[rankCrispR.get(i)]) { + rankCrispR.add(i, r); + assigned = true; + } + i++; + } + + if(!assigned) + rankCrispR.add(r); + } + } + + private void computeRankingCrispQ() { + TrapezoidalFunction temp; + + crispQ = new double[Qj.length]; + rankCrispQ = new ArrayList<>(); + + int i; + boolean assigned; + for (int q = 0; q < crispQ.length; q++) { + temp = Qj[q]; + crispQ[q] = (2d * temp.getB() + temp.getA() + temp.getD()) / 4d; + + i = 0; + assigned = false; + + while(i < rankCrispQ.size() && !assigned) { + if(crispQ[q] < crispQ[rankCrispQ.get(i)]) { + rankCrispQ.add(i, q); + assigned = true; + } + i++; + } + + if(!assigned) + rankCrispQ.add(q); + } + } + + /** + * Compute alternative that belong to the solution set + * @return Last alternative in the set. -1 if all of them are included + */ + public int calculateSolution() { + double DQ = 1.0 / (allAlternatives.length - 1); + + // Comprobar ventaja de la mejor crispQ (C1) + if(crispQ[rankCrispQ.get(1)] - crispQ[rankCrispQ.get(0)] >= DQ) { + // Comprobar estabilidad respecto crispS o crispR (C2) + if(rankCrispQ.get(0) == rankCrispS.get(0) || rankCrispQ.get(0) == rankCrispR.get(0)) { + return 0; + } + return 1; + } + + // Si no se cumplen C1, conjunto de soluciones + for(int i = 1; i < rankCrispQ.size(); i++) { + if(crispQ[rankCrispQ.get(i)] - crispQ[rankCrispQ.get(0)] >= DQ) { + return i-1; + } + } + return -1; + } +} diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/Messages.java b/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/Messages.java new file mode 100644 index 0000000..8d80546 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.vikorFuzzy.phase.result.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; +} diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/messages.properties b/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/messages.properties new file mode 100644 index 0000000..d4d789e --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/messages.properties @@ -0,0 +1 @@ +phase_name=VIKOR Results \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/messages_es.properties b/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/messages_es.properties new file mode 100644 index 0000000..02ad556 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy.phase.result/src/flintstones/method/vikorFuzzy/phase/result/messages/messages_es.properties @@ -0,0 +1 @@ +phase_name=Resultados VIKOR \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy/.classpath b/bundles/flintstones.method.vikorFuzzy/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.vikorFuzzy/.polyglot.META-INF b/bundles/flintstones.method.vikorFuzzy/.polyglot.META-INF new file mode 100644 index 0000000..b7511ce --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.vikorFuzzy + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] VIKOR Fuzzy + diff --git a/bundles/flintstones.method.vikorFuzzy/.project b/bundles/flintstones.method.vikorFuzzy/.project new file mode 100644 index 0000000..666b885 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/.project @@ -0,0 +1,45 @@ + + + flintstones.method.vikorFuzzy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362708 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.vikorFuzzy/META-INF/MANIFEST.MF b/bundles/flintstones.method.vikorFuzzy/META-INF/MANIFEST.MF new file mode 100644 index 0000000..daefa1f --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.vikorFuzzy;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.vikorFuzzy +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.validatedmethod, + flintstones.valuation.linguistic, + flintstones.helper.faq diff --git a/bundles/flintstones.method.vikorFuzzy/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.method.vikorFuzzy/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..4a50f6b --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.vikorFuzzy +Bundle-Name = VIKOR Fuzzy \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.method.vikorFuzzy/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..5a2d5f3 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,2 @@ +#Properties file for flintstones.method.vikorFuzzy +Bundle-Name = Fuzzy VIKOR \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy/build.properties b/bundles/flintstones.method.vikorFuzzy/build.properties new file mode 100644 index 0000000..dc37f15 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties,\ + OSGI-INF/,\ + faq/ diff --git a/bundles/flintstones.method.vikorFuzzy/faq/faq.en.md b/bundles/flintstones.method.vikorFuzzy/faq/faq.en.md new file mode 100644 index 0000000..80ba88d --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/faq/faq.en.md @@ -0,0 +1 @@ +The Fuzzy VIKOR method has been developed to solve problem in a fuzzy environment where both criteria and weights could be fuzzy sets. The triangular fuzzy numbers are used to handle imprecise numerical quantities. Fuzzy VIKOR is based on the aggregating fuzzy merit that represents distance of an alternative to the ideal solution. The fuzzy operations and procedures for ranking fuzzy numbers are used in developing the fuzzy VIKOR algorithm. \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy/faq/faq.es.md b/bundles/flintstones.method.vikorFuzzy/faq/faq.es.md new file mode 100644 index 0000000..f0a06b9 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/faq/faq.es.md @@ -0,0 +1 @@ +El método Fuzzy VIKOR se ha desarrollado para resolver problemas en un contexto difuso en el que tanto los criterios como los pesos pueden ser conjuntos difusos. Los números difusos triangulares se utilizan para manejar cantidades numéricas imprecisas. Fuzzy VIKOR se basa en la agregación de méritos difusos que representan la distancia de una alternativa a la solución ideal. Las operaciones difusas y los procedimientos para clasificar los números difusos se utilizan en el desarrollo del algoritmo Fuzzy VIKOR. \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy/plugin.xml b/bundles/flintstones.method.vikorFuzzy/plugin.xml new file mode 100644 index 0000000..334347a --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/FuzzyVikorMethod.java b/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/FuzzyVikorMethod.java new file mode 100644 index 0000000..c50c30f --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/FuzzyVikorMethod.java @@ -0,0 +1,48 @@ +package flintstones.method.vikorFuzzy; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.helper.faq.interfaces.IMarkdownFAQ; +import flintstones.method.vikorFuzzy.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; + +public class FuzzyVikorMethod extends ValidatedMethod implements IMarkdownFAQ { + + @Inject + @Translation + private Messages messages; + + @Override + public String getName() { + return "Fuzzy Multicriteria Optimization and Compromise Solution (Fuzzy VIKOR)"; + } + + @Override + public String getFAQFile() { + return "faq/faq"; + } + + @Override + protected void reloadValidator() { + + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String valuationsEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[1]; + validTypes[0] = LinguisticValuation.class.getSimpleName(); + ValuationTypeOperation valuationTypeOperator = new ValuationTypeOperation(valuationsEntity, validTypes, + valuations); + + validator.setReturn(this.getName()).custom(valuationTypeOperator).named("valuations"); + } + +} diff --git a/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/Messages.java b/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/Messages.java new file mode 100644 index 0000000..d244423 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/Messages.java @@ -0,0 +1,11 @@ +package flintstones.method.vikorFuzzy.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String method_name; + +} diff --git a/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/messages.properties b/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/messages.properties new file mode 100644 index 0000000..177e547 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/messages.properties @@ -0,0 +1 @@ +method_name=Fuzzy Multicriteria Optimization and Compromise Solution (Fuzzy VIKOR) \ No newline at end of file diff --git a/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/messages_es.properties b/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/messages_es.properties new file mode 100644 index 0000000..62d0916 --- /dev/null +++ b/bundles/flintstones.method.vikorFuzzy/src/flintstones/method/vikorFuzzy/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Optimizacin multicriterio y solucin de compromiso difusa (Fuzzy VIKOR) \ No newline at end of file diff --git a/bundles/flintstones.method.waspas.results.ui/.classpath b/bundles/flintstones.method.waspas.results.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.waspas.results.ui/.polyglot.META-INF b/bundles/flintstones.method.waspas.results.ui/.polyglot.META-INF new file mode 100644 index 0000000..2b9b28e --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.waspas.results.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.waspas.results.ui/.project b/bundles/flintstones.method.waspas.results.ui/.project new file mode 100644 index 0000000..80c0e2d --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.waspas.results.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362712 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.waspas.results.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.waspas.results.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..696a15b --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.waspas.results.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.waspas.results.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase.ui, + javax.inject, + flintstones.method.waspas.results, + org.eclipse.swt, + flintstones.helper.html, + flintstones.model.ui.service, + flintstones.entity.method.phase, + flintstones.engine.R, + flintstones.entity.problemelement diff --git a/bundles/flintstones.method.waspas.results.ui/build.properties b/bundles/flintstones.method.waspas.results.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.waspas.results.ui/plugin.xml b/bundles/flintstones.method.waspas.results.ui/plugin.xml new file mode 100644 index 0000000..893b88a --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/WASPASResultsUI.java b/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/WASPASResultsUI.java new file mode 100644 index 0000000..c9d1ffa --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/WASPASResultsUI.java @@ -0,0 +1,131 @@ +package flintstones.method.waspas.results.ui; + +import javax.inject.Inject; + +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.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.RVector; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.waspas.results.WASPASResults; +import flintstones.method.waspas.results.ui.messages.Messages; +import flintstones.model.ui.service.UiService; + +public class WASPASResultsUI extends PhaseMethodUI { + + @Inject + @Translation + Messages msg; + + /** + * Phase model implementation + */ + WASPASResults model; + + /** + * Value selector for lambda variable + */ + Spinner lambda; + + /** + * Results table + */ + HtmlTextTable results; + + @Override + public void init() { + model = (WASPASResults) this.getModel(); + model.loadData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + + Composite lambdaComposite = new Composite(base, SWT.NONE); + UiService.setGridData(lambdaComposite, 0, -1, true, false); + UiService.setGridLayout(lambdaComposite, 2); + Label textLambda = new Label(lambdaComposite, SWT.NONE); + textLambda.setText("Lambda:"); + + lambda = new Spinner(lambdaComposite, SWT.NONE); + lambda.setDigits(3); + lambda.setMinimum(0); + lambda.setMaximum(1000); + lambda.setIncrement(1); + lambda.setSelection(0); + + Composite tableBase = new Composite(base, SWT.NONE); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + lambda.addSelectionListener(new SelectionAdapter() { + /** + * Executes method on lambda value change + */ + @Override + public void widgetSelected(SelectionEvent e) { + createResultTable(tableBase); + } + }); + createResultTable(tableBase); + } + + /** + * Creates method results table + * + * @param base Composite + */ + private void createResultTable(Composite base) { + REXP rexp = model.executeR(lambda.getSelection() / Math.pow(10, lambda.getDigits())); + + int[] alts = (int[]) ((REXP) ((RVector) rexp.getContent()).get(0)).getContent(); + String[] rHeaders = new String[alts.length]; + for (int a = 0; a < alts.length; a++) { + rHeaders[a] = model.allAlternatives()[alts[a] - 1].getName(); + } + // Makes table data based on R-gui result table + String[] cHeaders = msg.headers.split(","); + String[][] values = new String[alts.length][cHeaders.length]; + double[] wsm = (double[]) ((REXP) ((RVector) rexp.getContent()).get(1)).getContent(); + double[] wpm = (double[]) ((REXP) ((RVector) rexp.getContent()).get(2)).getContent(); + double[] w = (double[]) ((REXP) ((RVector) rexp.getContent()).get(3)).getContent(); + int[] ranks = (int[]) ((REXP) ((RVector) rexp.getContent()).get(4)).getContent(); + + for (int i = 0; i < rHeaders.length; i++) { + values[i][0] = Double.toString(wsm[i]); + values[i][1] = Double.toString(wpm[i]); + values[i][2] = Double.toString(w[i]); + values[i][3] = Integer.toString(ranks[i]); + } + + if (results != null) { + results.dispose(); + } + + results = new HtmlTextTable(base, values, cHeaders, rHeaders); + results.render(); + } + + /** + * Reloads phase view + */ + @Override + public void refresh() { + sendRefresh(); + } + + /** + * @return false, last phase + */ + @Override + protected boolean isForwardEnabled() { + return false; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/Messages.java b/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/Messages.java new file mode 100644 index 0000000..016b18c --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.waspas.results.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String headers; +} diff --git a/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/messages.properties b/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/messages.properties new file mode 100644 index 0000000..dea1286 --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/messages.properties @@ -0,0 +1 @@ +headers=WSM, WPM, Q, Ranking \ No newline at end of file diff --git a/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/messages_es.properties b/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/messages_es.properties new file mode 100644 index 0000000..3355ac7 --- /dev/null +++ b/bundles/flintstones.method.waspas.results.ui/src/flintstones/method/waspas/results/ui/messages/messages_es.properties @@ -0,0 +1 @@ +headers=WSM, WPM, Q, Clasificacin \ No newline at end of file diff --git a/bundles/flintstones.method.waspas.results/.classpath b/bundles/flintstones.method.waspas.results/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.waspas.results/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.waspas.results/.polyglot.META-INF b/bundles/flintstones.method.waspas.results/.polyglot.META-INF new file mode 100644 index 0000000..7417b39 --- /dev/null +++ b/bundles/flintstones.method.waspas.results/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.waspas.results + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.waspas.results/.project b/bundles/flintstones.method.waspas.results/.project new file mode 100644 index 0000000..910b628 --- /dev/null +++ b/bundles/flintstones.method.waspas.results/.project @@ -0,0 +1,45 @@ + + + flintstones.method.waspas.results + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362711 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.waspas.results/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.waspas.results/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.waspas.results/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.waspas.results/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.waspas.results/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.waspas.results/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.waspas.results/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.waspas.results/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.waspas.results/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.waspas.results/META-INF/MANIFEST.MF b/bundles/flintstones.method.waspas.results/META-INF/MANIFEST.MF new file mode 100644 index 0000000..164ed0a --- /dev/null +++ b/bundles/flintstones.method.waspas.results/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.waspas.results;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.waspas.results +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase, + javax.inject, + flintstones.model.problemelement.service, + flintstones.engine.R, + flintstones.valuation.numeric, + flintstones.helper.data, + flintstones.entity.valuation +Export-Package: flintstones.method.waspas.results diff --git a/bundles/flintstones.method.waspas.results/build.properties b/bundles/flintstones.method.waspas.results/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.waspas.results/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.waspas.results/plugin.xml b/bundles/flintstones.method.waspas.results/plugin.xml new file mode 100644 index 0000000..b2f5da5 --- /dev/null +++ b/bundles/flintstones.method.waspas.results/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/WASPASResults.java b/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/WASPASResults.java new file mode 100644 index 0000000..f14e3b8 --- /dev/null +++ b/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/WASPASResults.java @@ -0,0 +1,140 @@ +package flintstones.method.waspas.results; + +import java.util.HashMap; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.Rengine; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.data.HashMatrix; +import flintstones.method.waspas.results.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.valuation.numeric.NumericValuation; + +public class WASPASResults extends PhaseMethod { + + @Inject + IProblemElementService problemService; + + @Inject + @Translation + Messages msg; + + /** + * Problem criteria + */ + Criterion[] allCriteria; + + /** + * Problem alternatives + */ + Alternative[] allAlternatives; + + /** + * R execution engine + */ + Rengine eng; + + /** + * Criteria weights + */ + HashMap aggCriWeights; + + /** + * Aggregated valuations + */ + HashMatrix aggregatedValues; + + /** + * @return Problem criteria + */ + public Criterion[] allCriteria() { + return allCriteria; + } + + /** + * @return Problem alternatives + */ + public Alternative[] allAlternatives() { + return allAlternatives; + } + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * Loads problem data from previous phases and creates R engine + */ + @SuppressWarnings("unchecked") + public void loadData() { + eng = Rengine.getMainEngine(); + if (eng == null) + eng = new Rengine(new String[] { "--no-save" }, false, null); + + allCriteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + + aggCriWeights = (HashMap) importData("criterionWeights"); + aggregatedValues = (HashMatrix) importData("decisionmatrix"); + } + + /** + * Executes FuzzyMMOORA function from R engine + * + * @return R expression with results + */ + public REXP executeR(double lambda) { + // Start library + eng.eval("library(MCDM)"); + + // Valuation matrix: decision <- matrix(c(...), nrow, ncol) + StringBuilder sb = new StringBuilder("decision <- matrix(c("); + NumericValuation temp; + for (int c = 0; c < allCriteria.length; c++) { + for (int a = 0; a < allAlternatives.length; a++) { + temp = (NumericValuation) aggregatedValues.get(allAlternatives[a], allCriteria[c]); + sb.append(Double.toString(temp.getValue()) + ","); + } + } + sb.deleteCharAt(sb.length() - 1); + sb.append("),nrow = " + allAlternatives.length + ",ncol = " + allCriteria.length + ")"); + eng.eval(sb.toString()); + + // Criterion weights: we <- c(...) + sb = new StringBuilder("we <- c("); + for (int c = 0; c < allCriteria.length; c++) { + sb.append(Double.toString(aggCriWeights.get(allCriteria[c])) + ","); + } + sb.deleteCharAt(sb.length() - 1); + sb.append(")"); + eng.eval(sb.toString()); + + // Type of criteria (cost/benefit) + sb = new StringBuilder("cb <- c("); + for (int c = 0; c < allCriteria.length; c++) { + if (allCriteria[c].isCost()) { + sb.append("\"min\","); + } else { + sb.append("\"max\","); + } + } + sb.deleteCharAt(sb.length() - 1); + sb.append(")"); + eng.eval(sb.toString()); + + return eng.eval("MCDM::WASPAS(decision, we, cb," + Double.toString(lambda) + ")"); + } +} diff --git a/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/Messages.java b/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/Messages.java new file mode 100644 index 0000000..b937356 --- /dev/null +++ b/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.waspas.results.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; +} diff --git a/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/messages.properties b/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/messages.properties new file mode 100644 index 0000000..4a0ba3d --- /dev/null +++ b/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/messages.properties @@ -0,0 +1 @@ +phase_name=Results \ No newline at end of file diff --git a/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/messages_es.properties b/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/messages_es.properties new file mode 100644 index 0000000..8aafffa --- /dev/null +++ b/bundles/flintstones.method.waspas.results/src/flintstones/method/waspas/results/messages/messages_es.properties @@ -0,0 +1 @@ +phase_name=Resultados \ No newline at end of file diff --git a/bundles/flintstones.method.waspas/.classpath b/bundles/flintstones.method.waspas/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.waspas/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.waspas/.polyglot.META-INF b/bundles/flintstones.method.waspas/.polyglot.META-INF new file mode 100644 index 0000000..8700aa1 --- /dev/null +++ b/bundles/flintstones.method.waspas/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.waspas + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.waspas/.project b/bundles/flintstones.method.waspas/.project new file mode 100644 index 0000000..9a03988 --- /dev/null +++ b/bundles/flintstones.method.waspas/.project @@ -0,0 +1,45 @@ + + + flintstones.method.waspas + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362711 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.waspas/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.waspas/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.waspas/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.waspas/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.waspas/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.waspas/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.waspas/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.waspas/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.waspas/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.waspas/META-INF/MANIFEST.MF b/bundles/flintstones.method.waspas/META-INF/MANIFEST.MF new file mode 100644 index 0000000..cd0add0 --- /dev/null +++ b/bundles/flintstones.method.waspas/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.waspas;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.waspas +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + javax.inject, + flintstones.entity.validatedmethod, + flintstones.valuation.numeric, + flintstones.valuation.linguistic diff --git a/bundles/flintstones.method.waspas/build.properties b/bundles/flintstones.method.waspas/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.waspas/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.waspas/plugin.xml b/bundles/flintstones.method.waspas/plugin.xml new file mode 100644 index 0000000..d83dc0e --- /dev/null +++ b/bundles/flintstones.method.waspas/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.waspas/src/flintstones/method/waspas/WASPASMethod.java b/bundles/flintstones.method.waspas/src/flintstones/method/waspas/WASPASMethod.java new file mode 100644 index 0000000..dfc53e0 --- /dev/null +++ b/bundles/flintstones.method.waspas/src/flintstones/method/waspas/WASPASMethod.java @@ -0,0 +1,49 @@ +package flintstones.method.waspas; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.RLibTestOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.waspas.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.numeric.NumericValuation; + +public class WASPASMethod extends ValidatedMethod{ + + @Inject + @Translation + private Messages msg; + + /** + * @return Method name + */ + @Override + public String getName() { + return msg.method_name; + } + + /** + * Tests if method is applicable + */ + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String vEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[2]; + validTypes[0] = NumericValuation.class.getSimpleName(); + validTypes[1] = LinguisticValuation.class.getSimpleName(); + ValuationTypeOperation vto = new ValuationTypeOperation(vEntity, validTypes, valuations); + + validator.setReturn(this.getName()).custom(vto).named("valuations").custom(new RLibTestOperation("RLibTest", "MCDM")).named("MCDM"); + } + +} diff --git a/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/Messages.java b/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/Messages.java new file mode 100644 index 0000000..27fc7cc --- /dev/null +++ b/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.waspas.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + + public String method_name; +} diff --git a/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/messages.properties b/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/messages.properties new file mode 100644 index 0000000..1aee88f --- /dev/null +++ b/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/messages.properties @@ -0,0 +1 @@ +method_name=Weighted Aggregated Sum Product ASsessment (WASPAS) \ No newline at end of file diff --git a/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/messages_es.properties b/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/messages_es.properties new file mode 100644 index 0000000..88a540e --- /dev/null +++ b/bundles/flintstones.method.waspas/src/flintstones/method/waspas/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Evaluacin del producto de la suma agregada ponderada (WASPAS) \ No newline at end of file diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/.classpath b/bundles/flintstones.method.waspasFuzzy.results.ui/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/.polyglot.META-INF b/bundles/flintstones.method.waspasFuzzy.results.ui/.polyglot.META-INF new file mode 100644 index 0000000..650277b --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.waspasFuzzy.results.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/.project b/bundles/flintstones.method.waspasFuzzy.results.ui/.project new file mode 100644 index 0000000..9578100 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.method.waspasFuzzy.results.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362714 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/META-INF/MANIFEST.MF b/bundles/flintstones.method.waspasFuzzy.results.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..62cbea5 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.waspasFuzzy.results.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.waspasFuzzy.results.ui +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + flintstones.entity.method.phase.ui, + javax.inject, + flintstones.method.waspasFuzzy.results, + flintstones.helper.html, + flintstones.entity.method.phase, + org.eclipse.swt, + flintstones.model.ui.service, + flintstones.engine.R, + flintstones.entity.problemelement diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/build.properties b/bundles/flintstones.method.waspasFuzzy.results.ui/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/plugin.xml b/bundles/flintstones.method.waspasFuzzy.results.ui/plugin.xml new file mode 100644 index 0000000..bd07e30 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/WASPASFuzzyResultsUI.java b/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/WASPASFuzzyResultsUI.java new file mode 100644 index 0000000..ade40d9 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/WASPASFuzzyResultsUI.java @@ -0,0 +1,132 @@ +package flintstones.method.waspasFuzzy.results.ui; + +import javax.inject.Inject; + +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.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.RVector; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.html.table.HtmlTextTable; +import flintstones.method.waspasFuzzy.results.WASPASFuzzyResults; +import flintstones.method.waspasFuzzy.results.ui.messages.Messages; +import flintstones.model.ui.service.UiService; + +public class WASPASFuzzyResultsUI extends PhaseMethodUI { + + @Inject + @Translation + Messages msg; + + /** + * Phase model implementation + */ + WASPASFuzzyResults model; + + /** + * Value selector for lambda variable + */ + Spinner lambda; + + /** + * Results table + */ + HtmlTextTable results; + + @Override + public void init() { + model = (WASPASFuzzyResults) this.getModel(); + model.loadData(); + + Composite base = this.getBaseComposite(); + UiService.setGridData(base, 9, 9, true, true); + UiService.setGridLayout(base, 1); + + + Composite lambdaComposite = new Composite(base, SWT.NONE); + UiService.setGridData(lambdaComposite, 0, -1, true, false); + UiService.setGridLayout(lambdaComposite, 2); + Label textLambda = new Label(lambdaComposite, SWT.NONE); + textLambda.setText("Lambda:"); + + lambda = new Spinner(lambdaComposite, SWT.NONE); + lambda.setDigits(3); + lambda.setMinimum(0); + lambda.setMaximum(1000); + lambda.setIncrement(1); + lambda.setSelection(0); + + Composite tableBase = new Composite(base, SWT.NONE); + UiService.setGridData(tableBase, 9, 9, true, true); + UiService.setGridLayout(tableBase, 1); + lambda.addSelectionListener(new SelectionAdapter() { + /** + * Executes method on lambda value change + */ + @Override + public void widgetSelected(SelectionEvent e) { + createResultTable(tableBase); + } + }); + createResultTable(tableBase); + } + + /** + * Creates method results table + * + * @param base Composite + */ + private void createResultTable(Composite base) { + REXP rexp = model.executeR(lambda.getSelection() / Math.pow(10, lambda.getDigits())); + + int[] alts = (int[]) ((REXP) ((RVector) rexp.getContent()).get(0)).getContent(); + String[] rHeaders = new String[alts.length]; + for (int a = 0; a < alts.length; a++) { + rHeaders[a] = model.allAlternatives()[alts[a] - 1].getName(); + } + // Makes table data based on R-gui result table + String[] cHeaders = msg.headers.split(","); + String[][] values = new String[alts.length][cHeaders.length]; + double[] wsm = (double[]) ((REXP) ((RVector) rexp.getContent()).get(1)).getContent(); + double[] wpm = (double[]) ((REXP) ((RVector) rexp.getContent()).get(2)).getContent(); + double[] w = (double[]) ((REXP) ((RVector) rexp.getContent()).get(3)).getContent(); + int[] ranks = (int[]) ((REXP) ((RVector) rexp.getContent()).get(4)).getContent(); + + for (int i = 0; i < rHeaders.length; i++) { + values[i][0] = Double.toString(wsm[i]); + values[i][1] = Double.toString(wpm[i]); + values[i][2] = Double.toString(w[i]); + values[i][3] = Integer.toString(ranks[i]); + } + + if (results != null) { + results.dispose(); + } + + results = new HtmlTextTable(base, values, cHeaders, rHeaders); + results.render(); + } + + /** + * Reloads phase view + */ + @Override + public void refresh() { + sendRefresh(); + } + + /** + * @return false, last phase + */ + @Override + protected boolean isForwardEnabled() { + return false; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/Messages.java b/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/Messages.java new file mode 100644 index 0000000..d864961 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.waspasFuzzy.results.ui.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String headers; +} diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/messages.properties b/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/messages.properties new file mode 100644 index 0000000..37a7dfc --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/messages.properties @@ -0,0 +1 @@ +headers=WSM, WPM, W, Ranking \ No newline at end of file diff --git a/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/messages_es.properties b/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/messages_es.properties new file mode 100644 index 0000000..e08e71a --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results.ui/src/flintstones/method/waspasFuzzy/results/ui/messages/messages_es.properties @@ -0,0 +1 @@ +headers=WSM, WPM, W, Clasificacin \ No newline at end of file diff --git a/bundles/flintstones.method.waspasFuzzy.results/.classpath b/bundles/flintstones.method.waspasFuzzy.results/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.waspasFuzzy.results/.polyglot.META-INF b/bundles/flintstones.method.waspasFuzzy.results/.polyglot.META-INF new file mode 100644 index 0000000..8cd67db --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.waspasFuzzy.results + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.waspasFuzzy.results/.project b/bundles/flintstones.method.waspasFuzzy.results/.project new file mode 100644 index 0000000..a6dacfe --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/.project @@ -0,0 +1,45 @@ + + + flintstones.method.waspasFuzzy.results + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362713 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.waspasFuzzy.results/META-INF/MANIFEST.MF b/bundles/flintstones.method.waspasFuzzy.results/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0cbe366 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.waspasFuzzy.results;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.waspasFuzzy.results +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: org.eclipse.e4.core.services, + javax.inject, + flintstones.entity.method.phase, + flintstones.model.problemelement.service, + flintstones.engine.R, + flintstones.domain.fuzzyset, + flintstones.helper.data +Export-Package: flintstones.method.waspasFuzzy.results diff --git a/bundles/flintstones.method.waspasFuzzy.results/build.properties b/bundles/flintstones.method.waspasFuzzy.results/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.waspasFuzzy.results/plugin.xml b/bundles/flintstones.method.waspasFuzzy.results/plugin.xml new file mode 100644 index 0000000..3d3c0cb --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/WASPASFuzzyResults.java b/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/WASPASFuzzyResults.java new file mode 100644 index 0000000..c652194 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/WASPASFuzzyResults.java @@ -0,0 +1,150 @@ +package flintstones.method.waspasFuzzy.results; + +import java.util.ArrayList; + +import javax.inject.Inject; + +import org.eclipse.e4.core.services.nls.Translation; +import org.rosuda.JRI.REXP; +import org.rosuda.JRI.Rengine; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.helper.data.HashMatrix; +import flintstones.method.waspasFuzzy.results.messages.Messages; +import flintstones.model.problemelement.service.IProblemElementService; + +public class WASPASFuzzyResults extends PhaseMethod{ + + @Inject + IProblemElementService problemService; + + @Inject + @Translation + Messages msg; + + /** + * Problem criteria + */ + Criterion[] allCriteria; + + /** + * Problem alternatives + */ + Alternative[] allAlternatives; + + /** + * R execution engine + */ + Rengine eng; + + /** + * Criteria weights + */ + ArrayList aggCriWeights; + + /** + * Aggregated valuations + */ + HashMatrix aggregatedValues; + + /** + * @return Problem criteria + */ + public Criterion[] allCriteria() { + return allCriteria; + } + + /** + * @return Problem alternatives + */ + public Alternative[] allAlternatives() { + return allAlternatives; + } + + /** + * @return Phase name + */ + @Override + public String getName() { + return msg.phase_name; + } + + /** + * Loads problem data from previous phases and creates R engine + */ + @SuppressWarnings("unchecked") + public void loadData() { + eng = Rengine.getMainEngine(); + if(eng == null) + eng = new Rengine(new String[] { "--no-save" }, false, null); + + allCriteria = ProblemElementHelper.asCriterions(problemService.getAll(Criterion.Type)); + allAlternatives = ProblemElementHelper.asAlternatives(problemService.getAll(Alternative.Type)); + + aggCriWeights = (ArrayList) importData("aggregatedWeights"); + aggregatedValues = (HashMatrix) importData( + "aggregatedValues"); + + + } + + /** + * Executes FuzzyMMOORA function from R engine + * @return R expression with results + */ + public REXP executeR(double lambda) { + //Start library + eng.eval("library(FuzzyMCDM)"); + + //Valuation matrix: decision <- matrix(c(...), nrow, ncol) + StringBuilder sb = new StringBuilder("decision <- matrix(c("); + TrapezoidalFunction temp; + for(int c = 0; c < allCriteria.length; c++) { + for(int v = 0; v < 3; v++) { + for(int a = 0; a < allAlternatives.length; a++) { + temp = aggregatedValues.get(allAlternatives[a], allCriteria[c]); + if(v==0) { + sb.append(temp.getA() + ","); + }else if(v==1) { + sb.append(temp.getB() + ","); + }else { + sb.append(temp.getD() + ","); + } + } + } + } + sb.deleteCharAt(sb.length()-1); + sb.append("),nrow = " + allAlternatives.length + ",ncol = " + allCriteria.length*3 + ")"); + eng.eval(sb.toString()); + + //Criterion weights: we <- c(...) + sb = new StringBuilder("we <- c("); + for(int c = 0; c < allCriteria.length; c++) { + temp = aggCriWeights.get(c); + sb.append(temp.getA() + "," + temp.getB() + "," + temp.getD() + ","); + } + sb.deleteCharAt(sb.length()-1); + sb.append(")"); + eng.eval(sb.toString()); + + //Type of criteria (cost/benefit) + sb = new StringBuilder("cb <- c("); + for(int c = 0; c < allCriteria.length; c++) { + if(allCriteria[c].isCost()) { + sb.append("\"min\","); + }else { + sb.append("\"max\","); + } + } + sb.deleteCharAt(sb.length()-1); + sb.append(")"); + eng.eval(sb.toString()); + + return eng.eval("FuzzyMCDM::FuzzyWASPAS(decision, we, cb," + Double.toString(lambda) + ")"); + } +} diff --git a/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/Messages.java b/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/Messages.java new file mode 100644 index 0000000..d1958a4 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/Messages.java @@ -0,0 +1,8 @@ +package flintstones.method.waspasFuzzy.results.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + public String phase_name; +} diff --git a/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/messages.properties b/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/messages.properties new file mode 100644 index 0000000..4a0ba3d --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/messages.properties @@ -0,0 +1 @@ +phase_name=Results \ No newline at end of file diff --git a/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/messages_es.properties b/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/messages_es.properties new file mode 100644 index 0000000..8aafffa --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy.results/src/flintstones/method/waspasFuzzy/results/messages/messages_es.properties @@ -0,0 +1 @@ +phase_name=Resultados \ No newline at end of file diff --git a/bundles/flintstones.method.waspasFuzzy/.classpath b/bundles/flintstones.method.waspasFuzzy/.classpath new file mode 100644 index 0000000..e801ebf --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.method.waspasFuzzy/.polyglot.META-INF b/bundles/flintstones.method.waspasFuzzy/.polyglot.META-INF new file mode 100644 index 0000000..499aae2 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.method.waspasFuzzy + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Bundle-Name + diff --git a/bundles/flintstones.method.waspasFuzzy/.project b/bundles/flintstones.method.waspasFuzzy/.project new file mode 100644 index 0000000..fe5ef0a --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/.project @@ -0,0 +1,45 @@ + + + flintstones.method.waspasFuzzy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362713 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c9545f0 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.method.waspasFuzzy/META-INF/MANIFEST.MF b/bundles/flintstones.method.waspasFuzzy/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7dc66fc --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.method.waspasFuzzy;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.method.waspasFuzzy +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: javax.inject, + org.eclipse.e4.core.services, + flintstones.entity.validatedmethod, + flintstones.valuation.linguistic diff --git a/bundles/flintstones.method.waspasFuzzy/build.properties b/bundles/flintstones.method.waspasFuzzy/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.method.waspasFuzzy/plugin.xml b/bundles/flintstones.method.waspasFuzzy/plugin.xml new file mode 100644 index 0000000..77fd459 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/plugin.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/FuzzyWASPASMethod.java b/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/FuzzyWASPASMethod.java new file mode 100644 index 0000000..2b7057c --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/FuzzyWASPASMethod.java @@ -0,0 +1,48 @@ +package flintstones.method.waspasFuzzy; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.services.nls.Translation; + +import flintstones.entity.validatedmethod.ValidatedMethod; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.chainvalidator.ChainValidator; +import flintstones.helper.chainvalidator.operation.method.RLibTestOperation; +import flintstones.helper.chainvalidator.operation.method.ValuationTypeOperation; +import flintstones.method.waspasFuzzy.messages.Messages; +import flintstones.valuation.linguistic.LinguisticValuation; + + +public class FuzzyWASPASMethod extends ValidatedMethod{ + + @Inject + @Translation + private Messages msg; + + /** + * @return Method name + */ + @Override + public String getName() { + return "Fuzzy Weighted Aggregated Sum Product ASsessment (Fuzzy WASPAS)"; + } + + /** + * Tests if method is applicable + */ + @Override + protected void reloadValidator() { + validator = ContextInjectionFactory.make(ChainValidator.class, context); + + Valuation[] valuations = valuationService.getAll(); + String vEntity = valuationMessages.Valuation_entity; + + String[] validTypes = new String[1]; + validTypes[0] = LinguisticValuation.class.getSimpleName(); + ValuationTypeOperation vto = new ValuationTypeOperation(vEntity, validTypes, valuations); + + validator.setReturn(this.getName()).custom(vto).named("valuations").custom(new RLibTestOperation("RLibTest", "FuzzyMCDM")).named("FuzzyMCDM"); + } + +} diff --git a/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/Messages.java b/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/Messages.java new file mode 100644 index 0000000..e716a2f --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/Messages.java @@ -0,0 +1,9 @@ +package flintstones.method.waspasFuzzy.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +public class Messages { + + public String method_name; +} diff --git a/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/messages.properties b/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/messages.properties new file mode 100644 index 0000000..7d2b52e --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/messages.properties @@ -0,0 +1 @@ +method_name=Fuzzy Weighted Aggregated Sum Product ASsessment (Fuzzy WASPAS) \ No newline at end of file diff --git a/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/messages_es.properties b/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/messages_es.properties new file mode 100644 index 0000000..c78ef70 --- /dev/null +++ b/bundles/flintstones.method.waspasFuzzy/src/flintstones/method/waspasFuzzy/messages/messages_es.properties @@ -0,0 +1 @@ +method_name=Evaluacin difusa del producto de la suma agregada ponderada (Fuzzy WASPAS) \ No newline at end of file diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/.classpath b/bundles/flintstones.model.ahp.referencepoint.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/.polyglot.META-INF b/bundles/flintstones.model.ahp.referencepoint.provider/.polyglot.META-INF new file mode 100644 index 0000000..5b960f3 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.ahp.referencepoint.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/.project b/bundles/flintstones.model.ahp.referencepoint.provider/.project new file mode 100644 index 0000000..c774b00 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.ahp.referencepoint.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362715 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.ahp.referencepoint.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ed933a8 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.ahp.referencepoint.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.ahp.referencepoint.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.model.ahp.referencepoint.service, + flintstones.helper.data, + flintstones.entity.ahpsort.referencepoint, + flintstones.entity.problemelement +Service-Component: component.xml +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/build.properties b/bundles/flintstones.model.ahp.referencepoint.provider/build.properties new file mode 100644 index 0000000..dafca8f --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/build.properties @@ -0,0 +1,5 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml +source.. = src/ diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/component.xml b/bundles/flintstones.model.ahp.referencepoint.provider/component.xml new file mode 100644 index 0000000..3c6a3d3 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/component.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ahp.referencepoint.provider/src/flintstones/model/ahp/referencepoint/provider/ReferencePointServiceProvider.java b/bundles/flintstones.model.ahp.referencepoint.provider/src/flintstones/model/ahp/referencepoint/provider/ReferencePointServiceProvider.java new file mode 100644 index 0000000..e6b45af --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.provider/src/flintstones/model/ahp/referencepoint/provider/ReferencePointServiceProvider.java @@ -0,0 +1,65 @@ +package flintstones.model.ahp.referencepoint.provider; + +import java.util.LinkedList; + +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.helper.data.LinkedMapList; +import flintstones.model.ahp.referencepoint.service.IReferencePointService; + +public class ReferencePointServiceProvider implements IReferencePointService { + + LinkedMapList content = new LinkedMapList<>(); + + @Override + public void addOrUpdate(Criterion c, Double[] points) { + + LinkedList list = new LinkedList<>(); + + for (int i = 0; i < points.length; i++) { + Double min = points[i]; + AHPSortReferencencePoint point = new AHPSortReferencencePoint(c, min); + list.add(point); + } + + content.put(c, list); + + } + + @Override + public void add(Criterion c, AHPSortReferencencePoint[] points) { + + content.put(c, points); + + } + + @Override + public LinkedList get(Criterion c) { + LinkedList l = content.get(c); + return l != null ? l : new LinkedList<>(); + } + + @Override + public String toString() { + return content.toString(); + } + + @Override + public void clear() { + content.clear(); + } + + @Override + public Double[] getAsRange(Criterion c) { + + LinkedList l = get(c); + if(l.size() == 0) + return new Double[0]; + + Double[] items = l.stream().map(k -> k.getValue()).toArray(Double[]::new); + + return items; + } + + +} diff --git a/bundles/flintstones.model.ahp.referencepoint.service/.classpath b/bundles/flintstones.model.ahp.referencepoint.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ahp.referencepoint.service/.polyglot.META-INF b/bundles/flintstones.model.ahp.referencepoint.service/.polyglot.META-INF new file mode 100644 index 0000000..a8d759e --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.ahp.referencepoint.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.ahp.referencepoint.service/.project b/bundles/flintstones.model.ahp.referencepoint.service/.project new file mode 100644 index 0000000..62905bc --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.ahp.referencepoint.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362716 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.ahp.referencepoint.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.ahp.referencepoint.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..1d0c320 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.ahp.referencepoint.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.ahp.referencepoint.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.model.ahp.referencepoint.service +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.problemelement, + flintstones.helper.data, + flintstones.entity.ahpsort.referencepoint diff --git a/bundles/flintstones.model.ahp.referencepoint.service/build.properties b/bundles/flintstones.model.ahp.referencepoint.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.ahp.referencepoint.service/src/flintstones/model/ahp/referencepoint/service/IReferencePointService.java b/bundles/flintstones.model.ahp.referencepoint.service/src/flintstones/model/ahp/referencepoint/service/IReferencePointService.java new file mode 100644 index 0000000..4cca997 --- /dev/null +++ b/bundles/flintstones.model.ahp.referencepoint.service/src/flintstones/model/ahp/referencepoint/service/IReferencePointService.java @@ -0,0 +1,19 @@ +package flintstones.model.ahp.referencepoint.service; + +import java.util.LinkedList; + +import flintstones.entity.ahpsort.referencepoint.AHPSortReferencencePoint; +import flintstones.entity.problemelement.entities.Criterion; + +public interface IReferencePointService { + + void addOrUpdate(Criterion c, Double[] points); + + void add(Criterion c, AHPSortReferencencePoint[] points); + + LinkedList get(Criterion c); + + Double[] getAsRange(Criterion c); + + void clear(); +} diff --git a/bundles/flintstones.model.ahppreferences.provider/.classpath b/bundles/flintstones.model.ahppreferences.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ahppreferences.provider/.polyglot.META-INF b/bundles/flintstones.model.ahppreferences.provider/.polyglot.META-INF new file mode 100644 index 0000000..1e70e95 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.ahppreferences.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.ahppreferences.provider/.project b/bundles/flintstones.model.ahppreferences.provider/.project new file mode 100644 index 0000000..e17570c --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.ahppreferences.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362716 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.ahppreferences.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.ahppreferences.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7b2ec02 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.ahppreferences.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.ahppreferences.provider +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.model.ahppreferences.service, + flintstones.entity.ahppreferences, + org.eclipse.e4.core.contexts, + javax.inject, + flintstones.model.problemelement.provider, + flintstones.model.problemelement.service, + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.core.di, + flintstones.entity.preferences.preferencecollection, + javax.annotation +Service-Component: component.xml +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.model.ahppreferences.provider/build.properties b/bundles/flintstones.model.ahppreferences.provider/build.properties new file mode 100644 index 0000000..dafca8f --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/build.properties @@ -0,0 +1,5 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml +source.. = src/ diff --git a/bundles/flintstones.model.ahppreferences.provider/component.xml b/bundles/flintstones.model.ahppreferences.provider/component.xml new file mode 100644 index 0000000..d2d944c --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/component.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ahppreferences.provider/src/flintstones/model/ahppreferences/provider/ProblemPreferencesServiceProvider.java b/bundles/flintstones.model.ahppreferences.provider/src/flintstones/model/ahppreferences/provider/ProblemPreferencesServiceProvider.java new file mode 100644 index 0000000..c8814ee --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.provider/src/flintstones/model/ahppreferences/provider/ProblemPreferencesServiceProvider.java @@ -0,0 +1,69 @@ +package flintstones.model.ahppreferences.provider; + +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.ahppreferences.PreferenceCollectionKey; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; +import flintstones.model.ahppreferences.service.IProblemPreferencesService; + +public class ProblemPreferencesServiceProvider implements IProblemPreferencesService { + + HashMap preferences = new HashMap<>(); + + @Inject + IEclipseContext context; + + @PostConstruct + private void init() {} + + @Override + public void addOrUpdate(PreferenceCollection pc) { + preferences.put(pc.getKey(), pc); + } + + @Override + public PreferenceCollection get(String mainType, String otherType, String leftType, String rightType) { + PreferenceCollectionKey pck = new PreferenceCollectionKey(mainType, otherType, leftType, rightType); + return get(pck); + } + + @Override + public PreferenceCollection get(PreferenceCollectionKey pck) { + return preferences.get(pck); + } + + @Override + public HashMap getAllPreferences() { + return preferences; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + for(Entry entry : preferences.entrySet()) { + + PreferenceCollectionKey key = entry.getKey(); + PreferenceCollection col = entry.getValue(); + + sb.append("Preferencias para "); + sb.append(key.toString()); + sb.append("\n"); + sb.append(col.toString()); + + } + + return sb.toString(); + } + + @Override + public void clear() { + preferences.clear(); + } + +} diff --git a/bundles/flintstones.model.ahppreferences.service/.classpath b/bundles/flintstones.model.ahppreferences.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ahppreferences.service/.polyglot.META-INF b/bundles/flintstones.model.ahppreferences.service/.polyglot.META-INF new file mode 100644 index 0000000..735c8b0 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.ahppreferences.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.ahppreferences.service/.project b/bundles/flintstones.model.ahppreferences.service/.project new file mode 100644 index 0000000..a6251d8 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.ahppreferences.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362717 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.ahppreferences.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.ahppreferences.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..da27c7c --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.ahppreferences.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.ahppreferences.service +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Export-Package: flintstones.model.ahppreferences.service +Require-Bundle: flintstones.entity.ahppreferences, + flintstones.entity.preferences.preferencecollection diff --git a/bundles/flintstones.model.ahppreferences.service/build.properties b/bundles/flintstones.model.ahppreferences.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.ahppreferences.service/src/flintstones/model/ahppreferences/service/IProblemPreferencesService.java b/bundles/flintstones.model.ahppreferences.service/src/flintstones/model/ahppreferences/service/IProblemPreferencesService.java new file mode 100644 index 0000000..86672c9 --- /dev/null +++ b/bundles/flintstones.model.ahppreferences.service/src/flintstones/model/ahppreferences/service/IProblemPreferencesService.java @@ -0,0 +1,20 @@ +package flintstones.model.ahppreferences.service; + +import java.util.HashMap; + +import flintstones.entity.ahppreferences.PreferenceCollectionKey; +import flintstones.entity.preferences.preferencecollection.PreferenceCollection; + +public interface IProblemPreferencesService { + + void addOrUpdate(PreferenceCollection pc); + + PreferenceCollection get(PreferenceCollectionKey pck); + + PreferenceCollection get(String mainType, String otherType, String leftType, String rightType); + + HashMap getAllPreferences(); + + void clear(); + +} diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/.classpath b/bundles/flintstones.model.ahpsort.profileassignment.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/.polyglot.META-INF b/bundles/flintstones.model.ahpsort.profileassignment.provider/.polyglot.META-INF new file mode 100644 index 0000000..8d06afc --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.ahpsort.profileassignment.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/.project b/bundles/flintstones.model.ahpsort.profileassignment.provider/.project new file mode 100644 index 0000000..c17a6d0 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.ahpsort.profileassignment.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362718 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.ahpsort.profileassignment.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..dd5eae4 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.ahpsort.profileassignment.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.profileassignment.provider +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.model.ahpsort.profileassignment.service, + flintstones.entity.problemelement, + flintstones.entity.ahpsort.profileassignment, + javax.inject, + flintstones.model.problemelement.service, + org.eclipse.e4.core.contexts, + flintstones.model.ahppreferences.service, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + flintstones.application.constants, + org.eclipse.e4.ui.workbench +Service-Component: component.xml +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/build.properties b/bundles/flintstones.model.ahpsort.profileassignment.provider/build.properties new file mode 100644 index 0000000..6247cd0 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/component.xml b/bundles/flintstones.model.ahpsort.profileassignment.provider/component.xml new file mode 100644 index 0000000..2c4eb38 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/component.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/src/flintstones/model/ahpsort/profileassignment/provider/ProfileAssignmentServiceContextFunction.java b/bundles/flintstones.model.ahpsort.profileassignment.provider/src/flintstones/model/ahpsort/profileassignment/provider/ProfileAssignmentServiceContextFunction.java new file mode 100644 index 0000000..e9ec4b2 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/src/flintstones/model/ahpsort/profileassignment/provider/ProfileAssignmentServiceContextFunction.java @@ -0,0 +1,21 @@ +package flintstones.model.ahpsort.profileassignment.provider; + +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +public class ProfileAssignmentServiceContextFunction extends ContextFunction { + + @Override + public Object compute(IEclipseContext context, String contextKey) { + IProfileAssignmentService domainService = ContextInjectionFactory.make(ProfileAssignmentServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IProfileAssignmentService.class, domainService); + return domainService; + } + +} diff --git a/bundles/flintstones.model.ahpsort.profileassignment.provider/src/flintstones/model/ahpsort/profileassignment/provider/ProfileAssignmentServiceProvider.java b/bundles/flintstones.model.ahpsort.profileassignment.provider/src/flintstones/model/ahpsort/profileassignment/provider/ProfileAssignmentServiceProvider.java new file mode 100644 index 0000000..728804e --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.provider/src/flintstones/model/ahpsort/profileassignment/provider/ProfileAssignmentServiceProvider.java @@ -0,0 +1,139 @@ +package flintstones.model.ahpsort.profileassignment.provider; + +import java.util.HashMap; +import java.util.Map.Entry; + +import javax.inject.Inject; + +import flintstones.entity.problemelement.entities.SortingProfile; +import flintstones.entity.problemelement.entities.SortingProfile.SortingProfileType; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.model.ahpsort.profileassignment.service.IProfileAssignmentService; +import flintstones.model.problemelement.service.IProblemElementService; + +public class ProfileAssignmentServiceProvider implements IProfileAssignmentService { + + HashMap> assignments = new HashMap<>(); + + @Inject + IProblemElementService problemService; + + SortingProfileType type = SortingProfile.SortingProfileType.Central; + + @Override + public ProfileAssignment get(Expert e, Criterion c) { + HashMap map = assignments.get(e); + if(map == null) + return null; + return map.get(c); + } + + @Override + public ProfileAssignment create(Expert e, Criterion c) { + return new ProfileAssignment(e, c); + } + + @Override + public ProfileAssignment getOrDefault(Expert e, Criterion c) { + ProfileAssignment pa = get(e,c); + if(pa == null) + return create(e,c); + return pa; + } + + @Override + public void addOrUpdate(ProfileAssignment pa) { + + delete(pa.getExpert(), pa.getCriterion()); + + HashMap map = assignments.get(pa.getExpert()); + if(map == null) + map = new HashMap<>(); + + map.put(pa.getCriterion(), pa); + assignments.put(pa.getExpert(), map); + + for( SortingProfile profile : pa.getAllProfiles() ) { + profile.setOrder(-1); + if(problemService.getById(SortingProfile.Type, profile.getId()) == null) + problemService.add(profile); + } + + + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("\n"); + + for(Entry> entry : assignments.entrySet()) { + Expert e = entry.getKey(); + for( Entry entry2 : entry.getValue().entrySet()) { + Criterion c = entry2.getKey(); + for( SortingProfile profile : entry2.getValue().getAllProfiles() ) { + sb.append( e.getName() ); + sb.append(", "); + sb.append( c.getName() ); + sb.append(" -> "); + sb.append(profile.getName()); + sb.append("\n"); + } + } + } + + sb.append("\n\nTYPE: " + type.toString()); + return sb.toString(); + } + + @Override + public HashMap> getAll() { + return assignments; + } + + + @Override + public boolean delete(Expert e, Criterion c) { + HashMap map = assignments.get(e); + if(map == null) + return false; + + ProfileAssignment pa = map.get(c); + if(pa == null) + return false; + + for( SortingProfile profile : pa.getAllProfiles() ) { + problemService.delete(profile); + } + + return map.remove(c) != null; + } + + + @Override + public HashMap get(Expert e) { + HashMap map = assignments.get(e); + return map; + } + + + + @Override + public void clear() { + assignments.clear(); + } + + @Override + public void setType(SortingProfileType typex) { + this.type = typex; + } + + @Override + public SortingProfileType getType() { + return type; + } + + +} diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/.classpath b/bundles/flintstones.model.ahpsort.profileassignment.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/.polyglot.META-INF b/bundles/flintstones.model.ahpsort.profileassignment.service/.polyglot.META-INF new file mode 100644 index 0000000..4b0f016 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.ahpsort.profileassignment.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/.project b/bundles/flintstones.model.ahpsort.profileassignment.service/.project new file mode 100644 index 0000000..39183ce --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.ahpsort.profileassignment.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362719 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.ahpsort.profileassignment.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6d782d3 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.ahpsort.profileassignment.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.profileassignment.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.model.ahpsort.profileassignment.service +Require-Bundle: flintstones.entity.problemelement, + flintstones.entity.ahpsort.profileassignment, + org.eclipse.osgi +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/build.properties b/bundles/flintstones.model.ahpsort.profileassignment.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.ahpsort.profileassignment.service/src/flintstones/model/ahpsort/profileassignment/service/IProfileAssignmentService.java b/bundles/flintstones.model.ahpsort.profileassignment.service/src/flintstones/model/ahpsort/profileassignment/service/IProfileAssignmentService.java new file mode 100644 index 0000000..67a13b7 --- /dev/null +++ b/bundles/flintstones.model.ahpsort.profileassignment.service/src/flintstones/model/ahpsort/profileassignment/service/IProfileAssignmentService.java @@ -0,0 +1,30 @@ +package flintstones.model.ahpsort.profileassignment.service; + +import java.util.HashMap; +import flintstones.entity.ahpsort.profileassignment.ProfileAssignment; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.SortingProfile; + +public interface IProfileAssignmentService { + + ProfileAssignment get(Expert e, Criterion c); + + HashMap get(Expert e); + + ProfileAssignment create(Expert e, Criterion c); + + ProfileAssignment getOrDefault(Expert e, Criterion c); + + boolean delete(Expert e, Criterion c); + + void addOrUpdate(ProfileAssignment pa); + + HashMap> getAll(); + + void clear(); + + void setType(SortingProfile.SortingProfileType type); + + SortingProfile.SortingProfileType getType(); +} diff --git a/bundles/flintstones.model.application.provider/.classpath b/bundles/flintstones.model.application.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.application.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.application.provider/.polyglot.META-INF b/bundles/flintstones.model.application.provider/.polyglot.META-INF new file mode 100644 index 0000000..128ebda --- /dev/null +++ b/bundles/flintstones.model.application.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.application.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.application.provider/.project b/bundles/flintstones.model.application.provider/.project new file mode 100644 index 0000000..75deeb1 --- /dev/null +++ b/bundles/flintstones.model.application.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.application.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362720 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.application.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.application.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.application.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.application.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.application.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.application.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.application.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.application.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.application.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.application.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.application.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ecaad95 --- /dev/null +++ b/bundles/flintstones.model.application.provider/META-INF/MANIFEST.MF @@ -0,0 +1,32 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: flintstones.model.application.provider;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.application.service +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Service-Component: plugin.xml, + OSGI-INF/flintstones.application.model.service.ApplicationServiceProvider.xml +Bundle-ActivationPolicy: lazy +Require-Bundle: flintstones.model.application.service, + flintstones.helper.data.io, + org.eclipse.e4.core.services, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.di, + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.ui.workbench, + javax.inject, + org.eclipse.jface, + flintstones.application.constants, + flintstones.helper.extensionpoint, + flintstones.helper.git, + javax.annotation, + org.eclipse.nebula.widgets.opal.notifier, + flintstones.helper.locale, + flintstones.application.debug +Export-Package: flintstones.application.model.service, + flintstones.application.model.service.handler +Import-Package: org.eclipse.core.runtime, + org.osgi.framework;version="1.9.0", + org.osgi.service.component.annotations;version="1.2.0" diff --git a/bundles/flintstones.model.application.provider/OSGI-INF/flintstones.application.model.service.ApplicationServiceProvider.xml b/bundles/flintstones.model.application.provider/OSGI-INF/flintstones.application.model.service.ApplicationServiceProvider.xml new file mode 100644 index 0000000..1830569 --- /dev/null +++ b/bundles/flintstones.model.application.provider/OSGI-INF/flintstones.application.model.service.ApplicationServiceProvider.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/bundles/flintstones.model.application.provider/OSGI-INF/l10n/bundle.properties b/bundles/flintstones.model.application.provider/OSGI-INF/l10n/bundle.properties new file mode 100644 index 0000000..447ea71 --- /dev/null +++ b/bundles/flintstones.model.application.provider/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,6 @@ +#Properties file for flintstones.model.application.provider +Bundle-Name = Service +extension-point.name = Language +language.chinese = Chinese +language.spanish = Spanish +language.english = English \ No newline at end of file diff --git a/bundles/flintstones.model.application.provider/OSGI-INF/l10n/bundle_es.properties b/bundles/flintstones.model.application.provider/OSGI-INF/l10n/bundle_es.properties new file mode 100644 index 0000000..9987702 --- /dev/null +++ b/bundles/flintstones.model.application.provider/OSGI-INF/l10n/bundle_es.properties @@ -0,0 +1,6 @@ +#Properties file for flintstones.model.application.provider +Bundle-Name = Service +extension-point.name = Language +language.chinese = Chino +language.spanish = Espaol +language.english = Ingls \ No newline at end of file diff --git a/bundles/flintstones.model.application.provider/build.properties b/bundles/flintstones.model.application.provider/build.properties new file mode 100644 index 0000000..f9ab1cd --- /dev/null +++ b/bundles/flintstones.model.application.provider/build.properties @@ -0,0 +1,7 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/,\ + plugin.xml,\ + OSGI-INF/l10n/bundle.properties +source.. = src/ diff --git a/bundles/flintstones.model.application.provider/plugin.xml b/bundles/flintstones.model.application.provider/plugin.xml new file mode 100644 index 0000000..bfbc974 --- /dev/null +++ b/bundles/flintstones.model.application.provider/plugin.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + diff --git a/bundles/flintstones.model.application.provider/schema/flintsonte.service.language.exsd b/bundles/flintstones.model.application.provider/schema/flintsonte.service.language.exsd new file mode 100644 index 0000000..4645b1d --- /dev/null +++ b/bundles/flintstones.model.application.provider/schema/flintsonte.service.language.exsd @@ -0,0 +1,123 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/ApplicationServiceProvider.java b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/ApplicationServiceProvider.java new file mode 100644 index 0000000..c89f816 --- /dev/null +++ b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/ApplicationServiceProvider.java @@ -0,0 +1,523 @@ +package flintstones.application.model.service; + +import java.io.File; +import java.io.IOException; +import java.text.MessageFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.eclipse.e4.core.services.nls.Translation; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.commands.MCommand; +import org.eclipse.e4.ui.model.application.commands.MParameter; +import org.eclipse.e4.ui.model.application.ui.MUIElement; +import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.model.application.ui.menu.ItemType; +import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; +import org.eclipse.e4.ui.model.application.ui.menu.MMenu; +import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; +import org.eclipse.e4.ui.workbench.UIEvents; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.e4.ui.workbench.modeling.EPartService; +import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.nebula.widgets.opal.notifier.INotificationClickedListener; +import org.eclipse.nebula.widgets.opal.notifier.NotifierColorsFactory.NotifierTheme; +import org.eclipse.nebula.widgets.opal.notifier.WNotifier; +import org.eclipse.swt.widgets.Display; +import org.osgi.service.component.annotations.Component; + +import flintstones.application.constants.ApplicationContants; +import flintstones.application.debug.handler.OpenSaveFileDebugHandler; +import flintstones.application.model.IApplicationService; +import flintstones.application.model.ProblemType; +import flintstones.application.model.service.handler.WindowCloseHandler; +import flintstones.application.model.service.messages.Messages; +import flintstones.helper.data.io.ClearData; +import flintstones.helper.data.io.FlintstonesIO; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.helper.git.GitInformation; +import flintstones.helper.locale.LocaleHelper; + +/** + * The Class ApplicationServiceProvider. Controls the status of the application + * using the concept of project stored on disk, unsaved changes and build id. + */ +@Component +public class ApplicationServiceProvider implements IApplicationService { + + /** The messages. */ + @Inject + @Translation + private Messages messages; + + /** The context. */ + @Inject + IEclipseContext context; + + /** The application. */ + @Inject + MApplication application; + + /** The model service. */ + @Inject + EModelService modelService; + + @Inject + MApplication app; + + @Inject + EPartService partService; + + @Inject + IEventBroker broker; + + /** The proyect path. */ + private String proyectPath; + + /** The saved. */ + boolean saved = true; + + /** The last save. */ + Date lastSave; + + /** The build hash. */ + String buildHash; + + /** The io version. */ + String ioVersion; + + // Problem type + ProblemType problemType = ProblemType.Ranking; + + /** + * Instantiates a new application service provider. + */ + public ApplicationServiceProvider() { + } + + /** + * Inits the. + */ + @PostConstruct + public void init() { + LocaleHelper.setLocale("en"); //$NON-NLS-1$ + this.buildHash = ContextInjectionFactory.make(GitInformation.class, this.context).getAppHash(); + this.newProblem(); + + loadLanguagesExtentionPoint(); + } + + /* + * (non-Javadoc) + * + * @see flintstones.application.model.IApplicationService#isSaved() + */ + @Override + public boolean isSaved() { + return this.saved; + } + + /* + * (non-Javadoc) + * + * @see flintstones.application.model.IApplicationService#getLastSave() + */ + @Override + public Date getLastSave() { + return this.lastSave; + } + + /* + * (non-Javadoc) + * + * @see flintstones.application.model.IApplicationService#getBuildHash() + */ + @Override + public String getBuildHash() { + return this.buildHash; + } + + /* + * (non-Javadoc) + * + * @see flintstones.application.model.IApplicationService#getIOVersion() + */ + @Override + public String getIOVersion() { + // TODO Auto-generated method stub x + return null; + } + + /* + * (non-Javadoc) + * + * @see flintstones.application.model.IApplicationService#newProblem() + */ + @Override + public void newProblem() { + + String filename = this.getNewFilename(true); + String path = this.getPath(filename); + + boolean reset = true; + if (!this.saved) + reset = this.getUnsavedConfirmation(); + + if (reset) { + System.out.println("!INFOFS Creando proyecto en " + path); //$NON-NLS-1$ + this.clearData(); + this.saveProblemAs(path); + } + + } + + @Override + public void clearData() { + ContextInjectionFactory.make(ClearData.class, this.context).execute(); + } + + /** + * Gets the savefile path . + * + * @param filename the filename + * @return the path + */ + private String getPath(String filename) { + // String folder = System.getProperty("user.home") + File.separator + "Desktop" + // + File.separator + "save"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + String folder = getFS4FolderPath() + File.separator + "save"; //$NON-NLS-1$ + String fullPath = folder + File.separator + filename; + + if (!new File(folder).exists()) + new File(folder).mkdirs(); + + return fullPath; + } + + @Override + public String getFS4FolderPath() { + String folder = System.getProperty("user.home") + File.separator + "flintstones"; //$NON-NLS-1$ //$NON-NLS-2$ + return folder; + } + + /** + * Gets the new filename using the current date. + * + * @param auto the auto + * @return the new filename + */ + private String getNewFilename(boolean auto) { + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); //$NON-NLS-1$ + String dateS = dateFormat.format(date); + + String template = "proyect-{0}{1}.flintstones"; //$NON-NLS-1$ + String file = MessageFormat.format(template, dateS, auto ? ".auto" : ""); //$NON-NLS-1$ //$NON-NLS-2$ + + return file; + } + + /* + * (non-Javadoc) + * + * @see flintstones.application.model.IApplicationService#loadProblem(java.lang. + * String) + */ + @Override + public void loadProblem(String filename) { + + this.clearData(); + + FlintstonesIO fio = ContextInjectionFactory.make(FlintstonesIO.class, this.context); + fio.load(filename); + this.setPath(filename); + + String pers = "flintstones.application.perspective.framework"; //$NON-NLS-1$ + + broker.send("TOPIC_WINDOW_TRIMBAR",pers); //$NON-NLS-1$ + this.changePerspective(pers); + + } + + /* + * (non-Javadoc) + * + * @see + * flintstones.application.model.IApplicationService#saveProblemAs(java.lang. + * String) + */ + @Override + public void saveProblemAs(String file) { + + this.setPath(file); + this.saveProblem(); + + } + + /* + * (non-Javadoc) + * + * @see flintstones.application.model.IApplicationService#saveProblem() + */ + @Override + public void saveProblem() { + FlintstonesIO fio = ContextInjectionFactory.make(FlintstonesIO.class, this.context); + try { + fio.writeFile(this.proyectPath); + } catch (IOException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + + this.lastSave = new Date(); + this.saved = true; + + new WNotifier(messages.saved, messages.saved_successfully, NotifierTheme.BLUE_THEME).onClick(new INotificationClickedListener() { //$NON-NLS-1$ //$NON-NLS-2$ + + @Override + public void onNotificationClick() { + ContextInjectionFactory.make(OpenSaveFileDebugHandler.class, context).execute(); + } + }, true) + .send(); + + } + + /** + * Sets the savefile path. + * + * @param newPath the new path + */ + private void setPath(String newPath) { + this.proyectPath = newPath; + this.refreshTitle(); + } + + /** + * Refresh the window itle. + */ + private void refreshTitle() { + String titleTemplate = this.messages.title_template; + String title = MessageFormat.format(titleTemplate, this.proyectPath, + !this.saved ? this.messages.unsaved_changes : "", //$NON-NLS-1$ + this.buildHash != null ? this.buildHash : "" //$NON-NLS-1$ + ); + MWindow window = (MWindow) this.modelService.find("flintstones.application.trimmedwindow.flintstones", //$NON-NLS-1$ + this.application); + window.setLabel(title); + } + + /** + * Register close event. + * + * @param application the application + * @param modelService the model service + */ + @Inject + @Optional + public void registerCloseEvent(@UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) MApplication application, + EModelService modelService) { + MWindow window = (MWindow) modelService.find("flintstones.application.trimmedwindow.flintstones", application); //$NON-NLS-1$ + WindowCloseHandler handler = ContextInjectionFactory.make(WindowCloseHandler.class, this.context); + window.getContext().set(IWindowCloseHandler.class, handler); + } + + /** + * Gets the unsaved confirmation if necesary. + * + * @return the unsaved confirmation + */ + private boolean getUnsavedConfirmation() { + if (this.devMode()) + return true; + + return MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), this.messages.button_confirm, + this.messages.unsaved_changes_full); + } + + /* + * (non-Javadoc) + * + * @see flintstones.application.model.IApplicationService#close() + */ + @Override + public boolean close() { + if (!this.saved) + return this.getUnsavedConfirmation(); + return true; + } + + /** + * Deprecado para que se dibuje en rojo. No hay problema en usarlo. + * + * @deprecated Deprecado para que se dibuje en rojo. No hay problema en usarlo. + */ + @Override + public boolean devMode() { + String[] args = Platform.getCommandLineArgs(); + boolean status = Arrays.asList(args).stream().anyMatch(flag -> flag.equals("-development")); //$NON-NLS-1$ + + return status; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("proyectPath ==> " + this.proyectPath + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + sb.append("saved ==> " + this.saved + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + sb.append("lastSave ==> " + this.lastSave.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + sb.append("buildHash ==> " + this.buildHash + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ +// sb.append("ioVersion ==> " + this.ioVersion + "\n"); + sb.append("currentLocale ==> " + LocaleHelper.getLocale() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + return sb.toString(); + } + + @Override + public void changePerspective(String perspectiveId) { + List perspectives = modelService.findElements(app, perspectiveId, MPerspective.class, null); + + // switch to perspective with the ID if found + if (!perspectives.isEmpty()) + partService.switchPerspective(perspectives.get(0)); + } + + @Override + public boolean isFlagEnabled(String key) { + String[] args = Platform.getCommandLineArgs(); + boolean status = Arrays.asList(args).stream().anyMatch(flag -> flag.equals("-" + key)); //$NON-NLS-1$ + return status; + } + + @Override + public String getSavePath() { + return proyectPath; + } + + private void loadLanguagesExtentionPoint() { + BaseRegistry reg = new BaseRegistry("flintsonte.service.language"); //$NON-NLS-1$ + + MWindow window = (MWindow) this.modelService.find(ApplicationContants.MWindow_Main, this.application); + + int indiceMenu = -1; + String slug = "", label = "", icon_uri = "", fullId; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + MMenu mainMenu = window.getMainMenu(); + List elements = mainMenu.getChildren(); + + // Buscamos el menu de idiomas en la aplicacion. + for (int i = 0; i < elements.size(); i++) { + if (elements.get(i).getElementId().equals("flintstones.application.menu.locale")) { //$NON-NLS-1$ + indiceMenu = i; + break; + } + } + + MMenu menu = (MMenu) elements.get(indiceMenu); + + // Obtenemos los puntos de extesion. + ExtensionRegistry[] br = reg.getAllRegistries(); + + for (int i = 0; i < br.length; i++) { + + slug = br[i].getAttribute("slug"); //$NON-NLS-1$ + label = br[i].getAttribute("label"); //$NON-NLS-1$ + icon_uri = br[i].getAttribute("icon_uri"); //$NON-NLS-1$ + fullId = "flintstones.application.menu." + slug; //$NON-NLS-1$ + + String commandId = ApplicationContants.MCommand_Global_Selectlocale; + + // MCommand command = createCommand(slug); + MCommand command = modelService.findElements(app, commandId, MCommand.class, null).get(0); + MHandledMenuItem dynamicMenuItem = createMenu(label, icon_uri, fullId, command); + + // addition + menu.getChildren().add(dynamicMenuItem); + + } + + } + + // https://wiki.eclipse.org/Eclipse4/RCP/FAQ + // Why is my parameterized handler not triggered? + + private MHandledMenuItem createMenu(String label, String icon_uri, String fullId, MCommand command) { + MHandledMenuItem dynamicMenuItem = modelService.createModelElement(MHandledMenuItem.class); + dynamicMenuItem.setLabel(label); + dynamicMenuItem.setType(ItemType.PUSH); + dynamicMenuItem.setIconURI(icon_uri); + + dynamicMenuItem.setCommand(command); + + MParameter parameter = modelService.createModelElement(MParameter.class); + parameter.setName(ApplicationContants.MParameter_Global_Selectlocale); + parameter.setValue(fullId); + dynamicMenuItem.getParameters().add(parameter); + + return dynamicMenuItem; + } + + @Override + public String getCurrentLocale() { + return LocaleHelper.getLocale(); + } + + @Override + public void setCurrentLocale(String slug) { + LocaleHelper.setLocale(slug); + } + + private void setVisible(String elementId, boolean status) { + MUIElement uiElement = (MUIElement) modelService.find(elementId, this.application); // $NON-NLS-1$ + uiElement.setVisible(status); + } + + String MPartStack_Domain = "flintstones.framework.ui.partstack.domains"; //$NON-NLS-1$ + String MPartStack_DomainViewer = "flintstones.framework.ui.partstack.domain"; //$NON-NLS-1$ + String MPartStack_AHPClasses = "flintstones.framework.ui.partstack.ahpclasses"; //$NON-NLS-1$ + String MPartStack_AHPPRofiles = "flintstones.framework.ui.partstack.ahpprofiles"; //$NON-NLS-1$ + String MPartStack_AHPViewer = "flintstones.framework.ui.partstack.ahpviewer"; //$NON-NLS-1$ + + @Override + public void launchProblem(ProblemType type) { + + problemType = type; + + boolean isRanking = type.equals(ProblemType.Ranking); + boolean isSorting = type.equals(ProblemType.Sorting); + + setVisible(ApplicationContants.MPartStack_Domain, true); + + if (isRanking) { + setVisible(ApplicationContants.MPartStack_DomainViewer, false); + setVisible(ApplicationContants.MPartStack_AHPClasses, !isRanking); + setVisible(ApplicationContants.MPartStack_AHPPRofiles, !isRanking); + setVisible(ApplicationContants.MPartStack_AHPViewer, !isRanking); + } + + if(isSorting) { + setVisible(ApplicationContants.MPartStack_DomainViewer, !isSorting); + setVisible(ApplicationContants.MPartStack_AHPClasses, isSorting); + setVisible(ApplicationContants.MPartStack_AHPPRofiles, isSorting); + setVisible(ApplicationContants.MPartStack_AHPViewer, isSorting); + } + } + + @Override + public ProblemType getProblemType() { + return problemType; + } +} diff --git a/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/handler/WindowCloseHandler.java b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/handler/WindowCloseHandler.java new file mode 100644 index 0000000..c44ddcd --- /dev/null +++ b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/handler/WindowCloseHandler.java @@ -0,0 +1,28 @@ +package flintstones.application.model.service.handler; + +import javax.inject.Inject; + +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler; + +import flintstones.application.model.IApplicationService; + +/** + * The Class WindowCloseHandler. + */ +public class WindowCloseHandler implements IWindowCloseHandler { + + /** The app service. */ + @Inject + IApplicationService appService; + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler#close(org.eclipse.e4 + * .ui.model.application.ui.basic.MWindow) */ + @Override + public boolean close(MWindow window) { + return this.appService.close(); + } +} diff --git a/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/Messages.java b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/Messages.java new file mode 100644 index 0000000..2d30ef8 --- /dev/null +++ b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/Messages.java @@ -0,0 +1,16 @@ +package flintstones.application.model.service.messages; + +import org.eclipse.e4.core.services.nls.Message; + +@Message +@SuppressWarnings("javadoc") +public class Messages { + + public String title_template; + public String unsaved_changes; + public String button_confirm; + public String unsaved_changes_full; + public String saved; + public String saved_successfully; + +} diff --git a/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/messages.properties b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/messages.properties new file mode 100644 index 0000000..f95f6eb --- /dev/null +++ b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/messages.properties @@ -0,0 +1,7 @@ +saved=Saved +saved_successfully=Saved successfully +X=1.1.1.1 +title_template=Flintstones - {0}{1} - {2} +unsaved_changes= (There are unsaved changes) +button_confirm=Confirm +unsaved_changes_full=There are unsaved changes. Changes will be lost. \ No newline at end of file diff --git a/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/messages_es.properties b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/messages_es.properties new file mode 100644 index 0000000..e031975 --- /dev/null +++ b/bundles/flintstones.model.application.provider/src/flintstones/application/model/service/messages/messages_es.properties @@ -0,0 +1,7 @@ +saved=Guardado +saved_successfully=Guardado con xito +X=1.1.1.2 +title_template=Flintstones - {0}{1} - {2} +unsaved_changes= (Hay cambios sin guardar) +button_confirm=Confirmar +unsaved_changes_full=Hay informacin sin guardar. Si continua la perder \ No newline at end of file diff --git a/bundles/flintstones.model.application.service/.classpath b/bundles/flintstones.model.application.service/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.model.application.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.application.service/.polyglot.META-INF b/bundles/flintstones.model.application.service/.polyglot.META-INF new file mode 100644 index 0000000..68f28cf --- /dev/null +++ b/bundles/flintstones.model.application.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.application.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Model + diff --git a/bundles/flintstones.model.application.service/.project b/bundles/flintstones.model.application.service/.project new file mode 100644 index 0000000..6bf6cb7 --- /dev/null +++ b/bundles/flintstones.model.application.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.application.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362720 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.application.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.application.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.application.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.application.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.application.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..fb1077b --- /dev/null +++ b/bundles/flintstones.model.application.service/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +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.release=enabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/flintstones.model.application.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.application.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.application.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.application.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.application.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0e288d9 --- /dev/null +++ b/bundles/flintstones.model.application.service/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Model +Bundle-SymbolicName: flintstones.model.application.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.application.model +Export-Package: flintstones.application.model +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/bundles/flintstones.model.application.service/build.properties b/bundles/flintstones.model.application.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.application.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.application.service/src/flintstones/application/model/IApplicationService.java b/bundles/flintstones.model.application.service/src/flintstones/application/model/IApplicationService.java new file mode 100644 index 0000000..08f9449 --- /dev/null +++ b/bundles/flintstones.model.application.service/src/flintstones/application/model/IApplicationService.java @@ -0,0 +1,113 @@ +package flintstones.application.model; + +import java.util.Date; + +/** + * The Interface IApplicationService. + */ +public interface IApplicationService { + + /** + * Checks if is every change is saved. + * + * @return true, if is saved + */ + boolean isSaved(); + + /** + * Gets the last save date. + * + * @return the last save + */ + Date getLastSave(); + + /** + * Gets the hash of the current build. AKA last git short hash. + * + * @return the builds the hash + */ + String getBuildHash(); + + /** + * Gets the IO version. + * + * @return the IO version + */ + String getIOVersion(); + + /** + * Loads a problem. + * + * @param filename the filename + */ + void loadProblem(String filename); + + /** + * Saves a problem. + */ + void saveProblem(); + + /** + * Creates a new problem deleting the previous one after a confirmation. + */ + void newProblem(); + + /** + * Save a problem as the given filename. + * + * @param file the file + */ + void saveProblemAs(String file); + + /** + * Close the software. + * + * @return true, if successful + */ + boolean close(); + + /** + * Clear data. + */ + void clearData(); + + /** + * Deprecado para que se dibuje en rojo. No hay problema en usarlo. + * + * @return true, if successful + * @deprecated Deprecado para que se dibuje en rojo. No hay problema en usarlo. + */ + boolean devMode(); + + /** + * Change perspective. + * + * @param perspectiveId the perspective id + */ + void changePerspective(String perspectiveId); + + /** + * Checks if is flag enabled. + * + * @param key the key + * @return true, if is flag enabled + */ + boolean isFlagEnabled(String key); + + /** + * Gets the save path. + * + * @return the save path + */ + String getSavePath(); + + String getCurrentLocale(); + + void setCurrentLocale(String slug); + + String getFS4FolderPath(); + + ProblemType getProblemType(); + + void launchProblem(ProblemType type); +} diff --git a/bundles/flintstones.model.application.service/src/flintstones/application/model/ProblemType.java b/bundles/flintstones.model.application.service/src/flintstones/application/model/ProblemType.java new file mode 100644 index 0000000..299856b --- /dev/null +++ b/bundles/flintstones.model.application.service/src/flintstones/application/model/ProblemType.java @@ -0,0 +1,5 @@ +package flintstones.application.model; + +public enum ProblemType { + Ranking, Sorting +} diff --git a/bundles/flintstones.model.domain.provider/.classpath b/bundles/flintstones.model.domain.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.domain.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.domain.provider/.polyglot.META-INF b/bundles/flintstones.model.domain.provider/.polyglot.META-INF new file mode 100644 index 0000000..25f9ef0 --- /dev/null +++ b/bundles/flintstones.model.domain.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.domain.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.domain.provider/.project b/bundles/flintstones.model.domain.provider/.project new file mode 100644 index 0000000..41fc8c8 --- /dev/null +++ b/bundles/flintstones.model.domain.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.domain.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362721 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.domain.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.domain.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.domain.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.domain.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.domain.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.domain.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.domain.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.domain.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.domain.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.domain.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.domain.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d187766 --- /dev/null +++ b/bundles/flintstones.model.domain.provider/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.domain.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.domain.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: javax.inject, + org.eclipse.e4.core.contexts, + flintstones.model.domain.service, + flintstones.entity.domain, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + flintstones.helper.extensionpoint, + javax.annotation +Service-Component: component.xml +Bundle-ActivationPolicy: lazy +Export-Package: flintstones.model.domain.provider +Import-Package: org.eclipse.e4.core.services.nls diff --git a/bundles/flintstones.model.domain.provider/build.properties b/bundles/flintstones.model.domain.provider/build.properties new file mode 100644 index 0000000..6247cd0 --- /dev/null +++ b/bundles/flintstones.model.domain.provider/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml diff --git a/bundles/flintstones.model.domain.provider/component.xml b/bundles/flintstones.model.domain.provider/component.xml new file mode 100644 index 0000000..0d49671 --- /dev/null +++ b/bundles/flintstones.model.domain.provider/component.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/bundles/flintstones.model.domain.provider/src/flintstones/model/domain/provider/DomainServiceContextFunction.java b/bundles/flintstones.model.domain.provider/src/flintstones/model/domain/provider/DomainServiceContextFunction.java new file mode 100644 index 0000000..16eed6a --- /dev/null +++ b/bundles/flintstones.model.domain.provider/src/flintstones/model/domain/provider/DomainServiceContextFunction.java @@ -0,0 +1,27 @@ +package flintstones.model.domain.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; +import flintstones.model.domain.service.IDomainService; + +/** + * The Class DomainServiceContextFunction add the Domain Service instance to global context. + */ +public class DomainServiceContextFunction extends ContextFunction { + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core. + * contexts.IEclipseContext, java.lang.String) */ + @Override + public Object compute(IEclipseContext context, String contextKey) { + IDomainService domainService = ContextInjectionFactory.make(DomainServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IDomainService.class, domainService); + return domainService; + } +} diff --git a/bundles/flintstones.model.domain.provider/src/flintstones/model/domain/provider/DomainServiceProvider.java b/bundles/flintstones.model.domain.provider/src/flintstones/model/domain/provider/DomainServiceProvider.java new file mode 100644 index 0000000..b027119 --- /dev/null +++ b/bundles/flintstones.model.domain.provider/src/flintstones/model/domain/provider/DomainServiceProvider.java @@ -0,0 +1,158 @@ +package flintstones.model.domain.provider; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainMockup; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.model.domain.service.IDomainService; + + +/** + * The Class DomainServiceProvider implements {@link flintstones.domain.service.IDomainService}. + */ +class DomainServiceProvider implements IDomainService{ + + @Inject + IEclipseContext context; + + private BaseRegistry domainReg; + private BaseRegistry domainCategoryReg; + + /** The domain list. */ + private final LinkedHashMap domains = new LinkedHashMap<>(); + + /** + * Instantiates a new domain service provider. + */ + public DomainServiceProvider() { + } + + /** + * Initialize. + */ + @PostConstruct + private void initialize() { + domainReg = new BaseRegistry(Domain.EXTENSION_POINT); + domainCategoryReg = new BaseRegistry(Domain.EXTENSION_POINT_CATEGORY); + } + + @Override + public Domain create(String id) { + Domain domain = (Domain) domainReg.instantiate(id, context); + domain.setType(id); + + return domain; + } + + @Override + public void add(Domain d) { + if(domains.get(d.getId()) != null) + throw new RuntimeException("Element already existed domainService.add("+ d.getName()+ ")"); + + d.updateId(); + domains.put(d.getId(), d); + } + + /* (non-Javadoc) + * + * @see flintstones.domain.service.IDomainService#getAll() */ + @Override + public Domain[] getAll() { + return domains.values().toArray(new Domain[domains.values().size()]); + } + + + @Override + public Domain[] getAll(String type) { + List domainsType = new ArrayList<>(); + + Domain[] domains = this.domains.values().toArray(new Domain[this.domains.values().size()]); + for(Domain domain: domains) { + if(domain.getType().equals(type)) + domainsType.add(domain); + } + + return domainsType.toArray(new Domain[domainsType.size()]); + } + + /* (non-Javadoc) + * + * @see flintstones.domain.service.IDomainService#getById(java.lang.String) */ + @Override + public Domain getByName(String name) { + for(String id: domains.keySet()) { + if(domains.get(id).getName().equals(name)) + return domains.get(id); + } + return null; + } + + @Override + public Domain getById(String id) { + return domains.get(id); + } + + @Override + public Domain removeDomain(String id) { + Domain d = domains.remove(id); + return d; + } + + @Override + public void clear() { + domains.clear(); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + for (Domain d : domains.values()) + sb.append(d.getName() + " ==> " + d.toString() + "\n"); + + return sb.toString(); + + } + + @Override + public DomainMockup[] getMockupDomains() { + + ArrayList mockups = new ArrayList<>(); + ExtensionRegistry[] categories = domainCategoryReg.getAllRegistries(); + + for(ExtensionRegistry categoryReg : categories) { + + String categoryId = categoryReg.getAttribute("uid"); + String categoryLabel = categoryReg.getAttribute("label"); + + DomainMockup parentMockup = new DomainMockup(categoryLabel); + mockups.add(parentMockup); + + ExtensionRegistry[] domainErs = domainReg.getAllRegistriesWhere(Domain.Fields.category, categoryId); + for(ExtensionRegistry domainEr : domainErs ) { + String domainId = domainEr.getAttribute(Domain.Fields.uid); + String domainLabel = domainEr.getAttribute(Domain.Fields.label); + DomainMockup mockup = new DomainMockup(domainId, domainLabel, categoryLabel); + parentMockup.addDomain(mockup); + } + + } + + return mockups.toArray(new DomainMockup[0]); + } + + @Override + public boolean exists(String id) { + return domains.get(id) != null; + } + +} diff --git a/bundles/flintstones.model.domain.service/.classpath b/bundles/flintstones.model.domain.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.domain.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.domain.service/.polyglot.META-INF b/bundles/flintstones.model.domain.service/.polyglot.META-INF new file mode 100644 index 0000000..b7e3bc0 --- /dev/null +++ b/bundles/flintstones.model.domain.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.domain.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.domain.service/.project b/bundles/flintstones.model.domain.service/.project new file mode 100644 index 0000000..82ab16b --- /dev/null +++ b/bundles/flintstones.model.domain.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.domain.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362721 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.domain.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.domain.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.domain.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.domain.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.domain.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.domain.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.domain.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.domain.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.domain.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.domain.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.domain.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..dea3c9f --- /dev/null +++ b/bundles/flintstones.model.domain.service/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.domain.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.domain.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.domain;visibility:=reexport +Export-Package: flintstones.model.domain.service diff --git a/bundles/flintstones.model.domain.service/build.properties b/bundles/flintstones.model.domain.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.domain.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.domain.service/src/flintstones/model/domain/service/IDomainService.java b/bundles/flintstones.model.domain.service/src/flintstones/model/domain/service/IDomainService.java new file mode 100644 index 0000000..bf0b090 --- /dev/null +++ b/bundles/flintstones.model.domain.service/src/flintstones/model/domain/service/IDomainService.java @@ -0,0 +1,77 @@ +package flintstones.model.domain.service; + +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.DomainMockup; + +/** + * Service + * IDomainService + * Nombre + * Description Creates and manage existing domains + * Provider + * DomainServiceProvider. + */ +public interface IDomainService { + + /** + * Return a Domain. + * + * @param id Type of domain + * @return Domain + */ + Domain create(String id); + + /** + * Add a domain. + * + * @param d The domain to add or update based on its name + */ + void add(Domain d) throws RuntimeException; + + /** + * Returns every domain. + * + * @return Every domain + */ + Domain[] getAll(); + + /** + * Returns every domain for a specific type. + * @param type The type of domain + * @return Every domain of a specific type + */ + Domain[] getAll(String type); + + /** + * Returns the domain with the given name. + * + * @param name the name + * @return The domain with the given name + */ + Domain getByName(String name); + + /** + * Returns the domain with the given Id. + * + * @param id the id + * @return The domain with the given Id + */ + Domain getById(String id); + + /** + * @param name The name of the domain to be deleted + */ + Domain removeDomain(String name); + + /** + * Clear the data save in the service/model. Removes each domain and resets any state var. + */ + void clear(); + + DomainMockup[] getMockupDomains(); + + boolean exists(String name); + + + +} diff --git a/bundles/flintstones.model.domain.ui.provider/.classpath b/bundles/flintstones.model.domain.ui.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.domain.ui.provider/.polyglot.META-INF b/bundles/flintstones.model.domain.ui.provider/.polyglot.META-INF new file mode 100644 index 0000000..5cc87ed --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.domain.ui.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.domain.ui.provider/.project b/bundles/flintstones.model.domain.ui.provider/.project new file mode 100644 index 0000000..43a717b --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.domain.ui.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362722 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.domain.ui.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.domain.ui.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ac54e6c --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.domain.ui.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.domain.ui.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.model.domain.ui.service, + flintstones.helper.extensionpoint, + flintstones.entity.domain.ui, + flintstones.entity.domain.ui.chart, + flintstones.entity.domain, + flintstones.entity.domain.ui.dialog, + org.eclipse.jface, + org.eclipse.e4.ui.model.workbench, + javax.inject +Bundle-ActivationPolicy: lazy +Service-Component: component.xml diff --git a/bundles/flintstones.model.domain.ui.provider/build.properties b/bundles/flintstones.model.domain.ui.provider/build.properties new file mode 100644 index 0000000..6247cd0 --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml diff --git a/bundles/flintstones.model.domain.ui.provider/component.xml b/bundles/flintstones.model.domain.ui.provider/component.xml new file mode 100644 index 0000000..045c7ee --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/component.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bundles/flintstones.model.domain.ui.provider/src/flintstones/model/domain/ui/provider/DomainUIServiceContextFunction.java b/bundles/flintstones.model.domain.ui.provider/src/flintstones/model/domain/ui/provider/DomainUIServiceContextFunction.java new file mode 100644 index 0000000..44e6c6e --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/src/flintstones/model/domain/ui/provider/DomainUIServiceContextFunction.java @@ -0,0 +1,27 @@ +package flintstones.model.domain.ui.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.model.domain.ui.service.IDomainUIService; +/** + * The Class DomainServiceContextFunction add the Domain Service instance to global context. + */ +public class DomainUIServiceContextFunction extends ContextFunction { + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core. + * contexts.IEclipseContext, java.lang.String) */ + @Override + public Object compute(IEclipseContext context, String contextKey) { + IDomainUIService domainService = ContextInjectionFactory.make(DomainUIServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IDomainUIService.class, domainService); + return domainService; + } +} diff --git a/bundles/flintstones.model.domain.ui.provider/src/flintstones/model/domain/ui/provider/DomainUIServiceProvider.java b/bundles/flintstones.model.domain.ui.provider/src/flintstones/model/domain/ui/provider/DomainUIServiceProvider.java new file mode 100644 index 0000000..bad3fe6 --- /dev/null +++ b/bundles/flintstones.model.domain.ui.provider/src/flintstones/model/domain/ui/provider/DomainUIServiceProvider.java @@ -0,0 +1,173 @@ +package flintstones.model.domain.ui.provider; + +import java.security.InvalidParameterException; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.DomainUI; +import flintstones.entity.domain.ui.chart.DomainChart; +import flintstones.entity.domain.ui.dialog.DomainDialog; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.model.domain.ui.service.IDomainUIService; + +/** + * The Class DomainUIServiceProvider. + * + * @author Sinbad 2 + * Service provided for Domain UI ( create domain, modify domain and domain chart ) + */ +class DomainUIServiceProvider implements IDomainUIService { + + /** The chart extension point. */ + private final String CHART_EXTENSION_POINT = "flintstones.domain.ui.chart.extensionpoint"; //$NON-NLS-1$ + + /** The new domain dialog extension point. */ + private final String NEW_DOMAIN_DIALOG_EXTENSION_POINT = "flintstones.domain.ui.new.dialog.extensionpoint"; //$NON-NLS-1$ + + /** The modify domain dialog extension point. */ + private final String MODIFY_DOMAIN_DIALOG_EXTENSION_POINT = "flintstones.domain.ui.modify.dialog.extensionpoint"; //$NON-NLS-1$ + + /** The chart registry. */ + private final BaseRegistry chartReg; + + /** The new domain dialog registry. */ + private final BaseRegistry newReg; + + /** The modify domain dialog registry. */ + private final BaseRegistry modReg; + + /** The context. */ + @Inject + IEclipseContext context; + + private enum registries { + newdialog, modifydialog, chart + }; + + /** + * Instantiates a new domain UI service provider. + */ + public DomainUIServiceProvider() { + this.chartReg = new BaseRegistry(this.CHART_EXTENSION_POINT); + this.chartReg.setLabel_implementation(DomainUI.Fields.chart); + this.newReg = new BaseRegistry(this.NEW_DOMAIN_DIALOG_EXTENSION_POINT); + this.modReg = new BaseRegistry(this.MODIFY_DOMAIN_DIALOG_EXTENSION_POINT); + } + + /* (non-Javadoc) + * + * @see + * flintstones.domain.ui.service.IDomainUIService#getDescriptionNewDomainDialog( + * java.lang.String) */ + @Override + public String getDescriptionNewDomainDialog(String id) { + ExtensionRegistry registry = this.newReg.getFirstRegistryWhere(DomainUI.Fields.uid, id); + return registry.getAttribute(DomainUI.Fields.description); + } + + /* (non-Javadoc) + * + * @see + * flintstones.domain.ui.service.IDomainUIService#newDomainDialog(flintstones. + * domain.Domain, java.lang.String) */ + @Override + public DomainDialog newDomainDialog(Domain domain, String id) { + DomainDialog result = (DomainDialog) this.newReg.instantiate(id, this.context); + result.setDomainTop(domain); + return result; + } + + /* (non-Javadoc) + * + * @see + * flintstones.domain.ui.service.IDomainUIService#modifyDomainDialog(flintstones + * .domain.Domain, java.lang.String) */ + @Override + public DomainDialog modifyDomainDialog(Domain domain) { + + + String dialogId = getModifyDomainDialogId(domain.getType()); + ExtensionRegistry er = modReg.getFirstRegistryWhere(DomainUI.Fields.uid,dialogId); + if(er == null) + return null; + + DomainDialog result = (DomainDialog) this.modReg.instantiate(dialogId, this.context); + result.setDomainTop(domain); + return result; + } + + + + /* (non-Javadoc) + * + * @see + * flintstones.domain.ui.service.IDomainUIService#getExtensionIdsForDomain(java. + * lang.String) */ + @Override + public String[] getExtensionIdsForDomain(String domain, String part) { + BaseRegistry reg = getBaseRegistry(part); + return reg.getAllAttributesWhere(DomainUI.Fields.domain, domain, DomainUI.Fields.uid); + } + + /** + * Gets the requested base registry. + * + * @param part the part "chart","modify","new" + * @return the base registry + */ + private BaseRegistry getBaseRegistry(String part) { + + // Compat. fix + if (part.equals("new")) //$NON-NLS-1$ + part = "newdialog"; //$NON-NLS-1$ + else if (part.equals("modify")) //$NON-NLS-1$ + part = "modifydialog"; //$NON-NLS-1$ + + if (part.equals(registries.chart.toString())) + return this.chartReg; + else if (part.equals(registries.newdialog.toString())) + return this.newReg; + else if (part.equals(registries.modifydialog.toString())) + return this.modReg; + else + throw new InvalidParameterException("Part no valida " + part); //$NON-NLS-1$ + } + + private String getExtensionNameForDomain(String domain, String part) { + BaseRegistry reg = this.getBaseRegistry(part); + ExtensionRegistry e = reg.getFirstRegistryWhere(DomainUI.Fields.domain, domain); + + if(e == null) + return null; + + return e.getAttribute(DomainUI.Fields.uid); + } + + @Override + public DomainChart createChart(String domainId) { + String chartId = getExtensionNameForDomain(domainId, "chart"); + + // Support for chart-less domains + ExtensionRegistry reg = chartReg.getFirstRegistryWhere(DomainUI.Fields.uid, chartId); + if(reg == null) + return null; + + if( reg.getAttribute("chart") == null ) + return null; + + DomainChart result = (DomainChart) chartReg.instantiate(chartId, this.context); + return result; + } + + @Override + public String getModifyDomainDialogId(String domainType) { + String[] dialogIds = getExtensionIdsForDomain(domainType,"modify"); + String dialogId = dialogIds[0]; + return dialogId; + } + + +} diff --git a/bundles/flintstones.model.domain.ui.service/.classpath b/bundles/flintstones.model.domain.ui.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.domain.ui.service/.polyglot.META-INF b/bundles/flintstones.model.domain.ui.service/.polyglot.META-INF new file mode 100644 index 0000000..9321994 --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.domain.ui.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.domain.ui.service/.project b/bundles/flintstones.model.domain.ui.service/.project new file mode 100644 index 0000000..176ee1a --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.domain.ui.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362722 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.domain.ui.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.domain.ui.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9a3eecb --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.domain.ui.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.domain.ui.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.model.domain.ui.service +Require-Bundle: flintstones.helper.extensionpoint, + flintstones.entity.domain, + flintstones.entity.domain.ui.chart, + flintstones.entity.domain.ui.dialog diff --git a/bundles/flintstones.model.domain.ui.service/build.properties b/bundles/flintstones.model.domain.ui.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.domain.ui.service/src/flintstones/model/domain/ui/service/IDomainUIService.java b/bundles/flintstones.model.domain.ui.service/src/flintstones/model/domain/ui/service/IDomainUIService.java new file mode 100644 index 0000000..1613cc1 --- /dev/null +++ b/bundles/flintstones.model.domain.ui.service/src/flintstones/model/domain/ui/service/IDomainUIService.java @@ -0,0 +1,45 @@ +package flintstones.model.domain.ui.service; + +import flintstones.entity.domain.Domain; +import flintstones.entity.domain.ui.chart.DomainChart; +import flintstones.entity.domain.ui.dialog.DomainDialog; + +/** + * @author Interface for the Domain UI service provider + * + */ +public interface IDomainUIService { + + // NEW API + public DomainChart createChart(String domainId); + + /** + * @param id The Extension Point ID + * @return The description of the given Extension Point Create Dialog + */ + public String getDescriptionNewDomainDialog(String id); + + /** + * @param domain The domain to be linked with the Dialog + * @param newDomainDialogId The id of the extension point + * @return The dialog to create the domain + */ + public DomainDialog newDomainDialog(Domain domain, String newDomainDialogId); + + /** + * @param oldDomain The domain to be linked with the Dialog + * @param modifyDomainDialogId The id of the extension point + * @return The dialog to modify the domain + */ + public DomainDialog modifyDomainDialog(Domain oldDomain); + + /** + * @param domain The id/name of the domain extension point + * @param domainId The id/name of the domain extension point + * @param type The type new/modify/chart of the extension needed in return + * @return The type new/modify/chart of the extension needed in return + */ + String[] getExtensionIdsForDomain(String domain, String part); + + String getModifyDomainDialogId(String domainType); +} diff --git a/bundles/flintstones.model.engine.r.provider/.classpath b/bundles/flintstones.model.engine.r.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.engine.r.provider/.polyglot.META-INF b/bundles/flintstones.model.engine.r.provider/.polyglot.META-INF new file mode 100644 index 0000000..650d41f --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.engine.r.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.engine.r.provider/.project b/bundles/flintstones.model.engine.r.provider/.project new file mode 100644 index 0000000..b1fa16d --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.engine.r.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362723 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.engine.r.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.engine.r.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a6d4a93 --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.engine.r.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.engine.r.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.model.engine.r.service, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + javax.inject, + javax.annotation +Service-Component: component.xml +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.model.engine.r.provider/build.properties b/bundles/flintstones.model.engine.r.provider/build.properties new file mode 100644 index 0000000..6247cd0 --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml diff --git a/bundles/flintstones.model.engine.r.provider/component.xml b/bundles/flintstones.model.engine.r.provider/component.xml new file mode 100644 index 0000000..9664786 --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/component.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/bundles/flintstones.model.engine.r.provider/src/flintstones/model/engine/r/provider/REngineServiceContextFunction.java b/bundles/flintstones.model.engine.r.provider/src/flintstones/model/engine/r/provider/REngineServiceContextFunction.java new file mode 100644 index 0000000..183c7c1 --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/src/flintstones/model/engine/r/provider/REngineServiceContextFunction.java @@ -0,0 +1,18 @@ +package flintstones.model.engine.r.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; +import flintstones.model.engine.r.service.IREngineService; + +public class REngineServiceContextFunction extends ContextFunction{ + @Override + public Object compute(IEclipseContext context, String contextKey) { + IREngineService domainService = ContextInjectionFactory.make(REngineServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IREngineService.class, domainService); + return domainService; + } +} diff --git a/bundles/flintstones.model.engine.r.provider/src/flintstones/model/engine/r/provider/REngineServiceProvider.java b/bundles/flintstones.model.engine.r.provider/src/flintstones/model/engine/r/provider/REngineServiceProvider.java new file mode 100644 index 0000000..389e05f --- /dev/null +++ b/bundles/flintstones.model.engine.r.provider/src/flintstones/model/engine/r/provider/REngineServiceProvider.java @@ -0,0 +1,18 @@ +package flintstones.model.engine.r.provider; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.model.engine.r.service.IREngineService; + +public class REngineServiceProvider implements IREngineService { + + @Inject + IEclipseContext context; + + @PostConstruct + private void prueba() { + + } +} diff --git a/bundles/flintstones.model.engine.r.service/.classpath b/bundles/flintstones.model.engine.r.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.engine.r.service/.polyglot.META-INF b/bundles/flintstones.model.engine.r.service/.polyglot.META-INF new file mode 100644 index 0000000..c28bc82 --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.engine.r.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.engine.r.service/.project b/bundles/flintstones.model.engine.r.service/.project new file mode 100644 index 0000000..1111ca8 --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.engine.r.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362723 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.engine.r.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.engine.r.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..2cfbc65 --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.engine.r.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.engine.r.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.model.engine.r.service +Bundle-ActivationPolicy: lazy +Require-Bundle: org.eclipse.osgi diff --git a/bundles/flintstones.model.engine.r.service/build.properties b/bundles/flintstones.model.engine.r.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.engine.r.service/src/flintstones/model/engine/r/service/IREngineService.java b/bundles/flintstones.model.engine.r.service/src/flintstones/model/engine/r/service/IREngineService.java new file mode 100644 index 0000000..f332b25 --- /dev/null +++ b/bundles/flintstones.model.engine.r.service/src/flintstones/model/engine/r/service/IREngineService.java @@ -0,0 +1,5 @@ +package flintstones.model.engine.r.service; + +public interface IREngineService { + +} diff --git a/bundles/flintstones.model.method.phase.provider/.classpath b/bundles/flintstones.model.method.phase.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.method.phase.provider/.polyglot.META-INF b/bundles/flintstones.model.method.phase.provider/.polyglot.META-INF new file mode 100644 index 0000000..822a0cf --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.method.phase.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.method.phase.provider/.project b/bundles/flintstones.model.method.phase.provider/.project new file mode 100644 index 0000000..9718366 --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.method.phase.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362724 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.method.phase.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.method.phase.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7c23b0d --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.method.phase.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.method.phase.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.core.contexts, + javax.inject, + flintstones.helper.extensionpoint, + flintstones.entity.method.phase, + flintstones.model.method.phase.service, + org.eclipse.e4.ui.model.workbench, + flintstones.entity.method.phase.ui, + javax.annotation, + org.eclipse.e4.core.services +Service-Component: component.xml +Bundle-ActivationPolicy: lazy +Import-Package: org.osgi.service.event diff --git a/bundles/flintstones.model.method.phase.provider/build.properties b/bundles/flintstones.model.method.phase.provider/build.properties new file mode 100644 index 0000000..6247cd0 --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml diff --git a/bundles/flintstones.model.method.phase.provider/component.xml b/bundles/flintstones.model.method.phase.provider/component.xml new file mode 100644 index 0000000..e1d4b58 --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/component.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/bundles/flintstones.model.method.phase.provider/src/flintstones/model/method/phase/provider/PhaseMethodServiceContextFunction.java b/bundles/flintstones.model.method.phase.provider/src/flintstones/model/method/phase/provider/PhaseMethodServiceContextFunction.java new file mode 100644 index 0000000..e63361f --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/src/flintstones/model/method/phase/provider/PhaseMethodServiceContextFunction.java @@ -0,0 +1,24 @@ +package flintstones.model.method.phase.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.model.method.phase.IPhaseMethodService; + +/** + * The Class PhaseMethodServiceContextFunction add the PhaseMethod Service instance to global context. + */ +public class PhaseMethodServiceContextFunction extends ContextFunction { + + @Override + public Object compute(IEclipseContext context, String contextKey) { + IPhaseMethodService service = ContextInjectionFactory.make(PhaseMethodServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IPhaseMethodService.class, service); + return service; + } + +} diff --git a/bundles/flintstones.model.method.phase.provider/src/flintstones/model/method/phase/provider/PhaseMethodServiceProvider.java b/bundles/flintstones.model.method.phase.provider/src/flintstones/model/method/phase/provider/PhaseMethodServiceProvider.java new file mode 100644 index 0000000..e4674ee --- /dev/null +++ b/bundles/flintstones.model.method.phase.provider/src/flintstones/model/method/phase/provider/PhaseMethodServiceProvider.java @@ -0,0 +1,139 @@ +package flintstones.model.method.phase.provider; + +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.events.IEventBroker; +import org.osgi.service.event.EventHandler; + +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.model.method.phase.IPhaseMethodService; + +/** + * The Class PhaseMethodServiceProvider. + */ +class PhaseMethodServiceProvider implements IPhaseMethodService { + + /** The context. */ + @Inject + IEclipseContext context; + + @Inject + IEventBroker broker; + + /** The reg. */ + private BaseRegistry reg; + private BaseRegistry uireg; + + /** The PhaseMethod list. */ + private final LinkedHashMap phases = new LinkedHashMap<>(); + + /** + * Instantiates a new phasemethod service provider. + */ + @Inject + public PhaseMethodServiceProvider() { + } + + /** + * Initialize. + */ + @PostConstruct + private void init() { + this.reg = new BaseRegistry(PhaseMethod.EXTENSION_POINT); + this.uireg = new BaseRegistry(PhaseMethodUI.EXTENSION_POINT); + } + + /* + * (non-Javadoc) + * + * @see flintstones.phasemethod.service.IPhaseMethodService#getAll() + */ + @Override + public PhaseMethodUI[] getAll() { + return this.phases.values().toArray(new PhaseMethodUI[this.phases.values().size()]); + } + + @Override + public PhaseMethodUI[] createPhases(String[] phasesId) { + + // Unsuscribe from event broker so garbage collector can remove the class from memory + phases.values() // + .stream() // + .filter(k -> k instanceof EventHandler ) // + .forEach(k -> broker.unsubscribe((EventHandler)k)); + + phases.clear(); + + PhaseMethodUI[] phasesUI = new PhaseMethodUI[phasesId.length]; + PhaseMethod phase = null; + int x = 0; + for (String phaseId : phasesId) { + // Create the Phase + PhaseMethodUI phaseUI = createPhase(phaseId); + phasesUI[x++] = phaseUI; + + phases.put(phaseId, phaseUI); + + // Link phases models + if( phase != null ) + phaseUI.getModel().setPreviousPhase(phase); + phase = phaseUI.getModel(); + + } + + return phasesUI; + } + + @Override + public PhaseMethodUI get(String id) { + return phases.get(id); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Entry entry : this.phases.entrySet()) { + sb.append(entry.getKey() + " ==> " + entry.getValue().getModel().getName() + " | " + + entry.getValue().toString() + "\n"); + } + return sb.toString(); + } + + @Override + public void clear() { + this.phases.clear(); + } + + @Override + public PhaseMethodUI createPhase(String phaseId) { + + // Create the model + PhaseMethod phase = (PhaseMethod) this.reg.instantiate(phaseId, this.context); + phase.setId(phaseId); + phase.setPosition(phases.size()); + + // Create the Phase UI + String phaseUiId = getIdFor(phase.getId()); + PhaseMethodUI phaseui = (PhaseMethodUI) this.uireg.instantiate(phaseUiId, this.context); + phaseui.setModel(phase); + + return phaseui; + } + + private String getIdFor(String phaseId) { + String[] matches = this.uireg.getAllAttributesWhere(PhaseMethodUI.Fields.phasemethod, phaseId, + PhaseMethodUI.Fields.uid); + if (matches.length != 1) + throw new Error("Encontrados " + matches.length + " " + phaseId + " (Debe ser 1) --> " + + this.uireg.getRegistryId()); + return this.uireg.getAllAttributesWhere(PhaseMethodUI.Fields.phasemethod, phaseId, PhaseMethodUI.Fields.uid)[0]; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.model.method.phase.service/.classpath b/bundles/flintstones.model.method.phase.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.method.phase.service/.polyglot.META-INF b/bundles/flintstones.model.method.phase.service/.polyglot.META-INF new file mode 100644 index 0000000..4c8c29d --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.method.phase.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.method.phase.service/.project b/bundles/flintstones.model.method.phase.service/.project new file mode 100644 index 0000000..8ad1425 --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.method.phase.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362724 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.method.phase.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.method.phase.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4ac0842 --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.method.phase.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.method.phase.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.model.method.phase +Require-Bundle: flintstones.entity.method.phase.ui, + flintstones.entity.method.phase diff --git a/bundles/flintstones.model.method.phase.service/build.properties b/bundles/flintstones.model.method.phase.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.method.phase.service/src/flintstones/model/method/phase/IPhaseMethodService.java b/bundles/flintstones.model.method.phase.service/src/flintstones/model/method/phase/IPhaseMethodService.java new file mode 100644 index 0000000..276e651 --- /dev/null +++ b/bundles/flintstones.model.method.phase.service/src/flintstones/model/method/phase/IPhaseMethodService.java @@ -0,0 +1,25 @@ +package flintstones.model.method.phase; + +import flintstones.entity.method.phase.ui.PhaseMethodUI; + +/** + * The Interface IPhaseMethodService. + */ +public interface IPhaseMethodService { + + /** + * Returns every PhaseMethod. + * + * @return Every PhaseMethod + */ + PhaseMethodUI[] getAll(); + + PhaseMethodUI get(String id); + + void clear(); + + PhaseMethodUI[] createPhases(String[] phasesId); + + PhaseMethodUI createPhase(String phaseId); + +} diff --git a/bundles/flintstones.model.method.provider/.classpath b/bundles/flintstones.model.method.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.method.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.method.provider/.polyglot.META-INF b/bundles/flintstones.model.method.provider/.polyglot.META-INF new file mode 100644 index 0000000..ca8047c --- /dev/null +++ b/bundles/flintstones.model.method.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.method.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.method.provider/.project b/bundles/flintstones.model.method.provider/.project new file mode 100644 index 0000000..fc3c696 --- /dev/null +++ b/bundles/flintstones.model.method.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.method.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362725 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.method.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.method.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.method.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.method.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.method.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.method.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.method.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.method.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.method.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.method.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.method.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b574e51 --- /dev/null +++ b/bundles/flintstones.model.method.provider/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.method.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.method.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: javax.inject, + org.eclipse.e4.core.contexts, + flintstones.model.method.service, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.core.services, + flintstones.helper.extensionpoint, + flintstones.entity.method, + flintstones.helper.data, + javax.annotation, + flintstones.entity.method.phase, + flintstones.model.method.phase.service, + flintstones.entity.method.phase.ui +Bundle-ActivationPolicy: lazy +Service-Component: component.xml diff --git a/bundles/flintstones.model.method.provider/build.properties b/bundles/flintstones.model.method.provider/build.properties new file mode 100644 index 0000000..6247cd0 --- /dev/null +++ b/bundles/flintstones.model.method.provider/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml diff --git a/bundles/flintstones.model.method.provider/component.xml b/bundles/flintstones.model.method.provider/component.xml new file mode 100644 index 0000000..2c679fe --- /dev/null +++ b/bundles/flintstones.model.method.provider/component.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/bundles/flintstones.model.method.provider/src/flintstones/model/method/provider/MethodServiceContextFunction.java b/bundles/flintstones.model.method.provider/src/flintstones/model/method/provider/MethodServiceContextFunction.java new file mode 100644 index 0000000..11bb64f --- /dev/null +++ b/bundles/flintstones.model.method.provider/src/flintstones/model/method/provider/MethodServiceContextFunction.java @@ -0,0 +1,29 @@ +package flintstones.model.method.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +//import flintstones.method.provider.MethodServiceProvider; +import flintstones.model.method.service.IMethodService; + +/** + * The Class DomainServiceContextFunction add the Domain Service instance to global context. + */ +public class MethodServiceContextFunction extends ContextFunction { + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core. + * contexts.IEclipseContext, java.lang.String) */ + @Override + public Object compute(IEclipseContext context, String contextKey) { + IMethodService domainService = ContextInjectionFactory.make(MethodServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IMethodService.class, domainService); + return domainService; + } +} diff --git a/bundles/flintstones.model.method.provider/src/flintstones/model/method/provider/MethodServiceProvider.java b/bundles/flintstones.model.method.provider/src/flintstones/model/method/provider/MethodServiceProvider.java new file mode 100644 index 0000000..f405195 --- /dev/null +++ b/bundles/flintstones.model.method.provider/src/flintstones/model/method/provider/MethodServiceProvider.java @@ -0,0 +1,124 @@ +package flintstones.model.method.provider; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.services.events.IEventBroker; + +import flintstones.entity.method.Method; +import flintstones.entity.method.phase.PhaseMethod; +import flintstones.entity.method.phase.ui.PhaseMethodUI; +import flintstones.helper.data.HashMapList; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.model.method.phase.IPhaseMethodService; +import flintstones.model.method.service.IMethodService; + +class MethodServiceProvider implements IMethodService { + + @Inject + IEclipseContext context; + + @Inject + IPhaseMethodService phaseService; + + @Inject + IEventBroker broker; + + private BaseRegistry reg; + private BaseRegistry categoryReg; + + private HashMapList categoryMethodMapping = null; // null -> Regen + + private HashMap methods = new HashMap<>(); + + public MethodServiceProvider() { + } + + @PostConstruct + public void init() { + this.reg = new BaseRegistry(Method.EXTENSION_POINT); + this.categoryReg = new BaseRegistry(Method.EXTENSION_POINT_CATEGORY); + this.cacheAllMethods(); + } + + @Override + public void loadPhasesFor(Method method) { + ExtensionRegistry methodRegistry = this.reg.getFirstRegistryWhere(Method.Fields.uid, method.getId()); + ExtensionRegistry[] phasesEr = methodRegistry.getAttributeReferences(Method.Fields.phase); + + // Prepare phases + PhaseMethodUI[] phasesUI = phaseService.createPhases(Arrays.stream(phasesEr).map(k -> k.getAttribute(PhaseMethod.Fields.uid)).toArray(String[]::new)); + for(PhaseMethodUI ui : phasesUI) + ui.getModel().setMethodData(method.getExportedData()); + + method.setPhases(phasesUI); + + } + + @Override + public void cacheAllMethods() { + + methods.clear(); + categoryMethodMapping = null; + + String methodIds[] = reg.getAllAttributesUnique(Method.Fields.uid); + for (String methodId : methodIds) { + Method method = (Method) reg.instantiate(methodId, this.context); + method.setId(methodId); + method.setName(reg.getAttributeFromId(methodId, Method.Fields.name)); + method.setCategory(lookForCategory(reg.getAttributeFromId(methodId, Method.Fields.category))); + methods.put(method.getId(), method); + } + } + + private String lookForCategory(String categoryId) { + return categoryReg.getAllRegistriesWhere(Method.Fields.uid, categoryId)[0] + .getAttribute(Method.Fields.category); + } + + @Override + public String[] getAllCategories() { + HashSet set = new HashSet<>(); + methods.values().stream().forEach(k -> set.add(k.getCategory())); + return set.toArray(new String[0]); + } + + @Override + public Method[] getAllMethodForCategory(String category) { + if (categoryMethodMapping == null) + cacheCategoryMethod(); + + Comparator byName = Comparator.comparing(Method::getName); + categoryMethodMapping.get(category).sort(byName); + return categoryMethodMapping.get(category).toArray(new Method[0]); + } + + private void cacheCategoryMethod() { + categoryMethodMapping = new HashMapList(); + + for (Method m : methods.values()) + categoryMethodMapping.add(m.getCategory(), m); + } + + @Override + public String toString() { + return ""; + } + + @Override + public void clear() { + broker.send("TOPIC_RATING/CONTAINER/CLEAR", null); + phaseService.clear(); + } + + @Override + public Method[] getAll() { + return methods.values().toArray(new Method[0]); + } +} diff --git a/bundles/flintstones.model.method.service/.classpath b/bundles/flintstones.model.method.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.method.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.method.service/.polyglot.META-INF b/bundles/flintstones.model.method.service/.polyglot.META-INF new file mode 100644 index 0000000..f14f18d --- /dev/null +++ b/bundles/flintstones.model.method.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.method.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.method.service/.project b/bundles/flintstones.model.method.service/.project new file mode 100644 index 0000000..4acda6f --- /dev/null +++ b/bundles/flintstones.model.method.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.method.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362725 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.method.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.method.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.method.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.method.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.method.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.method.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.method.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.method.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.method.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.method.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.method.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7874a1a --- /dev/null +++ b/bundles/flintstones.model.method.service/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.method.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.method.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.model.method.service +Require-Bundle: flintstones.entity.method diff --git a/bundles/flintstones.model.method.service/build.properties b/bundles/flintstones.model.method.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.method.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.method.service/src/flintstones/model/method/service/IMethodService.java b/bundles/flintstones.model.method.service/src/flintstones/model/method/service/IMethodService.java new file mode 100644 index 0000000..d88c65e --- /dev/null +++ b/bundles/flintstones.model.method.service/src/flintstones/model/method/service/IMethodService.java @@ -0,0 +1,22 @@ +package flintstones.model.method.service; + +import flintstones.entity.method.Method; + +/** + * The Interface IMethodService. + */ +public interface IMethodService { + + String[] getAllCategories(); + + void clear(); + + Method[] getAll(); + + void cacheAllMethods(); + + Method[] getAllMethodForCategory(String category); + + void loadPhasesFor(Method method); + +} diff --git a/bundles/flintstones.model.problemelement.provider/.classpath b/bundles/flintstones.model.problemelement.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.problemelement.provider/.polyglot.META-INF b/bundles/flintstones.model.problemelement.provider/.polyglot.META-INF new file mode 100644 index 0000000..b653b88 --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.problemelement.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.problemelement.provider/.project b/bundles/flintstones.model.problemelement.provider/.project new file mode 100644 index 0000000..6b6afe4 --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.problemelement.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362726 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.problemelement.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.problemelement.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4fcc776 --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.problemelement.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.problemelement.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Service-Component: component.xml +Bundle-ActivationPolicy: lazy +Require-Bundle: org.eclipse.e4.core.services, + flintstones.model.problemelement.service, + org.eclipse.e4.core.contexts, + javax.inject, + flintstones.entity.problemelement, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + javax.annotation, + flintstones.helper.debug +Export-Package: flintstones.model.problemelement.provider diff --git a/bundles/flintstones.model.problemelement.provider/build.properties b/bundles/flintstones.model.problemelement.provider/build.properties new file mode 100644 index 0000000..6247cd0 --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml diff --git a/bundles/flintstones.model.problemelement.provider/component.xml b/bundles/flintstones.model.problemelement.provider/component.xml new file mode 100644 index 0000000..d916872 --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/component.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/bundles/flintstones.model.problemelement.provider/src/flintstones/model/problemelement/provider/ProblemElementServiceContextFunction.java b/bundles/flintstones.model.problemelement.provider/src/flintstones/model/problemelement/provider/ProblemElementServiceContextFunction.java new file mode 100644 index 0000000..9fc4931 --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/src/flintstones/model/problemelement/provider/ProblemElementServiceContextFunction.java @@ -0,0 +1,28 @@ +package flintstones.model.problemelement.provider; + +import flintstones.model.problemelement.service.IProblemElementService; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +/** + * The Class ProblemElementServiceContextFunction add the Domain Service instance to global context. + */ +public class ProblemElementServiceContextFunction extends ContextFunction { + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core. + * contexts.IEclipseContext, java.lang.String) */ + @Override + public Object compute(IEclipseContext context, String contextKey) { + IProblemElementService domainService = ContextInjectionFactory.make(ProblemElementServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IProblemElementService.class, domainService); + return domainService; + } +} diff --git a/bundles/flintstones.model.problemelement.provider/src/flintstones/model/problemelement/provider/ProblemElementServiceProvider.java b/bundles/flintstones.model.problemelement.provider/src/flintstones/model/problemelement/provider/ProblemElementServiceProvider.java new file mode 100644 index 0000000..a4eaedf --- /dev/null +++ b/bundles/flintstones.model.problemelement.provider/src/flintstones/model/problemelement/provider/ProblemElementServiceProvider.java @@ -0,0 +1,227 @@ +package flintstones.model.problemelement.provider; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Optional; + +import flintstones.entity.problemelement.entities.FakeProblemElement; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.problemelement.entities.ProblemElementHelper; +import flintstones.model.problemelement.service.IProblemElementService; + +/** + * The Class ProblemElementServiceProvider. + */ +public class ProblemElementServiceProvider implements IProblemElementService { + + HashMap> elements = new LinkedHashMap<>(); + HashMap lastOrder = new HashMap<>(); + + /** + * Instantiates a new problem element service provider. + */ + public ProblemElementServiceProvider() { + } + + @Override + public void add(ProblemElement pe) { + HashMap map = elements.get(pe.getType()); + if (map == null) + map = new LinkedHashMap<>(); + + if(map.get(pe.getId()) != null) + throw new RuntimeException("Element already existed problemService.add("+pe.getName()+")"); + + pe.updateId(); + map.put(pe.getId(), pe); + elements.put(pe.getType(), map); + + // METADATA + assignOrder(pe); + } + + // READ + + @Override + public ProblemElement[] getAll(String type) { + + HashMap map = elements.get(type); + if (map == null) + return new ProblemElement[0]; + + ProblemElement[] gPe = map.values().toArray(new ProblemElement[0]); + return gPe; + } + + @Override + public ProblemElement getOnly(String type) throws RuntimeException { + ProblemElement[] all = getAll(type); + if (all.length != 1) + throw new RuntimeException("There are " + all.length + " elements. Should be 1."); + return all[0]; + } + + // Get generic problem element 1-instance only + @Override + public ProblemElement getGeneric() { + String name = "*"; + String type = FakeProblemElement.Type; + ProblemElement p = getByName(type, name); + if (p == null) { + p = new FakeProblemElement(name); + add(p); + } + + return p; + } + + // FILTER + + @Override + public ProblemElement getById(String type, String id) { + HashMap map = elements.get(type); + if (map == null) + map = new HashMap<>(); + return map.get(id); + } + + + @Override + public ProblemElement getByName(String type, String name) { + HashMap map = elements.get(type); + if (map == null) + return null; + + Optional opt = map.values().stream().filter(k -> k.getName().equals(name)).findFirst(); + return opt.isPresent() ? opt.get() : null; + + } + + @Override + public ProblemElement getByCanonicalName(String type, String canonicalName) { + + HashMap map = elements.get(type); + if (map == null) + map = new HashMap<>(); + + return map.values().stream() + // Filter the matches + .filter(k -> k.getCanonicalName().equals(canonicalName)) + // Stop and return at the first one + .findFirst().get(); + } + + @Override + public ProblemElement[] getMainElements(String type) { + + ProblemElement[] arr = getAll(type); + + return Arrays.stream(arr) + // Filter in the one with null parent + .filter(k -> !k.hasParent() || (k.hasParent() && k.getParent().getId().isEmpty())) + // As array + .toArray(ProblemElement[]::new); + + } + + @Override + public ProblemElement[] getSubElements(String type) { + return getSubElements(type, null); + } + + @Override + public ProblemElement[] getSubElements(String type, ProblemElement root) { + + ProblemElement[] arr; + // Should we use a root element and get it leaves or can we get the leaves of + // the full tree? + if (root == null) + arr = this.getMainElements(type); + else { + arr = new ProblemElement[1]; + arr[0] = root; + } + + return Arrays.stream(arr) + // Grab the final elements of each PE into a single stream + .flatMap(k -> Arrays.stream(k.getFinalElements())) + // As array + .toArray(ProblemElement[]::new); + + } + + // DELETE + + @Override + public void deleteAll() { + elements.clear(); + getGeneric(); + } + + @Override + public boolean delete(ProblemElement pe) { + + String type = pe.getType(); + String id = pe.getId(); + + HashMap map = elements.get(type); + if (map == null) + map = new HashMap<>(); + + ProblemElement item = map.remove(id); + if (item.hasParent()) + item.getParent().removeChildren(item); + + if (item.hasChildren()) { + for (ProblemElement child : item.getChildren()) + delete(child); + } + + return item != null; + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + String format = "{2}| {0} ({1}c) \n"; + + String[] types = elements.keySet().toArray(new String[0]); + for (String type : types) { + + sb.append(type + ":\n"); + ProblemElement[] elements = ProblemElementHelper.getAsUserOrdered(getAll(type)); + for (ProblemElement element : elements) { + sb.append(formatPE(format, element)); + } + sb.append("\n"); + } + + return sb.toString(); + + } + + // Internal + + protected String formatPE(String format, ProblemElement p) { + return MessageFormat.format(format, p.getName(), p.getChildren().length, p.getOrder() + "").toString(); + } + + protected void assignOrder(ProblemElement pe) { + + if (pe.getOrder() != -1) + return; + + Integer lastPosition = lastOrder.get(pe.getType()); + if (lastPosition == null) + lastPosition = 0; + + pe.setOrder(lastPosition++); + lastOrder.put(pe.getType(), lastPosition); + + } + + +} \ No newline at end of file diff --git a/bundles/flintstones.model.problemelement.service/.classpath b/bundles/flintstones.model.problemelement.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.problemelement.service/.polyglot.META-INF b/bundles/flintstones.model.problemelement.service/.polyglot.META-INF new file mode 100644 index 0000000..4771502 --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.problemelement.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.problemelement.service/.project b/bundles/flintstones.model.problemelement.service/.project new file mode 100644 index 0000000..15c9c35 --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.problemelement.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362726 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.problemelement.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.problemelement.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d7544b9 --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.problemelement.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.problemelement.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.problemelement;visibility:=reexport +Export-Package: flintstones.model.problemelement.service diff --git a/bundles/flintstones.model.problemelement.service/build.properties b/bundles/flintstones.model.problemelement.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.problemelement.service/src/flintstones/model/problemelement/service/IProblemElementService.java b/bundles/flintstones.model.problemelement.service/src/flintstones/model/problemelement/service/IProblemElementService.java new file mode 100644 index 0000000..996ef5d --- /dev/null +++ b/bundles/flintstones.model.problemelement.service/src/flintstones/model/problemelement/service/IProblemElementService.java @@ -0,0 +1,108 @@ +package flintstones.model.problemelement.service; + +import flintstones.entity.problemelement.entities.ProblemElement; + +/** + * The Interface IProblemElementService. + */ +public interface IProblemElementService { + + /** + * Adds the problem element to the service. + * + * @param problemElement the problem element + */ + void add(ProblemElement problemElement) throws RuntimeException; + + /** + * Gets the all the problem element with the given type. + * + * @param type the type + * @return the all + */ + ProblemElement[] getAll(String type); + + /** + * Gets the only problem element of the given type in the service. + * If there is more than one it throws an error. + * + * @param type the type + * @return the only + * @throws RuntimeException the runtime exception + */ + ProblemElement getOnly(String type) throws RuntimeException; + + /** + * Gets the generic problemElement. + * + * @return the generic + */ + ProblemElement getGeneric(); + + /** + * Gets the problem element by its id. + * + * @param type the type + * @param name the name + * @return the by id + */ + ProblemElement getById(String type, String id); + + /** + * Gets the problem element by its name. + * + * @param type the type + * @param name the name + * @return the by name + */ + ProblemElement getByName(String type, String name); + + /** + * Gets the problem element by its canonical name. + * + * @param type the type + * @param canonicalName the canonical name + * @return the by canonical name + */ + ProblemElement getByCanonicalName(String type, String canonicalName); + + /** + * Gets the main (root) elements. + * + * @param type the type + * @return the main elements + */ + ProblemElement[] getMainElements(String type); + + /** + * Gets the sub elements. + * + * @param type the type + * @return the sub elements + */ + ProblemElement[] getSubElements(String type); + + /** + * Gets the sub elements. + * + * @param type the type + * @param root the root + * @return the sub elements + */ + ProblemElement[] getSubElements(String type, ProblemElement root); + + /** + * Delete all the problem elements. + */ + void deleteAll(); + + /** + * Delete a problem element. + * + * @param pe the pe + * @return true, if successful + */ + boolean delete(ProblemElement problemElement); + + +} \ No newline at end of file diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/.classpath b/bundles/flintstones.model.sensitiveanalysismodel.provider/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/.polyglot.META-INF b/bundles/flintstones.model.sensitiveanalysismodel.provider/.polyglot.META-INF new file mode 100644 index 0000000..8f85a02 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.sensitiveanalysismodel.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider sensitive analysis model + + Sinbad2 + + diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/.project b/bundles/flintstones.model.sensitiveanalysismodel.provider/.project new file mode 100644 index 0000000..f67c6c2 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.sensitiveanalysismodel.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362727 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.sensitiveanalysismodel.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5963ab8 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider sensitive analysis model +Bundle-SymbolicName: flintstones.model.sensitiveanalysismodel.provider +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.model.sensitiveanalysismodel.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.model.sensitiveanalysismodel.service, + flintstones.helper.extensionpoint, + org.eclipse.e4.ui.model.workbench, + flintstones.entity.sensitiveanalysismodel, + javax.annotation, + javax.inject +Service-Component: component.xml +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/build.properties b/bundles/flintstones.model.sensitiveanalysismodel.provider/build.properties new file mode 100644 index 0000000..1451438 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/build.properties @@ -0,0 +1,5 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml +source.. = src/ diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/component.xml b/bundles/flintstones.model.sensitiveanalysismodel.provider/component.xml new file mode 100644 index 0000000..a5bc87a --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/component.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/src/flintstones/model/sensitiveanalysismodel/provider/SensitiveAnalysisModelContextFunction.java b/bundles/flintstones.model.sensitiveanalysismodel.provider/src/flintstones/model/sensitiveanalysismodel/provider/SensitiveAnalysisModelContextFunction.java new file mode 100644 index 0000000..29588dc --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/src/flintstones/model/sensitiveanalysismodel/provider/SensitiveAnalysisModelContextFunction.java @@ -0,0 +1,26 @@ +package flintstones.model.sensitiveanalysismodel.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.model.sensitiveanalysismodel.service.ISensitiveAnalysisModelService; + +public class SensitiveAnalysisModelContextFunction extends ContextFunction { + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core. + * contexts.IEclipseContext, java.lang.String) */ + @Override + public Object compute(IEclipseContext context, String contextKey) { + ISensitiveAnalysisModelService service = ContextInjectionFactory.make(SensitiveAnalysisModelServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(ISensitiveAnalysisModelService.class, service); + return service; + } + +} diff --git a/bundles/flintstones.model.sensitiveanalysismodel.provider/src/flintstones/model/sensitiveanalysismodel/provider/SensitiveAnalysisModelServiceProvider.java b/bundles/flintstones.model.sensitiveanalysismodel.provider/src/flintstones/model/sensitiveanalysismodel/provider/SensitiveAnalysisModelServiceProvider.java new file mode 100644 index 0000000..cffebd0 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.provider/src/flintstones/model/sensitiveanalysismodel/provider/SensitiveAnalysisModelServiceProvider.java @@ -0,0 +1,106 @@ +package flintstones.model.sensitiveanalysismodel.provider; + +import java.util.LinkedHashMap; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.model.sensitiveanalysismodel.service.ISensitiveAnalysisModelService; + +public class SensitiveAnalysisModelServiceProvider implements ISensitiveAnalysisModelService { + + /** The context. */ + @Inject + IEclipseContext context; + + /** The reg. */ + private BaseRegistry reg; + private BaseRegistry uireg; + + /** The SensitiveAnalysisModel list. */ + private final LinkedHashMap models = new LinkedHashMap<>(); + + /** + * Initialize. + */ + @PostConstruct + private void init() { + this.reg = new BaseRegistry(SensitiveAnalysisModel.EXTENSION_POINT); + this.uireg = new BaseRegistry(SensitiveAnalysisModelUi.EXTENSION_POINT); + createSensitiveAnalysisModels(); + } + + + @Override + public SensitiveAnalysisModelUi[] getAll() { + return this.models.values().toArray(new SensitiveAnalysisModelUi[this.models.values().size()]); + } + + @Override + public SensitiveAnalysisModelUi get(String modelId) { + return models.get(modelId); + } + + @Override + public void createSensitiveAnalysisModels() { + models.clear(); + + ExtensionRegistry[] registries = uireg.getAllRegistries(); + + String modelId; + for (ExtensionRegistry reg : registries) { + modelId = reg.getAttribute(SensitiveAnalysisModelUi.Fields.sensitivemodel); + SensitiveAnalysisModelUi modelUI = createSensitiveAnalysisModel(modelId); + + models.put(modelId, modelUI); + } + } + + @Override + public SensitiveAnalysisModelUi createSensitiveAnalysisModel(String modelId) { + // Create the model + SensitiveAnalysisModel model = (SensitiveAnalysisModel) this.reg.instantiate(modelId, this.context); + model.setId(modelId); + model.setName(this.reg.getAttributeFromId(modelId, SensitiveAnalysisModel.Fields.name)); + + // Create the Phase UI + String modelUiId = getIdFor(model.getId()); + SensitiveAnalysisModelUi modelui = (SensitiveAnalysisModelUi) this.uireg.instantiate(modelUiId, this.context); + modelui.setModel(model); + + return modelui; + } + + @Override + public SensitiveAnalysisModel getSensitiveAnalysisModel(String id) { + SensitiveAnalysisModelUi modelUi; + for(String modelId: models.keySet()) { + modelUi = models.get(modelId); + if(modelUi.getModel().getId().equals(id)) { + return modelUi.getModel(); + } + } + return null; + } + + private String getIdFor(String modelId) { + String[] matches = this.uireg.getAllAttributesWhere(SensitiveAnalysisModelUi.Fields.sensitivemodel, modelId, + SensitiveAnalysisModelUi.Fields.uid); + if (matches.length != 1) + throw new Error("Encontrados " + matches.length + " " + modelId + " (Debe ser 1) --> " + + this.uireg.getRegistryId()); + return this.uireg.getAllAttributesWhere(SensitiveAnalysisModelUi.Fields.sensitivemodel, modelId, SensitiveAnalysisModelUi.Fields.uid)[0]; + } + + @Override + public void clear() { + this.models.clear(); + } + +} diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/.classpath b/bundles/flintstones.model.sensitiveanalysismodel.service/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/.polyglot.META-INF b/bundles/flintstones.model.sensitiveanalysismodel.service/.polyglot.META-INF new file mode 100644 index 0000000..5e50861 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.sensitiveanalysismodel.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service sensitive analysis model + + Sinbad2 + + diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/.project b/bundles/flintstones.model.sensitiveanalysismodel.service/.project new file mode 100644 index 0000000..d95b490 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.sensitiveanalysismodel.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362727 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.sensitiveanalysismodel.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..40c9974 --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service sensitive analysis model +Bundle-SymbolicName: flintstones.model.sensitiveanalysismodel.service +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.model.sensitiveanalysismodel.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.sensitiveanalysismodel.ui;visibility:=reexport, + flintstones.entity.sensitiveanalysismodel +Export-Package: flintstones.model.sensitiveanalysismodel.service diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/build.properties b/bundles/flintstones.model.sensitiveanalysismodel.service/build.properties new file mode 100644 index 0000000..41eb6ad --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.sensitiveanalysismodel.service/src/flintstones/model/sensitiveanalysismodel/service/ISensitiveAnalysisModelService.java b/bundles/flintstones.model.sensitiveanalysismodel.service/src/flintstones/model/sensitiveanalysismodel/service/ISensitiveAnalysisModelService.java new file mode 100644 index 0000000..42b30bf --- /dev/null +++ b/bundles/flintstones.model.sensitiveanalysismodel.service/src/flintstones/model/sensitiveanalysismodel/service/ISensitiveAnalysisModelService.java @@ -0,0 +1,19 @@ +package flintstones.model.sensitiveanalysismodel.service; + +import flintstones.entity.sensitiveanalysismodel.SensitiveAnalysisModel; +import flintstones.entity.sensitiveanalysismodel.ui.SensitiveAnalysisModelUi; + +public interface ISensitiveAnalysisModelService { + + SensitiveAnalysisModelUi[] getAll(); + + SensitiveAnalysisModelUi get(String modelId); + + SensitiveAnalysisModel getSensitiveAnalysisModel(String id); + + void createSensitiveAnalysisModels(); + + SensitiveAnalysisModelUi createSensitiveAnalysisModel(String modelId); + + void clear(); +} diff --git a/bundles/flintstones.model.ui.service/.classpath b/bundles/flintstones.model.ui.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.ui.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.ui.service/.polyglot.META-INF b/bundles/flintstones.model.ui.service/.polyglot.META-INF new file mode 100644 index 0000000..3907440 --- /dev/null +++ b/bundles/flintstones.model.ui.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.ui.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.ui.service/.project b/bundles/flintstones.model.ui.service/.project new file mode 100644 index 0000000..50ddfc6 --- /dev/null +++ b/bundles/flintstones.model.ui.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.ui.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362729 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.ui.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.ui.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.ui.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.ui.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.ui.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.ui.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.ui.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.ui.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.ui.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.ui.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.ui.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ff02a92 --- /dev/null +++ b/bundles/flintstones.model.ui.service/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.ui.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.ui.service +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.model.ui.service, + flintstones.model.ui.service.style +Require-Bundle: org.eclipse.wb.swt, + org.eclipse.swt, + org.eclipse.jface, + org.eclipse.osgi, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.eclipse.equinox.registry, + org.eclipse.e4.ui.model.workbench, + flintstones.helper.debug diff --git a/bundles/flintstones.model.ui.service/build.properties b/bundles/flintstones.model.ui.service/build.properties new file mode 100644 index 0000000..c6baffa --- /dev/null +++ b/bundles/flintstones.model.ui.service/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + icons/ diff --git a/bundles/flintstones.model.ui.service/icons/Sample.png b/bundles/flintstones.model.ui.service/icons/Sample.png new file mode 100644 index 0000000..3bc0bd3 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/Sample.png differ diff --git a/bundles/flintstones.model.ui.service/icons/XLSExport_32.png b/bundles/flintstones.model.ui.service/icons/XLSExport_32.png new file mode 100644 index 0000000..0596ac4 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/XLSExport_32.png differ diff --git a/bundles/flintstones.model.ui.service/icons/XLSImport_32.png b/bundles/flintstones.model.ui.service/icons/XLSImport_32.png new file mode 100644 index 0000000..58b1b84 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/XLSImport_32.png differ diff --git a/bundles/flintstones.model.ui.service/icons/action_add.png b/bundles/flintstones.model.ui.service/icons/action_add.png new file mode 100644 index 0000000..cbece78 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_add.png differ diff --git a/bundles/flintstones.model.ui.service/icons/action_clear.png b/bundles/flintstones.model.ui.service/icons/action_clear.png new file mode 100644 index 0000000..fc82915 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_clear.png differ diff --git a/bundles/flintstones.model.ui.service/icons/action_delete.png b/bundles/flintstones.model.ui.service/icons/action_delete.png new file mode 100644 index 0000000..ed4d89b Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_delete.png differ diff --git a/bundles/flintstones.model.ui.service/icons/action_help.png b/bundles/flintstones.model.ui.service/icons/action_help.png new file mode 100644 index 0000000..41291da Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_help.png differ diff --git a/bundles/flintstones.model.ui.service/icons/action_paste.png b/bundles/flintstones.model.ui.service/icons/action_paste.png new file mode 100644 index 0000000..3995a21 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_paste.png differ diff --git a/bundles/flintstones.model.ui.service/icons/action_profile_central.gif b/bundles/flintstones.model.ui.service/icons/action_profile_central.gif new file mode 100644 index 0000000..da1be5a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_profile_central.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/action_profile_limiting.gif b/bundles/flintstones.model.ui.service/icons/action_profile_limiting.gif new file mode 100644 index 0000000..076bb30 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_profile_limiting.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/action_reduce.png b/bundles/flintstones.model.ui.service/icons/action_reduce.png new file mode 100644 index 0000000..315ea36 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_reduce.png differ diff --git a/bundles/flintstones.model.ui.service/icons/action_transpose.png b/bundles/flintstones.model.ui.service/icons/action_transpose.png new file mode 100644 index 0000000..3180788 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/action_transpose.png differ diff --git a/bundles/flintstones.model.ui.service/icons/add.png b/bundles/flintstones.model.ui.service/icons/add.png new file mode 100644 index 0000000..52c7087 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/add.png differ diff --git a/bundles/flintstones.model.ui.service/icons/add_group_of_experts.png b/bundles/flintstones.model.ui.service/icons/add_group_of_experts.png new file mode 100644 index 0000000..128102b Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/add_group_of_experts.png differ diff --git a/bundles/flintstones.model.ui.service/icons/add_some_alternatives.png b/bundles/flintstones.model.ui.service/icons/add_some_alternatives.png new file mode 100644 index 0000000..b543137 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/add_some_alternatives.png differ diff --git a/bundles/flintstones.model.ui.service/icons/add_some_criteria.png b/bundles/flintstones.model.ui.service/icons/add_some_criteria.png new file mode 100644 index 0000000..0b1dcaa Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/add_some_criteria.png differ diff --git a/bundles/flintstones.model.ui.service/icons/add_some_domains.png b/bundles/flintstones.model.ui.service/icons/add_some_domains.png new file mode 100644 index 0000000..9174b81 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/add_some_domains.png differ diff --git a/bundles/flintstones.model.ui.service/icons/add_some_sortingclass.png b/bundles/flintstones.model.ui.service/icons/add_some_sortingclass.png new file mode 100644 index 0000000..cae7ab2 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/add_some_sortingclass.png differ diff --git a/bundles/flintstones.model.ui.service/icons/aggregation_operator_22.png b/bundles/flintstones.model.ui.service/icons/aggregation_operator_22.png new file mode 100644 index 0000000..4decc89 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/aggregation_operator_22.png differ diff --git a/bundles/flintstones.model.ui.service/icons/ahpmatrix.png b/bundles/flintstones.model.ui.service/icons/ahpmatrix.png new file mode 100644 index 0000000..36a7339 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/ahpmatrix.png differ diff --git a/bundles/flintstones.model.ui.service/icons/alt_window_16.gif b/bundles/flintstones.model.ui.service/icons/alt_window_16.gif new file mode 100644 index 0000000..05626b1 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/alt_window_16.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/alt_window_32.gif b/bundles/flintstones.model.ui.service/icons/alt_window_32.gif new file mode 100644 index 0000000..b432f88 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/alt_window_32.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/alternative.png b/bundles/flintstones.model.ui.service/icons/alternative.png new file mode 100644 index 0000000..bcb6f8a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/alternative.png differ diff --git a/bundles/flintstones.model.ui.service/icons/alternatives.png b/bundles/flintstones.model.ui.service/icons/alternatives.png new file mode 100644 index 0000000..5e8a813 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/alternatives.png differ diff --git a/bundles/flintstones.model.ui.service/icons/analysis_24x24.png b/bundles/flintstones.model.ui.service/icons/analysis_24x24.png new file mode 100644 index 0000000..bda9bfb Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/analysis_24x24.png differ diff --git a/bundles/flintstones.model.ui.service/icons/benefit.png b/bundles/flintstones.model.ui.service/icons/benefit.png new file mode 100644 index 0000000..6fca5a4 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/benefit.png differ diff --git a/bundles/flintstones.model.ui.service/icons/category_obj.gif b/bundles/flintstones.model.ui.service/icons/category_obj.gif new file mode 100644 index 0000000..b487d07 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/category_obj.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/change_order_22.png b/bundles/flintstones.model.ui.service/icons/change_order_22.png new file mode 100644 index 0000000..08d9330 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/change_order_22.png differ diff --git a/bundles/flintstones.model.ui.service/icons/core/fs4folder.png b/bundles/flintstones.model.ui.service/icons/core/fs4folder.png new file mode 100644 index 0000000..709660a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/core/fs4folder.png differ diff --git a/bundles/flintstones.model.ui.service/icons/core/phase_left.png b/bundles/flintstones.model.ui.service/icons/core/phase_left.png new file mode 100644 index 0000000..ec8c3ca Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/core/phase_left.png differ diff --git a/bundles/flintstones.model.ui.service/icons/core/phase_right.png b/bundles/flintstones.model.ui.service/icons/core/phase_right.png new file mode 100644 index 0000000..1ee2d0c Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/core/phase_right.png differ diff --git a/bundles/flintstones.model.ui.service/icons/cost.png b/bundles/flintstones.model.ui.service/icons/cost.png new file mode 100644 index 0000000..ec3127a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/cost.png differ diff --git a/bundles/flintstones.model.ui.service/icons/criteria.png b/bundles/flintstones.model.ui.service/icons/criteria.png new file mode 100644 index 0000000..6a9a793 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/criteria.png differ diff --git a/bundles/flintstones.model.ui.service/icons/criteriaFirst.png b/bundles/flintstones.model.ui.service/icons/criteriaFirst.png new file mode 100644 index 0000000..23b1828 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/criteriaFirst.png differ diff --git a/bundles/flintstones.model.ui.service/icons/criterion.png b/bundles/flintstones.model.ui.service/icons/criterion.png new file mode 100644 index 0000000..7a8a5df Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/criterion.png differ diff --git a/bundles/flintstones.model.ui.service/icons/debug/afryca_export_24.png b/bundles/flintstones.model.ui.service/icons/debug/afryca_export_24.png new file mode 100644 index 0000000..adb6245 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/debug/afryca_export_24.png differ diff --git a/bundles/flintstones.model.ui.service/icons/debug/terminal-24.png b/bundles/flintstones.model.ui.service/icons/debug/terminal-24.png new file mode 100644 index 0000000..a6a6bb5 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/debug/terminal-24.png differ diff --git a/bundles/flintstones.model.ui.service/icons/decision_matrix_24x24.png b/bundles/flintstones.model.ui.service/icons/decision_matrix_24x24.png new file mode 100644 index 0000000..47f6673 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/decision_matrix_24x24.png differ diff --git a/bundles/flintstones.model.ui.service/icons/deselect.png b/bundles/flintstones.model.ui.service/icons/deselect.png new file mode 100644 index 0000000..c0f4394 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/deselect.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain.png b/bundles/flintstones.model.ui.service/icons/domain.png new file mode 100644 index 0000000..eff653d Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahp.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahp.png new file mode 100644 index 0000000..e9be686 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahp.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahpsort.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahpsort.png new file mode 100644 index 0000000..e9be686 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahpsort.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahpsortii.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahpsortii.png new file mode 100644 index 0000000..e9be686 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.ahpsortii.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.hesitant.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.hesitant.png new file mode 100644 index 0000000..e3a3ca1 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.hesitant.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.linguistic.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.linguistic.png new file mode 100644 index 0000000..e3a3ca1 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.linguistic.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.linguistic.unbalanced.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.linguistic.unbalanced.png new file mode 100644 index 0000000..e3a3ca1 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.linguistic.unbalanced.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.integer.intervalar.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.integer.intervalar.png new file mode 100644 index 0000000..3309484 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.integer.intervalar.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.integer.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.integer.png new file mode 100644 index 0000000..3309484 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.integer.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.real.intervalar.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.real.intervalar.png new file mode 100644 index 0000000..3309484 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.real.intervalar.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.real.png b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.real.png new file mode 100644 index 0000000..3309484 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain/flintstones.domain.numeric.real.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domain_big.png b/bundles/flintstones.model.ui.service/icons/domain_big.png new file mode 100644 index 0000000..f5daa7b Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domain_big.png differ diff --git a/bundles/flintstones.model.ui.service/icons/domains.png b/bundles/flintstones.model.ui.service/icons/domains.png new file mode 100644 index 0000000..2c69b43 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/domains.png differ diff --git a/bundles/flintstones.model.ui.service/icons/edit.png b/bundles/flintstones.model.ui.service/icons/edit.png new file mode 100644 index 0000000..efa79f6 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/edit.png differ diff --git a/bundles/flintstones.model.ui.service/icons/edit_22.png b/bundles/flintstones.model.ui.service/icons/edit_22.png new file mode 100644 index 0000000..a7a1c22 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/edit_22.png differ diff --git a/bundles/flintstones.model.ui.service/icons/edit_par_22.png b/bundles/flintstones.model.ui.service/icons/edit_par_22.png new file mode 100644 index 0000000..e54e7d6 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/edit_par_22.png differ diff --git a/bundles/flintstones.model.ui.service/icons/element.png b/bundles/flintstones.model.ui.service/icons/element.png new file mode 100644 index 0000000..16d2ef5 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/element.png differ diff --git a/bundles/flintstones.model.ui.service/icons/elementassignmentstable.png b/bundles/flintstones.model.ui.service/icons/elementassignmentstable.png new file mode 100644 index 0000000..85b8e2c Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/elementassignmentstable.png differ diff --git a/bundles/flintstones.model.ui.service/icons/elementvaluations.png b/bundles/flintstones.model.ui.service/icons/elementvaluations.png new file mode 100644 index 0000000..6f97be8 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/elementvaluations.png differ diff --git a/bundles/flintstones.model.ui.service/icons/error.png b/bundles/flintstones.model.ui.service/icons/error.png new file mode 100644 index 0000000..01dd984 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/error.png differ diff --git a/bundles/flintstones.model.ui.service/icons/excel_23x23.png b/bundles/flintstones.model.ui.service/icons/excel_23x23.png new file mode 100644 index 0000000..a5e9409 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/excel_23x23.png differ diff --git a/bundles/flintstones.model.ui.service/icons/execute.png b/bundles/flintstones.model.ui.service/icons/execute.png new file mode 100644 index 0000000..fffaf96 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/execute.png differ diff --git a/bundles/flintstones.model.ui.service/icons/exit.png b/bundles/flintstones.model.ui.service/icons/exit.png new file mode 100644 index 0000000..d55347a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/exit.png differ diff --git a/bundles/flintstones.model.ui.service/icons/exit_16.png b/bundles/flintstones.model.ui.service/icons/exit_16.png new file mode 100644 index 0000000..0c9aa6d Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/exit_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/expert.png b/bundles/flintstones.model.ui.service/icons/expert.png new file mode 100644 index 0000000..869377d Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/expert.png differ diff --git a/bundles/flintstones.model.ui.service/icons/expertsFirst.png b/bundles/flintstones.model.ui.service/icons/expertsFirst.png new file mode 100644 index 0000000..0377109 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/expertsFirst.png differ diff --git a/bundles/flintstones.model.ui.service/icons/flag_china.png b/bundles/flintstones.model.ui.service/icons/flag_china.png new file mode 100644 index 0000000..3e5a7cd Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/flag_china.png differ diff --git a/bundles/flintstones.model.ui.service/icons/flag_china_16.png b/bundles/flintstones.model.ui.service/icons/flag_china_16.png new file mode 100644 index 0000000..0f489b2 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/flag_china_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/flag_spain.png b/bundles/flintstones.model.ui.service/icons/flag_spain.png new file mode 100644 index 0000000..538c0ab Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/flag_spain.png differ diff --git a/bundles/flintstones.model.ui.service/icons/flag_spain_16.png b/bundles/flintstones.model.ui.service/icons/flag_spain_16.png new file mode 100644 index 0000000..efc6fc4 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/flag_spain_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/flag_uk.png b/bundles/flintstones.model.ui.service/icons/flag_uk.png new file mode 100644 index 0000000..3759ac6 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/flag_uk.png differ diff --git a/bundles/flintstones.model.ui.service/icons/flag_uk_16.png b/bundles/flintstones.model.ui.service/icons/flag_uk_16.png new file mode 100644 index 0000000..ffd2ec8 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/flag_uk_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/flintstones.png b/bundles/flintstones.model.ui.service/icons/flintstones.png new file mode 100644 index 0000000..eddeab1 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/flintstones.png differ diff --git a/bundles/flintstones.model.ui.service/icons/framework.png b/bundles/flintstones.model.ui.service/icons/framework.png new file mode 100644 index 0000000..8e31ca5 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/framework.png differ diff --git a/bundles/flintstones.model.ui.service/icons/frameworkstructuring.png b/bundles/flintstones.model.ui.service/icons/frameworkstructuring.png new file mode 100644 index 0000000..a242eaa Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/frameworkstructuring.png differ diff --git a/bundles/flintstones.model.ui.service/icons/gathering.png b/bundles/flintstones.model.ui.service/icons/gathering.png new file mode 100644 index 0000000..c6d6a2b Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/gathering.png differ diff --git a/bundles/flintstones.model.ui.service/icons/graph_16x16.png b/bundles/flintstones.model.ui.service/icons/graph_16x16.png new file mode 100644 index 0000000..1e72f44 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/graph_16x16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/graph_24x24.png b/bundles/flintstones.model.ui.service/icons/graph_24x24.png new file mode 100644 index 0000000..db203e2 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/graph_24x24.png differ diff --git a/bundles/flintstones.model.ui.service/icons/group-of-experts.png b/bundles/flintstones.model.ui.service/icons/group-of-experts.png new file mode 100644 index 0000000..646d055 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/group-of-experts.png differ diff --git a/bundles/flintstones.model.ui.service/icons/info.png b/bundles/flintstones.model.ui.service/icons/info.png new file mode 100644 index 0000000..8c29f9f Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/info.png differ diff --git a/bundles/flintstones.model.ui.service/icons/info2.png b/bundles/flintstones.model.ui.service/icons/info2.png new file mode 100644 index 0000000..d7c237b Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/info2.png differ diff --git a/bundles/flintstones.model.ui.service/icons/load_file_23x23.png b/bundles/flintstones.model.ui.service/icons/load_file_23x23.png new file mode 100644 index 0000000..3f3e0b7 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/load_file_23x23.png differ diff --git a/bundles/flintstones.model.ui.service/icons/new.png b/bundles/flintstones.model.ui.service/icons/new.png new file mode 100644 index 0000000..e6d64bb Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/new.png differ diff --git a/bundles/flintstones.model.ui.service/icons/new_16.png b/bundles/flintstones.model.ui.service/icons/new_16.png new file mode 100644 index 0000000..20dffbf Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/new_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/add.png b/bundles/flintstones.model.ui.service/icons/originales/add.png new file mode 100644 index 0000000..e65d1c8 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/add.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/close.png b/bundles/flintstones.model.ui.service/icons/originales/close.png new file mode 100644 index 0000000..91c2294 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/close.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_Close_Icon_1398919.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_Close_Icon_1398919.png new file mode 100644 index 0000000..53cbb9a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_Close_Icon_1398919.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_Close_Icon_1398919_mod.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_Close_Icon_1398919_mod.png new file mode 100644 index 0000000..53cbb9a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_Close_Icon_1398919_mod.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_File_Files_Folder_Clipboard_Data_Checklist-12_3909328.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_File_Files_Folder_Clipboard_Data_Checklist-12_3909328.png new file mode 100644 index 0000000..3edcecd Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_File_Files_Folder_Clipboard_Data_Checklist-12_3909328.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_arrow_back_backwards_repeat_previous_1868955.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_arrow_back_backwards_repeat_previous_1868955.png new file mode 100644 index 0000000..850da74 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_arrow_back_backwards_repeat_previous_1868955.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_close_square_black_243657.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_close_square_black_243657.png new file mode 100644 index 0000000..6277891 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_close_square_black_243657.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_content-paste_326599.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_content-paste_326599.png new file mode 100644 index 0000000..e0891ae Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_content-paste_326599.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_ic_vertical_align_center_48px_352193.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_ic_vertical_align_center_48px_352193.png new file mode 100644 index 0000000..d788e5a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_ic_vertical_align_center_48px_352193.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_icon-folder_211608.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_icon-folder_211608.png new file mode 100644 index 0000000..cd14a93 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_icon-folder_211608.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/iconfinder_music_forward_front_next_arrow_1868975.png b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_music_forward_front_next_arrow_1868975.png new file mode 100644 index 0000000..2a20be0 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/iconfinder_music_forward_front_next_arrow_1868975.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/if_164_QuestionMark_183285.png b/bundles/flintstones.model.ui.service/icons/originales/if_164_QuestionMark_183285.png new file mode 100644 index 0000000..1d0b49d Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/if_164_QuestionMark_183285.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/if_Close_Icon_Dark_1398917.png b/bundles/flintstones.model.ui.service/icons/originales/if_Close_Icon_Dark_1398917.png new file mode 100644 index 0000000..d87c386 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/if_Close_Icon_Dark_1398917.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/if_Menu_Icon_1398918.png b/bundles/flintstones.model.ui.service/icons/originales/if_Menu_Icon_1398918.png new file mode 100644 index 0000000..443e330 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/if_Menu_Icon_1398918.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/if_Tick_Mark_Dark_1398912.png b/bundles/flintstones.model.ui.service/icons/originales/if_Tick_Mark_Dark_1398912.png new file mode 100644 index 0000000..edc294c Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/originales/if_Tick_Mark_Dark_1398912.png differ diff --git a/bundles/flintstones.model.ui.service/icons/originales/licencias.txt b/bundles/flintstones.model.ui.service/icons/originales/licencias.txt new file mode 100644 index 0000000..7aaecde --- /dev/null +++ b/bundles/flintstones.model.ui.service/icons/originales/licencias.txt @@ -0,0 +1,8 @@ +License Free for commercial use +https://www.iconfinder.com/icons/1398918/device_menu_mobile_smartphone_icon +https://www.iconfinder.com/icons/1398917/circle_close_cross_delete_incorrect_invalid_x_icon +https://www.iconfinder.com/icons/1398912/check_circle_correct_mark_success_tick_yes_icon +https://www.iconfinder.com/icons/183285/help_mark_question_icon +https://www.iconfinder.com/icons/1398919/cancel_close_cross_delete_incorrect_invalid_x_icon +https://www.iconfinder.com/icons/3909328/checklist_clipboard_data_file_files_folder_icon +https://www.iconfinder.com/icons/211608/folder_icon \ No newline at end of file diff --git a/bundles/flintstones.model.ui.service/icons/perspective_ahp.png b/bundles/flintstones.model.ui.service/icons/perspective_ahp.png new file mode 100644 index 0000000..18fb63e Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/perspective_ahp.png differ diff --git a/bundles/flintstones.model.ui.service/icons/perspective_ahpgathering.png b/bundles/flintstones.model.ui.service/icons/perspective_ahpgathering.png new file mode 100644 index 0000000..8326713 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/perspective_ahpgathering.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/_old/criterion.png b/bundles/flintstones.model.ui.service/icons/problemelement/_old/criterion.png new file mode 100644 index 0000000..7a8a5df Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/_old/criterion.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/_old/criterion_cost.png b/bundles/flintstones.model.ui.service/icons/problemelement/_old/criterion_cost.png new file mode 100644 index 0000000..030feee Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/_old/criterion_cost.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/alternative.png b/bundles/flintstones.model.ui.service/icons/problemelement/alternative.png new file mode 100644 index 0000000..bcb6f8a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/alternative.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/alternatives.png b/bundles/flintstones.model.ui.service/icons/problemelement/alternatives.png new file mode 100644 index 0000000..5e8a813 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/alternatives.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/criterion.png b/bundles/flintstones.model.ui.service/icons/problemelement/criterion.png new file mode 100644 index 0000000..17f6525 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/criterion.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/criterion_cost.png b/bundles/flintstones.model.ui.service/icons/problemelement/criterion_cost.png new file mode 100644 index 0000000..41abbb7 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/criterion_cost.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/criterions.png b/bundles/flintstones.model.ui.service/icons/problemelement/criterions.png new file mode 100644 index 0000000..6a9a793 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/criterions.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/expert.png b/bundles/flintstones.model.ui.service/icons/problemelement/expert.png new file mode 100644 index 0000000..869377d Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/expert.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/experts.png b/bundles/flintstones.model.ui.service/icons/problemelement/experts.png new file mode 100644 index 0000000..646d055 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/experts.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/fake.png b/bundles/flintstones.model.ui.service/icons/problemelement/fake.png new file mode 100644 index 0000000..7efcbe3 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/fake.png differ diff --git a/bundles/flintstones.model.ui.service/icons/problemelement/sortclass.png b/bundles/flintstones.model.ui.service/icons/problemelement/sortclass.png new file mode 100644 index 0000000..435bd61 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/problemelement/sortclass.png differ diff --git a/bundles/flintstones.model.ui.service/icons/promethee/promethee_type1.PNG b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type1.PNG new file mode 100644 index 0000000..8256cf6 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type1.PNG differ diff --git a/bundles/flintstones.model.ui.service/icons/promethee/promethee_type2.PNG b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type2.PNG new file mode 100644 index 0000000..b5a6bee Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type2.PNG differ diff --git a/bundles/flintstones.model.ui.service/icons/promethee/promethee_type3.PNG b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type3.PNG new file mode 100644 index 0000000..e5024d6 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type3.PNG differ diff --git a/bundles/flintstones.model.ui.service/icons/promethee/promethee_type4.PNG b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type4.PNG new file mode 100644 index 0000000..0d0051b Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type4.PNG differ diff --git a/bundles/flintstones.model.ui.service/icons/promethee/promethee_type5.PNG b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type5.PNG new file mode 100644 index 0000000..4fa7352 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type5.PNG differ diff --git a/bundles/flintstones.model.ui.service/icons/promethee/promethee_type6.PNG b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type6.PNG new file mode 100644 index 0000000..503ac04 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/promethee/promethee_type6.PNG differ diff --git a/bundles/flintstones.model.ui.service/icons/quick_edit.gif b/bundles/flintstones.model.ui.service/icons/quick_edit.gif new file mode 100644 index 0000000..bdc3f15 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/quick_edit.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/ranking_24x24.png b/bundles/flintstones.model.ui.service/icons/ranking_24x24.png new file mode 100644 index 0000000..aebe7c5 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/ranking_24x24.png differ diff --git a/bundles/flintstones.model.ui.service/icons/rating.png b/bundles/flintstones.model.ui.service/icons/rating.png new file mode 100644 index 0000000..7432376 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/rating.png differ diff --git a/bundles/flintstones.model.ui.service/icons/read_16.png b/bundles/flintstones.model.ui.service/icons/read_16.png new file mode 100644 index 0000000..6bacd35 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/read_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/remove.gif b/bundles/flintstones.model.ui.service/icons/remove.gif new file mode 100644 index 0000000..0ac20f6 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/remove.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/save-and-close.png b/bundles/flintstones.model.ui.service/icons/save-and-close.png new file mode 100644 index 0000000..db5c52b Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/save-and-close.png differ diff --git a/bundles/flintstones.model.ui.service/icons/save-and-close_16.png b/bundles/flintstones.model.ui.service/icons/save-and-close_16.png new file mode 100644 index 0000000..a19ce3f Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/save-and-close_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/save-as.png b/bundles/flintstones.model.ui.service/icons/save-as.png new file mode 100644 index 0000000..b5da838 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/save-as.png differ diff --git a/bundles/flintstones.model.ui.service/icons/save-as_16.png b/bundles/flintstones.model.ui.service/icons/save-as_16.png new file mode 100644 index 0000000..b508491 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/save-as_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/save.png b/bundles/flintstones.model.ui.service/icons/save.png new file mode 100644 index 0000000..aee3e22 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/save.png differ diff --git a/bundles/flintstones.model.ui.service/icons/save_16.png b/bundles/flintstones.model.ui.service/icons/save_16.png new file mode 100644 index 0000000..53d900b Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/save_16.png differ diff --git a/bundles/flintstones.model.ui.service/icons/sensitivity_analysis_24x24.png b/bundles/flintstones.model.ui.service/icons/sensitivity_analysis_24x24.png new file mode 100644 index 0000000..485abea Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/sensitivity_analysis_24x24.png differ diff --git a/bundles/flintstones.model.ui.service/icons/sensitivityanalysis.png b/bundles/flintstones.model.ui.service/icons/sensitivityanalysis.png new file mode 100644 index 0000000..7e0569d Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/sensitivityanalysis.png differ diff --git a/bundles/flintstones.model.ui.service/icons/signed_no.gif b/bundles/flintstones.model.ui.service/icons/signed_no.gif new file mode 100644 index 0000000..c610608 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/signed_no.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/signed_yes.gif b/bundles/flintstones.model.ui.service/icons/signed_yes.gif new file mode 100644 index 0000000..e17722d Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/signed_yes.gif differ diff --git a/bundles/flintstones.model.ui.service/icons/status_right.png b/bundles/flintstones.model.ui.service/icons/status_right.png new file mode 100644 index 0000000..bb6ad74 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/status_right.png differ diff --git a/bundles/flintstones.model.ui.service/icons/status_unknown.png b/bundles/flintstones.model.ui.service/icons/status_unknown.png new file mode 100644 index 0000000..0a425a0 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/status_unknown.png differ diff --git a/bundles/flintstones.model.ui.service/icons/status_wrong.png b/bundles/flintstones.model.ui.service/icons/status_wrong.png new file mode 100644 index 0000000..44c640a Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/status_wrong.png differ diff --git a/bundles/flintstones.model.ui.service/icons/transpose.png b/bundles/flintstones.model.ui.service/icons/transpose.png new file mode 100644 index 0000000..8c27b13 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/transpose.png differ diff --git a/bundles/flintstones.model.ui.service/icons/type-of-criterion.png b/bundles/flintstones.model.ui.service/icons/type-of-criterion.png new file mode 100644 index 0000000..e7d0542 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/type-of-criterion.png differ diff --git a/bundles/flintstones.model.ui.service/icons/valuation-panel.png b/bundles/flintstones.model.ui.service/icons/valuation-panel.png new file mode 100644 index 0000000..a4c5b1f Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/valuation-panel.png differ diff --git a/bundles/flintstones.model.ui.service/icons/valuation.png b/bundles/flintstones.model.ui.service/icons/valuation.png new file mode 100644 index 0000000..4482021 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/valuation.png differ diff --git a/bundles/flintstones.model.ui.service/icons/warning.png b/bundles/flintstones.model.ui.service/icons/warning.png new file mode 100644 index 0000000..e9e3e70 Binary files /dev/null and b/bundles/flintstones.model.ui.service/icons/warning.png differ diff --git a/bundles/flintstones.model.ui.service/src/flintstones/model/ui/service/UiService.java b/bundles/flintstones.model.ui.service/src/flintstones/model/ui/service/UiService.java new file mode 100644 index 0000000..865a3ea --- /dev/null +++ b/bundles/flintstones.model.ui.service/src/flintstones/model/ui/service/UiService.java @@ -0,0 +1,644 @@ +package flintstones.model.ui.service; + +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +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.Monitor; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.wb.swt.SWTResourceManager; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; +import flintstones.helper.debug.DH; +import flintstones.model.ui.service.style.ForegroundStyler; + +/** + * The Interface UiService. + * + * @author UJA + */ +@SuppressWarnings("nls") +public class UiService { + + /** Label to request an "error" font. */ + public static String FONT_TEXT_ERROR = "font_error"; + + /** The font text success. */ + public static String FONT_TEXT_SUCCESS = "font_success"; + + /** Label to request an "section" font. */ + public static String FONT_SECTION_TITLE = "font_section"; + + public static String FONT_BIG_TITLE = "font_big"; + + /** Label to request an "text" font. */ + public static String FONT_TEXT_NORMAL = "font_text"; + + /** Label to request an "bold text" font. */ + public static String FONT_TEXT_BOLD = "font_text_bold"; + + /** Label to request an "bold text" font. */ + public static String FONT_CODE = "font_code"; + + /** Label to request an "warning" font. */ + public static String FONT_WARNING = "font_warning"; + + public static String FONT_BUTTON = "font_button"; + + /** The code background. */ + public static String CODE_BACKGROUND = "code_background"; + + /** The code foreground. */ + public static String CODE_FOREGROUND = "code_foreground"; + + /** The code value. */ + public static String CODE_VALUE = "code_variable"; + + /** The code operator. */ + public static String CODE_OPERATOR = "code_operator"; + + /** The code key. */ + public static String CODE_KEY = "code_object"; + + /** The code string. */ + public static String CODE_STRING = "code_string"; + + /** The code method. */ + public static String CODE_METHOD = "code_method"; + + /** The code condition. */ + public static String CODE_CONDITION = "code_condition"; + + /** The code comment. */ + public static String CODE_COMMENT = "code_comment"; + + /** The code wrong status. */ + public static String CODE_WRONG = "code_wrong"; + + /** The code right status. */ + public static String CODE_RIGHT = "code_right"; + + /** The background color for wrong input elements. */ + public static Color COLOR_BG_WRONG = new Color(Display.getDefault(), 255, 150, 150); + + /** The color background success color. */ + public static Color COLOR_BG_SUCCESS = new Color(Display.getDefault(), 150, 255, 150); + + /** The default background color for input elements. */ + public static Color COLOR_BG_NORMAL = new Color(Display.getDefault(), 255, 255, 255); + + /** The background button normal color. */ + public static Color COLOR_BG_BUTTON_NORMAL = new Color(Display.getDefault(), 228, 228, 228); + + /** The background button highlight. */ + public static Color COLOR_BG_BUTTON_HIGHLIGHT = new Color(Display.getDefault(), 225, 245, 243); + + /** The background button highlight 2. */ + public static Color COLOR_BG_BUTTON_HIGHLIGHT2 = new Color(Display.getDefault(), 240, 230, 220); + + /** The background color for disabled input elements. */ + public static Color COLOR_BG_DISABLED = new Color(Display.getDefault(), 215, 215, 215); + + /** The color foreground normal color. */ + public static Color COLOR_FG_NORMAL = new Color(Display.getDefault(), 0, 0, 0); + + /** The color foreground secondary color. */ + public static Color COLOR_FG_SECONDARY = new Color(Display.getDefault(), 149, 125, 71); + + public static Color COLOR_FG_ERROR = new Color(Display.getDefault(), 150, 0, 0); + + public static Color COLOR_FG_SUCCESS = new Color(Display.getDefault(), 0, 150, 0); + + //public static Color COLOR_MAIN = new Color(Display.getDefault(), 0, 144, 255); + public static Color COLOR_MAIN = new Color(Display.getDefault(), 61, 113, 178); // CONTROL -> button_background + public static Color COLOR_MAIN_FG = new Color(Display.getDefault(), 255, 255, 255); // CONTROL -> button_foreground + public static Color COLOR_BORDER_BG = new Color(Display.getDefault(), 173, 173, 173); // Composite + public static Color COLOR_MAIN_HOVER = new Color(Display.getDefault(), 124, 182, 255); // HOVER + + public static Color COLOR_SECONDARY = new Color(Display.getDefault(), 135, 113, 179); // CONTROL -> button_background + public static Color COLOR_SECONDARY_FG = new Color(Display.getDefault(), 255, 255, 255); // CONTROL -> button_foreground + public static Color COLOR_SECONDARY_HOVER = new Color(Display.getDefault(), 95, 53, 181); + + public static Color COLOR_TERTIARY = new Color(Display.getDefault(), 181, 158, 53); // CONTROL -> button_background + public static Color COLOR_TERTIARY_FG = new Color(Display.getDefault(), 255, 255, 255); // CONTROL -> button_foreground + public static Color COLOR_TERTIARY_HOVER = new Color(Display.getDefault(), 181, 158, 77); + + + + /** Add button. */ + public static String IMAGE_CONTROLS_ADD = "add.png"; + + /** Edit button. */ + public static String IMAGE_CONTROLS_EDIT = "quick_edit.gif"; + + /** Remove button. */ + public static String IMAGE_CONTROLS_REMOVE = "remove.gif"; + + /** Run button. */ + public static String IMAGE_CONTROLS_RUN = "execute.png"; + + /** Deselect button. */ + public static String IMAGE_CONTROLS_DESELECT = "deselect.png"; + + /** + * Apply predefined styles to labels and other text elements based on the type + * of the element. "section", "error". + * + * @param item A Label or text item + * @param type The chosen style for the item. + */ + public static void setFont(Control item, String type) { + if (type.equals(UiService.FONT_SECTION_TITLE)) + item.setFont(SWTResourceManager.getFont("Cantarell", 11, SWT.BOLD)); + else if (type.equals(UiService.FONT_TEXT_ERROR)) + item.setFont(SWTResourceManager.getFont("Helvetica", 8, SWT.ITALIC)); + else if (type.equals(UiService.FONT_TEXT_SUCCESS)) + item.setFont(SWTResourceManager.getFont("Helvetica", 8, SWT.ITALIC)); + else if (type.equals(UiService.FONT_TEXT_NORMAL)) + item.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.NORMAL)); + else if (type.equals(UiService.FONT_TEXT_BOLD)) + item.setFont(SWTResourceManager.getFont("Cantarell", 10, SWT.BOLD)); + else if (type.equals(UiService.FONT_CODE)) + item.setFont(SWTResourceManager.getFont("Consolas", 10, SWT.NORMAL)); + else if (type.equals(UiService.FONT_WARNING)) + item.setFont(SWTResourceManager.getFont("Occidental", 10, SWT.BOLD)); + else if (type.equals(UiService.FONT_BIG_TITLE)) + item.setFont(SWTResourceManager.getFont("Times New Roman", 17, SWT.BOLD)); + else if (type.equals(UiService.FONT_BUTTON)) + item.setFont(SWTResourceManager.getFont("Helvetica", 10, SWT.BOLD)); + else + throw new Error("El estilo seleccionado no ex�ste. No se aplicar� estilo: " + type); + } + + // https://stackoverflow.com/questions/1449968/change-just-the-font-size-in-swt + public static void setFontSize(Control item, int size) { + FontData[] fD = item.getFont().getFontData(); + fD[0].setHeight(size); + item.setFont(new Font(Display.getCurrent(), fD[0])); + } + + public static void setFontColor(Control item, Color c) { + item.setForeground(c); + } + + public static void setFontFamily(Control item, String font) { + + FontData[] fD = item.getFont().getFontData(); + fD[0].setName(font); + item.setFont(new Font(Display.getCurrent(), fD[0])); + + } + + /** + * Apply GridData to an items. It work like a GridData wrapper that place an + * element into a GridLayout using gravity-like params. + * + * @param item The item to position + * @param horAlign Horizontal alignment. -1 LEFT. 0 CENTER. 1 RIGHT. 9 FILL. + * @param verAlign Vertical alignment. -1 BOTTM. 0 CENTER. 1 UP. 9 FILL. + * @param horGrab Grab extra horizontal spacing. + * @param verGrab Grab extra vertical spacing. + * @return The styled gridData. + */ + public static GridData setGridData(Control item, int horAlign, int verAlign, boolean horGrab, boolean verGrab) { + + int horizontal = SWT.CENTER; + if (horAlign == -1) + horizontal = SWT.LEFT; + if (horAlign == 1) + horizontal = SWT.RIGHT; + if (horAlign == 9) + horizontal = SWT.FILL; + + int vertical = SWT.CENTER; + if (verAlign == -1) + vertical = SWT.BOTTOM; + if (verAlign == 1) + vertical = SWT.TOP; + if (verAlign == 9) + vertical = SWT.FILL; + + GridData data = new GridData(horizontal, vertical, horGrab, verGrab); + + item.setLayoutData(data); + + return data; + + } + + /** + * Creates a new GridLayout with the given columns. + * + * @param base The base layout + * @param colNumber Number of columns 1+. + * @return The new layout + */ + public static GridLayout setGridLayout(Composite base, int colNumber) { + return setGridLayout(base, colNumber, false); + } + + /** + * Creates a new GridLayout with the given columns. + * + * @param base The base layout + * @param colNumber Number of columns 1+. + * @param sameWidth the same width + * @return The new layout + */ + public static GridLayout setGridLayout(Composite base, int colNumber, boolean sameWidth) { + GridLayout gridLayout = new GridLayout(colNumber, sameWidth); + gridLayout.verticalSpacing = 0; + base.setLayout(gridLayout); + return gridLayout; + } + + /** + * Sets the background color. + * + * @param c the c + * @param r the red value + * @param g the green value + * @param b the blue value + */ + public static void setBackgroundColor(Control c, Color color) { + c.setBackground(color); + } + + /** + * Sets the background color. + * + * @param c the composite + * @param all every color value + */ + public static void setBackgroundColor(Control c, int all) { + setBackgroundColor(c, getColor(all, all, all)); + } + + public static void setBackgroundColor(Control c, int r, int g, int b) { + setBackgroundColor(c, getColor(r, g, b)); + } + + /** + * Gets the color. + * + * @param all the all + * @return the color + */ + public static Color getColor(int all) { + return getColor(all, all, all); + } + + /** + * Gets the swt color object. + * + * @param r the red value + * @param g the green value + * @param b the blue value + * @return the color + */ + public static Color getColor(int r, int g, int b) { + return new Color(Display.getCurrent(), r, g, b); + } + + public static Color[] getColorScale(int cuts, boolean reverse) { + + int max = 255; + int desp = 255 / cuts; + + Color[] colors = new Color[cuts]; + + for (int i = 0; i < cuts; i++) { + int despI = desp * i; + + if (reverse) + colors[i] = getColor(despI, max - despI, 0); + else + colors[i] = getColor(max - despI, despI, 0); + } + + return colors; + } + + public static String toHEX(Color c) { + RGB rgb = c.getRGB(); + return String.format("#%02x%02x%02x", rgb.red, rgb.green, rgb.blue); + } + + /** + * Get the swt code color for code/pseudocode. + * + * @param type the type + * @param dark the dark + * @return the code color + */ + public static Color getCodeForeground(String type, boolean dark) { + + if (dark) { + + if (type.equals(UiService.CODE_BACKGROUND)) + return getColor(28, 31, 34); + if (type.equals(UiService.CODE_VALUE)) + return getColor(237, 127, 66); + if (type.equals(UiService.CODE_KEY)) + return getColor(102, 225, 248); + if (type.equals(UiService.CODE_STRING)) + return getColor(23, 173, 103); + if (type.equals(UiService.CODE_METHOD)) + return getColor(125, 236, 33); + if (type.equals(UiService.CODE_CONDITION)) + return getColor(204, 120, 50); + if (type.equals(UiService.CODE_WRONG)) + return getColor(255, 0, 0); + if (type.equals(UiService.CODE_RIGHT)) + return getColor(0, 255, 0); + return getColor(255, 255, 255); + + } + + if (type.equals(UiService.CODE_BACKGROUND)) + return getColor(28, 31, 34); + if (type.equals(UiService.CODE_VALUE)) + return getColor(237, 127, 66); + if (type.equals(UiService.CODE_KEY)) + return getColor(102, 225, 248); + if (type.equals(UiService.CODE_STRING)) + return getColor(23, 173, 103); + if (type.equals(UiService.CODE_METHOD)) + return getColor(125, 236, 33); + if (type.equals(UiService.CODE_CONDITION)) + return getColor(204, 120, 50); + if (type.equals(UiService.CODE_WRONG)) + return getColor(255, 0, 0); + if (type.equals(UiService.CODE_RIGHT)) + return getColor(0, 255, 0); + return getColor(255, 255, 255); + + } + + /** + * Get the swt style for code/pseudocode. + * + * @param type the type + * @param dark the dark theme is enabled? + * @return the code style + */ + public static int getCodeStyle(String type, boolean dark) { + if (type.equals(UiService.CODE_COMMENT)) + return SWT.BOLD; + if (type.equals(UiService.CODE_WRONG)) + return SWT.BOLD; + if (type.equals(UiService.CODE_RIGHT)) + return SWT.BOLD; + return SWT.NONE; + + } + + /** + * Sets the margin. + * + * @param base the base + * @param all all the sides margin + * @return the grid layout + */ + public static GridLayout setMargin(Composite base, int all) { + return setMargin(base, all, all, all, all); + } + + /** + * Sets the margin. + * + * @param base the base + * @param vertical up/down side margin + * @param horizontal right/left side margin + * @return the grid layout + */ + public static GridLayout setMargin(Composite base, int vertical, int horizontal) { + return setMargin(base, vertical, horizontal, vertical, horizontal); + } + + /** + * Sets the margin. + * + * @param base the base + * @param up the up margin + * @param right the right margin + * @param down the down margin + * @param left the left margin + * @return the grid layout + */ + public static GridLayout setMargin(Composite base, int up, int right, int down, int left) { + GridLayout current = (GridLayout) base.getLayout(); + current.marginTop = up; + current.marginRight = right; + current.marginLeft = left; + current.marginBottom = down; + current.verticalSpacing = (up + down)/2; + base.setLayout(current); + return current; + } + + /** + * Debug UI with colors using grayscale backgrounds. + * + * @param args the args + */ + public static void debugWithColors(Control... args) { + int total = args.length; + int step = 256 / total; + + for (int i = 0; i < total; i++) { + Control c = args[i]; + setBackgroundColor(c, i * step); + } + } + + /** + * Re layout shell to adjust it to the content size. + * + * @param shell the shell + */ + public static void reLayoutShell(Shell shell) { + shell.layout(true, true); + final Point newSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + shell.setSize(newSize); + + centerShell(shell, false); + } + + /** + * Center shell into the window/monitor. + * + * @param shell the shell + * @param inMonitor the in monitor + */ + public static void centerShell(Shell shell, boolean inMonitor) { + + int x; + int y; + if (inMonitor) { + Monitor m = shell.getMonitor(); + Rectangle bounds = m.getBounds(); + Rectangle rect = shell.getBounds(); + + x = bounds.x + (bounds.width - rect.width) / 2; + y = bounds.y + (bounds.height - rect.height) / 2; + } else { + Rectangle parentSize = shell.getParent().getBounds(); + Rectangle shellSize = shell.getBounds(); + x = (parentSize.width - shellSize.width) / 2 + parentSize.x; + y = (parentSize.height - shellSize.height) / 2 + parentSize.y; + } + + shell.setLocation(x, y); + } + + /** + * Sets the background color. + * + * @param c the c + * @param color the color + */ + private static ImageDescriptor getImageDescriptor(String folder, String fileName) { + Bundle bundle = FrameworkUtil.getBundle(UiService.class); + + URL url = FileLocator.find(bundle, new Path("icons/" + fileName), null); + ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url); + + return imageDescriptor; + + } + + /** + * Gets the icon. + * + * @param name the name + * @return the icon + */ + public static ImageDescriptor getIcon(String name, Composite parent) { + return getImageDescriptor("icons", name); + } + + /** + * Gets the image. + * + * @param name the name + * @return the image + */ + public static ImageDescriptor getImage(String name, Composite parent) { + return getImageDescriptor("images", name); + } + + /** + * Gets the icon and will dispose it when the parent composite is disposed. + * + * @param name the name + * @param parent the parent + * @return the icon + */ + public static ImageDescriptor getIcon(String name) { + if (!name.contains(".")) + name += ".png"; + return getIcon(name, null); + } + + /** + * Gets the image and will dispose it when the parent composite is disposed. + * + * @param name the name + * @param parent the parent + * @return the image + */ + public static ImageDescriptor getImage(String name) { + return getImage(name, null); + } + + public static StyledString paintText(String primaryText, String secondaryText, Color secondaryColor) { + return paintText(primaryText, secondaryText, UiService.COLOR_FG_NORMAL, secondaryColor); + } + + public static StyledString paintText(String primaryText, String secondaryText, Color primaryColor, + Color secondaryColor) { + + Color foregroundColorLeft = primaryColor; + Color foregroundColorRight = secondaryColor; + + StyledString leftT = new StyledString(primaryText, new ForegroundStyler(foregroundColorLeft)); + StyledString rightT = new StyledString(secondaryText, new ForegroundStyler(foregroundColorRight)); + + return leftT.append(" ").append(rightT); + } + + public static StyledString paintTextWithBrackets(String primaryText, String secondaryText) { + return paintTextWithBrackets(primaryText, secondaryText, UiService.COLOR_FG_NORMAL, UiService.COLOR_FG_SECONDARY); + } + + public static StyledString paintTextWithBrackets(String primaryText, String secondaryText, Color secondaryColor) { + return paintTextWithBrackets(primaryText, secondaryText, UiService.COLOR_FG_NORMAL, secondaryColor); + } + + public static StyledString paintTextWithBrackets(String primaryText, String secondaryText, Color primaryColor, + Color secondaryColor) { + + Color foregroundColorLeft = primaryColor; + Color foregroundColorRight = secondaryColor; + + StyledString leftT = new StyledString(primaryText, new ForegroundStyler(foregroundColorLeft)); + StyledString rightT = new StyledString("["+secondaryText+"]", new ForegroundStyler(foregroundColorRight)); + + return leftT.append(" ").append(rightT); + } + + public static GridData setGridDataAuto(Control control) { + if (control instanceof Label) + return setGridData(control, -1, 1, true, false); + if (control instanceof Text) + return setGridData(control, 9, 0, true, false); + else if (control instanceof Composite) + return setGridData(control, 9, 9, true, true); + + throw new RuntimeException("Control no soportado " + control.getClass()); + + } + + public static void DumpComposites(Composite base, int level) { + + String t = "\t"; + String tabs = ""; + for (int i = 0; i < level; i++) + tabs += t; + + DH.out(tabs + base.getLayout() + " s " + base.getSize() ); +// DH.out(tabs + base.getLayoutData()); + if (base.getLayout() instanceof GridLayout) { +// GridLayout l = (GridLayout) base.getLayout(); + GridData d = (GridData) base.getLayoutData(); + DH.out(tabs + d); + + } + + Control[] controls = base.getChildren(); + for (Control c : controls) + if (c instanceof Composite) + DumpComposites((Composite) c, level + 1); + else + DH.out(tabs + t + c.toString()); + + } + +} diff --git a/bundles/flintstones.model.ui.service/src/flintstones/model/ui/service/style/ForegroundStyler.java b/bundles/flintstones.model.ui.service/src/flintstones/model/ui/service/style/ForegroundStyler.java new file mode 100644 index 0000000..65c8445 --- /dev/null +++ b/bundles/flintstones.model.ui.service/src/flintstones/model/ui/service/style/ForegroundStyler.java @@ -0,0 +1,20 @@ +package flintstones.model.ui.service.style; + +import org.eclipse.jface.viewers.StyledString.Styler; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.TextStyle; + +public class ForegroundStyler extends Styler { + + Color chosenColor; + + public ForegroundStyler(Color color) { + chosenColor = color; + } + + @Override + public void applyStyles(TextStyle textStyle) { + textStyle.foreground = chosenColor; + } + +} diff --git a/bundles/flintstones.model.valuation.provider/.classpath b/bundles/flintstones.model.valuation.provider/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.valuation.provider/.polyglot.META-INF b/bundles/flintstones.model.valuation.provider/.polyglot.META-INF new file mode 100644 index 0000000..c52f093 --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.valuation.provider + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Provider + diff --git a/bundles/flintstones.model.valuation.provider/.project b/bundles/flintstones.model.valuation.provider/.project new file mode 100644 index 0000000..13176e9 --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/.project @@ -0,0 +1,50 @@ + + + flintstones.model.valuation.provider + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362730 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.valuation.provider/META-INF/MANIFEST.MF b/bundles/flintstones.model.valuation.provider/META-INF/MANIFEST.MF new file mode 100644 index 0000000..29054b8 --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Provider +Bundle-SymbolicName: flintstones.model.valuation.provider +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.valuation.provider +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.helper.extensionpoint, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + javax.inject, + javax.annotation, + flintstones.entity.problemelement, + flintstones.entity.valuation, + flintstones.entity.domain, + org.eclipse.e4.ui.di, + flintstones.application.constants, + flintstones.model.valuation.service, + org.eclipse.e4.ui.model.workbench, + javax.annotation, + flintstones.model.problemelement.service, + flintstones.model.domain.service, + flintstones.helper.debug +Service-Component: component.xml +Bundle-ActivationPolicy: lazy diff --git a/bundles/flintstones.model.valuation.provider/build.properties b/bundles/flintstones.model.valuation.provider/build.properties new file mode 100644 index 0000000..6247cd0 --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml diff --git a/bundles/flintstones.model.valuation.provider/component.xml b/bundles/flintstones.model.valuation.provider/component.xml new file mode 100644 index 0000000..cfb336b --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/component.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/bundles/flintstones.model.valuation.provider/src/flintstones/model/valuation/provider/ValuationServiceContextFunction.java b/bundles/flintstones.model.valuation.provider/src/flintstones/model/valuation/provider/ValuationServiceContextFunction.java new file mode 100644 index 0000000..882e0bc --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/src/flintstones/model/valuation/provider/ValuationServiceContextFunction.java @@ -0,0 +1,25 @@ +package flintstones.model.valuation.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.model.valuation.service.IValuationService; + + +/** + * The Class ValuationServiceContextFunction add the Valuation Service instance to global context. + */ +public class ValuationServiceContextFunction extends ContextFunction { + + @Override + public Object compute(IEclipseContext context, String contextKey) { + IValuationService service = ContextInjectionFactory.make(ValuationServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IValuationService.class, service); + return service; + } + +} diff --git a/bundles/flintstones.model.valuation.provider/src/flintstones/model/valuation/provider/ValuationServiceProvider.java b/bundles/flintstones.model.valuation.provider/src/flintstones/model/valuation/provider/ValuationServiceProvider.java new file mode 100644 index 0000000..4d8a284 --- /dev/null +++ b/bundles/flintstones.model.valuation.provider/src/flintstones/model/valuation/provider/ValuationServiceProvider.java @@ -0,0 +1,265 @@ +package flintstones.model.valuation.provider; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; + +import flintstones.application.constants.FrameworkConstants; +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.Alternative; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.Expert; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.BaseRegistry.InvalidExtensionIdentifier; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.problemelement.service.IProblemElementService; +import flintstones.model.valuation.service.IValuationService; + +/** + * @author Sinbad2 + * + */ +class ValuationServiceProvider implements IValuationService { + + @Inject + IEclipseContext context; + + @Inject + IProblemElementService problemService; + + @Inject + IDomainService domainService; + + private BaseRegistry reg; + + private LinkedHashMap valuationsK = new LinkedHashMap<>(); + + /** + * Valuation Service + */ + public ValuationServiceProvider() { + } + + @PostConstruct + private void init() { + this.reg = new BaseRegistry(Valuation.EXTENSION_POINT); + this.valuationsK = new LinkedHashMap<>(); + } + + @Override + public Valuation[] getAll() { + return this.valuationsK.values().toArray(new Valuation[this.valuationsK.values().size()]); + } + + @Override + public LinkedHashMap getAllKV() { + return this.valuationsK; + } + + @Override + public String getExtensionIdFor(String domainType) { + ExtensionRegistry[] eArr = this.reg.getAllRegistriesWhere(Valuation.Fields.domain, domainType); + for (ExtensionRegistry e : eArr) + if (!e.getAttributeBoolean(Valuation.Fields.is_intermediate)) + return e.getAttribute(Valuation.Fields.uid); + return null; + + } + + @Override + public String getDomainFor(String valuationId) { + return this.reg.getFirstRegistryWhere(Valuation.Fields.uid, valuationId).getAttribute(Valuation.Fields.domain); + } + + @Override + public String getExtensionNameFor(String domainType) { + ExtensionRegistry[] eArr = this.reg.getAllRegistriesWhere(Valuation.Fields.domain, domainType); + for (ExtensionRegistry e : eArr) + if (!e.getAttributeBoolean(Valuation.Fields.is_intermediate)) + return e.getAttribute(Valuation.Fields.name); + return null; + + } + + @Override + public Valuation create(Domain d) { + String domainId = d.getType(); + String valuationId = getExtensionIdFor(domainId); + Valuation valuation = null; + try { + if(valuationId == null) + return null; + valuation = (Valuation) this.reg.instantiate(valuationId, this.context); + valuation.setId(valuationId); + valuation.setName(this.reg.getFirstRegistryWhere(Valuation.Fields.uid, valuationId) + .getAttribute(Valuation.Fields.name)); + valuation.setDomain(d); + + } catch (InvalidExtensionIdentifier e) { + e.printStackTrace(); + } + + return valuation; + } + + @Override + public void addOrUpdate(ProblemElementKey pek, Valuation v) { + if (pek.getCriterion().hasChildren()) { + throw new RuntimeException("No se permiten pek con child " + pek.getCriterion().getName()); + } + + if (pek.getExpert().hasChildren()) { + throw new RuntimeException("No se permiten pek con child" + pek.getExpert().getName()); + } + + this.valuationsK.put(pek, v); + } + + @Override + public Valuation[] getAllValuationsWith(ProblemElement item) { + + String type = item.getType(); + + return this.valuationsK.entrySet().stream().filter(k -> k.getKey().get(type).getName().equals(item.getName())) + .map(k -> k.getValue()).toArray(Valuation[]::new); + + } + + @Override + public HashMap getAllValuationsKVWith(ProblemElement item) { + + String type = item.getType(); + HashMap result = new HashMap<>(); + + this.valuationsK.entrySet().stream().filter(k -> k.getKey().get(type).getName().equals(item.getName())) + .forEach(entry -> result.put(entry.getKey(), entry.getValue())); + + return result; + + } + + @Override + public Valuation getValuationFor(ProblemElementKey pek) { + return this.valuationsK.get(pek); + } + + @Override + public void removeValuationFor(Domain domain) { + + List peks = this.valuationsK.entrySet().stream() + // Filter the valuation with the searched domain + .filter(k -> k.getValue().getDomain().getName().equals(domain.getName())) + // Map KEY,VALUE -> KEY + .map(k2 -> k2.getKey()) + // To a list, we cannot modify the DE that we are reading + .collect(Collectors.toList()); + + // Delete all of them + peks.forEach(k3 -> this.valuationsK.remove(k3)); + + } + + @Override + public void removeValuationFor(String type, ProblemElement item) { + + List peksToRemove = new LinkedList(); + for(ProblemElementKey pek: this.valuationsK.keySet()) { + if(pek.get(type) != null) { + if(pek.get(type).getName().equals(item.getName())) + peksToRemove.add(pek); + } + } + + peksToRemove.forEach(k3 -> this.valuationsK.remove(k3)); + + } + + @Override + public void clear() { + this.valuationsK.clear(); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + for (Entry entry : valuationsK.entrySet()) + sb.append((entry.getValue().isEvaluated() ? "V" : "X") + " | " + entry.getKey().toString() + " ==> " + + entry.getValue() + " | " + entry.getValue().getId() + "\n"); + + return sb.toString(); + + } + + @Override + public boolean isAssignmentFilled() { + + ProblemElement[] experts = problemService.getSubElements(Expert.Type); + ProblemElement[] criterions = problemService.getSubElements(Criterion.Type); + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + + for (ProblemElement e : experts) + for (ProblemElement c : criterions) + for (ProblemElement a : alternatives) + if (getValuationFor(new ProblemElementKey((Expert) e, (Alternative) a, (Criterion) c)) == null) + return false; + return true; + + } + + @Override + public boolean isEvaluationFilled() { + + if (!isAssignmentFilled()) + return false; + + ProblemElement[] experts = problemService.getSubElements(Expert.Type); + ProblemElement[] criterions = problemService.getSubElements(Criterion.Type); + ProblemElement[] alternatives = problemService.getAll(Alternative.Type); + + for (ProblemElement e : experts) + for (ProblemElement c : criterions) + for (ProblemElement a : alternatives) + if (!getValuationFor(new ProblemElementKey((Expert) e, (Alternative) a, (Criterion) c)) + .isEvaluated()) + return false; + return true; + } + + @Override + public void removeValuation(ProblemElementKey pek) { + // Create a new one. + Valuation v = valuationsK.get(pek); + v = create(v.getDomain()); + valuationsK.put(pek, v); + } + + @Inject + @Optional + private void subscribe(@UIEventTopic(FrameworkConstants.TOPIC_FRAMEWORK_DOMAIN_DELETED) Domain d) { + + for (Entry entry : this.getAllKV().entrySet()) { + ProblemElementKey pek = entry.getKey(); + Valuation v = entry.getValue(); + + if (v.getDomain().equals(d)) { + this.valuationsK.remove(pek); + v.setDomain(null); + } + } + } +} diff --git a/bundles/flintstones.model.valuation.service/.classpath b/bundles/flintstones.model.valuation.service/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.model.valuation.service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.model.valuation.service/.polyglot.META-INF b/bundles/flintstones.model.valuation.service/.polyglot.META-INF new file mode 100644 index 0000000..21d4e1a --- /dev/null +++ b/bundles/flintstones.model.valuation.service/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.model.valuation.service + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Service + diff --git a/bundles/flintstones.model.valuation.service/.project b/bundles/flintstones.model.valuation.service/.project new file mode 100644 index 0000000..c0c7ee9 --- /dev/null +++ b/bundles/flintstones.model.valuation.service/.project @@ -0,0 +1,45 @@ + + + flintstones.model.valuation.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362730 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.model.valuation.service/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.model.valuation.service/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.model.valuation.service/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.model.valuation.service/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.model.valuation.service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.model.valuation.service/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.model.valuation.service/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.model.valuation.service/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.model.valuation.service/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.model.valuation.service/META-INF/MANIFEST.MF b/bundles/flintstones.model.valuation.service/META-INF/MANIFEST.MF new file mode 100644 index 0000000..fe4c607 --- /dev/null +++ b/bundles/flintstones.model.valuation.service/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Service +Bundle-SymbolicName: flintstones.model.valuation.service +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.model.valuation.service, +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.valuation;visibility:=reexport, + flintstones.entity.problemelement, + flintstones.entity.domain +Export-Package: flintstones.model.valuation.service diff --git a/bundles/flintstones.model.valuation.service/build.properties b/bundles/flintstones.model.valuation.service/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.model.valuation.service/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.model.valuation.service/src/flintstones/model/valuation/service/IValuationService.java b/bundles/flintstones.model.valuation.service/src/flintstones/model/valuation/service/IValuationService.java new file mode 100644 index 0000000..f916713 --- /dev/null +++ b/bundles/flintstones.model.valuation.service/src/flintstones/model/valuation/service/IValuationService.java @@ -0,0 +1,117 @@ +package flintstones.model.valuation.service; + +import java.util.HashMap; +import java.util.LinkedHashMap; + +import flintstones.entity.domain.Domain; +import flintstones.entity.problemelement.ProblemElementKey; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; + +/** + * The Interface IValuationService. + * + * @author Sinbad2 Valuation Service Proider + */ +public interface IValuationService { + + /** + * Creates a Valuation for the given extension point with the given domain. + * + * @param id extension point id + * @param d domain + * @return Working valuation + */ + public Valuation create(Domain d); + + /** + * Inserts or updates a valuation into the service. + * + * @param pek Problem element key to assing the valuation + * @param v The valuation + */ + void addOrUpdate(ProblemElementKey pek, Valuation v); + + void removeValuation(ProblemElementKey pek); + + /** + * Gets the extension id for the given domain type. + * + * @param domainType the domain type + * @return Every extension ID for the given domain + */ + String getExtensionIdFor(String domainType); + + /** + * Gets the extension name for the given domain type. + * + * @param domainType the domain type + * @return the extension name for + */ + String getExtensionNameFor(String domainType); + + /** + * Gets every valuation. + * + * @return Every valuation + */ + Valuation[] getAll(); + + /** + * Gets the valuation for a PEK. + * + * @param pek Problem element key + * @return The valuation assigned to the PE Key given + */ + Valuation getValuationFor(ProblemElementKey pek); + + /** + * Removes the valuation for a given domain. + * + * @param domain the domain + */ + void removeValuationFor(Domain domain); + + /** + * Removes the valuation for an PE item. + * + * @param type the type + * @param item the item + */ + void removeValuationFor(String type, ProblemElement item); + + /** + * Gets the domain for a valuation. + * + * @param valuationId the valuation id + * @return the domain for + */ + String getDomainFor(String valuationId); + + /** + * Clear the service memory. + */ + void clear(); + + /** + * Gets the all the Key-Value PEK-Valuation. + * + * @return the all KV + */ + LinkedHashMap getAllKV(); + + /** + * Gets the all valuations for a given ProblemElement. + * + * @param item the item + * @return the all valuations + */ + Valuation[] getAllValuationsWith(ProblemElement item); + + HashMap getAllValuationsKVWith(ProblemElement item); + + boolean isAssignmentFilled(); + + boolean isEvaluationFilled(); + +} diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/.classpath b/bundles/flintstones.operator.aggregation.arithmeticmean/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.arithmeticmean/.polyglot.META-INF new file mode 100644 index 0000000..7e16e8e --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.arithmeticmean + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Arithmetic Mean + diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/.project b/bundles/flintstones.operator.aggregation.arithmeticmean/.project new file mode 100644 index 0000000..5f083b5 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.arithmeticmean + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362731 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..9f6ece8 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +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.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.arithmeticmean/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0c71806 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Arithmetic Mean +Bundle-SymbolicName: flintstones.operator.aggregation.arithmeticmean;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.aggregation.arithmeticmean +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric.integer, + flintstones.valuation.numeric.real, + flintstones.valuation.linguistic, + flintstones.valuation.twoTuple, + flintstones.valuation.proportionaltwotuple, + flintstones.valuation.fuzzy, + flintstones.valuation.elicit, + flintstones.domain.numeric.real, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di, + flintstones.entity.domain, + flintstones.entity.operator +Export-Package: flintstones.operator.aggregation.arithmeticmean +Import-Package: org.eclipse.jface.wizard diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/build.properties b/bundles/flintstones.operator.aggregation.arithmeticmean/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/plugin.xml b/bundles/flintstones.operator.aggregation.arithmeticmean/plugin.xml new file mode 100644 index 0000000..b9acaa0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/plugin.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/ArithmeticMean.java b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/ArithmeticMean.java new file mode 100644 index 0000000..b50d651 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/ArithmeticMean.java @@ -0,0 +1,19 @@ +package flintstones.operator.aggregation.arithmeticmean; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; +import flintstones.entity.operator.interfaces.IWeightedAggregationOperator; + +/** + * The Class ArithmeticMean. + * https://en.wikipedia.org/wiki/Arithmetic_mean + */ +public abstract class ArithmeticMean extends AggregationOperator implements IUnweightedAggregationOperator, IWeightedAggregationOperator { + + public static final String ID = "flintstones.operator.aggregation.arithmeticmean"; + + @Override + public String getName() { + return "Arithmetic Mean"; + } +} diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanDouble.java b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanDouble.java new file mode 100644 index 0000000..eec2f90 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanDouble.java @@ -0,0 +1,77 @@ +package flintstones.operator.aggregation.arithmeticmean.operators; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.arithmeticmean.ArithmeticMean; +import flintstones.valuation.numeric.real.RealValuation; + +public class ArithmeticMeanDouble extends ArithmeticMean { + + + @Override + public Valuation aggregate(List valuations) { + + RealValuation result = null; + double value = 0; + int size = valuations.size(); + NumericRealDomain domain = null; + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {RealValuation.class.toString()}); + + if(domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.RealOperator_Invalid_domain"); + } + + value += (((RealValuation) valuation).getValue()) / size; + } + + if(domain != null) { + result = (RealValuation) valuations.get(0).clone(); + result.setValue(value); + } + + return result; + } + + + @Override + public Valuation aggregate(List valuations, List weights) { + RealValuation result = null; + double measure = 0; + List measures = new LinkedList(); + NumericRealDomain domain = null; + + for(Valuation valuation : valuations) { + + Validator.notIllegalElementType(valuation, new String[] { RealValuation.class.toString() }); + + if (domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.RealOperator_Invalid_domain"); + } + + measures.add(((RealValuation) valuation).getValue()); + } + + if (domain != null) { + int size = measures.size(); + for (int i = 0; i < size; i++) { + measure += weights.get(i) * measures.get(i); + } + + result = (RealValuation) valuations.get(0).clone(); + result.setValue( measure); + } + + return result; + + } +} diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanELICIT.java b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanELICIT.java new file mode 100644 index 0000000..b816b70 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanELICIT.java @@ -0,0 +1,79 @@ +package flintstones.operator.aggregation.arithmeticmean.operators; + +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.arithmeticmean.ArithmeticMean; +import flintstones.valuation.elicit.ELICIT; + +public class ArithmeticMeanELICIT extends ArithmeticMean { + + @Inject + IEclipseContext context; + + @Override + public Valuation aggregate(List valuations) { + ELICIT v = null; + + TrapezoidalFunction tpf, + tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] {0, 0, 0, 0}); + + int size = valuations.size(); + for(int i = 0; i < size; ++i) { + v = (ELICIT) valuations.get(i); + Validator.notIllegalElementType(v, new String[] { ELICIT.class.toString() }); + + if(((ELICIT) v).getBeta() == null) + tpf = ((ELICIT) v).calculateFuzzyEnvelope(); + else + tpf = ((ELICIT) v).getBeta(); + + tpfResult = tpfResult.additionAlphaCuts(tpf); + } + + tpfResult = tpfResult.divisionScalar(size); + + ELICIT aggregatedElicit = ContextInjectionFactory.make(ELICIT.class, context); + aggregatedElicit.setDomain(valuations.get(0).getDomain()); + aggregatedElicit.createRelation(tpfResult); + + return aggregatedElicit; + } + + @Override + public Valuation aggregate(List valuations, List weights) { + ELICIT v = null; + + TrapezoidalFunction tpf, + tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] {0, 0, 0, 0}); + + int size = valuations.size(); + for(int i = 0; i < size; ++i) { + v = (ELICIT) valuations.get(i); + Validator.notIllegalElementType(v, new String[] { ELICIT.class.toString() }); + + if(((ELICIT) v).getBeta() == null) + tpf = ((ELICIT) v).calculateFuzzyEnvelope(); + else + tpf = ((ELICIT) v).getBeta(); + + tpf = tpf.multiplicationScalar(weights.get(i)); + tpfResult = tpfResult.additionAlphaCuts(tpf); + } + + ELICIT aggregatedElicit = ContextInjectionFactory.make(ELICIT.class, context); + aggregatedElicit.setDomain(valuations.get(0).getDomain()); + aggregatedElicit.createRelation(tpfResult); + + return aggregatedElicit; + } +} diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanFuzzy.java b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanFuzzy.java new file mode 100644 index 0000000..3d95233 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanFuzzy.java @@ -0,0 +1,86 @@ +package flintstones.operator.aggregation.arithmeticmean.operators; + +import java.util.List; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.operator.interfaces.IFuzzyWeightedAggregationOperator; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.arithmeticmean.ArithmeticMean; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class ArithmeticMeanFuzzy extends ArithmeticMean implements IFuzzyWeightedAggregationOperator { + + @Override + public Valuation aggregate(List valuations) { + FuzzyValuation v = null; + TrapezoidalFunction tpf, tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] { 0, 0, 0, 0 }); + + int size = valuations.size(); + for (int i = 0; i < size; ++i) { + v = (FuzzyValuation) valuations.get(i); + + Validator.notIllegalElementType(v, new String[] { FuzzyValuation.class.toString() }); + + tpf = v.getFuzzyNumber(); + + tpfResult = tpfResult.additionAlphaCuts(tpf); + } + + tpfResult = tpfResult.divisionScalar(size); + + FuzzyValuation aggregatedFuzzyValuation = new FuzzyValuation(tpfResult, valuations.get(0).getDomain()); + + return aggregatedFuzzyValuation; + + } + + @Override + public Valuation aggregate(List valuations, List weights) { + FuzzyValuation v = null; + TrapezoidalFunction tpf, tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] { 0, 0, 0, 0 }); + + int size = valuations.size(); + for (int i = 0; i < size; ++i) { + v = (FuzzyValuation) valuations.get(i); + + Validator.notIllegalElementType(v, new String[] { FuzzyValuation.class.toString() }); + + tpf = v.getFuzzyNumber(); + tpf = tpf.multiplicationScalar(weights.get(i)); + + tpfResult = tpfResult.additionAlphaCuts(tpf); + } + + FuzzyValuation aggregatedFuzzyValuation = new FuzzyValuation(tpfResult, valuations.get(0).getDomain()); + + return aggregatedFuzzyValuation; + } + + @Override + public Valuation aggregateF(List valuations, List weights) { + FuzzyValuation v = null; + TrapezoidalFunction tpf, tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] { 0, 0, 0, 0 }); + + int size = valuations.size(); + for (int i = 0; i < size; ++i) { + v = (FuzzyValuation) valuations.get(i); + + Validator.notIllegalElementType(v, new String[] { FuzzyValuation.class.toString() }); + + tpf = v.getFuzzyNumber(); + tpf = tpf.multiplication(weights.get(i)); + + tpfResult = tpfResult.additionAlphaCuts(tpf); + } + + tpfResult = tpfResult.divisionScalar(size); + + FuzzyValuation aggregatedFuzzyValuation = new FuzzyValuation(tpfResult, valuations.get(0).getDomain()); + + return aggregatedFuzzyValuation; + } +} diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanInteger.java b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanInteger.java new file mode 100644 index 0000000..8afb9a3 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanInteger.java @@ -0,0 +1,72 @@ +package flintstones.operator.aggregation.arithmeticmean.operators; + +import java.util.LinkedList; +import java.util.List; +import java.util.OptionalDouble; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.arithmeticmean.ArithmeticMean; +import flintstones.valuation.numeric.integer.IntegerValuation; + +public class ArithmeticMeanInteger extends ArithmeticMean { + + @Inject + IEclipseContext context; + + @Override + public Valuation aggregate(List valuations) { + + OptionalDouble averageOptional = valuations.stream().mapToDouble(k -> ((IntegerValuation) k).getValue()) + .average(); + double average = averageOptional.getAsDouble(); + + // Es necesario mantener el dominio? (clonar) + IntegerValuation result = ContextInjectionFactory.make(IntegerValuation.class, context); + result.setDomain(valuations.get(0).getDomain()); + result.setValue(Math.round(average)); + + return result; + + } + + @Override + public Valuation aggregate(List valuations, List weights) { + IntegerValuation result = null; + double measure = 0; + List measures = new LinkedList(); + NumericIntegerDomain domain = null; + + for(Valuation valuation : valuations) { + + Validator.notIllegalElementType(valuation, new String[] { IntegerValuation.class.toString() }); + + if (domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntegerOperator_Invalid_domain"); + } + + measures.add(((IntegerValuation) valuation).getValue()); + } + + if (domain != null) { + int size = measures.size(); + for (int i = 0; i < size; i++) { + measure += weights.get(i) * measures.get(i); + } + + result = (IntegerValuation) valuations.get(0).clone(); + result.setValue(measure); + } + + return result; + + } +} diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanProportionalTwoTuple.java b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanProportionalTwoTuple.java new file mode 100644 index 0000000..7429a80 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanProportionalTwoTuple.java @@ -0,0 +1,75 @@ +package flintstones.operator.aggregation.arithmeticmean.operators; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.arithmeticmean.ArithmeticMean; +import flintstones.valuation.proportionaltwotuple.ProportionalTwoTuple; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class ArithmeticMeanProportionalTwoTuple extends ArithmeticMean { + + @Override + public Valuation aggregate(List valuations) { + ProportionalTwoTuple result = null; + + FuzzySet domain = null; + + double beta = 0; + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { ProportionalTwoTuple.class.toString() }); + + if(domain == null) + domain = (FuzzySet) valuation.getDomain(); + else if(!domain.equals(valuation.getDomain())) + throw new IllegalArgumentException("Invalid_domain"); + + beta += ((ProportionalTwoTuple) valuation).calculatePi(); + } + + beta /= valuations.size(); + + if (domain != null) { + result = (ProportionalTwoTuple) valuations.get(0).clone(); + result.calculateInversePi(beta); + } + + return result; + + } + + @Override + public Valuation aggregate(List valuations, List weights) { + ProportionalTwoTuple result = null; + + FuzzySet domain = null; + + List measures = new LinkedList(); + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { TwoTupleValuation.class.toString() }); + + if (domain == null) + domain = (FuzzySet) valuation.getDomain(); + else if (!domain.equals(valuation.getDomain())) + throw new IllegalArgumentException("Invalid_domain"); + + measures.add(((ProportionalTwoTuple) valuation).calculatePi()); + } + + if (domain != null) { + double beta = 0; + for (int i = 0; i < measures.size(); i++) + beta += weights.get(i) * measures.get(i); + + result = (ProportionalTwoTuple) valuations.get(0).clone(); + result.calculateInversePi(beta); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanTwoTuple.java b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanTwoTuple.java new file mode 100644 index 0000000..02bfa59 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.arithmeticmean/src/flintstones/operator/aggregation/arithmeticmean/operators/ArithmeticMeanTwoTuple.java @@ -0,0 +1,81 @@ +package flintstones.operator.aggregation.arithmeticmean.operators; + +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.arithmeticmean.ArithmeticMean; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class ArithmeticMeanTwoTuple extends ArithmeticMean { + + @Inject + IEclipseContext context; + + @Override + public Valuation aggregate(List valuations) { + TwoTupleValuation result = null; + double beta = 0; + FuzzySet domain = null; + int size = valuations.size(); + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { TwoTupleValuation.class.toString() }); + + if(domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.TwoTupleOperator_Invalid_domain"); + } + + beta += (((TwoTupleValuation) valuation).calculateInverseDelta()); + } + + beta /= size; + + if (domain != null) { + result = (TwoTupleValuation) valuations.get(0).clone(); + result.calculateDelta(beta); + } + + return result; + + } + + @Override + public Valuation aggregate(List valuations, List weights) { + TwoTupleValuation result = null; + List measures = new LinkedList(); + FuzzySet domain = null; + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { TwoTupleValuation.class.toString() }); + + if (domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.TwoTupleOperator_Invalid_domain"); + } + measures.add(((TwoTupleValuation) valuation).calculateInverseDelta()); + } + + if (domain != null) { + int size = measures.size(); + double beta = 0; + for (int i = 0; i < size; i++) { + beta += weights.get(i) * measures.get(i); + } + + result = (TwoTupleValuation) valuations.get(0).clone(); + result.calculateDelta(beta); + } + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/.classpath b/bundles/flintstones.operator.aggregation.bonferroniMean/.classpath new file mode 100644 index 0000000..ca3785c --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/.project b/bundles/flintstones.operator.aggregation.bonferroniMean/.project new file mode 100644 index 0000000..e0a6195 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/.project @@ -0,0 +1,28 @@ + + + flintstones.operator.aggregation.bonferroniMean + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.bonferroniMean/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.bonferroniMean/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bd1095b --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.bonferroniMean/META-INF/MANIFEST.MF new file mode 100644 index 0000000..c0c7ffe --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/META-INF/MANIFEST.MF @@ -0,0 +1,21 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Bonferroni Mean aggregation operator +Bundle-SymbolicName: flintstones.operator.aggregation.bonferroniMean;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.operator.bonferroniMean +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.entity.operator, + flintstones.entity.valuation, + flintstones.domain.fuzzyset, + flintstones.model.ui.service, + org.eclipse.jface, + flintstones.operator, + de.kupzog.ktable, + javax.inject, + flintstones.model.problemelement.service, + flintstones.valuation.numeric.real, + flintstones.valuation.fuzzy, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/build.properties b/bundles/flintstones.operator.aggregation.bonferroniMean/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/plugin.xml b/bundles/flintstones.operator.aggregation.bonferroniMean/plugin.xml new file mode 100644 index 0000000..680727f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/plugin.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/BonferroniMean.java b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/BonferroniMean.java new file mode 100644 index 0000000..6c618b4 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/BonferroniMean.java @@ -0,0 +1,52 @@ +package flintstones.operator.aggregation.bonferroniMean; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IParameterizedOperator; +import flintstones.entity.operator.interfaces.IWeightedAggregationOperator; +import flintstones.model.problemelement.service.IProblemElementService; + +public abstract class BonferroniMean extends AggregationOperator implements IWeightedAggregationOperator, IParameterizedOperator { + + @Inject + protected IEclipseContext context; + + @Inject + protected IProblemElementService problemService; + + protected double p; + protected double q; + protected String[][] relations; + + @Override + public String getName() { + return "Bonferroni Mean"; + } + + public double getP() { + return p; + } + + public void setP(double p) { + this.p = p; + } + + public double getQ() { + return q; + } + + public void setQ(double q) { + this.q = q; + } + + public String[][] getRelations() { + return relations; + } + + public void setRelations(String[][] relations) { + this.relations = relations; + } +} diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/dialog/BonferroniMeanDialog.java b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/dialog/BonferroniMeanDialog.java new file mode 100644 index 0000000..75d6559 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/dialog/BonferroniMeanDialog.java @@ -0,0 +1,159 @@ +package flintstones.operator.aggregation.bonferroniMean.dialog; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Point; +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.Shell; +import org.eclipse.swt.widgets.Spinner; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.model.ui.service.UiService; +import flintstones.operator.aggregation.bonferroniMean.table.AttributesRelationTable; + +public class BonferroniMeanDialog extends Dialog { + + private static final int DIALOG_SIZE_Y = 600; + private static final int DIALOG_SIZE_X = 650; + + private ProblemElement[] items; + private double p; + private double q; + + private AttributesRelationTable table; + private Spinner spinner1; + private Spinner spinner2; + private Button okButton; + + public BonferroniMeanDialog(Shell parentShell) { + super(parentShell); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite container = (Composite) super.createDialogArea(parent); + + UiService.setGridLayout(parent, 1); + UiService.setGridDataAuto(parent); + + this.addContent(container); + + return container; + } + + private void addContent(Composite container) { + this.addSpinners(container); + this.addRelationsTable(container); + } + + private void addSpinners(Composite container) { + Composite parametersComposite = new Composite(container, SWT.BORDER); + UiService.setGridLayout(parametersComposite, 3); + UiService.setGridData(parametersComposite, 9, 9, false, false); + + Composite spinner1Composite = new Composite(parametersComposite, SWT.NONE); + UiService.setGridLayout(spinner1Composite, 2); + UiService.setGridDataAuto(spinner1Composite); + + Label parameterP = new Label(spinner1Composite, SWT.BOLD); + FontData fontData = parameterP.getFont().getFontData()[0]; + Font font = new Font(Display.getDefault(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD)); + parameterP.setFont(font); + parameterP.setText("P:"); + UiService.setGridData(parameterP, 9, 1, false, false); + + spinner1 = new Spinner(spinner1Composite, SWT.NONE); + spinner1.setDigits(2); + spinner1.setMinimum((int) (1 * 100d)); + spinner1.setMaximum((int) (10 * 100d)); + spinner1.setSelection((int) (1 * 100d)); + UiService.setGridData(spinner1, 9, 1, true, false); + p = spinner1.getSelection() / 100d; + + spinner1.addModifyListener(e -> { + p = spinner1.getSelection() / 100d; + }); + + Composite spinner2Composite = new Composite(parametersComposite, SWT.NONE); + UiService.setGridLayout(spinner2Composite, 2); + UiService.setGridDataAuto(spinner2Composite); + + Label parameterQ = new Label(spinner2Composite, SWT.BOLD); + parameterQ.setFont(font); + parameterQ.setText("Q:"); + UiService.setGridData(parameterQ, 9, 1, false, false); + + spinner2 = new Spinner(spinner2Composite, SWT.NONE); + spinner2.setDigits(2); + spinner2.setMinimum((int) (1 * 100d)); + spinner2.setMaximum((int) (10 * 100d)); + spinner2.setSelection((int) (1 * 100d)); + UiService.setGridData(spinner2, 9, 1, true, false); + q = spinner2.getSelection() / 100d; + + spinner2.addModifyListener(e -> { + q = spinner2.getSelection() / 100d; + }); + } + + private void addRelationsTable(Composite container) { + Label relationLabel = new Label(container, SWT.BOLD); + FontData fontData = relationLabel.getFont().getFontData()[0]; + Font font = new Font(Display.getDefault(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD)); + relationLabel.setFont(font); + relationLabel.setText("If two arguments are interrelated then set 1 otherwise 0"); + + table = new AttributesRelationTable(container); + table.setModel(items); + UiService.setGridDataAuto(table); + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText("Configuration"); + } + + @Override + protected Point getInitialSize() { + return new Point(DIALOG_SIZE_X, DIALOG_SIZE_Y); + } + + @Override + protected void okPressed() { + super.okPressed(); + } + + @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); + + this.okButton = this.getButton(IDialogConstants.OK_ID); + this.okButton.setEnabled(true); + this.okButton.setToolTipText("Aggregate with this configuration"); + } + + public void setItems(ProblemElement[] items) { + this.items = items; + } + + public String[][] getRelations() { + return table.getRelations(); + } + + public double getP() { + return p; + } + + public double getQ() { + return q; + } +} diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/operators/BonferroniMeanDouble.java b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/operators/BonferroniMeanDouble.java new file mode 100644 index 0000000..6430973 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/operators/BonferroniMeanDouble.java @@ -0,0 +1,311 @@ +package flintstones.operator.aggregation.bonferroniMean.operators; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Display; + +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.bonferroniMean.BonferroniMean; +import flintstones.operator.aggregation.bonferroniMean.dialog.BonferroniMeanDialog; +import flintstones.valuation.numeric.real.RealValuation; + +/** Finding the extended Bonferroni mean for a set of crisp arguments +B. Dutta, D. Guha, R. Mesiar, A Model based on linguistic 2-tuples for dealing with +heterogeneous relationship among attributes in multi-expert decision making, IEEE +Transaction on Fuzzy Systems, 23(5):1817–1830, 2015. +Original author: Bapi Dutta, Apr. 9, 2021. + relations is relationship matrix. For n arguments relationship matrix is a n*n matrix whose rows and columns are arguments and the entries are 0 or + 1. If two arguments are interrelated then entries are 1 otherwise 0. + Note that a_i is not related to itself i.e. corresponding entry would be zero + valuations is aggregated arguments + weights normalized weight vector + p, q parameters of EBM **/ +public class BonferroniMeanDouble extends BonferroniMean { + + @Override + public Valuation aggregate(List valuations, List weights) { + + RealValuation result = null; + + Double[] dependentAttributeWeights; + Double[] v1, v2; + Valuation[] dependentAttributes; + double ebm_dep = 0, ebm_ind, ebm, part1, part2; + + if(allDepedentAttributes()) { + + for(int i = 0; i < valuations.size(); ++i) { + + Validator.notIllegalElementType(valuations.get(i), new String[] {RealValuation.class.toString()}); + + part1 = (weights.get(i) * Math.pow(((RealValuation) valuations.get(i)).getValue(), p)); + + dependentAttributeWeights = getDependentAttributeWeights(i, weights); + dependentAttributes = getDependentAttributes(i, valuations); + + v1 = divideElementsBySum(dependentAttributeWeights); + v2 = powerAttributes(dependentAttributes, q); + + part2 = dot(v1, v2); + + ebm_dep += part1 * part2; + } + + ebm = Math.pow(ebm_dep, 1d / (p + q)); + + } else { + + Integer[] dependentIndexes = getDependentRelationsIndexes(); + + //dependent part computation + double sum_dependent_attribute_weights = sumElementsByIndexes(dependentIndexes, weights); + + for(Integer dep_ind: dependentIndexes) { + + Validator.notIllegalElementType(valuations.get(dep_ind), new String[] {RealValuation.class.toString()}); + + part1 = (weights.get(dep_ind) / sum_dependent_attribute_weights) * Math.pow(((RealValuation) valuations.get(dep_ind)).getValue(), p); + + dependentAttributeWeights = getDependentAttributeWeights(dep_ind, weights); + dependentAttributes = getDependentAttributes(dep_ind, valuations); + + v1 = divideElementsBySum(dependentAttributeWeights); + v2 = powerAttributes(dependentAttributes, q); + + part2 = dot(v1, v2); + + ebm_dep += part1 * part2; + } + + ebm_dep = Math.pow(ebm_dep, p / (p + q)); + + //independent part computation + Double[] independentAttributeWeights; + Valuation[] independentAttributes; + + Integer[] independentIndexes = getIndependentRelationsIndexes(); + + double sum_independent_attribute_weights = sumElementsByIndexes(independentIndexes, weights); + + independentAttributeWeights = getWeightsForIndependentAttributes(independentIndexes, weights); + independentAttributes = getIndependentAttributes(independentIndexes, valuations); + + ebm_ind = (1d / sum_independent_attribute_weights) * dot(independentAttributeWeights, powerAttributes(independentAttributes, p)); + + //combining both + ebm = (1d - sum_independent_attribute_weights) * ebm_dep + (Math.pow(sum_independent_attribute_weights * ebm_ind, 1d / p)); + } + + result = (RealValuation) valuations.get(0).clone(); + result.setValue(ebm); + + return result; + } + + /** + * Check if there are relations among attributes + * @return + */ + private boolean allDepedentAttributes() { + boolean independent = true; + for(int i = 0; i < relations.length - 1; ++i) { + for (int j = i + 1; j < relations.length; ++j) { + if(relations[i][j].equals("1")) + independent = false; + } + + if(independent) + return false; + + } + return true; + } + + /** + * Get weights from dependent attributes + * @param index current attribute + * @param weights attribute weights + * @return weights of the dependent attributes + */ + private Double[] getDependentAttributeWeights(int index, List weights) { + Integer[] attributeRelationsIndexes = getAttributeDependentRelationsIndexes(index); + + List dependentAttributeWeights = new ArrayList(); + for(Integer i: attributeRelationsIndexes) + dependentAttributeWeights.add(weights.get(i)); + + return dependentAttributeWeights.toArray(new Double[0]); + } + + /** + * Get indexes of the dependent attributes related to another attribute + * @param index index of the attribute + * @return indexes of the attributes with a relation + */ + private Integer[] getAttributeDependentRelationsIndexes(int index) { + String[] attributeRelations = relations[index]; + + List attributeRelationsIndexes = new ArrayList(); + for(int i = 0; i < attributeRelations.length; ++i) { + if(attributeRelations[i].equals("1")) + attributeRelationsIndexes.add(i); + } + + return attributeRelationsIndexes.toArray(new Integer[0]); + } + + /** + * Get valuations of the dependent attributes related to another attribute + * @param index index of the attribute + * @return valuation values of the attributes + */ + private Valuation[] getDependentAttributes(int index, List attributes) { + Integer[] attributeRelationsIndexes = getAttributeDependentRelationsIndexes(index); + + List dependentAttribute = new ArrayList(); + for(Integer i: attributeRelationsIndexes) + dependentAttribute.add(attributes.get(i)); + + return dependentAttribute.toArray(new Valuation[0]); + } + + /** + * Get the sum of all the dependent weights + * @param dependentWeights weights of the dependent attributes + * @return sum of the dependent attributes + */ + private double getSumWeights(Double[] dependentWeights) { + double acum = 0; + + for(Double dependentWeight: dependentWeights) + acum += dependentWeight; + + return acum; + } + + /** + * Get the division of each weight by the total sum + * @param dependentAttributeWeights dependent weights + * @return + */ + private Double[] divideElementsBySum(Double[] attributeWeights) { + double sum = getSumWeights(attributeWeights); + + Double[] result = new Double[attributeWeights.length]; + + for(int i = 0; i < result.length; ++i) + result[i] = attributeWeights[i] /sum; + + return result; + } + + /** + * Get the power of each dependent attribute + * @param dependentAttributes values of the dependent attributes + * @return power of each dependent attribute + */ + private Double[] powerAttributes(Valuation[] dependentAttributes, double power) { + Double[] result = new Double[dependentAttributes.length]; + + for(int i = 0; i < result.length; ++i) + result[i] = Math.pow(((RealValuation) dependentAttributes[i]).getValue(), power); + + return result; + } + + /** + * Dot operation among vectors + * @param v1 vector1 + * @param v2 vector2 + * @return dot operation + */ + private double dot(Double[] v1, Double[] v2) { + double acum = 0; + for(int i = 0; i < v1.length; ++i) + acum += v1[i] * v2[i]; + + return acum; + } + + private Integer[] getDependentRelationsIndexes() { + List dependentIndexes = new ArrayList(); + + String[] relationsAttribute; + for(int i = 0; i < relations.length; ++i) { + relationsAttribute = relations[i]; + for(String relation: relationsAttribute) { + if(relation.equals("1")) { + dependentIndexes.add(i); + break; + } + } + } + + return dependentIndexes.toArray(new Integer[0]); + } + + private Integer[] getIndependentRelationsIndexes() { + List independentIndexes = new ArrayList(); + + String[] relationsAttribute; + + boolean independent = true; + for(int i = 0; i < relations.length; ++i) { + relationsAttribute = relations[i]; + independent = true; + for(String relation: relationsAttribute) { + if(relation.equals("1")) { + independent = false; + break; + } + } + + if(independent) + independentIndexes.add(i); + } + + return independentIndexes.toArray(new Integer[0]); + } + + private double sumElementsByIndexes(Integer[] indexes, List weights) { + double acum = 0; + for(Integer i: indexes) + acum += weights.get(i); + + return acum; + } + + private Double[] getWeightsForIndependentAttributes(Integer[] independentIndexes, List weights) { + List independentWeights = new ArrayList(); + for(Integer i: independentIndexes) + independentWeights.add(weights.get(i)); + + return independentWeights.toArray(new Double[0]); + } + + private Valuation[] getIndependentAttributes(Integer[] independentIndexes, List attributes) { + List independentAttributes = new ArrayList(); + for(Integer i: independentIndexes) + independentAttributes.add(attributes.get(i)); + + return independentAttributes.toArray(new Valuation[0]); + } + + @Override + public void openDialog(ProblemElement[] items) { + BonferroniMeanDialog dialog = new BonferroniMeanDialog(Display.getDefault().getActiveShell()); + dialog.setItems(items); + dialog.create(); + if (dialog.open() == Window.OK) { + p = dialog.getP(); + q = dialog.getQ(); + relations = dialog.getRelations(); + dialog.close(); + } + } + +} diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/operators/BonferroniMeanFuzzy.java b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/operators/BonferroniMeanFuzzy.java new file mode 100644 index 0000000..03165de --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/operators/BonferroniMeanFuzzy.java @@ -0,0 +1,64 @@ +package flintstones.operator.aggregation.bonferroniMean.operators; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Display; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.problemelement.entities.ProblemElement; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.aggregation.bonferroniMean.BonferroniMean; +import flintstones.operator.aggregation.bonferroniMean.dialog.BonferroniMeanDialog; +import flintstones.valuation.fuzzy.FuzzyValuation; +import flintstones.valuation.numeric.real.RealValuation; + +public class BonferroniMeanFuzzy extends BonferroniMean { + + @Override + public Valuation aggregate(List valuations, List weights) { + double[] limits = new double[4]; + + BonferroniMeanDouble bm_crisp = new BonferroniMeanDouble(); + bm_crisp.setP(p); + bm_crisp.setQ(q); + bm_crisp.setRelations(relations); + + ContextInjectionFactory.inject(bm_crisp, context); + + List crispValuations; + for(int i = 0; i < 4; ++i) { + crispValuations = new ArrayList(); + for(Valuation v: valuations) { + RealValuation crisp = new RealValuation(); + NumericRealDomain domain = new NumericRealDomain(); + domain.setMinMax(0, Double.MAX_VALUE); + crisp.setDomain(domain); + crisp.setValue(((FuzzyValuation) v).getFuzzyNumber().getLimits()[i]); + crispValuations.add(crisp); + } + + limits[i] = ((RealValuation) bm_crisp.aggregate(crispValuations, weights)).getValue(); + } + + TrapezoidalFunction fuzzy_number = new TrapezoidalFunction(limits); + FuzzyValuation aggregatedFuzzyValuation = new FuzzyValuation(fuzzy_number, valuations.get(0).getDomain()); + + return aggregatedFuzzyValuation; + } + + @Override + public void openDialog(ProblemElement[] items) { + BonferroniMeanDialog dialog = new BonferroniMeanDialog(Display.getDefault().getActiveShell()); + dialog.setItems(items); + dialog.create(); + if (dialog.open() == Window.OK) { + p = dialog.getP(); + q = dialog.getQ(); + relations = dialog.getRelations(); + } + } +} diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/table/AttributesRelationContentProvider.java b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/table/AttributesRelationContentProvider.java new file mode 100644 index 0000000..9891af1 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/table/AttributesRelationContentProvider.java @@ -0,0 +1,215 @@ +package flintstones.operator.aggregation.bonferroniMean.table; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import de.kupzog.ktable.KTableCellEditor; +import de.kupzog.ktable.KTableCellRenderer; +import de.kupzog.ktable.KTableNoScrollModel; +import de.kupzog.ktable.SWTX; +import de.kupzog.ktable.editors.KTableCellEditorText; +import de.kupzog.ktable.renderers.DefaultCellRenderer; +import de.kupzog.ktable.renderers.FixedCellRenderer; +import flintstones.entity.problemelement.entities.Criterion; +import flintstones.entity.problemelement.entities.ProblemElement; + +public class AttributesRelationContentProvider extends KTableNoScrollModel { + + private KTable table; + + private ProblemElement[] attributes; + private String[][] relations; + + private final FixedCellRenderer fixedRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | SWT.BOLD); + private final FixedCellRenderer editableRenderer = new FixedCellRenderer(DefaultCellRenderer.STYLE_FLAT | DefaultCellRenderer.INDICATION_FOCUS); + + private class TableCellEditorText extends KTableCellEditorText { + @Override + protected void onKeyPressed(KeyEvent e) { + if(e.keyCode == 13) + this.close(true); + } + + @Override + public int getActivationSignals() { + return SINGLECLICK; + } + } + + private TableCellEditorText text; + + public AttributesRelationContentProvider(KTable table) { + super(table); + } + + public void init(KTable table, ProblemElement[] attributes) { + this.table = table; + this.attributes = attributes; + + this.relations = new String[attributes.length][attributes.length]; + + for(int i = 0; i < this.relations.length; ++i) { + for(int j = 0; j < this.relations.length; ++j) { + + this.relations[i][j] = "0"; + + } + } + + initialize(); + setDesign(); + } + + private void setDesign() { + fixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + fixedRenderer.setBackground(new Color(Display.getCurrent(), 255, 165, 0)); + + editableRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER | SWTX.ALIGN_VERTICAL_CENTER); + editableRenderer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); + } + + @Override + public int getFixedHeaderColumnCount() { + return 1; + } + + @Override + public int getFixedHeaderRowCount() { + return 1; + } + + @Override + public int getFixedSelectableColumnCount() { + return 0; + } + + @Override + public int getFixedSelectableRowCount() { + return 0; + } + + @Override + public int getRowHeightMinimum() { + return 0; + } + + @Override + public boolean isColumnResizable(int arg0) { + return false; + } + + @Override + public boolean isRowResizable(int arg0) { + return false; + } + + @Override + public KTableCellEditor doGetCellEditor(int col, int row) { + + if (col != 0 && row != 0 && col != row) { + text = new TableCellEditorText(); + return text; + } + + return null; + } + + @Override + public KTableCellRenderer doGetCellRenderer(int col, int row) { + if((col < getFixedColumnCount()) || (row < getFixedRowCount())) + return fixedRenderer; + else + return editableRenderer; + } + + @Override + public int doGetColumnCount() { + return attributes.length + getFixedColumnCount(); + } + + @Override + public Object doGetContentAt(int col, int row) { + + if ((col == 0) && (row == 0)) + return "Relations"; //$NON-NLS-1$ + + Object content; + + try { + if (col == 0) + content = criterionAbbreviation(row); + else if (row == 0) + content = criterionAbbreviation(col); + else + content = relations[row - 1][col - 1]; + } catch (Exception e) { + content = ""; //$NON-NLS-1$ + } + + return content; + } + + private Object criterionAbbreviation(int pos) { + if(attributes[0] instanceof Criterion) + return "C" + pos; + else + return "E" + pos; + } + + @Override + public int doGetRowCount() { + return attributes.length + getFixedRowCount(); + } + + @Override + public void doSetContentAt(int col, int row, Object value) { + if(((String) value).equals("0") || ((String) value).equals("1")) { + relations[row - 1][col - 1] = (String) value; + relations[col - 1][row - 1] = (String) value; + table.redraw(); + } + } + + @Override + public int getInitialColumnWidth(int arg0) { + return 20; + } + + @Override + public int getInitialRowHeight(int arg0) { + return 30; + } + + @Override + public boolean isFixedCell(int col, int row) { + if (col == 0) + return true; + else if (row == 0) + return true; + return false; + } + + @Override + public boolean isHeaderCell(int col, int row) { + return isFixedCell(col, row); + } + + @Override + public String doGetTooltipAt(int col, int row) { + if ((col == 0) && (row == 0)) + return ""; //$NON-NLS-1$ + else if (col < getFixedColumnCount()) { + return attributes[row - 1].getName(); + } else if (row < getFixedRowCount()) + return attributes[col - 1].getName(); + else + return relations[row - 1][col - 1]; + } + + public String[][] getRelations() { + return relations; + } +} \ No newline at end of file diff --git a/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/table/AttributesRelationTable.java b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/table/AttributesRelationTable.java new file mode 100644 index 0000000..35f59cc --- /dev/null +++ b/bundles/flintstones.operator.aggregation.bonferroniMean/src/flintstones/operator/aggregation/bonferroniMean/table/AttributesRelationTable.java @@ -0,0 +1,37 @@ +package flintstones.operator.aggregation.bonferroniMean.table; + + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +import de.kupzog.ktable.KTable; +import flintstones.entity.problemelement.entities.ProblemElement; + +public class AttributesRelationTable extends KTable { + + private AttributesRelationContentProvider provider; + + public AttributesRelationTable(Composite parent) { + super(parent, SWT.NO_BACKGROUND | SWT.FLAT | SWT.V_SCROLL); + setBackground(new Color(Display.getCurrent(), 255, 255, 255)); + provider = null; + } + + public void setModel(ProblemElement[] items) { + provider = new AttributesRelationContentProvider(this); + provider.init(this, items); + + setModel(provider); + } + + public String[][] getRelations() { + return provider.getRelations(); + } + + @Override + public void dispose() { + super.dispose(); + } +} \ No newline at end of file diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/.classpath b/bundles/flintstones.operator.aggregation.choquetIntegral/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.choquetIntegral/.polyglot.META-INF new file mode 100644 index 0000000..a6cdd16 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.choquetIntegral + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] ChoquetIntegral + diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/.project b/bundles/flintstones.operator.aggregation.choquetIntegral/.project new file mode 100644 index 0000000..c308ce1 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.choquetIntegral + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362732 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.choquetIntegral/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d3866be --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ChoquetIntegral +Bundle-SymbolicName: flintstones.operator.aggregation.choquetIntegral +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.aggregation.choquetIntegral +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator, + flintstones.entity.operator +Import-Package: flintstones.domain.numeric, + flintstones.domain.numeric.integer, + flintstones.helper.validator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric, + flintstones.valuation.numeric.integer diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/build.properties b/bundles/flintstones.operator.aggregation.choquetIntegral/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/ChoquetIntegral.java b/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/ChoquetIntegral.java new file mode 100644 index 0000000..6d7cc56 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/ChoquetIntegral.java @@ -0,0 +1,157 @@ +package flintstones.operator.aggregation.choquetIntegral; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IWeightedAggregationOperator; + +public abstract class ChoquetIntegral extends AggregationOperator implements IWeightedAggregationOperator{ + + @Override + public String getName() { + return "Choquet Integral"; + } + + public List getRanking(List values) { + + // TODO: QUITAR ESTO; ARREGLAR; SACAR; PONER NOMBRE + class MyObject implements Comparable { + private Integer _pos; + private Double _value; + + public MyObject(Integer pos, Double value) { + _pos = pos; + _value = value; + } + + public Integer getPos() { + return _pos; + } + + public Double getValue() { + return _value; + } + + @Override + public int compareTo(MyObject o) { + return Double.compare(_value, o.getValue()); + } + + } + + List result = new LinkedList(); + List aux = new LinkedList(); + + int size = values.size(); + + for(int i = 0; i < size; i++) { + aux.add(new MyObject(i, values.get(i))); + } + + Collections.sort(aux); + for(int i = 0; i < size; i++) { + result.add(aux.get(i).getPos()); + } + + return result; + } + + public List getMeasures(List measures, List ranking) { + List result = new LinkedList(); + Double[] values = new Double[measures.size()]; + + double last = 0; + for(Integer i : ranking) { + values[i] = measures.get(i) - last; + last += values[i]; + } + + for(Double value : values) { + result.add(value); + } + + return result; + } + + public List getWeights(List ranking, List weights, List> assignments) { + + List result = new LinkedList(); + Map auxResult = new HashMap(); + + Set currentSet = new HashSet(); + for (int i = 0; i < ranking.size(); i++) { + currentSet.add(i); + } + + Set currentAssignment; + int assignmentsSize = assignments.size(); + boolean duplicate = false; + Set elementAssignments; + + // Iteramos sobre todos los elementos + for(Integer currentElement : ranking) { + + elementAssignments = new HashSet(); + + // vamos aadiendo asignaciones una a una + for(int assignmentPos = 0; assignmentPos < assignmentsSize; assignmentPos++) { + currentAssignment = assignments.get(assignmentPos); + + if(currentSet.containsAll(currentAssignment)) { + //Comprobamos si no exite una asignacin con ms elementos que la contenga + duplicate = false; + Iterator iterator = elementAssignments.iterator(); + while(iterator.hasNext() && (!duplicate)) { + if(assignments.get(iterator.next()).containsAll(currentAssignment)) { + duplicate = true; + } + } + + if(!duplicate) { + // Eliminamos asignaciones contenidas en esta + List toRemove = new LinkedList(); + for(Integer testToRemove : elementAssignments) { + if (currentAssignment.containsAll(assignments.get(testToRemove))) { + toRemove.add(testToRemove); + } + } + + for(Integer removePos : toRemove) { + elementAssignments.remove(removePos); + } + + // Aadimos la asignacin + elementAssignments.add(assignmentPos); + } + } + } + + // Calculamos la ponderacin para cada elemento + double weight = 0; + for(Integer i : elementAssignments) { + weight += weights.get(i); + } + auxResult.put(currentElement, weight); + + // Eliminamos el elemento del conjunto a calcular + currentSet.remove(currentElement); + + } + + // Establecemos los pesos para cada elemento + int size = auxResult.size(); + for(int pos = 0; pos < size; pos++) { + result.add(auxResult.get(pos)); + } + + return result; + } + +} diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralInteger.java b/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralInteger.java new file mode 100644 index 0000000..a0a5098 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralInteger.java @@ -0,0 +1,71 @@ +package flintstones.operator.aggregation.choquetIntegral.operators; + +import java.util.List; + +import flintstones.entity.valuation.Valuation; +import flintstones.operator.aggregation.choquetIntegral.ChoquetIntegral; + +/* + * +http://serezade.ujaen.es:8003/igmunoz/flintstones3/blob/master/sinbad2.aggregationoperator.choquetIntegral/src/sinbad2/aggregationoperator/choquetIntegral/valuation/IntegerOperator.java +http://serezade.ujaen.es:8003/igmunoz/flintstones3/blob/master/sinbad2.aggregationoperator.choquetIntegral/src/sinbad2/aggregationoperator/choquetIntegral/valuation/RealOperator.java +http://serezade.ujaen.es:8003/igmunoz/flintstones3/blob/master/sinbad2.aggregationoperator.choquetIntegral/src/sinbad2/aggregationoperator/choquetIntegral/valuation/TwoTupleOperator.java + */ + +public class ChoquetIntegralInteger extends ChoquetIntegral { + + @Override + public Valuation aggregate(List valuations, List weights) { + + /* + IntegerValuation result = null; + double measure = 0; + List measures = new LinkedList(); + NumericIntegerDomain domain = null; + + for (Valuation valuation : valuations) { + // Controlar evaluacin de tipo invlido + Validator.notIllegalElementType(valuation, new String[] { IntegerValuation.class.toString() }); + + // Comprobamos que el dominio sea igual + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Invalid domain"); + } + + // Agregamos la evaluacin + measures.add((double) ((IntegerValuation) valuation).getValue()); + + } + + // Calculamos la evaluacin + if(domain != null) { + // Calculamos el ranking + List ranking = this.getRanking(measures); + + // Calculamos los pesos para cada elemento + List finalWeights = this.getWeights(ranking, weights, assignments, rules); + + // Calculamos las medidas finales + List finalMeasures = this.getMeasures(measures, ranking); + + // Calculamos el resultado del operador + int size = finalMeasures.size(); + for (int i = 0; i < size; i++) { + measure += finalWeights.get(i) * finalMeasures.get(i); + } + + // Establecemos la medida del resultado + result = (IntegerValuation) valuations.get(0).clone(); + result.setValue(measure); + } + + return result; + */ + + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralReal.java b/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralReal.java new file mode 100644 index 0000000..2778c7d --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralReal.java @@ -0,0 +1,16 @@ +package flintstones.operator.aggregation.choquetIntegral.operators; + +import java.util.List; + +import flintstones.entity.valuation.Valuation; +import flintstones.operator.aggregation.choquetIntegral.ChoquetIntegral; + +public class ChoquetIntegralReal extends ChoquetIntegral { + + @Override + public Valuation aggregate(List valuations, List weights) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralTwoTuple.java b/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralTwoTuple.java new file mode 100644 index 0000000..fbf7228 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.choquetIntegral/src/flintstones/operator/aggregation/choquetIntegral/operators/ChoquetIntegralTwoTuple.java @@ -0,0 +1,16 @@ +package flintstones.operator.aggregation.choquetIntegral.operators; + +import java.util.List; + +import flintstones.entity.valuation.Valuation; +import flintstones.operator.aggregation.choquetIntegral.ChoquetIntegral; + +public class ChoquetIntegralTwoTuple extends ChoquetIntegral { + + @Override + public Valuation aggregate(List valuations, List weights) { + // TODO Auto-generated method stub + return null; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.operator.aggregation.geometricMean/.classpath b/bundles/flintstones.operator.aggregation.geometricMean/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.geometricMean/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.geometricMean/.polyglot.META-INF new file mode 100644 index 0000000..fbe856b --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.geometricMean + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] GeometricMean + diff --git a/bundles/flintstones.operator.aggregation.geometricMean/.project b/bundles/flintstones.operator.aggregation.geometricMean/.project new file mode 100644 index 0000000..455e8b9 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.geometricMean + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362732 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.geometricMean/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.geometricMean/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5cb478f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: GeometricMean +Bundle-SymbolicName: flintstones.operator.aggregation.geometricMean;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.aggregation.geometricMean +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.domain.numeric.real, + flintstones.valuation.numeric.real, + flintstones.valuation.numeric.integer, + flintstones.valuation.twoTuple, + flintstones.entity.domain, + flintstones.entity.operator, + flintstones.valuation.elicit, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di, + flintstones.valuation.fuzzy +Export-Package: flintstones.operator.aggregation.geometricMean diff --git a/bundles/flintstones.operator.aggregation.geometricMean/build.properties b/bundles/flintstones.operator.aggregation.geometricMean/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.geometricMean/plugin.xml b/bundles/flintstones.operator.aggregation.geometricMean/plugin.xml new file mode 100644 index 0000000..f0276bb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/plugin.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/GeometricMean.java b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/GeometricMean.java new file mode 100644 index 0000000..e281238 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/GeometricMean.java @@ -0,0 +1,14 @@ +package flintstones.operator.aggregation.geometricMean; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; +import flintstones.entity.operator.interfaces.IWeightedAggregationOperator; + +public abstract class GeometricMean extends AggregationOperator implements IUnweightedAggregationOperator, IWeightedAggregationOperator { + + @Override + public String getName() { + return "Geometric Mean"; + } + +} diff --git a/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanELICIT.java b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanELICIT.java new file mode 100644 index 0000000..3ef6e7c --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanELICIT.java @@ -0,0 +1,81 @@ +package flintstones.operator.aggregation.geometricMean.operators; + +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.geometricMean.GeometricMean; +import flintstones.valuation.elicit.ELICIT; + +public class GeometricMeanELICIT extends GeometricMean { + + @Inject + IEclipseContext context; + + @Override + public Valuation aggregate(List valuations) { + ELICIT v = null; + + TrapezoidalFunction tpf, + tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] {1, 1, 1, 1}); + + int size = valuations.size(); + for(int i = 0; i < size; ++i) { + v = (ELICIT) valuations.get(i); + + Validator.notIllegalElementType(v, new String[] { ELICIT.class.toString() }); + + if(((ELICIT) v).getBeta() == null) + tpf = ((ELICIT) v).calculateFuzzyEnvelope(); + else + tpf = ((ELICIT) v).getBeta(); + + tpfResult = tpfResult.multiplicationAlphaCuts(tpf); + } + + tpfResult = tpfResult.potence(1d / size); + + ELICIT aggregatedElicit = ContextInjectionFactory.make(ELICIT.class, context); + aggregatedElicit.setDomain(valuations.get(0).getDomain()); + aggregatedElicit.createRelation(tpfResult); + + return aggregatedElicit; + } + + @Override + public Valuation aggregate(List valuations, List weights) { + ELICIT v = null; + + TrapezoidalFunction tpf, + tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] {1, 1, 1, 1}); + + int size = valuations.size(); + for(int i = 0; i < size; ++i) { + v = (ELICIT) valuations.get(i); + Validator.notIllegalElementType(v, new String[] { ELICIT.class.toString() }); + + if(((ELICIT) v).getBeta() == null) + tpf = ((ELICIT) v).calculateFuzzyEnvelope(); + else + tpf = ((ELICIT) v).getBeta(); + + tpf = tpf.potence(weights.get(i)); + tpfResult = tpfResult.multiplicationAlphaCuts(tpf); + } + + ELICIT aggregatedElicit = ContextInjectionFactory.make(ELICIT.class, context); + aggregatedElicit.setDomain(valuations.get(0).getDomain()); + aggregatedElicit.createRelation(tpfResult); + + return aggregatedElicit; + } + +} diff --git a/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanFuzzy.java b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanFuzzy.java new file mode 100644 index 0000000..6c6b6b5 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanFuzzy.java @@ -0,0 +1,88 @@ +package flintstones.operator.aggregation.geometricMean.operators; + +import java.util.ArrayList; +import java.util.List; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.operator.interfaces.IFuzzyWeightedAggregationOperator; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.geometricMean.GeometricMean; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class GeometricMeanFuzzy extends GeometricMean implements IFuzzyWeightedAggregationOperator { + + public Valuation aggregate(List valuations) { + FuzzyValuation v = null; + + TrapezoidalFunction tpf, + tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] {1, 1, 1, 1}); + + int size = valuations.size(); + for(int i = 0; i < size; ++i) { + v = (FuzzyValuation) valuations.get(i); + + Validator.notIllegalElementType(v, new String[] { FuzzyValuation.class.toString() }); + + tpf = ((FuzzyValuation) v).getFuzzyNumber(); + + tpfResult = tpfResult.multiplicationAlphaCuts(tpf); + } + + tpfResult = tpfResult.potence(1d / size); + + FuzzyValuation aggregatedFuzzyValuation = new FuzzyValuation(tpfResult, valuations.get(0).getDomain()); + + return aggregatedFuzzyValuation; + } + + @Override + public Valuation aggregate(List valuations, List weights) { + FuzzyValuation v = null; + + TrapezoidalFunction tpf, + tpfResult = new TrapezoidalFunction(); + tpfResult.setLimits(new double[] {1, 1, 1, 1}); + + int size = valuations.size(); + for(int i = 0; i < size; ++i) { + v = (FuzzyValuation) valuations.get(i); + + Validator.notIllegalElementType(v, new String[] { FuzzyValuation.class.toString() }); + + tpf = ((FuzzyValuation) v).getFuzzyNumber(); + tpf = tpf.potence(weights.get(i)); + tpfResult = tpfResult.multiplicationAlphaCuts(tpf); + } + + FuzzyValuation aggregatedFuzzyValuation = new FuzzyValuation(tpfResult, valuations.get(0).getDomain()); + + return aggregatedFuzzyValuation; + } + + //TODO Fix to a proper fuzzy weighted geometric mean aggregation operator + @Override + public Valuation aggregateF(List valuations, List weights) { + + List defuzziedWeights = new ArrayList(); + + double acum = 0, centroid; + for(TrapezoidalFunction w: weights) { + centroid = w.centroid(); + + if(Double.valueOf(centroid).isNaN())//Fuzzy number (1, 1, 1) + centroid = w.getLimits()[1]; + + defuzziedWeights.add(centroid); + acum += centroid; + } + + List normalizedDefuzziedWeights = new ArrayList(); + + for(Double dw: defuzziedWeights) + normalizedDefuzziedWeights.add(dw / acum); + + return aggregate(valuations, normalizedDefuzziedWeights); + } +} diff --git a/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanInteger.java b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanInteger.java new file mode 100644 index 0000000..6174eca --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanInteger.java @@ -0,0 +1,63 @@ +package flintstones.operator.aggregation.geometricMean.operators; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.geometricMean.GeometricMean; +import flintstones.valuation.numeric.integer.IntegerValuation; + +public class GeometricMeanInteger extends GeometricMean { + + public Valuation aggregate(List valuations) { + IntegerValuation result = null; + + double value = 1; + for (Valuation valuation : valuations) + value *= ((IntegerValuation) valuation).getValue(); + + double aux = (long) Math.pow(value, 1d / valuations.size()); + + result = (IntegerValuation) valuations.get(0).clone(); + result.setValue(aux); + + return result; + } + + + @Override + public Valuation aggregate(List valuations, List weights) { + IntegerValuation result = null; + + NumericIntegerDomain domain = null; + + List measures = new LinkedList(); + for(Valuation valuation : valuations) { + + Validator.notIllegalElementType(valuation, new String[] { IntegerValuation.class.toString() }); + + if (domain == null) + domain = (NumericIntegerDomain) valuation.getDomain(); + else if (!domain.equals(valuation.getDomain())) + throw new IllegalArgumentException("Invalid domain"); + + measures.add(((IntegerValuation) valuation).getValue()); + } + + if (domain != null) { + + double measure = 1; + for (int i = 0; i < measures.size(); i++) + measure *= Math.pow(measures.get(i), weights.get(i)); + + result = (IntegerValuation) valuations.get(0).clone(); + result.setValue(measure); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanReal.java b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanReal.java new file mode 100644 index 0000000..c8760ee --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanReal.java @@ -0,0 +1,64 @@ +package flintstones.operator.aggregation.geometricMean.operators; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.geometricMean.GeometricMean; +import flintstones.valuation.numeric.real.RealValuation; + +public class GeometricMeanReal extends GeometricMean { + + @Override + public Valuation aggregate(List valuations) { + RealValuation result = null; + + double value = 1; + for (Valuation valuation : valuations) + value *= ((RealValuation) valuation).getValue(); + + double aux = Math.pow(value, 1d / valuations.size()); + + result = (RealValuation) valuations.get(0).clone(); + result.setValue(aux); + + return result; + } + + @Override + public Valuation aggregate(List valuations, List weights) { + RealValuation result = null; + + NumericRealDomain domain = null; + + List measures = new LinkedList(); + for(Valuation valuation : valuations) { + + Validator.notIllegalElementType(valuation, new String[] { RealValuation.class.toString() }); + + if (domain == null) + domain = (NumericRealDomain) valuation.getDomain(); + else if (!domain.equals(valuation.getDomain())) + throw new IllegalArgumentException("Invalid domain"); + + measures.add(((RealValuation) valuation).getValue()); + } + + if (domain != null) { + + double measure = 1; + for (int i = 0; i < measures.size(); i++) + measure *= Math.pow(measures.get(i), weights.get(i)); + + + result = (RealValuation) valuations.get(0).clone(); + result.setValue(measure); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanTwoTuple.java b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanTwoTuple.java new file mode 100644 index 0000000..8eccdae --- /dev/null +++ b/bundles/flintstones.operator.aggregation.geometricMean/src/flintstones/operator/aggregation/geometricMean/operators/GeometricMeanTwoTuple.java @@ -0,0 +1,59 @@ +package flintstones.operator.aggregation.geometricMean.operators; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.geometricMean.GeometricMean; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class GeometricMeanTwoTuple extends GeometricMean { + + public Valuation aggregate(List valuations) { + TwoTupleValuation result = null; + + double beta = 1; + for (Valuation valuation : valuations) + beta *= (((TwoTupleValuation) valuation).calculateInverseDelta()); + + double aux = Math.pow(beta, 1d / valuations.size()); + + result = (TwoTupleValuation) valuations.get(0).clone(); + result.calculateDelta(aux); + + return result; + } + + @Override + public Valuation aggregate(List valuations, List weights) { + TwoTupleValuation result = null; + + FuzzySet domain = null; + + List measures = new LinkedList(); + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { TwoTupleValuation.class.toString() }); + + if (domain == null) + domain = (FuzzySet) valuation.getDomain(); + else if (!domain.equals(valuation.getDomain())) + throw new IllegalArgumentException("Invalid domain"); + + measures.add(((TwoTupleValuation) valuation).calculateInverseDelta()); + } + + if (domain != null) { + double beta = 1; + + for (int i = 0; i < measures.size(); i++) + beta *= Math.pow(measures.get(i), weights.get(i)); + + result = (TwoTupleValuation) valuations.get(0).clone(); + result.calculateDelta(beta); + } + + return result; + } +} diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/.classpath b/bundles/flintstones.operator.aggregation.harmonicmean/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.harmonicmean/.polyglot.META-INF new file mode 100644 index 0000000..378efaa --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.harmonicmean + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Harmonicmean + diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/.project b/bundles/flintstones.operator.aggregation.harmonicmean/.project new file mode 100644 index 0000000..05c52e6 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.harmonicmean + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362733 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.harmonicmean/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6e5e998 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Harmonicmean +Bundle-SymbolicName: flintstones.operator.aggregation.harmonicmean;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.aggregation.harmonicmean +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric.integer, + flintstones.helper.validator, + flintstones.valuation.numeric.real, + flintstones.domain.numeric.real, + flintstones.valuation.twoTuple, + flintstones.entity.domain, + flintstones.entity.operator diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/build.properties b/bundles/flintstones.operator.aggregation.harmonicmean/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/plugin.xml b/bundles/flintstones.operator.aggregation.harmonicmean/plugin.xml new file mode 100644 index 0000000..4353899 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/plugin.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/HarmonicMean.java b/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/HarmonicMean.java new file mode 100644 index 0000000..a20646f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/HarmonicMean.java @@ -0,0 +1,14 @@ +package flintstones.operator.aggregation.harmonicmean; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; +import flintstones.entity.operator.interfaces.IWeightedAggregationOperator; + +public abstract class HarmonicMean extends AggregationOperator implements IUnweightedAggregationOperator, IWeightedAggregationOperator { + + @Override + public String getName() { + return "Harmonic Mean"; + } + +} diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanInteger.java b/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanInteger.java new file mode 100644 index 0000000..b36257c --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanInteger.java @@ -0,0 +1,79 @@ +package flintstones.operator.aggregation.harmonicmean.operators; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.harmonicmean.HarmonicMean; +import flintstones.valuation.numeric.integer.IntegerValuation; + +public class HarmonicMeanInteger extends HarmonicMean { + + @Override + public Valuation aggregate(List valuations) { + IntegerValuation result = null; + double value = 0, aux = 0; + int size = valuations.size(); + NumericIntegerDomain domain = null; + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {IntegerValuation.class.toString()}); + + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Invalid domain"); + } + + value += (1d / ((IntegerValuation) valuation).getValue()); + } + + aux = size / value; + value = aux; + + if(domain != null) { + result = (IntegerValuation) valuations.get(0).clone(); + result.setValue(value); + } + + return result; + + } + + @Override + public Valuation aggregate(List valuations, List weights) { + IntegerValuation result = null; + NumericIntegerDomain domain = null; + + List measures = new LinkedList(); + for(Valuation valuation : valuations) { + + Validator.notIllegalElementType(valuation, new String[] { IntegerValuation.class.toString() }); + + if (domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Invalid domain"); + } + + measures.add(((IntegerValuation) valuation).getValue()); + } + + if (domain != null) { + int size = measures.size(); + + double measure = 0; + for (int i = 0; i < size; i++) + measure += weights.get(i) / measures.get(i); + + measure = 1d / measure; + result = (IntegerValuation) valuations.get(0).clone(); + result.setValue(measure); + } + + return result; + + } +} diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanReal.java b/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanReal.java new file mode 100644 index 0000000..e2a46f3 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanReal.java @@ -0,0 +1,80 @@ +package flintstones.operator.aggregation.harmonicmean.operators; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.harmonicmean.HarmonicMean; +import flintstones.valuation.numeric.real.RealValuation; + +public class HarmonicMeanReal extends HarmonicMean { + + @Override + public Valuation aggregate(List valuations) { + RealValuation result = null; + double value = 0, aux = 0; + int size = valuations.size(); + NumericRealDomain domain = null; + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {RealValuation.class.toString()}); + + if(domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Invalid domain"); + } + + value += (1d / ((RealValuation) valuation).getValue()); + } + + aux = size / value; + value = aux; + + if(domain != null) { + result = (RealValuation) valuations.get(0).clone(); + result.setValue(value); + } + + return result; + + } + + @Override + public Valuation aggregate(List valuations, List weights) { + RealValuation result = null; + NumericRealDomain domain = null; + + List measures = new LinkedList(); + for(Valuation valuation : valuations) { + + Validator.notIllegalElementType(valuation, new String[] { RealValuation.class.toString() }); + + if (domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Invalid domain"); + } + + measures.add(((RealValuation) valuation).getValue()); + } + + if (domain != null) { + int size = measures.size(); + + double measure = 0; + for (int i = 0; i < size; i++) + measure += weights.get(i) / measures.get(i); + + measure = 1d / measure; + result = (RealValuation) valuations.get(0).clone(); + result.setValue(measure); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanTwoTuple.java b/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanTwoTuple.java new file mode 100644 index 0000000..1115a17 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.harmonicmean/src/flintstones/operator/aggregation/harmonicmean/operators/HarmonicMeanTwoTuple.java @@ -0,0 +1,77 @@ +package flintstones.operator.aggregation.harmonicmean.operators; + +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.harmonicmean.HarmonicMean; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class HarmonicMeanTwoTuple extends HarmonicMean { + + @Override + public Valuation aggregate(List valuations) { + TwoTupleValuation result = null; + double beta = 0, aux =0; + FuzzySet domain = null; + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { TwoTupleValuation.class.toString() }); + + if(domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Invalid domain"); + } + + beta += 1d / ((TwoTupleValuation) valuation).calculateInverseDelta(); + } + + aux = valuations.size() / beta; + beta = aux; + + if (domain != null) { + result = (TwoTupleValuation) valuations.get(0).clone(); + result.calculateDelta(beta); + } + + return result; + + } + + @Override + public Valuation aggregate(List valuations, List weights) { + TwoTupleValuation result = null; + FuzzySet domain = null; + + List measures = new LinkedList(); + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { TwoTupleValuation.class.toString() }); + + if (domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Invalid domain"); + } + + measures.add(((TwoTupleValuation) valuation).calculateInverseDelta()); + } + + if (domain != null) { + int size = measures.size(); + + double beta = 0; + for (int i = 0; i < size; i++) + beta += weights.get(i) / measures.get(i); + + beta = 1d / beta; + result = (TwoTupleValuation) valuations.get(0).clone(); + result.calculateDelta(beta); + } + + return result; + } + +} \ No newline at end of file diff --git a/bundles/flintstones.operator.aggregation.max/.classpath b/bundles/flintstones.operator.aggregation.max/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.max/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.max/.polyglot.META-INF new file mode 100644 index 0000000..390ec12 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.max + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Max + diff --git a/bundles/flintstones.operator.aggregation.max/.project b/bundles/flintstones.operator.aggregation.max/.project new file mode 100644 index 0000000..3cb8d70 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.max + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362733 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.max/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.max/META-INF/MANIFEST.MF new file mode 100644 index 0000000..aee659f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/META-INF/MANIFEST.MF @@ -0,0 +1,25 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Max +Bundle-SymbolicName: flintstones.operator.aggregation.max;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.aggregation.max +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric.integer, + flintstones.valuation.numeric.integer.interval, + flintstones.valuation.numeric.real, + flintstones.valuation.numeric.real.interval, + flintstones.valuation.twoTuple, + flintstones.valuation.elicit, + flintstones.domain.numeric.real, + flintstones.entity.domain, + flintstones.valuation.numeric, + flintstones.entity.operator, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di, + flintstones.valuation.fuzzy +Export-Package: flintstones.operator.aggregation.max diff --git a/bundles/flintstones.operator.aggregation.max/build.properties b/bundles/flintstones.operator.aggregation.max/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.max/plugin.xml b/bundles/flintstones.operator.aggregation.max/plugin.xml new file mode 100644 index 0000000..1faed64 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/plugin.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/Max.java b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/Max.java new file mode 100644 index 0000000..e5ca258 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/Max.java @@ -0,0 +1,12 @@ +package flintstones.operator.aggregation.max; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; + +public abstract class Max extends AggregationOperator implements IUnweightedAggregationOperator { + + @Override + public String getName() { + return "Max"; + } +} diff --git a/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxELICIT.java b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxELICIT.java new file mode 100644 index 0000000..230bcb3 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxELICIT.java @@ -0,0 +1,66 @@ +package flintstones.operator.aggregation.max.operators; + +import java.util.Collections; +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 flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.max.Max; +import flintstones.valuation.elicit.ELICIT; + +public class MaxELICIT extends Max { + + @Inject + IEclipseContext context; + + @Override + public Valuation aggregate(List valuations) { + List a = new LinkedList(), b = new LinkedList(), c = new LinkedList(), d = new LinkedList(); + double limits[] = new double[4]; + + TrapezoidalFunction tpf; + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { ELICIT.class.toString() }); + + if(((ELICIT) valuation).getBeta() == null) + tpf = ((ELICIT) valuation).calculateFuzzyEnvelope(); + else + tpf = ((ELICIT) valuation).getBeta(); + + limits = tpf.getLimits(); + a.add(limits[0]); + b.add(limits[1]); + c.add(limits[2]); + d.add(limits[3]); + } + + Collections.sort(a); + Collections.sort(b); + Collections.sort(c); + Collections.sort(d); + + int size = a.size(); + + double maxa = a.get(size - 1); + double maxb = b.get(size - 1); + double maxc = c.get(size - 1); + double maxd = d.get(size - 1); + + ELICIT aggregatedElicit = ContextInjectionFactory.make(ELICIT.class, context); + aggregatedElicit.setDomain(valuations.get(0).getDomain()); + TrapezoidalFunction envelope = new TrapezoidalFunction(); + envelope.setLimits(new double[] {maxa, maxb, maxc, maxd}); + aggregatedElicit.createRelation(envelope); + + return aggregatedElicit; + } + +} diff --git a/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxFuzzy.java b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxFuzzy.java new file mode 100644 index 0000000..c97b1ab --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxFuzzy.java @@ -0,0 +1,55 @@ +package flintstones.operator.aggregation.max.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.max.Max; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class MaxFuzzy extends Max { + + @Override + public Valuation aggregate(List valuations) { + List a = new LinkedList(), b = new LinkedList(), c = new LinkedList(), d = new LinkedList(); + double limits[] = new double[4]; + + TrapezoidalFunction tpf; + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { FuzzyValuation.class.toString() }); + + tpf = ((FuzzyValuation) valuation).getFuzzyNumber(); + + limits = tpf.getLimits(); + a.add(limits[0]); + b.add(limits[1]); + c.add(limits[2]); + d.add(limits[3]); + } + + Collections.sort(a); + Collections.sort(b); + Collections.sort(c); + Collections.sort(d); + + int size = a.size(); + + double maxa = a.get(size - 1); + double maxb = b.get(size - 1); + double maxc = c.get(size - 1); + double maxd = d.get(size - 1); + + FuzzyValuation aggregatedValuation = new FuzzyValuation(); + aggregatedValuation.setDomain(valuations.get(0).getDomain()); + TrapezoidalFunction fuzzy_number = new TrapezoidalFunction(); + fuzzy_number.setLimits(new double[] {maxa, maxb, maxc, maxd}); + aggregatedValuation.setFuzzyNumber(fuzzy_number); + + return aggregatedValuation; + } + +} diff --git a/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxInteger.java b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxInteger.java new file mode 100644 index 0000000..a7f155f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxInteger.java @@ -0,0 +1,43 @@ +package flintstones.operator.aggregation.max.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.max.Max; +import flintstones.valuation.numeric.integer.IntegerValuation; + +public class MaxInteger extends Max { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericIntegerDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {IntegerValuation.class.toString()}); + + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntegerOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + result = values.get(values.size() - 1); + result = (Valuation) result.clone(); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxIntegerInterval.java b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxIntegerInterval.java new file mode 100644 index 0000000..1f234c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxIntegerInterval.java @@ -0,0 +1,43 @@ +package flintstones.operator.aggregation.max.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.max.Max; +import flintstones.valuation.numeric.integer.interval.IntegerIntervalValuation; + +public class MaxIntegerInterval extends Max { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericIntegerDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {IntegerIntervalValuation.class.toString()}); + + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntervalIntegerOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + result = values.get(values.size() - 1); + result = (Valuation) result.clone(); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxReal.java b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxReal.java new file mode 100644 index 0000000..4267230 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxReal.java @@ -0,0 +1,42 @@ +package flintstones.operator.aggregation.max.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.max.Max; +import flintstones.valuation.numeric.real.RealValuation; + +public class MaxReal extends Max { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericRealDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {RealValuation.class.toString()}); + + if(domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.RealOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + result = values.get(values.size() - 1); + result = (Valuation) result.clone(); + } + + return result; + } + +} diff --git a/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxRealInterval.java b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxRealInterval.java new file mode 100644 index 0000000..0a867b5 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxRealInterval.java @@ -0,0 +1,43 @@ +package flintstones.operator.aggregation.max.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.max.Max; +import flintstones.valuation.numeric.real.interval.RealIntervalValuation; + +public class MaxRealInterval extends Max { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericRealDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {RealIntervalValuation.class.toString()}); + + if(domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntervalRealOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + result = values.get(values.size() - 1); + result = (Valuation) result.clone(); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxTwoTuple.java b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxTwoTuple.java new file mode 100644 index 0000000..8485c50 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.max/src/flintstones/operator/aggregation/max/operators/MaxTwoTuple.java @@ -0,0 +1,43 @@ +package flintstones.operator.aggregation.max.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.max.Max; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class MaxTwoTuple extends Max { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + FuzzySet domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {TwoTupleValuation.class.toString()}); + + if(domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.TwoTupleOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(domain != null) { + Collections.sort(values); + result = values.get(values.size() - 1); + result = (Valuation) result.clone(); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.median/.classpath b/bundles/flintstones.operator.aggregation.median/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.median/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.median/.polyglot.META-INF new file mode 100644 index 0000000..90e268e --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.median + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Median + diff --git a/bundles/flintstones.operator.aggregation.median/.project b/bundles/flintstones.operator.aggregation.median/.project new file mode 100644 index 0000000..3a63eb5 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.median + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362734 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.median/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.median/META-INF/MANIFEST.MF new file mode 100644 index 0000000..284f93a --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Median +Bundle-SymbolicName: flintstones.operator.aggregation.median;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.aggregation.median +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric.integer.interval, + flintstones.valuation.numeric.integer, + flintstones.valuation.numeric.real.interval, + flintstones.valuation.numeric.real, + flintstones.valuation.twoTuple, + flintstones.valuation.linguistic, + flintstones.domain.numeric.real, + flintstones.entity.domain, + flintstones.entity.operator diff --git a/bundles/flintstones.operator.aggregation.median/build.properties b/bundles/flintstones.operator.aggregation.median/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.median/plugin.xml b/bundles/flintstones.operator.aggregation.median/plugin.xml new file mode 100644 index 0000000..c7f0ddb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/plugin.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/Median.java b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/Median.java new file mode 100644 index 0000000..c9a7973 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/Median.java @@ -0,0 +1,13 @@ +package flintstones.operator.aggregation.median; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; + +public abstract class Median extends AggregationOperator implements IUnweightedAggregationOperator { + + @Override + public String getName() { + return "Median"; + } + +} diff --git a/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianInteger.java b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianInteger.java new file mode 100644 index 0000000..e142a94 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianInteger.java @@ -0,0 +1,63 @@ +package flintstones.operator.aggregation.median.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.median.Median; +import flintstones.valuation.numeric.integer.IntegerValuation; + +public class MedianInteger extends Median { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericIntegerDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {IntegerValuation.class.toString()}); + + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntegerOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + + Collections.sort(values); + + if(values.size() % 2 != 0) { + int median = (values.size() + 1) / 2; + + result = values.get(median); + result = (Valuation) result.clone(); + + } else { + int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding downwards + int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding upwards + + Valuation auxValuation1 = values.get(firstPosMedian); + Valuation auxValuation2 = values.get(secondPosMedian); + + double value = (((IntegerValuation) auxValuation1).getValue() + ((IntegerValuation) auxValuation2).getValue()) / 2d; + + result = values.get(firstPosMedian); + result = (Valuation) result.clone(); + + ((IntegerValuation) result).setValue(value); + } + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianIntegerInterval.java b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianIntegerInterval.java new file mode 100644 index 0000000..f29e65b --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianIntegerInterval.java @@ -0,0 +1,69 @@ +package flintstones.operator.aggregation.median.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.median.Median; +import flintstones.valuation.numeric.integer.interval.IntegerIntervalValuation; + +public class MedianIntegerInterval extends Median { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericIntegerDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {IntegerIntervalValuation.class.toString()}); + + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntervalIntegerOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + + if((values.size() % 2) != 0) { + + int median = (values.size() + 1) / 2; + + result = values.get(median); + result = (Valuation) result.clone(); + + } else { + + int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding downwards + int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding upwards + + Valuation auxValuation1 = values.get(firstPosMedian); + Valuation auxValuation2 = values.get(secondPosMedian); + + double minValue = (((IntegerIntervalValuation) auxValuation1).getMin()) + (((IntegerIntervalValuation) auxValuation2).getMin()); + double maxValue = (((IntegerIntervalValuation) auxValuation1).getMax()) + (((IntegerIntervalValuation) auxValuation2).getMax()); + + minValue /= 2d; + maxValue /= 2d; + + result = values.get(firstPosMedian); + result = (Valuation) result.clone();//clone any valuation + + ((IntegerIntervalValuation) result).setMinMax(minValue, maxValue); + } + } + + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianReal.java b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianReal.java new file mode 100644 index 0000000..4d4350f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianReal.java @@ -0,0 +1,66 @@ +package flintstones.operator.aggregation.median.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.median.Median; +import flintstones.valuation.numeric.real.RealValuation; + +public class MedianReal extends Median { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericRealDomain domain = null; + List values = new LinkedList(); + + for (Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { RealValuation.class.toString() }); + + if (domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.RealOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if (!values.isEmpty()) { + + Collections.sort(values); + + if (values.size() % 2 != 0) { + int median = (values.size() + 1) / 2; + + result = values.get(median - 1); + result = (Valuation) result.clone(); + + } else { + int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);// the nearest integer when + // rounding downwards + int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);// the nearest integer when + // rounding upwards + + Valuation auxValuation1 = values.get(firstPosMedian); + Valuation auxValuation2 = values.get(secondPosMedian); + + double value = (((RealValuation) auxValuation1).getValue() + ((RealValuation) auxValuation2).getValue()) + / 2d; + + result = values.get(firstPosMedian); + result = (Valuation) result.clone(); + + ((RealValuation) result).setValue(value); + } + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianRealInterval.java b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianRealInterval.java new file mode 100644 index 0000000..692687d --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianRealInterval.java @@ -0,0 +1,68 @@ +package flintstones.operator.aggregation.median.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.median.Median; +import flintstones.valuation.numeric.real.interval.RealIntervalValuation; + +public class MedianRealInterval extends Median { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericRealDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {RealIntervalValuation.class.toString()}); + + if(domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntervalRealOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + + if((values.size() % 2) != 0) { + + int median = (values.size() + 1) / 2; + + result = values.get(median); + result = (Valuation) result.clone(); + + } else { + + int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding downwards + int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding upwards + + Valuation auxValuation1 = values.get(firstPosMedian); + Valuation auxValuation2 = values.get(secondPosMedian); + + double minValue = (((RealIntervalValuation) auxValuation1).getMin()) + (((RealIntervalValuation) auxValuation2).getMin()); + double maxValue = (((RealIntervalValuation) auxValuation1).getMax()) + (((RealIntervalValuation) auxValuation2).getMax()); + + minValue /= 2d; + maxValue /= 2d; + + result = values.get(firstPosMedian); + result = (Valuation) result.clone();//clone any valuation + + ((RealIntervalValuation) result).setMinMax(minValue, maxValue); + } + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianTwoTuple.java b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianTwoTuple.java new file mode 100644 index 0000000..fb61d91 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.median/src/flintstones/operator/aggregation/median/operators/MedianTwoTuple.java @@ -0,0 +1,65 @@ +package flintstones.operator.aggregation.median.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.median.Median; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class MedianTwoTuple extends Median { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + FuzzySet domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {TwoTupleValuation.class.toString()}); + + if(domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.TwoTupleOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(domain != null) { + + if(!values.isEmpty()) { + + Collections.sort(values); + + if(values.size() % 2 != 0) { + int median = (values.size() + 1) / 2; + + result = values.get(median); + result = (Valuation) result.clone(); + + } else { + int firstPosMedian = (int) Math.floor(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding downwards + int secondPosMedian = (int) Math.ceil(((values.size() + 1d) / 2d) - 1d);//the nearest integer when rounding upwards + + Valuation auxValuation1 = values.get(firstPosMedian); + Valuation auxValuation2 = values.get(secondPosMedian); + + double beta = (((TwoTupleValuation) auxValuation1).calculateInverseDelta() + ((TwoTupleValuation) auxValuation2).calculateInverseDelta()) / 2d; + + result = values.get(firstPosMedian); + result = (Valuation) result.clone(); + + ((TwoTupleValuation) result).calculateDelta(beta); + } + } + } + + return result; + } + +} diff --git a/bundles/flintstones.operator.aggregation.min/.classpath b/bundles/flintstones.operator.aggregation.min/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.min/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.min/.polyglot.META-INF new file mode 100644 index 0000000..69942a5 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.min + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Min + diff --git a/bundles/flintstones.operator.aggregation.min/.project b/bundles/flintstones.operator.aggregation.min/.project new file mode 100644 index 0000000..cf6c83e --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.min + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362734 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.min/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.min/META-INF/MANIFEST.MF new file mode 100644 index 0000000..76500f1 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Min +Bundle-SymbolicName: flintstones.operator.aggregation.min;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.aggregation.min +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric.integer, + flintstones.valuation.numeric.integer.interval, + flintstones.valuation.numeric.real, + flintstones.valuation.numeric.real.interval, + flintstones.valuation.twoTuple, + flintstones.valuation.elicit, + flintstones.valuation.fuzzy, + flintstones.domain.numeric.real, + flintstones.entity.domain, + flintstones.entity.operator, + org.eclipse.e4.core.contexts, + javax.inject, + org.eclipse.e4.core.di +Export-Package: flintstones.operator.aggregation.min diff --git a/bundles/flintstones.operator.aggregation.min/build.properties b/bundles/flintstones.operator.aggregation.min/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.min/plugin.xml b/bundles/flintstones.operator.aggregation.min/plugin.xml new file mode 100644 index 0000000..5f715a6 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/plugin.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/Min.java b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/Min.java new file mode 100644 index 0000000..0b42cd3 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/Min.java @@ -0,0 +1,13 @@ +package flintstones.operator.aggregation.min; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; + +public abstract class Min extends AggregationOperator implements IUnweightedAggregationOperator { + + @Override + public String getName() { + return "Min"; + } + +} diff --git a/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinELICIT.java b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinELICIT.java new file mode 100644 index 0000000..c3cffd3 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinELICIT.java @@ -0,0 +1,64 @@ +package flintstones.operator.aggregation.min.operators; + +import java.util.Collections; +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 flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.min.Min; +import flintstones.valuation.elicit.ELICIT; + +public class MinELICIT extends Min { + + @Inject + IEclipseContext context; + + @Override + public Valuation aggregate(List valuations) { + List a = new LinkedList(), b = new LinkedList(), c = new LinkedList(), d = new LinkedList(); + double limits[] = new double[4]; + + TrapezoidalFunction tpf; + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { ELICIT.class.toString() }); + + if(((ELICIT) valuation).getBeta() == null) + tpf = ((ELICIT) valuation).calculateFuzzyEnvelope(); + else + tpf = ((ELICIT) valuation).getBeta(); + + limits = tpf.getLimits(); + a.add(limits[0]); + b.add(limits[1]); + c.add(limits[2]); + d.add(limits[3]); + } + + Collections.sort(a); + Collections.sort(b); + Collections.sort(c); + Collections.sort(d); + + double mina = a.get(0); + double minb = b.get(0); + double minc = c.get(0); + double mind = d.get(0); + + ELICIT aggregatedElicit = ContextInjectionFactory.make(ELICIT.class, context); + aggregatedElicit.setDomain(valuations.get(0).getDomain()); + TrapezoidalFunction envelope = new TrapezoidalFunction(); + envelope.setLimits(new double[]{mina, minb, minc, mind}); + aggregatedElicit.createRelation(envelope); + + return aggregatedElicit; + } + +} diff --git a/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinFuzzy.java b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinFuzzy.java new file mode 100644 index 0000000..c7e386d --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinFuzzy.java @@ -0,0 +1,60 @@ +package flintstones.operator.aggregation.min.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.min.Min; +import flintstones.valuation.fuzzy.FuzzyValuation; + +public class MinFuzzy extends Min { + + @Inject + IEclipseContext context; + + @Override + public Valuation aggregate(List valuations) { + List a = new LinkedList(), b = new LinkedList(), c = new LinkedList(), d = new LinkedList(); + double limits[] = new double[4]; + + TrapezoidalFunction tpf; + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { FuzzyValuation.class.toString() }); + + tpf = ((FuzzyValuation) valuation).getFuzzyNumber(); + + limits = tpf.getLimits(); + a.add(limits[0]); + b.add(limits[1]); + c.add(limits[2]); + d.add(limits[3]); + } + + Collections.sort(a); + Collections.sort(b); + Collections.sort(c); + Collections.sort(d); + + double mina = a.get(0); + double minb = b.get(0); + double minc = c.get(0); + double mind = d.get(0); + + FuzzyValuation aggregatedValuation = new FuzzyValuation(); + aggregatedValuation.setDomain(valuations.get(0).getDomain()); + TrapezoidalFunction fuzzy_number = new TrapezoidalFunction(); + fuzzy_number.setLimits(new double[]{mina, minb, minc, mind}); + aggregatedValuation.setFuzzyNumber(fuzzy_number); + + return aggregatedValuation; + } + +} diff --git a/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinInteger.java b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinInteger.java new file mode 100644 index 0000000..5aeb929 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinInteger.java @@ -0,0 +1,43 @@ +package flintstones.operator.aggregation.min.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.min.Min; +import flintstones.valuation.numeric.integer.IntegerValuation; + +public class MinInteger extends Min { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericIntegerDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {IntegerValuation.class.toString()}); + + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntegerOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + result = values.get(0); + result = (Valuation) result.clone(); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinIntegerInterval.java b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinIntegerInterval.java new file mode 100644 index 0000000..9608002 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinIntegerInterval.java @@ -0,0 +1,43 @@ +package flintstones.operator.aggregation.min.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.min.Min; +import flintstones.valuation.numeric.integer.interval.IntegerIntervalValuation; + +public class MinIntegerInterval extends Min { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericIntegerDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {IntegerIntervalValuation.class.toString()}); + + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntervalIntegerOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + result = values.get(values.size() - 1); + result = (Valuation) result.clone(); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinReal.java b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinReal.java new file mode 100644 index 0000000..00096e6 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinReal.java @@ -0,0 +1,44 @@ +package flintstones.operator.aggregation.min.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.min.Min; +import flintstones.valuation.numeric.real.RealValuation; + +public class MinReal extends Min { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericRealDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {RealValuation.class.toString()}); + + if(domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.RealOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + result = values.get(0); + result = (Valuation) result.clone(); + } + + return result; + + + } + +} diff --git a/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinRealInterval.java b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinRealInterval.java new file mode 100644 index 0000000..420c5b0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinRealInterval.java @@ -0,0 +1,43 @@ +package flintstones.operator.aggregation.min.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.min.Min; +import flintstones.valuation.numeric.real.interval.RealIntervalValuation; + +public class MinRealInterval extends Min { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + NumericRealDomain domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {RealIntervalValuation.class.toString()}); + + if(domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntervalRealOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + Collections.sort(values); + result = values.get(0); + result = (Valuation) result.clone(); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinRealTwoTuple.java b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinRealTwoTuple.java new file mode 100644 index 0000000..d1b7b6b --- /dev/null +++ b/bundles/flintstones.operator.aggregation.min/src/flintstones/operator/aggregation/min/operators/MinRealTwoTuple.java @@ -0,0 +1,43 @@ +package flintstones.operator.aggregation.min.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.min.Min; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class MinRealTwoTuple extends Min { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + FuzzySet domain = null; + List values = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {TwoTupleValuation.class.toString()}); + + if(domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.TwoTupleOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(domain != null) { + Collections.sort(values); + result = values.get(0); + result = (Valuation) result.clone(); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.minmax/.classpath b/bundles/flintstones.operator.aggregation.minmax/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.minmax/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.minmax/.polyglot.META-INF new file mode 100644 index 0000000..91e44e4 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.minmax + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Minmax + diff --git a/bundles/flintstones.operator.aggregation.minmax/.project b/bundles/flintstones.operator.aggregation.minmax/.project new file mode 100644 index 0000000..d7c9baa --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.minmax + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362735 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.minmax/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.minmax/META-INF/MANIFEST.MF new file mode 100644 index 0000000..cce866b --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Minmax +Bundle-SymbolicName: flintstones.operator.aggregation.minmax;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.aggregation.minmax +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.hesitant, + flintstones.domain.fuzzyset, + flintstones.helper.validator, + flintstones.entity.domain, + flintstones.valuation, + flintstones.entity.operator diff --git a/bundles/flintstones.operator.aggregation.minmax/build.properties b/bundles/flintstones.operator.aggregation.minmax/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.minmax/plugin.xml b/bundles/flintstones.operator.aggregation.minmax/plugin.xml new file mode 100644 index 0000000..5c41108 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/plugin.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.minmax/src/flintstones/operator/aggregation/minmax/MinMax.java b/bundles/flintstones.operator.aggregation.minmax/src/flintstones/operator/aggregation/minmax/MinMax.java new file mode 100644 index 0000000..f76ceb8 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/src/flintstones/operator/aggregation/minmax/MinMax.java @@ -0,0 +1,13 @@ +package flintstones.operator.aggregation.minmax; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; + +public abstract class MinMax extends AggregationOperator implements IUnweightedAggregationOperator { + + @Override + public String getName() { + return "MinMax"; + } + +} diff --git a/bundles/flintstones.operator.aggregation.minmax/src/flintstones/operator/aggregation/minmax/operators/MinMaxHesitant.java b/bundles/flintstones.operator.aggregation.minmax/src/flintstones/operator/aggregation/minmax/operators/MinMaxHesitant.java new file mode 100644 index 0000000..be825d1 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.minmax/src/flintstones/operator/aggregation/minmax/operators/MinMaxHesitant.java @@ -0,0 +1,50 @@ +package flintstones.operator.aggregation.minmax.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.minmax.MinMax; +import flintstones.valuation.hesitant.HesitantValuation; + +public class MinMaxHesitant extends MinMax { + + @Override + public Valuation aggregate(List valuations) { + Valuation result = null; + FuzzySet domain = null; + List values = new LinkedList(); + List max = new LinkedList(); + + for(Valuation valuation: valuations) { + Validator.notIllegalElementType(valuation, new String[] {HesitantValuation.class.toString()}); + + if(domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if(!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.HesitantOperator_Invalid_domain"); + } + + values.add(valuation); + } + + if(!values.isEmpty()) { + for(Valuation valuation: values) { + if(valuation instanceof HesitantValuation) { + HesitantValuation hesitantVal = (HesitantValuation) valuation; + max.add(hesitantVal.getEnvelopeIndex()[1]); + } + } + Collections.sort(max); + result = new HesitantValuation(domain); + ((HesitantValuation) result).setLabel(max.get(0)); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.aggregation.owa/.classpath b/bundles/flintstones.operator.aggregation.owa/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.owa/.polyglot.META-INF b/bundles/flintstones.operator.aggregation.owa/.polyglot.META-INF new file mode 100644 index 0000000..e142c22 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.aggregation.owa + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Owa + + Sinbad2 + + diff --git a/bundles/flintstones.operator.aggregation.owa/.project b/bundles/flintstones.operator.aggregation.owa/.project new file mode 100644 index 0000000..acad4d0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.aggregation.owa + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362735 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.aggregation.owa/META-INF/MANIFEST.MF b/bundles/flintstones.operator.aggregation.owa/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b2fd106 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Owa +Bundle-SymbolicName: flintstones.operator.aggregation.owa;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric.integer, + flintstones.valuation.numeric.real, + flintstones.valuation.linguistic, + flintstones.valuation.twoTuple, + flintstones.quantifiers.yager, + flintstones.domain.numeric.real, + flintstones.entity.domain, + flintstones.entity.operator +Automatic-Module-Name: flintstones.operator.aggregation.owa +Export-Package: flintstones.operator.aggregation.owa diff --git a/bundles/flintstones.operator.aggregation.owa/build.properties b/bundles/flintstones.operator.aggregation.owa/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.aggregation.owa/plugin.xml b/bundles/flintstones.operator.aggregation.owa/plugin.xml new file mode 100644 index 0000000..bd7da2c --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/plugin.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/OWA.java b/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/OWA.java new file mode 100644 index 0000000..cb06c4c --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/OWA.java @@ -0,0 +1,16 @@ +package flintstones.operator.aggregation.owa; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.interfaces.IWeightedAggregationOperator; + +@SuppressWarnings("javadoc") +public abstract class OWA extends AggregationOperator implements IWeightedAggregationOperator { + + public static final String ID = "flintstones.operator.aggregation.owa"; //$NON-NLS-1$ + + @Override + public String getName() { + return "OWA"; + } + +} diff --git a/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OWAInteger.java b/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OWAInteger.java new file mode 100644 index 0000000..8d5b446 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OWAInteger.java @@ -0,0 +1,61 @@ +package flintstones.operator.aggregation.owa.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.integer.NumericIntegerDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.owa.OWA; +import flintstones.quantifiers.yager.YagerQuantifiers; +import flintstones.valuation.numeric.integer.IntegerValuation; + +public class OWAInteger extends OWA { + + @Override + public Valuation aggregate(List valuations, List weights) { + return this.aggregate(valuations, weights.get(0), weights.get(1)); + } + + + public Valuation aggregate(List valuations, double alphaQ, double betaQ) { + IntegerValuation result = null; + double measure = 0; + List measures = new LinkedList(); + NumericIntegerDomain domain = null; + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { IntegerValuation.class.toString() }); + + if(domain == null) { + domain = (NumericIntegerDomain) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.IntegerOperator_Invalid_domain"); + } + + measures.add(((IntegerValuation) valuation).getValue()); + + } + + if(domain != null) { + Collections.sort(measures); + Collections.reverse(measures); + + int size = measures.size(); + double[] weights = YagerQuantifiers.Q(size, alphaQ, betaQ); + + for(int i = 0; i < size; i++) { + measure += weights[i] * measures.get(i); + } + + result = (IntegerValuation) valuations.get(0).clone(); + result.setValue(measure); + } + + return result; + } + +} + + diff --git a/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OWAReal.java b/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OWAReal.java new file mode 100644 index 0000000..6cd5747 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OWAReal.java @@ -0,0 +1,61 @@ +package flintstones.operator.aggregation.owa.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.owa.OWA; +import flintstones.quantifiers.yager.YagerQuantifiers; +import flintstones.valuation.numeric.real.RealValuation; + +public class OWAReal extends OWA { + + @Override + public Valuation aggregate(List valuations, List weights) { + return this.aggregate(valuations, weights.get(0), weights.get(1)); + } + + public Valuation aggregate(List valuations, double alphaQ, double betaQ) { + RealValuation result = null; + double measure = 0; + List measures = new LinkedList(); + NumericRealDomain domain = null; + + for(Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { RealValuation.class.toString() }); + + if(domain == null) { + domain = (NumericRealDomain) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.RealOperator_Invalid_domain"); + } + + measures.add(((RealValuation) valuation).getValue()); + + } + + if(domain != null) { + Collections.sort(measures); + Collections.reverse(measures); + + int size = measures.size(); + double[] weights = YagerQuantifiers.Q(size, alphaQ, betaQ); + + for(int i = 0; i < size; i++) { + measure += weights[i] * measures.get(i); + } + + result = (RealValuation) valuations.get(0).clone(); + result.setValue(measure); + } + + return result; + } + + +} + + diff --git a/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OwaTwoTuple.java b/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OwaTwoTuple.java new file mode 100644 index 0000000..f29e991 --- /dev/null +++ b/bundles/flintstones.operator.aggregation.owa/src/flintstones/operator/aggregation/owa/operators/OwaTwoTuple.java @@ -0,0 +1,93 @@ +package flintstones.operator.aggregation.owa.operators; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.aggregation.owa.OWA; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class OwaTwoTuple extends OWA { +// +// @Override +// public Valuation aggregate(List valuations, List weights) { +// return this.aggregate(valuations, weights.get(0), weights.get(1)); +// } +// +// public Valuation aggregate(List valuations, double alphaQ, double betaQ) { +// TwoTuple result = null; +// double beta = 0; +// List measures = new LinkedList(); +// FuzzySet domain = null; +// +// for (Valuation valuation : valuations) { +// Validator.notIllegalElementType(valuation, new String[] { TwoTuple.class.toString() }); +// +// if (domain == null) { +// domain = (FuzzySet) valuation.getDomain(); +// } else if (!domain.equals(valuation.getDomain())) { +// throw new IllegalArgumentException("Messages.TwoTupleOperator_Invalid_domain"); +// } +// +// measures.add(((TwoTuple) valuation).calculateInverseDelta()); +// } +// +// if (domain != null) { +// Collections.sort(measures); +// Collections.reverse(measures); +// +// int size = measures.size(); +// double[] weights = YagerQuantifiers.Q(size, alphaQ, betaQ); +// +// for (int i = 0; i < size; i++) { +// beta += weights[i] * measures.get(i); +// } +// +// result = (TwoTuple) valuations.get(0) +// .clone(); +// result.calculateDelta(beta); +// } +// +// return result; +// +// } + + + public Valuation aggregate(List valuations, List weights) { + TwoTupleValuation result = null; + double beta = 0; + List measures = new LinkedList(); + FuzzySet domain = null; + + for (Valuation valuation : valuations) { + Validator.notIllegalElementType(valuation, new String[] { TwoTupleValuation.class.toString() }); + + if (domain == null) { + domain = (FuzzySet) valuation.getDomain(); + } else if (!domain.equals(valuation.getDomain())) { + throw new IllegalArgumentException("Messages.TwoTupleOperator_Invalid_domain"); + } + measures.add(((TwoTupleValuation) valuation).calculateInverseDelta()); + } + + if (domain != null) { + Collections.sort(measures); + Collections.reverse(measures); + + int size = measures.size(); + for (int i = 0; i < size; i++) { + beta += weights.get(i) * measures.get(i); + } + + result = (TwoTupleValuation) valuations.get(0).clone(); + result.calculateDelta(beta); + } + + return result; + + } + +} diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/.classpath b/bundles/flintstones.operator.normalization.numeric.distributed/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/.polyglot.META-INF b/bundles/flintstones.operator.normalization.numeric.distributed/.polyglot.META-INF new file mode 100644 index 0000000..69a041f --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.normalization.numeric.distributed + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Distributed + diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/.project b/bundles/flintstones.operator.normalization.numeric.distributed/.project new file mode 100644 index 0000000..c7228ad --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.normalization.numeric.distributed + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362736 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/META-INF/MANIFEST.MF b/bundles/flintstones.operator.normalization.numeric.distributed/META-INF/MANIFEST.MF new file mode 100644 index 0000000..4f25bd8 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Distributed +Bundle-SymbolicName: flintstones.operator.normalization.numeric.distributed;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.normalization.numeric.distributed +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator, + flintstones.valuation.numeric.real, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.valuation.numeric, + javax.inject, + flintstones.domain.numeric.real, + flintstones.entity.problemelement, + flintstones.entity.wvaluation, + flintstones.model.domain.service, + flintstones.entity.operator diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/build.properties b/bundles/flintstones.operator.normalization.numeric.distributed/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/plugin.xml b/bundles/flintstones.operator.normalization.numeric.distributed/plugin.xml new file mode 100644 index 0000000..c6a930b --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/plugin.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.normalization.numeric.distributed/src/flintstones/operator/normalization/numeric/distributed/DistributedNormalizationOperator.java b/bundles/flintstones.operator.normalization.numeric.distributed/src/flintstones/operator/normalization/numeric/distributed/DistributedNormalizationOperator.java new file mode 100644 index 0000000..d77a834 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.distributed/src/flintstones/operator/normalization/numeric/distributed/DistributedNormalizationOperator.java @@ -0,0 +1,53 @@ +package flintstones.operator.normalization.numeric.distributed; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import flintstones.entity.operator.NormalizationOperator; +import flintstones.entity.wvaluation.WValuation; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.valuation.numeric.NumericValuation; + + +public class DistributedNormalizationOperator extends NormalizationOperator { + + @Inject + IValuationService valuationService; + + @Inject + IDomainService domainService; + + @Override + public String getName() { + return "Distributed Normalization"; + } + + @Override + public WValuation[] normalize(List valuations) { + + double downSum = valuations.stream().map(k -> (NumericValuation)k.getValuation() ).mapToDouble( k -> k.getValue()*k.getValue() ).sum(); + double sqrtDown = Math.sqrt(downSum); + + List valuationNorm = new ArrayList<>(); + + for(WValuation v : valuations) { + + NumericValuation oldValuation = (NumericValuation)v.getValuation(); + NumericValuation newValuation = oldValuation.cloneToNormalize(); + + newValuation.setValue(oldValuation.getValue()/sqrtDown); + + WValuation newWaluation = new WValuation(v.getPEK(), newValuation); + valuationNorm.add(newWaluation); + } + + return valuationNorm.stream().map( k -> k).toArray(WValuation[]::new ); + + + } + + +} diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/.classpath b/bundles/flintstones.operator.normalization.numeric.ideal/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/.polyglot.META-INF b/bundles/flintstones.operator.normalization.numeric.ideal/.polyglot.META-INF new file mode 100644 index 0000000..b823d52 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.normalization.numeric.ideal + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ideal + diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/.project b/bundles/flintstones.operator.normalization.numeric.ideal/.project new file mode 100644 index 0000000..1de9a47 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.normalization.numeric.ideal + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362736 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/META-INF/MANIFEST.MF b/bundles/flintstones.operator.normalization.numeric.ideal/META-INF/MANIFEST.MF new file mode 100644 index 0000000..afb9f3b --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ideal +Bundle-SymbolicName: flintstones.operator.normalization.numeric.ideal;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.normalization.numeric.ideal +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.operator, + flintstones.entity.valuation, + flintstones.model.valuation.service, + flintstones.entity.wvaluation, + javax.inject, + flintstones.operator.aggregation.min, + flintstones.operator.aggregation.max, + flintstones.valuation.numeric.real, + flintstones.domain.numeric.real, + flintstones.entity.problemelement, + flintstones.model.domain.service, + flintstones.entity.operator diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/build.properties b/bundles/flintstones.operator.normalization.numeric.ideal/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/plugin.xml b/bundles/flintstones.operator.normalization.numeric.ideal/plugin.xml new file mode 100644 index 0000000..e5fcae2 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/plugin.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.normalization.numeric.ideal/src/flintstones/operator/normalization/numeric/ideal/IdealNormalizationOperator.java b/bundles/flintstones.operator.normalization.numeric.ideal/src/flintstones/operator/normalization/numeric/ideal/IdealNormalizationOperator.java new file mode 100644 index 0000000..4be2197 --- /dev/null +++ b/bundles/flintstones.operator.normalization.numeric.ideal/src/flintstones/operator/normalization/numeric/ideal/IdealNormalizationOperator.java @@ -0,0 +1,87 @@ +package flintstones.operator.normalization.numeric.ideal; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.NormalizationOperator; +import flintstones.entity.valuation.Valuation; +import flintstones.entity.wvaluation.WValuation; +import flintstones.model.domain.service.IDomainService; +import flintstones.model.valuation.service.IValuationService; +import flintstones.operator.aggregation.max.Max; +import flintstones.operator.aggregation.min.Min; +import flintstones.operator.service.IOperatorService; +import flintstones.valuation.numeric.NumericValuation; + +public class IdealNormalizationOperator extends NormalizationOperator { + + @Inject + IOperatorService operatorService; + + @Inject + IValuationService valuationService; + + @Inject + IDomainService domainService; + + @Override + public WValuation[] normalize(List valuations) { + + boolean isCost = valuations.get(0).getPEK().getCriterion().isCost(); + + List valuationNorm = isCost ? minimize(valuations) : maximize(valuations); + + return valuationNorm.toArray( new WValuation[valuationNorm.size()]); + + } + + private List minimize(List valuations) { + + List valuationNorm = new ArrayList<>(); + String operatorId = Min.class.getPackage().getName(); + AggregationOperator min = operatorService.getAggregationOperator(operatorId, WValuation.getValuationAsList(valuations).get(0).getId()); + Valuation lowerValuation = min.computeAggregation(WValuation.getValuationAsList(valuations), null); + double lowerValue = ((NumericValuation)lowerValuation).getValue(); + + for(WValuation v : valuations) { + + NumericValuation oldValuation = (NumericValuation)v.getValuation(); + double oldValue = oldValuation.getValue(); + NumericValuation newValuation = oldValuation.cloneToNormalize(); + + newValuation.setValue( lowerValue / oldValue ); + valuationNorm.add(new WValuation(v.getPEK(),newValuation)); + } + return valuationNorm; + + } + + private List maximize(List valuations) { + + List valuationNorm = new ArrayList<>(); + String operatorId = Max.class.getPackage().getName(); + AggregationOperator max = operatorService.getAggregationOperator(operatorId, WValuation.getValuationAsList(valuations).get(0).getId()); + Valuation biggerValuation = max.computeAggregation(WValuation.getValuationAsList(valuations), null); + double biggerValue = ((NumericValuation)biggerValuation).getValue(); + + for(WValuation v : valuations) { + + NumericValuation oldValuation = (NumericValuation)v.getValuation(); + double oldValue = oldValuation.getValue(); + NumericValuation newValuation = oldValuation.cloneToNormalize(); + + newValuation.setValue( oldValue / biggerValue ); + valuationNorm.add(new WValuation(v.getPEK(),newValuation)); + } + return valuationNorm; + } + + @Override + public String getName() { + return "Ideal Normalization"; + } + +} diff --git a/bundles/flintstones.operator.unification.elicit/.classpath b/bundles/flintstones.operator.unification.elicit/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.unification.elicit/.polyglot.META-INF b/bundles/flintstones.operator.unification.elicit/.polyglot.META-INF new file mode 100644 index 0000000..4d0973a --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.unification.elicit + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Unification operator ELICIT + diff --git a/bundles/flintstones.operator.unification.elicit/.project b/bundles/flintstones.operator.unification.elicit/.project new file mode 100644 index 0000000..ddaac62 --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.unification.elicit + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362737 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.unification.elicit/META-INF/MANIFEST.MF b/bundles/flintstones.operator.unification.elicit/META-INF/MANIFEST.MF new file mode 100644 index 0000000..48a0369 --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Unification operator ELICIT +Bundle-SymbolicName: flintstones.operator.unification.elicit;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.unification.elicit +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator.unification, + flintstones.valuation.hesitant, + flintstones.valuation.twoTuple, + flintstones.valuation.elicit, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + javax.inject diff --git a/bundles/flintstones.operator.unification.elicit/build.properties b/bundles/flintstones.operator.unification.elicit/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.unification.elicit/plugin.xml b/bundles/flintstones.operator.unification.elicit/plugin.xml new file mode 100644 index 0000000..628c42f --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/plugin.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/bundles/flintstones.operator.unification.elicit/src/flintstones/operator/unification/elicit/UnificationELICIT.java b/bundles/flintstones.operator.unification.elicit/src/flintstones/operator/unification/elicit/UnificationELICIT.java new file mode 100644 index 0000000..ab17587 --- /dev/null +++ b/bundles/flintstones.operator.unification.elicit/src/flintstones/operator/unification/elicit/UnificationELICIT.java @@ -0,0 +1,87 @@ +package flintstones.operator.unification.elicit; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.elicit.ELICIT; +import flintstones.valuation.hesitant.EUnaryRelationType; +import flintstones.valuation.hesitant.HesitantValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +public class UnificationELICIT extends UnificationOperator { + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + HesitantValuation hValuation = (HesitantValuation) valuation; + + if (hValuation.isPrimary()) { + return this.unifyPrimaryRelation(unificationDomain, hValuation); + } else if (((HesitantValuation) valuation).isUnary()) { + return this.unifyUnaryRelation(unificationDomain, hValuation); + } else { + return this.unifyBinaryRelation(unificationDomain, hValuation); + } + } + + private Valuation unifyBinaryRelation(Domain unificationDomain, HesitantValuation hValuation) { + LabelLinguisticDomain lowerTerm = hValuation.getLowerTerm(); + LabelLinguisticDomain upperTerm = hValuation.getUpperTerm(); + + TwoTupleValuation twoTupleLowerTerm = ContextInjectionFactory.make(TwoTupleValuation.class, context); + twoTupleLowerTerm.build((FuzzySet) hValuation.getDomain(), lowerTerm); + TwoTupleValuation elicitLowerTerm = twoTupleLowerTerm.transform((FuzzySet) unificationDomain); + TwoTupleValuation twoTupleUpperTerm = ContextInjectionFactory.make(TwoTupleValuation.class, context); + twoTupleUpperTerm.build((FuzzySet) hValuation.getDomain(), upperTerm); + TwoTupleValuation elicitUpperTerm = twoTupleUpperTerm.transform((FuzzySet) unificationDomain); + + ELICIT elicit = ContextInjectionFactory.make(ELICIT.class, context); + elicit.setDomain((FuzzySet) hValuation.getDomain()); + elicit.setBinaryRelation(elicitLowerTerm, elicitUpperTerm); + + elicit.computeInverse(); + + return elicit; + } + + private Valuation unifyPrimaryRelation(Domain unificationDomain, HesitantValuation hValuation) { + TwoTupleValuation term = ContextInjectionFactory.make(TwoTupleValuation.class, context); + term.build((FuzzySet) hValuation.getDomain(), hValuation.getLabel()); + TwoTupleValuation elicitTerm = term.transform((FuzzySet) unificationDomain); + + ELICIT elicit = ContextInjectionFactory.make(ELICIT.class, context); + elicit.setDomain((FuzzySet) hValuation.getDomain()); + elicit.setTwoTupleLabel(elicitTerm); + + elicit.computeInverse(); + + return elicit; + } + + private Valuation unifyUnaryRelation(Domain unificationDomain, HesitantValuation hValuation) { + LabelLinguisticDomain term = hValuation.getTerm(); + EUnaryRelationType unary = hValuation.getUnaryRelation(); + + TwoTupleValuation twoTupleTerm = ContextInjectionFactory.make(TwoTupleValuation.class, context); + twoTupleTerm.build((FuzzySet) hValuation.getDomain(), term); + TwoTupleValuation elicitTerm = twoTupleTerm.transform((FuzzySet) unificationDomain); + + ELICIT elicit = ContextInjectionFactory.make(ELICIT.class, context); + elicit.setDomain((FuzzySet) hValuation.getDomain()); + elicit.setUnaryRelation(unary, elicitTerm); + + elicit.computeInverse(); + + return elicit; + } + +} diff --git a/bundles/flintstones.operator.unification.fuzzy/.classpath b/bundles/flintstones.operator.unification.fuzzy/.classpath new file mode 100644 index 0000000..ca3785c --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.unification.fuzzy/.project b/bundles/flintstones.operator.unification.fuzzy/.project new file mode 100644 index 0000000..25e556f --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/.project @@ -0,0 +1,28 @@ + + + flintstones.operator.unification.fuzzy + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/flintstones.operator.unification.fuzzy/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.unification.fuzzy/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.unification.fuzzy/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.unification.fuzzy/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..bd1095b --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.unification.fuzzy/META-INF/MANIFEST.MF b/bundles/flintstones.operator.unification.fuzzy/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6f7865a --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Unification for fuzzy valuations +Bundle-SymbolicName: flintstones.operator.unification.fuzzy;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.operator.unification.fuzzy +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Require-Bundle: flintstones.operator.unification, + flintstones.domain.fuzzyset, + flintstones.valuation.numeric, + flintstones.valuation.fuzzy, + flintstones.valuation.linguistic diff --git a/bundles/flintstones.operator.unification.fuzzy/build.properties b/bundles/flintstones.operator.unification.fuzzy/build.properties new file mode 100644 index 0000000..6f20375 --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.unification.fuzzy/plugin.xml b/bundles/flintstones.operator.unification.fuzzy/plugin.xml new file mode 100644 index 0000000..9837c1a --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/plugin.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyInteger.java b/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyInteger.java new file mode 100644 index 0000000..9a8a0df --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyInteger.java @@ -0,0 +1,19 @@ +package flintstones.operator.unification.fuzzy; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.fuzzy.FuzzyValuation; +import flintstones.valuation.numeric.NumericValuation; + +public class UnificationFuzzyInteger extends UnificationOperator { + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + NumericValuation numeric = (NumericValuation) valuation; + double value = numeric.getValue(); + + return new FuzzyValuation(new TrapezoidalFunction(value, value, value, value), unificationDomain); + } +} diff --git a/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyLinguistic.java b/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyLinguistic.java new file mode 100644 index 0000000..b6d38d2 --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyLinguistic.java @@ -0,0 +1,18 @@ +package flintstones.operator.unification.fuzzy; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.fuzzy.FuzzyValuation; +import flintstones.valuation.linguistic.LinguisticValuation; + +public class UnificationFuzzyLinguistic extends UnificationOperator { + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + LinguisticValuation linguistic = (LinguisticValuation) valuation; + + return new FuzzyValuation((TrapezoidalFunction) linguistic.getLabel().getSemantic(), unificationDomain); + } +} diff --git a/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyReal.java b/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyReal.java new file mode 100644 index 0000000..2574330 --- /dev/null +++ b/bundles/flintstones.operator.unification.fuzzy/src/flintstones/operator/unification/fuzzy/UnificationFuzzyReal.java @@ -0,0 +1,20 @@ +package flintstones.operator.unification.fuzzy; + +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.fuzzy.FuzzyValuation; +import flintstones.valuation.numeric.NumericValuation; + +public class UnificationFuzzyReal extends UnificationOperator { + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + NumericValuation numeric = (NumericValuation) valuation; + double value = numeric.getValue(); + + return new FuzzyValuation(new TrapezoidalFunction(value, value, value, value), unificationDomain); + } + +} diff --git a/bundles/flintstones.operator.unification.twotuple/.classpath b/bundles/flintstones.operator.unification.twotuple/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.unification.twotuple/.polyglot.META-INF b/bundles/flintstones.operator.unification.twotuple/.polyglot.META-INF new file mode 100644 index 0000000..26168b1 --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.unification.twotuple + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Unification 2-tuple + diff --git a/bundles/flintstones.operator.unification.twotuple/.project b/bundles/flintstones.operator.unification.twotuple/.project new file mode 100644 index 0000000..43d5b6e --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/.project @@ -0,0 +1,45 @@ + + + flintstones.operator.unification.twotuple + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362738 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.unification.twotuple/META-INF/MANIFEST.MF b/bundles/flintstones.operator.unification.twotuple/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0e2148c --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Unification 2-tuple +Bundle-SymbolicName: flintstones.operator.unification.twotuple;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.operator.unification.twotuple +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.operator.unification, + flintstones.domain.fuzzyset.unbalanced, + flintstones.valuation.hesitant, + flintstones.valuation.numeric, + flintstones.valuation.numeric.integer.interval, + flintstones.valuation.numeric.real.interval, + flintstones.valuation.unifiedValuation, + flintstones.valuation.twoTuple, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + javax.inject diff --git a/bundles/flintstones.operator.unification.twotuple/build.properties b/bundles/flintstones.operator.unification.twotuple/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/bundles/flintstones.operator.unification.twotuple/plugin.xml b/bundles/flintstones.operator.unification.twotuple/plugin.xml new file mode 100644 index 0000000..e893e51 --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/plugin.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationHierarchiesTwoTupleLinguistic.java b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationHierarchiesTwoTupleLinguistic.java new file mode 100644 index 0000000..82ec846 --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationHierarchiesTwoTupleLinguistic.java @@ -0,0 +1,27 @@ +package flintstones.operator.unification.twotuple; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class UnificationHierarchiesTwoTupleLinguistic extends UnificationOperator { + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + TwoTupleValuation transformed2Tuple = ContextInjectionFactory.make(TwoTupleValuation.class, context); + transformed2Tuple.setDomain((FuzzySet) valuation.getDomain()); + transformed2Tuple.setLabel(((LinguisticValuation) valuation).getLabel()); + return transformed2Tuple.transform((FuzzySet) unificationDomain); + } +} diff --git a/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleHesitant.java b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleHesitant.java new file mode 100644 index 0000000..55ea07e --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleHesitant.java @@ -0,0 +1,45 @@ +package flintstones.operator.unification.twotuple; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.hesitant.HesitantValuation; +import flintstones.valuation.unifiedValuation.UnifiedValuation; + +public class UnificationTwoTupleHesitant extends UnificationOperator { + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + FuzzySet unifiedDomain = this.unification(unificationDomain, valuation); + UnifiedValuation unifiedValuation = ContextInjectionFactory.make(UnifiedValuation.class, context); + unifiedValuation.setDomain(unifiedDomain); + return unifiedValuation.disunification(unifiedDomain); + } + + public FuzzySet unification(Domain unificationDomain, Valuation valuation) { + FuzzySet unifiedDomain = (FuzzySet) ((FuzzySet) unificationDomain).clone(); + int g = unifiedDomain.getLabelSet().getCardinality(); + + TrapezoidalFunction tmf = ((HesitantValuation) valuation).calculateFuzzyEnvelope((FuzzySet) unificationDomain); + + FuzzySet fuzzysetF = (FuzzySet) unificationDomain; + FuzzySet valuationdomainF = (FuzzySet) valuation.getDomain(); + for (int i = 0; i < g; i++) { + IMembershipFunction function = unifiedDomain.getLabelSet().getLabel(i).getSemantic(); + unifiedDomain.setValue(i, function.maxMin(tmf, fuzzysetF, valuationdomainF)); + } + + return unifiedDomain; + } +} diff --git a/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleInteger.java b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleInteger.java new file mode 100644 index 0000000..05e1fe3 --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleInteger.java @@ -0,0 +1,49 @@ +package flintstones.operator.unification.twotuple; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.numeric.NumericValuation; +import flintstones.valuation.unifiedValuation.UnifiedValuation; + +public class UnificationTwoTupleInteger extends UnificationOperator { + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + FuzzySet unifiedDomain = this.unification(unificationDomain, valuation); + UnifiedValuation unifiedValuation = ContextInjectionFactory.make(UnifiedValuation.class, context); + unifiedValuation.setDomain(unifiedDomain); + return unifiedValuation.disunification(unifiedDomain); + } + + public FuzzySet unification(Domain unificationDomain, Valuation valuation) { + + Validator.notNull(unificationDomain); + + if (!((FuzzySet) unificationDomain).isBLTS()) + throw new IllegalArgumentException("Not BLTS fuzzy set"); + + FuzzySet unifiedDomain = (FuzzySet) unificationDomain.clone(); + int cardinality = ((FuzzySet) unificationDomain).getLabelSet().getCardinality(); + NumericValuation normalized = (NumericValuation) ((NumericValuation) valuation).normalized(); + + IMembershipFunction function; + for (int i = 0; i < cardinality; i++) { + function = unifiedDomain.getLabelSet().getLabel(i).getSemantic(); + unifiedDomain.setValue(i, function.getMembershipValue(normalized.getValue())); + } + + return unifiedDomain; + } +} diff --git a/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleIntervalInteger.java b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleIntervalInteger.java new file mode 100644 index 0000000..802225d --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleIntervalInteger.java @@ -0,0 +1,49 @@ +package flintstones.operator.unification.twotuple; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.numeric.integer.interval.IntegerIntervalValuation; +import flintstones.valuation.unifiedValuation.UnifiedValuation; + +public class UnificationTwoTupleIntervalInteger extends UnificationOperator { + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + FuzzySet unifiedDomain = this.unification(unificationDomain, valuation); + UnifiedValuation unifiedValuation = ContextInjectionFactory.make(UnifiedValuation.class, context); + unifiedValuation.setDomain(unifiedDomain); + return unifiedValuation.disunification(unifiedDomain); + } + + public FuzzySet unification(Domain unificationDomain, Valuation valuation) { + + Validator.notNull(unificationDomain); + + if (!((FuzzySet) unificationDomain).isBLTS()) + throw new IllegalArgumentException("Not BLTS fuzzy set"); + + FuzzySet result = (FuzzySet) unificationDomain.clone(); + int cardinality = ((FuzzySet) unificationDomain).getLabelSet().getCardinality(); + IntegerIntervalValuation normalized = (IntegerIntervalValuation) ((IntegerIntervalValuation) valuation).normalized(); + + IMembershipFunction function; + for (int i = 0; i < cardinality; i++) { + function = result.getLabelSet().getLabel(i).getSemantic(); + result.setValue(i, function.maxMin(normalized.getMax(), normalized.getMin())); + } + + return result; + } +} diff --git a/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleIntervalReal.java b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleIntervalReal.java new file mode 100644 index 0000000..ed3dfbe --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleIntervalReal.java @@ -0,0 +1,50 @@ +package flintstones.operator.unification.twotuple; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.function.types.TrapezoidalFunction; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.numeric.real.interval.RealIntervalValuation; +import flintstones.valuation.unifiedValuation.UnifiedValuation; + +public class UnificationTwoTupleIntervalReal extends UnificationOperator{ + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + FuzzySet unifiedDomain = this.unification(unificationDomain, valuation); + UnifiedValuation unifiedValuation = ContextInjectionFactory.make(UnifiedValuation.class, context); + unifiedValuation.setDomain(unifiedDomain); + return unifiedValuation.disunification(unifiedDomain); + } + + public FuzzySet unification(Domain unificationDomain, Valuation valuation) { + + Validator.notNull(unificationDomain); + + if (!((FuzzySet) unificationDomain).isBLTS()) + throw new IllegalArgumentException("Not BLTS fuzzy set"); + + FuzzySet result = (FuzzySet) unificationDomain.clone(); + int cardinality = ((FuzzySet) unificationDomain).getLabelSet().getCardinality(); + RealIntervalValuation normalized = (RealIntervalValuation) ((RealIntervalValuation) valuation).normalized(); + + IMembershipFunction function; + for (int i = 0; i < cardinality; i++) { + function = result.getLabelSet().getLabel(i).getSemantic(); + result.setValue(i, ((TrapezoidalFunction) function).maxMin(normalized.getMax(), normalized.getMin())); + } + + return result; + } +} diff --git a/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleLinguistic.java b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleLinguistic.java new file mode 100644 index 0000000..c0427ee --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleLinguistic.java @@ -0,0 +1,51 @@ +package flintstones.operator.unification.twotuple; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.unifiedValuation.UnifiedValuation; + +public class UnificationTwoTupleLinguistic extends UnificationOperator { + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + FuzzySet unifiedDomain = this.unification(unificationDomain, valuation); + UnifiedValuation unifiedValuation = ContextInjectionFactory.make(UnifiedValuation.class, context); + unifiedValuation.setDomain(unifiedDomain); + return unifiedValuation.disunification(unifiedDomain); + } + + public FuzzySet unification(Domain unificationDomain, Valuation valuation) { + + Validator.notNull(unificationDomain); + + if (!((FuzzySet) unificationDomain).isBLTS()) + throw new IllegalArgumentException("Not BLTS fuzzy set"); + + FuzzySet fuzzysetF = (FuzzySet) unificationDomain; + FuzzySet valuationdomainF = (FuzzySet) valuation.getDomain(); + + FuzzySet unifiedDomain = (FuzzySet) ((FuzzySet) unificationDomain).clone(); + int cardinality = unifiedDomain.getLabelSet().getCardinality(); + + IMembershipFunction function; + for (int i = 0; i < cardinality; i++) { + function = unifiedDomain.getLabelSet().getLabel(i).getSemantic(); + unifiedDomain.setValue(i, function.maxMin(((LinguisticValuation) valuation).getLabel().getSemantic(), fuzzysetF, valuationdomainF)); + } + + return unifiedDomain; + } +} diff --git a/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleReal.java b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleReal.java new file mode 100644 index 0000000..eab789a --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleReal.java @@ -0,0 +1,49 @@ +package flintstones.operator.unification.twotuple; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.FuzzySet; +import flintstones.domain.fuzzyset.semantic.IMembershipFunction; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.validator.Validator; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.numeric.NumericValuation; +import flintstones.valuation.unifiedValuation.UnifiedValuation; + +public class UnificationTwoTupleReal extends UnificationOperator { + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + FuzzySet unifiedDomain = this.unification(unificationDomain, valuation); + UnifiedValuation unifiedValuation = ContextInjectionFactory.make(UnifiedValuation.class, context); + unifiedValuation.setDomain(unifiedDomain); + return unifiedValuation.disunification(unifiedDomain); + } + + public FuzzySet unification(Domain unificationDomain, Valuation valuation) { + + Validator.notNull(unificationDomain); + + if (!((FuzzySet) unificationDomain).isBLTS()) + throw new IllegalArgumentException("Not BLTS fuzzy set"); + + FuzzySet unifiedDomain = (FuzzySet) unificationDomain.clone(); + int cardinality = ((FuzzySet) unificationDomain).getLabelSet().getCardinality(); + NumericValuation normalized = (NumericValuation) ((NumericValuation) valuation).normalized(); + + IMembershipFunction function; + for (int i = 0; i < cardinality; i++) { + function = unifiedDomain.getLabelSet().getLabel(i).getSemantic(); + unifiedDomain.setValue(i, function.getMembershipValue(normalized.getValue())); + } + + return unifiedDomain; + } +} diff --git a/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleUnbalanced.java b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleUnbalanced.java new file mode 100644 index 0000000..839886f --- /dev/null +++ b/bundles/flintstones.operator.unification.twotuple/src/flintstones/operator/unification/twotuple/UnificationTwoTupleUnbalanced.java @@ -0,0 +1,177 @@ +package flintstones.operator.unification.twotuple; + +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.domain.fuzzyset.label.LabelLinguisticDomain; +import flintstones.domain.fuzzyset.unbalanced.Unbalanced; +import flintstones.domain.numeric.real.NumericRealDomain; +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.unification.UnificationOperator; +import flintstones.valuation.linguistic.LinguisticValuation; +import flintstones.valuation.twoTuple.TwoTupleValuation; + +public class UnificationTwoTupleUnbalanced extends UnificationOperator { + + private static final int LEFT = 0; + private static final int RIGHT = 1; + + private Unbalanced hgls; + private Unbalanced unificationDomain; + + @Inject + IEclipseContext context; + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation) { + this.unificationDomain = (Unbalanced) unificationDomain; + + Map lhDomains = this.generateLHDomains(valuation); + return this.transformInto2Tuple(valuation, lhDomains); + } + + public Map generateLHDomains(Valuation valuation) { + Map lhDomains = new HashMap(); + + if (unificationDomain != null) { + + hgls = null; + + int[] lh = ((Unbalanced) unificationDomain).getLh(); + + for (int i = 0; i < lh.length; i++) { + lhDomains.put(lh[i], generateDomain(lh[i])); + + if (i == (lh.length - 1)) { + hgls = lhDomains.get(lh[i]); + } + } + } + + return lhDomains; + } + + public Valuation transformInto2Tuple(Valuation valuation, Map lhDomains) { + LabelLinguisticDomain label = null; + + double alpha = 0; + if (valuation instanceof TwoTupleValuation) { + label = ((TwoTupleValuation) valuation).getLabel(); + alpha = ((TwoTupleValuation) valuation).getAlpha(); + } else if (valuation instanceof LinguisticValuation) { + label = ((LinguisticValuation) valuation).getLabel(); + } else { + throw new IllegalArgumentException(); + } + + int pos = ((Unbalanced) unificationDomain).getLabelSet().getPos(label); + Map domains = ((Unbalanced) unificationDomain).getLabel(pos); + int size = domains.size(); + + Unbalanced[] auxDomains = new Unbalanced[size]; + LabelLinguisticDomain[] labels = new LabelLinguisticDomain[size]; + int[] sizes = new int[size]; + + int i = 0; + for (Integer domainSize : domains.keySet()) { + auxDomains[i] = lhDomains.get(domainSize); + labels[i] = auxDomains[i].getLabelSet().getLabel(domains.get(domainSize)); + sizes[i] = domainSize; + i++; + } + + return transform(label, alpha, (size > 1), auxDomains, labels, sizes); + } + + private Unbalanced generateDomain(int cardinality) { + String[] labels = new String[cardinality]; + for (int i = 0; i < cardinality; i++) { + labels[i] = Integer.toString(i); + } + + Unbalanced domain = ContextInjectionFactory.make(Unbalanced.class, context); + domain.setName("lh(" + labels.length + ")"); + domain.createTrapezoidalFunction(labels); + + return domain; + } + + private Valuation transform(LabelLinguisticDomain label, double alpha, boolean brid, Unbalanced[] domains, + LabelLinguisticDomain[] labels, int[] sizes) { + + Valuation result; + + if ((!brid) || (alpha == 0)) { + if (brid) { + if (sizes[0] > sizes[1]) { + result = transformInDomain(domains[0], labels[0], alpha); + } else { + result = transformInDomain(domains[1], labels[1], alpha); + } + } else { + result = transformInDomain(domains[0], labels[0], alpha); + } + } else { + if (alpha > 0) { + if (smallSide(label) == RIGHT) { + if (sizes[0] > sizes[1]) { + result = transformInDomain(domains[0], labels[0], alpha); + } else { + result = transformInDomain(domains[1], labels[1], alpha); + } + } else { + if (sizes[0] > sizes[1]) { + result = transformInDomain(domains[1], labels[1], alpha); + } else { + result = transformInDomain(domains[0], labels[0], alpha); + } + } + } else { + if (smallSide(label) == RIGHT) { + if (sizes[0] > sizes[1]) { + result = transformInDomain(domains[1], labels[1], alpha); + } else { + result = transformInDomain(domains[0], labels[0], alpha); + } + } else { + if (sizes[0] > sizes[1]) { + result = transformInDomain(domains[0], labels[0], alpha); + } else { + result = transformInDomain(domains[1], labels[1], alpha); + } + } + } + } + return result; + } + + private Valuation transformInDomain(Unbalanced domain, LabelLinguisticDomain label, double alpha) { + TwoTupleValuation result = ContextInjectionFactory.make(TwoTupleValuation.class, context); + result.build(domain, label, alpha); + + if (domain != hgls) + result = result.transform(hgls); + + return result; + } + + private int smallSide(LabelLinguisticDomain l) { + NumericRealDomain center = l.getSemantic().getCenter(); + NumericRealDomain coverage = l.getSemantic().getCoverage(); + + double left = center.getMin() - coverage.getMin(); + double right = coverage.getMax() - center.getMax(); + + if (left > right) { + return RIGHT; + } else { + return LEFT; + } + } +} diff --git a/bundles/flintstones.operator.unification/.classpath b/bundles/flintstones.operator.unification/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.operator.unification/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator.unification/.polyglot.META-INF b/bundles/flintstones.operator.unification/.polyglot.META-INF new file mode 100644 index 0000000..2063f86 --- /dev/null +++ b/bundles/flintstones.operator.unification/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator.unification + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Unification operator + + Sinbad2 + + diff --git a/bundles/flintstones.operator.unification/.project b/bundles/flintstones.operator.unification/.project new file mode 100644 index 0000000..6af4d30 --- /dev/null +++ b/bundles/flintstones.operator.unification/.project @@ -0,0 +1,50 @@ + + + flintstones.operator.unification + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362737 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator.unification/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator.unification/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator.unification/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator.unification/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator.unification/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator.unification/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator.unification/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator.unification/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator.unification/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator.unification/META-INF/MANIFEST.MF b/bundles/flintstones.operator.unification/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f082e97 --- /dev/null +++ b/bundles/flintstones.operator.unification/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Unification operator +Bundle-SymbolicName: flintstones.operator.unification;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.operator.unification +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.valuation;visibility:=reexport, + flintstones.helper.extensionpoint, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + javax.inject +Service-Component: component.xml +Bundle-ActivationPolicy: lazy +Export-Package: flintstones.operator.unification, + flintstones.operator.unification.service diff --git a/bundles/flintstones.operator.unification/build.properties b/bundles/flintstones.operator.unification/build.properties new file mode 100644 index 0000000..516c952 --- /dev/null +++ b/bundles/flintstones.operator.unification/build.properties @@ -0,0 +1,6 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml,\ + plugin.xml +source.. = src/ diff --git a/bundles/flintstones.operator.unification/component.xml b/bundles/flintstones.operator.unification/component.xml new file mode 100644 index 0000000..9efb233 --- /dev/null +++ b/bundles/flintstones.operator.unification/component.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/flintstones.operator.unification/plugin.xml b/bundles/flintstones.operator.unification/plugin.xml new file mode 100644 index 0000000..400a434 --- /dev/null +++ b/bundles/flintstones.operator.unification/plugin.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/bundles/flintstones.operator.unification/schema/flintstones.operator.unification.extensionpoint.exsd b/bundles/flintstones.operator.unification/schema/flintstones.operator.unification.extensionpoint.exsd new file mode 100644 index 0000000..2eaa269 --- /dev/null +++ b/bundles/flintstones.operator.unification/schema/flintstones.operator.unification.extensionpoint.exsd @@ -0,0 +1,140 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.operator.unification/src/flintstones/operator/unification/UnificationOperator.java b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/UnificationOperator.java new file mode 100644 index 0000000..ec888d0 --- /dev/null +++ b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/UnificationOperator.java @@ -0,0 +1,130 @@ +package flintstones.operator.unification; + +import flintstones.entity.domain.Domain; +import flintstones.entity.extensionenum.ExtensionEnum; +import flintstones.entity.valuation.Valuation; + +public abstract class UnificationOperator { + + /** The id. */ + protected String id; + + /** The name. */ + protected String name; + + /** The source valuation id. */ + protected String source_valuation_id; + + /** The final valuation id. */ + protected String final_valuation_id; + + /** + * The Class Fields. + */ + public enum Fields implements ExtensionEnum { + + /** The id. */ + id, + /** The name. */ + name, + /** The implementation. */ + implementation, + /** The source valuation. */ + source_valuation, + /** The final valuation. */ + final_valuation, + /** The source valuation id. */ + source_valuation_type, + /** The final valuation id. */ + final_valuation_type, + /** The specific method id. */ + specific_method; + } + + /** + * Instantiates a new aggregation operator. + */ + public UnificationOperator() { + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the id. + * + * @param id the new id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Sets the name. + * + * @param name the new name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets the source valuation id. + * + * @return the source valuation id + */ + public String getSourceValuationId() { + return this.source_valuation_id; + } + + /** + * Sets the source valuation id. + * + * @param name the new source valuation id + */ + public void setSourceValuationId(String source_valuation_id) { + this.source_valuation_id = source_valuation_id; + } + + /** + * Gets the final valuation id. + * + * @return the final valuation id + */ + public String getFinalValuationId() { + return this.final_valuation_id; + } + + /** + * Sets the final valuation id. + * + * @param name the new final valuation id + */ + public void setFinalValuationId(String final_valuation_id) { + this.final_valuation_id = final_valuation_id; + } + + /** + * Unify valuation + * @param valuation valuation to unify + * @param unificationDomain unification domain + * @return unified valuation + */ + public abstract Valuation unify(Domain unificationDomain, Valuation valuation); + +} diff --git a/bundles/flintstones.operator.unification/src/flintstones/operator/unification/exception/UnificationOperatorFinalValuationNotFound.java b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/exception/UnificationOperatorFinalValuationNotFound.java new file mode 100644 index 0000000..f9dfa6c --- /dev/null +++ b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/exception/UnificationOperatorFinalValuationNotFound.java @@ -0,0 +1,19 @@ +package flintstones.operator.unification.exception; + +/** + * The Class AggregationOperatorNotFound. + */ +public class UnificationOperatorFinalValuationNotFound extends Error { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 3486693795198966709L; + + /** + * Instantiates a new unification operator not found. + * + * @param operatorId the operator id + */ + public UnificationOperatorFinalValuationNotFound(String finalValuation) { + super("No existe operador de unificación que pueda unificar a " + finalValuation); //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/bundles/flintstones.operator.unification/src/flintstones/operator/unification/exception/UnificationOperatorNotImplemented.java b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/exception/UnificationOperatorNotImplemented.java new file mode 100644 index 0000000..d2eacad --- /dev/null +++ b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/exception/UnificationOperatorNotImplemented.java @@ -0,0 +1,20 @@ +package flintstones.operator.unification.exception; + +/** + * The Class AggregationOperatorNotImplementedForValuation. + */ +public class UnificationOperatorNotImplemented extends Exception { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 8029363988701450857L; + + /** + * Instantiates a new aggregation operator not implemented for valuation. + * + * @param operatorId the operator id + * @param valuationId the valuation id + */ + public UnificationOperatorNotImplemented(String sourceValuation, String finalValuation) { + super("No existe operador de unificación que unifique la valoración " + sourceValuation + " a la valoración " + finalValuation + "." ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } +} diff --git a/bundles/flintstones.operator.unification/src/flintstones/operator/unification/provider/UnificationOperatorServiceContextFunction.java b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/provider/UnificationOperatorServiceContextFunction.java new file mode 100644 index 0000000..0f926c7 --- /dev/null +++ b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/provider/UnificationOperatorServiceContextFunction.java @@ -0,0 +1,26 @@ +package flintstones.operator.unification.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.operator.unification.service.IUnificationOperatorService; + +public class UnificationOperatorServiceContextFunction extends ContextFunction { + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core. + * contexts.IEclipseContext, java.lang.String) */ + @Override + public Object compute(IEclipseContext context, String contextKey) { + IUnificationOperatorService service = ContextInjectionFactory.make(UnificationOperatorServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IUnificationOperatorService.class, service); + return service; + } + +} diff --git a/bundles/flintstones.operator.unification/src/flintstones/operator/unification/provider/UnificationOperatorServiceProvider.java b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/provider/UnificationOperatorServiceProvider.java new file mode 100644 index 0000000..af04a89 --- /dev/null +++ b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/provider/UnificationOperatorServiceProvider.java @@ -0,0 +1,115 @@ +package flintstones.operator.unification.provider; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; + +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.operator.unification.UnificationOperator; +import flintstones.operator.unification.exception.UnificationOperatorFinalValuationNotFound; +import flintstones.operator.unification.exception.UnificationOperatorNotImplemented; +import flintstones.operator.unification.service.IUnificationOperatorService; + +public class UnificationOperatorServiceProvider implements IUnificationOperatorService { + + /** The extension point. */ + private final String EXTENSION_POINT_UNIFICATION = "flintstones.operator.unification.extensionpoint"; //$NON-NLS-1$ + + /** The context. */ + @Inject + IEclipseContext context; + + /** The register. */ + private final BaseRegistry unificationReg; + + /** + * Instantiates a new unification operator service provider. + */ + public UnificationOperatorServiceProvider() { + this.unificationReg = new BaseRegistry(this.EXTENSION_POINT_UNIFICATION); + } + + /* + * (non-Javadoc) + * + * @see flintstones.operator.unification.service.IUnificationOperatorService# + * getAggregationOperator(java.lang.String) + */ + @Override + public UnificationOperator getUnificationOperator(String sourceValuation, String finalValuation, String methodId) { + + // The ER of the operator_type, allow us to find in its children the right + // implementation for the given valuations + + ExtensionRegistry[] registries = unificationReg.getAllRegistriesWhere("final_valuation_type", finalValuation); + + if (registries.length == 0) + throw new UnificationOperatorFinalValuationNotFound(finalValuation); + + // We need the registry of the unification operator to instance it + ExtensionRegistry selectedOperator = getUnificationOperator(registries, sourceValuation, finalValuation, methodId); + + if (selectedOperator == null) { + try { + throw new UnificationOperatorNotImplemented(sourceValuation, finalValuation); + } catch (UnificationOperatorNotImplemented e) { + System.err.println(e.getMessage()); + } + return null; + } + + UnificationOperator operator = (UnificationOperator) unificationReg.instantiate(selectedOperator, context); + operator.setId(selectedOperator.getAttribute(UnificationOperator.Fields.id)); + operator.setSourceValuationId(sourceValuation); + operator.setFinalValuationId(finalValuation); + + return operator; + } + + private ExtensionRegistry getUnificationOperator(ExtensionRegistry[] registries, String sourceValuation, String finalValuation, String methodId) { + List registriesByValuation = new ArrayList<>(); + + ExtensionRegistry selectedOperator = null; + + //Get unification operators with the same source and final valuation + for(ExtensionRegistry local: registries) { + for(ExtensionRegistry sourceRegistry: local.getAttributeReferences(UnificationOperator.Fields.source_valuation)) { + if(sourceRegistry.getAttribute(UnificationOperator.Fields.source_valuation_type).equals(sourceValuation)) + registriesByValuation.add(sourceRegistry); + } + } + + //Get the unification operator for a specific method if necessary + if(registriesByValuation.size() == 1) + selectedOperator = registriesByValuation.get(0);//Default unification operator + else { + String methodIdAttribute; + for(ExtensionRegistry local: registriesByValuation) { + methodIdAttribute = local.getAttribute(UnificationOperator.Fields.specific_method); + if(methodIdAttribute != null) { + if(methodIdAttribute.equals(methodId)) + selectedOperator = local;//Unification operator for specific domain + } else + selectedOperator = local;//Default unification operator + } + } + + return selectedOperator; + } + + @Override + public Valuation unify(Domain unificationDomain, Valuation valuation, String finalValuationType, String methodId) { + UnificationOperator operator = this.getUnificationOperator(valuation.getId(), finalValuationType, methodId); + Valuation result = operator.unify(unificationDomain, valuation); + result.setId(finalValuationType); + + return result; + } + +} diff --git a/bundles/flintstones.operator.unification/src/flintstones/operator/unification/service/IUnificationOperatorService.java b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/service/IUnificationOperatorService.java new file mode 100644 index 0000000..d8b7dfb --- /dev/null +++ b/bundles/flintstones.operator.unification/src/flintstones/operator/unification/service/IUnificationOperatorService.java @@ -0,0 +1,33 @@ +package flintstones.operator.unification.service; + +import flintstones.entity.domain.Domain; +import flintstones.entity.valuation.Valuation; +import flintstones.operator.unification.UnificationOperator; + +/** + * The Interface IUnificationOperatorService. + */ +public interface IUnificationOperatorService { + + /** + * Gets an unification operator for a specific method by the type of the source valuation and the type of the unified valuation. + * + * @param sourceValuationId id of source valuation + * @param finalValuationId id of valuation to unify + * @param methodId id of the method + * @return Instanced UnificationOperator + */ + UnificationOperator getUnificationOperator(String sourceValuationId, String finalValuationId, String methodId); + + /** + * Unify. + * + * @param unificationDomain unification domain + * @param valuation valuation to unify + * @param finalValuationId id of valuation to unify + * @param methodId id of the method + * @return Final unified valuation + */ + Valuation unify(Domain unificationDomain, Valuation valuation, String finalValuationId, String methodId); + +} diff --git a/bundles/flintstones.operator/.classpath b/bundles/flintstones.operator/.classpath new file mode 100644 index 0000000..f9c6884 --- /dev/null +++ b/bundles/flintstones.operator/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.operator/.polyglot.META-INF b/bundles/flintstones.operator/.polyglot.META-INF new file mode 100644 index 0000000..bca3022 --- /dev/null +++ b/bundles/flintstones.operator/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.operator + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] flintstones.operator + + Sinbad2 + + diff --git a/bundles/flintstones.operator/.project b/bundles/flintstones.operator/.project new file mode 100644 index 0000000..1e9d01d --- /dev/null +++ b/bundles/flintstones.operator/.project @@ -0,0 +1,50 @@ + + + flintstones.operator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362731 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.operator/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.operator/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.operator/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.operator/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.operator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.operator/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.operator/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.operator/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.operator/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.operator/META-INF/MANIFEST.MF b/bundles/flintstones.operator/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8334a7b --- /dev/null +++ b/bundles/flintstones.operator/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: flintstones.operator +Bundle-SymbolicName: flintstones.operator;singleton:=true +Bundle-Vendor: Sinbad2 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: flintstones.entity.valuation, + flintstones.model.valuation.service, + org.eclipse.e4.core.contexts, + org.eclipse.e4.core.di, + flintstones.helper.extensionpoint, + org.eclipse.e4.ui.model.workbench, + flintstones.entity.wvaluation, + flintstones.entity.extensionenum, + org.eclipse.e4.ui.services, + org.eclipse.swt, + javax.inject, + flintstones.model.ui.service, + flintstones.entity.operator, + flintstones.domain.fuzzyset +Export-Package: flintstones.operator.provider, + flintstones.operator.service +Automatic-Module-Name: flintstones.aggregationoperator +Service-Component: component.xml +Bundle-ActivationPolicy: lazy +Import-Package: org.eclipse.jface.dialogs, + org.eclipse.jface.wizard, + org.eclipse.swt +Bundle-Version: 1.0.0.qualifier diff --git a/bundles/flintstones.operator/build.properties b/bundles/flintstones.operator/build.properties new file mode 100644 index 0000000..516c952 --- /dev/null +++ b/bundles/flintstones.operator/build.properties @@ -0,0 +1,6 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + component.xml,\ + plugin.xml +source.. = src/ diff --git a/bundles/flintstones.operator/component.xml b/bundles/flintstones.operator/component.xml new file mode 100644 index 0000000..e262bb5 --- /dev/null +++ b/bundles/flintstones.operator/component.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/bundles/flintstones.operator/plugin.xml b/bundles/flintstones.operator/plugin.xml new file mode 100644 index 0000000..c8ea0cb --- /dev/null +++ b/bundles/flintstones.operator/plugin.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/bundles/flintstones.operator/schema/aggregation.operator.exsd b/bundles/flintstones.operator/schema/aggregation.operator.exsd new file mode 100644 index 0000000..c86ed46 --- /dev/null +++ b/bundles/flintstones.operator/schema/aggregation.operator.exsd @@ -0,0 +1,145 @@ + + + + + + + + + Este punto de extensión permite añadir nuevos operadores de agregación. Cada operador de agregación definido (aggregation_operator_type) podrá ser implementado para las distintas "valuation", para eso se agregarán al mismo aggregation_operator. + +Por ejemplo podremos añadir el aggregation_operator_type Max e implementarlo para el evaluaciones numéricas enteras y para evaluaciones de tipo lingüístico fuzzyset. + +============================================================================================================================================== + +This extension point allows you to add new aggregation operators. Each defined aggregation_operator_type can be implemented for the different valuation, for that they will be added to the same aggregation_operator. + +For example, we can add the aggregation_operator_type Max and implement it for entire numerical evaluations and for fuzzyset linguistic evaluations. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.operator/schema/normalization.operator.exsd b/bundles/flintstones.operator/schema/normalization.operator.exsd new file mode 100644 index 0000000..43fce1c --- /dev/null +++ b/bundles/flintstones.operator/schema/normalization.operator.exsd @@ -0,0 +1,127 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/bundles/flintstones.operator/src/flintstones/operator/exception/AggregationOperatorNotFound.java b/bundles/flintstones.operator/src/flintstones/operator/exception/AggregationOperatorNotFound.java new file mode 100644 index 0000000..9adf792 --- /dev/null +++ b/bundles/flintstones.operator/src/flintstones/operator/exception/AggregationOperatorNotFound.java @@ -0,0 +1,19 @@ +package flintstones.operator.exception; + +/** + * The Class AggregationOperatorNotFound. + */ +public class AggregationOperatorNotFound extends Error { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 3486693795198966709L; + + /** + * Instantiates a new aggregation operator not found. + * + * @param operatorId the operator id + */ + public AggregationOperatorNotFound(String operatorId) { + super("El operador con ID " + operatorId + " no se ha encontrado"); //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/bundles/flintstones.operator/src/flintstones/operator/exception/AggregationOperatorNotImplementedForValuation.java b/bundles/flintstones.operator/src/flintstones/operator/exception/AggregationOperatorNotImplementedForValuation.java new file mode 100644 index 0000000..084fe4e --- /dev/null +++ b/bundles/flintstones.operator/src/flintstones/operator/exception/AggregationOperatorNotImplementedForValuation.java @@ -0,0 +1,20 @@ +package flintstones.operator.exception; + +/** + * The Class AggregationOperatorNotImplementedForValuation. + */ +public class AggregationOperatorNotImplementedForValuation extends Exception { + + /** The Constant serialVersionUID. */ + private static final long serialVersionUID = 8029363988701450857L; + + /** + * Instantiates a new aggregation operator not implemented for valuation. + * + * @param operatorId the operator id + * @param valuationId the valuation id + */ + public AggregationOperatorNotImplementedForValuation(String operatorId, String valuationId) { + super("El operador con ID " + operatorId + " no tiene implementación para la evaluación " + valuationId + "." ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } +} diff --git a/bundles/flintstones.operator/src/flintstones/operator/exception/NormalizationOperatorIncompatible.java b/bundles/flintstones.operator/src/flintstones/operator/exception/NormalizationOperatorIncompatible.java new file mode 100644 index 0000000..3edc0f2 --- /dev/null +++ b/bundles/flintstones.operator/src/flintstones/operator/exception/NormalizationOperatorIncompatible.java @@ -0,0 +1,13 @@ +package flintstones.operator.exception; + +public class NormalizationOperatorIncompatible extends Error { + + /** + * + */ + private static final long serialVersionUID = 273710095661069675L; + + public NormalizationOperatorIncompatible(String operatorId, String valuationId){ + super("El operador con id " + operatorId + " no puede normalizar operaciones del tipo " + valuationId ); + } +} diff --git a/bundles/flintstones.operator/src/flintstones/operator/provider/OperatorServiceContextFunction.java b/bundles/flintstones.operator/src/flintstones/operator/provider/OperatorServiceContextFunction.java new file mode 100644 index 0000000..a3f6a8c --- /dev/null +++ b/bundles/flintstones.operator/src/flintstones/operator/provider/OperatorServiceContextFunction.java @@ -0,0 +1,28 @@ +package flintstones.operator.provider; + +import org.eclipse.e4.core.contexts.ContextFunction; +import org.eclipse.e4.core.contexts.ContextInjectionFactory; +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; + +import flintstones.operator.service.IOperatorService; + +/** + * The Class DomainServiceContextFunction add the Domain Service instance to global context. + */ +public class OperatorServiceContextFunction extends ContextFunction { + + /* (non-Javadoc) + * + * @see + * org.eclipse.e4.core.contexts.ContextFunction#compute(org.eclipse.e4.core. + * contexts.IEclipseContext, java.lang.String) */ + @Override + public Object compute(IEclipseContext context, String contextKey) { + IOperatorService service = ContextInjectionFactory.make(OperatorServiceProvider.class, context); + MApplication application = context.get(MApplication.class); + IEclipseContext applicationContext = application.getContext(); + applicationContext.set(IOperatorService.class, service); + return service; + } +} diff --git a/bundles/flintstones.operator/src/flintstones/operator/provider/OperatorServiceProvider.java b/bundles/flintstones.operator/src/flintstones/operator/provider/OperatorServiceProvider.java new file mode 100644 index 0000000..0264ed0 --- /dev/null +++ b/bundles/flintstones.operator/src/flintstones/operator/provider/OperatorServiceProvider.java @@ -0,0 +1,204 @@ +package flintstones.operator.provider; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.NormalizationOperator; +import flintstones.entity.operator.interfaces.IUnweightedAggregationOperator; +import flintstones.entity.operator.interfaces.IWeightedAggregationOperator; +import flintstones.entity.valuation.Valuation; +import flintstones.entity.wvaluation.WValuation; +import flintstones.helper.extensionpoint.BaseRegistry; +import flintstones.helper.extensionpoint.ExtensionRegistry; +import flintstones.operator.exception.AggregationOperatorNotFound; +import flintstones.operator.exception.AggregationOperatorNotImplementedForValuation; +import flintstones.operator.exception.NormalizationOperatorIncompatible; +import flintstones.operator.service.IOperatorService; + +/** + * The Class AggregationOperatorServiceProvider. + * + * @author Sinbad2 + * AggregationOperator Service. + */ +public class OperatorServiceProvider implements IOperatorService { + + /** The extension point. */ + private final String EXTENSION_POINT_AGGREGATION = "flintstones.operator.aggregation.extensionpoint"; //$NON-NLS-1$ + private final String EXTENSION_POINT_NORMALIZATION = "flintstones.operator.normalization"; //$NON-NLS-1$ + + /** The context. */ + @Inject + IEclipseContext context; + + /** The register. */ + private final BaseRegistry aggregationReg; + private final BaseRegistry normalizationReg; + + /** + * Instantiates a new aggregation operator service provider. + */ + public OperatorServiceProvider() { + this.aggregationReg = new BaseRegistry(this.EXTENSION_POINT_AGGREGATION); + this.normalizationReg = new BaseRegistry(this.EXTENSION_POINT_NORMALIZATION); + } + + /* (non-Javadoc) + * + * @see flintstones.operator.aggregation.service.IAggregationOperatorService# + * getAggregationOperator(java.lang.String) */ + @Override + public AggregationOperator getAggregationOperator(String operatorId, String valuationId) { + + // The ER of the operator_type, allow us to find in its children the right + // implementation for the given valuations + ExtensionRegistry typeEr = aggregationReg.getFirstRegistryWhere(AggregationOperator.Fields.uid, operatorId); + if(typeEr == null) + throw new AggregationOperatorNotFound(operatorId); + + // We need the registry of the aggregation_operator to instance it + ExtensionRegistry selectedOperator = null; + + + for (ExtensionRegistry local : typeEr.getAttributeReferences(AggregationOperator.Fields.aggregation_operator)) { + if (local.getAttribute(AggregationOperator.Fields.valuationId).equals(valuationId)) { + selectedOperator = local; + break; + } + } + + if(selectedOperator == null ) { + try { + throw new AggregationOperatorNotImplementedForValuation(operatorId, valuationId); + } catch(AggregationOperatorNotImplementedForValuation e) { + System.err.println(e.getMessage()); + } + return null; + } + + + AggregationOperator operator = (AggregationOperator) aggregationReg.instantiate(selectedOperator, context); + operator.setId(operatorId); + + return operator; + } + + /*@SuppressWarnings("unchecked") + @Override + public Valuation aggregate(String operatorId, List valuations, List weights) { + + String valuationId = valuations.get(0).getId(); + AggregationOperator operator = this.getAggregationOperator(operatorId, valuationId); + Valuation result; + + if ((operator instanceof IWeightedAggregationOperator || + operator instanceof IFuzzyWeightedAggregationOperator) + && weights != null) + + if(weights.get(0) instanceof Double) + result = ((IWeightedAggregationOperator) operator).aggregate(valuations, (List) weights); + else + result = ((IFuzzyWeightedAggregationOperator) operator).aggregateF(valuations, (List) weights); + + else + result = ((IUnweightedAggregationOperator) operator).aggregate(valuations); + + result.setId(valuationId); + + return result; + }*/ + + /*@Override + public Valuation aggregate(String operatorId, List valuations) { + return this.aggregate(operatorId, valuations, null); + }*/ + + @Override + public AggregationOperator[] getAggregationOperatorsFor(String valuationId, boolean importedWeights) { + ArrayList operators = new ArrayList<>(); + String[] operatorIds = aggregationReg.getAllAttributes(AggregationOperator.Fields.uid); + + for (String operatorId : operatorIds) { + AggregationOperator operator = getAggregationOperator(operatorId, valuationId); + if (operator != null) { + + if((operator instanceof IUnweightedAggregationOperator) || + (operator instanceof IWeightedAggregationOperator && importedWeights)) + operators.add(operator); + } + } + + return operators.toArray(new AggregationOperator[operators.size()]); + + } + + @Override + public NormalizationOperator getNormalizationOperator(String operatorId) { + NormalizationOperator op = (NormalizationOperator) this.normalizationReg.instantiate(operatorId, context); + op.setId(operatorId); + return op; + } + + @Override + public NormalizationOperator[] getNormalizationOperatorsFor(Valuation v) { + String valuationId = v.getId(); + + ArrayList operators = new ArrayList<>(); + for( ExtensionRegistry er : normalizationReg.getAllRegistries() ) { + ExtensionRegistry matchingValuationsEr[] = er.getAttributeReferences("matching_valuation"); + + for(ExtensionRegistry matchingValuation : matchingValuationsEr) { + if( matchingValuation.getAttribute("valuationId").equals(valuationId)) { + NormalizationOperator op = this.getNormalizationOperator(er.getAttribute("uid")); + operators.add(op); + continue; + } + } + } + + return operators.toArray(new NormalizationOperator[operators.size()]); + } + + + @Override + public WValuation[] normalize(String operatorId, List valuations) { + return this.normalize(operatorId, valuations, null); + } + + + @Override + public WValuation[] normalize(String operatorId, List valuations, List weights) { + + if(weights != null) + throw new RuntimeException("No es posible normalizar con pesos."); + + ExtensionRegistry er = this.normalizationReg.getFirstRegistryWhere("uid",operatorId); + String valuationId = valuations.get(0).getValuation().getId(); + if(!isMatchingValuation(er, valuationId)) { + throw new NormalizationOperatorIncompatible(operatorId, valuationId); + } + + NormalizationOperator op = this.getNormalizationOperator(er.getAttribute("uid")); + WValuation[] result = op.normalize(valuations); + + return result; + } + + private boolean isMatchingValuation(ExtensionRegistry normalizationOperatorRegistry, String valuationId) { + + ExtensionRegistry[] valuationRegistries = normalizationOperatorRegistry.getAttributeReferences("matching_valuation"); + for(ExtensionRegistry ex : valuationRegistries) { + if( ex.getAttribute("valuationId").equals(valuationId) ) { + return true; + } + } + return false; + } + + + +} diff --git a/bundles/flintstones.operator/src/flintstones/operator/service/IOperatorService.java b/bundles/flintstones.operator/src/flintstones/operator/service/IOperatorService.java new file mode 100644 index 0000000..6b147e0 --- /dev/null +++ b/bundles/flintstones.operator/src/flintstones/operator/service/IOperatorService.java @@ -0,0 +1,56 @@ +package flintstones.operator.service; + +import java.util.List; + +import flintstones.entity.operator.AggregationOperator; +import flintstones.entity.operator.NormalizationOperator; +import flintstones.entity.valuation.Valuation; +import flintstones.entity.wvaluation.WValuation; + +/** + * The Interface IAggregationOperatorService. + */ +public interface IOperatorService { + + /** + * Gets a aggregation operator by its id. + * + * @param operatorId the operator id + * @param valuationId the valuation id + * @return Instanced AggregationOperator + */ + AggregationOperator getAggregationOperator(String operatorId, String valuationId); + + /** + * Aggregate. + * + * @param operatorId the operator id + * @param valuations the valuations + * @return Final valuation + */ + //Valuation aggregate(String operatorId, List valuations); + + /** + * Aggregate. + * + * @param operatorId the operator id + * @param valuations the valuations + * @param weights the weights + * @return Final valuation + */ + //Valuation aggregate(String operatorId, List valuations, List weights); + + AggregationOperator[] getAggregationOperatorsFor(String valuationId, boolean weights); + + // NORMALIZATION + + WValuation[] normalize(String operatorId, List valuations); + + WValuation[] normalize(String operatorId, List valuations, List weights); + + NormalizationOperator getNormalizationOperator(String operatorId); + + NormalizationOperator[] getNormalizationOperatorsFor(Valuation v); + + +} diff --git a/bundles/flintstones.quantifiers.yager/.classpath b/bundles/flintstones.quantifiers.yager/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.quantifiers.yager/.polyglot.META-INF b/bundles/flintstones.quantifiers.yager/.polyglot.META-INF new file mode 100644 index 0000000..d9c6455 --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.quantifiers.yager + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Yager + diff --git a/bundles/flintstones.quantifiers.yager/.project b/bundles/flintstones.quantifiers.yager/.project new file mode 100644 index 0000000..5e07664 --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/.project @@ -0,0 +1,45 @@ + + + flintstones.quantifiers.yager + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362740 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.quantifiers.yager/META-INF/MANIFEST.MF b/bundles/flintstones.quantifiers.yager/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b8e35f6 --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Yager +Bundle-SymbolicName: flintstones.quantifiers.yager +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: flintstones.quantifiers.yager +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: flintstones.quantifiers.yager diff --git a/bundles/flintstones.quantifiers.yager/build.properties b/bundles/flintstones.quantifiers.yager/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.quantifiers.yager/src/flintstones/quantifiers/yager/YagerQuantifiers.java b/bundles/flintstones.quantifiers.yager/src/flintstones/quantifiers/yager/YagerQuantifiers.java new file mode 100644 index 0000000..d56af5e --- /dev/null +++ b/bundles/flintstones.quantifiers.yager/src/flintstones/quantifiers/yager/YagerQuantifiers.java @@ -0,0 +1,297 @@ +package flintstones.quantifiers.yager; + +@SuppressWarnings("javadoc") +public class YagerQuantifiers { + + public enum QuantificationType { + most("most"), at_least_half("at least half"), as_many_as_possible("as_many_as_possible"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private QuantificationType(String text) { + } + } + + public enum NumeredQuantificationType { + FilevYager("Filev-Yager"); //$NON-NLS-1$ + + private final String _text; + + private NumeredQuantificationType(String text) { + this._text = text; + } + + public String getText() { + return this._text; + } + } + + private static double RIM(double r, double alpha, double beta) { + + if (r <= alpha) + return 0; + else if (r > beta) + return 1; + else + return ((r - alpha) / (beta - alpha)); + } + + public static double[] Q(int numberOfValuations, double alpha, double beta) { + + double[] result = new double[numberOfValuations]; + + double value1 = -1; + double value2 = -1; + for (int i = 0; i < numberOfValuations; i++) { + if (value1 == -1) + value2 = (((double) i) / ((double) numberOfValuations)); + else + value2 = value1; + value1 = (((double) (i + 1)) / ((double) numberOfValuations)); + + result[i] = YagerQuantifiers.RIM(value1, alpha, beta) - YagerQuantifiers.RIM(value2, alpha, beta); + } + + return result; + } + + public static double[] QWeighted(NumeredQuantificationType type, int g, int[] envelope, Boolean lower) { + + double[] result = null; + + if (type == NumeredQuantificationType.FilevYager) { + int values; + double alpha; + if (lower == null) { // Between + if (envelope[0] == envelope[1]) { + result = new double[1]; + result[0] = 1; + } else if ((envelope[0] + envelope[1]) % 2 == 0) { + values = (envelope[1] - envelope[0] + 2) / 2; + result = new double[values]; + alpha = envelope[0] / g; + for (int i = 0; i < values; ++i) + if (i == 0) + result[i] = Math.pow(alpha, (envelope[1] - envelope[0] / 2d)); + else if (i == values - 1) + result[i] = 1 - alpha; + else + result[i] = (1 - alpha) * Math.pow(alpha, (envelope[1] - envelope[0] - (i + 1)) / 2d); + } else { + values = (envelope[1] - envelope[0] + 1) / 2; + result = new double[values]; + alpha = envelope[0] / g; + for (int i = 0; i < values; ++i) + if (i == 0) + result[i] = Math.pow(alpha, (envelope[1] - envelope[0] - 1 / 2d)); + else if (i == values - 1) + result[i] = 1 - alpha; + else + result[i] = (1 - alpha) * Math.pow(alpha, (envelope[1] - envelope[0] - (i + 2)) / 2d); + } + } else { + int aux; + + if (lower) {// At most and Lower than + values = envelope[1] + 1; + aux = values - 1; + + result = new double[values]; + alpha = (((double) values) - 1) / g; + + for (int i = 0; i <= aux; i++) + if (i == aux) + result[i] = Math.pow(1d - alpha, i); + else + result[i] = alpha * Math.pow(1d - alpha, i); + + } else { // At least and Greater than + values = (envelope[1] - envelope[0]) + 1; + aux = values - 1; + + result = new double[values]; + alpha = ((double) envelope[0]) / g; + + for (int i = 0; i <= aux; i++) + if (i == 0) + result[i] = Math.pow(alpha, g - envelope[0]); + else + result[i] = (1d - alpha) * Math.pow(alpha, g - envelope[0] - i); + } + } + } + return result; + } + + public static double[] QWeigthedBinaryRelation(NumeredQuantificationType type, int g, int[] envelope, Boolean pointB, Double alpha) { + double[] result = null; + + if (type == NumeredQuantificationType.FilevYager) { + if (envelope[0] == envelope[1]) { + result = new double[1]; + result[0] = 1; + } else { + if(pointB) { + return QWeightedBetweenPointB(g, envelope, alpha); + } else { + return QWeightedBetweenPointC(g, envelope, alpha); + } + } + } + return result; + } + + public static double[] QWeightedBetweenPointB(int g, int[] envelope, Double alpha) { + double[] result = null; + int values; + + if (envelope[0] == envelope[1]) { + result = new double[1]; + result[0] = 1; + } else { + if((envelope[0] + envelope[1]) % 2 == 0) { + values = (envelope[1] - envelope[0] + 2) / 2; + result = new double[values]; + alpha = (alpha == null) ? envelope[0] / g : alpha; + for(int i = 0; i < values; ++i) { + if(i == 0) { + result[i] = Math.pow(alpha, (envelope[1] - envelope[0] / 2d)); + } else if(i == values - 1) { + result[i] = 1 - alpha; + } else { + result[i] = (1 - alpha) * Math.pow(alpha, (envelope[1] - envelope[0] - (i + 1)) / 2d); + } + } + } else { + values = (envelope[1] - envelope[0] + 1) / 2; + result = new double[values]; + alpha = (alpha == null) ? envelope[0] / g : alpha; + for(int i = 0; i < values; ++i) { + if(i == 0) { + result[i] = Math.pow(alpha, (envelope[1] - envelope[0] - 1 / 2d)); + } else if(i == values - 1) { + result[i] = 1 - alpha; + } else { + result[i] = (1 - alpha) * Math.pow(alpha, (envelope[1] - envelope[0] - (i + 2)) / 2d); + } + } + } + } + + return result; + } + + public static double[] QWeightedBetweenPointC(int g, int[] envelope, Double alpha) { + double[] result = null; + int values; + double alpha2; + + if (envelope[0] == envelope[1]) { + result = new double[1]; + result[0] = 1; + } else { + if((envelope[0] + envelope[1]) % 2 == 0) { + values = (envelope[1] - envelope[0] + 2) / 2; + result = new double[values]; + alpha2 = (alpha == null) ? (g - envelope[0]) / g : alpha; + + for(int i = 0; i < values; ++i) { + if(i == 0) { + result[i] = alpha2; + } else if(i == values - 1) { + result[i] = Math.pow(1 - alpha2, (envelope[1] - envelope[0]) / 2d); + } else { + result[i] = alpha2 * Math.pow(1d - alpha2, (envelope[1] - envelope[0] - (i + 1)) / 2d); + } + } + } else { + values = (envelope[1] - envelope[0] + 1) / 2; + result = new double[values]; + alpha2 = (alpha == null) ? (g - envelope[0]) / g : alpha; + + for(int i = 0; i < values; ++i) { + if(i == 0) { + result[i] = alpha2; + } else if(i == values - 1) { + result[i] = Math.pow(1d - alpha2, (envelope[1] - envelope[0] - 1d) / 2d); + } else { + result[i] = (alpha2) * Math.pow(1d - alpha2, (envelope[1] - envelope[0] - (i + 2)) / 2d); + } + } + } + } + + return result; + } + + public static double[] QWeigthedUnaryRelation(NumeredQuantificationType type, int g, int[] envelope, Boolean atMost, Double alpha) { + + double[] result = null; + + int aux, values; + + if(atMost) {//At most and Lower than + values = envelope[1] + 1; + aux = values - 1; + + result = new double[values]; + alpha = (alpha == null) ? (((double) values) - 1) / g : alpha; + + for (int i = 0; i <= aux; i++) { + if (i == aux) { + result[i] = Math.pow(1d - alpha, i); + } else { + result[i] = alpha * Math.pow(1d - alpha, i); + } + } + } else { //At least and Greater than + values = (envelope[1] - envelope[0]) + 1; + aux = values - 1; + + result = new double[values]; + alpha = (alpha == null) ? ((double) envelope[0]) / g : alpha; + + for (int i = 0; i <= aux; i++) { + if (i == 0) { + result[i] = Math.pow(alpha, g - envelope[0]); + } else { + result[i] = (1d - alpha) * Math.pow(alpha, g - envelope[0] - i); + } + } + } + + return result; + } + + + public static double[] Quantification(QuantificationType type, int numberOfValuations) { + + switch (type) { + case most: + return YagerQuantifiers.Q(numberOfValuations, 0.3, 0.8); + + case at_least_half: + return YagerQuantifiers.Q(numberOfValuations, 0, 0.5); + + case as_many_as_possible: + return YagerQuantifiers.Q(numberOfValuations, 0.5, 1); + + default: + return null; + } + } + + public static double[] getQuantificationParams(QuantificationType type) { + switch (type) { + case most: + return new double[] { 0.3, 0.8 }; + + case at_least_half: + return new double[] { 0, 0.5 }; + + case as_many_as_possible: + return new double[] { 0.5, 1 }; + + default: + return null; + } + } +} diff --git a/bundles/flintstones.theme/.classpath b/bundles/flintstones.theme/.classpath new file mode 100644 index 0000000..b862a29 --- /dev/null +++ b/bundles/flintstones.theme/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.theme/.polyglot.META-INF b/bundles/flintstones.theme/.polyglot.META-INF new file mode 100644 index 0000000..602e743 --- /dev/null +++ b/bundles/flintstones.theme/.polyglot.META-INF @@ -0,0 +1,17 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.theme + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Theme + + Sinbad2 + + diff --git a/bundles/flintstones.theme/.project b/bundles/flintstones.theme/.project new file mode 100644 index 0000000..f736877 --- /dev/null +++ b/bundles/flintstones.theme/.project @@ -0,0 +1,45 @@ + + + flintstones.theme + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362742 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.theme/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.theme/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.theme/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.theme/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.theme/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..295926d --- /dev/null +++ b/bundles/flintstones.theme/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.theme/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.theme/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.theme/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.theme/META-INF/MANIFEST.MF b/bundles/flintstones.theme/META-INF/MANIFEST.MF new file mode 100644 index 0000000..22dddbf --- /dev/null +++ b/bundles/flintstones.theme/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Theme +Bundle-SymbolicName: flintstones.theme;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Sinbad2 +Automatic-Module-Name: flintstones.theme +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.e4.ui.css.swt.theme diff --git a/bundles/flintstones.theme/build.properties b/bundles/flintstones.theme/build.properties new file mode 100644 index 0000000..bbf6189 --- /dev/null +++ b/bundles/flintstones.theme/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + css/ diff --git a/bundles/flintstones.theme/css/blue.css b/bundles/flintstones.theme/css/blue.css new file mode 100644 index 0000000..d1df9c6 --- /dev/null +++ b/bundles/flintstones.theme/css/blue.css @@ -0,0 +1,70 @@ +Label { + font-size: 10px; + font-family: BBAWLibertine; /*FreeSerif;*/ + color: black; +} + +Composite Label { + color: black; +} + +#SeparatorLabel { + color: #1d659f; +} + +Text { + font: Verdana 8px; +} + +Composite Text { + background-color: white; + color: black; +} + + +SashForm { + background-color: #c1d5ef; +} + + + +Table { + background-color: #e3efff #c1d5ef 60%; + color: black; + font-size: 10px; + font-family: BBAWLibertine; /*FreeSerif;*/ +} + +.MTrimBar { + background-color: #e3efff #c1d5ef; + color: white; + font-size: 10px; + font-family: BBAWLibertine; /*FreeSerif;*/ +} + +ETabFolder { + simple: true; +} + +CTabItem { + color: black; + font-size: 10px; + font-family: BBAWLibertine; /*FreeSerif;*/ +} + +CTabItem:selected { + background-color: #e3efff #c1d5ef 60%; + font-weight: normal; + font-size: 10px; + font-family: BBAWLibertine; /*FreeSerif;*/ +} + +CTabItem.active:selected { + background-color: #e3efff #c1d5ef 50%; + color: #1d659f; + font: bold; +} + +Shell { + background-color: #e3efff #c1d5ef 60%; +} \ No newline at end of file diff --git a/bundles/flintstones.theme/css/default.css b/bundles/flintstones.theme/css/default.css new file mode 100644 index 0000000..e69de29 diff --git a/bundles/flintstones.theme/css/grey.css b/bundles/flintstones.theme/css/grey.css new file mode 100644 index 0000000..15008c2 --- /dev/null +++ b/bundles/flintstones.theme/css/grey.css @@ -0,0 +1,158 @@ +.MPart.busy { + font-style: italic; +} + +.MPart.highlighted { + font-weight: bold; +} + +* { + font-size: 10px; + font-family: BBAWLibertine; /*FreeSerif;*/ +} + +CTabItem:selected { +// color: '#org-eclipse-ui-workbench-ACTIVE_TAB_TEXT_COLOR'; +} + +.MTrimmedWindow { + margin-top: 0px; + margin-bottom: 0px; + margin-left: 2px; + margin-right: 2px; +} + +.MPartStack { +// swt-tab-renderer: url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering'); +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_START' '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_END' 100%; + swt-simple: false; + swt-mru-visible: true; +// color: '#org-eclipse-ui-workbench-INACTIVE_TAB_TEXT_COLOR'; +} + +.MPartStack.active { +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_START' '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_END' 100%; +} + +.MPartStack.active.noFocus { +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_START' '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_END' 100%; +} + +.MPartStack.active.noFocus > CTabItem:selected { +// color: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_TEXT_COLOR'; +} + +#PerspectiveSwitcher { + eclipse-perspective-keyline-color: #ECE9D8 #FFFFFF; +} + +.MToolControl.TrimStack { +// frame-image: url(./winClassicTSFrame.png); +// handle-image: url(./winClassicHandle.png); + frame-cuts: 5px 1px 5px 16px; +} + +.MToolBar.Draggable { +// handle-image: url(./dragHandle.png); +} + +.MToolControl.Draggable { +// handle-image: url(./dragHandle.png); +} + +.DragFeedback { + background-color: COLOR-WIDGET-NORMAL-SHADOW; +} + +.ModifiedDragFeedback { + background-color: #A0A000; +} + +#org-eclipse-ui-editorss { + swt-tab-height: 8px; +} +//ScrolledComposite { +// background-color: #FFFFFF; +//} +// +//Group { +// background-color: #FFFFFF; +//} +// +//PassportEntryItemEditor { +// background-color: #FFFFFF; +//} +//PassportEntryGroupEditor { +// background-color: #FFFFFF; +//} +// +//Label { +// background-color: #FFFFFF; +// +//} +//TableItem { +// font-family: BBAWLibertine; +// font-size: 12px; +//} +//Table{ +// font-family: BBAWLibertine; +// font-size: 12px; +//} + +//Button { +// background-color: #FFFFFF; +//} + +//* { +// font-size: 10px; +// font-family: BBAWLibertine; /*FreeSerif;*/ +// +//} +//Text { +// background-color: #FFFFFF; +//} +//Link { +// background-color: #FFFFFF; +// +//} + +/*MTrimBar { + background-color: rgb(245, 243, 237); +} +MToolBar { + background-color: rgb(245, 243, 237); +} + +MToolItem { + background-color: rgb(245, 243, 237); +} +CorpusToolControl { + background-color: rgb(245, 243, 237); +} +ProjectToolControl { + background-color: rgb(245, 243, 237); +} +UserToolcontrol { + background-color: rgb(245, 243, 237); +} + +*/ +/* for AnnotationPart RelatedObjectGroup*/ +.unselected { + background-color: #FFFFFF; +} + +.selected { + background-color: #E6E3C3; +} + +/*RelatedObjectGroup.selected { + background-color: #E6E3C3; +} + +*/ + +// STE background +.SignTextCanvas { + background-color: COLOR-WHITE; +} \ No newline at end of file diff --git a/bundles/flintstones.theme/css/grey_big.css b/bundles/flintstones.theme/css/grey_big.css new file mode 100644 index 0000000..7deea93 --- /dev/null +++ b/bundles/flintstones.theme/css/grey_big.css @@ -0,0 +1,158 @@ +.MPart.busy { + font-style: italic; +} + +.MPart.highlighted { + font-weight: bold; +} + +* { + font-size: 12px; + font-family: BBAWLibertine; /*FreeSerif;*/ +} + +CTabItem:selected { +// color: '#org-eclipse-ui-workbench-ACTIVE_TAB_TEXT_COLOR'; +} + +.MTrimmedWindow { + margin-top: 0px; + margin-bottom: 0px; + margin-left: 2px; + margin-right: 2px; +} + +.MPartStack { +// swt-tab-renderer: url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering'); +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_START' '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_END' 100%; + swt-simple: false; + swt-mru-visible: true; +// color: '#org-eclipse-ui-workbench-INACTIVE_TAB_TEXT_COLOR'; +} + +.MPartStack.active { +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_START' '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_END' 100%; +} + +.MPartStack.active.noFocus { +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_START' '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_END' 100%; +} + +.MPartStack.active.noFocus > CTabItem:selected { +// color: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_TEXT_COLOR'; +} + +#PerspectiveSwitcher { + eclipse-perspective-keyline-color: #ECE9D8 #FFFFFF; +} + +.MToolControl.TrimStack { +// frame-image: url(./winClassicTSFrame.png); +// handle-image: url(./winClassicHandle.png); + frame-cuts: 5px 1px 5px 16px; +} + +.MToolBar.Draggable { +// handle-image: url(./dragHandle.png); +} + +.MToolControl.Draggable { +// handle-image: url(./dragHandle.png); +} + +.DragFeedback { + background-color: COLOR-WIDGET-NORMAL-SHADOW; +} + +.ModifiedDragFeedback { + background-color: #A0A000; +} + +#org-eclipse-ui-editorss { + swt-tab-height: 8px; +} +//ScrolledComposite { +// background-color: #FFFFFF; +//} +// +//Group { +// background-color: #FFFFFF; +//} +// +//PassportEntryItemEditor { +// background-color: #FFFFFF; +//} +//PassportEntryGroupEditor { +// background-color: #FFFFFF; +//} +// +//Label { +// background-color: #FFFFFF; +// +//} +//TableItem { +// font-family: BBAWLibertine; +// font-size: 12px; +//} +//Table{ +// font-family: BBAWLibertine; +// font-size: 12px; +//} + +//Button { +// background-color: #FFFFFF; +//} + +//* { +// font-size: 10px; +// font-family: BBAWLibertine; /*FreeSerif;*/ +// +//} +//Text { +// background-color: #FFFFFF; +//} +//Link { +// background-color: #FFFFFF; +// +//} + +/*MTrimBar { + background-color: rgb(245, 243, 237); +} +MToolBar { + background-color: rgb(245, 243, 237); +} + +MToolItem { + background-color: rgb(245, 243, 237); +} +CorpusToolControl { + background-color: rgb(245, 243, 237); +} +ProjectToolControl { + background-color: rgb(245, 243, 237); +} +UserToolcontrol { + background-color: rgb(245, 243, 237); +} + +*/ +/* for AnnotationPart RelatedObjectGroup*/ +.unselected { + background-color: #FFFFFF; +} + +.selected { + background-color: #E6E3C3; +} + +/*RelatedObjectGroup.selected { + background-color: #E6E3C3; +} + +*/ + +// STE background +.SignTextCanvas { + background-color: COLOR-WHITE; +} \ No newline at end of file diff --git a/bundles/flintstones.theme/css/grey_extra_big.css b/bundles/flintstones.theme/css/grey_extra_big.css new file mode 100644 index 0000000..2cab227 --- /dev/null +++ b/bundles/flintstones.theme/css/grey_extra_big.css @@ -0,0 +1,159 @@ +.MPart.busy { + font-style: italic; +} + +.MPart.highlighted { + font-weight: bold; +} + +* { + font-size: 14px; + font-family: BBAWLibertine; /*FreeSerif;*/ +} + +CTabItem:selected { +// color: '#org-eclipse-ui-workbench-ACTIVE_TAB_TEXT_COLOR'; +} + +.MTrimmedWindow { + margin-top: 0px; + margin-bottom: 0px; + margin-left: 2px; + margin-right: 2px; +} + +.MPartStack { +// swt-tab-renderer: url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering'); +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_START' '#org-eclipse-ui-workbench-INACTIVE_TAB_BG_END' 100%; + swt-simple: false; + swt-mru-visible: true; +// color: '#org-eclipse-ui-workbench-INACTIVE_TAB_TEXT_COLOR'; +} + +.MPartStack.active { +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_START' '#org-eclipse-ui-workbench-ACTIVE_TAB_BG_END' 100%; +} + +.MPartStack.active.noFocus { +// swt-selected-tabs-background: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_START' '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_BG_END' 100%; +} + +.MPartStack.active.noFocus > CTabItem:selected { +// color: '#org-eclipse-ui-workbench-ACTIVE_NOFOCUS_TAB_TEXT_COLOR'; +} + +#PerspectiveSwitcher { + eclipse-perspective-keyline-color: #ECE9D8 #FFFFFF; +} + +.MToolControl.TrimStack { +// frame-image: url(./winClassicTSFrame.png); +// handle-image: url(./winClassicHandle.png); + frame-cuts: 5px 1px 5px 16px; +} + +.MToolBar.Draggable { +// handle-image: url(./dragHandle.png); +} + +.MToolControl.Draggable { +// handle-image: url(./dragHandle.png); +} + +.DragFeedback { + background-color: COLOR-WIDGET-NORMAL-SHADOW; +} + +.ModifiedDragFeedback { + background-color: #A0A000; +} + +#org-eclipse-ui-editorss { + swt-tab-height: 8px; +} +//ScrolledComposite { +// background-color: #FFFFFF; +//} +// +//Group { +// background-color: #FFFFFF; +//} +// +//PassportEntryItemEditor { +// background-color: #FFFFFF; +//} +//PassportEntryGroupEditor { +// background-color: #FFFFFF; +//} +// +//Label { +// background-color: #FFFFFF; +// +//} +//TableItem { +// font-family: BBAWLibertine; +// font-size: 12px; +//} +//Table{ +// font-family: BBAWLibertine; +// font-size: 12px; +//} + +//Button { +// background-color: #FFFFFF; +//} + +//* { +// font-size: 10px; +// font-family: BBAWLibertine; /*FreeSerif;*/ +// +//} +//Text { +// background-color: #FFFFFF; +//} +//Link { +// background-color: #FFFFFF; +// +//} + +/*MTrimBar { + background-color: rgb(245, 243, 237); +} +MToolBar { + background-color: rgb(245, 243, 237); +} + +MToolItem { + background-color: rgb(245, 243, 237); +} +CorpusToolControl { + background-color: rgb(245, 243, 237); +} +ProjectToolControl { + background-color: rgb(245, 243, 237); +} +UserToolcontrol { + background-color: rgb(245, 243, 237); +} + +*/ +/* for AnnotationPart RelatedObjectGroup*/ +.unselected { + background-color: #FFFFFF; +} + +.selected { + background-color: #E6E3C3; +} + +/*RelatedObjectGroup.selected { + background-color: #E6E3C3; +} + +*/ + + +// STE background +.SignTextCanvas { + background-color: COLOR-WHITE; +} \ No newline at end of file diff --git a/bundles/flintstones.theme/css/olive.css b/bundles/flintstones.theme/css/olive.css new file mode 100644 index 0000000..4444cdb --- /dev/null +++ b/bundles/flintstones.theme/css/olive.css @@ -0,0 +1,157 @@ +.MTrimmedWindow { + margin-top: 2px; + margin-bottom: 2px; + margin-left: 2px; + margin-right: 2px; +} + +.MTrimmedWindow.topLevel { + margin-top: 24px; + margin-bottom: 2px; + margin-left: 12px; + margin-right: 12px; +} + +.MPartStack { + swt-unselected-tabs-color: #FFFFFF #FFFFFF #FFFFFF 100% 100%; + swt-outer-keyline-color: #FFFFFF; + swt-inner-keyline-color: #FFFFFF; + font-size: 10; + swt-simple: false; + padding: 0px 10px 11px; + swt-mru-visible: false; + + swt-shadow-visible: true; + swt-shadow-color: #EDEACA; +} + + +Shell { + background-color: #F5F3ED #F0ECE0 30%; +} +.MPartStack.active { + swt-unselected-tabs-color: #E6E3C3 #EDEACA #FFFFFF 100% 100%; + swt-outer-keyline-color: #BFCDA4; + swt-inner-keyline-color: #FFFFFF; + swt-tab-outline: #B6BCCC; +} + +MPartStack.Composite { + swt-unselected-tabs-color: #E6E3C3 #EDEACA #FFFFFF 100% 100%; + swt-outer-keyline-color: #BFCDA4; + swt-inner-keyline-color: #FFFFFF; + swt-tab-outline: #B6BCCC; +} + +#PerspectiveSwitcher { + background-color: #F5F3ED #F0ECE0 100%; + eclipse-perspective-keyline-color: #A7B680 #A7B680; +} + +CTabFolder { + swt-selected-tabs-background: red; + swt-outer-keyline-color: red; +} +CTabItem:selected { + background-color: #E6E3C3; +} + +CTabItem { + font-style: normal; + font-weight: normal; +} + +CTabItem.busy { + font-style: italic; +} + +CTabItem.highlighted { + font-weight: bold; +} +Composite { + background-color: #FFFFFF; +} +ScrolledComposite { + background-color: #FFFFFF; +} + +Group { + background-color: #FFFFFF; +} + +PassportEntryItemEditor { + background-color: #FFFFFF; +} +PassportEntryGroupEditor { + background-color: #FFFFFF; +} + +Label { + background-color: #FFFFFF; + +} +TableItem { + font-family: BBAWLibertine; + font-size: 12px; +} +Table{ + font-family: BBAWLibertine; + font-size: 12px; +} + +Button { + background-color: #FFFFFF; +} + +* { + font-size: 10px; + font-family: BBAWLibertine; /*FreeSerif;*/ + +} +Text { + background-color: #FFFFFF; +} +Link { + background-color: #FFFFFF; + +} + +MTrimBar { + background-color: rgb(245, 243, 237); +} +MToolBar { + background-color: rgb(245, 243, 237); +} + +MToolItem { + background-color: rgb(245, 243, 237); +} +CorpusToolControl { + background-color: rgb(245, 243, 237); +} +ProjectToolControl { + background-color: rgb(245, 243, 237); +} +UserToolcontrol { + background-color: rgb(245, 243, 237); +} + + +/* for AnnotationPart RelatedObjectGroup*/ +.unselected { + background-color: #FFFFFF; +} + +.selected { + background-color: #E6E3C3; +} + +RelatedObjectGroup.selected { + background-color: #E6E3C3; +} + + +// STE background +.SignTextCanvas { + background-color: COLOR-WHITE; +} \ No newline at end of file diff --git a/bundles/flintstones.theme/css/olive_big.css b/bundles/flintstones.theme/css/olive_big.css new file mode 100644 index 0000000..b87fff6 --- /dev/null +++ b/bundles/flintstones.theme/css/olive_big.css @@ -0,0 +1,157 @@ +.MTrimmedWindow { + margin-top: 2px; + margin-bottom: 2px; + margin-left: 2px; + margin-right: 2px; +} + +.MTrimmedWindow.topLevel { + margin-top: 24px; + margin-bottom: 2px; + margin-left: 12px; + margin-right: 12px; +} + +.MPartStack { + swt-unselected-tabs-color: #FFFFFF #FFFFFF #FFFFFF 100% 100%; + swt-outer-keyline-color: #FFFFFF; + swt-inner-keyline-color: #FFFFFF; + font-size: 10; + swt-simple: false; + padding: 0px 10px 11px; + swt-mru-visible: false; + + swt-shadow-visible: true; + swt-shadow-color: #EDEACA; +} + + +Shell { + background-color: #F5F3ED #F0ECE0 30%; +} +.MPartStack.active { + swt-unselected-tabs-color: #E6E3C3 #EDEACA #FFFFFF 100% 100%; + swt-outer-keyline-color: #BFCDA4; + swt-inner-keyline-color: #FFFFFF; + swt-tab-outline: #B6BCCC; +} + +MPartStack.Composite { + swt-unselected-tabs-color: #E6E3C3 #EDEACA #FFFFFF 100% 100%; + swt-outer-keyline-color: #BFCDA4; + swt-inner-keyline-color: #FFFFFF; + swt-tab-outline: #B6BCCC; +} + +#PerspectiveSwitcher { + background-color: #F5F3ED #F0ECE0 100%; + eclipse-perspective-keyline-color: #A7B680 #A7B680; +} + +CTabFolder { + swt-selected-tabs-background: red; + swt-outer-keyline-color: red; +} +CTabItem:selected { + background-color: #E6E3C3; +} + +CTabItem { + font-style: normal; + font-weight: normal; +} + +CTabItem.busy { + font-style: italic; +} + +CTabItem.highlighted { + font-weight: bold; +} +Composite { + background-color: #FFFFFF; +} +ScrolledComposite { + background-color: #FFFFFF; +} + +Group { + background-color: #FFFFFF; +} + +PassportEntryItemEditor { + background-color: #FFFFFF; +} +PassportEntryGroupEditor { + background-color: #FFFFFF; +} + +Label { + background-color: #FFFFFF; + +} +TableItem { + font-family: BBAWLibertine; + font-size: 12px; +} +Table{ + font-family: BBAWLibertine; + font-size: 12px; +} + +Button { + background-color: #FFFFFF; +} + +* { + font-size: 12px; + font-family: BBAWLibertine; /*FreeSerif;*/ + +} +Text { + background-color: #FFFFFF; +} +Link { + background-color: #FFFFFF; + +} + +MTrimBar { + background-color: rgb(245, 243, 237); +} +MToolBar { + background-color: rgb(245, 243, 237); +} + +MToolItem { + background-color: rgb(245, 243, 237); +} +CorpusToolControl { + background-color: rgb(245, 243, 237); +} +ProjectToolControl { + background-color: rgb(245, 243, 237); +} +UserToolcontrol { + background-color: rgb(245, 243, 237); +} + + +/* for AnnotationPart RelatedObjectGroup*/ +.unselected { + background-color: #FFFFFF; +} + +.selected { + background-color: #E6E3C3; +} + +RelatedObjectGroup.selected { + background-color: #E6E3C3; +} + + +// STE background +.SignTextCanvas { + background-color: COLOR-WHITE; +} \ No newline at end of file diff --git a/bundles/flintstones.theme/css/olive_extra_big.css b/bundles/flintstones.theme/css/olive_extra_big.css new file mode 100644 index 0000000..c1909c1 --- /dev/null +++ b/bundles/flintstones.theme/css/olive_extra_big.css @@ -0,0 +1,157 @@ +.MTrimmedWindow { + margin-top: 2px; + margin-bottom: 2px; + margin-left: 2px; + margin-right: 2px; +} + +.MTrimmedWindow.topLevel { + margin-top: 24px; + margin-bottom: 2px; + margin-left: 12px; + margin-right: 12px; +} + +.MPartStack { + swt-unselected-tabs-color: #FFFFFF #FFFFFF #FFFFFF 100% 100%; + swt-outer-keyline-color: #FFFFFF; + swt-inner-keyline-color: #FFFFFF; + font-size: 10; + swt-simple: false; + padding: 0px 10px 11px; + swt-mru-visible: false; + + swt-shadow-visible: true; + swt-shadow-color: #EDEACA; +} + + +Shell { + background-color: #F5F3ED #F0ECE0 30%; +} +.MPartStack.active { + swt-unselected-tabs-color: #E6E3C3 #EDEACA #FFFFFF 100% 100%; + swt-outer-keyline-color: #BFCDA4; + swt-inner-keyline-color: #FFFFFF; + swt-tab-outline: #B6BCCC; +} + +MPartStack.Composite { + swt-unselected-tabs-color: #E6E3C3 #EDEACA #FFFFFF 100% 100%; + swt-outer-keyline-color: #BFCDA4; + swt-inner-keyline-color: #FFFFFF; + swt-tab-outline: #B6BCCC; +} + +#PerspectiveSwitcher { + background-color: #F5F3ED #F0ECE0 100%; + eclipse-perspective-keyline-color: #A7B680 #A7B680; +} + +CTabFolder { + swt-selected-tabs-background: red; + swt-outer-keyline-color: red; +} +CTabItem:selected { + background-color: #E6E3C3; +} + +CTabItem { + font-style: normal; + font-weight: normal; +} + +CTabItem.busy { + font-style: italic; +} + +CTabItem.highlighted { + font-weight: bold; +} +Composite { + background-color: #FFFFFF; +} +ScrolledComposite { + background-color: #FFFFFF; +} + +Group { + background-color: #FFFFFF; +} + +PassportEntryItemEditor { + background-color: #FFFFFF; +} +PassportEntryGroupEditor { + background-color: #FFFFFF; +} + +Label { + background-color: #FFFFFF; + +} +TableItem { + font-family: BBAWLibertine; + font-size: 12px; +} +Table{ + font-family: BBAWLibertine; + font-size: 12px; +} + +Button { + background-color: #FFFFFF; +} + +* { + font-size: 14px; + font-family: BBAWLibertine; /*FreeSerif;*/ + +} +Text { + background-color: #FFFFFF; +} +Link { + background-color: #FFFFFF; + +} + +MTrimBar { + background-color: rgb(245, 243, 237); +} +MToolBar { + background-color: rgb(245, 243, 237); +} + +MToolItem { + background-color: rgb(245, 243, 237); +} +CorpusToolControl { + background-color: rgb(245, 243, 237); +} +ProjectToolControl { + background-color: rgb(245, 243, 237); +} +UserToolcontrol { + background-color: rgb(245, 243, 237); +} + + +/* for AnnotationPart RelatedObjectGroup*/ +.unselected { + background-color: #FFFFFF; +} + +.selected { + background-color: #E6E3C3; +} + +RelatedObjectGroup.selected { + background-color: #E6E3C3; +} + + +// STE background +.SignTextCanvas { + background-color: COLOR-WHITE; +} \ No newline at end of file diff --git a/bundles/flintstones.theme/plugin.xml b/bundles/flintstones.theme/plugin.xml new file mode 100644 index 0000000..4995107 --- /dev/null +++ b/bundles/flintstones.theme/plugin.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/bundles/flintstones.theme/src/flintstones/theme/NoBorrar.java b/bundles/flintstones.theme/src/flintstones/theme/NoBorrar.java new file mode 100644 index 0000000..b5d943e --- /dev/null +++ b/bundles/flintstones.theme/src/flintstones/theme/NoBorrar.java @@ -0,0 +1,5 @@ +package flintstones.theme; + +public class NoBorrar { + +} diff --git a/bundles/flintstones.valuation.ahp.ui/.classpath b/bundles/flintstones.valuation.ahp.ui/.classpath new file mode 100644 index 0000000..eca7bdb --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/flintstones.valuation.ahp.ui/.polyglot.META-INF b/bundles/flintstones.valuation.ahp.ui/.polyglot.META-INF new file mode 100644 index 0000000..b496478 --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/.polyglot.META-INF @@ -0,0 +1,14 @@ + + + 4.0.0 + + flintstones.group + flintstones.bundles + 1.0.0-SNAPSHOT + + flintstones.valuation.ahp.ui + 1.0.0-SNAPSHOT + eclipse-plugin + [bundle] Ui + diff --git a/bundles/flintstones.valuation.ahp.ui/.project b/bundles/flintstones.valuation.ahp.ui/.project new file mode 100644 index 0000000..0529468 --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/.project @@ -0,0 +1,45 @@ + + + flintstones.valuation.ahp.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1779484362744 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.core.resources.prefs b/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.m2e.core.prefs b/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/bundles/flintstones.valuation.ahp.ui/META-INF/MANIFEST.MF b/bundles/flintstones.valuation.ahp.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000..dd6890f --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/flintstones.valuation.ahp.ui/build.properties b/bundles/flintstones.valuation.ahp.ui/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/bundles/flintstones.valuation.ahp.ui/src/flintstones/valuation/ahp/ui/AHPValuationPanel.java b/bundles/flintstones.valuation.ahp.ui/src/flintstones/valuation/ahp/ui/AHPValuationPanel.java new file mode 100644 index 0000000..1830372 --- /dev/null +++ b/bundles/flintstones.valuation.ahp.ui/src/flintstones/valuation/ahp/ui/AHPValuationPanel.java @@ -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>> buttons = new HashMap<>(); + + /** The button click listener. */ + IAHPValuationPanelClickListener buttonClickListener; + + /** The parent. */ + Composite parent; + + /** The show all. */ + boolean showAll = true; + + /** The left items indexes. */ + HashMap leftItemsIndexes = new HashMap<>(); + + /** The right items indexes. */ + HashMap 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> map1 = buttons.get(main); + if (map1 == null) + map1 = new HashMap<>(); + + ArrayList