|
@@ -1,42 +1,34 @@ |
1 |
1 |
|
package org.litesoft.GWT.client.util; |
2 |
2 |
|
|
|
3 |
+ |
import org.litesoft.commonfoundation.base.*; |
3 |
4 |
|
import org.litesoft.commonfoundation.typeutils.*; |
4 |
5 |
|
|
5 |
6 |
|
import java.util.*; |
6 |
7 |
|
|
7 |
|
- |
import org.litesoft.commonfoundation.base.*; |
8 |
|
- |
|
9 |
|
- |
public class StyledSafeTextMessageUserSink implements MessageUserSink |
10 |
|
- |
{ |
|
8 |
+ |
public class StyledSafeTextMessageUserSink implements MessageUserSink { |
11 |
9 |
|
private final Manager mManager = new Manager(); |
12 |
10 |
|
private final StyledSafeTextSink mSafeTextSink; |
13 |
11 |
|
private PriorityMessage mCurrentMessage; |
14 |
12 |
|
|
15 |
|
- |
public StyledSafeTextMessageUserSink( StyledSafeTextSink pSafeTextSink ) |
16 |
|
- |
{ |
|
13 |
+ |
public StyledSafeTextMessageUserSink( StyledSafeTextSink pSafeTextSink ) { |
17 |
14 |
|
mSafeTextSink = pSafeTextSink; |
18 |
15 |
|
} |
19 |
16 |
|
|
20 |
17 |
|
@Override |
21 |
|
- |
public void clearMessage() |
22 |
|
- |
{ |
|
18 |
+ |
public void clearMessage() { |
23 |
19 |
|
Priority zNextPriority = mManager.getNextPriority(); |
24 |
|
- |
if ( !optionallyUpdateCurrentMessage( zNextPriority ) ) |
25 |
|
- |
{ |
|
20 |
+ |
if ( !optionallyUpdateCurrentMessage( zNextPriority ) ) { |
26 |
21 |
|
removeCurrentMessageStyle(); |
27 |
22 |
|
mCurrentMessage = null; |
28 |
|
- |
if ( !optionallyUpdateCurrentMessage( zNextPriority ) ) |
29 |
|
- |
{ |
|
23 |
+ |
if ( !optionallyUpdateCurrentMessage( zNextPriority ) ) { |
30 |
24 |
|
setMessageAndStyle( "", Priority.Info ); |
31 |
25 |
|
} |
32 |
26 |
|
} |
33 |
27 |
|
} |
34 |
28 |
|
|
35 |
29 |
|
@Override |
36 |
|
- |
public void clearMessage( String pMessage ) |
37 |
|
- |
{ |
38 |
|
- |
if ( mCurrentMessage != null && mCurrentMessage.hasMessage( pMessage ) ) |
39 |
|
- |
{ |
|
30 |
+ |
public void clearMessage( String pMessage ) { |
|
31 |
+ |
if ( mCurrentMessage != null && mCurrentMessage.hasMessage( pMessage ) ) { |
40 |
32 |
|
clearMessage(); |
41 |
33 |
|
return; |
42 |
34 |
|
} |
|
@@ -44,28 +36,23 @@ |
44 |
36 |
|
} |
45 |
37 |
|
|
46 |
38 |
|
@Override |
47 |
|
- |
public void setInfoMessage( String pMessage ) |
48 |
|
- |
{ |
|
39 |
+ |
public void setInfoMessage( String pMessage ) { |
49 |
40 |
|
optionallyUpdateCurrentMessage( mManager.addMessage( Priority.Info, pMessage ) ); |
50 |
41 |
|
} |
51 |
42 |
|
|
52 |
43 |
|
@Override |
53 |
|
- |
public void setWarningMessage( String pMessage ) |
54 |
|
- |
{ |
|
44 |
+ |
public void setWarningMessage( String pMessage ) { |
55 |
45 |
|
optionallyUpdateCurrentMessage( mManager.addMessage( Priority.Warning, pMessage ) ); |
56 |
46 |
|
} |
57 |
47 |
|
|
58 |
48 |
|
@Override |
59 |
|
- |
public void setErrorMessage( String pMessage ) |
60 |
|
- |
{ |
|
49 |
+ |
public void setErrorMessage( String pMessage ) { |
61 |
50 |
|
optionallyUpdateCurrentMessage( mManager.addMessage( Priority.Error, pMessage ) ); |
62 |
51 |
|
} |
63 |
52 |
|
|
64 |
53 |
|
@Override |
65 |
|
- |
public void setErrorMessage( Throwable pThrowable, String pMessage ) |
66 |
|
- |
{ |
67 |
|
- |
if ( pThrowable != null ) |
68 |
|
- |
{ |
|
54 |
+ |
public void setErrorMessage( Throwable pThrowable, String pMessage ) { |
|
55 |
+ |
if ( pThrowable != null ) { |
69 |
56 |
|
System.err.println( "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" ); |
70 |
57 |
|
System.err.println( pMessage ); |
71 |
58 |
|
pThrowable.printStackTrace(); |
|
@@ -79,13 +66,10 @@ |
79 |
66 |
|
* |
80 |
67 |
|
* @return true if updated the the Current Message |
81 |
68 |
|
*/ |
82 |
|
- |
private boolean optionallyUpdateCurrentMessage( Priority pNextHighestPriority ) |
83 |
|
- |
{ |
84 |
|
- |
if ( pNextHighestPriority != null ) |
85 |
|
- |
{ |
|
69 |
+ |
private boolean optionallyUpdateCurrentMessage( Priority pNextHighestPriority ) { |
|
70 |
+ |
if ( pNextHighestPriority != null ) { |
86 |
71 |
|
Priority zCurrentPriority = getCurrentMessagePriority(); |
87 |
|
- |
if ( zCurrentPriority == null || zCurrentPriority.isLowerPriorityThan( pNextHighestPriority ) ) |
88 |
|
- |
{ |
|
72 |
+ |
if ( zCurrentPriority == null || zCurrentPriority.isLowerPriorityThan( pNextHighestPriority ) ) { |
89 |
73 |
|
removeCurrentMessageStyle(); |
90 |
74 |
|
mCurrentMessage = mManager.getNextMessage(); |
91 |
75 |
|
setMessageAndStyle( mCurrentMessage.getMessage(), mCurrentMessage.getPriority() ); |
|
@@ -95,62 +79,51 @@ |
95 |
79 |
|
return false; |
96 |
80 |
|
} |
97 |
81 |
|
|
98 |
|
- |
private void removeCurrentMessageStyle() |
99 |
|
- |
{ |
|
82 |
+ |
private void removeCurrentMessageStyle() { |
100 |
83 |
|
Priority zCurrentStyle = Priority.deNull( getCurrentMessagePriority() ); |
101 |
84 |
|
mSafeTextSink.removeStyleName( zCurrentStyle.name() ); |
102 |
85 |
|
} |
103 |
86 |
|
|
104 |
|
- |
private void setMessageAndStyle( String pMessage, Priority pPriority ) |
105 |
|
- |
{ |
|
87 |
+ |
private void setMessageAndStyle( String pMessage, Priority pPriority ) { |
106 |
88 |
|
mSafeTextSink.addStyleName( pPriority.name() ); |
107 |
89 |
|
mSafeTextSink.setText( pMessage ); |
108 |
90 |
|
} |
109 |
91 |
|
|
110 |
|
- |
private Priority getCurrentMessagePriority() |
111 |
|
- |
{ |
|
92 |
+ |
private Priority getCurrentMessagePriority() { |
112 |
93 |
|
return (mCurrentMessage != null) ? mCurrentMessage.getPriority() : null; |
113 |
94 |
|
} |
114 |
95 |
|
|
115 |
|
- |
private static class PriorityMessage |
116 |
|
- |
{ |
|
96 |
+ |
private static class PriorityMessage { |
117 |
97 |
|
private Priority mPriority; |
118 |
98 |
|
private String mMessage; |
119 |
99 |
|
|
120 |
|
- |
public PriorityMessage( Priority pPriority, String pMessage ) |
121 |
|
- |
{ |
|
100 |
+ |
public PriorityMessage( Priority pPriority, String pMessage ) { |
122 |
101 |
|
mPriority = pPriority; |
123 |
102 |
|
mMessage = pMessage; |
124 |
103 |
|
} |
125 |
104 |
|
|
126 |
|
- |
public Priority getPriority() |
127 |
|
- |
{ |
|
105 |
+ |
public Priority getPriority() { |
128 |
106 |
|
return mPriority; |
129 |
107 |
|
} |
130 |
108 |
|
|
131 |
|
- |
public String getMessage() |
132 |
|
- |
{ |
|
109 |
+ |
public String getMessage() { |
133 |
110 |
|
return mMessage; |
134 |
111 |
|
} |
135 |
112 |
|
|
136 |
|
- |
public boolean isLowerPriorityThan( Priority pPriority ) |
137 |
|
- |
{ |
|
113 |
+ |
public boolean isLowerPriorityThan( Priority pPriority ) { |
138 |
114 |
|
return mPriority.isLowerPriorityThan( pPriority ); |
139 |
115 |
|
} |
140 |
116 |
|
|
141 |
|
- |
public boolean hasMessage( String pMessage ) |
142 |
|
- |
{ |
|
117 |
+ |
public boolean hasMessage( String pMessage ) { |
143 |
118 |
|
return mMessage.equals( pMessage ); |
144 |
119 |
|
} |
145 |
120 |
|
} |
146 |
121 |
|
|
147 |
|
- |
private static class Manager |
148 |
|
- |
{ |
|
122 |
+ |
private static class Manager { |
149 |
123 |
|
private final List<String>[] mMessagesByPriority = Cast.it( new List[Priority.values().length] ); |
150 |
124 |
|
|
151 |
125 |
|
{ |
152 |
|
- |
for ( int i = 0; i < mMessagesByPriority.length; i++ ) |
153 |
|
- |
{ |
|
126 |
+ |
for ( int i = 0; i < mMessagesByPriority.length; i++ ) { |
154 |
127 |
|
mMessagesByPriority[i] = new ArrayList<String>(); |
155 |
128 |
|
} |
156 |
129 |
|
} |
|
@@ -160,12 +133,9 @@ |
160 |
133 |
|
* |
161 |
134 |
|
* @return null means no more messages |
162 |
135 |
|
*/ |
163 |
|
- |
public Priority getNextPriority() |
164 |
|
- |
{ |
165 |
|
- |
for ( Priority zPriority : Priority.values() ) |
166 |
|
- |
{ |
167 |
|
- |
if ( !mMessagesByPriority[zPriority.ordinal()].isEmpty() ) |
168 |
|
- |
{ |
|
136 |
+ |
public Priority getNextPriority() { |
|
137 |
+ |
for ( Priority zPriority : Priority.values() ) { |
|
138 |
+ |
if ( !mMessagesByPriority[zPriority.ordinal()].isEmpty() ) { |
169 |
139 |
|
return zPriority; |
170 |
140 |
|
} |
171 |
141 |
|
} |
|
@@ -177,13 +147,10 @@ |
177 |
147 |
|
* |
178 |
148 |
|
* @return null means no more messages |
179 |
149 |
|
*/ |
180 |
|
- |
public PriorityMessage getNextMessage() |
181 |
|
- |
{ |
182 |
|
- |
for ( Priority zPriority : Priority.values() ) |
183 |
|
- |
{ |
|
150 |
+ |
public PriorityMessage getNextMessage() { |
|
151 |
+ |
for ( Priority zPriority : Priority.values() ) { |
184 |
152 |
|
List<String> zMessages = mMessagesByPriority[zPriority.ordinal()]; |
185 |
|
- |
if ( !zMessages.isEmpty() ) |
186 |
|
- |
{ |
|
153 |
+ |
if ( !zMessages.isEmpty() ) { |
187 |
154 |
|
return new PriorityMessage( zPriority, zMessages.remove( 0 ) ); |
188 |
155 |
|
} |
189 |
156 |
|
} |
|
@@ -195,29 +162,22 @@ |
195 |
162 |
|
* |
196 |
163 |
|
* @return The Highest Priority Message's Priority OR null if no Messages waiting |
197 |
164 |
|
*/ |
198 |
|
- |
public Priority addMessage( Priority pPriority, String pMessage ) |
199 |
|
- |
{ |
200 |
|
- |
if ( null != (pMessage = Strings.noEmpty( pMessage )) ) |
201 |
|
- |
{ |
|
165 |
+ |
public Priority addMessage( Priority pPriority, String pMessage ) { |
|
166 |
+ |
if ( null != (pMessage = Strings.noEmpty( pMessage )) ) { |
202 |
167 |
|
mMessagesByPriority[Priority.deNull( pPriority ).ordinal()].add( pMessage ); |
203 |
168 |
|
} |
204 |
|
- |
for ( Priority zPriority : Priority.values() ) |
205 |
|
- |
{ |
206 |
|
- |
if ( !mMessagesByPriority[zPriority.ordinal()].isEmpty() ) |
207 |
|
- |
{ |
|
169 |
+ |
for ( Priority zPriority : Priority.values() ) { |
|
170 |
+ |
if ( !mMessagesByPriority[zPriority.ordinal()].isEmpty() ) { |
208 |
171 |
|
return zPriority; |
209 |
172 |
|
} |
210 |
173 |
|
} |
211 |
174 |
|
return null; |
212 |
175 |
|
} |
213 |
176 |
|
|
214 |
|
- |
public void removeMessage( String pMessage ) |
215 |
|
- |
{ |
216 |
|
- |
for ( Priority zPriority : Priority.values() ) |
217 |
|
- |
{ |
|
177 |
+ |
public void removeMessage( String pMessage ) { |
|
178 |
+ |
for ( Priority zPriority : Priority.values() ) { |
218 |
179 |
|
List<String> zMessages = mMessagesByPriority[zPriority.ordinal()]; |
219 |
|
- |
if ( zMessages.remove( pMessage ) ) |
220 |
|
- |
{ |
|
180 |
+ |
if ( zMessages.remove( pMessage ) ) { |
221 |
181 |
|
return; |
222 |
182 |
|
} |
223 |
183 |
|
} |