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,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(" > ");
}
}
@@ -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<String, String> 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);
}
}
@@ -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());
}
});
}
}
@@ -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<String, String, Boolean> blockedPerspectiveType = new HashMatrix<>();
private HashMap<String, Integer> blockedPerspectiveDomainNumber = new HashMap<>();
private HashMatrix<String, String, Integer> blockedPerspectiveProblemElementNumber = new HashMatrix<>();
private HashMatrix<String, String, Boolean> 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;
// }
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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");
}
}
@@ -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<String, String> map = (HashMap<String, String>) 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);
}
}
@@ -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<MPerspective> 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);
}
}
@@ -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$
}
}
@@ -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<String, String> map = (HashMap<String, String>) 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<String, String> 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);
}
}
}