Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 346089 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rwt/internal/engine/ApplicationContextUtil.java (+1 lines)
Lines 59-64 Link Here
59
    JSLibraryConcatenator.class,
59
    JSLibraryConcatenator.class,
60
    TextSizeStorage.class,
60
    TextSizeStorage.class,
61
    ProbeStore.class,
61
    ProbeStore.class,
62
    LifeCycleAdapterFactory.class
62
  };
63
  };
63
64
64
  public static ApplicationContext registerDefaultApplicationContext( ServletContext context ) {
65
  public static ApplicationContext registerDefaultApplicationContext( ServletContext context ) {
(-)src/org/eclipse/rwt/internal/engine/RWTFactory.java (+4 lines)
Lines 125-130 Link Here
125
    return ( ResourceManagerProvider )getApplicationSingleton( ResourceManagerProvider.class );
125
    return ( ResourceManagerProvider )getApplicationSingleton( ResourceManagerProvider.class );
126
  }
126
  }
127
  
127
  
128
  public static LifeCycleAdapterFactory getLifeCycleAdapterFactory() {
129
    return ( LifeCycleAdapterFactory )getApplicationSingleton( LifeCycleAdapterFactory.class );
130
  }
131
128
  private static Object getApplicationSingleton( Class type ) {
132
  private static Object getApplicationSingleton( Class type ) {
129
    return ApplicationContextUtil.getInstance().getInstance( type );
133
    return ApplicationContextUtil.getInstance().getInstance( type );
130
  }
134
  }
(-)src/org/eclipse/rwt/internal/engine/RWTServletContextListener.java (-8 / +4 lines)
Lines 21-29 Link Here
21
21
22
import org.eclipse.rwt.AdapterFactory;
22
import org.eclipse.rwt.AdapterFactory;
23
import org.eclipse.rwt.branding.AbstractBranding;
23
import org.eclipse.rwt.branding.AbstractBranding;
24
import org.eclipse.rwt.internal.*;
24
import org.eclipse.rwt.internal.AdapterManager;
25
import org.eclipse.rwt.internal.EngineConfig;
25
import org.eclipse.rwt.internal.lifecycle.*;
26
import org.eclipse.rwt.internal.lifecycle.*;
26
import org.eclipse.rwt.internal.resources.*;
27
import org.eclipse.rwt.internal.resources.DefaultResourceManagerFactory;
28
import org.eclipse.rwt.internal.resources.JSLibraryServiceHandler;
27
import org.eclipse.rwt.internal.service.SettingStoreManager;
29
import org.eclipse.rwt.internal.service.SettingStoreManager;
28
import org.eclipse.rwt.internal.textsize.MeasurementListener;
30
import org.eclipse.rwt.internal.textsize.MeasurementListener;
29
import org.eclipse.rwt.internal.theme.*;
31
import org.eclipse.rwt.internal.theme.*;
Lines 36-43 Link Here
36
import org.eclipse.rwt.resources.IResourceManagerFactory;
38
import org.eclipse.rwt.resources.IResourceManagerFactory;
37
import org.eclipse.rwt.service.ISettingStoreFactory;
39
import org.eclipse.rwt.service.ISettingStoreFactory;
38
import org.eclipse.rwt.service.RWTFileSettingStoreFactory;
40
import org.eclipse.rwt.service.RWTFileSettingStoreFactory;
39
import org.eclipse.swt.widgets.Display;
40
import org.eclipse.swt.widgets.Widget;
41
41
42
42
43
public final class RWTServletContextListener implements ServletContextListener {
43
public final class RWTServletContextListener implements ServletContextListener {
Lines 267-276 Link Here
267
          }
267
          }
268
        }
268
        }
269
      }
269
      }
270
    } else {
271
      LifeCycleAdapterFactory lifeCycleAdapterFactory = new LifeCycleAdapterFactory();
272
      adapterManager.registerAdapters( Widget.class, lifeCycleAdapterFactory );
273
      adapterManager.registerAdapters( Display.class, lifeCycleAdapterFactory );
274
    }
270
    }
275
  }
271
  }
276
272
(-)src/org/eclipse/rwt/internal/lifecycle/DisplayUtil.java (-8 / +2 lines)
Lines 11-18 Link Here
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.rwt.internal.lifecycle;
12
package org.eclipse.rwt.internal.lifecycle;
13
13
14
import java.text.MessageFormat;
15
16
import org.eclipse.rwt.lifecycle.ILifeCycleAdapter;
14
import org.eclipse.rwt.lifecycle.ILifeCycleAdapter;
17
import org.eclipse.rwt.lifecycle.IWidgetAdapter;
15
import org.eclipse.rwt.lifecycle.IWidgetAdapter;
18
import org.eclipse.swt.widgets.Display;
16
import org.eclipse.swt.widgets.Display;
Lines 47-57 Link Here
47
    return getAdapter( display ).getId();
45
    return getAdapter( display ).getId();
48
  }
46
  }
49
  
47
  
50
  private static void throwAdapterException( final Class clazz ) {
48
  private static void throwAdapterException( Class clazz ) {
51
    String text =   "Could not retrieve an instance of ''{0}''. Probably the "
49
    throw new IllegalStateException( "Failed to obtain adapter: " + clazz.getName() );
52
                  + "AdapterFactory was not properly registered.";
53
    Object[] param = new Object[]{ clazz.getName() };
54
    String msg = MessageFormat.format( text, param );
55
    throw new IllegalStateException( msg );
56
  }
50
  }
57
}
51
}
(-)src/org/eclipse/rwt/internal/lifecycle/LifeCycleAdapterFactory.java (-32 / +4 lines)
Lines 14-20 Link Here
14
import java.util.HashMap;
14
import java.util.HashMap;
15
import java.util.Map;
15
import java.util.Map;
16
16
17
import org.eclipse.rwt.AdapterFactory;
18
import org.eclipse.rwt.internal.util.ClassInstantiationException;
17
import org.eclipse.rwt.internal.util.ClassInstantiationException;
19
import org.eclipse.rwt.internal.util.ClassUtil;
18
import org.eclipse.rwt.internal.util.ClassUtil;
20
import org.eclipse.rwt.lifecycle.ILifeCycleAdapter;
19
import org.eclipse.rwt.lifecycle.ILifeCycleAdapter;
Lines 24-84 Link Here
24
import org.eclipse.swt.widgets.Widget;
23
import org.eclipse.swt.widgets.Widget;
25
24
26
25
27
public final class LifeCycleAdapterFactory implements AdapterFactory {
26
public final class LifeCycleAdapterFactory {
28
27
29
  private static final Class[] ADAPTER_LIST = new Class[] {
30
    ILifeCycleAdapter.class
31
  };
32
33
  private final Object displayAdapterLock;
34
  private final Object widgetAdaptersLock;
28
  private final Object widgetAdaptersLock;
35
  // Holds the single display life cycle adapter. MUST be created lazily because its constructor 
29
  private final IDisplayLifeCycleAdapter displayAdapter;
36
  // needs a resource manager to be in place
37
  private IDisplayLifeCycleAdapter displayAdapter;
38
  // Maps widget classes to their respective life cycle adapters
30
  // Maps widget classes to their respective life cycle adapters
39
  // Key: Class<Widget>, value: IWidgetLifeCycleAdapter
31
  // Key: Class<Widget>, value: IWidgetLifeCycleAdapter
40
  private final Map widgetAdapters;
32
  private final Map widgetAdapters;
41
33
42
  
43
  public LifeCycleAdapterFactory() {
34
  public LifeCycleAdapterFactory() {
44
    displayAdapterLock = new Object();
45
    widgetAdaptersLock = new Object();
35
    widgetAdaptersLock = new Object();
46
    widgetAdapters = new HashMap();
36
    widgetAdapters = new HashMap();
37
    displayAdapter = DisplayLCAFacade.getDisplayLCA();
47
  }
38
  }
48
  
39
  
49
  public Object getAdapter( Object adaptable, Class adapter ) {
40
  public Object getAdapter( Object adaptable, Class adapter ) {
50
    Object result = null;
41
    Object result = null;
51
    if( isDisplayLCA( adaptable, adapter ) ) {
42
    if( isDisplayLCA( adaptable, adapter ) ) {
52
      result = getDisplayLCA();
43
      result = displayAdapter;
53
    } else if( isWidgetLCA( adaptable, adapter ) ) {
44
    } else if( isWidgetLCA( adaptable, adapter ) ) {
54
      result = getWidgetLCA( adaptable.getClass() );
45
      result = getWidgetLCA( adaptable.getClass() );
55
    }
46
    }
56
    return result;
47
    return result;
57
  }
48
  }
58
49
59
  public Class[] getAdapterList() {
60
    return ADAPTER_LIST;
61
  }
62
63
  ///////////////////////////////////////////////////////////
64
  // Helping methods to obtain life cycle adapter for display
65
66
  private static boolean isDisplayLCA( Object adaptable, Class adapter ) {
50
  private static boolean isDisplayLCA( Object adaptable, Class adapter ) {
67
    return adaptable instanceof Display && adapter == ILifeCycleAdapter.class;
51
    return adaptable instanceof Display && adapter == ILifeCycleAdapter.class;
68
  }
52
  }
69
53
70
  private synchronized ILifeCycleAdapter getDisplayLCA() {
71
    synchronized( displayAdapterLock ) {
72
      if( displayAdapter == null ) {
73
        displayAdapter = DisplayLCAFacade.getDisplayLCA();
74
      }
75
      return displayAdapter;
76
    }
77
  }
78
79
  ////////////////////////////////////////////////////////////
80
  // Helping methods to obtain life cycle adapters for widgets
81
82
  private static boolean isWidgetLCA( Object adaptable, Class adapter ) {
54
  private static boolean isWidgetLCA( Object adaptable, Class adapter ) {
83
    return adaptable instanceof Widget && adapter == ILifeCycleAdapter.class;
55
    return adaptable instanceof Widget && adapter == ILifeCycleAdapter.class;
84
  }
56
  }
(-)src/org/eclipse/rwt/lifecycle/WidgetUtil.java (-5 / +1 lines)
Lines 205-215 Link Here
205
  }
205
  }
206
206
207
  private static void throwAdapterException( Class clazz ) {
207
  private static void throwAdapterException( Class clazz ) {
208
    String text =   "Could not retrieve an instance of ''{0}''. Probably the "
208
    throw new IllegalStateException( "Failed to obtain adapter: " + clazz.getName() );
209
                  + "AdapterFactory was not properly registered.";
210
    Object[] param = new Object[]{ clazz.getName() };
211
    String msg = MessageFormat.format( text, param );
212
    throw new IllegalStateException( msg );
213
  }
209
  }
214
210
215
  private static boolean validateVariantString( String variant ) {
211
  private static boolean validateVariantString( String variant ) {
(-)src/org/eclipse/swt/widgets/Display.java (-8 / +28 lines)
Lines 190-195 Link Here
190
  private Control focusControl;
190
  private Control focusControl;
191
  private final Monitor monitor;
191
  private final Monitor monitor;
192
  private IDisplayAdapter displayAdapter;
192
  private IDisplayAdapter displayAdapter;
193
  private IDisplayLifeCycleAdapter displayLCA;
193
  private WidgetAdapter widgetAdapter;
194
  private WidgetAdapter widgetAdapter;
194
  private Set closeListeners;
195
  private Set closeListeners;
195
  private Set disposeListeners;
196
  private Set disposeListeners;
Lines 749-769 Link Here
749
  public Object getAdapter( final Class adapter ) {
750
  public Object getAdapter( final Class adapter ) {
750
    Object result = null;
751
    Object result = null;
751
    if( adapter == IDisplayAdapter.class ) {
752
    if( adapter == IDisplayAdapter.class ) {
752
      if( displayAdapter == null ) {
753
      result = getDisplayAdapter();
753
        displayAdapter = new DisplayAdapter();
754
      }
755
      result = displayAdapter;
756
    } else if( adapter == IWidgetAdapter.class ) {
754
    } else if( adapter == IWidgetAdapter.class ) {
757
      if( widgetAdapter == null ) {
755
      result = getWidgetAdapter();
758
        widgetAdapter = new WidgetAdapter( "w1" );
756
    } else if( adapter == ILifeCycleAdapter.class ) {
759
      }
757
      result = getDisplayLifeCycleAdapter();
760
      result = widgetAdapter;
761
    } else {
758
    } else {
762
      result = RWTFactory.getAdapterManager().getAdapter( this, adapter );
759
      result = RWTFactory.getAdapterManager().getAdapter( this, adapter );
763
    }
760
    }
764
    return result;
761
    return result;
765
  }
762
  }
766
763
764
  private Object getDisplayAdapter() {
765
    if( displayAdapter == null ) {
766
      displayAdapter = new DisplayAdapter();
767
    }
768
    return displayAdapter;
769
  }
770
771
  private Object getWidgetAdapter() {
772
    if( widgetAdapter == null ) {
773
      widgetAdapter = new WidgetAdapter( "w1" );
774
    }
775
    return widgetAdapter;
776
  }
777
778
  private Object getDisplayLifeCycleAdapter() {
779
    if( displayLCA == null ) {
780
      LifeCycleAdapterFactory factory = RWTFactory.getLifeCycleAdapterFactory();
781
      Object adapter = factory.getAdapter( this, ILifeCycleAdapter.class );
782
      displayLCA = ( IDisplayLifeCycleAdapter )adapter;
783
    }
784
    return displayLCA;
785
  }
786
767
  ///////////////////
787
  ///////////////////
768
  // Shell management
788
  // Shell management
769
789
(-)src/org/eclipse/swt/widgets/Widget.java (-19 / +14 lines)
Lines 12-23 Link Here
12
package org.eclipse.swt.widgets;
12
package org.eclipse.swt.widgets;
13
13
14
import org.eclipse.rwt.Adaptable;
14
import org.eclipse.rwt.Adaptable;
15
import org.eclipse.rwt.internal.AdapterManager;
16
import org.eclipse.rwt.internal.engine.RWTFactory;
15
import org.eclipse.rwt.internal.engine.RWTFactory;
17
import org.eclipse.rwt.internal.events.EventAdapter;
16
import org.eclipse.rwt.internal.events.EventAdapter;
18
import org.eclipse.rwt.internal.events.IEventAdapter;
17
import org.eclipse.rwt.internal.events.IEventAdapter;
18
import org.eclipse.rwt.internal.lifecycle.LifeCycleAdapterFactory;
19
import org.eclipse.rwt.internal.theme.IThemeAdapter;
19
import org.eclipse.rwt.internal.theme.IThemeAdapter;
20
import org.eclipse.rwt.lifecycle.IWidgetAdapter;
20
import org.eclipse.rwt.lifecycle.*;
21
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.SWTException;
22
import org.eclipse.swt.SWTException;
23
import org.eclipse.swt.events.DisposeEvent;
23
import org.eclipse.swt.events.DisposeEvent;
Lines 94-106 Link Here
94
  int state;
94
  int state;
95
  Display display;
95
  Display display;
96
  private Object data;
96
  private Object data;
97
  private AdapterManager adapterManager;
97
  private AbstractWidgetLCA widgetLCA;
98
  private IWidgetAdapter widgetAdapter;
98
  private IWidgetAdapter widgetAdapter;
99
  private IEventAdapter eventAdapter;
99
  private IEventAdapter eventAdapter;
100
  private UntypedEventAdapter untypedAdapter;
100
  private UntypedEventAdapter untypedAdapter;
101
  private IWidgetGraphicsAdapter widgetGraphicsAdapter;
101
  private IWidgetGraphicsAdapter widgetGraphicsAdapter;
102
102
103
104
  Widget() {
103
  Widget() {
105
    // prevent instantiation from outside this package
104
    // prevent instantiation from outside this package
106
  }
105
  }
Lines 152-190 Link Here
152
   * from application code.
151
   * from application code.
153
   * </p>
152
   * </p>
154
   */
153
   */
155
  public Object getAdapter( final Class adapter ) {
154
  public Object getAdapter( Class adapter ) {
155
    // The AdapterManager is bypassed for the sake of performance.
156
    Object result;
156
    Object result;
157
    if( adapter == IEventAdapter.class ) {
157
    if( adapter == IEventAdapter.class ) {
158
      // Note: This is not implemented via the AdapterManager, since the
158
      // Note: This is not implemented via the AdapterManager since the manager's mapping mechanism 
159
      // manager's mapping mechanism prevents the component being released
159
      // prevents the component being released unless the session is invalidated.
160
      // unless the session is invalidated.
161
      if( eventAdapter == null ) {
160
      if( eventAdapter == null ) {
162
        eventAdapter = new EventAdapter();
161
        eventAdapter = new EventAdapter();
163
      }
162
      }
164
      result = eventAdapter;
163
      result = eventAdapter;
165
    } else if( adapter == IWidgetAdapter.class ) {
164
    } else if( adapter == IWidgetAdapter.class ) {
166
      // [fappel] Directly return the WidgetAdapter instead of consulting the
167
      // adapter factory. This is done for performance reasons and must not
168
      // be changed without good reason.
169
      if( widgetAdapter == null ) {
165
      if( widgetAdapter == null ) {
170
        widgetAdapter = new WidgetAdapter();
166
        widgetAdapter = new WidgetAdapter();
171
      }
167
      }
172
      result = widgetAdapter;
168
      result = widgetAdapter;
173
    } else if( adapter == IThemeAdapter.class ) {
169
    } else if( adapter == IThemeAdapter.class ) {
174
      // This also bypasses the AdapterManager for the sake of performance.
175
      // ThemeAdapters are requested frequently during size computations.
176
      result = RWTFactory.getThemeAdapterManager().getThemeAdapter( this );
170
      result = RWTFactory.getThemeAdapterManager().getThemeAdapter( this );
177
    } else if( adapter == IWidgetGraphicsAdapter.class ) {
171
    } else if( adapter == IWidgetGraphicsAdapter.class ) {
178
      if( widgetGraphicsAdapter == null ) {
172
      if( widgetGraphicsAdapter == null ) {
179
        widgetGraphicsAdapter = new WidgetGraphicsAdapter();
173
        widgetGraphicsAdapter = new WidgetGraphicsAdapter();
180
      }
174
      }
181
      result = widgetGraphicsAdapter;
175
      result = widgetGraphicsAdapter;
182
    } else {
176
    } else if( adapter == ILifeCycleAdapter.class ) {
183
      // [fappel] Buffer the adapterManager to improve performance
177
      if( widgetLCA == null ) {
184
      if( adapterManager == null ) {
178
        LifeCycleAdapterFactory factory = RWTFactory.getLifeCycleAdapterFactory();
185
        adapterManager = RWTFactory.getAdapterManager();
179
        widgetLCA = ( AbstractWidgetLCA )factory.getAdapter( this, ILifeCycleAdapter.class );
186
      }
180
      }
187
      result = adapterManager.getAdapter( this, adapter );
181
      result = widgetLCA;
182
    } else {
183
      result = RWTFactory.getAdapterManager().getAdapter( this, adapter );
188
    }
184
    }
189
    return result;
185
    return result;
190
  }
186
  }
Lines 811-817 Link Here
811
  }
807
  }
812
808
813
  void releaseWidget() {
809
  void releaseWidget() {
814
    adapterManager = null;
815
    untypedAdapter = null;
810
    untypedAdapter = null;
816
    state |= DISPOSED;
811
    state |= DISPOSED;
817
  }
812
  }
(-)src/org/eclipse/rwt/internal/engine/RWTFactory_Test.java (+3 lines)
Lines 86-91 Link Here
86
    
86
    
87
    assertNotNull( RWTFactory.getProbeStore() );
87
    assertNotNull( RWTFactory.getProbeStore() );
88
    assertSame( RWTFactory.getProbeStore(), RWTFactory.getProbeStore() );
88
    assertSame( RWTFactory.getProbeStore(), RWTFactory.getProbeStore() );
89
    
90
    assertNotNull( RWTFactory.getLifeCycleAdapterFactory() );
91
    assertSame( RWTFactory.getLifeCycleAdapterFactory(), RWTFactory.getLifeCycleAdapterFactory() );
89
  }
92
  }
90
93
91
  protected void setUp() throws Exception {
94
  protected void setUp() throws Exception {
(-)plugin.xml (-11 lines)
Lines 2384-2400 Link Here
2384
  </extension>
2384
  </extension>
2385
  
2385
  
2386
  <!-- RAP specific -->
2386
  <!-- RAP specific -->
2387
    <extension
2388
      id="org.eclipse.ui.workbench.adapterfactories"
2389
      point="org.eclipse.rap.ui.adapterfactory">
2390
    <factory
2391
        factoryClass="org.eclipse.rwt.internal.lifecycle.LifeCycleAdapterFactory"
2392
        adaptableClass="org.eclipse.swt.widgets.Widget"/>
2393
    <factory
2394
        factoryClass="org.eclipse.rwt.internal.lifecycle.LifeCycleAdapterFactory"
2395
        adaptableClass="org.eclipse.swt.widgets.Display"/>
2396
  </extension>
2397
2398
  <extension
2387
  <extension
2399
        id="org.eclipse.ui.workbench.currentPhase"
2388
        id="org.eclipse.ui.workbench.currentPhase"
2400
        point="org.eclipse.rap.ui.phaselistener">
2389
        point="org.eclipse.rap.ui.phaselistener">

Return to bug 346089