|
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 ) { |