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
// This Source Code is Copyright & Licenced as indicated below
package org.litesoft.GWT.client.widgets.nonpublic.external;
/*
 * Copyright 2006 Mat Gessel <mat.gessel@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

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

import java.util.*;

/**
 * Wraps an widget to provide event processing via
 * {@link asquare.gwt.tk.client.ui.behavior.Controller controllers}. The
 * wrapped widget will process events and notify listeners as if it was not
 * wrapped.
 */
public class CWrapper extends EventWrapper implements ControllerSupport {
    private final ControllerSupportDelegate m_controllerSupport;

    /**
     * Creates a CWrapper around the specified widget.
     */
    public CWrapper( Widget widget ) {
        this( widget, null );
    }

    /**
     * Creates a CWrapper around the specified widget. Pass a
     * value for <code>controllers</code> if you wish to avoid controller
     * creation via {@link #createControllers()}. Otherwise pass null.
     *
     * @param controllers a list of 0 or more controllers, or <code>null</code>
     *
     * @throws IllegalArgumentException if <code>element</code> is null
     */
    public CWrapper( Widget widget, List controllers ) {
        initWidget( widget );
        m_controllerSupport = new ControllerSupportDelegate( this );

        if ( controllers == null ) {
            controllers = createControllers();
        }

        setControllers( controllers );
    }

    /**
     * A factory method which gives subclasses the opportunity to override
     * default controller creation.
     *
     * @return a List with 0 or more controllers, or <code>null</code>
     */
    protected List createControllers() {
        return null;
    }

    /*
      *  (non-Javadoc)
      * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#getController(java.lang.Class)
      */
    @Override
    public Controller getController( Class id ) {
        return m_controllerSupport.getController( id );
    }

    /*
      *  (non-Javadoc)
      * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#addController(asquare.gwt.tk.client.ui.behavior.Controller)
      */
    @Override
    public Widget addController( Controller controller ) {
        return m_controllerSupport.addController( controller );
    }

    /*
      *  (non-Javadoc)
      * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#removeController(asquare.gwt.tk.client.ui.behavior.Controller)
      */
    @Override
    public Widget removeController( Controller controller ) {
        return m_controllerSupport.removeController( controller );
    }

    /*
      *  (non-Javadoc)
      * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#setControllers(java.util.List)
      */
    @Override
    public void setControllers( List controllers ) {
        m_controllerSupport.setControllers( controllers );
    }

    /*
      *  (non-Javadoc)
      * @see com.google.gwt.user.client.ui.UIObject#sinkEvents(int)
      */
    @Override
    public void sinkEvents( int eventBits ) {
        m_controllerSupport.sinkEvents( eventBits );
    }

    /*
      *  (non-Javadoc)
      * @see com.google.gwt.user.client.ui.UIObject#unsinkEvents(int)
      */
    @Override
    public void unsinkEvents( int eventBits ) {
        m_controllerSupport.unsinkEvents( eventBits );
    }

    /*
      *  (non-Javadoc)
      * @see com.google.gwt.user.client.ui.Widget#onAttach()
      */
    @Override
    protected void onAttach() {
        if ( isAttached() ) {
            return;
        }
        m_controllerSupport.onAttach();
        super.onAttach();
    }

    /*
      *  (non-Javadoc)
      * @see com.google.gwt.user.client.ui.Widget#onDetach()
      */
    @Override
    protected void onDetach() {
        if ( !isAttached() ) {
            return;
        }

        try {
            super.onDetach();
        }
        finally {
            m_controllerSupport.onDetach();
        }
    }

    /*
      *  (non-Javadoc)
      * @see com.google.gwt.user.client.EventListener#onBrowserEvent(com.google.gwt.user.client.Event)
      */
    @Override
    public void onBrowserEvent( Event event ) {
        if ( (m_controllerSupport.getLegacyEventBits() & DOM.eventGetType( event )) != 0 ) {
            super.onBrowserEvent( event );
        }
        m_controllerSupport.onBrowserEvent( event );
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/external/CWrapper.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

23 Diff Diff GeorgeS picture GeorgeS Wed 24 Feb, 2010 00:34:32 +0000
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000