|
@@ -1,82 +1,82 @@ |
1 |
|
- |
package com.temp.client.foundation.widget.input.fieldsupport; |
2 |
|
- |
|
3 |
|
- |
import com.google.gwt.event.dom.client.*; |
4 |
|
- |
import com.google.gwt.event.shared.*; |
5 |
|
- |
import com.temp.client.foundation.widget.input.support.*; |
6 |
|
- |
import com.temp.client.foundation.widget.input.support.events.*; |
7 |
|
- |
import com.temp.shared.utils.*; |
8 |
|
- |
|
9 |
|
- |
public class InputWidgetChangeFilter<T> implements InputWidgetValueAdapter<T> { |
10 |
|
- |
protected final NonDomHandlerManager<ChangeHandler> handlerManager; |
11 |
|
- |
protected final InputWidgetValueAdapter<T> delegateTo; |
12 |
|
- |
protected T baseNotChangedValue; |
13 |
|
- |
protected boolean isChanged; |
14 |
|
- |
|
15 |
|
- |
public InputWidgetChangeFilter( InputWidgetValueAdapter<T> delegateTo ) { |
16 |
|
- |
handlerManager = new NonDomHandlerManager<ChangeHandler>( this ); |
17 |
|
- |
this.delegateTo = delegateTo; |
18 |
|
- |
baseNotChangedValue = delegateTo.getValue(); |
19 |
|
- |
delegateTo.addChangeHandler( new ChangeHandler() { |
20 |
|
- |
@Override |
21 |
|
- |
public void onChange( ChangeEvent event ) { |
22 |
|
- |
checkForChange(); |
23 |
|
- |
} |
24 |
|
- |
} ); |
25 |
|
- |
} |
26 |
|
- |
|
27 |
|
- |
public HandlerRegistration addFilteredChangeHandler( ChangeHandler handler ) { |
28 |
|
- |
return handler == null ? null : registerChangeHandler( handler ); |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
@Override |
32 |
|
- |
public HandlerRegistration addChangeHandler( ChangeHandler handler ) { |
33 |
|
- |
return delegateTo.addChangeHandler( handler ); |
34 |
|
- |
} |
35 |
|
- |
|
36 |
|
- |
@Override |
37 |
|
- |
public T getValue() { |
38 |
|
- |
return checkForChange(); |
39 |
|
- |
} |
40 |
|
- |
|
41 |
|
- |
@Override |
42 |
|
- |
public void setValue( T value ) { |
43 |
|
- |
delegateTo.setValue( value ); |
44 |
|
- |
baseNotChangedValue = delegateTo.getValue(); |
45 |
|
- |
setChanged( false ); |
46 |
|
- |
} |
47 |
|
- |
|
48 |
|
- |
public T getBaseValue() { |
49 |
|
- |
return baseNotChangedValue; |
50 |
|
- |
} |
51 |
|
- |
|
52 |
|
- |
public void setValueAsUser( T value ) { |
53 |
|
- |
delegateTo.setValue( value ); |
54 |
|
- |
checkForChange(); |
55 |
|
- |
} |
56 |
|
- |
|
57 |
|
- |
public boolean isChanged() { |
58 |
|
- |
return isChanged; |
59 |
|
- |
} |
60 |
|
- |
|
61 |
|
- |
protected T checkForChange() { |
62 |
|
- |
T curValue = delegateTo.getValue(); |
63 |
|
- |
setChanged( !ObjectUtils.areEqual( baseNotChangedValue, curValue ) ); |
64 |
|
- |
return curValue; |
65 |
|
- |
} |
66 |
|
- |
|
67 |
|
- |
protected void setChanged( boolean newChangedState ) { |
68 |
|
- |
boolean curChangedState = isChanged; |
69 |
|
- |
isChanged = newChangedState; |
70 |
|
- |
if ( curChangedState != newChangedState ) { |
71 |
|
- |
notifyChangeHandlers(); |
72 |
|
- |
} |
73 |
|
- |
} |
74 |
|
- |
|
75 |
|
- |
protected void notifyChangeHandlers() { |
76 |
|
- |
handlerManager.fireEvent( new NonDomChangeEvent() ); |
77 |
|
- |
} |
78 |
|
- |
|
79 |
|
- |
protected HandlerRegistration registerChangeHandler( ChangeHandler handler ) { |
80 |
|
- |
return handlerManager.addHandler( handler ); |
81 |
|
- |
} |
82 |
|
- |
} |
|
1 |
+ |
package com.temp.client.foundation.widget.input.fieldsupport; |
|
2 |
+ |
|
|
3 |
+ |
import com.google.gwt.event.dom.client.*; |
|
4 |
+ |
import com.google.gwt.event.shared.*; |
|
5 |
+ |
import com.temp.client.foundation.widget.input.support.*; |
|
6 |
+ |
import com.temp.client.foundation.widget.input.support.events.*; |
|
7 |
+ |
import com.temp.shared.utils.*; |
|
8 |
+ |
|
|
9 |
+ |
public class InputWidgetChangeFilter<T> implements InputWidgetValueAdapter<T> { |
|
10 |
+ |
protected final NonDomHandlerManager<ChangeHandler> handlerManager; |
|
11 |
+ |
protected final InputWidgetValueAdapter<T> delegateTo; |
|
12 |
+ |
protected T baseNotChangedValue; |
|
13 |
+ |
protected boolean isChanged; |
|
14 |
+ |
|
|
15 |
+ |
public InputWidgetChangeFilter( InputWidgetValueAdapter<T> delegateTo ) { |
|
16 |
+ |
handlerManager = new NonDomHandlerManager<ChangeHandler>( this ); |
|
17 |
+ |
this.delegateTo = delegateTo; |
|
18 |
+ |
baseNotChangedValue = delegateTo.getValue(); |
|
19 |
+ |
delegateTo.addChangeHandler( new ChangeHandler() { |
|
20 |
+ |
@Override |
|
21 |
+ |
public void onChange( ChangeEvent event ) { |
|
22 |
+ |
checkForChange(); |
|
23 |
+ |
} |
|
24 |
+ |
} ); |
|
25 |
+ |
} |
|
26 |
+ |
|
|
27 |
+ |
public HandlerRegistration addFilteredChangeHandler( ChangeHandler handler ) { |
|
28 |
+ |
return handler == null ? null : registerChangeHandler( handler ); |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
@Override |
|
32 |
+ |
public HandlerRegistration addChangeHandler( ChangeHandler handler ) { |
|
33 |
+ |
return delegateTo.addChangeHandler( handler ); |
|
34 |
+ |
} |
|
35 |
+ |
|
|
36 |
+ |
@Override |
|
37 |
+ |
public T getValue() { |
|
38 |
+ |
return checkForChange(); |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
@Override |
|
42 |
+ |
public void setValue( T value ) { |
|
43 |
+ |
delegateTo.setValue( value ); |
|
44 |
+ |
baseNotChangedValue = delegateTo.getValue(); |
|
45 |
+ |
setChanged( false ); |
|
46 |
+ |
} |
|
47 |
+ |
|
|
48 |
+ |
public T getBaseValue() { |
|
49 |
+ |
return baseNotChangedValue; |
|
50 |
+ |
} |
|
51 |
+ |
|
|
52 |
+ |
public void setValueAsUser( T value ) { |
|
53 |
+ |
delegateTo.setValue( value ); |
|
54 |
+ |
checkForChange(); |
|
55 |
+ |
} |
|
56 |
+ |
|
|
57 |
+ |
public boolean isChanged() { |
|
58 |
+ |
return isChanged; |
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
protected T checkForChange() { |
|
62 |
+ |
T curValue = delegateTo.getValue(); |
|
63 |
+ |
setChanged( !ObjectUtils.areEqual( baseNotChangedValue, curValue ) ); |
|
64 |
+ |
return curValue; |
|
65 |
+ |
} |
|
66 |
+ |
|
|
67 |
+ |
protected void setChanged( boolean newChangedState ) { |
|
68 |
+ |
boolean curChangedState = isChanged; |
|
69 |
+ |
isChanged = newChangedState; |
|
70 |
+ |
if ( curChangedState != newChangedState ) { |
|
71 |
+ |
notifyChangeHandlers(); |
|
72 |
+ |
} |
|
73 |
+ |
} |
|
74 |
+ |
|
|
75 |
+ |
protected void notifyChangeHandlers() { |
|
76 |
+ |
handlerManager.fireEvent( new NonDomChangeEvent() ); |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
protected HandlerRegistration registerChangeHandler( ChangeHandler handler ) { |
|
80 |
+ |
return handlerManager.addHandler( handler ); |
|
81 |
+ |
} |
|
82 |
+ |
} |