-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration test of composite editor
- Loading branch information
Showing
6 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...src/test/java/com/developmentontheedge/beans/integration/composite/BeanInfoExGeneric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.developmentontheedge.beans.integration.composite; | ||
|
||
import java.util.function.Function; | ||
import java.util.stream.Stream; | ||
|
||
import com.developmentontheedge.beans.BeanInfoEx; | ||
|
||
public class BeanInfoExGeneric<T> extends BeanInfoEx | ||
{ | ||
protected BeanInfoExGeneric() | ||
{ | ||
super(); | ||
} | ||
/** | ||
* @param beanClass | ||
*/ | ||
public BeanInfoExGeneric(Class<? extends T> beanClass) | ||
{ | ||
super(beanClass, true); | ||
} | ||
|
||
@Override | ||
public PropertyDescriptorBuilder2 property(String name) | ||
{ | ||
return new PropertyDescriptorBuilder2( name ); | ||
} | ||
|
||
public class PropertyDescriptorBuilder2 extends PropertyDescriptorBuilder | ||
{ | ||
public PropertyDescriptorBuilder2(String name) | ||
{ | ||
super(name); | ||
} | ||
|
||
public void add() | ||
{ | ||
BeanInfoExGeneric.this.add(pd); | ||
} | ||
|
||
public void add(int i) | ||
{ | ||
BeanInfoExGeneric.this.add(i, pd); | ||
} | ||
|
||
@SuppressWarnings ( "unchecked" ) | ||
public PropertyDescriptorBuilder2 tags(Function<T, Stream<String>> tagsSupplier) | ||
{ | ||
tagsFunction( (Function<Object, Stream<String>>)tagsSupplier ); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PropertyDescriptorBuilder2 tags(String... tags) | ||
{ | ||
return tags( bean -> Stream.of(tags) ); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
beans/src/test/java/com/developmentontheedge/beans/integration/composite/Curve.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.developmentontheedge.beans.integration.composite; | ||
|
||
import com.developmentontheedge.beans.Option; | ||
import com.developmentontheedge.beans.annot.PropertyName; | ||
import one.util.streamex.StreamEx; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class Curve extends Option { | ||
|
||
private static final String TIME_VARIABLE = "time"; | ||
private String path = "path1"; | ||
private String name = TIME_VARIABLE; | ||
private String title = TIME_VARIABLE; | ||
|
||
private static final Map<String, String[]> pathToNameMap = new HashMap<String, String[]>() {{ | ||
put("path1", new String[]{TIME_VARIABLE, "1_1", "1_2", "1_3", "1_4", "1_5"}); | ||
put("path2", new String[]{TIME_VARIABLE, "2_1", "2_2", "2_3", "2_4", "2_5"}); | ||
put("path3", new String[]{TIME_VARIABLE, "3_1", "3_2", "3_3", "3_4", "3_5"}); | ||
put("path4", new String[]{TIME_VARIABLE, "4_1", "4_2", "4_3", "4_4", "4_5"}); | ||
put("path5", new String[]{TIME_VARIABLE, "5_1", "5_2", "5_3", "5_4", "5_5"}); | ||
}}; | ||
private static final Map<String, String> nametoTitleMap = new HashMap<String, String>() {{ | ||
for (String[] names : pathToNameMap.values()) | ||
for (String name : names) | ||
put(name, name.replace('_', ':')); | ||
}}; | ||
|
||
@PropertyName("Path") | ||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
String oldValue = this.path; | ||
this.path = path; | ||
firePropertyChange("path", oldValue, path); | ||
if (!Objects.equals(oldValue, path)) { | ||
setName(TIME_VARIABLE); | ||
setTitle(TIME_VARIABLE); | ||
firePropertyChange("*", null, null); | ||
} | ||
} | ||
|
||
@PropertyName("Name") | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
String oldValue = this.name; | ||
|
||
this.name = name; | ||
setTitle(nametoTitleMap.getOrDefault(name, name)); | ||
|
||
|
||
firePropertyChange("name", oldValue, name); | ||
} | ||
|
||
public StreamEx<String> variables() { | ||
if (path == null) | ||
return StreamEx.empty(); | ||
|
||
return StreamEx.of(pathToNameMap.getOrDefault(path, new String[]{""})); | ||
} | ||
|
||
public StreamEx<String> modules() { | ||
return StreamEx.of(pathToNameMap.keySet()); | ||
} | ||
|
||
@PropertyName("Title") | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
String oldValue = this.title; | ||
this.title = title; | ||
firePropertyChange("title", oldValue, title); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
beans/src/test/java/com/developmentontheedge/beans/integration/composite/CurveBeanInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.developmentontheedge.beans.integration.composite; | ||
|
||
public class CurveBeanInfo extends BeanInfoExGeneric<Curve> { | ||
public CurveBeanInfo() { | ||
super(Curve.class); | ||
setHideChildren(true); | ||
setCompositeEditor("path;name;title", new java.awt.GridLayout(1, 3)); | ||
} | ||
|
||
public void initProperties() { | ||
property("path").tags(bean -> bean.modules()).add(); | ||
property("name").tags(bean -> bean.variables()).add(); | ||
add("title"); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
beans/src/test/java/com/developmentontheedge/beans/integration/composite/CurveTestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.developmentontheedge.beans.integration.composite; | ||
|
||
import com.developmentontheedge.beans.integration.SwingBeanIT; | ||
import junit.framework.Test; | ||
|
||
public class CurveTestIT extends SwingBeanIT { | ||
public CurveTestIT(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public void testModelProperties() throws Exception { | ||
|
||
} | ||
|
||
|
||
public static Test suite() { | ||
SwingBeanIT.beanClass = CurveWrapper.class; | ||
SwingBeanIT.testClass = com.developmentontheedge.beans.integration.SwingDynamicPropertiesBeanIT.class; | ||
|
||
return SwingBeanIT.suite(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SwingBeanIT.beanClass = CurveWrapper.class; | ||
SwingBeanIT.testClass = com.developmentontheedge.beans.integration.SwingDynamicPropertiesBeanIT.class; | ||
|
||
try { | ||
SwingBeanIT beanTest = new com.developmentontheedge.beans.integration.SwingDynamicPropertiesBeanIT("XXX"); | ||
beanTest.testCreateBeanInstance(); | ||
beanTest.testCreateModel(); | ||
beanTest.testViewModel(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
beans/src/test/java/com/developmentontheedge/beans/integration/composite/CurveWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.developmentontheedge.beans.integration.composite; | ||
|
||
import com.developmentontheedge.beans.Option; | ||
import com.developmentontheedge.beans.annot.PropertyName; | ||
|
||
public class CurveWrapper extends Option { | ||
Curve[] curves; | ||
Curve singleCurve = new Curve(); | ||
String test = ""; | ||
|
||
public CurveWrapper() | ||
{ | ||
curves = new Curve[1]; | ||
curves[0] = new Curve(); | ||
} | ||
|
||
@PropertyName("Curves list") | ||
public Curve[] getCurves() { | ||
return curves; | ||
} | ||
|
||
public void setCurves(Curve[] curves) { | ||
Object oldValue = this.curves; | ||
this.curves = curves; | ||
firePropertyChange("curves", oldValue, curves); | ||
} | ||
|
||
@PropertyName("Useless string") | ||
public String getTest() { | ||
return test; | ||
} | ||
|
||
public void setTest(String test) { | ||
String oldValue = this.test; | ||
this.test = test; | ||
firePropertyChange("test", oldValue, test); | ||
} | ||
|
||
@PropertyName("Single curve") | ||
public Curve getSingleCurve() { | ||
return singleCurve; | ||
} | ||
|
||
public void setSingleCurve(Curve singleCurve) { | ||
Object oldValue = this.singleCurve; | ||
this.singleCurve = singleCurve; | ||
firePropertyChange("singleCurve", oldValue, singleCurve); | ||
} | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
.../test/java/com/developmentontheedge/beans/integration/composite/CurveWrapperBeanInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.developmentontheedge.beans.integration.composite; | ||
|
||
public class CurveWrapperBeanInfo extends BeanInfoExGeneric<CurveWrapper> { | ||
|
||
public CurveWrapperBeanInfo() { | ||
super(CurveWrapper.class); | ||
} | ||
|
||
@Override | ||
public void initProperties() throws Exception { | ||
add("singleCurve"); | ||
add("test"); | ||
add("curves"); | ||
} | ||
} |