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

(-)src/org/eclipse/swt/internal/widgets/toolitemkit/PushToolItemLCA.java (-2 / +5 lines)
Lines 19-24 Link Here
19
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.internal.widgets.ItemLCAUtil;
20
import org.eclipse.swt.internal.widgets.ItemLCAUtil;
21
import org.eclipse.swt.internal.widgets.Props;
21
import org.eclipse.swt.internal.widgets.Props;
22
import org.eclipse.swt.widgets.ToolBar;
22
import org.eclipse.swt.widgets.ToolItem;
23
import org.eclipse.swt.widgets.ToolItem;
23
24
24
final class PushToolItemLCA extends ToolItemDelegateLCA {
25
final class PushToolItemLCA extends ToolItemDelegateLCA {
Lines 44-53 Link Here
44
45
45
  void renderInitialization( final ToolItem toolItem ) throws IOException {
46
  void renderInitialization( final ToolItem toolItem ) throws IOException {
46
    JSWriter writer = JSWriter.getWriterFor( toolItem );
47
    JSWriter writer = JSWriter.getWriterFor( toolItem );
48
    ToolBar toolBar = toolItem.getParent();
47
    Object[] args = new Object[]{
49
    Object[] args = new Object[]{
48
      WidgetUtil.getId( toolItem ),
50
      WidgetUtil.getId( toolItem ),
49
      toolItem.getParent(),
51
      toolBar,
50
      Boolean.valueOf( ( toolItem.getParent().getStyle() & SWT.FLAT ) != 0 )
52
      new Integer( toolBar.indexOf( toolItem ) ),
53
      Boolean.valueOf( ( toolBar.getStyle() & SWT.FLAT ) != 0 )
51
    };
54
    };
52
    writer.callStatic( CREATE_PUSH, args );
55
    writer.callStatic( CREATE_PUSH, args );
53
  }
56
  }
(-)src/org/eclipse/swt/internal/widgets/toolitemkit/RadioToolItemLCA.java (-3 / +4 lines)
Lines 60-69 Link Here
60
  void renderInitialization( final ToolItem toolItem ) throws IOException {
60
  void renderInitialization( final ToolItem toolItem ) throws IOException {
61
    JSWriter writer = JSWriter.getWriterFor( toolItem );
61
    JSWriter writer = JSWriter.getWriterFor( toolItem );
62
    ToolBar bar = toolItem.getParent();
62
    ToolBar bar = toolItem.getParent();
63
    int myIndex = bar.indexOf( toolItem );
63
    int itemIndex = bar.indexOf( toolItem );
64
    ToolItem neighbour = null;
64
    ToolItem neighbour = null;
65
    if ( myIndex > 0 ) {
65
    if ( itemIndex > 0 ) {
66
      neighbour = bar.getItem( myIndex - 1 );
66
      neighbour = bar.getItem( itemIndex - 1 );
67
      if( ( neighbour.getStyle() & SWT.RADIO ) == 0 ) {
67
      if( ( neighbour.getStyle() & SWT.RADIO ) == 0 ) {
68
        neighbour = null;
68
        neighbour = null;
69
      }
69
      }
Lines 71-76 Link Here
71
    Object[] args = new Object[] {
71
    Object[] args = new Object[] {
72
      WidgetUtil.getId( toolItem ),
72
      WidgetUtil.getId( toolItem ),
73
      toolItem.getParent(),
73
      toolItem.getParent(),
74
      new Integer( itemIndex ),
74
      toolItem.getSelection() ? "true" : null,
75
      toolItem.getSelection() ? "true" : null,
75
      neighbour
76
      neighbour
76
    };
77
    };
(-)src/org/eclipse/swt/internal/widgets/toolitemkit/SeparatorToolItemLCA.java (-4 / +5 lines)
Lines 17-24 Link Here
17
import org.eclipse.rwt.lifecycle.*;
17
import org.eclipse.rwt.lifecycle.*;
18
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.internal.widgets.WidgetAdapter;
19
import org.eclipse.swt.internal.widgets.WidgetAdapter;
20
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.*;
21
import org.eclipse.swt.widgets.ToolItem;
22
21
23
final class SeparatorToolItemLCA extends ToolItemDelegateLCA {
22
final class SeparatorToolItemLCA extends ToolItemDelegateLCA {
24
23
Lines 43-52 Link Here
43
  
42
  
44
  void renderInitialization( final ToolItem toolItem ) throws IOException {
43
  void renderInitialization( final ToolItem toolItem ) throws IOException {
45
    JSWriter writer = JSWriter.getWriterFor( toolItem );
44
    JSWriter writer = JSWriter.getWriterFor( toolItem );
45
    ToolBar toolBar = toolItem.getParent();
46
    Object[] args = new Object[]{
46
    Object[] args = new Object[]{
47
      WidgetUtil.getId( toolItem ),
47
      WidgetUtil.getId( toolItem ),
48
      toolItem.getParent(),
48
      toolBar,
49
      Boolean.valueOf( ( toolItem.getParent().getStyle() & SWT.FLAT  ) != 0 )
49
      new Integer( toolBar.indexOf( toolItem ) ),
50
      Boolean.valueOf( ( toolBar.getStyle() & SWT.FLAT  ) != 0 )
50
    };
51
    };
51
    writer.callStatic( CREATE_SEPARATOR, args );    
52
    writer.callStatic( CREATE_SEPARATOR, args );    
52
  }
53
  }
(-)src/org/eclipse/swt/internal/widgets/toolitemkit/DropDownToolItemLCA.java (-5 / +5 lines)
Lines 23-31 Link Here
23
import org.eclipse.swt.graphics.Rectangle;
23
import org.eclipse.swt.graphics.Rectangle;
24
import org.eclipse.swt.internal.widgets.ItemLCAUtil;
24
import org.eclipse.swt.internal.widgets.ItemLCAUtil;
25
import org.eclipse.swt.internal.widgets.Props;
25
import org.eclipse.swt.internal.widgets.Props;
26
import org.eclipse.swt.widgets.ToolItem;
26
import org.eclipse.swt.widgets.*;
27
import org.eclipse.swt.widgets.Widget;
28
import org.eclipse.swt.widgets.Display;
29
27
30
final class DropDownToolItemLCA extends ToolItemDelegateLCA {
28
final class DropDownToolItemLCA extends ToolItemDelegateLCA {
31
29
Lines 72-81 Link Here
72
70
73
  void renderInitialization( final ToolItem toolItem ) throws IOException {
71
  void renderInitialization( final ToolItem toolItem ) throws IOException {
74
    JSWriter writer = JSWriter.getWriterFor( toolItem );
72
    JSWriter writer = JSWriter.getWriterFor( toolItem );
73
    ToolBar toolBar = toolItem.getParent();
75
    Object[] args = new Object[] {
74
    Object[] args = new Object[] {
76
      WidgetUtil.getId( toolItem ),
75
      WidgetUtil.getId( toolItem ),
77
      toolItem.getParent(),
76
      toolBar,
78
      Boolean.valueOf( ( toolItem.getParent().getStyle() & SWT.FLAT ) != 0 )
77
      new Integer( toolBar.indexOf( toolItem ) ),
78
      Boolean.valueOf( ( toolBar.getStyle() & SWT.FLAT ) != 0 )
79
    };
79
    };
80
    writer.callStatic( CREATE_DROP_DOWN, args );
80
    writer.callStatic( CREATE_DROP_DOWN, args );
81
  }
81
  }
(-)src/org/eclipse/swt/internal/widgets/toolitemkit/CheckToolItemLCA.java (-2 / +5 lines)
Lines 19-24 Link Here
19
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.internal.widgets.ItemLCAUtil;
20
import org.eclipse.swt.internal.widgets.ItemLCAUtil;
21
import org.eclipse.swt.internal.widgets.Props;
21
import org.eclipse.swt.internal.widgets.Props;
22
import org.eclipse.swt.widgets.ToolBar;
22
import org.eclipse.swt.widgets.ToolItem;
23
import org.eclipse.swt.widgets.ToolItem;
23
24
24
25
Lines 52-64 Link Here
52
53
53
  void renderInitialization( final ToolItem toolItem ) throws IOException {
54
  void renderInitialization( final ToolItem toolItem ) throws IOException {
54
    JSWriter writer = JSWriter.getWriterFor( toolItem );
55
    JSWriter writer = JSWriter.getWriterFor( toolItem );
56
    ToolBar toolBar = toolItem.getParent();
55
    Object[] args = new Object[] {
57
    Object[] args = new Object[] {
56
      WidgetUtil.getId( toolItem ),
58
      WidgetUtil.getId( toolItem ),
57
      toolItem.getParent()
59
      toolBar,
60
      new Integer( toolBar.indexOf( toolItem ) )
58
    };
61
    };
59
    writer.callStatic( CREATE_CHECK, args );
62
    writer.callStatic( CREATE_CHECK, args );
60
    writer.set( "checked", toolItem.getSelection() );
63
    writer.set( "checked", toolItem.getSelection() );
61
    if( ( toolItem.getParent().getStyle() & SWT.FLAT ) != 0 ) {
64
    if( ( toolBar.getStyle() & SWT.FLAT ) != 0 ) {
62
      writer.call( "addState", new Object[]{ "rwt_FLAT" } );
65
      writer.call( "addState", new Object[]{ "rwt_FLAT" } );
63
    }
66
    }
64
  }
67
  }
(-)js/org/eclipse/swt/ToolItemUtil.js (-11 / +11 lines)
Lines 17-23 Link Here
17
qx.Class.define( "org.eclipse.swt.ToolItemUtil", {
17
qx.Class.define( "org.eclipse.swt.ToolItemUtil", {
18
18
19
  statics : {
19
  statics : {
20
    createSeparator : function( id, parent, isFlat ) {
20
    createSeparator : function( id, parent, index, isFlat ) {
21
      var sep = new qx.ui.toolbar.Separator();
21
      var sep = new qx.ui.toolbar.Separator();
22
      var line = sep.getFirstChild();
22
      var line = sep.getFirstChild();
23
      sep.setUserData( "line", line );
23
      sep.setUserData( "line", line );
Lines 27-33 Link Here
27
      }
27
      }
28
      org.eclipse.swt.WidgetManager.getInstance().add( sep, id, false );
28
      org.eclipse.swt.WidgetManager.getInstance().add( sep, id, false );
29
      sep.setParent( parent );
29
      sep.setParent( parent );
30
      parent.add( sep );
30
      parent.addAt( sep, index );
31
    },
31
    },
32
32
33
    setControl : function( sep, control ) {
33
    setControl : function( sep, control ) {
Lines 45-54 Link Here
45
      }
45
      }
46
    },
46
    },
47
47
48
    createRadio : function( id, parent, selected, neighbour ) {
48
    createRadio : function( id, parent, index, selected, neighbour ) {
49
      var radio = new qx.ui.toolbar.RadioButton();
49
      var radio = new qx.ui.toolbar.RadioButton();
50
      radio.setDisableUncheck( true );
50
      radio.setDisableUncheck( true );
51
      parent.add( radio );
51
      parent.addAt( radio, index );
52
      if( neighbour ) {
52
      if( neighbour ) {
53
        radio.radioManager = neighbour.radioManager;
53
        radio.radioManager = neighbour.radioManager;
54
      } else {
54
      } else {
Lines 66-72 Link Here
66
      org.eclipse.swt.ToolItemUtil._registerMouseListeners( radio );
66
      org.eclipse.swt.ToolItemUtil._registerMouseListeners( radio );
67
    },
67
    },
68
68
69
    createPush : function( id, parent, isFlat ) {
69
    createPush : function( id, parent, index, isFlat ) {
70
      var push = new qx.ui.toolbar.Button();
70
      var push = new qx.ui.toolbar.Button();
71
      if( isFlat ) {
71
      if( isFlat ) {
72
        push.addState( "rwt_FLAT" );
72
        push.addState( "rwt_FLAT" );
Lines 75-87 Link Here
75
      push.setLabel( "(empty)" );
75
      push.setLabel( "(empty)" );
76
      push.getLabelObject().setMode( qx.constant.Style.LABEL_MODE_HTML );
76
      push.getLabelObject().setMode( qx.constant.Style.LABEL_MODE_HTML );
77
      push.setLabel( "" );
77
      push.setLabel( "" );
78
      parent.add( push );
78
      parent.addAt( push, index );
79
      org.eclipse.swt.WidgetManager.getInstance().add( push, id, false );
79
      org.eclipse.swt.WidgetManager.getInstance().add( push, id, false );
80
      org.eclipse.swt.ToolItemUtil._registerMouseListeners( push );
80
      org.eclipse.swt.ToolItemUtil._registerMouseListeners( push );
81
    },
81
    },
82
82
83
    createDropDown : function( id, parent, isFlat ) {
83
    createDropDown : function( id, parent, index, isFlat ) {
84
      org.eclipse.swt.ToolItemUtil.createPush( id, parent, isFlat );
84
      org.eclipse.swt.ToolItemUtil.createPush( id, parent, index, isFlat );
85
      var button 
85
      var button 
86
        = org.eclipse.swt.WidgetManager.getInstance().findWidgetById( id );
86
        = org.eclipse.swt.WidgetManager.getInstance().findWidgetById( id );
87
      var dropDown = new qx.ui.toolbar.Button( "", "widget/arrows/down.gif" );
87
      var dropDown = new qx.ui.toolbar.Button( "", "widget/arrows/down.gif" );
Lines 90-96 Link Here
90
      if( isFlat ) {
90
      if( isFlat ) {
91
        dropDown.addState( "rwt_FLAT" );
91
        dropDown.addState( "rwt_FLAT" );
92
      }
92
      }
93
      parent.add( dropDown );
93
      parent.addAfter( dropDown, button );
94
      var dropDownId = org.eclipse.swt.ToolItemUtil._getDropDownId( button );
94
      var dropDownId = org.eclipse.swt.ToolItemUtil._getDropDownId( button );
95
      org.eclipse.swt.WidgetManager.getInstance().add( dropDown, dropDownId, false );
95
      org.eclipse.swt.WidgetManager.getInstance().add( dropDown, dropDownId, false );
96
      // Register enable listener that keeps enabled state of dropDown in sync
96
      // Register enable listener that keeps enabled state of dropDown in sync
Lines 139-147 Link Here
139
      }
139
      }
140
    },
140
    },
141
141
142
    createCheck : function( id, parent ) {
142
    createCheck : function( id, parent, index ) {
143
      var button = new qx.ui.toolbar.CheckBox();
143
      var button = new qx.ui.toolbar.CheckBox();
144
      parent.add( button );
144
      parent.addAt( button, index );
145
      org.eclipse.swt.WidgetManager.getInstance().add( button, id, false );
145
      org.eclipse.swt.WidgetManager.getInstance().add( button, id, false );
146
      org.eclipse.swt.ToolItemUtil._registerMouseListeners( button );
146
      org.eclipse.swt.ToolItemUtil._registerMouseListeners( button );
147
    },
147
    },
(-)src/org/eclipse/swt/internal/widgets/toolitemkit/ToolItemLCA_Test.java (+22 lines)
Lines 225-230 Link Here
225
    item.setDisabledImage( null );
225
    item.setDisabledImage( null );
226
    assertSame( enabledImage, ToolItemLCAUtil.getImage( item ) );
226
    assertSame( enabledImage, ToolItemLCAUtil.getImage( item ) );
227
  }
227
  }
228
  
229
  public void testIndexOnInitialize() throws Exception {
230
    Fixture.fakeResponseWriter();
231
    Display display = new Display();
232
    Shell shell = new Shell( display, SWT.NONE );
233
    ToolBar tb = new ToolBar( shell, SWT.NONE );
234
    final ToolItem item1 = new ToolItem( tb, SWT.PUSH );
235
    final ToolItem item2 = new ToolItem( tb, SWT.PUSH );
236
    shell.open();
237
    ToolItemLCA itemLCA = new ToolItemLCA();
238
    itemLCA.renderInitialization( item1 );
239
    itemLCA.renderInitialization( item2 );
240
    String parent = "wm.findWidgetById( \"" + WidgetUtil.getId( tb )+ "\" )";
241
    String expected = "createPush( \"" + WidgetUtil.getId( item1 ) + "\", " + parent + ", 0, false );";
242
    assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 );
243
    expected = "createPush( \"" + WidgetUtil.getId( item2 ) + "\", " + parent + ", 1, false );";
244
    assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 );
245
    final ToolItem item0 = new ToolItem( tb, SWT.PUSH, 0 );
246
    itemLCA.renderInitialization( item0 );
247
    expected = "createPush( \"" + WidgetUtil.getId( item0 ) + "\", " + parent + ", 0, false );";
248
    assertTrue( Fixture.getAllMarkup().indexOf( expected ) != -1 );
249
  }
228
250
229
  protected void setUp() throws Exception {
251
  protected void setUp() throws Exception {
230
    RWTFixture.setUp();
252
    RWTFixture.setUp();
(-)src/org/eclipse/rap/demo/controls/ToolBarTab.java (-1 / +30 lines)
Lines 18-24 Link Here
18
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Point;
21
import org.eclipse.swt.layout.RowLayout;
21
import org.eclipse.swt.layout.*;
22
import org.eclipse.swt.widgets.*;
22
import org.eclipse.swt.widgets.*;
23
23
24
24
Lines 44-49 Link Here
44
    createBgColorButton();
44
    createBgColorButton();
45
    createBgImageButton();
45
    createBgImageButton();
46
    createFontChooser();
46
    createFontChooser();
47
    createNewItemButton();
48
  }
49
50
  private void createNewItemButton() {
51
    Group group = new Group( styleComp, SWT.NONE );
52
    group.setLayout( new GridLayout( 2, false ) );
53
    group.setText( "New Item" );
54
    Label label = new Label( group, SWT.NONE );
55
    label.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, false, false ) );
56
    label.setText( "Index:" );
57
    final Text index = new Text( group, SWT.SINGLE | SWT.LEAD | SWT.BORDER );
58
    index.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
59
    index.setText( "0" );
60
    Button addItemButton = new Button( group, SWT.PUSH );
61
    GridData gridData = new GridData( SWT.BEGINNING,
62
                                               SWT.CENTER,
63
                                               false,
64
                                               false );
65
    gridData.horizontalSpan = 2;
66
    addItemButton.setLayoutData( gridData );
67
    addItemButton.setText( "Add Item" );
68
    addItemButton.addSelectionListener( new SelectionAdapter() {
69
70
      public void widgetSelected( SelectionEvent e ) {
71
        int newIndex = Integer.parseInt( index.getText() );
72
        ToolItem toolItem = new ToolItem( toolBar, SWT.PUSH, newIndex );
73
        toolItem.setText( "Item" );
74
      }
75
    } );
47
  }
76
  }
48
77
49
  protected void createExampleControls( final Composite parent ) {
78
  protected void createExampleControls( final Composite parent ) {

Return to bug 285581