Skip to content

Commit

Permalink
see component bindTo as fluent API
Browse files Browse the repository at this point in the history
  • Loading branch information
tbee committed Mar 15, 2023
1 parent 9a02928 commit 2406594
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 157 deletions.
47 changes: 21 additions & 26 deletions src/main/java/org/tbee/sway/SButtonGroup.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tbee.sway;

import org.tbee.sway.binding.Binding;
import org.tbee.sway.binding.BindingEndpoint;
import org.tbee.sway.binding.ExceptionHandler;
import org.tbee.sway.format.Format;
Expand Down Expand Up @@ -44,7 +43,7 @@
* .add(1, new SRadioButton("1")) //
* .add(2, new SRadioButton("2") //
* .add(3, new SRadioButton("3") //
* .bind(race, "position");
* .bindTo(race, "position");
* }
* </pre>
* Or combined with Format and FormatRegistry:
Expand Down Expand Up @@ -194,30 +193,6 @@ private AbstractButton getSelectedButton() {
}


// ========================================================
// BIND

/**
* Binds the default property 'value'
*
* @param bindingEndpoint
* @return this, for fluent API
*/
public SButtonGroup<T> bindTo(BindingEndpoint<T> bindingEndpoint) {
value$().bindTo(bindingEndpoint);
return this;
}

/**
* Binds the default property 'value'
*
* @param bindingEndpoint
* @return
*/
public Binding binding(BindingEndpoint<T> bindingEndpoint) {
return value$().bindTo(bindingEndpoint);
}

// ===========================================================================================================================
// CONVENIENCE

Expand Down Expand Up @@ -378,4 +353,24 @@ private boolean handleException(Throwable e) {
// Mark exception as handled
return true;
}


// ========================================================
// FLUENT API

/**
* Binds the default property 'value'
*/
public SButtonGroup<T> bindTo(BindingEndpoint<T> bindingEndpoint) {
value$().bindTo(bindingEndpoint);
return this;
}

/**
* Binds to the default property 'value'.
* Binding in this way is not type safe!
*/
public SButtonGroup<T> bindTo(Object bean, String propertyName) {
return bindTo(BindingEndpoint.of(bean, propertyName));
}
}
42 changes: 16 additions & 26 deletions src/main/java/org/tbee/sway/SCheckBox.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tbee.sway;

import org.tbee.sway.binding.Binding;
import org.tbee.sway.binding.BindingEndpoint;
import org.tbee.sway.binding.ExceptionHandler;
import org.tbee.sway.support.IconRegistry;
Expand Down Expand Up @@ -115,31 +114,6 @@ private boolean handleException(Throwable e) {
}


// ==================================================
// BIND

/**
* Binds the default property 'selected'
*
* @param bindingEndpoint
* @return this, for fluent API
*/
public SCheckBox bindTo(BindingEndpoint<Boolean> bindingEndpoint) {
selected$().bindTo(bindingEndpoint);
return this;
}

/**
* Binds the default property 'selected'
*
* @param bindingEndpoint
* @return
*/
public Binding binding(BindingEndpoint<Boolean> bindingEndpoint) {
return selected$().bindTo(bindingEndpoint);
}


// ==============================================
// FLUENT API

Expand Down Expand Up @@ -187,4 +161,20 @@ public SCheckBox visible(boolean value) {
setVisible(value);
return this;
}

/**
* Binds the default property 'selected'
*/
public SCheckBox bindTo(BindingEndpoint<Boolean> bindingEndpoint) {
selected$().bindTo(bindingEndpoint);
return this;
}

/**
* Binds to the default property 'selected'.
* Binding in this way is not type safe!
*/
public SCheckBox bindTo(Object bean, String propertyName) {
return bindTo(BindingEndpoint.of(bean, propertyName));
}
}
41 changes: 16 additions & 25 deletions src/main/java/org/tbee/sway/SCheckBox3.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

package org.tbee.sway;

import org.tbee.sway.binding.Binding;
import org.tbee.sway.binding.BindingEndpoint;
import org.tbee.sway.binding.ExceptionHandler;
import org.tbee.sway.support.IconRegistry;
Expand Down Expand Up @@ -280,30 +279,6 @@ private boolean handleException(Throwable e) {
return true;
}

// ==================================================
// BIND

/**
* Binds the default property 'selected3'
*
* @param bindingEndpoint
* @return this, for fluent API
*/
public SCheckBox3 bindTo(BindingEndpoint<Boolean> bindingEndpoint) {
selected3$().bindTo(bindingEndpoint);
return this;
}

/**
* Binds the default property 'selected3'
*
* @param bindingEndpoint
* @return
*/
public Binding binding(BindingEndpoint<Boolean> bindingEndpoint) {
return selected3$().bindTo(bindingEndpoint);
}


// ==============================================
// FLUENT API
Expand Down Expand Up @@ -352,5 +327,21 @@ public SCheckBox3 visible(boolean value) {
setVisible(value);
return this;
}

/**
* Binds the default property 'selected3'
*/
public SCheckBox3 bindTo(BindingEndpoint<Boolean> bindingEndpoint) {
selected3$().bindTo(bindingEndpoint);
return this;
}

/**
* Binds to the default property 'selected3'.
* Binding in this way is not type safe!
*/
public SCheckBox3 bindTo(Object bean, String propertyName) {
return bindTo(BindingEndpoint.of(bean, propertyName));
}
}

43 changes: 17 additions & 26 deletions src/main/java/org/tbee/sway/SComboBox.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.tbee.sway;

import org.tbee.sway.binding.Binding;
import org.tbee.sway.binding.BindingEndpoint;
import org.tbee.sway.binding.ExceptionHandler;
import org.tbee.sway.format.Format;
Expand Down Expand Up @@ -226,20 +225,6 @@ static public <T> SComboBox<T> of(List<T> data) {
}


// ===========================================================================
// FLUENT API

public SComboBox<T> name(String v) {
setName(v);
return this;
}

public SComboBox<T> visible(boolean v) {
setVisible(v);
return this;
}


// ========================================================
// EXCEPTION HANDLER

Expand Down Expand Up @@ -279,27 +264,33 @@ private boolean handleException(Throwable e) {
return true;
}

// ========================================================
// BIND
// ===========================================================================
// FLUENT API

public SComboBox<T> name(String v) {
setName(v);
return this;
}

public SComboBox<T> visible(boolean v) {
setVisible(v);
return this;
}

/**
* Binds the default property 'value'
* @param bindingEndpoint
* @return this, for fluent API
* Binds to the default property 'value'
*/
public SComboBox<T> bindTo(BindingEndpoint<T> bindingEndpoint) {
value$().bindTo(bindingEndpoint);
return this;
}

/**
* Binds the default property 'value'
*
* @param bindingEndpoint
* @return
* Binds to the default property 'value'.
* Binding in this way is not type safe!
*/
public Binding binding(BindingEndpoint<T> bindingEndpoint) {
return value$().bindTo(bindingEndpoint);
public SComboBox<T> bindTo(Object bean, String propertyName) {
return bindTo(BindingEndpoint.of(bean, propertyName));
}

// TBEERNOT Tests
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/org/tbee/sway/SList.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,21 @@ static public <T> SList<T> of(List<T> data) {
return new SList<T>().data(data);
}

/**
* Binds to the default property 'selection'
*/
public SList<T> bindTo(BindingEndpoint<List<T>> bindingEndpoint) {
selection$().bindTo(bindingEndpoint);
return this;
}

/**
* Binds to the default property 'selection'.
* Binding in this way is not type safe!
*/
public SList<T> bindTo(Object bean, String propertyName) {
return bindTo(BindingEndpoint.of(bean, propertyName));
}

// TBEERNOT ExceptionHandler
// TBEERNOT BINDING of selection (bind with STable)
// TBEERNOT introduce value as the last selected row? because of: binding of value
}
19 changes: 15 additions & 4 deletions src/main/java/org/tbee/sway/STable.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public STable<TableType> onSelectionChanged(Consumer<List<TableType>> onSelectio


// ===========================================================================
// BINING
// BINDING

private Method addPropertyChangeListenerMethod = null;
private Method removePropertyChangeListenerMethod = null;
Expand Down Expand Up @@ -1327,8 +1327,19 @@ public STable<TableType> visible(boolean value) {
return this;
}

/**
* Binds to the default property 'selection'
*/
public STable<TableType> bindTo(BindingEndpoint<List<TableType>> bindingEndpoint) {
selection$().bindTo(bindingEndpoint);
return this;
}

// TBEERNOT BINDING of selection (bind with SList)
// TBEERNOT introduce value as the last selected row? because of: binding of value

/**
* Binds to the default property 'selection'.
* Binding in this way is not type safe!
*/
public STable<TableType> bindTo(Object bean, String propertyName) {
return bindTo(BindingEndpoint.of(bean, propertyName));
}
}
Loading

0 comments on commit 2406594

Please sign in to comment.