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,146 @@
package flintstones.valuation.ui;
import java.util.LinkedList;
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.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.Display;
import flintstones.entity.domain.Domain;
import flintstones.entity.domain.ui.chart.DomainChart;
import flintstones.entity.valuation.Valuation;
import flintstones.model.domain.ui.service.IDomainUIService;
import flintstones.model.ui.service.UiService;
import flintstones.model.valuation.service.IValuationService;
import flintstones.valuation.ui.listener.EValuationPanelEvent;
import flintstones.valuation.ui.listener.IValuationPanelListener;
import flintstones.valuation.ui.listener.ValuationPanelEvent;
import flintstones.valuation.ui.messages.Messages;
@SuppressWarnings("javadoc")
public abstract class ValuationPanel {
private Composite container;
protected Composite valuationPart;
private Composite domainPart;
protected Button valuateButton;
protected Valuation valuation;
protected Domain domain;
private DomainChart chart;
private final List<IValuationPanelListener> listeners;
@Inject
IValuationService valuationService;
@Inject
IDomainUIService uiDomainService;
@Inject
@Translation
private Messages messages;
public ValuationPanel() {
this.chart = null;
this.listeners = new LinkedList<>();
}
public void initialize(Composite parent, Domain domain, Valuation valuation) {
this.container = new Composite(parent, SWT.NONE);
this.container.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
UiService.setGridLayout(this.container, 2);
this.domain = domain;
this.valuation = valuation;
this.createValuationPart();
this.createDomainPart();
this.createControls();
}
public void dispose() {
this.listeners.clear();
}
public void selectionChange() {
Valuation result = this.createNewValuation();
this.notifyValuationChanges(result);
if (this.chart != null)
this.chart.setSelection(this.getSelection());
}
private void notifyValuationChanges(Valuation valuation) {
EValuationPanelEvent type = (ValuationPanel.this.valuation == null) ? EValuationPanelEvent.NEW_VALUATION : EValuationPanelEvent.MODIFY_VALUATION;
ValuationPanel.this.notifyValuationPanelChange(new ValuationPanelEvent(type, ValuationPanel.this.valuation, valuation));
ValuationPanel.this.valuation = valuation;
}
public void registerValuationPanelListener(IValuationPanelListener listener) {
this.listeners.add(listener);
}
public void unregisterValuationPanelListener(IValuationPanelListener listener) {
this.listeners.remove(listener);
}
public void notifyValuationPanelChange(ValuationPanelEvent event) {
for (IValuationPanelListener listener : this.listeners)
listener.notifyValuationPanelChange(event);
}
protected abstract void createControls();
public abstract Valuation createNewValuation();
public abstract Object getSelection();
private void createValuationPart() {
this.valuationPart = new Composite(this.container, SWT.NONE);
UiService.setGridData(this.valuationPart, 9, 9, false, true);
this.valuationPart.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
}
private void createDomainPart() {
this.domainPart = new Composite(this.container, SWT.BORDER);
UiService.setGridData(this.domainPart, 9, 9, true, true);
this.domainPart.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
ValuationPanel.this.refreshChart();
}
});
}
private void refreshChart() {
if (this.chart != null)
for (Control control : this.domainPart.getChildren())
if (!control.isDisposed())
control.dispose();
if (this.domain != null) {
Point size = this.domainPart.getSize();
this.chart = this.uiDomainService.createChart(domain.getType());
this.chart.initialize(this.domain, this.domainPart, size.x, size.y, SWT.NONE);
this.chart.setSelection(this.getSelection());
}
}
}
@@ -0,0 +1,72 @@
package flintstones.valuation.ui;
import javax.inject.Inject;
import org.eclipse.e4.core.services.nls.Translation;
import flintstones.entity.extensionenum.ExtensionEnum;
import flintstones.valuation.ui.messages.Messages;
/**
* The Class ValuationUI.
*/
public class ValuationUI {
/** The messages. */
@Inject
@Translation
private Messages messages;
/** The Constant EXTENSION_POINT. */
public final static String EXTENSION_POINT = Messages.ValuationUI_extension;
/** The valuation. */
private String _valuation;
/**
* Instantiates a new valuation UI.
*/
public ValuationUI() {
this._valuation = null;
}
/**
* Sets the valuation.
*
* @param valuation the new valuation
*/
public void setValuation(String valuation) {
this._valuation = valuation;
}
/**
* Gets the valuation.
*
* @return the valuation
*/
public String getValuation() {
return this._valuation;
}
/**
* The Enum Fields.
*/
public enum Fields implements ExtensionEnum {
/** The id. */
uid,
/** The valuation. */
valuation,
/** The new domain dialog. */
new_domain_dialog,
/** The modify domain dialog. */
modify_domain_dialog,
/** The dialog. */
dialog,
/** The valuation panel. */
valuation_panel,
/** The panel. */
panel;
}
}
@@ -0,0 +1,6 @@
package flintstones.valuation.ui.listener;
@SuppressWarnings("javadoc")
public enum EValuationPanelEvent {
NEW_VALUATION, MODIFY_VALUATION, REMOVE_VALUATION;
}
@@ -0,0 +1,8 @@
package flintstones.valuation.ui.listener;
@SuppressWarnings("javadoc")
public interface IValuationPanelListener {
public void notifyValuationPanelChange(ValuationPanelEvent event);
}
@@ -0,0 +1,67 @@
package flintstones.valuation.ui.listener;
import flintstones.entity.valuation.Valuation;
/**
* The Class ValuationPanelEvent.
*/
public class ValuationPanelEvent {
/** The event. */
private EValuationPanelEvent _event;
/** The old valuation. */
private Valuation _oldValuation;
/** The new valuation. */
private Valuation _newValuation;
/**
* Instantiates a new valuation panel event.
*/
private ValuationPanelEvent() {
}
/**
* Instantiates a new valuation panel event.
*
* @param event the event
* @param oldValuation the old valuation
* @param newValuation the new valuation
*/
public ValuationPanelEvent(EValuationPanelEvent event, Valuation oldValuation, Valuation newValuation) {
this();
this._event = event;
this._oldValuation = oldValuation;
this._newValuation = newValuation;
}
/**
* Gets the event.
*
* @return the event
*/
public EValuationPanelEvent getEvent() {
return this._event;
}
/**
* Gets the old valuation.
*
* @return the old valuation
*/
public Valuation getOldValuation() {
return this._oldValuation;
}
/**
* Gets the new valuation.
*
* @return the new valuation
*/
public Valuation getNewValuation() {
return this._newValuation;
}
}
@@ -0,0 +1,13 @@
// This file has been auto-generated
package flintstones.valuation.ui.messages;
import org.eclipse.e4.core.services.nls.Message;
@Message
@SuppressWarnings("javadoc")
public class Messages {
public static String ValuationUI_extension;
public String ValuationPanel_Evaluate;
}
@@ -0,0 +1,2 @@
ValuationPanel_Evaluate=Evaluate
ValuationUI_extension=flintstones.valuation.ui.extensionpoint
@@ -0,0 +1,2 @@
ValuationPanel_Evaluate=Evaluar
ValuationUI_extension=flintstones.valuation.ui.extensionpoint
@@ -0,0 +1,24 @@
package flintstones.valuation.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.valuation.ui.service.IValuationUIService;
/**
* The Class ValuationServiceContextFunction add the Valuation Service instance to global context.
*/
public class ValuationUIServiceContextFunction extends ContextFunction {
@Override
public Object compute(IEclipseContext context, String contextKey) {
IValuationUIService service = ContextInjectionFactory.make(ValuationUIServiceProvider.class, context);
MApplication application = context.get(MApplication.class);
IEclipseContext applicationContext = application.getContext();
applicationContext.set(IValuationUIService.class, service);
return service;
}
}
@@ -0,0 +1,88 @@
package flintstones.valuation.ui.provider;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import flintstones.helper.extensionpoint.BaseRegistry;
import flintstones.valuation.ui.ValuationPanel;
import flintstones.valuation.ui.ValuationUI;
import flintstones.valuation.ui.service.IValuationUIService;
/**
* The Class ValuationUIServiceProvider.
*/
public class ValuationUIServiceProvider implements IValuationUIService {
/** The reg. */
BaseRegistry reg;
/** The valuation U is. */
private Map<String, ValuationUI> valuationUIs;
/** The context. */
@Inject
IEclipseContext context;
/**
* Instantiates a new valuation UI service provider.
*/
public ValuationUIServiceProvider() {
}
/**
* Inits the.
*/
@PostConstruct
public void init() {
this.reg = new BaseRegistry("flintstones.valuation.ui.extensionpoint"); //$NON-NLS-1$
this.reg.setLabel_implementation(ValuationUI.Fields.valuation_panel);
this.valuationUIs = new HashMap<>();
}
/* (non-Javadoc)
*
* @see
* flintstones.valuation.ui.service.IValuationUIService#newValuationPanel(java.
* lang.String) */
@Override
public ValuationPanel newValuationPanel(String valuationUiId) {
return (ValuationPanel) this.reg.instantiate(valuationUiId, this.context);
}
/* (non-Javadoc)
*
* @see
* flintstones.valuation.ui.service.IValuationUIService#getValuationUI(java.lang
* .String) */
@Override
public ValuationUI getValuationUI(String valuation) {
return this.valuationUIs.get(valuation);
}
/* (non-Javadoc)
*
* @see
* flintstones.valuation.ui.service.IValuationUIService#getExtensionIdFor(java.
* lang.String) */
@Override
public String getExtensionIdFor(String valuationId) {
return this.reg.getFirstRegistryWhere(ValuationUI.Fields.valuation, valuationId)
.getAttribute(ValuationUI.Fields.uid);
}
/* (non-Javadoc)
*
* @see
* flintstones.valuation.ui.service.IValuationUIService#getRegistersIDs() */
@Override
public String[] getRegistersIDs() {
return this.reg.getAllAttributes(ValuationUI.Fields.uid);
}
}
@@ -0,0 +1,41 @@
package flintstones.valuation.ui.service;
import flintstones.valuation.ui.ValuationPanel;
import flintstones.valuation.ui.ValuationUI;
/**
* The Interface IValuationUIService.
*/
public interface IValuationUIService {
/**
* Creates a new valuation panel.
*
* @param valuation the valuation
* @return the valuation panel
*/
ValuationPanel newValuationPanel(String valuation);
/**
* Gets the valuation UI.
*
* @param valuation the valuation
* @return the valuation UI
*/
ValuationUI getValuationUI(String valuation);
/**
* Gets the registers Ids.
*
* @return the registers Ids
*/
public String[] getRegistersIDs();
/**
* Gets the extension id for a given valuationId.
*
* @param valuationId the valuation id
* @return the extension id for
*/
String getExtensionIdFor(String valuationId);
}