cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgen...@apache.org
Subject [46/50] cayenne-modeler git commit: Streamlined binding methods and added JavaDoc.
Date Thu, 05 Jan 2017 22:09:54 GMT
Streamlined binding methods and added JavaDoc.

Project: http://git-wip-us.apache.org/repos/asf/cayenne-modeler/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne-modeler/commit/12a8c774
Tree: http://git-wip-us.apache.org/repos/asf/cayenne-modeler/tree/12a8c774
Diff: http://git-wip-us.apache.org/repos/asf/cayenne-modeler/diff/12a8c774

Branch: refs/heads/master
Commit: 12a8c7745df1b56f7881f8e8baf6f8afc5442a6f
Parents: 830a7d1
Author: mrg <blacknext@gmail.com>
Authored: Tue Dec 6 08:58:22 2016 -0500
Committer: mrg <blacknext@gmail.com>
Committed: Tue Dec 6 08:58:22 2016 -0500

----------------------------------------------------------------------
 .../adapters/CayennePropertyAdapter.java        | 81 ++++++++++++++++----
 1 file changed, 64 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne-modeler/blob/12a8c774/src/main/java/org/apache/cayenne/modeler/adapters/CayennePropertyAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/cayenne/modeler/adapters/CayennePropertyAdapter.java
b/src/main/java/org/apache/cayenne/modeler/adapters/CayennePropertyAdapter.java
index 95a7776..018b13c 100644
--- a/src/main/java/org/apache/cayenne/modeler/adapters/CayennePropertyAdapter.java
+++ b/src/main/java/org/apache/cayenne/modeler/adapters/CayennePropertyAdapter.java
@@ -25,47 +25,94 @@ import org.apache.commons.logging.LogFactory;
 
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.IntegerProperty;
+import javafx.beans.property.Property;
 import javafx.beans.property.StringProperty;
 import javafx.beans.property.adapter.JavaBeanBooleanPropertyBuilder;
 import javafx.beans.property.adapter.JavaBeanIntegerPropertyBuilder;
 import javafx.beans.property.adapter.JavaBeanStringPropertyBuilder;
 
+/**
+ * Provides a common mechanism for creating property adapters. Property adapters
+ * map existing Java/Beans classes to JavaFX properties which can be used in
+ * bi-directional bindings within the UI.
+ */
 public abstract class CayennePropertyAdapter
 {
     private static final Log LOGGER = LogFactory.getLog(CayennePropertyAdapter.class);
 
+    /**
+     * Binds a Java/Bean String property to a JavaFX property. Note: The JavaFX
+     * property observes changes and marks the Cayenne project dirty when a
+     * change occurs.
+     *
+     * @param property
+     *            The Java/Bean property to bind to.
+     * @return A new JavaFX property bound to the Java/Bean property.
+     * @throws NoSuchMethodException
+     *             If the specified Java/Bean property does not exist (check the
+     *             property's spelling).
+     */
     public BooleanProperty bindBoolean(String property) throws NoSuchMethodException
     {
-        BooleanProperty boundProperty = JavaBeanBooleanPropertyBuilder.create().bean(getWrappedObject()).name(property).build();
-
-        boundProperty.addListener((observable, newValue, oldValue) -> markProjectDirty());
-
-        return boundProperty;
+        return observePropertyChanges(JavaBeanBooleanPropertyBuilder.create().bean(getWrappedObject()).name(property).build());
     }
 
+    /**
+     * Binds a Java/Bean String property to a JavaFX property. Note: The JavaFX
+     * property observes changes and marks the Cayenne project dirty when a
+     * change occurs.
+     *
+     * @param property
+     *            The Java/Bean property to bind to.
+     * @return A new JavaFX property bound to the Java/Bean property.
+     * @throws NoSuchMethodException
+     *             If the specified Java/Bean property does not exist (check the
+     *             property's spelling).
+     */
     public IntegerProperty bindInteger(String property) throws NoSuchMethodException
     {
-        IntegerProperty boundProperty = JavaBeanIntegerPropertyBuilder.create().bean(getWrappedObject()).name(property).build();
-
-        boundProperty.addListener((observable, newValue, oldValue) -> markProjectDirty());
-
-        return boundProperty;
+        return observePropertyChanges(JavaBeanIntegerPropertyBuilder.create().bean(getWrappedObject()).name(property).build());
     }
 
+    /**
+     * Binds a Java/Bean String property to a JavaFX property. Note: The JavaFX
+     * property observes changes and marks the Cayenne project dirty when a
+     * change occurs.
+     *
+     * @param property
+     *            The Java/Bean property to bind to.
+     * @return A new JavaFX property bound to the Java/Bean property.
+     * @throws NoSuchMethodException
+     *             If the specified Java/Bean property does not exist (check the
+     *             property's spelling).
+     */
     public StringProperty bindString(String property) throws NoSuchMethodException
     {
-        StringProperty boundProperty = JavaBeanStringPropertyBuilder.create().bean(getWrappedObject()).name(property).build();
-
-        boundProperty.addListener((observable, newValue, oldValue) -> markProjectDirty());
-
-        return boundProperty;
+        return observePropertyChanges(JavaBeanStringPropertyBuilder.create().bean(getWrappedObject()).name(property).build());
     }
 
-    private void markProjectDirty()
+    /**
+     * Observes changes to the given property and marks the project dirty
+     * (edited) when the property is changed.
+     *
+     * @param property
+     *            The property to observe changes.
+     * @return The observed property.
+     */
+    private <T extends Property<?>> T observePropertyChanges(T property)
     {
-        getCayennePropject().setDirty(true);
+        property.addListener((observable, newValue, oldValue) -> getCayennePropject().setDirty(true));
+
+        return property;
     }
 
+    /**
+     * @return The Cayenne project this property adapter is attached to.
+     */
     public abstract CayenneProject getCayennePropject();
+
+    /**
+     * @return The Cayenne Java/Bean object this property adapter wraps.
+     */
     public abstract Object getWrappedObject();
 }


Mime
View raw message