Author: tchemit Date: 2011-04-21 17:15:55 +0200 (Thu, 21 Apr 2011) New Revision: 2268 Url: http://nuiton.org/repositories/revision/jaxx/2268 Log: add a reloadAfterFire internal state in bindings to be able to reload it after each fire Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/binding/DefaultJAXXBinding.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java 2011-04-21 15:14:35 UTC (rev 2267) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/writers/DefaultJAXXBindingWriter.java 2011-04-21 15:15:55 UTC (rev 2268) @@ -81,7 +81,7 @@ removeBuffer.append(" != null) {"); removeBuffer.append(eol); } - int indentLevel = needTest?4:0; + int indentLevel = needTest ? 4 : 0; addBuffer.append(JavaFileGenerator.indent( tracker.getAddListenerCode(), indentLevel, false, eol)); removeBuffer.append(JavaFileGenerator.indent( @@ -123,6 +123,15 @@ @Override protected String getConstructorParams(DataBinding binding, DataListener[] trackers) { - return "this, " + binding.getConstantId() + ", true"; + + String params = "this, " + binding.getConstantId() + ", true"; + if (trackers.length > 1) { + //FIXME tchemit-2011-04-21 Must improve this : only need a complex binding + // when chaining properties : example getA().getB() but not getA() || getB() + // with a complex binding, we will need to reload de binding after each fire... + params += ", true"; + + } + return params; } } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/binding/DefaultJAXXBinding.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/binding/DefaultJAXXBinding.java 2011-04-21 15:14:35 UTC (rev 2267) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/binding/DefaultJAXXBinding.java 2011-04-21 15:15:55 UTC (rev 2268) @@ -26,6 +26,7 @@ import jaxx.runtime.JAXXBinding; import jaxx.runtime.JAXXObject; +import jaxx.runtime.JAXXUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -42,10 +43,10 @@ private static final Log log = LogFactory.getLog(DefaultJAXXBinding.class); /** Counter of all bindings hits */ - private static long NB = 0; + private static long NB; /** Counter of current binding hits */ - private long nb = 0; + private long nb; /** Id of the binding */ private final String id; @@ -53,21 +54,54 @@ /** The source of the binding. */ protected final JAXXObject source; - /** flag to know {@code true} : if the binding was init from a generated jaxx object, {@code false} otherwise. */ + /** + * flag to know {@code true} : if the binding was init from a generated + * jaxx object, {@code false} otherwise. + */ protected final boolean defaultBinding; /** + * Internal state to reapply the binding after each fires :this is sometimes + * necessary when binding is complex. For example with this binding + * <pre> + * ui.getModel().getProperty() + * </pre> + * We need to listen two things : first listen on {@code ui} the + * modification of {@code model}, then on {@code model} the {@code property}. + * + * @since 2.4.2 + */ + protected final boolean reloadAfterFire; + + /** * Creates a new Data binding which will run the given data binding * when it receives a <code>PropertyChangeEvent</code>. * - * @param source the {@link jaxx.runtime.JAXXObject} source of the binding + * @param source the {@link JAXXObject} source of the binding * @param id the name of the data binding to run * @param defaultBinding flag to knwon if binding is coming from a generated jaxx object ({@code true}). */ - public DefaultJAXXBinding(JAXXObject source, String id, boolean defaultBinding) { + public DefaultJAXXBinding(JAXXObject source, String id, + boolean defaultBinding) { + this(source, id, defaultBinding, false); + } + + /** + * Creates a new Data binding which will run the given data binding + * when it receives a <code>PropertyChangeEvent</code>. + * + * @param source the {@link JAXXObject} source of the binding + * @param id the name of the data binding to run + * @param defaultBinding flag to know if binding is coming from a generated jaxx object ({@code true}). + * @param reloadAfterFire flag to know if the binding need to be reload after each fires + */ + public DefaultJAXXBinding(JAXXObject source, String id, + boolean defaultBinding, + boolean reloadAfterFire) { this.source = source; this.id = id; this.defaultBinding = defaultBinding; + this.reloadAfterFire = reloadAfterFire; } @Override @@ -106,7 +140,7 @@ public void propertyChange(PropertyChangeEvent e) { long count = NB; if (log.isDebugEnabled()) { - log.debug(String.format(LOG_START_PATTERN, (++nb), (++NB), this)); + log.debug(String.format(LOG_START_PATTERN, ++nb, ++NB, this)); } //TODO-TC-20091202 perharps could we have a nicer way to process it, // let the source deal with it to avoid re-entrant code @@ -118,10 +152,13 @@ // for now, handle dependency changes by always removing & reapplying // the binding. We should be more efficient and only do this when it's // actually necessary + if (reloadAfterFire) { + JAXXUtil.reloadBinding(this); + } // source.removeDataBinding(id); // source.applyDataBinding(id); if (log.isDebugEnabled()) { - log.debug(String.format(LOG_END_PATTERN, (++nb), (++NB), this, (NB - count))); + log.debug(String.format(LOG_END_PATTERN, ++nb, ++NB, this, NB - count)); } }
participants (1)
-
tchemit@users.nuiton.org