Jaxx-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
January 2010
- 2 participants
- 24 discussions
30 Jan '10
Author: tchemit
Date: 2010-01-30 12:46:50 +0100 (Sat, 30 Jan 2010)
New Revision: 1728
Modified:
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
Log:
- add jaxx.runtime and jaxx.runtime.swing namespace in all generated files
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-30 09:57:56 UTC (rev 1727)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-30 11:46:50 UTC (rev 1728)
@@ -647,13 +647,14 @@
"javax.swing.*",
"javax.swing.border.*",
"javax.swing.event.*",
- "jaxx.runtime.swing.JAXXButtonGroup",
- "jaxx.runtime.swing.HBox",
- "jaxx.runtime.swing.VBox",
- "jaxx.runtime.swing.Table",
- "jaxx.runtime.Util",
- "jaxx.runtime.JAXXUtil",
- "jaxx.runtime.SwingUtil",
+// "jaxx.runtime.swing.JAXXButtonGroup",
+// "jaxx.runtime.swing.HBox",
+// "jaxx.runtime.swing.VBox",
+// "jaxx.runtime.swing.Table",
+ "jaxx.runtime.*",
+ "jaxx.runtime.swing.*",
+// "jaxx.runtime.JAXXUtil",
+// "jaxx.runtime.SwingUtil",
"static org.nuiton.i18n.I18n._",
"static jaxx.runtime.SwingUtil.createImageIcon")
);
1
0
30 Jan '10
Author: tchemit
Date: 2010-01-30 10:57:56 +0100 (Sat, 30 Jan 2010)
New Revision: 1727
Modified:
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
Log:
For the moment let old Util class in generation to make it compatible
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-29 17:32:57 UTC (rev 1726)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-30 09:57:56 UTC (rev 1727)
@@ -651,6 +651,7 @@
"jaxx.runtime.swing.HBox",
"jaxx.runtime.swing.VBox",
"jaxx.runtime.swing.Table",
+ "jaxx.runtime.Util",
"jaxx.runtime.JAXXUtil",
"jaxx.runtime.SwingUtil",
"static org.nuiton.i18n.I18n._",
1
0
r1726 - in trunk: jaxx-compiler/src/main/java/jaxx/compiler jaxx-runtime/src/main/java/jaxx/runtime
by sletellier@users.nuiton.org 29 Jan '10
by sletellier@users.nuiton.org 29 Jan '10
29 Jan '10
Author: sletellier
Date: 2010-01-29 18:32:57 +0100 (Fri, 29 Jan 2010)
New Revision: 1726
Modified:
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
Log:
Evol 292 : Refactoring, Util is deprecated and will be replaced by JAXXUtil
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 16:58:54 UTC (rev 1725)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 17:32:57 UTC (rev 1726)
@@ -127,7 +127,7 @@
*/
protected final IDHelper idHelper;
/**
- * Binding JAXXUtil
+ * Binding Util
*/
protected final DataBindingHelper bindingHelper;
/**
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2010-01-29 16:58:54 UTC (rev 1725)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2010-01-29 17:32:57 UTC (rev 1726)
@@ -20,6 +20,9 @@
* ##%*
*/
-@Deprecated // since 2.0.4-XXX, will be removed
+/**
+ * @deprecated since 2, will be removed in 2.1
+ */
+@Deprecated
public class Util extends JAXXUtil{
}
1
0
Author: sletellier
Date: 2010-01-29 17:58:54 +0100 (Fri, 29 Jan 2010)
New Revision: 1725
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
Modified:
trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java
trunk/jaxx-compiler/src/site/rst/BeanValidator.rst
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java
trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java
trunk/src/site/rst/BeanValidator.rst
Log:
Evol 292 : Refactoring, Util is deprecated and will be replaced by JAXXUtil
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -460,8 +460,8 @@
MethodDescriptor addMethod = handler.getAddMethod();
ClassDescriptor listenerClass = addMethod.getParameterTypes()[0];
//TC-20091026 use 'this' instead of root object javaCode
- //TC-20091105 Util.getEventListener is generic, no more need cast and use simple name
- return getJavaCode() + '.' + addMethod.getName() + "(Util.getEventListener(" + listenerClass.getSimpleName() + ".class, " +
+ //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple name
+ return getJavaCode() + '.' + addMethod.getName() + "(JAXXUtil.getEventListener(" + listenerClass.getSimpleName() + ".class, " +
TypeManager.getJavaCode(handler.getListenerMethod().getName()) + ", this, " +
TypeManager.getJavaCode(compiler.getEventHandlerMethodName(handler)) + "));" + JAXXCompiler.getLineSeparator();
}
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -127,7 +127,7 @@
*/
protected final IDHelper idHelper;
/**
- * Binding Util
+ * Binding JAXXUtil
*/
protected final DataBindingHelper bindingHelper;
/**
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -651,7 +651,7 @@
"jaxx.runtime.swing.HBox",
"jaxx.runtime.swing.VBox",
"jaxx.runtime.swing.Table",
- "jaxx.runtime.Util",
+ "jaxx.runtime.JAXXUtil",
"jaxx.runtime.SwingUtil",
"static org.nuiton.i18n.I18n._",
"static jaxx.runtime.SwingUtil.createImageIcon")
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -37,7 +37,7 @@
import jaxx.compiler.tags.DefaultObjectHandler;
import jaxx.compiler.tags.TagManager;
import jaxx.compiler.types.TypeManager;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -620,12 +620,12 @@
}
String code = objectCode + (eventInfo.getModelName() != null ? ".get" + StringUtils.capitalize(eventInfo.getModelName()) + "()" : "");
result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator());
- //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
- result.append(code).append('.').append(eventInfo.getAddMethod()).append("( Util.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
+ //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
+ result.append(code).append('.').append(eventInfo.getAddMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
result.append(JAXXCompiler.getLineSeparator());
if (eventInfo.getModelName() != null) {
result.append(getAddMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()),
- Util.class.getSimpleName() + ".getDataBindingUpdateListener(" + (compiler.getOutputClassName() + ".this") + ", " + constantId + ")",
+ JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + (compiler.getOutputClassName() + ".this") + ", " + constantId + ")",
compiler));
}
return result.toString();
@@ -696,12 +696,12 @@
result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol);
//TC-20091105 test if $target is not null
result.append("if ($target != null) {").append(eol);
- //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
- result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( Util.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
+ //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
+ result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
result.append("}").append(eol);
if (eventInfo.getModelName() != null) {
result.append(getRemoveMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()),
- Util.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this, " + constantId + ")",
+ JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this, " + constantId + ")",
compiler));
}
return result.toString();
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -194,7 +194,7 @@
*
*/
protected static final JavaMethod GET_JAXX_OBJECT_DESCRIPTOR_METHOD = newMethod(PUBLIC | STATIC, "JAXXObjectDescriptor", METHOD_NAME_$GET_JAXXOBJECT_DESCRIPTOR,
- "return Util.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false);
+ "return JAXXUtil.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false);
/**
*
*/
@@ -624,7 +624,7 @@
}
}
if (!superclassIsJAXXObject) {
- code.append(Util.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");");
+ code.append(JAXXUtil.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");");
code.append(eol);
}
code.append(METHOD_NAME_$INITIALIZE + "();");
@@ -708,7 +708,7 @@
if (bindings.length > 0) {
result.append(eol).append("// apply ").append(bindings.length).append(" data bindings").append(eol);
- result.append(Util.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol);
+ result.append(JAXXUtil.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol);
}
bindings = compiler.getBindingHelper().getSimpleBindings();
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -133,7 +133,7 @@
for (FieldDescriptor field : fields) {
if (field.getName().equals(lhs)) {
//lhs.substring(lhs.lastIndexOf(".") + 1);
- node.firstToken.image = "jaxx.runtime.Util.assignment(" + node.firstToken.image;
+ node.firstToken.image = "jaxx.runtime.JAXXUtil.assignment(" + node.firstToken.image;
String outputClassName = compiler.getOutputClassName();
node.lastToken.image = node.lastToken.image + ", \"" + lhs + "\", " + outputClassName + ".this)";
}
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -337,13 +337,13 @@
// }
// String code = objectCode + (eventInfo.modelName != null ? ".get" + StringUtils.capitalize(eventInfo.modelName) + "()" : "");
// result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator());
-// //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
-// result.append(code).append('.').append(eventInfo.addMethod).append("( Util.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
+// //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
+// result.append(code).append('.').append(eventInfo.addMethod).append("( JAXXUtil.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
// result.append(JAXXCompiler.getLineSeparator());
// if (eventInfo.modelName != null) {
// result.append(getAddMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName),
-// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this , " + dataBinding + ")",
-//// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this , \"" + dataBinding + "\")",
+// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this , " + dataBinding + ")",
+//// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this , \"" + dataBinding + "\")",
// compiler));
// }
// return result.toString();
@@ -407,14 +407,14 @@
// result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol);
// //TC-20091105 test if $target is not null
// result.append("if ($target != null) {").append(eol);
-// //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
-// result.append(" $target.").append(eventInfo.removeMethod).append("( Util.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
+// //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
+// result.append(" $target.").append(eventInfo.removeMethod).append("( JAXXUtil.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
// result.append("}").append(eol);
// if (eventInfo.modelName != null) {
//// String bi = dataBinding.startsWith("this.") ? dataBinding : ("\"" + dataBinding + "\"");
// result.append(getRemoveMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName),
-// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this, " + dataBinding + ")",
-//// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")",
+// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this, " + dataBinding + ")",
+//// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")",
// compiler));
// }
// return result.toString();
Modified: trunk/jaxx-compiler/src/site/rst/BeanValidator.rst
===================================================================
--- trunk/jaxx-compiler/src/site/rst/BeanValidator.rst 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-compiler/src/site/rst/BeanValidator.rst 2010-01-29 16:58:54 UTC (rev 1725)
@@ -170,7 +170,7 @@
::
- jaxx.runtime.Util.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
+ jaxx.runtime.JAXXUtil.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
On obtiendra si une erreur de conversion intervient, une erreur dont le libellé est de la forme *error.convertor.XXX*
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -29,7 +29,7 @@
import java.util.Properties;
import jaxx.demo.component.jaxx.navigation.FullNavigationTreeDemo;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -214,7 +214,7 @@
};
public void removeJaxxPropertyChangeListener() {
- PropertyChangeListener[] toRemove = Util.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
+ PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
if (toRemove == null || toRemove.length == 0) {
return;
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -37,7 +37,7 @@
import jaxx.demo.fun.LabelStyleDemo;
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
@@ -191,7 +191,7 @@
/**
* la definition de l'unqiue object a partage
*/
- static private final JAXXContextEntryDef<DemoConfig> def = Util.newContextEntryDef(DemoConfig.class);
+ static private final JAXXContextEntryDef<DemoConfig> def = JAXXUtil.newContextEntryDef(DemoConfig.class);
/**
* la pile des noeuds parent
*/
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -21,7 +21,7 @@
package jaxx.demo;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.DefaultApplicationContext;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.context.JAXXInitialContext;
@@ -57,7 +57,7 @@
* to use log facility, just put in your code: log.info(\"...\");
*/
static private Log log = LogFactory.getLog(DemoUIHandler.class);
- static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = Util.newContextEntryDef("mainui", DemoUI.class);
+ static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = JAXXUtil.newContextEntryDef("mainui", DemoUI.class);
/**
* Methode pour initialiser l'ui principale sans l'afficher.
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -22,7 +22,7 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
@@ -63,11 +63,11 @@
/**
* where the movies are hold in context
*/
- static public final JAXXContextEntryDef<List<Movie>> MOVIES = Util.newListContextEntryDef("movies");
+ static public final JAXXContextEntryDef<List<Movie>> MOVIES = JAXXUtil.newListContextEntryDef("movies");
/**
* where the actors are hold in context
*/
- static public final JAXXContextEntryDef<List<People>> ACTORS = Util.newListContextEntryDef("actors");
+ static public final JAXXContextEntryDef<List<People>> ACTORS = JAXXUtil.newListContextEntryDef("actors");
protected FullNavigationTreeModelBuilder builder;
public FullNavigationTreeHelper() {
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -0,0 +1,516 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime;
+
+import jaxx.runtime.context.JAXXContextEntryDef;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeListenerProxy;
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.*;
+
+public class JAXXUtil {
+
+ // public static final String DEFAULT_ICON_PATH = "/icons/";
+ // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path";
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(JAXXUtil.class);
+ public static final String PARENT = "parent";
+ // Maps root objects to lists of event listeners
+ private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
+ private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
+
+ private static class EventListenerDescriptor {
+
+ Class<?> listenerClass;
+ String listenerMethodName;
+ String methodName;
+ Object eventListener;
+ }
+
+ /**
+ * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping
+ * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField
+ * for the rationale behind this (admittedly ugly) approach.
+ *
+ * @param descriptor descriptor to decode
+ * @return the dedoced descriptor
+ */
+ public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) {
+ try {
+ return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false);
+ /*byte[] data = new byte[descriptor.length()];
+ // copy low-order bytes into the array. The high-order bytes should all be zero.
+ System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
+ //descriptor.getBytes(0, descriptor.length(), data, 0);
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
+ return (JAXXObjectDescriptor) in.readObject();*/
+ } catch (IOException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ }
+ }
+
+ public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) {
+ try {
+ return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true);
+
+ /*byte[] data = new byte[descriptor.length()];
+ // copy low-order bytes into the array. The high-order bytes should all be zero.
+ System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
+ //descriptor.getBytes(0, descriptor.length(), data, 0);
+ ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data)));
+ return (JAXXObjectDescriptor) in.readObject();*/
+ } catch (IOException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ }
+ }
+
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
+ return newContextEntryDef(null, klass);
+ }
+
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
+ return new JAXXContextEntryDef<O>(name, klass);
+ }
+
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
+ return newListContextEntryDef(null);
+ }
+
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
+ Class<List<O>> castList = JAXXUtil.castList();
+ JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList);
+ return contextEntryDef;
+ }
+
+// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) {
+// bindings.put(binding.getId(), binding);
+//// binding.applyDataBinding();
+//// binding.processDataBinding();
+// return binding;
+// }
+
+// /**
+// * Return parent's container corresponding to the Class clazz
+// *
+// * @param <O> type of container to obtain from context
+// * @param top the top container
+// * @param clazz desired
+// * @return parent's container
+// */
+// @SuppressWarnings({"unchecked"})
+// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
+// if (top == null) {
+// throw new IllegalArgumentException("top parameter can not be null");
+// }
+// if (!Container.class.isAssignableFrom(top.getClass())) {
+// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class);
+// }
+// Container parent = ((Container) top).getParent();
+// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) {
+// parent = getParentContainer(parent, clazz);
+// }
+// return (O) parent;
+// }
+
+ @SuppressWarnings({"unchecked"})
+ protected static <O> Class<List<O>> castList() {
+ return (Class<List<O>>) Collections.emptyList().getClass();
+ }
+
+ /**
+ * Method to initialize the context of a ui.
+ *
+ * @param ui the ui
+ * @param parentContext the context to set in ui
+ */
+ public static void initContext(JAXXObject ui, JAXXContext parentContext) {
+
+ if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) {
+ ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui);
+ } else {
+ ui.setContextValue(parentContext);
+ }
+ // if parentContext is a JAXXObject then
+ // add an special parent entry to can go up
+ if (parentContext instanceof JAXXObject) {
+ ui.setContextValue(parentContext, PARENT);
+ }
+ }
+
+ public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
+ WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
+ List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
+ if (descriptors == null) {
+ descriptors = new ArrayList<EventListenerDescriptor>();
+ eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
+ } else {
+ for (EventListenerDescriptor descriptor : descriptors) {
+ if (listenerClass == descriptor.listenerClass &&
+ (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
+ methodName.equals(descriptor.methodName)) {
+ return (E) descriptor.eventListener;
+ }
+ }
+ }
+
+ // else we need to create a new listener
+ final EventListenerDescriptor descriptor = new EventListenerDescriptor();
+ descriptor.listenerClass = listenerClass;
+ descriptor.listenerMethodName = listenerMethodName;
+ descriptor.methodName = methodName;
+ try {
+ final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
+ Method listenerMethod = null;
+ if (listenerMethodName != null) {
+ for (Method listenerMethod1 : listenerMethods) {
+ if ((listenerMethod1).getName().equals(listenerMethodName)) {
+ listenerMethod = listenerMethod1;
+ break;
+ }
+ }
+ }
+ if (listenerMethodName != null && listenerMethod == null) {
+ throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
+ }
+ Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes();
+ Class<?> methodContainerClass = methodContainer.getClass();
+ final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
+ descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
+ new Class<?>[]{listenerClass},
+ new InvocationHandler() {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) {
+ String methodName = method.getName();
+ if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
+ try {
+ targetMethod.setAccessible(true);
+ return targetMethod.invoke(methodContainer, args);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("could not invoke on container " + methodContainer, e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (methodName.equals("toString")) {
+ return toString();
+ }
+ if (methodName.equals("equals")) {
+ return descriptor.eventListener == args[0];
+ }
+ if (methodName.equals("hashCode")) {
+ return hashCode();
+ }
+ return null;
+ }
+ });
+ descriptors.add(descriptor);
+ return (E) descriptor.eventListener;
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) {
+ return getEventListener(listenerClass, null, methodContainer, methodName);
+ }
+
+ public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) {
+ WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object);
+ List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get();
+ if (listeners == null) {
+ listeners = new ArrayList<DataBindingUpdateListener>();
+ dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners));
+ } else {
+ for (DataBindingUpdateListener listener : listeners) {
+ if (bindingName.equals(listener.getBindingName())) {
+ return listener;
+ }
+ }
+ }
+ DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName);
+ listeners.add(listener);
+ return listener;
+ }
+
+// public static void setComponentWidth(Component component, int width) {
+// component.setSize(width, component.getHeight());
+// if (component instanceof JComponent) {
+// JComponent jcomponent = (JComponent) component;
+// jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height));
+// jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height));
+// if (jcomponent.isDisplayable()) {
+// jcomponent.revalidate();
+// }
+// }
+// }
+
+// public static void setComponentHeight(Component component, int height) {
+// component.setSize(component.getWidth(), height);
+// if (component instanceof JComponent) {
+// JComponent jcomponent = (JComponent) component;
+// jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height));
+// jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height));
+// if (jcomponent.isDisplayable()) {
+// jcomponent.revalidate();
+// }
+// }
+// }
+
+ public static boolean assignment(boolean value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static byte assignment(byte value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static short assignment(short value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static int assignment(int value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static long assignment(long value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static float assignment(float value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static double assignment(double value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static char assignment(char value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ /**
+ * Compute the string representation of an object.
+ * <p/>
+ * Return empty string if given object is null
+ *
+ * @param value the value to write
+ * @return the string representation of the given object or an empty string if object is null.
+ */
+ public static String getStringValue(Object value) {
+ String result;
+ result = value == null ? "" : value.toString();
+ return result;
+ }
+
+ /**
+ * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found.
+ * <p/>
+ * If entry is found, return his value in context.
+ *
+ * @param <T> the type of required data
+ * @param context the context to test
+ * @param def the definition of the entry to seek in context
+ * @return the value from the context
+ * @throws IllegalArgumentException if the entry is not found in context.
+ */
+ public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException {
+
+ T value = def.getContextValue(context);
+
+ if (value == null) {
+ throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context);
+ }
+
+ return value;
+ }
+
+ /**
+ * Convinient method to apply more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void applyDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.applyDataBinding(binding);
+ }
+ }
+ /**
+ * Convinient method to apply more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void applyDataBinding(JAXXObject src, Collection<String> bindings) {
+ for (String binding : bindings) {
+ src.applyDataBinding(binding);
+ }
+ }
+
+ /**
+ * Convinient method to process more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void processDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.processDataBinding(binding);
+ }
+ }
+
+ /**
+ * Convinient method to remove more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void removeDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.removeDataBinding(binding);
+ }
+ }
+
+// public static ImageIcon createIcon(String path) {
+// java.net.URL imgURL = JAXXUtil.class.getResource(path);
+// if (imgURL != null) {
+// return new ImageIcon(imgURL);
+// } else {
+// throw new IllegalArgumentException("could not find icon " + path);
+// }
+// }
+
+// /**
+// * @param path the location of icons in root directory icons
+// * @return the icon at {@link #getIconPath()}+path
+// */
+// public static ImageIcon createImageIcon(String path) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + path);
+// }
+//
+// /**
+// * @param key the key of the icon to retreave from {@link UIManager}
+// * @return the icon, or <code>null if no icon found in {@link UIManager}
+// */
+// public static Icon getUIManagerIcon(String key) {
+// return UIManager.getIcon(key);
+// }
+//
+// /**
+// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code>
+// *
+// * @param key the key of the action icon to retreave from {@link UIManager}
+// * @return the icon, or <code>null if no icon found in {@link UIManager}
+// */
+// public static Icon getUIManagerActionIcon(String key) {
+// return getUIManagerIcon("action." + key);
+// }
+//
+// public static ImageIcon createActionIcon(String name) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + "action-" + name + ".png");
+// }
+//
+// public static ImageIcon createI18nIcon(String name) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + "i18n/" + name + ".png");
+// }
+
+ /**
+ * detects all PropertychangedListener added by Jaxx uis
+ * (should be a {@link DataBindingListener}
+ *
+ * @param propertyNames the array of property names to find
+ * @param listeners the array of listeners to filter
+ * @return the filtered listeners
+ */
+ public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) {
+ if (listeners == null || listeners.length == 0) {
+ return new PropertyChangeListener[0];
+ }
+ List<String> pNames = Arrays.asList(propertyNames);
+
+ List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>();
+
+ for (PropertyChangeListener listener : listeners) {
+ String pName = null;
+ PropertyChangeListenerProxy plistener = null;
+ if (listener instanceof PropertyChangeListenerProxy) {
+ plistener = (PropertyChangeListenerProxy) listener;
+ if (!pNames.contains(plistener.getPropertyName())) {
+ // not on the good property
+ continue;
+ }
+ listener = (PropertyChangeListener) plistener.getListener();
+ pName = plistener.getPropertyName();
+ }
+ if (plistener != null && pName != null && listener instanceof DataBindingListener) {
+ if (log.isDebugEnabled()) {
+ log.debug("find config listener to remove [" + pName + "] : " + listener);
+ }
+ toRemove.add(plistener);
+ //toRemove.add(listener);
+ }
+ }
+ return toRemove.toArray(new PropertyChangeListener[toRemove.size()]);
+ }
+
+// private static String getIconPath() {
+// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY);
+// if (iconPath == null) {
+// iconPath = DEFAULT_ICON_PATH;
+// } else {
+// if (!iconPath.endsWith("/")) {
+// iconPath += "/";
+// }
+// }
+// return iconPath;
+// }
+}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -79,7 +79,7 @@
* @author tony
* @since 1.2
*/
-public class SwingUtil extends Util {
+public class SwingUtil extends JAXXUtil {
/**
* to use log facility, just put in your code: log.info(\"...\");
@@ -861,7 +861,7 @@
}
public static ImageIcon createIcon(String path) {
- java.net.URL imgURL = Util.class.getResource(path);
+ java.net.URL imgURL = JAXXUtil.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -1,5 +1,6 @@
+package jaxx.runtime;
/*
- * *##%
+ * *##%
* JAXX Runtime
* Copyright (C) 2008 - 2009 CodeLutin
*
@@ -18,499 +19,7 @@
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* ##%*
*/
-package jaxx.runtime;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeListenerProxy;
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.*;
-
-public class Util {
-
- // public static final String DEFAULT_ICON_PATH = "/icons/";
- // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path";
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(Util.class);
- public static final String PARENT = "parent";
- // Maps root objects to lists of event listeners
- private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
- private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
-
- private static class EventListenerDescriptor {
-
- Class<?> listenerClass;
- String listenerMethodName;
- String methodName;
- Object eventListener;
- }
-
- /**
- * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping
- * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField
- * for the rationale behind this (admittedly ugly) approach.
- *
- * @param descriptor descriptor to decode
- * @return the dedoced descriptor
- */
- public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) {
- try {
- return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false);
- /*byte[] data = new byte[descriptor.length()];
- // copy low-order bytes into the array. The high-order bytes should all be zero.
- System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
- //descriptor.getBytes(0, descriptor.length(), data, 0);
- ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
- return (JAXXObjectDescriptor) in.readObject();*/
- } catch (IOException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- }
- }
-
- public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) {
- try {
- return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true);
-
- /*byte[] data = new byte[descriptor.length()];
- // copy low-order bytes into the array. The high-order bytes should all be zero.
- System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
- //descriptor.getBytes(0, descriptor.length(), data, 0);
- ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data)));
- return (JAXXObjectDescriptor) in.readObject();*/
- } catch (IOException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- }
- }
-
- public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
- return newContextEntryDef(null, klass);
- }
-
- public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
- return new JAXXContextEntryDef<O>(name, klass);
- }
-
- public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
- return newListContextEntryDef(null);
- }
-
- public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
- Class<List<O>> castList = Util.castList();
- JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList);
- return contextEntryDef;
- }
-
-// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) {
-// bindings.put(binding.getId(), binding);
-//// binding.applyDataBinding();
-//// binding.processDataBinding();
-// return binding;
-// }
-
-// /**
-// * Return parent's container corresponding to the Class clazz
-// *
-// * @param <O> type of container to obtain from context
-// * @param top the top container
-// * @param clazz desired
-// * @return parent's container
-// */
-// @SuppressWarnings({"unchecked"})
-// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
-// if (top == null) {
-// throw new IllegalArgumentException("top parameter can not be null");
-// }
-// if (!Container.class.isAssignableFrom(top.getClass())) {
-// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class);
-// }
-// Container parent = ((Container) top).getParent();
-// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) {
-// parent = getParentContainer(parent, clazz);
-// }
-// return (O) parent;
-// }
-
- @SuppressWarnings({"unchecked"})
- protected static <O> Class<List<O>> castList() {
- return (Class<List<O>>) Collections.emptyList().getClass();
- }
-
- /**
- * Method to initialize the context of a ui.
- *
- * @param ui the ui
- * @param parentContext the context to set in ui
- */
- public static void initContext(JAXXObject ui, JAXXContext parentContext) {
-
- if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) {
- ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui);
- } else {
- ui.setContextValue(parentContext);
- }
- // if parentContext is a JAXXObject then
- // add an special parent entry to can go up
- if (parentContext instanceof JAXXObject) {
- ui.setContextValue(parentContext, PARENT);
- }
- }
-
- public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
- WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
- List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
- if (descriptors == null) {
- descriptors = new ArrayList<EventListenerDescriptor>();
- eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
- } else {
- for (EventListenerDescriptor descriptor : descriptors) {
- if (listenerClass == descriptor.listenerClass &&
- (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
- methodName.equals(descriptor.methodName)) {
- return (E) descriptor.eventListener;
- }
- }
- }
-
- // else we need to create a new listener
- final EventListenerDescriptor descriptor = new EventListenerDescriptor();
- descriptor.listenerClass = listenerClass;
- descriptor.listenerMethodName = listenerMethodName;
- descriptor.methodName = methodName;
- try {
- final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
- Method listenerMethod = null;
- if (listenerMethodName != null) {
- for (Method listenerMethod1 : listenerMethods) {
- if ((listenerMethod1).getName().equals(listenerMethodName)) {
- listenerMethod = listenerMethod1;
- break;
- }
- }
- }
- if (listenerMethodName != null && listenerMethod == null) {
- throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
- }
- Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes();
- Class<?> methodContainerClass = methodContainer.getClass();
- final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
- descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
- new Class<?>[]{listenerClass},
- new InvocationHandler() {
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) {
- String methodName = method.getName();
- if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
- try {
- targetMethod.setAccessible(true);
- return targetMethod.invoke(methodContainer, args);
- } catch (IllegalAccessException e) {
- throw new RuntimeException("could not invoke on container " + methodContainer, e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
- if (methodName.equals("toString")) {
- return toString();
- }
- if (methodName.equals("equals")) {
- return descriptor.eventListener == args[0];
- }
- if (methodName.equals("hashCode")) {
- return hashCode();
- }
- return null;
- }
- });
- descriptors.add(descriptor);
- return (E) descriptor.eventListener;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) {
- return getEventListener(listenerClass, null, methodContainer, methodName);
- }
-
- public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) {
- WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object);
- List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get();
- if (listeners == null) {
- listeners = new ArrayList<DataBindingUpdateListener>();
- dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners));
- } else {
- for (DataBindingUpdateListener listener : listeners) {
- if (bindingName.equals(listener.getBindingName())) {
- return listener;
- }
- }
- }
- DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName);
- listeners.add(listener);
- return listener;
- }
-
-// public static void setComponentWidth(Component component, int width) {
-// component.setSize(width, component.getHeight());
-// if (component instanceof JComponent) {
-// JComponent jcomponent = (JComponent) component;
-// jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height));
-// jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height));
-// if (jcomponent.isDisplayable()) {
-// jcomponent.revalidate();
-// }
-// }
-// }
-
-// public static void setComponentHeight(Component component, int height) {
-// component.setSize(component.getWidth(), height);
-// if (component instanceof JComponent) {
-// JComponent jcomponent = (JComponent) component;
-// jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height));
-// jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height));
-// if (jcomponent.isDisplayable()) {
-// jcomponent.revalidate();
-// }
-// }
-// }
-
- public static boolean assignment(boolean value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static byte assignment(byte value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static short assignment(short value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static int assignment(int value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static long assignment(long value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static float assignment(float value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static double assignment(double value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static char assignment(char value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- /**
- * Compute the string representation of an object.
- * <p/>
- * Return empty string if given object is null
- *
- * @param value the value to write
- * @return the string representation of the given object or an empty string if object is null.
- */
- public static String getStringValue(Object value) {
- String result;
- result = value == null ? "" : value.toString();
- return result;
- }
-
- /**
- * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found.
- * <p/>
- * If entry is found, return his value in context.
- *
- * @param <T> the type of required data
- * @param context the context to test
- * @param def the definition of the entry to seek in context
- * @return the value from the context
- * @throws IllegalArgumentException if the entry is not found in context.
- */
- public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException {
-
- T value = def.getContextValue(context);
-
- if (value == null) {
- throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context);
- }
-
- return value;
- }
-
- /**
- * Convinient method to apply more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void applyDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.applyDataBinding(binding);
- }
- }
- /**
- * Convinient method to apply more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void applyDataBinding(JAXXObject src, Collection<String> bindings) {
- for (String binding : bindings) {
- src.applyDataBinding(binding);
- }
- }
-
- /**
- * Convinient method to process more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void processDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.processDataBinding(binding);
- }
- }
-
- /**
- * Convinient method to remove more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void removeDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.removeDataBinding(binding);
- }
- }
-
-// public static ImageIcon createIcon(String path) {
-// java.net.URL imgURL = Util.class.getResource(path);
-// if (imgURL != null) {
-// return new ImageIcon(imgURL);
-// } else {
-// throw new IllegalArgumentException("could not find icon " + path);
-// }
-// }
-
-// /**
-// * @param path the location of icons in root directory icons
-// * @return the icon at {@link #getIconPath()}+path
-// */
-// public static ImageIcon createImageIcon(String path) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + path);
-// }
-//
-// /**
-// * @param key the key of the icon to retreave from {@link UIManager}
-// * @return the icon, or <code>null if no icon found in {@link UIManager}
-// */
-// public static Icon getUIManagerIcon(String key) {
-// return UIManager.getIcon(key);
-// }
-//
-// /**
-// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code>
-// *
-// * @param key the key of the action icon to retreave from {@link UIManager}
-// * @return the icon, or <code>null if no icon found in {@link UIManager}
-// */
-// public static Icon getUIManagerActionIcon(String key) {
-// return getUIManagerIcon("action." + key);
-// }
-//
-// public static ImageIcon createActionIcon(String name) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + "action-" + name + ".png");
-// }
-//
-// public static ImageIcon createI18nIcon(String name) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + "i18n/" + name + ".png");
-// }
-
- /**
- * detects all PropertychangedListener added by Jaxx uis
- * (should be a {@link DataBindingListener}
- *
- * @param propertyNames the array of property names to find
- * @param listeners the array of listeners to filter
- * @return the filtered listeners
- */
- public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) {
- if (listeners == null || listeners.length == 0) {
- return new PropertyChangeListener[0];
- }
- List<String> pNames = Arrays.asList(propertyNames);
-
- List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>();
-
- for (PropertyChangeListener listener : listeners) {
- String pName = null;
- PropertyChangeListenerProxy plistener = null;
- if (listener instanceof PropertyChangeListenerProxy) {
- plistener = (PropertyChangeListenerProxy) listener;
- if (!pNames.contains(plistener.getPropertyName())) {
- // not on the good property
- continue;
- }
- listener = (PropertyChangeListener) plistener.getListener();
- pName = plistener.getPropertyName();
- }
- if (plistener != null && pName != null && listener instanceof DataBindingListener) {
- if (log.isDebugEnabled()) {
- log.debug("find config listener to remove [" + pName + "] : " + listener);
- }
- toRemove.add(plistener);
- //toRemove.add(listener);
- }
- }
- return toRemove.toArray(new PropertyChangeListener[toRemove.size()]);
- }
-
-// private static String getIconPath() {
-// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY);
-// if (iconPath == null) {
-// iconPath = DEFAULT_ICON_PATH;
-// } else {
-// if (!iconPath.endsWith("/")) {
-// iconPath += "/";
-// }
-// }
-// return iconPath;
-// }
+@Deprecated // since 2.0.4-XXX, will be removed
+public class Util extends JAXXUtil{
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -21,7 +21,7 @@
package jaxx.runtime.context;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -248,7 +248,7 @@
}
public void removeJaxxPropertyChangeListener() {
- PropertyChangeListener[] toRemove = Util.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
+ PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
if (toRemove == null || toRemove.length == 0) {
return;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -22,7 +22,7 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -47,7 +47,7 @@
/**
* entry of the parent context
*/
- protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = Util.newContextEntryDef(JAXXContext.class);
+ protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = JAXXUtil.newContextEntryDef(JAXXContext.class);
/**
* Logger
*/
@@ -194,7 +194,7 @@
// }
protected JAXXContextEntryDef<?> getKey(String name, Class<?> klass) {
- return Util.newContextEntryDef(name, klass);
+ return JAXXUtil.newContextEntryDef(name, klass);
}
@SuppressWarnings({"unchecked"})
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -23,7 +23,7 @@
import javax.swing.JTree;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.JAXXContextEntryDef;
/**
@@ -71,13 +71,13 @@
public NavigationTreeContextHelper(String prefix) {
this.prefix = prefix;
- treeContextEntry = Util.newContextEntryDef(prefix + "-tree", JTree.class);
- treeModelContextEntry = Util.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class);
- treeHandlerContextEntry = Util.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class);
- selectedBeanContextEntry = Util.newContextEntryDef(prefix + "-selected-bean", Object.class);
- selectedNodeContextEntry = Util.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class);
- selectedPathContextEntry = Util.newContextEntryDef(prefix + "-selected-path", String.class);
-// selectedUIContextEntry = Util.newContextEntryDef(prefix + "-selected-ui", Component.class);
+ treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class);
+ treeModelContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class);
+ treeHandlerContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class);
+ selectedBeanContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-bean", Object.class);
+ selectedNodeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class);
+ selectedPathContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-path", String.class);
+// selectedUIContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-ui", Component.class);
}
public String getPrefix() {
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -33,10 +33,10 @@
@Test
public void testGetEventListener() {
count = 0;
- DocumentListener listener = (DocumentListener) Util.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
+ DocumentListener listener = (DocumentListener) JAXXUtil.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
listener.insertUpdate(null);
Assert.assertEquals(count, 1);
- DocumentListener listener2 = (DocumentListener) Util.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
+ DocumentListener listener2 = (DocumentListener) JAXXUtil.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
listener2.removeUpdate(null);
Assert.assertEquals(count, 2);
//assertTrue("Received two different event listeners despite using identical parameters", listener == listener2);
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -20,7 +20,7 @@
*/
package jaxx.runtime.swing.navigation;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.DefaultJAXXContext;
import jaxx.runtime.JAXXContext;
import org.junit.Assert;
@@ -164,10 +164,10 @@
NavigationTreeNode sonSonNode;
NavigationTreeNode sonSonSonNode;
- builder.build(rootNode, (String) null, Util.newContextEntryDef("name", String.class), "name", null, null);
- builder.build(rootNode, (String) null, Util.newContextEntryDef("name2", String.class), "name2", null, null);
+ builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef("name", String.class), "name", null, null);
+ builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef("name2", String.class), "name2", null, null);
- sonNode = builder.build(rootNode, (String) null, Util.newContextEntryDef(Model.class), "model", null, null);
+ sonNode = builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef(Model.class), "model", null, null);
builder.build(sonNode, (String) null, "../name", "name", null, null);
builder.build(sonNode, (String) null, "../integerValue", "integerValue", null, null);
@@ -286,7 +286,7 @@
NavigationTreeNode sonSonSonNode;
// first son is a list of models
- sonNode = builder.build(rootNode, (String) null, Util.newListContextEntryDef("models"), "models", null, null);
+ sonNode = builder.build(rootNode, (String) null, JAXXUtil.newListContextEntryDef("models"), "models", null, null);
// first son son is a model
sonSonNode = builder.build(sonNode, (String) null, "..[1]", "0", null, null);
Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java
===================================================================
--- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java 2010-01-29 16:58:54 UTC (rev 1725)
@@ -23,7 +23,7 @@
import jaxx.runtime.Base64Coder;
import jaxx.compiler.JAXXCompiler;
import jaxx.runtime.JAXXObjectDescriptor;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -48,7 +48,7 @@
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
- descriptor2 = Util.decodeJAXXObjectDescriptor(data);
+ descriptor2 = JAXXUtil.decodeJAXXObjectDescriptor(data);
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
@@ -58,7 +58,7 @@
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
- descriptor2 = Util.decodeCompressedJAXXObjectDescriptor(data);
+ descriptor2 = JAXXUtil.decodeCompressedJAXXObjectDescriptor(data);
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
Modified: trunk/src/site/rst/BeanValidator.rst
===================================================================
--- trunk/src/site/rst/BeanValidator.rst 2010-01-29 15:49:15 UTC (rev 1724)
+++ trunk/src/site/rst/BeanValidator.rst 2010-01-29 16:58:54 UTC (rev 1725)
@@ -170,7 +170,7 @@
::
- jaxx.runtime.Util.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
+ jaxx.runtime.JAXXUtil.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
On obtiendra si une erreur de conversion intervient, une erreur dont le libellé est de la forme *error.convertor.XXX*
1
0
Author: sletellier
Date: 2010-01-29 16:49:15 +0100 (Fri, 29 Jan 2010)
New Revision: 1724
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
Removed:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
Modified:
trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java
trunk/jaxx-compiler/src/site/rst/BeanValidator.rst
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java
trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java
trunk/src/site/rst/BeanValidator.rst
Log:
Revert
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -460,8 +460,8 @@
MethodDescriptor addMethod = handler.getAddMethod();
ClassDescriptor listenerClass = addMethod.getParameterTypes()[0];
//TC-20091026 use 'this' instead of root object javaCode
- //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple name
- return getJavaCode() + '.' + addMethod.getName() + "(JAXXUtil.getEventListener(" + listenerClass.getSimpleName() + ".class, " +
+ //TC-20091105 Util.getEventListener is generic, no more need cast and use simple name
+ return getJavaCode() + '.' + addMethod.getName() + "(Util.getEventListener(" + listenerClass.getSimpleName() + ".class, " +
TypeManager.getJavaCode(handler.getListenerMethod().getName()) + ", this, " +
TypeManager.getJavaCode(compiler.getEventHandlerMethodName(handler)) + "));" + JAXXCompiler.getLineSeparator();
}
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -127,7 +127,7 @@
*/
protected final IDHelper idHelper;
/**
- * Binding JAXXUtil
+ * Binding Util
*/
protected final DataBindingHelper bindingHelper;
/**
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -651,7 +651,7 @@
"jaxx.runtime.swing.HBox",
"jaxx.runtime.swing.VBox",
"jaxx.runtime.swing.Table",
- "jaxx.runtime.JAXXUtil",
+ "jaxx.runtime.Util",
"jaxx.runtime.SwingUtil",
"static org.nuiton.i18n.I18n._",
"static jaxx.runtime.SwingUtil.createImageIcon")
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -37,7 +37,7 @@
import jaxx.compiler.tags.DefaultObjectHandler;
import jaxx.compiler.tags.TagManager;
import jaxx.compiler.types.TypeManager;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -620,12 +620,12 @@
}
String code = objectCode + (eventInfo.getModelName() != null ? ".get" + StringUtils.capitalize(eventInfo.getModelName()) + "()" : "");
result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator());
- //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
- result.append(code).append('.').append(eventInfo.getAddMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
+ //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
+ result.append(code).append('.').append(eventInfo.getAddMethod()).append("( Util.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
result.append(JAXXCompiler.getLineSeparator());
if (eventInfo.getModelName() != null) {
result.append(getAddMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()),
- JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + (compiler.getOutputClassName() + ".this") + ", " + constantId + ")",
+ Util.class.getSimpleName() + ".getDataBindingUpdateListener(" + (compiler.getOutputClassName() + ".this") + ", " + constantId + ")",
compiler));
}
return result.toString();
@@ -696,12 +696,12 @@
result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol);
//TC-20091105 test if $target is not null
result.append("if ($target != null) {").append(eol);
- //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
- result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
+ //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
+ result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( Util.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
result.append("}").append(eol);
if (eventInfo.getModelName() != null) {
result.append(getRemoveMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()),
- JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this, " + constantId + ")",
+ Util.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this, " + constantId + ")",
compiler));
}
return result.toString();
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -194,7 +194,7 @@
*
*/
protected static final JavaMethod GET_JAXX_OBJECT_DESCRIPTOR_METHOD = newMethod(PUBLIC | STATIC, "JAXXObjectDescriptor", METHOD_NAME_$GET_JAXXOBJECT_DESCRIPTOR,
- "return JAXXUtil.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false);
+ "return Util.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false);
/**
*
*/
@@ -624,7 +624,7 @@
}
}
if (!superclassIsJAXXObject) {
- code.append(JAXXUtil.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");");
+ code.append(Util.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");");
code.append(eol);
}
code.append(METHOD_NAME_$INITIALIZE + "();");
@@ -708,7 +708,7 @@
if (bindings.length > 0) {
result.append(eol).append("// apply ").append(bindings.length).append(" data bindings").append(eol);
- result.append(JAXXUtil.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol);
+ result.append(Util.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol);
}
bindings = compiler.getBindingHelper().getSimpleBindings();
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -133,7 +133,7 @@
for (FieldDescriptor field : fields) {
if (field.getName().equals(lhs)) {
//lhs.substring(lhs.lastIndexOf(".") + 1);
- node.firstToken.image = "jaxx.runtime.JAXXUtil.assignment(" + node.firstToken.image;
+ node.firstToken.image = "jaxx.runtime.Util.assignment(" + node.firstToken.image;
String outputClassName = compiler.getOutputClassName();
node.lastToken.image = node.lastToken.image + ", \"" + lhs + "\", " + outputClassName + ".this)";
}
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -337,13 +337,13 @@
// }
// String code = objectCode + (eventInfo.modelName != null ? ".get" + StringUtils.capitalize(eventInfo.modelName) + "()" : "");
// result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator());
-// //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
-// result.append(code).append('.').append(eventInfo.addMethod).append("( JAXXUtil.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
+// //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
+// result.append(code).append('.').append(eventInfo.addMethod).append("( Util.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
// result.append(JAXXCompiler.getLineSeparator());
// if (eventInfo.modelName != null) {
// result.append(getAddMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName),
-// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this , " + dataBinding + ")",
-//// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this , \"" + dataBinding + "\")",
+// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this , " + dataBinding + ")",
+//// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this , \"" + dataBinding + "\")",
// compiler));
// }
// return result.toString();
@@ -407,14 +407,14 @@
// result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol);
// //TC-20091105 test if $target is not null
// result.append("if ($target != null) {").append(eol);
-// //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
-// result.append(" $target.").append(eventInfo.removeMethod).append("( JAXXUtil.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
+// //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
+// result.append(" $target.").append(eventInfo.removeMethod).append("( Util.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
// result.append("}").append(eol);
// if (eventInfo.modelName != null) {
//// String bi = dataBinding.startsWith("this.") ? dataBinding : ("\"" + dataBinding + "\"");
// result.append(getRemoveMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName),
-// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this, " + dataBinding + ")",
-//// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")",
+// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this, " + dataBinding + ")",
+//// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")",
// compiler));
// }
// return result.toString();
Modified: trunk/jaxx-compiler/src/site/rst/BeanValidator.rst
===================================================================
--- trunk/jaxx-compiler/src/site/rst/BeanValidator.rst 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-compiler/src/site/rst/BeanValidator.rst 2010-01-29 15:49:15 UTC (rev 1724)
@@ -170,7 +170,7 @@
::
- jaxx.runtime.JAXXUtil.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
+ jaxx.runtime.Util.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
On obtiendra si une erreur de conversion intervient, une erreur dont le libellé est de la forme *error.convertor.XXX*
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -29,7 +29,7 @@
import java.util.Properties;
import jaxx.demo.component.jaxx.navigation.FullNavigationTreeDemo;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -214,7 +214,7 @@
};
public void removeJaxxPropertyChangeListener() {
- PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
+ PropertyChangeListener[] toRemove = Util.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
if (toRemove == null || toRemove.length == 0) {
return;
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -37,7 +37,7 @@
import jaxx.demo.fun.LabelStyleDemo;
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
@@ -191,7 +191,7 @@
/**
* la definition de l'unqiue object a partage
*/
- static private final JAXXContextEntryDef<DemoConfig> def = JAXXUtil.newContextEntryDef(DemoConfig.class);
+ static private final JAXXContextEntryDef<DemoConfig> def = Util.newContextEntryDef(DemoConfig.class);
/**
* la pile des noeuds parent
*/
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -21,7 +21,7 @@
package jaxx.demo;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import jaxx.runtime.context.DefaultApplicationContext;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.context.JAXXInitialContext;
@@ -57,7 +57,7 @@
* to use log facility, just put in your code: log.info(\"...\");
*/
static private Log log = LogFactory.getLog(DemoUIHandler.class);
- static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = JAXXUtil.newContextEntryDef("mainui", DemoUI.class);
+ static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = Util.newContextEntryDef("mainui", DemoUI.class);
/**
* Methode pour initialiser l'ui principale sans l'afficher.
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -22,7 +22,7 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
@@ -63,11 +63,11 @@
/**
* where the movies are hold in context
*/
- static public final JAXXContextEntryDef<List<Movie>> MOVIES = JAXXUtil.newListContextEntryDef("movies");
+ static public final JAXXContextEntryDef<List<Movie>> MOVIES = Util.newListContextEntryDef("movies");
/**
* where the actors are hold in context
*/
- static public final JAXXContextEntryDef<List<People>> ACTORS = JAXXUtil.newListContextEntryDef("actors");
+ static public final JAXXContextEntryDef<List<People>> ACTORS = Util.newListContextEntryDef("actors");
protected FullNavigationTreeModelBuilder builder;
public FullNavigationTreeHelper() {
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -1,516 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime;
-
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeListenerProxy;
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.*;
-
-public class JAXXUtil {
-
- // public static final String DEFAULT_ICON_PATH = "/icons/";
- // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path";
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(JAXXUtil.class);
- public static final String PARENT = "parent";
- // Maps root objects to lists of event listeners
- private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
- private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
-
- private static class EventListenerDescriptor {
-
- Class<?> listenerClass;
- String listenerMethodName;
- String methodName;
- Object eventListener;
- }
-
- /**
- * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping
- * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField
- * for the rationale behind this (admittedly ugly) approach.
- *
- * @param descriptor descriptor to decode
- * @return the dedoced descriptor
- */
- public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) {
- try {
- return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false);
- /*byte[] data = new byte[descriptor.length()];
- // copy low-order bytes into the array. The high-order bytes should all be zero.
- System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
- //descriptor.getBytes(0, descriptor.length(), data, 0);
- ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
- return (JAXXObjectDescriptor) in.readObject();*/
- } catch (IOException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- }
- }
-
- public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) {
- try {
- return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true);
-
- /*byte[] data = new byte[descriptor.length()];
- // copy low-order bytes into the array. The high-order bytes should all be zero.
- System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
- //descriptor.getBytes(0, descriptor.length(), data, 0);
- ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data)));
- return (JAXXObjectDescriptor) in.readObject();*/
- } catch (IOException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- }
- }
-
- public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
- return newContextEntryDef(null, klass);
- }
-
- public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
- return new JAXXContextEntryDef<O>(name, klass);
- }
-
- public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
- return newListContextEntryDef(null);
- }
-
- public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
- Class<List<O>> castList = JAXXUtil.castList();
- JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList);
- return contextEntryDef;
- }
-
-// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) {
-// bindings.put(binding.getId(), binding);
-//// binding.applyDataBinding();
-//// binding.processDataBinding();
-// return binding;
-// }
-
-// /**
-// * Return parent's container corresponding to the Class clazz
-// *
-// * @param <O> type of container to obtain from context
-// * @param top the top container
-// * @param clazz desired
-// * @return parent's container
-// */
-// @SuppressWarnings({"unchecked"})
-// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
-// if (top == null) {
-// throw new IllegalArgumentException("top parameter can not be null");
-// }
-// if (!Container.class.isAssignableFrom(top.getClass())) {
-// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class);
-// }
-// Container parent = ((Container) top).getParent();
-// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) {
-// parent = getParentContainer(parent, clazz);
-// }
-// return (O) parent;
-// }
-
- @SuppressWarnings({"unchecked"})
- protected static <O> Class<List<O>> castList() {
- return (Class<List<O>>) Collections.emptyList().getClass();
- }
-
- /**
- * Method to initialize the context of a ui.
- *
- * @param ui the ui
- * @param parentContext the context to set in ui
- */
- public static void initContext(JAXXObject ui, JAXXContext parentContext) {
-
- if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) {
- ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui);
- } else {
- ui.setContextValue(parentContext);
- }
- // if parentContext is a JAXXObject then
- // add an special parent entry to can go up
- if (parentContext instanceof JAXXObject) {
- ui.setContextValue(parentContext, PARENT);
- }
- }
-
- public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
- WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
- List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
- if (descriptors == null) {
- descriptors = new ArrayList<EventListenerDescriptor>();
- eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
- } else {
- for (EventListenerDescriptor descriptor : descriptors) {
- if (listenerClass == descriptor.listenerClass &&
- (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
- methodName.equals(descriptor.methodName)) {
- return (E) descriptor.eventListener;
- }
- }
- }
-
- // else we need to create a new listener
- final EventListenerDescriptor descriptor = new EventListenerDescriptor();
- descriptor.listenerClass = listenerClass;
- descriptor.listenerMethodName = listenerMethodName;
- descriptor.methodName = methodName;
- try {
- final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
- Method listenerMethod = null;
- if (listenerMethodName != null) {
- for (Method listenerMethod1 : listenerMethods) {
- if ((listenerMethod1).getName().equals(listenerMethodName)) {
- listenerMethod = listenerMethod1;
- break;
- }
- }
- }
- if (listenerMethodName != null && listenerMethod == null) {
- throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
- }
- Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes();
- Class<?> methodContainerClass = methodContainer.getClass();
- final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
- descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
- new Class<?>[]{listenerClass},
- new InvocationHandler() {
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) {
- String methodName = method.getName();
- if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
- try {
- targetMethod.setAccessible(true);
- return targetMethod.invoke(methodContainer, args);
- } catch (IllegalAccessException e) {
- throw new RuntimeException("could not invoke on container " + methodContainer, e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
- if (methodName.equals("toString")) {
- return toString();
- }
- if (methodName.equals("equals")) {
- return descriptor.eventListener == args[0];
- }
- if (methodName.equals("hashCode")) {
- return hashCode();
- }
- return null;
- }
- });
- descriptors.add(descriptor);
- return (E) descriptor.eventListener;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) {
- return getEventListener(listenerClass, null, methodContainer, methodName);
- }
-
- public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) {
- WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object);
- List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get();
- if (listeners == null) {
- listeners = new ArrayList<DataBindingUpdateListener>();
- dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners));
- } else {
- for (DataBindingUpdateListener listener : listeners) {
- if (bindingName.equals(listener.getBindingName())) {
- return listener;
- }
- }
- }
- DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName);
- listeners.add(listener);
- return listener;
- }
-
-// public static void setComponentWidth(Component component, int width) {
-// component.setSize(width, component.getHeight());
-// if (component instanceof JComponent) {
-// JComponent jcomponent = (JComponent) component;
-// jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height));
-// jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height));
-// if (jcomponent.isDisplayable()) {
-// jcomponent.revalidate();
-// }
-// }
-// }
-
-// public static void setComponentHeight(Component component, int height) {
-// component.setSize(component.getWidth(), height);
-// if (component instanceof JComponent) {
-// JComponent jcomponent = (JComponent) component;
-// jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height));
-// jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height));
-// if (jcomponent.isDisplayable()) {
-// jcomponent.revalidate();
-// }
-// }
-// }
-
- public static boolean assignment(boolean value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static byte assignment(byte value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static short assignment(short value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static int assignment(int value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static long assignment(long value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static float assignment(float value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static double assignment(double value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static char assignment(char value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- /**
- * Compute the string representation of an object.
- * <p/>
- * Return empty string if given object is null
- *
- * @param value the value to write
- * @return the string representation of the given object or an empty string if object is null.
- */
- public static String getStringValue(Object value) {
- String result;
- result = value == null ? "" : value.toString();
- return result;
- }
-
- /**
- * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found.
- * <p/>
- * If entry is found, return his value in context.
- *
- * @param <T> the type of required data
- * @param context the context to test
- * @param def the definition of the entry to seek in context
- * @return the value from the context
- * @throws IllegalArgumentException if the entry is not found in context.
- */
- public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException {
-
- T value = def.getContextValue(context);
-
- if (value == null) {
- throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context);
- }
-
- return value;
- }
-
- /**
- * Convinient method to apply more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void applyDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.applyDataBinding(binding);
- }
- }
- /**
- * Convinient method to apply more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void applyDataBinding(JAXXObject src, Collection<String> bindings) {
- for (String binding : bindings) {
- src.applyDataBinding(binding);
- }
- }
-
- /**
- * Convinient method to process more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void processDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.processDataBinding(binding);
- }
- }
-
- /**
- * Convinient method to remove more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void removeDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.removeDataBinding(binding);
- }
- }
-
-// public static ImageIcon createIcon(String path) {
-// java.net.URL imgURL = JAXXUtil.class.getResource(path);
-// if (imgURL != null) {
-// return new ImageIcon(imgURL);
-// } else {
-// throw new IllegalArgumentException("could not find icon " + path);
-// }
-// }
-
-// /**
-// * @param path the location of icons in root directory icons
-// * @return the icon at {@link #getIconPath()}+path
-// */
-// public static ImageIcon createImageIcon(String path) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + path);
-// }
-//
-// /**
-// * @param key the key of the icon to retreave from {@link UIManager}
-// * @return the icon, or <code>null if no icon found in {@link UIManager}
-// */
-// public static Icon getUIManagerIcon(String key) {
-// return UIManager.getIcon(key);
-// }
-//
-// /**
-// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code>
-// *
-// * @param key the key of the action icon to retreave from {@link UIManager}
-// * @return the icon, or <code>null if no icon found in {@link UIManager}
-// */
-// public static Icon getUIManagerActionIcon(String key) {
-// return getUIManagerIcon("action." + key);
-// }
-//
-// public static ImageIcon createActionIcon(String name) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + "action-" + name + ".png");
-// }
-//
-// public static ImageIcon createI18nIcon(String name) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + "i18n/" + name + ".png");
-// }
-
- /**
- * detects all PropertychangedListener added by Jaxx uis
- * (should be a {@link DataBindingListener}
- *
- * @param propertyNames the array of property names to find
- * @param listeners the array of listeners to filter
- * @return the filtered listeners
- */
- public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) {
- if (listeners == null || listeners.length == 0) {
- return new PropertyChangeListener[0];
- }
- List<String> pNames = Arrays.asList(propertyNames);
-
- List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>();
-
- for (PropertyChangeListener listener : listeners) {
- String pName = null;
- PropertyChangeListenerProxy plistener = null;
- if (listener instanceof PropertyChangeListenerProxy) {
- plistener = (PropertyChangeListenerProxy) listener;
- if (!pNames.contains(plistener.getPropertyName())) {
- // not on the good property
- continue;
- }
- listener = (PropertyChangeListener) plistener.getListener();
- pName = plistener.getPropertyName();
- }
- if (plistener != null && pName != null && listener instanceof DataBindingListener) {
- if (log.isDebugEnabled()) {
- log.debug("find config listener to remove [" + pName + "] : " + listener);
- }
- toRemove.add(plistener);
- //toRemove.add(listener);
- }
- }
- return toRemove.toArray(new PropertyChangeListener[toRemove.size()]);
- }
-
-// private static String getIconPath() {
-// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY);
-// if (iconPath == null) {
-// iconPath = DEFAULT_ICON_PATH;
-// } else {
-// if (!iconPath.endsWith("/")) {
-// iconPath += "/";
-// }
-// }
-// return iconPath;
-// }
-}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -79,7 +79,7 @@
* @author tony
* @since 1.2
*/
-public class SwingUtil extends JAXXUtil {
+public class SwingUtil extends Util {
/**
* to use log facility, just put in your code: log.info(\"...\");
@@ -861,7 +861,7 @@
}
public static ImageIcon createIcon(String path) {
- java.net.URL imgURL = JAXXUtil.class.getResource(path);
+ java.net.URL imgURL = Util.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -0,0 +1,516 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime;
+
+import jaxx.runtime.context.JAXXContextEntryDef;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeListenerProxy;
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.*;
+
+public class Util {
+
+ // public static final String DEFAULT_ICON_PATH = "/icons/";
+ // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path";
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(Util.class);
+ public static final String PARENT = "parent";
+ // Maps root objects to lists of event listeners
+ private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
+ private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
+
+ private static class EventListenerDescriptor {
+
+ Class<?> listenerClass;
+ String listenerMethodName;
+ String methodName;
+ Object eventListener;
+ }
+
+ /**
+ * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping
+ * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField
+ * for the rationale behind this (admittedly ugly) approach.
+ *
+ * @param descriptor descriptor to decode
+ * @return the dedoced descriptor
+ */
+ public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) {
+ try {
+ return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false);
+ /*byte[] data = new byte[descriptor.length()];
+ // copy low-order bytes into the array. The high-order bytes should all be zero.
+ System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
+ //descriptor.getBytes(0, descriptor.length(), data, 0);
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
+ return (JAXXObjectDescriptor) in.readObject();*/
+ } catch (IOException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ }
+ }
+
+ public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) {
+ try {
+ return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true);
+
+ /*byte[] data = new byte[descriptor.length()];
+ // copy low-order bytes into the array. The high-order bytes should all be zero.
+ System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
+ //descriptor.getBytes(0, descriptor.length(), data, 0);
+ ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data)));
+ return (JAXXObjectDescriptor) in.readObject();*/
+ } catch (IOException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ }
+ }
+
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
+ return newContextEntryDef(null, klass);
+ }
+
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
+ return new JAXXContextEntryDef<O>(name, klass);
+ }
+
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
+ return newListContextEntryDef(null);
+ }
+
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
+ Class<List<O>> castList = Util.castList();
+ JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList);
+ return contextEntryDef;
+ }
+
+// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) {
+// bindings.put(binding.getId(), binding);
+//// binding.applyDataBinding();
+//// binding.processDataBinding();
+// return binding;
+// }
+
+// /**
+// * Return parent's container corresponding to the Class clazz
+// *
+// * @param <O> type of container to obtain from context
+// * @param top the top container
+// * @param clazz desired
+// * @return parent's container
+// */
+// @SuppressWarnings({"unchecked"})
+// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
+// if (top == null) {
+// throw new IllegalArgumentException("top parameter can not be null");
+// }
+// if (!Container.class.isAssignableFrom(top.getClass())) {
+// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class);
+// }
+// Container parent = ((Container) top).getParent();
+// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) {
+// parent = getParentContainer(parent, clazz);
+// }
+// return (O) parent;
+// }
+
+ @SuppressWarnings({"unchecked"})
+ protected static <O> Class<List<O>> castList() {
+ return (Class<List<O>>) Collections.emptyList().getClass();
+ }
+
+ /**
+ * Method to initialize the context of a ui.
+ *
+ * @param ui the ui
+ * @param parentContext the context to set in ui
+ */
+ public static void initContext(JAXXObject ui, JAXXContext parentContext) {
+
+ if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) {
+ ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui);
+ } else {
+ ui.setContextValue(parentContext);
+ }
+ // if parentContext is a JAXXObject then
+ // add an special parent entry to can go up
+ if (parentContext instanceof JAXXObject) {
+ ui.setContextValue(parentContext, PARENT);
+ }
+ }
+
+ public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
+ WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
+ List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
+ if (descriptors == null) {
+ descriptors = new ArrayList<EventListenerDescriptor>();
+ eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
+ } else {
+ for (EventListenerDescriptor descriptor : descriptors) {
+ if (listenerClass == descriptor.listenerClass &&
+ (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
+ methodName.equals(descriptor.methodName)) {
+ return (E) descriptor.eventListener;
+ }
+ }
+ }
+
+ // else we need to create a new listener
+ final EventListenerDescriptor descriptor = new EventListenerDescriptor();
+ descriptor.listenerClass = listenerClass;
+ descriptor.listenerMethodName = listenerMethodName;
+ descriptor.methodName = methodName;
+ try {
+ final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
+ Method listenerMethod = null;
+ if (listenerMethodName != null) {
+ for (Method listenerMethod1 : listenerMethods) {
+ if ((listenerMethod1).getName().equals(listenerMethodName)) {
+ listenerMethod = listenerMethod1;
+ break;
+ }
+ }
+ }
+ if (listenerMethodName != null && listenerMethod == null) {
+ throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
+ }
+ Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes();
+ Class<?> methodContainerClass = methodContainer.getClass();
+ final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
+ descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
+ new Class<?>[]{listenerClass},
+ new InvocationHandler() {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) {
+ String methodName = method.getName();
+ if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
+ try {
+ targetMethod.setAccessible(true);
+ return targetMethod.invoke(methodContainer, args);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("could not invoke on container " + methodContainer, e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (methodName.equals("toString")) {
+ return toString();
+ }
+ if (methodName.equals("equals")) {
+ return descriptor.eventListener == args[0];
+ }
+ if (methodName.equals("hashCode")) {
+ return hashCode();
+ }
+ return null;
+ }
+ });
+ descriptors.add(descriptor);
+ return (E) descriptor.eventListener;
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) {
+ return getEventListener(listenerClass, null, methodContainer, methodName);
+ }
+
+ public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) {
+ WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object);
+ List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get();
+ if (listeners == null) {
+ listeners = new ArrayList<DataBindingUpdateListener>();
+ dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners));
+ } else {
+ for (DataBindingUpdateListener listener : listeners) {
+ if (bindingName.equals(listener.getBindingName())) {
+ return listener;
+ }
+ }
+ }
+ DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName);
+ listeners.add(listener);
+ return listener;
+ }
+
+// public static void setComponentWidth(Component component, int width) {
+// component.setSize(width, component.getHeight());
+// if (component instanceof JComponent) {
+// JComponent jcomponent = (JComponent) component;
+// jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height));
+// jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height));
+// if (jcomponent.isDisplayable()) {
+// jcomponent.revalidate();
+// }
+// }
+// }
+
+// public static void setComponentHeight(Component component, int height) {
+// component.setSize(component.getWidth(), height);
+// if (component instanceof JComponent) {
+// JComponent jcomponent = (JComponent) component;
+// jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height));
+// jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height));
+// if (jcomponent.isDisplayable()) {
+// jcomponent.revalidate();
+// }
+// }
+// }
+
+ public static boolean assignment(boolean value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static byte assignment(byte value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static short assignment(short value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static int assignment(int value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static long assignment(long value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static float assignment(float value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static double assignment(double value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static char assignment(char value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ /**
+ * Compute the string representation of an object.
+ * <p/>
+ * Return empty string if given object is null
+ *
+ * @param value the value to write
+ * @return the string representation of the given object or an empty string if object is null.
+ */
+ public static String getStringValue(Object value) {
+ String result;
+ result = value == null ? "" : value.toString();
+ return result;
+ }
+
+ /**
+ * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found.
+ * <p/>
+ * If entry is found, return his value in context.
+ *
+ * @param <T> the type of required data
+ * @param context the context to test
+ * @param def the definition of the entry to seek in context
+ * @return the value from the context
+ * @throws IllegalArgumentException if the entry is not found in context.
+ */
+ public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException {
+
+ T value = def.getContextValue(context);
+
+ if (value == null) {
+ throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context);
+ }
+
+ return value;
+ }
+
+ /**
+ * Convinient method to apply more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void applyDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.applyDataBinding(binding);
+ }
+ }
+ /**
+ * Convinient method to apply more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void applyDataBinding(JAXXObject src, Collection<String> bindings) {
+ for (String binding : bindings) {
+ src.applyDataBinding(binding);
+ }
+ }
+
+ /**
+ * Convinient method to process more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void processDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.processDataBinding(binding);
+ }
+ }
+
+ /**
+ * Convinient method to remove more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void removeDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.removeDataBinding(binding);
+ }
+ }
+
+// public static ImageIcon createIcon(String path) {
+// java.net.URL imgURL = Util.class.getResource(path);
+// if (imgURL != null) {
+// return new ImageIcon(imgURL);
+// } else {
+// throw new IllegalArgumentException("could not find icon " + path);
+// }
+// }
+
+// /**
+// * @param path the location of icons in root directory icons
+// * @return the icon at {@link #getIconPath()}+path
+// */
+// public static ImageIcon createImageIcon(String path) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + path);
+// }
+//
+// /**
+// * @param key the key of the icon to retreave from {@link UIManager}
+// * @return the icon, or <code>null if no icon found in {@link UIManager}
+// */
+// public static Icon getUIManagerIcon(String key) {
+// return UIManager.getIcon(key);
+// }
+//
+// /**
+// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code>
+// *
+// * @param key the key of the action icon to retreave from {@link UIManager}
+// * @return the icon, or <code>null if no icon found in {@link UIManager}
+// */
+// public static Icon getUIManagerActionIcon(String key) {
+// return getUIManagerIcon("action." + key);
+// }
+//
+// public static ImageIcon createActionIcon(String name) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + "action-" + name + ".png");
+// }
+//
+// public static ImageIcon createI18nIcon(String name) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + "i18n/" + name + ".png");
+// }
+
+ /**
+ * detects all PropertychangedListener added by Jaxx uis
+ * (should be a {@link DataBindingListener}
+ *
+ * @param propertyNames the array of property names to find
+ * @param listeners the array of listeners to filter
+ * @return the filtered listeners
+ */
+ public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) {
+ if (listeners == null || listeners.length == 0) {
+ return new PropertyChangeListener[0];
+ }
+ List<String> pNames = Arrays.asList(propertyNames);
+
+ List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>();
+
+ for (PropertyChangeListener listener : listeners) {
+ String pName = null;
+ PropertyChangeListenerProxy plistener = null;
+ if (listener instanceof PropertyChangeListenerProxy) {
+ plistener = (PropertyChangeListenerProxy) listener;
+ if (!pNames.contains(plistener.getPropertyName())) {
+ // not on the good property
+ continue;
+ }
+ listener = (PropertyChangeListener) plistener.getListener();
+ pName = plistener.getPropertyName();
+ }
+ if (plistener != null && pName != null && listener instanceof DataBindingListener) {
+ if (log.isDebugEnabled()) {
+ log.debug("find config listener to remove [" + pName + "] : " + listener);
+ }
+ toRemove.add(plistener);
+ //toRemove.add(listener);
+ }
+ }
+ return toRemove.toArray(new PropertyChangeListener[toRemove.size()]);
+ }
+
+// private static String getIconPath() {
+// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY);
+// if (iconPath == null) {
+// iconPath = DEFAULT_ICON_PATH;
+// } else {
+// if (!iconPath.endsWith("/")) {
+// iconPath += "/";
+// }
+// }
+// return iconPath;
+// }
+}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -21,7 +21,7 @@
package jaxx.runtime.context;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -248,7 +248,7 @@
}
public void removeJaxxPropertyChangeListener() {
- PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
+ PropertyChangeListener[] toRemove = Util.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
if (toRemove == null || toRemove.length == 0) {
return;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -22,7 +22,7 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -47,7 +47,7 @@
/**
* entry of the parent context
*/
- protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = JAXXUtil.newContextEntryDef(JAXXContext.class);
+ protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = Util.newContextEntryDef(JAXXContext.class);
/**
* Logger
*/
@@ -194,7 +194,7 @@
// }
protected JAXXContextEntryDef<?> getKey(String name, Class<?> klass) {
- return JAXXUtil.newContextEntryDef(name, klass);
+ return Util.newContextEntryDef(name, klass);
}
@SuppressWarnings({"unchecked"})
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -23,7 +23,7 @@
import javax.swing.JTree;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import jaxx.runtime.context.JAXXContextEntryDef;
/**
@@ -71,13 +71,13 @@
public NavigationTreeContextHelper(String prefix) {
this.prefix = prefix;
- treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class);
- treeModelContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class);
- treeHandlerContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class);
- selectedBeanContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-bean", Object.class);
- selectedNodeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class);
- selectedPathContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-path", String.class);
-// selectedUIContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-ui", Component.class);
+ treeContextEntry = Util.newContextEntryDef(prefix + "-tree", JTree.class);
+ treeModelContextEntry = Util.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class);
+ treeHandlerContextEntry = Util.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class);
+ selectedBeanContextEntry = Util.newContextEntryDef(prefix + "-selected-bean", Object.class);
+ selectedNodeContextEntry = Util.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class);
+ selectedPathContextEntry = Util.newContextEntryDef(prefix + "-selected-path", String.class);
+// selectedUIContextEntry = Util.newContextEntryDef(prefix + "-selected-ui", Component.class);
}
public String getPrefix() {
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -33,10 +33,10 @@
@Test
public void testGetEventListener() {
count = 0;
- DocumentListener listener = (DocumentListener) JAXXUtil.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
+ DocumentListener listener = (DocumentListener) Util.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
listener.insertUpdate(null);
Assert.assertEquals(count, 1);
- DocumentListener listener2 = (DocumentListener) JAXXUtil.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
+ DocumentListener listener2 = (DocumentListener) Util.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
listener2.removeUpdate(null);
Assert.assertEquals(count, 2);
//assertTrue("Received two different event listeners despite using identical parameters", listener == listener2);
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -20,7 +20,7 @@
*/
package jaxx.runtime.swing.navigation;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import jaxx.runtime.context.DefaultJAXXContext;
import jaxx.runtime.JAXXContext;
import org.junit.Assert;
@@ -164,10 +164,10 @@
NavigationTreeNode sonSonNode;
NavigationTreeNode sonSonSonNode;
- builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef("name", String.class), "name", null, null);
- builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef("name2", String.class), "name2", null, null);
+ builder.build(rootNode, (String) null, Util.newContextEntryDef("name", String.class), "name", null, null);
+ builder.build(rootNode, (String) null, Util.newContextEntryDef("name2", String.class), "name2", null, null);
- sonNode = builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef(Model.class), "model", null, null);
+ sonNode = builder.build(rootNode, (String) null, Util.newContextEntryDef(Model.class), "model", null, null);
builder.build(sonNode, (String) null, "../name", "name", null, null);
builder.build(sonNode, (String) null, "../integerValue", "integerValue", null, null);
@@ -286,7 +286,7 @@
NavigationTreeNode sonSonSonNode;
// first son is a list of models
- sonNode = builder.build(rootNode, (String) null, JAXXUtil.newListContextEntryDef("models"), "models", null, null);
+ sonNode = builder.build(rootNode, (String) null, Util.newListContextEntryDef("models"), "models", null, null);
// first son son is a model
sonSonNode = builder.build(sonNode, (String) null, "..[1]", "0", null, null);
Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java
===================================================================
--- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java 2010-01-29 15:49:15 UTC (rev 1724)
@@ -23,7 +23,7 @@
import jaxx.runtime.Base64Coder;
import jaxx.compiler.JAXXCompiler;
import jaxx.runtime.JAXXObjectDescriptor;
-import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.Util;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -48,7 +48,7 @@
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
- descriptor2 = JAXXUtil.decodeJAXXObjectDescriptor(data);
+ descriptor2 = Util.decodeJAXXObjectDescriptor(data);
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
@@ -58,7 +58,7 @@
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
- descriptor2 = JAXXUtil.decodeCompressedJAXXObjectDescriptor(data);
+ descriptor2 = Util.decodeCompressedJAXXObjectDescriptor(data);
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
Modified: trunk/src/site/rst/BeanValidator.rst
===================================================================
--- trunk/src/site/rst/BeanValidator.rst 2010-01-29 15:18:50 UTC (rev 1723)
+++ trunk/src/site/rst/BeanValidator.rst 2010-01-29 15:49:15 UTC (rev 1724)
@@ -170,7 +170,7 @@
::
- jaxx.runtime.JAXXUtil.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
+ jaxx.runtime.Util.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
On obtiendra si une erreur de conversion intervient, une erreur dont le libellé est de la forme *error.convertor.XXX*
1
0
Author: sletellier
Date: 2010-01-29 16:18:50 +0100 (Fri, 29 Jan 2010)
New Revision: 1723
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
Removed:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
Modified:
trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java
trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java
trunk/jaxx-compiler/src/site/rst/BeanValidator.rst
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java
trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java
trunk/src/site/rst/BeanValidator.rst
Log:
Evol 929 : Refactor Util to JAXXUtil
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -460,8 +460,8 @@
MethodDescriptor addMethod = handler.getAddMethod();
ClassDescriptor listenerClass = addMethod.getParameterTypes()[0];
//TC-20091026 use 'this' instead of root object javaCode
- //TC-20091105 Util.getEventListener is generic, no more need cast and use simple name
- return getJavaCode() + '.' + addMethod.getName() + "(Util.getEventListener(" + listenerClass.getSimpleName() + ".class, " +
+ //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple name
+ return getJavaCode() + '.' + addMethod.getName() + "(JAXXUtil.getEventListener(" + listenerClass.getSimpleName() + ".class, " +
TypeManager.getJavaCode(handler.getListenerMethod().getName()) + ", this, " +
TypeManager.getJavaCode(compiler.getEventHandlerMethodName(handler)) + "));" + JAXXCompiler.getLineSeparator();
}
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -127,7 +127,7 @@
*/
protected final IDHelper idHelper;
/**
- * Binding Util
+ * Binding JAXXUtil
*/
protected final DataBindingHelper bindingHelper;
/**
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -651,7 +651,7 @@
"jaxx.runtime.swing.HBox",
"jaxx.runtime.swing.VBox",
"jaxx.runtime.swing.Table",
- "jaxx.runtime.Util",
+ "jaxx.runtime.JAXXUtil",
"jaxx.runtime.SwingUtil",
"static org.nuiton.i18n.I18n._",
"static jaxx.runtime.SwingUtil.createImageIcon")
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -37,7 +37,7 @@
import jaxx.compiler.tags.DefaultObjectHandler;
import jaxx.compiler.tags.TagManager;
import jaxx.compiler.types.TypeManager;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -620,12 +620,12 @@
}
String code = objectCode + (eventInfo.getModelName() != null ? ".get" + StringUtils.capitalize(eventInfo.getModelName()) + "()" : "");
result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator());
- //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
- result.append(code).append('.').append(eventInfo.getAddMethod()).append("( Util.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
+ //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
+ result.append(code).append('.').append(eventInfo.getAddMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
result.append(JAXXCompiler.getLineSeparator());
if (eventInfo.getModelName() != null) {
result.append(getAddMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()),
- Util.class.getSimpleName() + ".getDataBindingUpdateListener(" + (compiler.getOutputClassName() + ".this") + ", " + constantId + ")",
+ JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + (compiler.getOutputClassName() + ".this") + ", " + constantId + ")",
compiler));
}
return result.toString();
@@ -696,12 +696,12 @@
result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol);
//TC-20091105 test if $target is not null
result.append("if ($target != null) {").append(eol);
- //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
- result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( Util.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
+ //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
+ result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
result.append("}").append(eol);
if (eventInfo.getModelName() != null) {
result.append(getRemoveMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()),
- Util.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this, " + constantId + ")",
+ JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this, " + constantId + ")",
compiler));
}
return result.toString();
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -194,7 +194,7 @@
*
*/
protected static final JavaMethod GET_JAXX_OBJECT_DESCRIPTOR_METHOD = newMethod(PUBLIC | STATIC, "JAXXObjectDescriptor", METHOD_NAME_$GET_JAXXOBJECT_DESCRIPTOR,
- "return Util.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false);
+ "return JAXXUtil.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false);
/**
*
*/
@@ -624,7 +624,7 @@
}
}
if (!superclassIsJAXXObject) {
- code.append(Util.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");");
+ code.append(JAXXUtil.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");");
code.append(eol);
}
code.append(METHOD_NAME_$INITIALIZE + "();");
@@ -708,7 +708,7 @@
if (bindings.length > 0) {
result.append(eol).append("// apply ").append(bindings.length).append(" data bindings").append(eol);
- result.append(Util.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol);
+ result.append(JAXXUtil.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol);
}
bindings = compiler.getBindingHelper().getSimpleBindings();
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -133,7 +133,7 @@
for (FieldDescriptor field : fields) {
if (field.getName().equals(lhs)) {
//lhs.substring(lhs.lastIndexOf(".") + 1);
- node.firstToken.image = "jaxx.runtime.Util.assignment(" + node.firstToken.image;
+ node.firstToken.image = "jaxx.runtime.JAXXUtil.assignment(" + node.firstToken.image;
String outputClassName = compiler.getOutputClassName();
node.lastToken.image = node.lastToken.image + ", \"" + lhs + "\", " + outputClassName + ".this)";
}
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -337,13 +337,13 @@
// }
// String code = objectCode + (eventInfo.modelName != null ? ".get" + StringUtils.capitalize(eventInfo.modelName) + "()" : "");
// result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator());
-// //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
-// result.append(code).append('.').append(eventInfo.addMethod).append("( Util.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
+// //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
+// result.append(code).append('.').append(eventInfo.addMethod).append("( JAXXUtil.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));");
// result.append(JAXXCompiler.getLineSeparator());
// if (eventInfo.modelName != null) {
// result.append(getAddMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName),
-// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this , " + dataBinding + ")",
-//// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this , \"" + dataBinding + "\")",
+// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this , " + dataBinding + ")",
+//// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this , \"" + dataBinding + "\")",
// compiler));
// }
// return result.toString();
@@ -407,14 +407,14 @@
// result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol);
// //TC-20091105 test if $target is not null
// result.append("if ($target != null) {").append(eol);
-// //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name
-// result.append(" $target.").append(eventInfo.removeMethod).append("( Util.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
+// //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name
+// result.append(" $target.").append(eventInfo.removeMethod).append("( JAXXUtil.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol);
// result.append("}").append(eol);
// if (eventInfo.modelName != null) {
//// String bi = dataBinding.startsWith("this.") ? dataBinding : ("\"" + dataBinding + "\"");
// result.append(getRemoveMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName),
-// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this, " + dataBinding + ")",
-//// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")",
+// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this, " + dataBinding + ")",
+//// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")",
// compiler));
// }
// return result.toString();
Modified: trunk/jaxx-compiler/src/site/rst/BeanValidator.rst
===================================================================
--- trunk/jaxx-compiler/src/site/rst/BeanValidator.rst 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-compiler/src/site/rst/BeanValidator.rst 2010-01-29 15:18:50 UTC (rev 1723)
@@ -170,7 +170,7 @@
::
- jaxx.runtime.Util.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
+ jaxx.runtime.JAXXUtil.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
On obtiendra si une erreur de conversion intervient, une erreur dont le libellé est de la forme *error.convertor.XXX*
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -29,6 +29,7 @@
import java.util.Properties;
import jaxx.demo.component.jaxx.navigation.FullNavigationTreeDemo;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -213,7 +214,7 @@
};
public void removeJaxxPropertyChangeListener() {
- PropertyChangeListener[] toRemove = jaxx.runtime.Util.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
+ PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
if (toRemove == null || toRemove.length == 0) {
return;
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -37,6 +37,7 @@
import jaxx.demo.fun.LabelStyleDemo;
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
@@ -190,7 +191,7 @@
/**
* la definition de l'unqiue object a partage
*/
- static private final JAXXContextEntryDef<DemoConfig> def = jaxx.runtime.Util.newContextEntryDef(DemoConfig.class);
+ static private final JAXXContextEntryDef<DemoConfig> def = JAXXUtil.newContextEntryDef(DemoConfig.class);
/**
* la pile des noeuds parent
*/
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -21,6 +21,7 @@
package jaxx.demo;
import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.DefaultApplicationContext;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.context.JAXXInitialContext;
@@ -56,7 +57,7 @@
* to use log facility, just put in your code: log.info(\"...\");
*/
static private Log log = LogFactory.getLog(DemoUIHandler.class);
- static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = jaxx.runtime.Util.newContextEntryDef("mainui", DemoUI.class);
+ static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = JAXXUtil.newContextEntryDef("mainui", DemoUI.class);
/**
* Methode pour initialiser l'ui principale sans l'afficher.
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -22,7 +22,7 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
@@ -63,11 +63,11 @@
/**
* where the movies are hold in context
*/
- static public final JAXXContextEntryDef<List<Movie>> MOVIES = Util.newListContextEntryDef("movies");
+ static public final JAXXContextEntryDef<List<Movie>> MOVIES = JAXXUtil.newListContextEntryDef("movies");
/**
* where the actors are hold in context
*/
- static public final JAXXContextEntryDef<List<People>> ACTORS = Util.newListContextEntryDef("actors");
+ static public final JAXXContextEntryDef<List<People>> ACTORS = JAXXUtil.newListContextEntryDef("actors");
protected FullNavigationTreeModelBuilder builder;
public FullNavigationTreeHelper() {
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -0,0 +1,516 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime;
+
+import jaxx.runtime.context.JAXXContextEntryDef;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeListenerProxy;
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.*;
+
+public class JAXXUtil {
+
+ // public static final String DEFAULT_ICON_PATH = "/icons/";
+ // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path";
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(JAXXUtil.class);
+ public static final String PARENT = "parent";
+ // Maps root objects to lists of event listeners
+ private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
+ private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
+
+ private static class EventListenerDescriptor {
+
+ Class<?> listenerClass;
+ String listenerMethodName;
+ String methodName;
+ Object eventListener;
+ }
+
+ /**
+ * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping
+ * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField
+ * for the rationale behind this (admittedly ugly) approach.
+ *
+ * @param descriptor descriptor to decode
+ * @return the dedoced descriptor
+ */
+ public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) {
+ try {
+ return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false);
+ /*byte[] data = new byte[descriptor.length()];
+ // copy low-order bytes into the array. The high-order bytes should all be zero.
+ System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
+ //descriptor.getBytes(0, descriptor.length(), data, 0);
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
+ return (JAXXObjectDescriptor) in.readObject();*/
+ } catch (IOException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ }
+ }
+
+ public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) {
+ try {
+ return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true);
+
+ /*byte[] data = new byte[descriptor.length()];
+ // copy low-order bytes into the array. The high-order bytes should all be zero.
+ System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
+ //descriptor.getBytes(0, descriptor.length(), data, 0);
+ ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data)));
+ return (JAXXObjectDescriptor) in.readObject();*/
+ } catch (IOException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ }
+ }
+
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
+ return newContextEntryDef(null, klass);
+ }
+
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
+ return new JAXXContextEntryDef<O>(name, klass);
+ }
+
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
+ return newListContextEntryDef(null);
+ }
+
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
+ Class<List<O>> castList = JAXXUtil.castList();
+ JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList);
+ return contextEntryDef;
+ }
+
+// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) {
+// bindings.put(binding.getId(), binding);
+//// binding.applyDataBinding();
+//// binding.processDataBinding();
+// return binding;
+// }
+
+// /**
+// * Return parent's container corresponding to the Class clazz
+// *
+// * @param <O> type of container to obtain from context
+// * @param top the top container
+// * @param clazz desired
+// * @return parent's container
+// */
+// @SuppressWarnings({"unchecked"})
+// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
+// if (top == null) {
+// throw new IllegalArgumentException("top parameter can not be null");
+// }
+// if (!Container.class.isAssignableFrom(top.getClass())) {
+// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class);
+// }
+// Container parent = ((Container) top).getParent();
+// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) {
+// parent = getParentContainer(parent, clazz);
+// }
+// return (O) parent;
+// }
+
+ @SuppressWarnings({"unchecked"})
+ protected static <O> Class<List<O>> castList() {
+ return (Class<List<O>>) Collections.emptyList().getClass();
+ }
+
+ /**
+ * Method to initialize the context of a ui.
+ *
+ * @param ui the ui
+ * @param parentContext the context to set in ui
+ */
+ public static void initContext(JAXXObject ui, JAXXContext parentContext) {
+
+ if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) {
+ ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui);
+ } else {
+ ui.setContextValue(parentContext);
+ }
+ // if parentContext is a JAXXObject then
+ // add an special parent entry to can go up
+ if (parentContext instanceof JAXXObject) {
+ ui.setContextValue(parentContext, PARENT);
+ }
+ }
+
+ public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
+ WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
+ List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
+ if (descriptors == null) {
+ descriptors = new ArrayList<EventListenerDescriptor>();
+ eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
+ } else {
+ for (EventListenerDescriptor descriptor : descriptors) {
+ if (listenerClass == descriptor.listenerClass &&
+ (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
+ methodName.equals(descriptor.methodName)) {
+ return (E) descriptor.eventListener;
+ }
+ }
+ }
+
+ // else we need to create a new listener
+ final EventListenerDescriptor descriptor = new EventListenerDescriptor();
+ descriptor.listenerClass = listenerClass;
+ descriptor.listenerMethodName = listenerMethodName;
+ descriptor.methodName = methodName;
+ try {
+ final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
+ Method listenerMethod = null;
+ if (listenerMethodName != null) {
+ for (Method listenerMethod1 : listenerMethods) {
+ if ((listenerMethod1).getName().equals(listenerMethodName)) {
+ listenerMethod = listenerMethod1;
+ break;
+ }
+ }
+ }
+ if (listenerMethodName != null && listenerMethod == null) {
+ throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
+ }
+ Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes();
+ Class<?> methodContainerClass = methodContainer.getClass();
+ final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
+ descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
+ new Class<?>[]{listenerClass},
+ new InvocationHandler() {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) {
+ String methodName = method.getName();
+ if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
+ try {
+ targetMethod.setAccessible(true);
+ return targetMethod.invoke(methodContainer, args);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("could not invoke on container " + methodContainer, e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (methodName.equals("toString")) {
+ return toString();
+ }
+ if (methodName.equals("equals")) {
+ return descriptor.eventListener == args[0];
+ }
+ if (methodName.equals("hashCode")) {
+ return hashCode();
+ }
+ return null;
+ }
+ });
+ descriptors.add(descriptor);
+ return (E) descriptor.eventListener;
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) {
+ return getEventListener(listenerClass, null, methodContainer, methodName);
+ }
+
+ public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) {
+ WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object);
+ List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get();
+ if (listeners == null) {
+ listeners = new ArrayList<DataBindingUpdateListener>();
+ dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners));
+ } else {
+ for (DataBindingUpdateListener listener : listeners) {
+ if (bindingName.equals(listener.getBindingName())) {
+ return listener;
+ }
+ }
+ }
+ DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName);
+ listeners.add(listener);
+ return listener;
+ }
+
+// public static void setComponentWidth(Component component, int width) {
+// component.setSize(width, component.getHeight());
+// if (component instanceof JComponent) {
+// JComponent jcomponent = (JComponent) component;
+// jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height));
+// jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height));
+// if (jcomponent.isDisplayable()) {
+// jcomponent.revalidate();
+// }
+// }
+// }
+
+// public static void setComponentHeight(Component component, int height) {
+// component.setSize(component.getWidth(), height);
+// if (component instanceof JComponent) {
+// JComponent jcomponent = (JComponent) component;
+// jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height));
+// jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height));
+// if (jcomponent.isDisplayable()) {
+// jcomponent.revalidate();
+// }
+// }
+// }
+
+ public static boolean assignment(boolean value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static byte assignment(byte value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static short assignment(short value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static int assignment(int value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static long assignment(long value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static float assignment(float value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static double assignment(double value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static char assignment(char value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) {
+ src.firePropertyChange(name.trim(), null, "dummy value");
+ return value;
+ }
+
+ /**
+ * Compute the string representation of an object.
+ * <p/>
+ * Return empty string if given object is null
+ *
+ * @param value the value to write
+ * @return the string representation of the given object or an empty string if object is null.
+ */
+ public static String getStringValue(Object value) {
+ String result;
+ result = value == null ? "" : value.toString();
+ return result;
+ }
+
+ /**
+ * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found.
+ * <p/>
+ * If entry is found, return his value in context.
+ *
+ * @param <T> the type of required data
+ * @param context the context to test
+ * @param def the definition of the entry to seek in context
+ * @return the value from the context
+ * @throws IllegalArgumentException if the entry is not found in context.
+ */
+ public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException {
+
+ T value = def.getContextValue(context);
+
+ if (value == null) {
+ throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context);
+ }
+
+ return value;
+ }
+
+ /**
+ * Convinient method to apply more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void applyDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.applyDataBinding(binding);
+ }
+ }
+ /**
+ * Convinient method to apply more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void applyDataBinding(JAXXObject src, Collection<String> bindings) {
+ for (String binding : bindings) {
+ src.applyDataBinding(binding);
+ }
+ }
+
+ /**
+ * Convinient method to process more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void processDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.processDataBinding(binding);
+ }
+ }
+
+ /**
+ * Convinient method to remove more than one binding on a JAXX ui.
+ *
+ * @param src the ui to treate
+ * @param bindings the list of binding to process.
+ */
+ public static void removeDataBinding(JAXXObject src, String... bindings) {
+ for (String binding : bindings) {
+ src.removeDataBinding(binding);
+ }
+ }
+
+// public static ImageIcon createIcon(String path) {
+// java.net.URL imgURL = JAXXUtil.class.getResource(path);
+// if (imgURL != null) {
+// return new ImageIcon(imgURL);
+// } else {
+// throw new IllegalArgumentException("could not find icon " + path);
+// }
+// }
+
+// /**
+// * @param path the location of icons in root directory icons
+// * @return the icon at {@link #getIconPath()}+path
+// */
+// public static ImageIcon createImageIcon(String path) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + path);
+// }
+//
+// /**
+// * @param key the key of the icon to retreave from {@link UIManager}
+// * @return the icon, or <code>null if no icon found in {@link UIManager}
+// */
+// public static Icon getUIManagerIcon(String key) {
+// return UIManager.getIcon(key);
+// }
+//
+// /**
+// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code>
+// *
+// * @param key the key of the action icon to retreave from {@link UIManager}
+// * @return the icon, or <code>null if no icon found in {@link UIManager}
+// */
+// public static Icon getUIManagerActionIcon(String key) {
+// return getUIManagerIcon("action." + key);
+// }
+//
+// public static ImageIcon createActionIcon(String name) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + "action-" + name + ".png");
+// }
+//
+// public static ImageIcon createI18nIcon(String name) {
+// String iconPath = getIconPath();
+// return createIcon(iconPath + "i18n/" + name + ".png");
+// }
+
+ /**
+ * detects all PropertychangedListener added by Jaxx uis
+ * (should be a {@link DataBindingListener}
+ *
+ * @param propertyNames the array of property names to find
+ * @param listeners the array of listeners to filter
+ * @return the filtered listeners
+ */
+ public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) {
+ if (listeners == null || listeners.length == 0) {
+ return new PropertyChangeListener[0];
+ }
+ List<String> pNames = Arrays.asList(propertyNames);
+
+ List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>();
+
+ for (PropertyChangeListener listener : listeners) {
+ String pName = null;
+ PropertyChangeListenerProxy plistener = null;
+ if (listener instanceof PropertyChangeListenerProxy) {
+ plistener = (PropertyChangeListenerProxy) listener;
+ if (!pNames.contains(plistener.getPropertyName())) {
+ // not on the good property
+ continue;
+ }
+ listener = (PropertyChangeListener) plistener.getListener();
+ pName = plistener.getPropertyName();
+ }
+ if (plistener != null && pName != null && listener instanceof DataBindingListener) {
+ if (log.isDebugEnabled()) {
+ log.debug("find config listener to remove [" + pName + "] : " + listener);
+ }
+ toRemove.add(plistener);
+ //toRemove.add(listener);
+ }
+ }
+ return toRemove.toArray(new PropertyChangeListener[toRemove.size()]);
+ }
+
+// private static String getIconPath() {
+// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY);
+// if (iconPath == null) {
+// iconPath = DEFAULT_ICON_PATH;
+// } else {
+// if (!iconPath.endsWith("/")) {
+// iconPath += "/";
+// }
+// }
+// return iconPath;
+// }
+}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -79,7 +79,7 @@
* @author tony
* @since 1.2
*/
-public class SwingUtil extends Util {
+public class SwingUtil extends JAXXUtil {
/**
* to use log facility, just put in your code: log.info(\"...\");
@@ -861,7 +861,7 @@
}
public static ImageIcon createIcon(String path) {
- java.net.URL imgURL = Util.class.getResource(path);
+ java.net.URL imgURL = JAXXUtil.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -1,516 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime;
-
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeListenerProxy;
-import java.io.IOException;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.*;
-
-public class Util {
-
- // public static final String DEFAULT_ICON_PATH = "/icons/";
- // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path";
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(Util.class);
- public static final String PARENT = "parent";
- // Maps root objects to lists of event listeners
- private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
- private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
-
- private static class EventListenerDescriptor {
-
- Class<?> listenerClass;
- String listenerMethodName;
- String methodName;
- Object eventListener;
- }
-
- /**
- * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping
- * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField
- * for the rationale behind this (admittedly ugly) approach.
- *
- * @param descriptor descriptor to decode
- * @return the dedoced descriptor
- */
- public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) {
- try {
- return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false);
- /*byte[] data = new byte[descriptor.length()];
- // copy low-order bytes into the array. The high-order bytes should all be zero.
- System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
- //descriptor.getBytes(0, descriptor.length(), data, 0);
- ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
- return (JAXXObjectDescriptor) in.readObject();*/
- } catch (IOException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- }
- }
-
- public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) {
- try {
- return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true);
-
- /*byte[] data = new byte[descriptor.length()];
- // copy low-order bytes into the array. The high-order bytes should all be zero.
- System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
- //descriptor.getBytes(0, descriptor.length(), data, 0);
- ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data)));
- return (JAXXObjectDescriptor) in.readObject();*/
- } catch (IOException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- }
- }
-
- public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
- return newContextEntryDef(null, klass);
- }
-
- public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
- return new JAXXContextEntryDef<O>(name, klass);
- }
-
- public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
- return newListContextEntryDef(null);
- }
-
- public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
- Class<List<O>> castList = Util.castList();
- JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList);
- return contextEntryDef;
- }
-
-// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) {
-// bindings.put(binding.getId(), binding);
-//// binding.applyDataBinding();
-//// binding.processDataBinding();
-// return binding;
-// }
-
-// /**
-// * Return parent's container corresponding to the Class clazz
-// *
-// * @param <O> type of container to obtain from context
-// * @param top the top container
-// * @param clazz desired
-// * @return parent's container
-// */
-// @SuppressWarnings({"unchecked"})
-// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
-// if (top == null) {
-// throw new IllegalArgumentException("top parameter can not be null");
-// }
-// if (!Container.class.isAssignableFrom(top.getClass())) {
-// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class);
-// }
-// Container parent = ((Container) top).getParent();
-// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) {
-// parent = getParentContainer(parent, clazz);
-// }
-// return (O) parent;
-// }
-
- @SuppressWarnings({"unchecked"})
- protected static <O> Class<List<O>> castList() {
- return (Class<List<O>>) Collections.emptyList().getClass();
- }
-
- /**
- * Method to initialize the context of a ui.
- *
- * @param ui the ui
- * @param parentContext the context to set in ui
- */
- public static void initContext(JAXXObject ui, JAXXContext parentContext) {
-
- if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) {
- ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui);
- } else {
- ui.setContextValue(parentContext);
- }
- // if parentContext is a JAXXObject then
- // add an special parent entry to can go up
- if (parentContext instanceof JAXXObject) {
- ui.setContextValue(parentContext, PARENT);
- }
- }
-
- public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
- WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
- List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
- if (descriptors == null) {
- descriptors = new ArrayList<EventListenerDescriptor>();
- eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
- } else {
- for (EventListenerDescriptor descriptor : descriptors) {
- if (listenerClass == descriptor.listenerClass &&
- (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
- methodName.equals(descriptor.methodName)) {
- return (E) descriptor.eventListener;
- }
- }
- }
-
- // else we need to create a new listener
- final EventListenerDescriptor descriptor = new EventListenerDescriptor();
- descriptor.listenerClass = listenerClass;
- descriptor.listenerMethodName = listenerMethodName;
- descriptor.methodName = methodName;
- try {
- final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
- Method listenerMethod = null;
- if (listenerMethodName != null) {
- for (Method listenerMethod1 : listenerMethods) {
- if ((listenerMethod1).getName().equals(listenerMethodName)) {
- listenerMethod = listenerMethod1;
- break;
- }
- }
- }
- if (listenerMethodName != null && listenerMethod == null) {
- throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
- }
- Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes();
- Class<?> methodContainerClass = methodContainer.getClass();
- final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
- descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
- new Class<?>[]{listenerClass},
- new InvocationHandler() {
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) {
- String methodName = method.getName();
- if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
- try {
- targetMethod.setAccessible(true);
- return targetMethod.invoke(methodContainer, args);
- } catch (IllegalAccessException e) {
- throw new RuntimeException("could not invoke on container " + methodContainer, e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
- if (methodName.equals("toString")) {
- return toString();
- }
- if (methodName.equals("equals")) {
- return descriptor.eventListener == args[0];
- }
- if (methodName.equals("hashCode")) {
- return hashCode();
- }
- return null;
- }
- });
- descriptors.add(descriptor);
- return (E) descriptor.eventListener;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) {
- return getEventListener(listenerClass, null, methodContainer, methodName);
- }
-
- public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) {
- WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object);
- List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get();
- if (listeners == null) {
- listeners = new ArrayList<DataBindingUpdateListener>();
- dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners));
- } else {
- for (DataBindingUpdateListener listener : listeners) {
- if (bindingName.equals(listener.getBindingName())) {
- return listener;
- }
- }
- }
- DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName);
- listeners.add(listener);
- return listener;
- }
-
-// public static void setComponentWidth(Component component, int width) {
-// component.setSize(width, component.getHeight());
-// if (component instanceof JComponent) {
-// JComponent jcomponent = (JComponent) component;
-// jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height));
-// jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height));
-// if (jcomponent.isDisplayable()) {
-// jcomponent.revalidate();
-// }
-// }
-// }
-
-// public static void setComponentHeight(Component component, int height) {
-// component.setSize(component.getWidth(), height);
-// if (component instanceof JComponent) {
-// JComponent jcomponent = (JComponent) component;
-// jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height));
-// jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height));
-// if (jcomponent.isDisplayable()) {
-// jcomponent.revalidate();
-// }
-// }
-// }
-
- public static boolean assignment(boolean value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static byte assignment(byte value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static short assignment(short value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static int assignment(int value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static long assignment(long value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static float assignment(float value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static double assignment(double value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static char assignment(char value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) {
- src.firePropertyChange(name.trim(), null, "dummy value");
- return value;
- }
-
- /**
- * Compute the string representation of an object.
- * <p/>
- * Return empty string if given object is null
- *
- * @param value the value to write
- * @return the string representation of the given object or an empty string if object is null.
- */
- public static String getStringValue(Object value) {
- String result;
- result = value == null ? "" : value.toString();
- return result;
- }
-
- /**
- * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found.
- * <p/>
- * If entry is found, return his value in context.
- *
- * @param <T> the type of required data
- * @param context the context to test
- * @param def the definition of the entry to seek in context
- * @return the value from the context
- * @throws IllegalArgumentException if the entry is not found in context.
- */
- public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException {
-
- T value = def.getContextValue(context);
-
- if (value == null) {
- throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context);
- }
-
- return value;
- }
-
- /**
- * Convinient method to apply more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void applyDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.applyDataBinding(binding);
- }
- }
- /**
- * Convinient method to apply more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void applyDataBinding(JAXXObject src, Collection<String> bindings) {
- for (String binding : bindings) {
- src.applyDataBinding(binding);
- }
- }
-
- /**
- * Convinient method to process more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void processDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.processDataBinding(binding);
- }
- }
-
- /**
- * Convinient method to remove more than one binding on a JAXX ui.
- *
- * @param src the ui to treate
- * @param bindings the list of binding to process.
- */
- public static void removeDataBinding(JAXXObject src, String... bindings) {
- for (String binding : bindings) {
- src.removeDataBinding(binding);
- }
- }
-
-// public static ImageIcon createIcon(String path) {
-// java.net.URL imgURL = Util.class.getResource(path);
-// if (imgURL != null) {
-// return new ImageIcon(imgURL);
-// } else {
-// throw new IllegalArgumentException("could not find icon " + path);
-// }
-// }
-
-// /**
-// * @param path the location of icons in root directory icons
-// * @return the icon at {@link #getIconPath()}+path
-// */
-// public static ImageIcon createImageIcon(String path) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + path);
-// }
-//
-// /**
-// * @param key the key of the icon to retreave from {@link UIManager}
-// * @return the icon, or <code>null if no icon found in {@link UIManager}
-// */
-// public static Icon getUIManagerIcon(String key) {
-// return UIManager.getIcon(key);
-// }
-//
-// /**
-// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code>
-// *
-// * @param key the key of the action icon to retreave from {@link UIManager}
-// * @return the icon, or <code>null if no icon found in {@link UIManager}
-// */
-// public static Icon getUIManagerActionIcon(String key) {
-// return getUIManagerIcon("action." + key);
-// }
-//
-// public static ImageIcon createActionIcon(String name) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + "action-" + name + ".png");
-// }
-//
-// public static ImageIcon createI18nIcon(String name) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + "i18n/" + name + ".png");
-// }
-
- /**
- * detects all PropertychangedListener added by Jaxx uis
- * (should be a {@link DataBindingListener}
- *
- * @param propertyNames the array of property names to find
- * @param listeners the array of listeners to filter
- * @return the filtered listeners
- */
- public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) {
- if (listeners == null || listeners.length == 0) {
- return new PropertyChangeListener[0];
- }
- List<String> pNames = Arrays.asList(propertyNames);
-
- List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>();
-
- for (PropertyChangeListener listener : listeners) {
- String pName = null;
- PropertyChangeListenerProxy plistener = null;
- if (listener instanceof PropertyChangeListenerProxy) {
- plistener = (PropertyChangeListenerProxy) listener;
- if (!pNames.contains(plistener.getPropertyName())) {
- // not on the good property
- continue;
- }
- listener = (PropertyChangeListener) plistener.getListener();
- pName = plistener.getPropertyName();
- }
- if (plistener != null && pName != null && listener instanceof DataBindingListener) {
- if (log.isDebugEnabled()) {
- log.debug("find config listener to remove [" + pName + "] : " + listener);
- }
- toRemove.add(plistener);
- //toRemove.add(listener);
- }
- }
- return toRemove.toArray(new PropertyChangeListener[toRemove.size()]);
- }
-
-// private static String getIconPath() {
-// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY);
-// if (iconPath == null) {
-// iconPath = DEFAULT_ICON_PATH;
-// } else {
-// if (!iconPath.endsWith("/")) {
-// iconPath += "/";
-// }
-// }
-// return iconPath;
-// }
-}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -21,7 +21,7 @@
package jaxx.runtime.context;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -248,7 +248,7 @@
}
public void removeJaxxPropertyChangeListener() {
- PropertyChangeListener[] toRemove = Util.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
+ PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners());
if (toRemove == null || toRemove.length == 0) {
return;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -22,7 +22,7 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -47,7 +47,7 @@
/**
* entry of the parent context
*/
- protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = Util.newContextEntryDef(JAXXContext.class);
+ protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = JAXXUtil.newContextEntryDef(JAXXContext.class);
/**
* Logger
*/
@@ -194,7 +194,7 @@
// }
protected JAXXContextEntryDef<?> getKey(String name, Class<?> klass) {
- return Util.newContextEntryDef(name, klass);
+ return JAXXUtil.newContextEntryDef(name, klass);
}
@SuppressWarnings({"unchecked"})
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -23,11 +23,9 @@
import javax.swing.JTree;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.JAXXContextEntryDef;
-import java.awt.*;
-
/**
* To help getting and setting navigation tree objects from a {@link JAXXContext}.
* <p/>
@@ -73,13 +71,13 @@
public NavigationTreeContextHelper(String prefix) {
this.prefix = prefix;
- treeContextEntry = Util.newContextEntryDef(prefix + "-tree", JTree.class);
- treeModelContextEntry = Util.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class);
- treeHandlerContextEntry = Util.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class);
- selectedBeanContextEntry = Util.newContextEntryDef(prefix + "-selected-bean", Object.class);
- selectedNodeContextEntry = Util.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class);
- selectedPathContextEntry = Util.newContextEntryDef(prefix + "-selected-path", String.class);
-// selectedUIContextEntry = Util.newContextEntryDef(prefix + "-selected-ui", Component.class);
+ treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class);
+ treeModelContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class);
+ treeHandlerContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class);
+ selectedBeanContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-bean", Object.class);
+ selectedNodeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class);
+ selectedPathContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-path", String.class);
+// selectedUIContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-ui", Component.class);
}
public String getPrefix() {
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -1,23 +1,23 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
package jaxx.runtime;
import org.junit.Assert;
@@ -33,10 +33,10 @@
@Test
public void testGetEventListener() {
count = 0;
- DocumentListener listener = (DocumentListener) jaxx.runtime.Util.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
+ DocumentListener listener = (DocumentListener) JAXXUtil.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
listener.insertUpdate(null);
Assert.assertEquals(count, 1);
- DocumentListener listener2 = (DocumentListener) jaxx.runtime.Util.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
+ DocumentListener listener2 = (DocumentListener) JAXXUtil.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount");
listener2.removeUpdate(null);
Assert.assertEquals(count, 2);
//assertTrue("Received two different event listeners despite using identical parameters", listener == listener2);
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -20,6 +20,7 @@
*/
package jaxx.runtime.swing.navigation;
+import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.DefaultJAXXContext;
import jaxx.runtime.JAXXContext;
import org.junit.Assert;
@@ -28,7 +29,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import jaxx.runtime.Util;
/**
* Test du model de navigation.
@@ -164,10 +164,10 @@
NavigationTreeNode sonSonNode;
NavigationTreeNode sonSonSonNode;
- builder.build(rootNode, (String) null, Util.newContextEntryDef("name", String.class), "name", null, null);
- builder.build(rootNode, (String) null, Util.newContextEntryDef("name2", String.class), "name2", null, null);
+ builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef("name", String.class), "name", null, null);
+ builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef("name2", String.class), "name2", null, null);
- sonNode = builder.build(rootNode, (String) null, Util.newContextEntryDef(Model.class), "model", null, null);
+ sonNode = builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef(Model.class), "model", null, null);
builder.build(sonNode, (String) null, "../name", "name", null, null);
builder.build(sonNode, (String) null, "../integerValue", "integerValue", null, null);
@@ -286,7 +286,7 @@
NavigationTreeNode sonSonSonNode;
// first son is a list of models
- sonNode = builder.build(rootNode, (String) null, Util.newListContextEntryDef("models"), "models", null, null);
+ sonNode = builder.build(rootNode, (String) null, JAXXUtil.newListContextEntryDef("models"), "models", null, null);
// first son son is a model
sonSonNode = builder.build(sonNode, (String) null, "..[1]", "0", null, null);
Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java
===================================================================
--- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java 2010-01-29 15:18:50 UTC (rev 1723)
@@ -23,7 +23,7 @@
import jaxx.runtime.Base64Coder;
import jaxx.compiler.JAXXCompiler;
import jaxx.runtime.JAXXObjectDescriptor;
-import jaxx.runtime.Util;
+import jaxx.runtime.JAXXUtil;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -48,7 +48,7 @@
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
- descriptor2 = Util.decodeJAXXObjectDescriptor(data);
+ descriptor2 = JAXXUtil.decodeJAXXObjectDescriptor(data);
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
@@ -58,7 +58,7 @@
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
- descriptor2 = Util.decodeCompressedJAXXObjectDescriptor(data);
+ descriptor2 = JAXXUtil.decodeCompressedJAXXObjectDescriptor(data);
assertNotNull(descriptor2);
assertEquals(descriptor.toString(), descriptor2.toString());
Modified: trunk/src/site/rst/BeanValidator.rst
===================================================================
--- trunk/src/site/rst/BeanValidator.rst 2010-01-26 21:06:53 UTC (rev 1722)
+++ trunk/src/site/rst/BeanValidator.rst 2010-01-29 15:18:50 UTC (rev 1723)
@@ -170,7 +170,7 @@
::
- jaxx.runtime.Util.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
+ jaxx.runtime.JAXXUtil.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class);
On obtiendra si une erreur de conversion intervient, une erreur dont le libellé est de la forme *error.convertor.XXX*
1
0
Author: tchemit
Date: 2010-01-26 22:06:53 +0100 (Tue, 26 Jan 2010)
New Revision: 1722
Modified:
trunk/pom.xml
Log:
Utilisation de mavenpom4redmine 2.0.4
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-01-24 23:35:36 UTC (rev 1721)
+++ trunk/pom.xml 2010-01-26 21:06:53 UTC (rev 1722)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.0.3</version>
+ <version>2.0.4</version>
</parent>
<artifactId>jaxx</artifactId>
1
0
Author: tchemit
Date: 2010-01-25 00:35:36 +0100 (Mon, 25 Jan 2010)
New Revision: 1721
Modified:
trunk/pom.xml
Log:
Utilisation de mavenpom4redmine 2.0.3
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-01-19 17:50:08 UTC (rev 1720)
+++ trunk/pom.xml 2010-01-24 23:35:36 UTC (rev 1721)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.0.2</version>
+ <version>2.0.3</version>
</parent>
<artifactId>jaxx</artifactId>
1
0
r1720 - trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin
by tchemit@users.nuiton.org 19 Jan '10
by tchemit@users.nuiton.org 19 Jan '10
19 Jan '10
Author: tchemit
Date: 2010-01-19 18:50:08 +0100 (Tue, 19 Jan 2010)
New Revision: 1720
Modified:
trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java
trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java
trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java
trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java
trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java
trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java
trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java
trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java
Log:
clean code + debut de resolution de Anomalie #236: La generation de l'index de l'aide n'est pas correct
Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java
===================================================================
--- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java 2010-01-19 17:33:41 UTC (rev 1719)
+++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractGenerateHelpMojo.java 2010-01-19 17:50:08 UTC (rev 1720)
@@ -107,7 +107,6 @@
@Override
protected void init() throws Exception {
-// protected boolean init() throws Exception {
if (StringUtils.isEmpty(locales)) {
throw new MojoFailureException("You must set the 'locales' property properly (was " + locales + ").");
@@ -132,8 +131,6 @@
defaultLocale = localesToTreate[0];
createDirectoryIfNecessary(getTargetDirectory());
-
-// return true;
}
@Override
@@ -148,10 +145,6 @@
@Override
protected void doAction() throws Exception {
-// if (skipAction()) {
-// return;
-// }
-
for (Locale locale : localesToTreate) {
boolean isDefaultLocale = locale == defaultLocale;
@@ -171,14 +164,6 @@
postDoAction();
}
-// protected boolean skipAction() {
-// if (!generateHelp) {
-// getLog().info("generateHelp flag is off, will skip goal.");
-// return true;
-// }
-// return false;
-// }
-
public File getOutputHelpIds() {
return outputHelpIds;
}
Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java
===================================================================
--- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2010-01-19 17:33:41 UTC (rev 1719)
+++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/AbstractJaxxMojo.java 2010-01-19 17:50:08 UTC (rev 1720)
@@ -81,7 +81,6 @@
protected boolean checkPackaging() {
// not accept pom modules
return !acceptPackaging(Packaging.pom);
-// return project != null && !"pom".equals(project.getPackaging()) && !"site".equals(project.getPackaging());
}
@Override
Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java
===================================================================
--- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java 2010-01-19 17:33:41 UTC (rev 1719)
+++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpFilesMojo.java 2010-01-19 17:50:08 UTC (rev 1720)
@@ -134,10 +134,8 @@
@Override
public void init() throws Exception {
-// public boolean init() throws Exception {
if (!generateHelp) {
return;
-// return true;
}
// check ressources
@@ -154,31 +152,12 @@
super.init();
-// boolean b = super.init();
-// if (!b) {
-// return false;
-// }
-
// load ids from idsStore file
-// File idsFile;
-
if (isForce()) {
idsFile = getMergeHelpIdsStoreFile();
-// if (!idsFile.exists()) {
-// if (isVerbose()) {
-// getLog().info("Force flag is on, but no helpIdStore-all to react at " + idsFile);
-// }
-// return true;
-// }
} else {
idsFile = getHelpIdsStoreFile();
-// if (!idsFile.exists()) {
-// if (isVerbose()) {
-// getLog().info("no helpIdStore to react at " + idsFile);
-// }
-// return true;
-// }
}
if (!idsFile.exists()) {
@@ -190,21 +169,10 @@
// loading all ids
Set<String> ids = loadHelpIds(idsFile);
-// if (ids.isEmpty()) {
-//
-// // no ids detected
-// if (isVerbose()) {
-// getLog().info("No helpIds detected, will skip.");
-// }
-// return true;
-// }
-
for (String id : ids) {
String path = id.replaceAll("\\.", File.separator) + ".html";
helpIds.put(id, path);
}
-
-// return true;
}
@Override
@@ -229,33 +197,6 @@
return b;
}
-// @Override
-// protected boolean skipAction() {
-// boolean b = super.skipAction();
-// if (!b) {
-// if (helpIds == null || helpIds.isEmpty()) {
-// getLog().info("No help ids to treate.");
-// return true;
-// }
-// }
-// return false;
-// }
-
-// @Override
-// public void doAction() throws Exception {
-//
-// if (skipAction()) {
-// return;
-// }
-//
-// if (helpIds == null || helpIds.isEmpty()) {
-// getLog().info("No help ids to treate.");
-// return;
-// }
-//
-// super.doAction();
-// }
-
protected void postDoAction() {
getLog().info(touchedFiles + " file(s) treated.");
}
Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java
===================================================================
--- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java 2010-01-19 17:33:41 UTC (rev 1719)
+++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpIdsMojo.java 2010-01-19 17:50:08 UTC (rev 1720)
@@ -32,19 +32,13 @@
@Override
public void init() throws Exception {
-// public boolean init() throws Exception {
if (!generateHelp) {
return;
-// return true;
}
super.init();
-// if (!super.init()) {
-// return false;
-// }
-
// check there is some bundle
if (getHelpIdsFilename() == null) {
throw new MojoFailureException("you must set the 'helpIdStore' property.");
@@ -58,7 +52,6 @@
// always clean helpIdsStore before all
cleanHelpIdsStore();
-// return true;
}
@Override
@@ -80,21 +73,6 @@
@Override
public void doAction() throws Exception {
-// if (skipAction()) {
-// return;
-// }
-
-// Set<String> helpIds = HelpRootCompiledObjectDecorator.getHelpIds();
-//
-// if (helpIds.isEmpty()) {
-//// if (isVerbose()) {
-// // no ids detected in this compilation round
-// getLog().info("No helpIds detected.");
-//// }
-// cleanHelpIdsStore();
-// return;
-// }
-
// store current jaxx session detected help ids
File idsStore = getHelpIdsStoreFile();
Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java
===================================================================
--- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2010-01-19 17:33:41 UTC (rev 1719)
+++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpMojo.java 2010-01-19 17:50:08 UTC (rev 1720)
@@ -45,19 +45,12 @@
public void setTargetDirectory(File targetDirectory) {
}
-// @Override
-// public boolean init() throws Exception {
-//
-// return true;
-// }
-
@Override
public void doAction() throws Exception {
}
protected void postDoAction() {
- //getLog().info(touchedFiles + " file(s) treated.");
}
protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File localizedTarget, String localePath) throws Exception {
Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java
===================================================================
--- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java 2010-01-19 17:33:41 UTC (rev 1719)
+++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateHelpSearchMojo.java 2010-01-19 17:50:08 UTC (rev 1720)
@@ -19,9 +19,7 @@
package org.nuiton.jaxx.plugin;
import com.sun.java.help.search.Indexer;
-import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.StringUtils;
import org.nuiton.plugin.PluginHelper;
import java.io.File;
@@ -56,25 +54,26 @@
*/
protected File outputHelpSearch;
+ /**
+ * The directory where to pick content files to generate the index.
+ *
+ * @parameter expression="${jaxx.inputHelp}" default-value="${project.basedir}/src/main/help"
+ * @required
+ * @since 2.0.0
+ */
+ protected File inputHelp;
+
protected String timestamp;
@Override
public void init() throws Exception {
-// public boolean init() throws Exception {
if (!generateHelp || !generateSearch) {
return;
-// return true;
}
-// if (!generateSearch) {
-//// getLog().info("Do not generate search.");
-// return true;
-// }
-
timestamp = "-" + System.currentTimeMillis();
super.init();
-// return super.init();
}
@Override
@@ -92,32 +91,23 @@
boolean b = super.checkSkip();
if (b) {
if (!generateSearch) {
- getLog().info("generateHelpsearch flag is off, will skip goal.");
+ getLog().info("generateSearch flag is off, will skip goal.");
return false;
}
}
return b;
}
-// protected boolean skipAction() {
-// if (!generateHelp) {
-// getLog().info("generateHelp flag is off, generate nothing.");
-// return true;
-// }
-// if (!generateSearch) {
-// getLog().info("generateHelpsearch flag is off, generate nothing.");
-// return true;
-// }
-// return false;
-// }
-
@Override
- protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File source, String localePath) throws Exception {
+ protected void doActionForLocale(Locale locale, boolean isDefaultLocale, File localizedTarget, String localePath) throws Exception {
String language = locale.getLanguage();
- File target = new File(getTargetDirectory(), localePath + File.separator + "JavaHelpSearch");
+ File source = new File(inputHelp, localePath);
+ File target = new File(localizedTarget, "JavaHelpSearch");
+// File target = new File(getTargetDirectory(), localePath + File.separator + "JavaHelpSearch");
+
// detect if need to generate
boolean generate = false;
@@ -167,6 +157,7 @@
}
createDirectoryIfNecessary(source);
+// createDirectoryIfNecessary(localizedTarget);
createDirectoryIfNecessary(target);
// ---------------------------------------------------------------
@@ -197,7 +188,8 @@
if (isVerbose()) {
getLog().info("copy files to " + tmpDir + " for indexing them.");
}
- FileUtils.copyDirectory(source, tmpDir, "**/*", StringUtils.join(DirectoryScanner.DEFAULTEXCLUDES, ","));
+ FileUtils.copyDirectoryStructure(source, tmpDir);
+// FileUtils.copyDirectory(source, tmpDir, "**/*", StringUtils.join(DirectoryScanner.DEFAULTEXCLUDES, ",")+",**/*.jpg");
// prepare arguments of Indexer.main calling
List<String> params = new ArrayList<String>();
Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java
===================================================================
--- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2010-01-19 17:33:41 UTC (rev 1719)
+++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/GenerateMojo.java 2010-01-19 17:50:08 UTC (rev 1720)
@@ -290,7 +290,6 @@
@SuppressWarnings("unchecked")
@Override
public void init() throws Exception {
-// public boolean init() throws Exception {
fixCompileSourceRoots();
@@ -308,7 +307,6 @@
nofiles = files == null || files.length == 0;
if (nofiles) {
return;
-// return true;
}
cl = initClassLoader(getProject(),
@@ -361,7 +359,6 @@
getLog().info("will parse " + file);
}
}
-// return true;
}
@Override
@@ -376,11 +373,6 @@
@Override
public void doAction() throws Exception {
-// if (nofiles) {
-// getLog().info("Nothing to generate - all files are uo to date.");
-// return;
-// }
-
getLog().info("Detects " + files.length + " modified jaxx file(s). ");
if (showBinding) {
Modified: trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java
===================================================================
--- trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java 2010-01-19 17:33:41 UTC (rev 1719)
+++ trunk/maven-jaxx-plugin/src/main/java/org/nuiton/jaxx/plugin/XmlHelper.java 2010-01-19 17:50:08 UTC (rev 1720)
@@ -68,8 +68,9 @@
}
});
- InputStream s = new FileInputStream(file);
+ InputStream s=null;
try {
+ s = new FileInputStream(file);
parser.parse(new InputSource(s));
} finally {
if (s != null) {
1
0
Author: tchemit
Date: 2010-01-19 18:33:41 +0100 (Tue, 19 Jan 2010)
New Revision: 1719
Modified:
trunk/pom.xml
Log:
Utilisation de mavenpom4redmine 2.0.2
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-01-17 20:14:22 UTC (rev 1718)
+++ trunk/pom.xml 2010-01-19 17:33:41 UTC (rev 1719)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.0.1</version>
+ <version>2.0.2</version>
</parent>
<artifactId>jaxx</artifactId>
1
0