public code v1

This commit is contained in:
2026-05-22 11:14:29 +02:00
parent 427197ec5a
commit b8141736eb
28859 changed files with 575079 additions and 0 deletions
@@ -0,0 +1,50 @@
package afryca.structure.service;
import java.util.List;
import afryca.structure.definition.StructureRegistry;
public interface IStructureService {
public static final String CONTEXT = "structure.service.context"; //$NON-NLS-1$
// Selected structure
public static final String SELECTED_PR = "SELECTED "; //$NON-NLS-1$
/**
* Return all registers id
*
* @return Registers id
*/
String[] getIds();
/**
* Return a StructureRegistry
*
* @param id
* Id of the StructureRegistry
* @return StructureRegistry
*/
StructureRegistry getRegistry(String id);
/**
* Return a StructureRegistry id
*
* @param name
* Name of the StructureRegistry
* @return Registry id
*/
String getRegistryIdByName(String name);
/**
* Return a list of domains id
*
* @param id
* id of the StructureRegistry
* @return List of available domains id
*/
List<String> getDomains(String id);
}
@@ -0,0 +1,26 @@
package afryca.structure.service.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 afryca.structure.service.IStructureService;
/**
* Structure service context function
*
* @author Sinbad²
* @version 3.0
*/
public class StructureServiceContextFunction extends ContextFunction {
@Override
public Object compute(IEclipseContext context, String contextKey) {
IStructureService structureService = ContextInjectionFactory.make(StructureServiceProvider.class, context);
MApplication application = context.get(MApplication.class);
IEclipseContext applicationContext = application.getContext();
applicationContext.set(IStructureService.class, structureService);
return structureService;
}
}
@@ -0,0 +1,124 @@
package afryca.structure.service.provider;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import afryca.structure.Structure;
import afryca.structure.definition.EElements;
import afryca.structure.definition.StructureRegistry;
import afryca.structure.provider.IStructureProvider;
import afryca.structure.service.IStructureService;
/**
* Structure service provider
*
* @author Sinbad²
* @version 3.0
*/
public class StructureServiceProvider implements IStructureService {
private Map<String, StructureRegistry> registers;
private Map<String, List<String>> registersDomains;
@Inject
private IEclipseContext context;
@Inject
public StructureServiceProvider() {
registers = new HashMap<>();
registersDomains = new HashMap<>();
}
@PostConstruct
private void initialize() {
loadProviders();
loadRegisters();
setEclipseContext();
}
private void loadProviders() {
// It's not set until @PostConstruct does not end
context.set(IStructureService.class, this);
context.get(IStructureProvider.class);
}
private void loadRegisters() {
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
IConfigurationElement[] extensionElements = extensionRegistry.getConfigurationElementsFor(Structure.EXTENSION_POINT);
Arrays.stream(extensionElements).forEach(this::loadRegistry);
}
private void loadRegistry(IConfigurationElement extensionElement) {
StructureRegistry registry = new StructureRegistry(extensionElement);
registers.put(registry.getElement(EElements.id), registry);
loadRegistryDomain(registry);
}
private void loadRegistryDomain(StructureRegistry registry) {
IConfigurationElement[] conf = registry.getConfiguration().getChildren(EElements.domain.toString());
String registryId = registry.getElement(EElements.id);
if(conf.length != 0) {
for(int d = 0; d < conf.length; d++) {
IConfigurationElement domain = conf[d];
List<String> domains;
if(registersDomains.get(registryId) != null) {
domains = registersDomains.get(registryId);
} else {
domains = new LinkedList<String>();
}
domains.add(domain.getAttribute(EElements.id.toString()));
registersDomains.put(registryId, domains);
}
}
}
private void setEclipseContext() {
getApplicationContext().set(CONTEXT, context);
}
@Override
public String[] getIds() {
return registers.keySet().toArray(new String[0]);
}
@Override
public StructureRegistry getRegistry(String id) {
return registers.get(id);
}
@Override
public String getRegistryIdByName(String name) {
for(String id: registers.keySet()) {
StructureRegistry registry = registers.get(id);
if(registry.getElement(EElements.name).equals(name)) {
return id;
}
}
return null;
}
@Override
public List<String> getDomains(String id) {
return registersDomains.get(id);
}
private IEclipseContext getApplicationContext() {
MApplication application = context.get(MApplication.class);
return application.getContext();
}
}