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

(-)src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarInitializer.java (+2 lines)
Lines 23-28 Link Here
23
  public static final String OVERFLOW_ACTIVE = "coolbar.overflow.active";
23
  public static final String OVERFLOW_ACTIVE = "coolbar.overflow.active";
24
  public static final String BUTTON_BG = "coolbar.button.bg";
24
  public static final String BUTTON_BG = "coolbar.button.bg";
25
  public static final String OVERFLOW_COLOR = "coolbar.overflow.color";
25
  public static final String OVERFLOW_COLOR = "coolbar.overflow.color";
26
  public static final String ARROW = "coolbar.arrow";
26
27
27
  public CoolbarInitializer() {
28
  public CoolbarInitializer() {
28
  }
29
  }
Lines 33-38 Link Here
33
    layoutSet.addImagePath( OVERFLOW_ACTIVE, 
34
    layoutSet.addImagePath( OVERFLOW_ACTIVE, 
34
                            "img/toolbar_overflow_hover_active.png" );
35
                            "img/toolbar_overflow_hover_active.png" );
35
    layoutSet.addImagePath( BUTTON_BG, "img/toolbarButtonBg.png" );
36
    layoutSet.addImagePath( BUTTON_BG, "img/toolbarButtonBg.png" );
37
    layoutSet.addImagePath( ARROW, "img/toolbar_arrow.png" );
36
    layoutSet.addColor( OVERFLOW_COLOR, Graphics.getColor( 0, 81, 148 ) );
38
    layoutSet.addColor( OVERFLOW_COLOR, Graphics.getColor( 0, 81, 148 ) );
37
  }
39
  }
38
}
40
}
(-)src/org/eclipse/rap/internal/design/business/layoutsets/StackInitializer.java (+4 lines)
Lines 50-55 Link Here
50
    = "stack.inactive.close.active";
50
    = "stack.inactive.close.active";
51
  public static final String VIEW_TOOLBAR_BG = "stack.viewtoolbar.bg";
51
  public static final String VIEW_TOOLBAR_BG = "stack.viewtoolbar.bg";
52
  public static final String VIEW_TOOLBAR_LAYER = "stack.viewtoolbar.layer";
52
  public static final String VIEW_TOOLBAR_LAYER = "stack.viewtoolbar.layer";
53
  public static final String VIEW_MENU_ICON = "stack.viewmenu.icon";
54
  public static final String VIEW_PULLDOWN = "stack.view.pulldown.arrow";
53
  
55
  
54
56
55
  public void initializeLayoutSet( LayoutSet layoutSet ) {
57
  public void initializeLayoutSet( LayoutSet layoutSet ) {
Lines 94-98 Link Here
94
                            "img/stack_tab_inactive_close_active.png" );
96
                            "img/stack_tab_inactive_close_active.png" );
95
    layoutSet.addImagePath( VIEW_TOOLBAR_BG, "img/viewtoolbar_bg.png" );
97
    layoutSet.addImagePath( VIEW_TOOLBAR_BG, "img/viewtoolbar_bg.png" );
96
    layoutSet.addImagePath( VIEW_TOOLBAR_LAYER, "img/viewToolBarLayer.gif" );
98
    layoutSet.addImagePath( VIEW_TOOLBAR_LAYER, "img/viewToolBarLayer.gif" );
99
    layoutSet.addImagePath( VIEW_MENU_ICON, "img/viewMenu.png" );
100
    layoutSet.addImagePath( VIEW_PULLDOWN, "img/viewPulldown.png" );
97
  }
101
  }
98
}
102
}
(-)src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarOverflowInitializer.java (+2 lines)
Lines 21-26 Link Here
21
  public static final String BG = "coolbar.layer.bg";
21
  public static final String BG = "coolbar.layer.bg";
22
  public static final String RIGHT = "coolbar.layer.right";
22
  public static final String RIGHT = "coolbar.layer.right";
23
  public static final String WAVE = "coolbar.layer.wave";
23
  public static final String WAVE = "coolbar.layer.wave";
24
  public static final String ARROW = "coolbar.layer.arrow";
24
25
25
  public CoolbarOverflowInitializer() {
26
  public CoolbarOverflowInitializer() {
26
  }
27
  }
Lines 29-33 Link Here
29
    layoutSet.addImagePath( BG, "img/toolbar_overflow_layer_bg.png" );
30
    layoutSet.addImagePath( BG, "img/toolbar_overflow_layer_bg.png" );
30
    layoutSet.addImagePath( RIGHT, "img/toolbar_overflow_layer_right.png" );
31
    layoutSet.addImagePath( RIGHT, "img/toolbar_overflow_layer_right.png" );
31
    layoutSet.addImagePath( WAVE, "img/header_wave_layer.png" );
32
    layoutSet.addImagePath( WAVE, "img/header_wave_layer.png" );
33
    layoutSet.addImagePath( ARROW, "img/toolbar_overflow_arrow.png" );
32
  }
34
  }
33
}
35
}
(-)src/org/eclipse/rap/internal/design/business/managers/BusinessCoolBarManager.java (-98 / +317 lines)
Lines 9-22 Link Here
9
*******************************************************************************/ 
9
*******************************************************************************/ 
10
package org.eclipse.rap.internal.design.business.managers;
10
package org.eclipse.rap.internal.design.business.managers;
11
11
12
import java.util.*;
12
import java.util.ArrayList;
13
import java.util.HashMap;
13
import java.util.List;
14
import java.util.List;
15
import java.util.Map;
14
16
17
import org.eclipse.core.commands.Command;
18
import org.eclipse.core.commands.ExecutionEvent;
19
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.runtime.Assert;
20
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.jface.action.*;
21
import org.eclipse.jface.action.Action;
22
import org.eclipse.jface.action.ActionContributionItem;
23
import org.eclipse.jface.action.ContributionItem;
24
import org.eclipse.jface.action.ContributionManager;
25
import org.eclipse.jface.action.IAction;
26
import org.eclipse.jface.action.IContributionItem;
27
import org.eclipse.jface.action.IContributionManagerOverrides;
28
import org.eclipse.jface.action.IMenuManager;
29
import org.eclipse.jface.action.IToolBarManager;
30
import org.eclipse.jface.action.ToolBarContributionItem;
17
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
31
import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
18
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
32
import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
19
import org.eclipse.jface.resource.ImageDescriptor;
33
import org.eclipse.jface.resource.ImageDescriptor;
34
import org.eclipse.rap.internal.design.business.CommandUtil;
35
import org.eclipse.rap.internal.design.business.CommandUtil.CommandParameter;
20
import org.eclipse.rap.internal.design.business.builder.CoolbarLayerBuilder;
36
import org.eclipse.rap.internal.design.business.builder.CoolbarLayerBuilder;
21
import org.eclipse.rap.internal.design.business.builder.DummyBuilder;
37
import org.eclipse.rap.internal.design.business.builder.DummyBuilder;
22
import org.eclipse.rap.internal.design.business.layoutsets.CoolbarInitializer;
38
import org.eclipse.rap.internal.design.business.layoutsets.CoolbarInitializer;
Lines 24-34 Link Here
24
import org.eclipse.rap.ui.interactiondesign.layout.ElementBuilder;
40
import org.eclipse.rap.ui.interactiondesign.layout.ElementBuilder;
25
import org.eclipse.rwt.lifecycle.WidgetUtil;
41
import org.eclipse.rwt.lifecycle.WidgetUtil;
26
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.events.*;
43
import org.eclipse.swt.events.ControlAdapter;
44
import org.eclipse.swt.events.ControlEvent;
45
import org.eclipse.swt.events.DisposeEvent;
46
import org.eclipse.swt.events.DisposeListener;
47
import org.eclipse.swt.events.FocusAdapter;
48
import org.eclipse.swt.events.FocusEvent;
49
import org.eclipse.swt.events.FocusListener;
50
import org.eclipse.swt.events.MouseAdapter;
51
import org.eclipse.swt.events.MouseEvent;
52
import org.eclipse.swt.events.SelectionAdapter;
53
import org.eclipse.swt.events.SelectionEvent;
28
import org.eclipse.swt.graphics.Color;
54
import org.eclipse.swt.graphics.Color;
29
import org.eclipse.swt.graphics.Image;
55
import org.eclipse.swt.graphics.Image;
30
import org.eclipse.swt.layout.*;
56
import org.eclipse.swt.graphics.Point;
31
import org.eclipse.swt.widgets.*;
57
import org.eclipse.swt.graphics.Rectangle;
58
import org.eclipse.swt.layout.FormAttachment;
59
import org.eclipse.swt.layout.FormData;
60
import org.eclipse.swt.layout.RowLayout;
61
import org.eclipse.swt.widgets.Button;
62
import org.eclipse.swt.widgets.Composite;
63
import org.eclipse.swt.widgets.Control;
64
import org.eclipse.swt.widgets.Display;
65
import org.eclipse.swt.widgets.Event;
66
import org.eclipse.swt.widgets.Item;
67
import org.eclipse.swt.widgets.Listener;
68
import org.eclipse.swt.widgets.Menu;
69
import org.eclipse.swt.widgets.MenuItem;
70
import org.eclipse.swt.widgets.Table;
71
import org.eclipse.swt.widgets.TableColumn;
72
import org.eclipse.swt.widgets.TableItem;
73
import org.eclipse.ui.internal.WWinPluginPulldown;
32
import org.eclipse.ui.menus.CommandContributionItem;
74
import org.eclipse.ui.menus.CommandContributionItem;
33
75
34
76
Lines 53-58 Link Here
53
  private Table overflowTable;
95
  private Table overflowTable;
54
  private int indexOfIcon;
96
  private int indexOfIcon;
55
  private int indexOfText;
97
  private int indexOfText;
98
  private int indexOfPulldown;
99
  private Map commandParamMap = new HashMap();
100
  private Menu openMenu;
101
  
56
  private FocusListener focusListener = new FocusAdapter() {
102
  private FocusListener focusListener = new FocusAdapter() {
57
    public void focusLost( FocusEvent event ) {
103
    public void focusLost( FocusEvent event ) {
58
      // close the overflow if the table focus is lost
104
      // close the overflow if the table focus is lost
Lines 60-65 Link Here
60
      toggleImages();
106
      toggleImages();
61
    }
107
    }
62
  };
108
  };
109
  
110
 
111
  
63
   
112
   
64
  
113
  
65
  public BusinessCoolBarManager() {
114
  public BusinessCoolBarManager() {
Lines 80-85 Link Here
80
    coolBar.addControlListener( new ControlAdapter() {
129
    coolBar.addControlListener( new ControlAdapter() {
81
      public void controlResized( final ControlEvent e ) {
130
      public void controlResized( final ControlEvent e ) {
82
        // close the overflow and update the coolbar if the browser has resized
131
        // close the overflow and update the coolbar if the browser has resized
132
        if( openMenu != null ) {
133
          // TODO: Sometimes the menu don't close when the control is resized
134
          openMenu.setVisible( false );
135
        }
83
        closeOverflow();
136
        closeOverflow();
84
        update( true );
137
        update( true );
85
      }
138
      }
Lines 221-227 Link Here
221
    if( coolBar != null ) {
274
    if( coolBar != null ) {
222
      Control[] children = coolBar.getChildren();
275
      Control[] children = coolBar.getChildren();
223
      for( int i = 0; i < children.length; i++ ) {
276
      for( int i = 0; i < children.length; i++ ) {
224
        if( children[ i ] instanceof Button && !children[ i ].isDisposed() ) {
277
        if( !children[ i ].isDisposed() ) {
225
          children[ i ].dispose();
278
          children[ i ].dispose();
226
        }
279
        }
227
      }
280
      }
Lines 264-270 Link Here
264
        }      
317
        }      
265
        
318
        
266
      }
319
      }
267
      coolBar.pack( true );
320
      coolBar.pack();
268
      coolBar.layout( true ); 
321
      coolBar.layout( true ); 
269
      manageOverflow( );
322
      manageOverflow( );
270
    }
323
    }
Lines 283-297 Link Here
283
      // remove last children (button)
336
      // remove last children (button)
284
      int lastIndex = coolBar.getChildren().length - 1;
337
      int lastIndex = coolBar.getChildren().length - 1;
285
      Control child = coolBar.getChildren()[ lastIndex ];
338
      Control child = coolBar.getChildren()[ lastIndex ];
286
      if( child instanceof Button ) {
339
      Object object = buttonItemMap.get( child );
287
        Object object = buttonItemMap.get( child );
340
      ContributionItem item = ( ContributionItem ) object;
288
        ContributionItem item = ( ContributionItem ) object;
341
      addOverflowItem( item );
289
        addOverflowItem( item );
342
      activeOverflowOpenButton();
290
        activeOverflowOpenButton();
343
      buttonItemMap.remove( child );
291
        buttonItemMap.remove( child );
344
      child.dispose();
292
        child.dispose();
345
      child = null;       
293
        child = null; 
294
      }
295
    }
346
    }
296
347
297
    // check if the overflow button should be activated or not
348
    // check if the overflow button should be activated or not
Lines 335-341 Link Here
335
    int result = 0;
386
    int result = 0;
336
    Control[] children = comp.getChildren();
387
    Control[] children = comp.getChildren();
337
    for( int i = 0; i < children.length; i++ ) {
388
    for( int i = 0; i < children.length; i++ ) {
338
      if( children[ i ] instanceof Button && !children[ i ].isDisposed() ) {
389
      if( !children[ i ].isDisposed() ) {
339
        result += ( children[ i ].getSize().x + SPACING );
390
        result += ( children[ i ].getSize().x + SPACING );
340
      }
391
      }
341
    }
392
    }
Lines 424-462 Link Here
424
      iconColumn.setResizable( false );
475
      iconColumn.setResizable( false );
425
      iconColumn.setMoveable( false );
476
      iconColumn.setMoveable( false );
426
      TableColumn textColumn = new TableColumn( overflowTable, SWT.NONE );
477
      TableColumn textColumn = new TableColumn( overflowTable, SWT.NONE );
478
      TableColumn pulldownColumn = new TableColumn( overflowTable, SWT.NONE );
479
      pulldownColumn.setResizable( false );
480
      pulldownColumn.setMoveable( false );
427
      indexOfIcon = overflowTable.indexOf( iconColumn );
481
      indexOfIcon = overflowTable.indexOf( iconColumn );
428
      indexOfText = overflowTable.indexOf( textColumn );
482
      indexOfText = overflowTable.indexOf( textColumn );
483
      indexOfPulldown = overflowTable.indexOf( pulldownColumn );
429
      overflowTable.addFocusListener( focusListener );
484
      overflowTable.addFocusListener( focusListener );
430
    }
485
    }
431
    overflowTable.clearAll();
486
    emptyOverflowTable();
432
    overflowTable.removeAll();
487
    overflowTable.setVisible( true );
433
    
488
    
434
    // add selection support
489
    // add selection support
435
    final Map itemMap = new HashMap();
490
    final Map itemMap = new HashMap();
436
    overflowTable.addSelectionListener( new SelectionAdapter() {
491
    final Map actionMap = new HashMap();
437
      public void widgetSelected(SelectionEvent e) { 
492
    overflowTable.addMouseListener( new MouseAdapter() {
438
        TableItem[] selection = overflowTable.getSelection();
493
      public void mouseDown( MouseEvent e ) {        
494
        TableItem[] selection = overflowTable.getSelection();        
439
        for( int i = 0; i < selection.length; i++ ) {
495
        for( int i = 0; i < selection.length; i++ ) {
496
          
440
          TableItem item = selection[ i ];
497
          TableItem item = selection[ i ];
498
          Rectangle bounds = item.getBounds( indexOfPulldown );
441
          Object object = itemMap.get( item );
499
          Object object = itemMap.get( item );
500
          Action action = null;
442
          if( object != null ) {
501
          if( object != null ) {
443
            if( object instanceof Action ) {
502
            if( object instanceof Action ) {
444
              // action
503
              // action
445
              Action action = ( Action ) object;
504
              action = ( Action ) object;                             
446
              toggleImages();
447
              action.run();              
448
            } 
505
            } 
449
          }
506
          }
507
          if( e.x < bounds.x && action != null ) {
508
            // action clicked
509
            closeOverflow();              
510
            action.run(); 
511
          } else {
512
            // pulldown clicked
513
            final Menu pulldownMenu 
514
              = getPulldownMenu( action, overflowTable, actionMap );
515
            if( pulldownMenu != null ) {      
516
              Display display = overflowTable.getDisplay();
517
              Point newLoc = display.map( overflowTable, 
518
                                          null, 
519
                                          bounds.x + 20, 
520
                                          bounds.y );
521
              pulldownMenu.setLocation( newLoc );
522
              pulldownMenu.setVisible( true );
523
              openMenu = pulldownMenu;
524
              pulldownMenu.addListener( SWT.Hide, new Listener() {              
525
                public void handleEvent( final Event event ) {
526
                  closeOverflow();
527
                  pulldownMenu.removeListener( SWT.Hide, this );
528
                }
529
              } );
530
            }
531
          }
450
        }
532
        }
451
      }
533
      }
452
      
453
    } );
534
    } );
454
    
535
    
455
    // fill the table
536
    // fill the table
456
    clearCommandItems();
537
    clearCommandItems();
538
    String key = CoolbarOverflowInitializer.ARROW;
539
    ElementBuilder dummy 
540
      = new DummyBuilder( null, CoolbarOverflowInitializer.SET_ID );
541
    Image arrowIcon = dummy.getImage( key );
457
    for( int i = 0; i < overflowItems.size(); i++ ) {
542
    for( int i = 0; i < overflowItems.size(); i++ ) {
458
      ContributionItem contrib = ( ContributionItem ) overflowItems.get( i );
543
      ContributionItem contrib = ( ContributionItem ) overflowItems.get( i );
459
      if( !buttonItemMap.containsValue( contrib ) ) {
544
      if( !buttonItemMap.containsValue( contrib ) ) {        
460
        TableItem tableItem = new TableItem( overflowTable, SWT.NONE );  
545
        TableItem tableItem = new TableItem( overflowTable, SWT.NONE );  
461
        Action action = null;
546
        Action action = null;
462
        if( contrib instanceof ActionContributionItem ) {
547
        if( contrib instanceof ActionContributionItem ) {
Lines 467-497 Link Here
467
        } else if( contrib instanceof CommandContributionItem ) {
552
        } else if( contrib instanceof CommandContributionItem ) {
468
          // comand
553
          // comand
469
          CommandContributionItem item = ( CommandContributionItem ) contrib;
554
          CommandContributionItem item = ( CommandContributionItem ) contrib;
470
          action = wrapCommand( item, tableItem );
555
          action = CommandUtil.wrapCommand( item, coolBar );
556
          actionMap.put( action, item );
471
        }
557
        }
558
        // icon column
472
        itemMap.put( tableItem, action );
559
        itemMap.put( tableItem, action );
473
        ImageDescriptor imageDescriptor = action.getImageDescriptor();
560
        ImageDescriptor imageDescriptor = action.getImageDescriptor();
474
        if( imageDescriptor != null ) {
561
        if( imageDescriptor != null ) {
475
          tableItem.setImage( indexOfIcon, imageDescriptor.createImage() );
562
          Image icon = imageDescriptor.createImage();
563
          tableItem.setImage( indexOfIcon, icon );          
476
        }
564
        }
565
        // text column
477
        setTableItemStyle( tableItem );
566
        setTableItemStyle( tableItem );
478
        String text = action.getText();
567
        String text = action.getText();
479
        // reomve the & because there is no shortkey suppor tin the coolbar
568
        // reomve the & because there is no shortkey suppor tin the coolbar
480
        tableItem.setText( indexOfText, text.replaceAll( "&", "" ) );
569
        tableItem.setText( indexOfText, text.replaceAll( "&", "" ) );
481
        tableItem.setData( WidgetUtil.CUSTOM_VARIANT, "overflow" );
570
        tableItem.setData( WidgetUtil.CUSTOM_VARIANT, "overflow" );
571
        // pulldown
572
        if( action.getStyle() == IAction.AS_DROP_DOWN_MENU ) {
573
          tableItem.setImage( indexOfPulldown, arrowIcon );  
574
        }
482
      }
575
      }
483
    }
576
    }
484
577
485
    // pack and set focus for the focuslistener
578
    // pack and set focus for the focuslistener     
486
    overflowTable.getColumn( indexOfIcon ).pack();
579
    overflowTable.getColumn( indexOfIcon ).pack();
487
    overflowTable.getColumn( indexOfText ).pack();
580
    overflowTable.getColumn( indexOfText ).pack();
581
    overflowTable.getColumn( indexOfPulldown ).pack();
582
    overflowTable.pack();   
583
    overflowLayer.layout( true, true );
488
    overflowTable.setFocus();
584
    overflowTable.setFocus();
489
  }
585
  }
490
586
587
  private Menu getPulldownMenu( 
588
    final Action action, 
589
    final Control parent, 
590
    final Map actionMap ) 
591
  {
592
    Menu result = null;
593
    if( action instanceof WWinPluginPulldown ) {
594
      WWinPluginPulldown pulldown = ( WWinPluginPulldown ) action;
595
      result = pulldown.getMenuCreator().getMenu( parent );
596
    } else if( actionMap != null ) {
597
      Object object = actionMap.get( action );
598
      if( object != null && object instanceof CommandContributionItem ) {
599
        CommandContributionItem item = ( CommandContributionItem ) object;
600
        CommandParameter param = extractCommandInformation( item );
601
        result = param.getMenu();
602
      }
603
    }
604
    return result;
605
  }
606
607
  private void emptyOverflowTable() {
608
    TableItem[] items = overflowTable.getItems();
609
    for( int i = 0; i < items.length; i++ ) {
610
      items[ i ].dispose();
611
    }
612
    overflowTable.clearAll();
613
    overflowTable.removeAll();
614
  }
615
491
  private void clearCommandItems() {
616
  private void clearCommandItems() {
492
    for( int i = 0; i < commanItems.size(); i++ ) {
617
    for( int i = 0; i < commanItems.size(); i++ ) {
493
      MenuItem item = ( MenuItem ) commanItems.get( i );
618
      MenuItem item = ( MenuItem ) commanItems.get( i );
494
      destroyMenuItem( item );
619
      destroyItem( item );
495
    }
620
    }
496
  }
621
  }
497
622
Lines 528-608 Link Here
528
        overflowLayer.getParent().setVisible( false );
653
        overflowLayer.getParent().setVisible( false );
529
        overflowParent.setBackgroundImage( preservedWave );
654
        overflowParent.setBackgroundImage( preservedWave );
530
        overflowOpenButton.setData( WidgetUtil.CUSTOM_VARIANT, INACTIVE );
655
        overflowOpenButton.setData( WidgetUtil.CUSTOM_VARIANT, INACTIVE );
531
        overflowItems.clear();
656
        overflowItems.clear();        
532
        clearCommandItems();
657
        clearCommandItems();
533
      }
658
      }
534
    }
659
    }
535
  }
660
  }
536
661
537
  private void addCommandToCoolBar( final CommandContributionItem command ) {
662
  private void addCommandToCoolBar( final CommandContributionItem item ) {
538
    final Menu menu = new Menu( coolBar );
663
    CommandParameter param = extractCommandInformation( item );    
539
    menu.setVisible( false );
664
    if( param.getStyle() == CommandContributionItem.STYLE_PULLDOWN ) {
540
    command.fill( menu, 0 );
665
      // pull down button
541
    MenuItem[] menuItems = menu.getItems();
666
      createPullDownButton( item, 
542
    for( int j = 0; j < menuItems.length; j++ ) {
667
                            CommandUtil.wrapCommand( item, coolBar ), 
543
      final MenuItem item = menuItems[ j ];
668
                            param.getStyle() );
544
      final Button button = new Button( coolBar, item.getStyle() );
669
    } else {
545
      button.setImage( item.getImage() );
670
      final Button button = new Button( coolBar, param.getStyle() );
546
      adjustButtonBounds( button );
671
      Command command = param.getCommand();
547
      button.setToolTipText( item.getText() );
672
      button.setData( command );
548
      button.setData( WidgetUtil.CUSTOM_VARIANT, "coolBar" );
673
      button.setText( param.getText() );
549
      button.setText( item.getText() );     
674
      button.setToolTipText( param.getTooltipText() );
675
      button.setData( WidgetUtil.CUSTOM_VARIANT, "coolBar" );        
676
      button.setImage( param.getIcon() );
550
      button.addSelectionListener( new SelectionAdapter() {
677
      button.addSelectionListener( new SelectionAdapter() {
551
        public void widgetSelected( SelectionEvent e ) {          
678
        public void widgetSelected( final SelectionEvent e ) {
552
          Event ev = new Event();
679
          try {
553
          ev.widget = ( Button ) e.getSource();
680
            Command buttonCommand = ( Command ) button.getData();
554
          item.notifyListeners( SWT.Selection, ev );
681
            buttonCommand.getHandler().execute( new ExecutionEvent() );
682
          } catch( ExecutionException e1 ) {
683
            e1.printStackTrace();
684
          }
555
        };
685
        };
556
      } );
686
      } );
557
      button.addDisposeListener( new DisposeListener() {      
687
      button.addDisposeListener( new DisposeListener() {      
558
        public void widgetDisposed( DisposeEvent event ) {
688
        public void widgetDisposed( DisposeEvent event ) {
559
          destroyMenuItem( item );
560
          buttonItemMap.remove( button );
689
          buttonItemMap.remove( button );
561
        }
690
        }
562
      } );
691
      } );
563
      buttonItemMap.put( button, command );
692
      buttonItemMap.put( button, item );
564
    }
693
    }          
565
  }
694
  }  
566
  
695
  
567
  /*
696
  private CommandParameter extractCommandInformation( 
568
   * Wraps a command contrib item to an action
697
    final CommandContributionItem item ) 
569
   */
570
  private Action wrapCommand( 
571
    final CommandContributionItem item, 
572
    final TableItem tableItem ) 
573
  {
698
  {
574
    Action result = null;
699
    CommandParameter result = null;
575
    final Menu menu = new Menu( coolBar );
700
    Object object = commandParamMap.get( item );
576
    menu.setVisible( false );
701
    if( object == null ) {
577
    item.fill( menu, 0 );
702
      result = CommandUtil.extractCommandInformation( item, coolBar );
578
    MenuItem[] menuItems = menu.getItems();
703
      commandParamMap.put( item, result );
579
    for( int j = 0; j < menuItems.length; j++ ) {
704
    } else {
580
      final MenuItem menuItem = menuItems[ j ];
705
      result = ( CommandParameter ) object;
581
      result = new Action() {
582
        public void run() {
583
          Event ev = new Event();
584
          ev.widget = tableItem.getParent();
585
          menuItem.notifyListeners( SWT.Selection, ev );
586
          destroyMenuItem( menuItem );
587
          commanItems.remove( menuItem );
588
        }
589
      };
590
      ImageDescriptor desc = new ImageDescriptor() {
591
        public Image createImage() {
592
          return menuItem.getImage();
593
        }      
594
      };
595
      commanItems.add( menuItem );
596
      result.setImageDescriptor( desc );
597
      result.setText( menuItem.getText() );
598
      result.setToolTipText( menuItem.getText() );  
599
    }
706
    }
600
    return result;
707
    return result;
601
  }
708
  }
709
710
602
  
711
  
603
  private void destroyMenuItem( final MenuItem item ) {
712
  private void destroyItem( Item item ) {
604
    item.dispose();
713
    item.dispose();
605
    //item = null;
714
    item = null;
606
  }
715
  }
607
  
716
  
608
  /*
717
  /*
Lines 616-643 Link Here
616
725
617
  private void addActionToCoolBar( final ActionContributionItem item ) {
726
  private void addActionToCoolBar( final ActionContributionItem item ) {
618
    final IAction action = item.getAction();
727
    final IAction action = item.getAction();
619
    final Button button = new Button( coolBar, action.getStyle() );
728
    int actionStyle = action.getStyle();
729
    int style = getButtonStyle( actionStyle );       
730
        
731
    if( action.getStyle() == IAction.AS_DROP_DOWN_MENU ) {
732
      // drop down button
733
      if( action instanceof WWinPluginPulldown ) {
734
        createPullDownButton( item, action, style );
735
      } else {
736
        throw new IllegalArgumentException( action.getId() + " does not " +
737
                "implement IWorkbenchWindowPulldownDelegate" );
738
      }
739
    } else {
740
      // create normal button
741
      final Button button = createCoolBarButton( coolBar, style, action );
742
      buttonItemMap.put( button, item );
743
      button.addDisposeListener( new DisposeListener() {      
744
        public void widgetDisposed( DisposeEvent event ) {
745
          buttonItemMap.remove( button );
746
        }
747
      } ); 
748
    }  
749
  }
750
751
  private void createPullDownButton( 
752
    final ContributionItem item,
753
    final IAction action,
754
    final int style )
755
  {
756
    final Composite buttonParent = new Composite( coolBar, SWT.NONE );
757
    buttonItemMap.put( buttonParent, item );
758
    RowLayout layout = new RowLayout( SWT.HORIZONTAL );
759
    layout.spacing = 0;
760
    layout.marginBottom = 0;
761
    layout.marginHeight = 0;
762
    layout.marginLeft = 0;
763
    layout.marginRight = 0;
764
    layout.marginTop = 0;
765
    layout.marginWidth = 0;
766
    buttonParent.setLayout( layout );
767
    buttonParent.setData( WidgetUtil.CUSTOM_VARIANT, "compTrans" );
768
    Button button = createCoolBarButton( buttonParent, SWT.PUSH, action );
769
    buttonParent.addDisposeListener( new DisposeListener() {      
770
      public void widgetDisposed( final  DisposeEvent event ) {
771
        buttonItemMap.remove( buttonParent );
772
        clearComposite( buttonParent );
773
      }
774
    } ); 
775
    // create the pulldown arrow
776
    final Button arrow = new Button( buttonParent, SWT.PUSH );   
777
    arrow.setData( WidgetUtil.CUSTOM_VARIANT, "coolBarPulldown" );
778
    arrow.setImage( dummyBuilder.getImage( CoolbarInitializer.ARROW ) );
779
    final Menu menu = getItemMenu( item, action, button );
780
    arrow.setText( " " );
781
    arrow.addSelectionListener( new SelectionAdapter() {
782
      public void widgetSelected( final SelectionEvent e ) {
783
        if( menu != null ) {
784
          menu.setVisible( true );
785
          openMenu = menu;
786
          Display display = arrow.getDisplay();
787
          Point newLoc = display.map( arrow, null, 10, arrow.getSize().y );
788
          menu.setLocation( newLoc );
789
        }
790
      };
791
    } );
792
    buttonParent.layout( true );
793
  }
794
795
  private Menu getItemMenu( 
796
    final ContributionItem item,
797
    final IAction action,
798
    final Button button )
799
  {
800
    Menu menu;
801
    if( item instanceof CommandContributionItem ) {
802
      CommandParameter param 
803
        = extractCommandInformation( ( CommandContributionItem ) item );
804
      menu = param.getMenu();
805
    } else {
806
      menu = getPulldownMenu( ( Action ) action, button, null );
807
    }
808
    return menu;
809
  }
810
811
  private void clearComposite( final Composite comp ) {
812
    Control[] children = comp.getChildren();
813
    for( int i = 0; i < children.length; i++ ) {
814
      children[ i ].dispose();
815
    }    
816
  }
817
818
  private int getButtonStyle( int actionStyle ) {
819
    int style;
820
    switch( actionStyle ) {
821
      case IAction.AS_CHECK_BOX:
822
        style = SWT.CHECK;
823
      break;
824
      case IAction.AS_DROP_DOWN_MENU:
825
        style = SWT.PUSH;
826
      break;
827
      case IAction.AS_RADIO_BUTTON:
828
        style = SWT.RADIO;
829
      break;
830
      default:
831
        style = SWT.PUSH;
832
      break;
833
    }
834
    return style;
835
  }
836
  
837
  private Button createCoolBarButton( 
838
    final Composite parent, 
839
    final int style, 
840
    final IAction action ) 
841
  {
842
    final Button button = new Button( parent, style );
620
    adjustButtonBounds( button );
843
    adjustButtonBounds( button );
621
    button.setText( action.getText() );
844
    button.setText( action.getText() );
622
    button.setToolTipText( action.getToolTipText() );
845
    button.setToolTipText( action.getToolTipText() );
623
    button.setImage( action.getImageDescriptor().createImage() );
846
    if( action.getImageDescriptor() != null ) {
847
      button.setImage( action.getImageDescriptor().createImage() );
848
    }
624
    button.setData( WidgetUtil.CUSTOM_VARIANT, "coolBar" );
849
    button.setData( WidgetUtil.CUSTOM_VARIANT, "coolBar" );
625
    button.addSelectionListener( new SelectionAdapter() {
850
    button.addSelectionListener( new SelectionAdapter() {
626
      public void widgetSelected( SelectionEvent e ) {
851
      public void widgetSelected( SelectionEvent e ) {
627
        try{ 
852
        try{      
628
          action.run();
853
          action.run();          
629
        } catch( Exception ex ) {
854
        } catch( Exception ex ) {
630
          
855
          
631
        }
856
        }
632
      }
857
      }
633
    } );
858
    } );           
634
    button.addDisposeListener( new DisposeListener() {      
859
    return button;
635
      public void widgetDisposed( DisposeEvent event ) {
636
        buttonItemMap.remove( button );
637
      }
638
    } );
639
    buttonItemMap.put( button, item );
640
    
641
  }
860
  }
642
  
861
  
643
  public void setOverflowParent( final Composite overflowParent ) {
862
  public void setOverflowParent( final Composite overflowParent ) {
(-)src/org/eclipse/rap/internal/design/business/managers/BusinessViewToolBarManager.java (-39 / +145 lines)
Lines 9-36 Link Here
9
*******************************************************************************/ 
9
*******************************************************************************/ 
10
package org.eclipse.rap.internal.design.business.managers;
10
package org.eclipse.rap.internal.design.business.managers;
11
11
12
import java.util.ArrayList;
13
import java.util.List;
14
15
import org.eclipse.jface.action.Action;
12
import org.eclipse.jface.action.ActionContributionItem;
16
import org.eclipse.jface.action.ActionContributionItem;
13
import org.eclipse.jface.action.ContributionManager;
17
import org.eclipse.jface.action.ContributionManager;
14
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.action.IContributionItem;
19
import org.eclipse.jface.action.IContributionItem;
20
import org.eclipse.jface.action.IMenuCreator;
16
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
21
import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
17
import org.eclipse.jface.util.IPropertyChangeListener;
22
import org.eclipse.jface.util.IPropertyChangeListener;
23
import org.eclipse.rap.internal.design.business.CommandUtil;
24
import org.eclipse.rap.internal.design.business.CommandUtil.CommandParameter;
25
import org.eclipse.rap.internal.design.business.builder.DummyBuilder;
26
import org.eclipse.rap.internal.design.business.layoutsets.StackInitializer;
27
import org.eclipse.rap.ui.interactiondesign.layout.ElementBuilder;
18
import org.eclipse.rwt.lifecycle.WidgetUtil;
28
import org.eclipse.rwt.lifecycle.WidgetUtil;
19
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.events.DisposeEvent;
31
import org.eclipse.swt.events.DisposeListener;
20
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionAdapter;
21
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.graphics.Image;
35
import org.eclipse.swt.graphics.Point;
36
import org.eclipse.swt.layout.FormAttachment;
37
import org.eclipse.swt.layout.FormData;
38
import org.eclipse.swt.layout.FormLayout;
22
import org.eclipse.swt.layout.RowLayout;
39
import org.eclipse.swt.layout.RowLayout;
23
import org.eclipse.swt.widgets.Button;
40
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
42
import org.eclipse.swt.widgets.Control;
43
import org.eclipse.swt.widgets.Display;
44
import org.eclipse.swt.widgets.Menu;
26
import org.eclipse.swt.widgets.ToolBar;
45
import org.eclipse.swt.widgets.ToolBar;
46
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate;
47
import org.eclipse.ui.internal.WWinPluginPulldown;
48
import org.eclipse.ui.menus.CommandContributionItem;
27
49
28
50
29
public class BusinessViewToolBarManager extends ContributionManager 
51
public class BusinessViewToolBarManager extends ContributionManager 
30
  implements IToolBarManager2 
52
  implements IToolBarManager2 
31
{
53
{
32
54
33
private Composite control;
55
  private Composite control;
56
  private List itemList = new ArrayList();
34
  
57
  
35
  public void addPropertyChangeListener( 
58
  public void addPropertyChangeListener( 
36
    final IPropertyChangeListener listener )  
59
    final IPropertyChangeListener listener )  
Lines 53-60 Link Here
53
    
76
    
54
  }
77
  }
55
78
56
  
57
58
  public ToolBar getControl() {
79
  public ToolBar getControl() {
59
    return null;
80
    return null;
60
  }
81
  }
Lines 67-106 Link Here
67
    return getItems().length;
88
    return getItems().length;
68
  }
89
  }
69
90
70
  private void makeButton( final IContributionItem item ) {
91
  private void makeButton( final Action action, final IContributionItem item ) {
71
92
    if( !itemList.contains( item.getId() ) ) {      
72
    final IAction action = ( ( ActionContributionItem ) item ).getAction();
93
      int flags = SWT.PUSH;
73
    int flags = SWT.PUSH;
94
      switch( action.getStyle() ) {
74
    if( action.getStyle() == IAction.AS_CHECK_BOX ) {
95
        case IAction.AS_CHECK_BOX:
75
      flags = SWT.TOGGLE;
96
          flags = SWT.TOGGLE;
76
    }
97
        break;
77
    if( action.getStyle() == IAction.AS_RADIO_BUTTON ) {
98
        case IAction.AS_DROP_DOWN_MENU:
78
      flags = SWT.RADIO;
99
          flags = SWT.DROP_DOWN;
79
    }
100
        break;
80
    
101
        case IAction.AS_RADIO_BUTTON:
81
    final Button button = new Button( control, flags );
102
          flags = SWT.TOGGLE;
82
    button.setData( item );
103
        break;
83
    button.setToolTipText( action.getToolTipText() );
104
        default:
84
    button.setImage( action.getImageDescriptor().createImage() );
105
          flags = SWT.PUSH;
85
    button.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" );
106
        break;
86
    button.addSelectionListener( new SelectionAdapter() {
107
      }
87
      public void widgetSelected( SelectionEvent e ) {
108
      
88
        // SWT.DROPDOWN not yet supportet
109
      Composite parent = control;
89
        boolean checked = button.getSelection();
110
      Menu menu = null;
90
        int style = button.getStyle();
111
      // pulldown 
91
        if( ( style & ( SWT.TOGGLE | SWT.CHECK ) ) != 0 ) {
112
      if( flags == SWT.DROP_DOWN && item instanceof CommandContributionItem ) {
92
          if( action.getStyle() == IAction.AS_CHECK_BOX ) {
113
        CommandContributionItem commandItem = ( CommandContributionItem ) item;
93
            action.setChecked( checked );
114
        CommandParameter param 
94
          }
115
          = CommandUtil.extractCommandInformation( commandItem, control );
95
        } else if( ( style & SWT.RADIO ) != 0 ) {
116
        if( param.getMenu() != null ) {
96
          if( action.getStyle() == IAction.AS_RADIO_BUTTON ) {
117
          menu = param.getMenu();
97
            action.setChecked( checked );
118
        }
119
      } else if( action instanceof WWinPluginPulldown ) {
120
        WWinPluginPulldown pulldown = ( WWinPluginPulldown ) action;
121
        menu = pulldown.getMenuCreator().getMenu( control );              
122
      } else if( action instanceof IMenuCreator ) {
123
        IMenuCreator creator = ( IMenuCreator ) action;
124
        menu = creator.getMenu( control );        
125
      } else if( action instanceof IWorkbenchWindowPulldownDelegate ) {
126
        System.out.println("pull");
127
      }
128
      if( menu != null ) {
129
        final Composite pulldownParent = getPulldownParent();
130
        parent = pulldownParent;        
131
        flags = SWT.PUSH;
132
      }  
133
      // normal items
134
      final Button button = new Button( parent, flags );    
135
      button.setData( item );
136
      button.setToolTipText( action.getToolTipText() );
137
      button.setImage( action.getImageDescriptor().createImage() );
138
      button.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" );
139
      button.addSelectionListener( new SelectionAdapter() {
140
        public void widgetSelected( final SelectionEvent e ) {
141
          // SWT.DROPDOWN not yet supported
142
          boolean checked = button.getSelection();
143
          int style = button.getStyle();
144
          if( ( style & ( SWT.TOGGLE | SWT.CHECK ) ) != 0 ) {
145
            if( action.getStyle() == IAction.AS_CHECK_BOX ) {
146
              action.setChecked( checked );
147
            }
148
          } else if( ( style & SWT.RADIO ) != 0 ) {
149
            if( action.getStyle() == IAction.AS_RADIO_BUTTON ) {
150
              action.setChecked( checked );
151
            }
98
          }
152
          }
153
          action.run();
154
        }
155
      } );
156
      // pulldown
157
      if( menu != null ) {
158
        FormData fdButton = new FormData();
159
        button.setLayoutData( fdButton );
160
        fdButton.left = new FormAttachment( 0 );
161
        fdButton.top = new FormAttachment( 0 );
162
        final Button arrow = new Button( parent, SWT.PUSH );
163
        FormData fdArrow = new FormData();
164
        arrow.setLayoutData( fdArrow );
165
        fdArrow.left = new FormAttachment( button, 0 );
166
        fdArrow.top = new FormAttachment( 0, 7 );
167
        ElementBuilder builder 
168
          = new DummyBuilder( null, StackInitializer.SET_ID );
169
        Image image = builder.getImage( StackInitializer.VIEW_PULLDOWN );
170
        arrow.setImage( image );
171
        arrow.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" );
172
        arrow.setMenu( menu );
173
        arrow.addSelectionListener( new SelectionAdapter() {
174
          public void widgetSelected( final SelectionEvent e ) {          
175
            Display display = arrow.getDisplay();
176
            Point newLoc = display.map( arrow, null, 0, 10 );
177
            arrow.getMenu().setVisible( true );
178
            arrow.getMenu().setLocation( newLoc );
179
          };
180
        } ); 
181
      }
182
      itemList.add( item.getId() );
183
    }
184
  }
185
186
  private Composite getPulldownParent() {
187
    final Composite pulldownParent = new Composite( control, SWT.NONE );        
188
    pulldownParent.setLayout( new FormLayout() );
189
    pulldownParent.setData( WidgetUtil.CUSTOM_VARIANT, "compTrans" );
190
    
191
    pulldownParent.addDisposeListener( new DisposeListener() {          
192
      public void widgetDisposed( final DisposeEvent event ) {
193
        Control[] children = pulldownParent.getChildren();
194
        for( int i = 0; i < children.length; i++ ) {
195
          Control control = children[ i ];
196
          control.dispose();
99
        }
197
        }
100
        action.run();
101
      }
198
      }
102
    } );
199
    } );
103
    
200
    return pulldownParent;
104
  }
201
  }
105
202
106
  public void removePropertyChangeListener( 
203
  public void removePropertyChangeListener( 
Lines 109-127 Link Here
109
  }
206
  }
110
  
207
  
111
  public void update( final boolean force ) {
208
  public void update( final boolean force ) {
112
    
209
    itemList.clear();
113
    Control[] children = control.getChildren();
210
    Control[] children = control.getChildren();
114
    for( int i = 0; i < children.length; i++ ) {
211
    for( int i = 0; i < children.length; i++ ) {
115
      if( children[ i ] instanceof Button ) {
212
      children[ i ].dispose();
116
        children[ i ].dispose();
117
      }
118
    }
213
    }
119
    
214
    
120
    IContributionItem[] items = getItems();
215
    IContributionItem[] items = getItems();
121
    for( int i = 0; i < items.length; i++ ) {
216
    for( int i = 0; i < items.length; i++ ) {
122
      IContributionItem item = items[ i ];
217
      IContributionItem item = items[ i ];
123
      if( item.isVisible() && ( item instanceof ActionContributionItem ) ) {       
218
      if( item.isVisible() && item instanceof ActionContributionItem ) {
124
        makeButton( item );
219
        // actions
220
        IAction action = ( ( ActionContributionItem ) item ).getAction();
221
        makeButton( ( Action ) action, item );
222
      } else if( item.isVisible() && item instanceof CommandContributionItem ) {
223
        // commands
224
        makeCommandButton( item );
125
      }
225
      }
126
    }  
226
    }  
127
    
227
    
Lines 129-134 Link Here
129
    control.layout( true );
229
    control.layout( true );
130
  }
230
  }
131
231
232
  private void makeCommandButton( final IContributionItem item ) {
233
    CommandContributionItem comamndItem = ( CommandContributionItem ) item;
234
    final Action action = CommandUtil.wrapCommand( comamndItem, control );
235
    makeButton( action, item );
236
  }
237
132
  public void dispose() {
238
  public void dispose() {
133
    if( control != null && !control.isDisposed() ) {
239
    if( control != null && !control.isDisposed() ) {
134
      control.dispose();
240
      control.dispose();
(-)src/org/eclipse/rap/internal/design/business/stacks/ConfigurationDialog.java (-1 / +50 lines)
Lines 43-51 Link Here
43
import org.eclipse.swt.widgets.Label;
43
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Listener;
44
import org.eclipse.swt.widgets.Listener;
45
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.swt.widgets.Shell;
46
import org.eclipse.swt.widgets.ToolBar;
47
import org.eclipse.swt.widgets.ToolItem;
46
import org.eclipse.ui.IWorkbench;
48
import org.eclipse.ui.IWorkbench;
47
import org.eclipse.ui.IWorkbenchWindow;
49
import org.eclipse.ui.IWorkbenchWindow;
48
import org.eclipse.ui.PlatformUI;
50
import org.eclipse.ui.PlatformUI;
51
import org.eclipse.ui.menus.CommandContributionItem;
49
import org.eclipse.ui.presentations.IStackPresentationSite;
52
import org.eclipse.ui.presentations.IStackPresentationSite;
50
53
51
/**
54
/**
Lines 241-246 Link Here
241
          String actionId = items[ i ].getId();
244
          String actionId = items[ i ].getId();
242
          
245
          
243
          if( items[ i ] instanceof ActionContributionItem ) {
246
          if( items[ i ] instanceof ActionContributionItem ) {
247
            // commands
244
            ActionContributionItem item 
248
            ActionContributionItem item 
245
              = ( ActionContributionItem) items[ i ];
249
              = ( ActionContributionItem) items[ i ];
246
            
250
            
Lines 267-273 Link Here
267
            actionButtonMap.put( actionId, check );
271
            actionButtonMap.put( actionId, check );
268
            actionList.add( actionId );
272
            actionList.add( actionId );
269
            
273
            
270
          }          
274
          } else if( items[ i ] instanceof CommandContributionItem ) {
275
            // commands
276
            CommandContributionItem item 
277
              = ( CommandContributionItem ) items[ i ];            
278
            Object[] commandInfo = getCommandInfo( item, container );
279
            if( commandInfo != null ) {
280
              Label imageLabel = new Label( container, SWT.NONE );
281
              imageLabel.setImage( ( Image ) commandInfo[ 0 ] );
282
              Label textLabel = new Label( container, SWT.NONE );
283
              if(    commandInfo[ 1 ] != null
284
                  && !commandInfo[ 1 ].equals( "" ) ) {
285
                textLabel.setText( ( String ) commandInfo[ 1 ] );
286
              } else {
287
                textLabel.setText( ( String  ) commandInfo[ 2 ] );
288
              }
289
              data = new GridData( GridData.FILL_HORIZONTAL );
290
              textLabel.setLayoutData( data );
291
              
292
              Button check = new Button( container, SWT.CHECK );
293
              check.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
294
              boolean selected 
295
                = action.isViewActionVisibile( paneId, item.getId() );
296
              check.setSelection( selected );
297
              actionButtonMap.put( item.getId(), check );
298
              actionList.add( item.getId() );
299
            }
300
          }
271
        }
301
        }
272
      }
302
      }
273
    }    
303
    }    
Lines 364-369 Link Here
364
//    }
394
//    }
365
//  }
395
//  }
366
396
397
  private Object[] getCommandInfo( 
398
    final CommandContributionItem item, 
399
    final Composite container ) 
400
  {
401
    Object[] result = null;
402
    ToolBar toolbar = new ToolBar( container, SWT.NONE );
403
    toolbar.setVisible( false );
404
    item.fill( toolbar, -1 );
405
    ToolItem[] items = toolbar.getItems();
406
    for( int i = 0; i < items.length; i++ ) {
407
      result = new Object[ 3 ];
408
      result[ 0 ] = items[ i ].getImage();
409
      result[ 1 ] = items[ i ].getText();
410
      result[ 2 ] = items[ i ].getToolTipText();
411
    }
412
    toolbar.dispose();
413
    return result;
414
  }
415
367
  public int open() {
416
  public int open() {
368
    int result = super.open();
417
    int result = super.open();
369
    closeListener = new Listener() {
418
    closeListener = new Listener() {
(-)src/org/eclipse/rap/internal/design/business/stacks/ViewStackPresentation.java (-10 / +43 lines)
Lines 50-55 Link Here
50
import org.eclipse.ui.PlatformUI;
50
import org.eclipse.ui.PlatformUI;
51
import org.eclipse.ui.internal.PartPane;
51
import org.eclipse.ui.internal.PartPane;
52
import org.eclipse.ui.internal.presentations.PresentablePart;
52
import org.eclipse.ui.internal.presentations.PresentablePart;
53
import org.eclipse.ui.presentations.IPartMenu;
53
import org.eclipse.ui.presentations.IPresentablePart;
54
import org.eclipse.ui.presentations.IPresentablePart;
54
55
55
56
Lines 72-77 Link Here
72
  private Shell toolBarLayer;
73
  private Shell toolBarLayer;
73
  private int state;
74
  private int state;
74
  protected boolean deactivated;
75
  protected boolean deactivated;
76
  private Button viewMenuButton;
75
77
76
  public ViewStackPresentation() {
78
  public ViewStackPresentation() {
77
    state = AS_INACTIVE;
79
    state = AS_INACTIVE;
Lines 101-106 Link Here
101
  private void createToolBarBg() {
103
  private void createToolBarBg() {
102
    Composite tabBar = getTabBar();
104
    Composite tabBar = getTabBar();
103
    toolbarBg = new Composite( tabBar.getParent(), SWT.NONE );
105
    toolbarBg = new Composite( tabBar.getParent(), SWT.NONE );
106
    toolbarBg.setLayout( new FormLayout() );
104
    Image bg = stackBuilder.getImage( StackInitializer.VIEW_TOOLBAR_BG );
107
    Image bg = stackBuilder.getImage( StackInitializer.VIEW_TOOLBAR_BG );
105
    toolbarBg.setBackgroundImage( bg );
108
    toolbarBg.setBackgroundImage( bg );
106
    FormData fdToolBar = new FormData();
109
    FormData fdToolBar = new FormData();
Lines 163-185 Link Here
163
  private void layoutToolBar() {
166
  private void layoutToolBar() {
164
    if( toolbarBg == null && tabBg != null ) {
167
    if( toolbarBg == null && tabBg != null ) {
165
      createToolBarBg();       
168
      createToolBarBg();       
166
    }
169
    }    
167
    
168
    if( currentPart != null ) {      
170
    if( currentPart != null ) {      
169
      Control toolBar = currentPart.getToolBar();
171
      Control toolBar = currentPart.getToolBar();
172
      final IPartMenu viewMenu = currentPart.getMenu();
173
      // viewmenu
174
      if( viewMenu != null ) {
175
        if( viewMenuButton == null ) {
176
          viewMenuButton = new Button( toolbarBg, SWT.PUSH );
177
          viewMenuButton.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" );
178
          Image icon = stackBuilder.getImage( StackInitializer.VIEW_MENU_ICON );
179
          viewMenuButton.setImage( icon );
180
          FormData fdViewMenuButton = new FormData();
181
          viewMenuButton.setLayoutData( fdViewMenuButton );
182
          fdViewMenuButton.right = new FormAttachment( 100, -3 );
183
          fdViewMenuButton.top = new FormAttachment( 0, 7 );
184
          viewMenuButton.addSelectionListener( new SelectionAdapter() {
185
            public void widgetSelected( final SelectionEvent e ) {
186
              Display display = viewMenuButton.getDisplay();
187
              int height = viewMenuButton.getSize().y;
188
              Point newLoc = display.map( viewMenuButton, null, 0, height );
189
              viewMenu.showMenu( newLoc );
190
            };
191
          } );
192
        }
193
      } else if( viewMenuButton != null ) {
194
        viewMenuButton.setVisible( false );
195
        viewMenuButton.dispose();
196
        viewMenuButton = null;
197
      }
198
      // toolbar
199
      Point size = toolbarBg.getSize();
170
      if( toolBar != null ) {
200
      if( toolBar != null ) {
171
        // Toolbar
201
        Point point = currentPart.getControl().getLocation();        
172
        Point point = currentPart.getControl().getLocation();
173
        Point size = toolbarBg.getSize();
174
        point.y -= ( size.y + 2 );
202
        point.y -= ( size.y + 2 );
175
        point.x += ( size.x - toolBar.getSize().x );
203
        point.x += ( size.x - toolBar.getSize().x );
204
        if( viewMenu != null ) {
205
          point.x -= 20;
206
        }
176
        toolBar.setLocation( point );
207
        toolBar.setLocation( point );
177
        
208
        
178
        toolBar.setVisible( true );
209
        toolBar.setVisible( true );
179
        toolbarBg.setVisible( true );
180
        toolbarBg.moveBelow( toolBar );
181
        presentationControl.moveBelow( toolBar );              
182
        
210
        
211
        toolbarBg.moveBelow( toolBar );
212
        presentationControl.moveBelow( toolBar );                   
213
      } 
214
      // toolbarbg and layer
215
      if( toolBar != null || viewMenu != null ) {
216
        toolbarBg.setVisible( true );
183
        // Toolbar Layer
217
        // Toolbar Layer
184
        if( !deactivated ) {          
218
        if( !deactivated ) {          
185
          getToolBarLayer();
219
          getToolBarLayer();
Lines 193-203 Link Here
193
                                    size.y - 1 
227
                                    size.y - 1 
194
                                  );
228
                                  );
195
            toolBarLayer.setVisible( true );
229
            toolBarLayer.setVisible( true );
196
            toolBarLayer.moveAbove( toolBar );
197
          }
230
          }
198
        }
231
        }
199
      } else {
232
      } else {
200
        toolbarBg.setVisible( false );        
233
        toolbarBg.setVisible( false );
201
      }
234
      }
202
      toolbarBg.layout( true );
235
      toolbarBg.layout( true );
203
    }
236
    }
(-)src/org/eclipse/rap/internal/design/business/CommandUtil.java (+184 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
10
package org.eclipse.rap.internal.design.business;
11
12
import org.eclipse.core.commands.Command;
13
import org.eclipse.core.commands.CommandManager;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.jface.action.Action;
17
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.action.MenuManager;
19
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Menu;
24
import org.eclipse.swt.widgets.ToolBar;
25
import org.eclipse.swt.widgets.ToolItem;
26
import org.eclipse.ui.IWorkbench;
27
import org.eclipse.ui.IWorkbenchWindow;
28
import org.eclipse.ui.PlatformUI;
29
import org.eclipse.ui.commands.ICommandService;
30
import org.eclipse.ui.menus.CommandContributionItem;
31
import org.eclipse.ui.menus.IMenuService;
32
33
34
public class CommandUtil {
35
  
36
  public static class CommandParameter {    
37
    private Menu menu;
38
    private int style;
39
    private Image icon;
40
    private String id;
41
    private Command command;
42
    private String text;
43
    private String tooltipText;
44
45
    public CommandParameter( 
46
      final Command command, 
47
      final String id, 
48
      final Image icon, 
49
      final int style, 
50
      final Menu menu,
51
      final String text,
52
      final String tooltipText ) 
53
    {
54
      this.command = command;
55
      this.id = id;
56
      this.icon = icon;
57
      this.style = style;
58
      this.menu = menu;
59
      this.text = text;
60
      this.tooltipText = tooltipText;
61
    }
62
    
63
    public Command getCommand() {
64
      return command;
65
    }
66
    
67
    public Menu getMenu() {
68
      return menu;
69
    }
70
    
71
    public int getStyle() {
72
      return style;
73
    }
74
    
75
    public Image getIcon() {
76
      return icon;
77
    }
78
    
79
    public String getText() {
80
      return text;
81
    }
82
83
    public String getTooltipText() {
84
      return tooltipText;
85
    }
86
  }
87
  
88
  /*
89
   * Wraps a command contrib item to an action
90
   */
91
  public static Action wrapCommand( 
92
    final CommandContributionItem item, 
93
    final Composite parent ) 
94
  {
95
    Action result = null;    
96
    final CommandParameter param = extractCommandInformation( item, parent );    
97
    String text = param.getTooltipText();
98
    String toolTipText = param.getTooltipText();
99
    int style = IAction.AS_PUSH_BUTTON;
100
    if( param.getStyle() == CommandContributionItem.STYLE_PULLDOWN ) {
101
      style = IAction.AS_DROP_DOWN_MENU;
102
    } else if( param.getStyle() == CommandContributionItem.STYLE_CHECK ) {
103
      style = IAction.AS_CHECK_BOX;
104
    } else if( param.getStyle() == CommandContributionItem.STYLE_RADIO ) {
105
      style = IAction.AS_RADIO_BUTTON;
106
    }
107
    result = new Action( text, style ){
108
      public void run() {
109
        Command command = param.getCommand();
110
        if( command != null ) {
111
          try {
112
            command.getHandler().execute( new ExecutionEvent() );
113
          } catch( final ExecutionException e ) {
114
            e.printStackTrace();
115
          }
116
        }
117
      }
118
    };
119
    ImageDescriptor desc = new ImageDescriptor() {
120
      public Image createImage() {
121
        return param.getIcon();
122
      }      
123
    };
124
    result.setImageDescriptor( desc );
125
    result.setToolTipText( toolTipText );    
126
    return result;
127
  }
128
  
129
  public static CommandParameter extractCommandInformation( 
130
    final CommandContributionItem item, 
131
    final Composite parent ) 
132
  {
133
    // extract command
134
    CommandParameter result = null;
135
    CommandManager manager = new CommandManager();
136
    Command command = manager.getCommand( item.getId() );
137
    IWorkbench workbench = PlatformUI.getWorkbench();
138
    IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow();
139
    Object service = activeWindow.getService( ICommandService.class );     
140
    if( !command.isDefined() ) {
141
      if( service != null && service instanceof ICommandService ) {
142
        ICommandService commandService = ( ICommandService ) service;        
143
        command = commandService.getCommand( item.getId() );
144
      }
145
    }
146
    // extract image
147
    Image icon = null;
148
    String text = "";
149
    String tooltipText = "";
150
    int style = CommandContributionItem.STYLE_PUSH;
151
    ToolBar toolbar = new ToolBar( parent, SWT.NONE );
152
    toolbar.setVisible( false );
153
    item.fill( toolbar, -1 );
154
    ToolItem[] toolItems = toolbar.getItems();
155
    for( int i = 0; i < toolItems.length; i++ ) {
156
      ToolItem toolItem = toolItems[ i ];
157
      style = toolItem.getStyle();
158
      icon = toolItem.getImage();
159
      text = toolItem.getToolTipText();
160
      tooltipText = toolItem.getToolTipText();
161
    }
162
    // extract menu
163
    Menu menu = null;
164
    if( style == CommandContributionItem.STYLE_PULLDOWN ) {
165
      final MenuManager menuManager = new MenuManager();      
166
      Object abstractService = activeWindow.getService( IMenuService.class );
167
      IMenuService menuService = ( IMenuService ) abstractService;
168
      String identifier = "menu:" + item.getId();
169
      menuService.populateContributionManager( menuManager, identifier );
170
      menu = menuManager.createContextMenu( parent );
171
    }
172
    result = new CommandParameter( 
173
                                 command, 
174
                                 item.getId(), 
175
                                 icon, 
176
                                 style, 
177
                                 menu, 
178
                                 text,
179
                                 tooltipText );
180
    
181
    toolbar.dispose();
182
    return result;
183
  }
184
}

Return to bug 275648