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 421852
Collapse All | Expand All

(-)a/bundles/org.eclipse.rap.rwt/js/rwt/remote/handler/MenuHandler.js (-9 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011, 2012 EclipseSource and others.
2
 * Copyright (c) 2011, 2013 EclipseSource and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-21 Link Here
16
    // TODO [tb] : split into Menu and MenuBar, or unify parent handling
16
    // TODO [tb] : split into Menu and MenuBar, or unify parent handling
17
    if( properties.style.indexOf( "BAR" ) != -1 ) {
17
    if( properties.style.indexOf( "BAR" ) != -1 ) {
18
      result = new rwt.widgets.MenuBar();
18
      result = new rwt.widgets.MenuBar();
19
      rwt.remote.HandlerUtil.callWithTarget( properties.parent, function( parent ) {
20
        result.setParent( parent );
21
      } );
19
    } else {
22
    } else {
20
      result = new rwt.widgets.Menu();
23
      result = new rwt.widgets.Menu();
21
    }
24
    }
Lines 28-47 Link Here
28
  getDestroyableChildren : rwt.remote.HandlerUtil.getDestroyableChildrenFinder(),
31
  getDestroyableChildren : rwt.remote.HandlerUtil.getDestroyableChildrenFinder(),
29
32
30
  properties : [
33
  properties : [
31
    "parent",
32
    "bounds",
34
    "bounds",
33
    "enabled",
35
    "enabled",
34
    "customVariant"
36
    "customVariant"
35
  ],
37
  ],
36
38
37
  propertyHandler : {
39
  propertyHandler : {
38
    "parent" : function( widget, value ) {
39
      if( widget.hasState( "rwt_BAR" ) ) {
40
        rwt.remote.HandlerUtil.callWithTarget( value, function( parent ) {
41
          widget.setParent( parent );
42
        } );
43
      }
44
    },
45
    "bounds" : function( widget, value ) {
40
    "bounds" : function( widget, value ) {
46
      if( widget.hasState( "rwt_BAR" ) ) {
41
      if( widget.hasState( "rwt_BAR" ) ) {
47
        widget.setLeft( value[ 0 ] );
42
        widget.setLeft( value[ 0 ] );
(-)a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/menukit/MenuLCA.java (-13 / +10 lines)
Lines 21-26 Link Here
21
import static org.eclipse.rap.rwt.lifecycle.WidgetLCAUtil.renderListener;
21
import static org.eclipse.rap.rwt.lifecycle.WidgetLCAUtil.renderListener;
22
import static org.eclipse.rap.rwt.lifecycle.WidgetLCAUtil.renderProperty;
22
import static org.eclipse.rap.rwt.lifecycle.WidgetLCAUtil.renderProperty;
23
import static org.eclipse.rap.rwt.lifecycle.WidgetLCAUtil.wasEventSent;
23
import static org.eclipse.rap.rwt.lifecycle.WidgetLCAUtil.wasEventSent;
24
import static org.eclipse.rap.rwt.lifecycle.WidgetUtil.getId;
24
import static org.eclipse.swt.internal.events.EventLCAUtil.isListening;
25
import static org.eclipse.swt.internal.events.EventLCAUtil.isListening;
25
26
26
import java.io.IOException;
27
import java.io.IOException;
Lines 34-39 Link Here
34
import org.eclipse.swt.graphics.Rectangle;
35
import org.eclipse.swt.graphics.Rectangle;
35
import org.eclipse.swt.internal.widgets.IMenuAdapter;
36
import org.eclipse.swt.internal.widgets.IMenuAdapter;
36
import org.eclipse.swt.internal.widgets.IShellAdapter;
37
import org.eclipse.swt.internal.widgets.IShellAdapter;
38
import org.eclipse.swt.internal.widgets.Props;
37
import org.eclipse.swt.widgets.Decorations;
39
import org.eclipse.swt.widgets.Decorations;
38
import org.eclipse.swt.widgets.Menu;
40
import org.eclipse.swt.widgets.Menu;
39
import org.eclipse.swt.widgets.MenuItem;
41
import org.eclipse.swt.widgets.MenuItem;
Lines 47-58 Link Here
47
    "BAR", "DROP_DOWN", "POP_UP", "NO_RADIO_GROUP"
49
    "BAR", "DROP_DOWN", "POP_UP", "NO_RADIO_GROUP"
48
  };
50
  };
49
51
50
  private static final String PROP_PARENT = "parent";
51
  private static final String PROP_ENABLED = "enabled";
52
  private static final String PROP_ENABLED = "enabled";
52
  private static final String PROP_SHOW_LISTENER = "Show";
53
  private static final String PROP_SHOW_LISTENER = "Show";
53
  private static final String PROP_HIDE_LISTENER = "Hide";
54
  private static final String PROP_HIDE_LISTENER = "Hide";
54
  private static final String METHOD_UNHIDE_ITEMS = "unhideItems";
55
  private static final String METHOD_UNHIDE_ITEMS = "unhideItems";
55
  private static final String METHOD_SHOW_MENU = "showMenu";
56
  private static final String METHOD_SHOW_MENU = "showMenu";
57
58
  private static final Rectangle DEFAULT_BOUNDS = new Rectangle( 0, 0, 0, 0 );
56
59
57
  @Override
60
  @Override
58
  public void preserveValues( Widget widget ) {
61
  public void preserveValues( Widget widget ) {
Lines 62-70 Link Here
62
    preserveListener( menu, PROP_HIDE_LISTENER, hasHideListener( menu ) );
65
    preserveListener( menu, PROP_HIDE_LISTENER, hasHideListener( menu ) );
63
    WidgetLCAUtil.preserveCustomVariant( menu );
66
    WidgetLCAUtil.preserveCustomVariant( menu );
64
    WidgetLCAUtil.preserveHelpListener( menu );
67
    WidgetLCAUtil.preserveHelpListener( menu );
65
    if( isMenuBar( menu ) ) {
66
      preserveProperty( menu, PROP_PARENT, getParent( menu ) );
67
    }
68
  }
68
  }
69
69
70
  @Override
70
  @Override
Lines 72-77 Link Here
72
    Menu menu = ( Menu )widget;
72
    Menu menu = ( Menu )widget;
73
    RemoteObject remoteObject = createRemoteObject( menu , TYPE );
73
    RemoteObject remoteObject = createRemoteObject( menu , TYPE );
74
    remoteObject.setHandler( new MenuOperationHandler( menu ) );
74
    remoteObject.setHandler( new MenuOperationHandler( menu ) );
75
    remoteObject.set( "parent", getId( menu.getParent() ) );
75
    remoteObject.set( "style", createJsonArray( getStyles( menu, ALLOWED_STYLES ) ) );
76
    remoteObject.set( "style", createJsonArray( getStyles( menu, ALLOWED_STYLES ) ) );
76
  }
77
  }
77
78
Lines 83-91 Link Here
83
    renderListener( menu, PROP_HIDE_LISTENER, hasHideListener( menu ), false );
84
    renderListener( menu, PROP_HIDE_LISTENER, hasHideListener( menu ), false );
84
    WidgetLCAUtil.renderCustomVariant( menu );
85
    WidgetLCAUtil.renderCustomVariant( menu );
85
    WidgetLCAUtil.renderListenHelp( menu );
86
    WidgetLCAUtil.renderListenHelp( menu );
86
    if( isMenuBar( menu ) ) {
87
      renderProperty( menu, PROP_PARENT, getParent( menu ), null );
88
    }
89
    renderBounds( menu );
87
    renderBounds( menu );
90
    renderShow( menu );
88
    renderShow( menu );
91
    renderUnhideItems( menu );
89
    renderUnhideItems( menu );
Lines 98-106 Link Here
98
  }
96
  }
99
97
100
  private static void renderBounds( Menu menu ) {
98
  private static void renderBounds( Menu menu ) {
101
    if( isMenuBar( menu ) && getParent( menu ) != null ) {
99
    if( isMenuBar( menu ) ) {
102
      // Bounds are preserved in ShellLCA#preserveMenuBounds
100
      // Bounds are preserved in ShellLCA#preserveMenuBounds
103
      WidgetLCAUtil.renderBounds( menu, getBounds( menu ) );
101
      renderProperty( menu, Props.BOUNDS, getBounds( menu ), DEFAULT_BOUNDS );
104
    }
102
    }
105
  }
103
  }
106
104
Lines 146-160 Link Here
146
144
147
  private static Rectangle getBounds( Menu menu ) {
145
  private static Rectangle getBounds( Menu menu ) {
148
    Rectangle result = new Rectangle( 0, 0, 0, 0 );
146
    Rectangle result = new Rectangle( 0, 0, 0, 0 );
149
    Decorations parent = getParent( menu );
147
    Decorations parent = getBoundingShell( menu );
150
    if( parent != null ) {
148
    if( parent != null ) {
151
      IShellAdapter shellAdapter = parent.getAdapter( IShellAdapter.class );
149
      result = parent.getAdapter( IShellAdapter.class ).getMenuBounds();
152
      result = shellAdapter.getMenuBounds();
153
    }
150
    }
154
    return result;
151
    return result;
155
  }
152
  }
156
153
157
  private static Decorations getParent( Menu menu ) {
154
  private static Decorations getBoundingShell( Menu menu ) {
158
    Decorations result = null;
155
    Decorations result = null;
159
    if( menu.getParent().getMenuBar() == menu ) {
156
    if( menu.getParent().getMenuBar() == menu ) {
160
      result = menu.getParent();
157
      result = menu.getParent();
(-)a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/menukit/MenuLCA_Test.java (-51 / +9 lines)
Lines 73-105 Link Here
73
  }
73
  }
74
74
75
  @Test
75
  @Test
76
  public void testUnassignedMenuBar() throws IOException {
77
    String shellId = WidgetUtil.getId( shell );
78
    Menu menuBar = new Menu( shell, SWT.BAR );
79
    Fixture.markInitialized( display );
80
    Fixture.markInitialized( menuBar );
81
    // Ensure that a menuBar that is not assigned to any shell (via setMenuBar)
82
    // is rendered but without settings its parent
83
    lca.renderChanges( menuBar );
84
    Message message = Fixture.getProtocolMessage();
85
    assertNull( message.findSetOperation( menuBar, "parent" ) );
86
    // The contrary: an assigned menuBar has to be rendered with setParent
87
    Fixture.fakeNewRequest();
88
    Fixture.preserveWidgets();
89
    shell.setMenuBar( menuBar );
90
    lca.renderChanges( menuBar );
91
    message = Fixture.getProtocolMessage();
92
    assertEquals( shellId, message.findSetProperty( menuBar, "parent" ).asString() );
93
    // Un-assigning a menuBar must result in setParent( null ) being rendered
94
    Fixture.fakeNewRequest();
95
    Fixture.preserveWidgets();
96
    shell.setMenuBar( null );
97
    lca.renderChanges( menuBar );
98
    message = Fixture.getProtocolMessage();
99
    assertEquals( JsonObject.NULL, message.findSetProperty( menuBar, "parent" ) );
100
  }
101
102
  @Test
103
  public void testRenderBoundsForMenuBar() {
76
  public void testRenderBoundsForMenuBar() {
104
    getRemoteObject( shell ).setHandler( new ShellOperationHandler( shell ) );
77
    getRemoteObject( shell ).setHandler( new ShellOperationHandler( shell ) );
105
    Menu menuBar = new Menu( shell, SWT.BAR );
78
    Menu menuBar = new Menu( shell, SWT.BAR );
Lines 205-243 Link Here
205
  }
178
  }
206
179
207
  @Test
180
  @Test
208
  public void testRenderInitialParent() throws IOException {
181
  public void testRenderParent_bar() throws IOException {
209
    Menu menu = new Menu( shell, SWT.BAR );
182
    Menu menu = new Menu( shell, SWT.BAR );
210
183
211
    lca.render( menu );
184
    lca.renderInitialization( menu );
212
185
213
    Message message = Fixture.getProtocolMessage();
186
    Message message = Fixture.getProtocolMessage();
214
    CreateOperation operation = message.findCreateOperation( menu );
187
    assertEquals( getId( shell ), message.findCreateProperty( menu, "parent" ).asString() );
215
    assertTrue( operation.getPropertyNames().indexOf( "parent" ) == -1 );
216
  }
188
  }
217
189
218
  @Test
190
  @Test
219
  public void testRenderParent() throws IOException {
191
  public void testRenderParent_popup() throws IOException {
220
    Menu menu = new Menu( shell, SWT.BAR );
192
    Menu menu = new Menu( shell, SWT.POP_UP );
221
193
222
    shell.setMenuBar( menu );
194
    lca.renderInitialization( menu );
223
    lca.renderChanges( menu );
224
195
225
    Message message = Fixture.getProtocolMessage();
196
    Message message = Fixture.getProtocolMessage();
226
    assertEquals( getId( shell ), message.findSetProperty( menu, "parent" ).asString() );
197
    assertEquals( getId( shell ), message.findCreateProperty( menu, "parent" ).asString() );
227
  }
228
229
  @Test
230
  public void testRenderParentUnchanged() throws IOException {
231
    Menu menu = new Menu( shell, SWT.BAR );
232
    Fixture.markInitialized( display );
233
    Fixture.markInitialized( menu );
234
235
    shell.setMenuBar( menu );
236
    Fixture.preserveWidgets();
237
    lca.renderChanges( menu );
238
239
    Message message = Fixture.getProtocolMessage();
240
    assertNull( message.findSetOperation( menu, "parent" ) );
241
  }
198
  }
242
199
243
  @Test
200
  @Test
Lines 290-296 Link Here
290
    lca.renderChanges( menu );
247
    lca.renderChanges( menu );
291
248
292
    Message message = Fixture.getProtocolMessage();
249
    Message message = Fixture.getProtocolMessage();
293
    assertNull( message.findSetOperation( menu, "bounds" ) );
250
    JsonArray bounds = message.findSetProperty( menu, "bounds" ).asArray();
251
    assertEquals( new JsonArray().add( 0 ).add( 0 ).add( 0 ).add( 0 ), bounds );
294
  }
252
  }
295
253
296
  @Test
254
  @Test

Return to bug 421852