[DEV] update widget

This commit is contained in:
Edouard DUPIN 2022-03-20 18:59:52 +01:00
parent f29254547d
commit 457f81f1f2
5 changed files with 105 additions and 84 deletions

2
.gitignore vendored
View File

@ -32,6 +32,8 @@ build.number
/.settings/ /.settings/
/junit/ /junit/
/target/ /target/
/__pycache__/
*.pdfd *.pdfd
*.dbc *.dbc

View File

@ -21,4 +21,15 @@
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature> <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures> </natures>
<filteredResources>
<filter>
<id>1646149232192</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> </projectDescription>

View File

@ -14,4 +14,15 @@
<natures> <natures>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<filteredResources>
<filter>
<id>1646149232193</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> </projectDescription>

View File

@ -11,8 +11,6 @@ import org.atriasoft.ewol.DrawProperty;
import org.atriasoft.ewol.Gravity; import org.atriasoft.ewol.Gravity;
import org.atriasoft.ewol.internal.Log; import org.atriasoft.ewol.internal.Log;
import org.atriasoft.ewol.object.EwolObject; import org.atriasoft.ewol.object.EwolObject;
import org.atriasoft.exml.model.XmlElement;
import org.atriasoft.exml.model.XmlNode;
/* /*
* @ingroup ewolWidgetGroup * @ingroup ewolWidgetGroup
@ -78,50 +76,50 @@ public class Container extends Widget {
return null; return null;
} }
@Override // @Override
public boolean loadXML(final XmlElement node) { // public boolean loadXML(final XmlElement node) {
if (node == null) { // if (node == null) {
return false; // return false;
} // }
// parse generic properties: // // parse generic properties:
super.loadXML(node); // super.loadXML(node);
// remove previous element: // // remove previous element:
subWidgetRemove(); // subWidgetRemove();
// parse all the elements: // // parse all the elements:
for (XmlNode it : node.getNodes()) { // for (XmlNode it : node.getNodes()) {
if (!it.isElement()) { // if (!it.isElement()) {
// trash here all that is not element // // trash here all that is not element
continue; // continue;
} // }
XmlElement pNode = it.toElement(); // XmlElement pNode = it.toElement();
String widgetName = pNode.getValue(); // String widgetName = pNode.getValue();
Log.verbose("[" + getId() + "] t=" + getClass().getCanonicalName() + " Load node name : '" + widgetName + "'"); // Log.verbose("[" + getId() + "] t=" + getClass().getCanonicalName() + " Load node name : '" + widgetName + "'");
if (!getWidgetManager().exist(widgetName)) { // if (!getWidgetManager().exist(widgetName)) {
Log.error("Unknown basic node='" + widgetName + "' not in : [" + getWidgetManager().list() + "]"); // Log.error("Unknown basic node='" + widgetName + "' not in : [" + getWidgetManager().list() + "]");
continue; // continue;
} // }
if (getSubWidget() != null) { // if (getSubWidget() != null) {
Log.error("Can only have one subWidget ??? node='" + widgetName + "'"); // Log.error("Can only have one subWidget ??? node='" + widgetName + "'");
continue; // continue;
} // }
Log.debug("try to create subwidget : '" + widgetName + "'"); // Log.debug("try to create subwidget : '" + widgetName + "'");
Widget tmpWidget = getWidgetManager().create(widgetName, pNode); // Widget tmpWidget = getWidgetManager().create(widgetName, pNode);
if (tmpWidget == null) { // if (tmpWidget == null) {
Log.error("Can not create the widget : '" + widgetName + "'"); // Log.error("Can not create the widget : '" + widgetName + "'");
continue; // continue;
} // }
// add widget : // // add widget :
setSubWidget(tmpWidget); // setSubWidget(tmpWidget);
if (!tmpWidget.loadXML(pNode)) { // if (!tmpWidget.loadXML(pNode)) {
Log.error("can not load widget properties : '" + widgetName + "'"); // Log.error("can not load widget properties : '" + widgetName + "'");
return false; // return false;
} // }
} // }
if (node.getNodes().size() != 0 && this.subWidget == null) { // if (node.getNodes().size() != 0 && this.subWidget == null) {
Log.warning("Load container with no data inside"); // Log.warning("Load container with no data inside");
} // }
return true; // return true;
} // }
@Override @Override
public void onChangeSize() { public void onChangeSize() {

View File

@ -1,9 +1,6 @@
package org.atriasoft.ewol.widget; package org.atriasoft.ewol.widget;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import org.atriasoft.ewol.internal.Log; import org.atriasoft.ewol.internal.Log;
import org.atriasoft.exml.model.XmlElement; import org.atriasoft.exml.model.XmlElement;
@ -89,18 +86,18 @@ public class WidgetManager {
* @param klass class interface * @param klass class interface
*/ */
public void addWidgetCreator(final String name, final Class<?> klass) throws Exception { public void addWidgetCreator(final String name, final Class<?> klass) throws Exception {
if (klass == null) { // if (klass == null) {
throw new Exception("Can not add widget creator without specified class."); // throw new Exception("Can not add widget creator without specified class.");
} // }
//Keep name in lower case : // //Keep name in lower case :
final String nameLower = name.toLowerCase(); // final String nameLower = name.toLowerCase();
final Class<?> it = WidgetXmlFactory..creatorList.get(nameLower); // final Class<?> it = WidgetXmlFactory.creatorList.get(nameLower);
if (it != null) { // if (it != null) {
Log.warning("Replace Creator of a specify widget : " + nameLower); // Log.warning("Replace Creator of a specify widget : " + nameLower);
return; // return;
} // }
this.creatorList.put(nameLower, klass); // this.creatorList.put(nameLower, klass);
// TODO check constructors ... // // TODO check constructors ...
} }
/** /**
@ -110,33 +107,33 @@ public class WidgetManager {
*/ */
public Widget create(final String name) { public Widget create(final String name) {
final String nameLower = name.toLowerCase(); final String nameLower = name.toLowerCase();
final Class<?> it = this.creatorList.get(nameLower); // final Class<?> it = this.creatorList.get(nameLower);
if (it != null) { // if (it != null) {
try { // try {
return (Widget) it.getConstructor().newInstance(); // return (Widget) it.getConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { // } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block // // TODO Auto-generated catch block
e.printStackTrace(); // e.printStackTrace();
return null; // return null;
} // }
} // }
Log.warning("try to create an UnExistant widget : " + nameLower); Log.warning("try to create an UnExistant widget : " + nameLower);
return null; return null;
} }
public Widget create(final String name, final XmlElement node) { public Widget create(final String name, final XmlElement node) {
final String nameLower = name.toLowerCase(); final String nameLower = name.toLowerCase();
final Class<?> it = this.creatorList.get(nameLower); // final Class<?> it = this.creatorList.get(nameLower);
if (it != null) { // if (it != null) {
try { // try {
Widget tmp = (Widget) it.getConstructor().newInstance(); // Widget tmp = (Widget) it.getConstructor().newInstance();
tmp.loadXML(node); // tmp.loadXML(node);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { // } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block // // TODO Auto-generated catch block
e.printStackTrace(); // e.printStackTrace();
return null; // return null;
} // }
} // }
Log.warning("try to create an UnExistant widget : " + nameLower); Log.warning("try to create an UnExistant widget : " + nameLower);
return null; return null;
} }
@ -148,7 +145,8 @@ public class WidgetManager {
* @return false The Widget Does NOT exist. * @return false The Widget Does NOT exist.
*/ */
public boolean exist(final String name) { public boolean exist(final String name) {
return this.creatorList.get(name.toLowerCase()) != null; // return this.creatorList.get(name.toLowerCase()) != null;
return false;
} }
/** /**
@ -259,7 +257,8 @@ public class WidgetManager {
* @return Separate with ',' string list. * @return Separate with ',' string list.
*/ */
public String list() { public String list() {
return this.creatorList.keySet().toString(); //return this.creatorList.keySet().toString();
return "";
} }
/** /**