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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package org.litesoft.GWT.client.nonpublic;

import java.util.*;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.widgets.*;

import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.*;

public class AbstractPopupManager implements PopupListener // todo: GWT 1.6
{
    protected static void show( AbstractEntry pEntry )
    {
        INSTANCE.addAndShow( pEntry );
    }

    private static final AbstractPopupManager INSTANCE = new AbstractPopupManager();

    private void addAndShow( AbstractEntry pEntry )
    {
        if ( add( pEntry ) && !showing() )
        {
            pEntry = getEntry();
            if ( pEntry != null )
            {
                pEntry.show( this );
            }
        }
    }

    public void onPopupClosed( PopupPanel sender, boolean autoClosed )
    {
        AbstractEntry zEntry = nextEntry();
        if ( zEntry != null )
        {
            zEntry.show( this );
        }
    }

    private synchronized boolean add( AbstractEntry pEntry )
    {
        String zFrom = pEntry.getFrom();
        if ( mFromsInQueue.contains( zFrom ) )
        {
            return false;
        }
        mFromsInQueue.add( zFrom );
        mFromQueue.add( pEntry );
        return true;
    }

    private boolean mShowing = false;
    private List<AbstractEntry> mFromQueue = new ArrayList<AbstractEntry>();
    private Set<String> mFromsInQueue = new HashSet<String>();

    /**
     * Will "manage" the mShowing flag
     */
    private synchronized boolean showing()
    {
        boolean rv = mShowing;
        mShowing = true;
        return rv;
    }

    /**
     * Will "manage" the mShowing flag in conjunction w/ the mFromQueue
     */
    private synchronized AbstractEntry getEntry()
    {
        if ( !mFromQueue.isEmpty() )
        {
            return mFromQueue.get( 0 );
        }
        mShowing = false;
        return null;
    }

    private synchronized AbstractEntry nextEntry()
    {
        if ( !mFromQueue.isEmpty() )
        {
            AbstractEntry entry = mFromQueue.remove( 0 );
            mFromsInQueue.remove( entry.getFrom() );
        }
        return getEntry();
    }

    protected abstract static class AbstractEntry
    {
        private String mFrom;
        protected String mTitle, mBody;
        protected DialogCloseCallBack mCloseCallBack;

        public AbstractEntry( String pFrom, String pTitle, String pBody, DialogCloseCallBack pCloseCallBack )
        {
            mFrom = pFrom;
            mTitle = pTitle;
            mBody = pBody;
            mCloseCallBack = pCloseCallBack;
        }

        public String getFrom()
        {
            return mFrom;
        }

        public void show( PopupListener pPopupListener )
        {
            final AbstractMessageDialog zDialog = create();
            zDialog.addPopupListener( pPopupListener );
            DeferredCommand.add( new Command()
            {
                public void execute()
                {
                    zDialog.show();
                }
            } );
        }

        abstract protected AbstractMessageDialog create();
    }

    public static void prefetchImages()
    {
        FGImageButton.prefetchImages();

        Image.prefetch( "common/images/misc/InfoIcon.cache.gif" );
        Image.prefetch( "common/images/misc/ConfirmIcon.cache.gif" );
        Image.prefetch( "common/images/misc/AlertError.cache.gif" );

        Image.prefetch( "common/images/misc/dialogShadow/ShadowTopLeft.cache.png" );
        Image.prefetch( "common/images/misc/dialogShadow/ShadowUpStraight.cache.png" );
        Image.prefetch( "common/images/misc/dialogShadow/ShadowTopRight.cache.png" );
        Image.prefetch( "common/images/misc/dialogShadow/ShadowLeftStraight.cache.png" );
        Image.prefetch( "common/images/misc/dialogShadow/ShadowRightStraight.cache.png" );
        Image.prefetch( "common/images/misc/dialogShadow/ShadowBottomLeft.cache.png" );
        Image.prefetch( "common/images/misc/dialogShadow/ShadowDownStraight.cache.png" );
        Image.prefetch( "common/images/misc/dialogShadow/ShadowBottomRight.cache.png" );

        // Both LnFs are prefetched, need to only load once per theme
        Image.prefetch( "lnf/classic/Dialog/CornerBottomLeft.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerBottomLeftDown.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerBottomLeftUp.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerBottomRight.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerBottomRightDown.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerBottomRightUp.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerTopLeft.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerTopLeftDown.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerTopLeftUp.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerTopRight.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerTopRightDown.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/CornerTopRightUp.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/StraightBottom.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/StraightLeftCaption.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/StraightLeftContent.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/StraightRightCaption.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/StraightRightContent.cache.png" );
        Image.prefetch( "lnf/classic/Dialog/StraightTop.cache.png" );

        Image.prefetch( "lnf/classic_rounded/Dialog/CornerBottomLeft.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerBottomLeftDown.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerBottomLeftUp.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerBottomRight.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerBottomRightDown.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerBottomRightUp.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerTopLeft.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerTopLeftDown.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerTopLeftUp.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerTopRight.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerTopRightDown.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/CornerTopRightUp.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/StraightBottom.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/StraightLeftCaption.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/StraightLeftContent.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/StraightRightCaption.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/StraightRightContent.cache.png" );
        Image.prefetch( "lnf/classic_rounded/Dialog/StraightTop.cache.png" );
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/nonpublic/AbstractPopupManager.java

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