functional/ControlsTests/src/javafx/scene/control/test/utils/ptables/AbstractPropertyValueSetter.java

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javafx.scene.control.test.utils.ptables;
  26 
  27 import java.lang.reflect.Method;
  28 import javafx.beans.property.Property;
  29 import javafx.event.ActionEvent;
  30 import javafx.event.EventHandler;
  31 import javafx.scene.control.Button;
  32 import javafx.scene.control.ButtonBuilder;
  33 import javafx.scene.control.Control;
  34 import javafx.scene.control.Label;
  35 import static javafx.scene.control.test.utils.ptables.StaticLogger.*;
  36 import javafx.scene.layout.HBox;
  37 
  38 /**
  39  * @author Alexander Kirov
  40  *
  41  * Partial implementation of mechanism of binding and unbinding, setters
  42  * implementing, and this functionality aggregating.
  43  */
  44 public abstract class AbstractPropertyValueSetter<ValueType> extends HBox implements AbstractPropertySetter<ValueType> {
  45 
  46     public final static String BIND_BUTTON_SUFFIX = "_BIND_BUTTON_ID";
  47     public final static String BIDIR_PREFIX = "BIDIR_";
  48     public final static String UNIDIR_PREFIX = "UNIDIR_";
  49     public final static String SET_PREFIX = "SETTER_";
  50     public final static String CONTROLLER_SUFFIX = "_CONTROLLER_ID";
  51     protected Property leadingProperty;
  52     protected Property listeningProperty;


  55     protected Object initialValue1;
  56     protected Object initialValue2;
  57     protected Object initialValue3;
  58     protected PropertyValueType propertyValueType;
  59     private BindingType btype;
  60     private EventHandler<ActionEvent> setAction;
  61 
  62     protected void bindComponent(final BindingType btype, final Object testedControl) {
  63         this.btype = btype;
  64         String bindButtonId = ((btype == BindingType.UNIDIRECTIONAL) ? UNIDIR_PREFIX : BIDIR_PREFIX) + listeningProperty.getName().toUpperCase() + BIND_BUTTON_SUFFIX;
  65         setStyle("-fx-border-color : black;");
  66         setSpacing(3);
  67 
  68         binding = new ToggleBindingSwitcher(leadingProperty, listeningProperty, btype);
  69         binding.getVisualRepresentation().setId(bindButtonId);
  70 
  71         String labelDescription = btype.equals(BindingType.UNIDIRECTIONAL) ? "UNIDIR" : "BIDIR";
  72         getChildren().addAll(new Label(labelDescription.toUpperCase().substring(0, Math.min(15, labelDescription.length()) - 1)), leadingControl, binding.getVisualRepresentation());
  73 
  74         if (btype == BindingType.UNIDIRECTIONAL) {
  75             Button setButton = ButtonBuilder.create().text("set").minWidth(38).id(SET_PREFIX + listeningProperty.getName().toUpperCase()).build();


  76             setAction = new EventHandler<ActionEvent>() {
  77                 public void handle(ActionEvent t) {
  78                     //bindingTB.setSelected(false);I think, that is not obligative.
  79                     //But otherwise, exception will be thrown each time, when unidirectional binding is switched on.
  80                     Method setter;
  81                     try {
  82                         Object value = listeningProperty.getValue();
  83 
  84                         Class returnClass;
  85 
  86 
  87                         if (value instanceof Boolean) {
  88                             returnClass = boolean.class;
  89                         } else {
  90                             returnClass = testedControl.getClass().getMethod("get" + listeningProperty.getName().substring(0, 1).toUpperCase() + listeningProperty.getName().substring(1, listeningProperty.getName().length())).getReturnType();
  91                         }
  92 
  93                         Object argument = leadingProperty.getValue();
  94                         if (value instanceof Integer) {
  95                             argument = (int) Math.round((Double) argument);




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javafx.scene.control.test.utils.ptables;
  26 
  27 import java.lang.reflect.Method;
  28 import javafx.beans.property.Property;
  29 import javafx.event.ActionEvent;
  30 import javafx.event.EventHandler;
  31 import javafx.scene.control.Button;

  32 import javafx.scene.control.Control;
  33 import javafx.scene.control.Label;
  34 import static javafx.scene.control.test.utils.ptables.StaticLogger.*;
  35 import javafx.scene.layout.HBox;
  36 
  37 /**
  38  * @author Alexander Kirov
  39  *
  40  * Partial implementation of mechanism of binding and unbinding, setters
  41  * implementing, and this functionality aggregating.
  42  */
  43 public abstract class AbstractPropertyValueSetter<ValueType> extends HBox implements AbstractPropertySetter<ValueType> {
  44 
  45     public final static String BIND_BUTTON_SUFFIX = "_BIND_BUTTON_ID";
  46     public final static String BIDIR_PREFIX = "BIDIR_";
  47     public final static String UNIDIR_PREFIX = "UNIDIR_";
  48     public final static String SET_PREFIX = "SETTER_";
  49     public final static String CONTROLLER_SUFFIX = "_CONTROLLER_ID";
  50     protected Property leadingProperty;
  51     protected Property listeningProperty;


  54     protected Object initialValue1;
  55     protected Object initialValue2;
  56     protected Object initialValue3;
  57     protected PropertyValueType propertyValueType;
  58     private BindingType btype;
  59     private EventHandler<ActionEvent> setAction;
  60 
  61     protected void bindComponent(final BindingType btype, final Object testedControl) {
  62         this.btype = btype;
  63         String bindButtonId = ((btype == BindingType.UNIDIRECTIONAL) ? UNIDIR_PREFIX : BIDIR_PREFIX) + listeningProperty.getName().toUpperCase() + BIND_BUTTON_SUFFIX;
  64         setStyle("-fx-border-color : black;");
  65         setSpacing(3);
  66 
  67         binding = new ToggleBindingSwitcher(leadingProperty, listeningProperty, btype);
  68         binding.getVisualRepresentation().setId(bindButtonId);
  69 
  70         String labelDescription = btype.equals(BindingType.UNIDIRECTIONAL) ? "UNIDIR" : "BIDIR";
  71         getChildren().addAll(new Label(labelDescription.toUpperCase().substring(0, Math.min(15, labelDescription.length()) - 1)), leadingControl, binding.getVisualRepresentation());
  72 
  73         if (btype == BindingType.UNIDIRECTIONAL) {
  74             Button setButton = new Button("set");

  75             setButton.setMinWidth(38);

  76             setButton.setId(SET_PREFIX + listeningProperty.getName().toUpperCase());

  77             setAction = new EventHandler<ActionEvent>() {
  78                 public void handle(ActionEvent t) {
  79                     //bindingTB.setSelected(false);I think, that is not obligative.
  80                     //But otherwise, exception will be thrown each time, when unidirectional binding is switched on.
  81                     Method setter;
  82                     try {
  83                         Object value = listeningProperty.getValue();
  84 
  85                         Class returnClass;
  86 
  87 
  88                         if (value instanceof Boolean) {
  89                             returnClass = boolean.class;
  90                         } else {
  91                             returnClass = testedControl.getClass().getMethod("get" + listeningProperty.getName().substring(0, 1).toUpperCase() + listeningProperty.getName().substring(1, listeningProperty.getName().length())).getReturnType();
  92                         }
  93 
  94                         Object argument = leadingProperty.getValue();
  95                         if (value instanceof Integer) {
  96                             argument = (int) Math.round((Double) argument);