|
@@ -1,84 +1,85 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.ebiconservice.client; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.iconservice.*; |
5 |
|
- |
import org.litesoft.commonfoundation.stringmatching.*; |
6 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
7 |
|
- |
|
8 |
|
- |
public class EBIconService implements IconService { |
9 |
|
- |
private static final Definition NO_FACTORY_DEFINITION = |
10 |
|
- |
new DefinitionImpl( "common/images/windowbar/NoFactory.gif", // |
11 |
|
- |
"common/images/windowbar/NoFactory24.gif", // |
12 |
|
- |
"No Factory Specified" ); |
13 |
|
- |
|
14 |
|
- |
private static final Definition NOT_FOUND_DEFINITION = |
15 |
|
- |
new DefinitionImpl( "common/images/windowbar/notfound.gif", // |
16 |
|
- |
"common/images/windowbar/notfound24.gif", // |
17 |
|
- |
"No Definition Found" ); |
18 |
|
- |
|
19 |
|
- |
private EBISDefPlus[] mDefinitions; |
20 |
|
- |
|
21 |
|
- |
public void setDefinitions( EBIconServiceDefinition[] pDefinitions ) { |
22 |
|
- |
if ( pDefinitions == null ) { |
23 |
|
- |
mDefinitions = EBISDefPlus.EMPTY_ARRAY; |
24 |
|
- |
} else { |
25 |
|
- |
mDefinitions = new EBISDefPlus[pDefinitions.length]; |
26 |
|
- |
for ( int i = 0; i < mDefinitions.length; i++ ) { |
27 |
|
- |
mDefinitions[i] = new EBISDefPlus( pDefinitions[i] ); |
28 |
|
- |
} |
29 |
|
- |
} |
30 |
|
- |
} |
31 |
|
- |
|
32 |
|
- |
public DefinitionPlus getDefinition( String pFloaterFactoryRef, String pCurrentFloaterTitle ) { |
33 |
|
- |
if ( null == (pFloaterFactoryRef = Strings.noEmpty( pFloaterFactoryRef )) ) { |
34 |
|
- |
return new DefinitionPlus( false, null, NO_FACTORY_DEFINITION ); |
35 |
|
- |
} |
36 |
|
- |
pCurrentFloaterTitle = Strings.deNull( pCurrentFloaterTitle ).trim(); |
37 |
|
- |
Definition zRV = getIconDefinition( pFloaterFactoryRef, pCurrentFloaterTitle ); |
38 |
|
- |
return new DefinitionPlus( true, Strings.noEmpty( pCurrentFloaterTitle ), zRV ); |
39 |
|
- |
} |
40 |
|
- |
|
41 |
|
- |
private Definition getIconDefinition( String pFloaterFactoryRef, String pCurrentFloaterTitle ) { |
42 |
|
- |
for ( int i = 0; i < mDefinitions.length; i++ ) { |
43 |
|
- |
EBISDefPlus zDefinition = mDefinitions[i]; |
44 |
|
- |
if ( zDefinition.matches( pFloaterFactoryRef, pCurrentFloaterTitle ) ) { |
45 |
|
- |
return zDefinition.getDefinition(); |
46 |
|
- |
} |
47 |
|
- |
} |
48 |
|
- |
LOGGER.error.log( "Not Found: '", pFloaterFactoryRef, "', '", pCurrentFloaterTitle, "'" ); |
49 |
|
- |
return NOT_FOUND_DEFINITION; |
50 |
|
- |
} |
51 |
|
- |
|
52 |
|
- |
public static class EBISDefPlus { |
53 |
|
- |
public static final EBISDefPlus[] EMPTY_ARRAY = new EBISDefPlus[0]; |
54 |
|
- |
|
55 |
|
- |
private EBIconServiceDefinition mDefinition; |
56 |
|
- |
private StringMatcher mFactoryRefMatcher, mTitleMatcher; |
57 |
|
- |
|
58 |
|
- |
public EBISDefPlus( EBIconServiceDefinition pDefinition ) { |
59 |
|
- |
mDefinition = pDefinition; |
60 |
|
- |
mFactoryRefMatcher = createMatcher( pDefinition.getFloaterFactoryRefPattern() ); |
61 |
|
- |
mTitleMatcher = createMatcher( pDefinition.getFloaterTitlePattern() ); |
62 |
|
- |
} |
63 |
|
- |
|
64 |
|
- |
private StringMatcher createMatcher( String pPattern ) { |
65 |
|
- |
pPattern = pPattern.trim(); |
66 |
|
- |
StringMatcher zMatcher = |
67 |
|
- |
StringMatcherFactory.createEquals( Strings.parseChar( pPattern, '*' ) ); |
68 |
|
- |
return (zMatcher != null) ? // |
69 |
|
- |
zMatcher : // |
70 |
|
- |
(pPattern.length() == 0) ? // |
71 |
|
- |
StringMatcher.NONE : // |
72 |
|
- |
StringMatcher.ALL; |
73 |
|
- |
} |
74 |
|
- |
|
75 |
|
- |
public EBIconServiceDefinition getDefinition() { |
76 |
|
- |
return mDefinition; |
77 |
|
- |
} |
78 |
|
- |
|
79 |
|
- |
public boolean matches( String pFloaterFactoryRef, String pCurrentFloaterTitle ) { |
80 |
|
- |
return mFactoryRefMatcher.matches( pFloaterFactoryRef ) && |
81 |
|
- |
mTitleMatcher.matches( pCurrentFloaterTitle ); |
82 |
|
- |
} |
83 |
|
- |
} |
84 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.ebiconservice.client; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.iconservice.*; |
|
5 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
6 |
+ |
import org.litesoft.commonfoundation.stringmatching.*; |
|
7 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
|
8 |
+ |
|
|
9 |
+ |
public class EBIconService implements IconService { |
|
10 |
+ |
private static final Definition NO_FACTORY_DEFINITION = |
|
11 |
+ |
new DefinitionImpl( "common/images/windowbar/NoFactory.gif", // |
|
12 |
+ |
"common/images/windowbar/NoFactory24.gif", // |
|
13 |
+ |
"No Factory Specified" ); |
|
14 |
+ |
|
|
15 |
+ |
private static final Definition NOT_FOUND_DEFINITION = |
|
16 |
+ |
new DefinitionImpl( "common/images/windowbar/notfound.gif", // |
|
17 |
+ |
"common/images/windowbar/notfound24.gif", // |
|
18 |
+ |
"No Definition Found" ); |
|
19 |
+ |
|
|
20 |
+ |
private EBISDefPlus[] mDefinitions; |
|
21 |
+ |
|
|
22 |
+ |
public void setDefinitions( EBIconServiceDefinition[] pDefinitions ) { |
|
23 |
+ |
if ( pDefinitions == null ) { |
|
24 |
+ |
mDefinitions = EBISDefPlus.EMPTY_ARRAY; |
|
25 |
+ |
} else { |
|
26 |
+ |
mDefinitions = new EBISDefPlus[pDefinitions.length]; |
|
27 |
+ |
for ( int i = 0; i < mDefinitions.length; i++ ) { |
|
28 |
+ |
mDefinitions[i] = new EBISDefPlus( pDefinitions[i] ); |
|
29 |
+ |
} |
|
30 |
+ |
} |
|
31 |
+ |
} |
|
32 |
+ |
|
|
33 |
+ |
public DefinitionPlus getDefinition( String pFloaterFactoryRef, String pCurrentFloaterTitle ) { |
|
34 |
+ |
if ( null == (pFloaterFactoryRef = ConstrainTo.significantOrNull( pFloaterFactoryRef )) ) { |
|
35 |
+ |
return new DefinitionPlus( false, null, NO_FACTORY_DEFINITION ); |
|
36 |
+ |
} |
|
37 |
+ |
pCurrentFloaterTitle = ConstrainTo.notNull( pCurrentFloaterTitle ).trim(); |
|
38 |
+ |
Definition zRV = getIconDefinition( pFloaterFactoryRef, pCurrentFloaterTitle ); |
|
39 |
+ |
return new DefinitionPlus( true, ConstrainTo.significantOrNull( pCurrentFloaterTitle ), zRV ); |
|
40 |
+ |
} |
|
41 |
+ |
|
|
42 |
+ |
private Definition getIconDefinition( String pFloaterFactoryRef, String pCurrentFloaterTitle ) { |
|
43 |
+ |
for ( int i = 0; i < mDefinitions.length; i++ ) { |
|
44 |
+ |
EBISDefPlus zDefinition = mDefinitions[i]; |
|
45 |
+ |
if ( zDefinition.matches( pFloaterFactoryRef, pCurrentFloaterTitle ) ) { |
|
46 |
+ |
return zDefinition.getDefinition(); |
|
47 |
+ |
} |
|
48 |
+ |
} |
|
49 |
+ |
LOGGER.error.log( "Not Found: '", pFloaterFactoryRef, "', '", pCurrentFloaterTitle, "'" ); |
|
50 |
+ |
return NOT_FOUND_DEFINITION; |
|
51 |
+ |
} |
|
52 |
+ |
|
|
53 |
+ |
public static class EBISDefPlus { |
|
54 |
+ |
public static final EBISDefPlus[] EMPTY_ARRAY = new EBISDefPlus[0]; |
|
55 |
+ |
|
|
56 |
+ |
private EBIconServiceDefinition mDefinition; |
|
57 |
+ |
private StringMatcher mFactoryRefMatcher, mTitleMatcher; |
|
58 |
+ |
|
|
59 |
+ |
public EBISDefPlus( EBIconServiceDefinition pDefinition ) { |
|
60 |
+ |
mDefinition = pDefinition; |
|
61 |
+ |
mFactoryRefMatcher = createMatcher( pDefinition.getFloaterFactoryRefPattern() ); |
|
62 |
+ |
mTitleMatcher = createMatcher( pDefinition.getFloaterTitlePattern() ); |
|
63 |
+ |
} |
|
64 |
+ |
|
|
65 |
+ |
private StringMatcher createMatcher( String pPattern ) { |
|
66 |
+ |
pPattern = pPattern.trim(); |
|
67 |
+ |
StringMatcher zMatcher = |
|
68 |
+ |
StringMatcherFactory.createEquals( Strings.parseChar( pPattern, '*' ) ); |
|
69 |
+ |
return (zMatcher != null) ? // |
|
70 |
+ |
zMatcher : // |
|
71 |
+ |
(pPattern.length() == 0) ? // |
|
72 |
+ |
StringMatcher.NONE : // |
|
73 |
+ |
StringMatcher.ALL; |
|
74 |
+ |
} |
|
75 |
+ |
|
|
76 |
+ |
public EBIconServiceDefinition getDefinition() { |
|
77 |
+ |
return mDefinition; |
|
78 |
+ |
} |
|
79 |
+ |
|
|
80 |
+ |
public boolean matches( String pFloaterFactoryRef, String pCurrentFloaterTitle ) { |
|
81 |
+ |
return mFactoryRefMatcher.matches( pFloaterFactoryRef ) && |
|
82 |
+ |
mTitleMatcher.matches( pCurrentFloaterTitle ); |
|
83 |
+ |
} |
|
84 |
+ |
} |
|
85 |
+ |
} |