public code v1
This commit is contained in:
@@ -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,14 @@
|
||||
<?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.model.problemelement.provider</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Provider</name>
|
||||
</project>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.model.problemelement.provider</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.pde.ds.core.builder</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>1779484362726</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>
|
||||
+2
@@ -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,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
|
||||
@@ -0,0 +1,5 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
component.xml
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="flintstones.model.problemelement.provider">
|
||||
<implementation class="flintstones.model.problemelement.provider.ProblemElementServiceContextFunction" />
|
||||
<property name="service.context.key" type="String" value="flintstones.model.problemelement.service.IProblemElementService" />
|
||||
<service>
|
||||
<provide interface="org.eclipse.e4.core.contexts.IContextFunction" />
|
||||
</service>
|
||||
</scr:component>
|
||||
+28
@@ -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;
|
||||
}
|
||||
}
|
||||
+227
@@ -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<String, HashMap<String, ProblemElement>> elements = new LinkedHashMap<>();
|
||||
HashMap<String, Integer> lastOrder = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new problem element service provider.
|
||||
*/
|
||||
public ProblemElementServiceProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(ProblemElement pe) {
|
||||
HashMap<String, ProblemElement> 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<String, ProblemElement> 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<String, ProblemElement> map = elements.get(type);
|
||||
if (map == null)
|
||||
map = new HashMap<>();
|
||||
return map.get(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ProblemElement getByName(String type, String name) {
|
||||
HashMap<String, ProblemElement> map = elements.get(type);
|
||||
if (map == null)
|
||||
return null;
|
||||
|
||||
Optional<ProblemElement> 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<String, ProblemElement> 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<String, ProblemElement> 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user