|
@@ -1,119 +1,119 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.client.components.factories.others; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
5 |
|
- |
import org.litesoft.GWT.forms.client.components.factories.*; |
6 |
|
- |
import org.litesoft.GWT.forms.client.nonpublic.*; |
7 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
8 |
|
- |
import org.litesoft.ui.def.*; |
9 |
|
- |
import org.litesoft.ui.def.nonpublic.*; |
10 |
|
- |
import org.litesoft.ui.def.nonpublic.support.*; |
11 |
|
- |
|
12 |
|
- |
import com.google.gwt.user.client.ui.*; |
13 |
|
- |
|
14 |
|
- |
import java.io.*; |
15 |
|
- |
|
16 |
|
- |
public class UiInputActionWidgetFactory implements FormComponentFactory { |
17 |
|
- |
public Widget create( FormInstanceComponentHandler pComponentHandler, UiDef pUiDef, |
18 |
|
- |
FormMetaData pFormMetaData, boolean pHasHorizontalPeer ) { |
19 |
|
- |
UiInputActionDef zDef = (UiInputActionDef) pUiDef; |
20 |
|
- |
AttributeMetaData zMD = pFormMetaData.getAttribute( zDef ); |
21 |
|
- |
if ( zMD == null ) { |
22 |
|
- |
throw new IllegalStateException( "Metadata required for a " + zDef ); |
23 |
|
- |
} |
24 |
|
- |
return ApplyFont.to( zDef.getFont(), new MyFormAdapter( pComponentHandler, zMD, zDef ).init() ); |
25 |
|
- |
} |
26 |
|
- |
|
27 |
|
- |
private static final class MyFormAdapter extends FormButtonAdapter implements FormAttributeAdapter { |
28 |
|
- |
private Integer mUniqueID; |
29 |
|
- |
private Boolean mBaseValue = Boolean.FALSE; |
30 |
|
- |
private Boolean mCurValue = Boolean.FALSE; |
31 |
|
- |
|
32 |
|
- |
public MyFormAdapter( FormInstanceComponentHandler pComponentHandler, // |
33 |
|
- |
AttributeMetaData pMD, UiInputActionDef pDef ) { |
34 |
|
- |
super( pComponentHandler, pMD.getAttributeReference(), pMD, pDef ); |
35 |
|
- |
mUniqueID = pMD.getUniqueID(); |
36 |
|
- |
} |
37 |
|
- |
|
38 |
|
- |
protected Widget initWidget() { |
39 |
|
- |
mComponentFormHandler.addAttributeAdapter( this ); |
40 |
|
- |
return super.initWidget(); |
41 |
|
- |
} |
42 |
|
- |
|
43 |
|
- |
public void onClick( Widget sender ) { |
44 |
|
- |
if ( !Boolean.TRUE.equals( mCurValue ) ) { |
45 |
|
- |
mCurValue = Boolean.TRUE; |
46 |
|
- |
mComponentFormHandler.componentChangedState( true ); |
47 |
|
- |
// send the attribute change |
48 |
|
- |
mComponentFormHandler.componentUpdatedValue( this, mCurValue ); |
49 |
|
- |
// then send the action |
50 |
|
- |
actionRequested( true ); |
51 |
|
- |
|
52 |
|
- |
setDisabled( true ); |
53 |
|
- |
} |
54 |
|
- |
} |
55 |
|
- |
|
56 |
|
- |
// FormAttributeAdapter |
57 |
|
- |
|
58 |
|
- |
public Integer getUniqueID() { |
59 |
|
- |
return mUniqueID; |
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
public String getAttributeReference() { |
63 |
|
- |
return getActionID(); |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
public boolean isErrorState() { |
67 |
|
- |
return false; |
68 |
|
- |
} |
69 |
|
- |
|
70 |
|
- |
public String getErrorText() { |
71 |
|
- |
return null; |
72 |
|
- |
} |
73 |
|
- |
|
74 |
|
- |
public void setErrorText( String pError ) { |
75 |
|
- |
// Buttons can not be in error |
76 |
|
- |
} |
77 |
|
- |
|
78 |
|
- |
public boolean isChangedState() { |
79 |
|
- |
return !mBaseValue.equals( mCurValue ); |
80 |
|
- |
} |
81 |
|
- |
|
82 |
|
- |
public Serializable getBaseValue() { |
83 |
|
- |
return mBaseValue; |
84 |
|
- |
} |
85 |
|
- |
|
86 |
|
- |
public void setBaseValue( Serializable pBaseValue ) { |
87 |
|
- |
setCurrentValue( mBaseValue = convert( pBaseValue ) ); |
88 |
|
- |
} |
89 |
|
- |
|
90 |
|
- |
public Serializable getCurrentValue() { |
91 |
|
- |
return mCurValue; |
92 |
|
- |
} |
93 |
|
- |
|
94 |
|
- |
public void setCurrentValue( Serializable pCurrentValue ) { |
95 |
|
- |
mCurValue = convert( pCurrentValue ); |
96 |
|
- |
setDisabled( Boolean.TRUE.equals( mCurValue ) ); |
97 |
|
- |
} |
98 |
|
- |
|
99 |
|
- |
public String getUserValue() { |
100 |
|
- |
return mCurValue.toString(); |
101 |
|
- |
} |
102 |
|
- |
|
103 |
|
- |
public void setUserValue( String pValue ) { |
104 |
|
- |
setCurrentValue( Booleans.fromString( pValue ) ); |
105 |
|
- |
} |
106 |
|
- |
|
107 |
|
- |
public void publishAnyPendingChanges() { |
108 |
|
- |
// Do nothing as Buttons do not do defferred processing |
109 |
|
- |
} |
110 |
|
- |
|
111 |
|
- |
public void updateValidOptions( Serializable[] pValidOptions ) { |
112 |
|
- |
// Do nothing as Buttons do NOT support valid Options |
113 |
|
- |
} |
114 |
|
- |
|
115 |
|
- |
private Boolean convert( Serializable pValue ) { |
116 |
|
- |
return Boolean.TRUE.equals( pValue ); |
117 |
|
- |
} |
118 |
|
- |
} |
119 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.client.components.factories.others; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
5 |
+ |
import org.litesoft.GWT.forms.client.components.factories.*; |
|
6 |
+ |
import org.litesoft.GWT.forms.client.nonpublic.*; |
|
7 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
|
8 |
+ |
import org.litesoft.ui.def.*; |
|
9 |
+ |
import org.litesoft.ui.def.nonpublic.*; |
|
10 |
+ |
import org.litesoft.ui.def.nonpublic.support.*; |
|
11 |
+ |
|
|
12 |
+ |
import com.google.gwt.user.client.ui.*; |
|
13 |
+ |
|
|
14 |
+ |
import java.io.*; |
|
15 |
+ |
|
|
16 |
+ |
public class UiInputActionWidgetFactory implements FormComponentFactory { |
|
17 |
+ |
public Widget create( FormInstanceComponentHandler pComponentHandler, UiDef pUiDef, |
|
18 |
+ |
FormMetaData pFormMetaData, boolean pHasHorizontalPeer ) { |
|
19 |
+ |
UiInputActionDef zDef = (UiInputActionDef) pUiDef; |
|
20 |
+ |
AttributeMetaData zMD = pFormMetaData.getAttribute( zDef ); |
|
21 |
+ |
if ( zMD == null ) { |
|
22 |
+ |
throw new IllegalStateException( "Metadata required for a " + zDef ); |
|
23 |
+ |
} |
|
24 |
+ |
return ApplyFont.to( zDef.getFont(), new MyFormAdapter( pComponentHandler, zMD, zDef ).init() ); |
|
25 |
+ |
} |
|
26 |
+ |
|
|
27 |
+ |
private static final class MyFormAdapter extends FormButtonAdapter implements FormAttributeAdapter { |
|
28 |
+ |
private Integer mUniqueID; |
|
29 |
+ |
private Boolean mBaseValue = Boolean.FALSE; |
|
30 |
+ |
private Boolean mCurValue = Boolean.FALSE; |
|
31 |
+ |
|
|
32 |
+ |
public MyFormAdapter( FormInstanceComponentHandler pComponentHandler, // |
|
33 |
+ |
AttributeMetaData pMD, UiInputActionDef pDef ) { |
|
34 |
+ |
super( pComponentHandler, pMD.getAttributeReference(), pMD, pDef ); |
|
35 |
+ |
mUniqueID = pMD.getUniqueID(); |
|
36 |
+ |
} |
|
37 |
+ |
|
|
38 |
+ |
protected Widget initWidget() { |
|
39 |
+ |
mComponentFormHandler.addAttributeAdapter( this ); |
|
40 |
+ |
return super.initWidget(); |
|
41 |
+ |
} |
|
42 |
+ |
|
|
43 |
+ |
public void onClick( Widget sender ) { |
|
44 |
+ |
if ( !Boolean.TRUE.equals( mCurValue ) ) { |
|
45 |
+ |
mCurValue = Boolean.TRUE; |
|
46 |
+ |
mComponentFormHandler.componentChangedState( true ); |
|
47 |
+ |
// send the attribute change |
|
48 |
+ |
mComponentFormHandler.componentUpdatedValue( this, mCurValue ); |
|
49 |
+ |
// then send the action |
|
50 |
+ |
actionRequested( true ); |
|
51 |
+ |
|
|
52 |
+ |
setDisabled( true ); |
|
53 |
+ |
} |
|
54 |
+ |
} |
|
55 |
+ |
|
|
56 |
+ |
// FormAttributeAdapter |
|
57 |
+ |
|
|
58 |
+ |
public Integer getUniqueID() { |
|
59 |
+ |
return mUniqueID; |
|
60 |
+ |
} |
|
61 |
+ |
|
|
62 |
+ |
public String getAttributeReference() { |
|
63 |
+ |
return getActionID(); |
|
64 |
+ |
} |
|
65 |
+ |
|
|
66 |
+ |
public boolean isErrorState() { |
|
67 |
+ |
return false; |
|
68 |
+ |
} |
|
69 |
+ |
|
|
70 |
+ |
public String getErrorText() { |
|
71 |
+ |
return null; |
|
72 |
+ |
} |
|
73 |
+ |
|
|
74 |
+ |
public void setErrorText( String pError ) { |
|
75 |
+ |
// Buttons can not be in error |
|
76 |
+ |
} |
|
77 |
+ |
|
|
78 |
+ |
public boolean isChangedState() { |
|
79 |
+ |
return !mBaseValue.equals( mCurValue ); |
|
80 |
+ |
} |
|
81 |
+ |
|
|
82 |
+ |
public Serializable getBaseValue() { |
|
83 |
+ |
return mBaseValue; |
|
84 |
+ |
} |
|
85 |
+ |
|
|
86 |
+ |
public void setBaseValue( Serializable pBaseValue ) { |
|
87 |
+ |
setCurrentValue( mBaseValue = convert( pBaseValue ) ); |
|
88 |
+ |
} |
|
89 |
+ |
|
|
90 |
+ |
public Serializable getCurrentValue() { |
|
91 |
+ |
return mCurValue; |
|
92 |
+ |
} |
|
93 |
+ |
|
|
94 |
+ |
public void setCurrentValue( Serializable pCurrentValue ) { |
|
95 |
+ |
mCurValue = convert( pCurrentValue ); |
|
96 |
+ |
setDisabled( Boolean.TRUE.equals( mCurValue ) ); |
|
97 |
+ |
} |
|
98 |
+ |
|
|
99 |
+ |
public String getUserValue() { |
|
100 |
+ |
return mCurValue.toString(); |
|
101 |
+ |
} |
|
102 |
+ |
|
|
103 |
+ |
public void setUserValue( String pValue ) { |
|
104 |
+ |
setCurrentValue( Booleans.fromString( pValue ) ); |
|
105 |
+ |
} |
|
106 |
+ |
|
|
107 |
+ |
public void publishAnyPendingChanges() { |
|
108 |
+ |
// Do nothing as Buttons do not do defferred processing |
|
109 |
+ |
} |
|
110 |
+ |
|
|
111 |
+ |
public void updateValidOptions( Serializable[] pValidOptions ) { |
|
112 |
+ |
// Do nothing as Buttons do NOT support valid Options |
|
113 |
+ |
} |
|
114 |
+ |
|
|
115 |
+ |
private Boolean convert( Serializable pValue ) { |
|
116 |
+ |
return Boolean.TRUE.equals( pValue ); |
|
117 |
+ |
} |
|
118 |
+ |
} |
|
119 |
+ |
} |