Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package org.litesoft.GWT.eventbus.client;

import java.util.*;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.eventbus.client.eventpackages.*;
import org.litesoft.GWT.eventbus.client.nonpublic.*;

public class DecendantManager
{
    private WindowNameClientIdCodec mWindowNameClientIdCodec;

    public DecendantManager( WindowNameClientIdCodec pWindowNameClientIdCodec )
    {
        mWindowNameClientIdCodec = pWindowNameClientIdCodec;
    }

    public void addEventListenersForNewClient( EventSubscriptionCollector pCollector )
    {
        pCollector.subscribe( new NotificationReDecendantPackageListener() );
        pCollector.subscribe( new CloseDecendantClientsPackageListener() );
    }

    private Set<Integer> mDecendants = new HashSet<Integer>();

    public boolean anyDecendants()
    {
        return !mDecendants.isEmpty();
    }

    public int decendants()
    {
        return mDecendants.size();
    }

    private void addDecendant( int pClientId )
    {
        //noinspection UnnecessaryBoxing,unchecked
        mDecendants.add( pClientId );
    }

    private void removeDecendant( int pClientId )
    {
        mDecendants.remove( pClientId );
    }

    public void closeAllDecendants()
    {
        //noinspection ForLoopReplaceableByForEach
        for ( Iterator<Integer> it = mDecendants.iterator(); it.hasNext(); )
        {
            //noinspection UnnecessaryUnboxing
            closeDecendant( it.next() );
        }
    }

    public void closeDecendant( int pDecendantClientId )
    {
        String encodedClientId = ClientIdCodec.encode( pDecendantClientId );
        String name = mWindowNameClientIdCodec.createWindowName( encodedClientId );
        UtilsGwt.closeWindow( name );
    }

    public void decendantToFront( int pDecendantClientId )
    {
        String encodedClientId = ClientIdCodec.encode( pDecendantClientId );
        String name = mWindowNameClientIdCodec.createWindowName( encodedClientId );
        UtilsGwt.windowToFront( name );
    }

    private class NotificationReDecendantPackageListener implements EventPackageSubscriber
    {
        public String subscribeWith()
        {
            return NotificationReDecendantEventPackage.SubscribeWith;
        }

        public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus )
        {
            NotificationReDecendantEventPackage event = (NotificationReDecendantEventPackage) pEventPackage;
            if ( event.isAdd() )
            {
                addDecendant( event.getClientId() );
            }
            else
            {
                removeDecendant( event.getClientId() );
            }
        }
    }

    private class CloseDecendantClientsPackageListener implements EventPackageSubscriber
    {
        public String subscribeWith()
        {
            return CloseDecendantClientsEventPackage.SubscribeWith;
        }

        public void packageReceivedVia( EventPackage pEventPackage, EventBus pEventBus )
        {
            closeAllDecendants();
        }
    }
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/eventbus/client/DecendantManager.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000