Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/external/CWrapper.java

Diff revisions: vs.
  @@ -1,166 +1,166 @@
1 - // This Source Code is Copyright & Licenced as indicated below
2 - package org.litesoft.GWT.client.widgets.nonpublic.external;
3 - /*
4 - * Copyright 2006 Mat Gessel <mat.gessel@gmail.com>
5 - *
6 - * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 - * use this file except in compliance with the License. You may obtain a copy of
8 - * the License at
9 - *
10 - * http://www.apache.org/licenses/LICENSE-2.0
11 - *
12 - * Unless required by applicable law or agreed to in writing, software
13 - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 - * License for the specific language governing permissions and limitations under
16 - * the License.
17 - */
18 -
19 - import com.google.gwt.user.client.*;
20 - import com.google.gwt.user.client.ui.*;
21 -
22 - import java.util.*;
23 -
24 - /**
25 - * Wraps an widget to provide event processing via
26 - * {@link asquare.gwt.tk.client.ui.behavior.Controller controllers}. The
27 - * wrapped widget will process events and notify listeners as if it was not
28 - * wrapped.
29 - */
30 - public class CWrapper extends EventWrapper implements ControllerSupport {
31 - private final ControllerSupportDelegate m_controllerSupport;
32 -
33 - /**
34 - * Creates a CWrapper around the specified widget.
35 - */
36 - public CWrapper( Widget widget ) {
37 - this( widget, null );
38 - }
39 -
40 - /**
41 - * Creates a CWrapper around the specified widget. Pass a
42 - * value for <code>controllers</code> if you wish to avoid controller
43 - * creation via {@link #createControllers()}. Otherwise pass null.
44 - *
45 - * @param controllers a list of 0 or more controllers, or <code>null</code>
46 - *
47 - * @throws IllegalArgumentException if <code>element</code> is null
48 - */
49 - public CWrapper( Widget widget, List controllers ) {
50 - initWidget( widget );
51 - m_controllerSupport = new ControllerSupportDelegate( this );
52 -
53 - if ( controllers == null ) {
54 - controllers = createControllers();
55 - }
56 -
57 - setControllers( controllers );
58 - }
59 -
60 - /**
61 - * A factory method which gives subclasses the opportunity to override
62 - * default controller creation.
63 - *
64 - * @return a List with 0 or more controllers, or <code>null</code>
65 - */
66 - protected List createControllers() {
67 - return null;
68 - }
69 -
70 - /*
71 - * (non-Javadoc)
72 - * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#getController(java.lang.Class)
73 - */
74 - @Override
75 - public Controller getController( Class id ) {
76 - return m_controllerSupport.getController( id );
77 - }
78 -
79 - /*
80 - * (non-Javadoc)
81 - * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#addController(asquare.gwt.tk.client.ui.behavior.Controller)
82 - */
83 - @Override
84 - public Widget addController( Controller controller ) {
85 - return m_controllerSupport.addController( controller );
86 - }
87 -
88 - /*
89 - * (non-Javadoc)
90 - * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#removeController(asquare.gwt.tk.client.ui.behavior.Controller)
91 - */
92 - @Override
93 - public Widget removeController( Controller controller ) {
94 - return m_controllerSupport.removeController( controller );
95 - }
96 -
97 - /*
98 - * (non-Javadoc)
99 - * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#setControllers(java.util.List)
100 - */
101 - @Override
102 - public void setControllers( List controllers ) {
103 - m_controllerSupport.setControllers( controllers );
104 - }
105 -
106 - /*
107 - * (non-Javadoc)
108 - * @see com.google.gwt.user.client.ui.UIObject#sinkEvents(int)
109 - */
110 - @Override
111 - public void sinkEvents( int eventBits ) {
112 - m_controllerSupport.sinkEvents( eventBits );
113 - }
114 -
115 - /*
116 - * (non-Javadoc)
117 - * @see com.google.gwt.user.client.ui.UIObject#unsinkEvents(int)
118 - */
119 - @Override
120 - public void unsinkEvents( int eventBits ) {
121 - m_controllerSupport.unsinkEvents( eventBits );
122 - }
123 -
124 - /*
125 - * (non-Javadoc)
126 - * @see com.google.gwt.user.client.ui.Widget#onAttach()
127 - */
128 - @Override
129 - protected void onAttach() {
130 - if ( isAttached() ) {
131 - return;
132 - }
133 - m_controllerSupport.onAttach();
134 - super.onAttach();
135 - }
136 -
137 - /*
138 - * (non-Javadoc)
139 - * @see com.google.gwt.user.client.ui.Widget#onDetach()
140 - */
141 - @Override
142 - protected void onDetach() {
143 - if ( !isAttached() ) {
144 - return;
145 - }
146 -
147 - try {
148 - super.onDetach();
149 - }
150 - finally {
151 - m_controllerSupport.onDetach();
152 - }
153 - }
154 -
155 - /*
156 - * (non-Javadoc)
157 - * @see com.google.gwt.user.client.EventListener#onBrowserEvent(com.google.gwt.user.client.Event)
158 - */
159 - @Override
160 - public void onBrowserEvent( Event event ) {
161 - if ( (m_controllerSupport.getLegacyEventBits() & DOM.eventGetType( event )) != 0 ) {
162 - super.onBrowserEvent( event );
163 - }
164 - m_controllerSupport.onBrowserEvent( event );
165 - }
166 - }
1 + // This Source Code is Copyright & Licenced as indicated below
2 + package org.litesoft.GWT.client.widgets.nonpublic.external;
3 + /*
4 + * Copyright 2006 Mat Gessel <mat.gessel@gmail.com>
5 + *
6 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 + * use this file except in compliance with the License. You may obtain a copy of
8 + * the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing, software
13 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 + * License for the specific language governing permissions and limitations under
16 + * the License.
17 + */
18 +
19 + import com.google.gwt.user.client.*;
20 + import com.google.gwt.user.client.ui.*;
21 +
22 + import java.util.*;
23 +
24 + /**
25 + * Wraps an widget to provide event processing via
26 + * {@link asquare.gwt.tk.client.ui.behavior.Controller controllers}. The
27 + * wrapped widget will process events and notify listeners as if it was not
28 + * wrapped.
29 + */
30 + public class CWrapper extends EventWrapper implements ControllerSupport {
31 + private final ControllerSupportDelegate m_controllerSupport;
32 +
33 + /**
34 + * Creates a CWrapper around the specified widget.
35 + */
36 + public CWrapper( Widget widget ) {
37 + this( widget, null );
38 + }
39 +
40 + /**
41 + * Creates a CWrapper around the specified widget. Pass a
42 + * value for <code>controllers</code> if you wish to avoid controller
43 + * creation via {@link #createControllers()}. Otherwise pass null.
44 + *
45 + * @param controllers a list of 0 or more controllers, or <code>null</code>
46 + *
47 + * @throws IllegalArgumentException if <code>element</code> is null
48 + */
49 + public CWrapper( Widget widget, List controllers ) {
50 + initWidget( widget );
51 + m_controllerSupport = new ControllerSupportDelegate( this );
52 +
53 + if ( controllers == null ) {
54 + controllers = createControllers();
55 + }
56 +
57 + setControllers( controllers );
58 + }
59 +
60 + /**
61 + * A factory method which gives subclasses the opportunity to override
62 + * default controller creation.
63 + *
64 + * @return a List with 0 or more controllers, or <code>null</code>
65 + */
66 + protected List createControllers() {
67 + return null;
68 + }
69 +
70 + /*
71 + * (non-Javadoc)
72 + * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#getController(java.lang.Class)
73 + */
74 + @Override
75 + public Controller getController( Class id ) {
76 + return m_controllerSupport.getController( id );
77 + }
78 +
79 + /*
80 + * (non-Javadoc)
81 + * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#addController(asquare.gwt.tk.client.ui.behavior.Controller)
82 + */
83 + @Override
84 + public Widget addController( Controller controller ) {
85 + return m_controllerSupport.addController( controller );
86 + }
87 +
88 + /*
89 + * (non-Javadoc)
90 + * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#removeController(asquare.gwt.tk.client.ui.behavior.Controller)
91 + */
92 + @Override
93 + public Widget removeController( Controller controller ) {
94 + return m_controllerSupport.removeController( controller );
95 + }
96 +
97 + /*
98 + * (non-Javadoc)
99 + * @see asquare.gwt.tk.client.ui.behavior.ControllerSupport#setControllers(java.util.List)
100 + */
101 + @Override
102 + public void setControllers( List controllers ) {
103 + m_controllerSupport.setControllers( controllers );
104 + }
105 +
106 + /*
107 + * (non-Javadoc)
108 + * @see com.google.gwt.user.client.ui.UIObject#sinkEvents(int)
109 + */
110 + @Override
111 + public void sinkEvents( int eventBits ) {
112 + m_controllerSupport.sinkEvents( eventBits );
113 + }
114 +
115 + /*
116 + * (non-Javadoc)
117 + * @see com.google.gwt.user.client.ui.UIObject#unsinkEvents(int)
118 + */
119 + @Override
120 + public void unsinkEvents( int eventBits ) {
121 + m_controllerSupport.unsinkEvents( eventBits );
122 + }
123 +
124 + /*
125 + * (non-Javadoc)
126 + * @see com.google.gwt.user.client.ui.Widget#onAttach()
127 + */
128 + @Override
129 + protected void onAttach() {
130 + if ( isAttached() ) {
131 + return;
132 + }
133 + m_controllerSupport.onAttach();
134 + super.onAttach();
135 + }
136 +
137 + /*
138 + * (non-Javadoc)
139 + * @see com.google.gwt.user.client.ui.Widget#onDetach()
140 + */
141 + @Override
142 + protected void onDetach() {
143 + if ( !isAttached() ) {
144 + return;
145 + }
146 +
147 + try {
148 + super.onDetach();
149 + }
150 + finally {
151 + m_controllerSupport.onDetach();
152 + }
153 + }
154 +
155 + /*
156 + * (non-Javadoc)
157 + * @see com.google.gwt.user.client.EventListener#onBrowserEvent(com.google.gwt.user.client.Event)
158 + */
159 + @Override
160 + public void onBrowserEvent( Event event ) {
161 + if ( (m_controllerSupport.getLegacyEventBits() & DOM.eventGetType( event )) != 0 ) {
162 + super.onBrowserEvent( event );
163 + }
164 + m_controllerSupport.onBrowserEvent( event );
165 + }
166 + }