|
@@ -1,85 +1,85 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.eventbus.client; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.*; |
5 |
|
- |
import org.litesoft.GWT.eventbus.client.eventpackages.*; |
6 |
|
- |
import org.litesoft.GWT.eventbus.client.nonpublic.*; |
7 |
|
- |
|
8 |
|
- |
import java.util.*; |
9 |
|
- |
|
10 |
|
- |
public class DecendantManager { |
11 |
|
- |
private WindowNameClientIdCodec mWindowNameClientIdCodec; |
12 |
|
- |
|
13 |
|
- |
public DecendantManager( WindowNameClientIdCodec pWindowNameClientIdCodec ) { |
14 |
|
- |
mWindowNameClientIdCodec = pWindowNameClientIdCodec; |
15 |
|
- |
} |
16 |
|
- |
|
17 |
|
- |
public void addEventListenersForNewClient( EventSubscriptionCollector pCollector ) { |
18 |
|
- |
pCollector.subscribe( new NotificationReDecendantPackageListener() ); |
19 |
|
- |
pCollector.subscribe( new CloseDecendantClientsPackageListener() ); |
20 |
|
- |
} |
21 |
|
- |
|
22 |
|
- |
private Set<Integer> mDecendants = new HashSet<Integer>(); |
23 |
|
- |
|
24 |
|
- |
public boolean anyDecendants() { |
25 |
|
- |
return !mDecendants.isEmpty(); |
26 |
|
- |
} |
27 |
|
- |
|
28 |
|
- |
public int decendants() { |
29 |
|
- |
return mDecendants.size(); |
30 |
|
- |
} |
31 |
|
- |
|
32 |
|
- |
private void addDecendant( int pClientId ) { |
33 |
|
- |
//noinspection UnnecessaryBoxing,unchecked |
34 |
|
- |
mDecendants.add( pClientId ); |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
private void removeDecendant( int pClientId ) { |
38 |
|
- |
mDecendants.remove( pClientId ); |
39 |
|
- |
} |
40 |
|
- |
|
41 |
|
- |
public void closeAllDecendants() { |
42 |
|
- |
//noinspection ForLoopReplaceableByForEach |
43 |
|
- |
for ( Iterator<Integer> it = mDecendants.iterator(); it.hasNext(); ) { |
44 |
|
- |
//noinspection UnnecessaryUnboxing |
45 |
|
- |
closeDecendant( it.next() ); |
46 |
|
- |
} |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
public void closeDecendant( int pDecendantClientId ) { |
50 |
|
- |
String encodedClientId = ClientIdCodec.encode( pDecendantClientId ); |
51 |
|
- |
String name = mWindowNameClientIdCodec.createWindowName( encodedClientId ); |
52 |
|
- |
UtilsGwt.closeWindow( name ); |
53 |
|
- |
} |
54 |
|
- |
|
55 |
|
- |
public void decendantToFront( int pDecendantClientId ) { |
56 |
|
- |
String encodedClientId = ClientIdCodec.encode( pDecendantClientId ); |
57 |
|
- |
String name = mWindowNameClientIdCodec.createWindowName( encodedClientId ); |
58 |
|
- |
UtilsGwt.windowToFront( name ); |
59 |
|
- |
} |
60 |
|
- |
|
61 |
|
- |
private class NotificationReDecendantPackageListener implements EventPackageSubscriber { |
62 |
|
- |
public String subscribeWith() { |
63 |
|
- |
return NotificationReDecendantEventPackage.SubscribeWith; |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus ) { |
67 |
|
- |
NotificationReDecendantEventPackage event = (NotificationReDecendantEventPackage) pEventPackage; |
68 |
|
- |
if ( event.isAdd() ) { |
69 |
|
- |
addDecendant( event.getClientId() ); |
70 |
|
- |
} else { |
71 |
|
- |
removeDecendant( event.getClientId() ); |
72 |
|
- |
} |
73 |
|
- |
} |
74 |
|
- |
} |
75 |
|
- |
|
76 |
|
- |
private class CloseDecendantClientsPackageListener implements EventPackageSubscriber { |
77 |
|
- |
public String subscribeWith() { |
78 |
|
- |
return CloseDecendantClientsEventPackage.SubscribeWith; |
79 |
|
- |
} |
80 |
|
- |
|
81 |
|
- |
public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus ) { |
82 |
|
- |
closeAllDecendants(); |
83 |
|
- |
} |
84 |
|
- |
} |
85 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.eventbus.client; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.*; |
|
5 |
+ |
import org.litesoft.GWT.eventbus.client.eventpackages.*; |
|
6 |
+ |
import org.litesoft.GWT.eventbus.client.nonpublic.*; |
|
7 |
+ |
|
|
8 |
+ |
import java.util.*; |
|
9 |
+ |
|
|
10 |
+ |
public class DecendantManager { |
|
11 |
+ |
private WindowNameClientIdCodec mWindowNameClientIdCodec; |
|
12 |
+ |
|
|
13 |
+ |
public DecendantManager( WindowNameClientIdCodec pWindowNameClientIdCodec ) { |
|
14 |
+ |
mWindowNameClientIdCodec = pWindowNameClientIdCodec; |
|
15 |
+ |
} |
|
16 |
+ |
|
|
17 |
+ |
public void addEventListenersForNewClient( EventSubscriptionCollector pCollector ) { |
|
18 |
+ |
pCollector.subscribe( new NotificationReDecendantPackageListener() ); |
|
19 |
+ |
pCollector.subscribe( new CloseDecendantClientsPackageListener() ); |
|
20 |
+ |
} |
|
21 |
+ |
|
|
22 |
+ |
private Set<Integer> mDecendants = new HashSet<Integer>(); |
|
23 |
+ |
|
|
24 |
+ |
public boolean anyDecendants() { |
|
25 |
+ |
return !mDecendants.isEmpty(); |
|
26 |
+ |
} |
|
27 |
+ |
|
|
28 |
+ |
public int decendants() { |
|
29 |
+ |
return mDecendants.size(); |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
private void addDecendant( int pClientId ) { |
|
33 |
+ |
//noinspection UnnecessaryBoxing,unchecked |
|
34 |
+ |
mDecendants.add( pClientId ); |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
private void removeDecendant( int pClientId ) { |
|
38 |
+ |
mDecendants.remove( pClientId ); |
|
39 |
+ |
} |
|
40 |
+ |
|
|
41 |
+ |
public void closeAllDecendants() { |
|
42 |
+ |
//noinspection ForLoopReplaceableByForEach |
|
43 |
+ |
for ( Iterator<Integer> it = mDecendants.iterator(); it.hasNext(); ) { |
|
44 |
+ |
//noinspection UnnecessaryUnboxing |
|
45 |
+ |
closeDecendant( it.next() ); |
|
46 |
+ |
} |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
public void closeDecendant( int pDecendantClientId ) { |
|
50 |
+ |
String encodedClientId = ClientIdCodec.encode( pDecendantClientId ); |
|
51 |
+ |
String name = mWindowNameClientIdCodec.createWindowName( encodedClientId ); |
|
52 |
+ |
UtilsGwt.closeWindow( name ); |
|
53 |
+ |
} |
|
54 |
+ |
|
|
55 |
+ |
public void decendantToFront( int pDecendantClientId ) { |
|
56 |
+ |
String encodedClientId = ClientIdCodec.encode( pDecendantClientId ); |
|
57 |
+ |
String name = mWindowNameClientIdCodec.createWindowName( encodedClientId ); |
|
58 |
+ |
UtilsGwt.windowToFront( name ); |
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
private class NotificationReDecendantPackageListener implements EventPackageSubscriber { |
|
62 |
+ |
public String subscribeWith() { |
|
63 |
+ |
return NotificationReDecendantEventPackage.SubscribeWith; |
|
64 |
+ |
} |
|
65 |
+ |
|
|
66 |
+ |
public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus ) { |
|
67 |
+ |
NotificationReDecendantEventPackage event = (NotificationReDecendantEventPackage) pEventPackage; |
|
68 |
+ |
if ( event.isAdd() ) { |
|
69 |
+ |
addDecendant( event.getClientId() ); |
|
70 |
+ |
} else { |
|
71 |
+ |
removeDecendant( event.getClientId() ); |
|
72 |
+ |
} |
|
73 |
+ |
} |
|
74 |
+ |
} |
|
75 |
+ |
|
|
76 |
+ |
private class CloseDecendantClientsPackageListener implements EventPackageSubscriber { |
|
77 |
+ |
public String subscribeWith() { |
|
78 |
+ |
return CloseDecendantClientsEventPackage.SubscribeWith; |
|
79 |
+ |
} |
|
80 |
+ |
|
|
81 |
+ |
public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus ) { |
|
82 |
+ |
closeAllDecendants(); |
|
83 |
+ |
} |
|
84 |
+ |
} |
|
85 |
+ |
} |