public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.element.common.ui</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Views common</name>
<organization>
<name>Sinbad2</name>
</organization>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.element.common.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362551</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,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
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
faq/
@@ -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.
@@ -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.
Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

@@ -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;
}
@@ -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
@@ -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 valoración
@@ -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<String, String> 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();
}
}
@@ -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<String, Object> 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<String, Object> 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<String, Object> 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");
}
}
@@ -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<String> tableHeaderH = new ArrayList<>();
/** The table header V. */
private ArrayList<String> tableHeaderV = new ArrayList<>();
/** The table placeholder. */
private final ArrayList<ArrayList<String>> tablePlaceholder = new ArrayList<>();
/** The table PEK. */
private final ArrayList<ArrayList<ProblemElementKey>> tablePEK = new ArrayList<>();
/** The table valuations. */
private ArrayList<ArrayList<WTableCell>> 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<ProblemElementKey> peks = new ArrayList<>();
for (ProblemElement pe2 : l2) {
ProblemElementKey pek = new ProblemElementKey(currentPE, pe1, pe2);
peks.add(pek);
}
this.tablePEK.add(peks);
}
for (ArrayList<ProblemElementKey> kList : this.tablePEK) {
ArrayList<String> placeholders = new ArrayList<>();
ArrayList<WTableCell> 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<String> 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<String> tableHeaderV) {
this.tableHeaderV = tableHeaderV;
}
/**
* Gets the table valuations.
*
* @return The table valuations
*/
public ArrayList<ArrayList<WTableCell>> getTableValuations() {
return this.tableValuations;
}
/**
* Transpose the table.
*/
public void transpose() {
ArrayList<ArrayList<WTableCell>> 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<WTableCell> tempList = new ArrayList<>();
for (ArrayList<WTableCell> row : this.tableValuations)
tempList.add(row.get(i));
transposedList.add(tempList);
}
this.tableValuations = transposedList;
ArrayList<String> 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;
}
}
@@ -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() {
}
}
@@ -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() {
}
}
@@ -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() {
}
}
@@ -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
}
}
@@ -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<ILabelProviderListener> 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);
}
}
@@ -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<String, Object> 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();
}
}