Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 136788 Details for
Bug 275648
[design] Pulldown Actions/Commands don't work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
pulldownPatch (text/plain), 49.93 KB, created by
Holger Staudacher
on 2009-05-22 06:10:06 EDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Holger Staudacher
Created:
2009-05-22 06:10:06 EDT
Size:
49.93 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.rap.design.business >Index: src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarInitializer.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.design.business/src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarInitializer.java,v >retrieving revision 1.1 >diff -u -r1.1 CoolbarInitializer.java >--- src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarInitializer.java 11 May 2009 13:00:33 -0000 1.1 >+++ src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarInitializer.java 22 May 2009 10:09:56 -0000 >@@ -23,6 +23,7 @@ > public static final String OVERFLOW_ACTIVE = "coolbar.overflow.active"; > public static final String BUTTON_BG = "coolbar.button.bg"; > public static final String OVERFLOW_COLOR = "coolbar.overflow.color"; >+ public static final String ARROW = "coolbar.arrow"; > > public CoolbarInitializer() { > } >@@ -33,6 +34,7 @@ > layoutSet.addImagePath( OVERFLOW_ACTIVE, > "img/toolbar_overflow_hover_active.png" ); > layoutSet.addImagePath( BUTTON_BG, "img/toolbarButtonBg.png" ); >+ layoutSet.addImagePath( ARROW, "img/toolbar_arrow.png" ); > layoutSet.addColor( OVERFLOW_COLOR, Graphics.getColor( 0, 81, 148 ) ); > } > } >Index: src/org/eclipse/rap/internal/design/business/layoutsets/StackInitializer.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.design.business/src/org/eclipse/rap/internal/design/business/layoutsets/StackInitializer.java,v >retrieving revision 1.1 >diff -u -r1.1 StackInitializer.java >--- src/org/eclipse/rap/internal/design/business/layoutsets/StackInitializer.java 21 Apr 2009 17:35:21 -0000 1.1 >+++ src/org/eclipse/rap/internal/design/business/layoutsets/StackInitializer.java 22 May 2009 10:09:56 -0000 >@@ -50,6 +50,8 @@ > = "stack.inactive.close.active"; > public static final String VIEW_TOOLBAR_BG = "stack.viewtoolbar.bg"; > public static final String VIEW_TOOLBAR_LAYER = "stack.viewtoolbar.layer"; >+ public static final String VIEW_MENU_ICON = "stack.viewmenu.icon"; >+ public static final String VIEW_PULLDOWN = "stack.view.pulldown.arrow"; > > > public void initializeLayoutSet( LayoutSet layoutSet ) { >@@ -94,5 +96,7 @@ > "img/stack_tab_inactive_close_active.png" ); > layoutSet.addImagePath( VIEW_TOOLBAR_BG, "img/viewtoolbar_bg.png" ); > layoutSet.addImagePath( VIEW_TOOLBAR_LAYER, "img/viewToolBarLayer.gif" ); >+ layoutSet.addImagePath( VIEW_MENU_ICON, "img/viewMenu.png" ); >+ layoutSet.addImagePath( VIEW_PULLDOWN, "img/viewPulldown.png" ); > } > } >Index: src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarOverflowInitializer.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.design.business/src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarOverflowInitializer.java,v >retrieving revision 1.1 >diff -u -r1.1 CoolbarOverflowInitializer.java >--- src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarOverflowInitializer.java 11 May 2009 13:00:33 -0000 1.1 >+++ src/org/eclipse/rap/internal/design/business/layoutsets/CoolbarOverflowInitializer.java 22 May 2009 10:09:56 -0000 >@@ -21,6 +21,7 @@ > public static final String BG = "coolbar.layer.bg"; > public static final String RIGHT = "coolbar.layer.right"; > public static final String WAVE = "coolbar.layer.wave"; >+ public static final String ARROW = "coolbar.layer.arrow"; > > public CoolbarOverflowInitializer() { > } >@@ -29,5 +30,6 @@ > layoutSet.addImagePath( BG, "img/toolbar_overflow_layer_bg.png" ); > layoutSet.addImagePath( RIGHT, "img/toolbar_overflow_layer_right.png" ); > layoutSet.addImagePath( WAVE, "img/header_wave_layer.png" ); >+ layoutSet.addImagePath( ARROW, "img/toolbar_overflow_arrow.png" ); > } > } >Index: src/org/eclipse/rap/internal/design/business/managers/BusinessCoolBarManager.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.design.business/src/org/eclipse/rap/internal/design/business/managers/BusinessCoolBarManager.java,v >retrieving revision 1.2 >diff -u -r1.2 BusinessCoolBarManager.java >--- src/org/eclipse/rap/internal/design/business/managers/BusinessCoolBarManager.java 11 May 2009 13:00:33 -0000 1.2 >+++ src/org/eclipse/rap/internal/design/business/managers/BusinessCoolBarManager.java 22 May 2009 10:09:58 -0000 >@@ -9,14 +9,30 @@ > *******************************************************************************/ > package org.eclipse.rap.internal.design.business.managers; > >-import java.util.*; >+import java.util.ArrayList; >+import java.util.HashMap; > import java.util.List; >+import java.util.Map; > >+import org.eclipse.core.commands.Command; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; > import org.eclipse.core.runtime.Assert; >-import org.eclipse.jface.action.*; >+import org.eclipse.jface.action.Action; >+import org.eclipse.jface.action.ActionContributionItem; >+import org.eclipse.jface.action.ContributionItem; >+import org.eclipse.jface.action.ContributionManager; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.action.IContributionItem; >+import org.eclipse.jface.action.IContributionManagerOverrides; >+import org.eclipse.jface.action.IMenuManager; >+import org.eclipse.jface.action.IToolBarManager; >+import org.eclipse.jface.action.ToolBarContributionItem; > import org.eclipse.jface.internal.provisional.action.ICoolBarManager2; > import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem; > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.rap.internal.design.business.CommandUtil; >+import org.eclipse.rap.internal.design.business.CommandUtil.CommandParameter; > import org.eclipse.rap.internal.design.business.builder.CoolbarLayerBuilder; > import org.eclipse.rap.internal.design.business.builder.DummyBuilder; > import org.eclipse.rap.internal.design.business.layoutsets.CoolbarInitializer; >@@ -24,11 +40,37 @@ > import org.eclipse.rap.ui.interactiondesign.layout.ElementBuilder; > import org.eclipse.rwt.lifecycle.WidgetUtil; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.*; >+import org.eclipse.swt.events.ControlAdapter; >+import org.eclipse.swt.events.ControlEvent; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.events.FocusAdapter; >+import org.eclipse.swt.events.FocusEvent; >+import org.eclipse.swt.events.FocusListener; >+import org.eclipse.swt.events.MouseAdapter; >+import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.graphics.Color; > import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.layout.*; >-import org.eclipse.swt.widgets.*; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.layout.FormAttachment; >+import org.eclipse.swt.layout.FormData; >+import org.eclipse.swt.layout.RowLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Item; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; >+import org.eclipse.swt.widgets.Table; >+import org.eclipse.swt.widgets.TableColumn; >+import org.eclipse.swt.widgets.TableItem; >+import org.eclipse.ui.internal.WWinPluginPulldown; > import org.eclipse.ui.menus.CommandContributionItem; > > >@@ -53,6 +95,10 @@ > private Table overflowTable; > private int indexOfIcon; > private int indexOfText; >+ private int indexOfPulldown; >+ private Map commandParamMap = new HashMap(); >+ private Menu openMenu; >+ > private FocusListener focusListener = new FocusAdapter() { > public void focusLost( FocusEvent event ) { > // close the overflow if the table focus is lost >@@ -60,6 +106,9 @@ > toggleImages(); > } > }; >+ >+ >+ > > > public BusinessCoolBarManager() { >@@ -80,6 +129,10 @@ > coolBar.addControlListener( new ControlAdapter() { > public void controlResized( final ControlEvent e ) { > // close the overflow and update the coolbar if the browser has resized >+ if( openMenu != null ) { >+ // TODO: Sometimes the menu don't close when the control is resized >+ openMenu.setVisible( false ); >+ } > closeOverflow(); > update( true ); > } >@@ -221,7 +274,7 @@ > if( coolBar != null ) { > Control[] children = coolBar.getChildren(); > for( int i = 0; i < children.length; i++ ) { >- if( children[ i ] instanceof Button && !children[ i ].isDisposed() ) { >+ if( !children[ i ].isDisposed() ) { > children[ i ].dispose(); > } > } >@@ -264,7 +317,7 @@ > } > > } >- coolBar.pack( true ); >+ coolBar.pack(); > coolBar.layout( true ); > manageOverflow( ); > } >@@ -283,15 +336,13 @@ > // remove last children (button) > int lastIndex = coolBar.getChildren().length - 1; > Control child = coolBar.getChildren()[ lastIndex ]; >- if( child instanceof Button ) { >- Object object = buttonItemMap.get( child ); >- ContributionItem item = ( ContributionItem ) object; >- addOverflowItem( item ); >- activeOverflowOpenButton(); >- buttonItemMap.remove( child ); >- child.dispose(); >- child = null; >- } >+ Object object = buttonItemMap.get( child ); >+ ContributionItem item = ( ContributionItem ) object; >+ addOverflowItem( item ); >+ activeOverflowOpenButton(); >+ buttonItemMap.remove( child ); >+ child.dispose(); >+ child = null; > } > > // check if the overflow button should be activated or not >@@ -335,7 +386,7 @@ > int result = 0; > Control[] children = comp.getChildren(); > for( int i = 0; i < children.length; i++ ) { >- if( children[ i ] instanceof Button && !children[ i ].isDisposed() ) { >+ if( !children[ i ].isDisposed() ) { > result += ( children[ i ].getSize().x + SPACING ); > } > } >@@ -424,39 +475,73 @@ > iconColumn.setResizable( false ); > iconColumn.setMoveable( false ); > TableColumn textColumn = new TableColumn( overflowTable, SWT.NONE ); >+ TableColumn pulldownColumn = new TableColumn( overflowTable, SWT.NONE ); >+ pulldownColumn.setResizable( false ); >+ pulldownColumn.setMoveable( false ); > indexOfIcon = overflowTable.indexOf( iconColumn ); > indexOfText = overflowTable.indexOf( textColumn ); >+ indexOfPulldown = overflowTable.indexOf( pulldownColumn ); > overflowTable.addFocusListener( focusListener ); > } >- overflowTable.clearAll(); >- overflowTable.removeAll(); >+ emptyOverflowTable(); >+ overflowTable.setVisible( true ); > > // add selection support > final Map itemMap = new HashMap(); >- overflowTable.addSelectionListener( new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- TableItem[] selection = overflowTable.getSelection(); >+ final Map actionMap = new HashMap(); >+ overflowTable.addMouseListener( new MouseAdapter() { >+ public void mouseDown( MouseEvent e ) { >+ TableItem[] selection = overflowTable.getSelection(); > for( int i = 0; i < selection.length; i++ ) { >+ > TableItem item = selection[ i ]; >+ Rectangle bounds = item.getBounds( indexOfPulldown ); > Object object = itemMap.get( item ); >+ Action action = null; > if( object != null ) { > if( object instanceof Action ) { > // action >- Action action = ( Action ) object; >- toggleImages(); >- action.run(); >+ action = ( Action ) object; > } > } >+ if( e.x < bounds.x && action != null ) { >+ // action clicked >+ closeOverflow(); >+ action.run(); >+ } else { >+ // pulldown clicked >+ final Menu pulldownMenu >+ = getPulldownMenu( action, overflowTable, actionMap ); >+ if( pulldownMenu != null ) { >+ Display display = overflowTable.getDisplay(); >+ Point newLoc = display.map( overflowTable, >+ null, >+ bounds.x + 20, >+ bounds.y ); >+ pulldownMenu.setLocation( newLoc ); >+ pulldownMenu.setVisible( true ); >+ openMenu = pulldownMenu; >+ pulldownMenu.addListener( SWT.Hide, new Listener() { >+ public void handleEvent( final Event event ) { >+ closeOverflow(); >+ pulldownMenu.removeListener( SWT.Hide, this ); >+ } >+ } ); >+ } >+ } > } > } >- > } ); > > // fill the table > clearCommandItems(); >+ String key = CoolbarOverflowInitializer.ARROW; >+ ElementBuilder dummy >+ = new DummyBuilder( null, CoolbarOverflowInitializer.SET_ID ); >+ Image arrowIcon = dummy.getImage( key ); > for( int i = 0; i < overflowItems.size(); i++ ) { > ContributionItem contrib = ( ContributionItem ) overflowItems.get( i ); >- if( !buttonItemMap.containsValue( contrib ) ) { >+ if( !buttonItemMap.containsValue( contrib ) ) { > TableItem tableItem = new TableItem( overflowTable, SWT.NONE ); > Action action = null; > if( contrib instanceof ActionContributionItem ) { >@@ -467,31 +552,71 @@ > } else if( contrib instanceof CommandContributionItem ) { > // comand > CommandContributionItem item = ( CommandContributionItem ) contrib; >- action = wrapCommand( item, tableItem ); >+ action = CommandUtil.wrapCommand( item, coolBar ); >+ actionMap.put( action, item ); > } >+ // icon column > itemMap.put( tableItem, action ); > ImageDescriptor imageDescriptor = action.getImageDescriptor(); > if( imageDescriptor != null ) { >- tableItem.setImage( indexOfIcon, imageDescriptor.createImage() ); >+ Image icon = imageDescriptor.createImage(); >+ tableItem.setImage( indexOfIcon, icon ); > } >+ // text column > setTableItemStyle( tableItem ); > String text = action.getText(); > // reomve the & because there is no shortkey suppor tin the coolbar > tableItem.setText( indexOfText, text.replaceAll( "&", "" ) ); > tableItem.setData( WidgetUtil.CUSTOM_VARIANT, "overflow" ); >+ // pulldown >+ if( action.getStyle() == IAction.AS_DROP_DOWN_MENU ) { >+ tableItem.setImage( indexOfPulldown, arrowIcon ); >+ } > } > } > >- // pack and set focus for the focuslistener >+ // pack and set focus for the focuslistener > overflowTable.getColumn( indexOfIcon ).pack(); > overflowTable.getColumn( indexOfText ).pack(); >+ overflowTable.getColumn( indexOfPulldown ).pack(); >+ overflowTable.pack(); >+ overflowLayer.layout( true, true ); > overflowTable.setFocus(); > } > >+ private Menu getPulldownMenu( >+ final Action action, >+ final Control parent, >+ final Map actionMap ) >+ { >+ Menu result = null; >+ if( action instanceof WWinPluginPulldown ) { >+ WWinPluginPulldown pulldown = ( WWinPluginPulldown ) action; >+ result = pulldown.getMenuCreator().getMenu( parent ); >+ } else if( actionMap != null ) { >+ Object object = actionMap.get( action ); >+ if( object != null && object instanceof CommandContributionItem ) { >+ CommandContributionItem item = ( CommandContributionItem ) object; >+ CommandParameter param = extractCommandInformation( item ); >+ result = param.getMenu(); >+ } >+ } >+ return result; >+ } >+ >+ private void emptyOverflowTable() { >+ TableItem[] items = overflowTable.getItems(); >+ for( int i = 0; i < items.length; i++ ) { >+ items[ i ].dispose(); >+ } >+ overflowTable.clearAll(); >+ overflowTable.removeAll(); >+ } >+ > private void clearCommandItems() { > for( int i = 0; i < commanItems.size(); i++ ) { > MenuItem item = ( MenuItem ) commanItems.get( i ); >- destroyMenuItem( item ); >+ destroyItem( item ); > } > } > >@@ -528,81 +653,65 @@ > overflowLayer.getParent().setVisible( false ); > overflowParent.setBackgroundImage( preservedWave ); > overflowOpenButton.setData( WidgetUtil.CUSTOM_VARIANT, INACTIVE ); >- overflowItems.clear(); >+ overflowItems.clear(); > clearCommandItems(); > } > } > } > >- private void addCommandToCoolBar( final CommandContributionItem command ) { >- final Menu menu = new Menu( coolBar ); >- menu.setVisible( false ); >- command.fill( menu, 0 ); >- MenuItem[] menuItems = menu.getItems(); >- for( int j = 0; j < menuItems.length; j++ ) { >- final MenuItem item = menuItems[ j ]; >- final Button button = new Button( coolBar, item.getStyle() ); >- button.setImage( item.getImage() ); >- adjustButtonBounds( button ); >- button.setToolTipText( item.getText() ); >- button.setData( WidgetUtil.CUSTOM_VARIANT, "coolBar" ); >- button.setText( item.getText() ); >+ private void addCommandToCoolBar( final CommandContributionItem item ) { >+ CommandParameter param = extractCommandInformation( item ); >+ if( param.getStyle() == CommandContributionItem.STYLE_PULLDOWN ) { >+ // pull down button >+ createPullDownButton( item, >+ CommandUtil.wrapCommand( item, coolBar ), >+ param.getStyle() ); >+ } else { >+ final Button button = new Button( coolBar, param.getStyle() ); >+ Command command = param.getCommand(); >+ button.setData( command ); >+ button.setText( param.getText() ); >+ button.setToolTipText( param.getTooltipText() ); >+ button.setData( WidgetUtil.CUSTOM_VARIANT, "coolBar" ); >+ button.setImage( param.getIcon() ); > button.addSelectionListener( new SelectionAdapter() { >- public void widgetSelected( SelectionEvent e ) { >- Event ev = new Event(); >- ev.widget = ( Button ) e.getSource(); >- item.notifyListeners( SWT.Selection, ev ); >+ public void widgetSelected( final SelectionEvent e ) { >+ try { >+ Command buttonCommand = ( Command ) button.getData(); >+ buttonCommand.getHandler().execute( new ExecutionEvent() ); >+ } catch( ExecutionException e1 ) { >+ e1.printStackTrace(); >+ } > }; > } ); > button.addDisposeListener( new DisposeListener() { > public void widgetDisposed( DisposeEvent event ) { >- destroyMenuItem( item ); > buttonItemMap.remove( button ); > } > } ); >- buttonItemMap.put( button, command ); >- } >- } >+ buttonItemMap.put( button, item ); >+ } >+ } > >- /* >- * Wraps a command contrib item to an action >- */ >- private Action wrapCommand( >- final CommandContributionItem item, >- final TableItem tableItem ) >+ private CommandParameter extractCommandInformation( >+ final CommandContributionItem item ) > { >- Action result = null; >- final Menu menu = new Menu( coolBar ); >- menu.setVisible( false ); >- item.fill( menu, 0 ); >- MenuItem[] menuItems = menu.getItems(); >- for( int j = 0; j < menuItems.length; j++ ) { >- final MenuItem menuItem = menuItems[ j ]; >- result = new Action() { >- public void run() { >- Event ev = new Event(); >- ev.widget = tableItem.getParent(); >- menuItem.notifyListeners( SWT.Selection, ev ); >- destroyMenuItem( menuItem ); >- commanItems.remove( menuItem ); >- } >- }; >- ImageDescriptor desc = new ImageDescriptor() { >- public Image createImage() { >- return menuItem.getImage(); >- } >- }; >- commanItems.add( menuItem ); >- result.setImageDescriptor( desc ); >- result.setText( menuItem.getText() ); >- result.setToolTipText( menuItem.getText() ); >+ CommandParameter result = null; >+ Object object = commandParamMap.get( item ); >+ if( object == null ) { >+ result = CommandUtil.extractCommandInformation( item, coolBar ); >+ commandParamMap.put( item, result ); >+ } else { >+ result = ( CommandParameter ) object; > } > return result; > } >+ >+ > >- private void destroyMenuItem( final MenuItem item ) { >+ private void destroyItem( Item item ) { > item.dispose(); >- //item = null; >+ item = null; > } > > /* >@@ -616,28 +725,138 @@ > > private void addActionToCoolBar( final ActionContributionItem item ) { > final IAction action = item.getAction(); >- final Button button = new Button( coolBar, action.getStyle() ); >+ int actionStyle = action.getStyle(); >+ int style = getButtonStyle( actionStyle ); >+ >+ if( action.getStyle() == IAction.AS_DROP_DOWN_MENU ) { >+ // drop down button >+ if( action instanceof WWinPluginPulldown ) { >+ createPullDownButton( item, action, style ); >+ } else { >+ throw new IllegalArgumentException( action.getId() + " does not " + >+ "implement IWorkbenchWindowPulldownDelegate" ); >+ } >+ } else { >+ // create normal button >+ final Button button = createCoolBarButton( coolBar, style, action ); >+ buttonItemMap.put( button, item ); >+ button.addDisposeListener( new DisposeListener() { >+ public void widgetDisposed( DisposeEvent event ) { >+ buttonItemMap.remove( button ); >+ } >+ } ); >+ } >+ } >+ >+ private void createPullDownButton( >+ final ContributionItem item, >+ final IAction action, >+ final int style ) >+ { >+ final Composite buttonParent = new Composite( coolBar, SWT.NONE ); >+ buttonItemMap.put( buttonParent, item ); >+ RowLayout layout = new RowLayout( SWT.HORIZONTAL ); >+ layout.spacing = 0; >+ layout.marginBottom = 0; >+ layout.marginHeight = 0; >+ layout.marginLeft = 0; >+ layout.marginRight = 0; >+ layout.marginTop = 0; >+ layout.marginWidth = 0; >+ buttonParent.setLayout( layout ); >+ buttonParent.setData( WidgetUtil.CUSTOM_VARIANT, "compTrans" ); >+ Button button = createCoolBarButton( buttonParent, SWT.PUSH, action ); >+ buttonParent.addDisposeListener( new DisposeListener() { >+ public void widgetDisposed( final DisposeEvent event ) { >+ buttonItemMap.remove( buttonParent ); >+ clearComposite( buttonParent ); >+ } >+ } ); >+ // create the pulldown arrow >+ final Button arrow = new Button( buttonParent, SWT.PUSH ); >+ arrow.setData( WidgetUtil.CUSTOM_VARIANT, "coolBarPulldown" ); >+ arrow.setImage( dummyBuilder.getImage( CoolbarInitializer.ARROW ) ); >+ final Menu menu = getItemMenu( item, action, button ); >+ arrow.setText( " " ); >+ arrow.addSelectionListener( new SelectionAdapter() { >+ public void widgetSelected( final SelectionEvent e ) { >+ if( menu != null ) { >+ menu.setVisible( true ); >+ openMenu = menu; >+ Display display = arrow.getDisplay(); >+ Point newLoc = display.map( arrow, null, 10, arrow.getSize().y ); >+ menu.setLocation( newLoc ); >+ } >+ }; >+ } ); >+ buttonParent.layout( true ); >+ } >+ >+ private Menu getItemMenu( >+ final ContributionItem item, >+ final IAction action, >+ final Button button ) >+ { >+ Menu menu; >+ if( item instanceof CommandContributionItem ) { >+ CommandParameter param >+ = extractCommandInformation( ( CommandContributionItem ) item ); >+ menu = param.getMenu(); >+ } else { >+ menu = getPulldownMenu( ( Action ) action, button, null ); >+ } >+ return menu; >+ } >+ >+ private void clearComposite( final Composite comp ) { >+ Control[] children = comp.getChildren(); >+ for( int i = 0; i < children.length; i++ ) { >+ children[ i ].dispose(); >+ } >+ } >+ >+ private int getButtonStyle( int actionStyle ) { >+ int style; >+ switch( actionStyle ) { >+ case IAction.AS_CHECK_BOX: >+ style = SWT.CHECK; >+ break; >+ case IAction.AS_DROP_DOWN_MENU: >+ style = SWT.PUSH; >+ break; >+ case IAction.AS_RADIO_BUTTON: >+ style = SWT.RADIO; >+ break; >+ default: >+ style = SWT.PUSH; >+ break; >+ } >+ return style; >+ } >+ >+ private Button createCoolBarButton( >+ final Composite parent, >+ final int style, >+ final IAction action ) >+ { >+ final Button button = new Button( parent, style ); > adjustButtonBounds( button ); > button.setText( action.getText() ); > button.setToolTipText( action.getToolTipText() ); >- button.setImage( action.getImageDescriptor().createImage() ); >+ if( action.getImageDescriptor() != null ) { >+ button.setImage( action.getImageDescriptor().createImage() ); >+ } > button.setData( WidgetUtil.CUSTOM_VARIANT, "coolBar" ); > button.addSelectionListener( new SelectionAdapter() { > public void widgetSelected( SelectionEvent e ) { >- try{ >- action.run(); >+ try{ >+ action.run(); > } catch( Exception ex ) { > > } > } >- } ); >- button.addDisposeListener( new DisposeListener() { >- public void widgetDisposed( DisposeEvent event ) { >- buttonItemMap.remove( button ); >- } >- } ); >- buttonItemMap.put( button, item ); >- >+ } ); >+ return button; > } > > public void setOverflowParent( final Composite overflowParent ) { >Index: src/org/eclipse/rap/internal/design/business/managers/BusinessViewToolBarManager.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.design.business/src/org/eclipse/rap/internal/design/business/managers/BusinessViewToolBarManager.java,v >retrieving revision 1.1 >diff -u -r1.1 BusinessViewToolBarManager.java >--- src/org/eclipse/rap/internal/design/business/managers/BusinessViewToolBarManager.java 21 Apr 2009 17:35:21 -0000 1.1 >+++ src/org/eclipse/rap/internal/design/business/managers/BusinessViewToolBarManager.java 22 May 2009 10:09:58 -0000 >@@ -9,28 +9,51 @@ > *******************************************************************************/ > package org.eclipse.rap.internal.design.business.managers; > >+import java.util.ArrayList; >+import java.util.List; >+ >+import org.eclipse.jface.action.Action; > import org.eclipse.jface.action.ActionContributionItem; > import org.eclipse.jface.action.ContributionManager; > import org.eclipse.jface.action.IAction; > import org.eclipse.jface.action.IContributionItem; >+import org.eclipse.jface.action.IMenuCreator; > import org.eclipse.jface.internal.provisional.action.IToolBarManager2; > import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.rap.internal.design.business.CommandUtil; >+import org.eclipse.rap.internal.design.business.CommandUtil.CommandParameter; >+import org.eclipse.rap.internal.design.business.builder.DummyBuilder; >+import org.eclipse.rap.internal.design.business.layoutsets.StackInitializer; >+import org.eclipse.rap.ui.interactiondesign.layout.ElementBuilder; > import org.eclipse.rwt.lifecycle.WidgetUtil; > import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; > import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.layout.FormAttachment; >+import org.eclipse.swt.layout.FormData; >+import org.eclipse.swt.layout.FormLayout; > import org.eclipse.swt.layout.RowLayout; > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Menu; > import org.eclipse.swt.widgets.ToolBar; >+import org.eclipse.ui.IWorkbenchWindowPulldownDelegate; >+import org.eclipse.ui.internal.WWinPluginPulldown; >+import org.eclipse.ui.menus.CommandContributionItem; > > > public class BusinessViewToolBarManager extends ContributionManager > implements IToolBarManager2 > { > >-private Composite control; >+ private Composite control; >+ private List itemList = new ArrayList(); > > public void addPropertyChangeListener( > final IPropertyChangeListener listener ) >@@ -53,8 +76,6 @@ > > } > >- >- > public ToolBar getControl() { > return null; > } >@@ -67,40 +88,116 @@ > return getItems().length; > } > >- private void makeButton( final IContributionItem item ) { >- >- final IAction action = ( ( ActionContributionItem ) item ).getAction(); >- int flags = SWT.PUSH; >- if( action.getStyle() == IAction.AS_CHECK_BOX ) { >- flags = SWT.TOGGLE; >- } >- if( action.getStyle() == IAction.AS_RADIO_BUTTON ) { >- flags = SWT.RADIO; >- } >- >- final Button button = new Button( control, flags ); >- button.setData( item ); >- button.setToolTipText( action.getToolTipText() ); >- button.setImage( action.getImageDescriptor().createImage() ); >- button.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" ); >- button.addSelectionListener( new SelectionAdapter() { >- public void widgetSelected( SelectionEvent e ) { >- // SWT.DROPDOWN not yet supportet >- boolean checked = button.getSelection(); >- int style = button.getStyle(); >- if( ( style & ( SWT.TOGGLE | SWT.CHECK ) ) != 0 ) { >- if( action.getStyle() == IAction.AS_CHECK_BOX ) { >- action.setChecked( checked ); >- } >- } else if( ( style & SWT.RADIO ) != 0 ) { >- if( action.getStyle() == IAction.AS_RADIO_BUTTON ) { >- action.setChecked( checked ); >+ private void makeButton( final Action action, final IContributionItem item ) { >+ if( !itemList.contains( item.getId() ) ) { >+ int flags = SWT.PUSH; >+ switch( action.getStyle() ) { >+ case IAction.AS_CHECK_BOX: >+ flags = SWT.TOGGLE; >+ break; >+ case IAction.AS_DROP_DOWN_MENU: >+ flags = SWT.DROP_DOWN; >+ break; >+ case IAction.AS_RADIO_BUTTON: >+ flags = SWT.TOGGLE; >+ break; >+ default: >+ flags = SWT.PUSH; >+ break; >+ } >+ >+ Composite parent = control; >+ Menu menu = null; >+ // pulldown >+ if( flags == SWT.DROP_DOWN && item instanceof CommandContributionItem ) { >+ CommandContributionItem commandItem = ( CommandContributionItem ) item; >+ CommandParameter param >+ = CommandUtil.extractCommandInformation( commandItem, control ); >+ if( param.getMenu() != null ) { >+ menu = param.getMenu(); >+ } >+ } else if( action instanceof WWinPluginPulldown ) { >+ WWinPluginPulldown pulldown = ( WWinPluginPulldown ) action; >+ menu = pulldown.getMenuCreator().getMenu( control ); >+ } else if( action instanceof IMenuCreator ) { >+ IMenuCreator creator = ( IMenuCreator ) action; >+ menu = creator.getMenu( control ); >+ } else if( action instanceof IWorkbenchWindowPulldownDelegate ) { >+ System.out.println("pull"); >+ } >+ if( menu != null ) { >+ final Composite pulldownParent = getPulldownParent(); >+ parent = pulldownParent; >+ flags = SWT.PUSH; >+ } >+ // normal items >+ final Button button = new Button( parent, flags ); >+ button.setData( item ); >+ button.setToolTipText( action.getToolTipText() ); >+ button.setImage( action.getImageDescriptor().createImage() ); >+ button.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" ); >+ button.addSelectionListener( new SelectionAdapter() { >+ public void widgetSelected( final SelectionEvent e ) { >+ // SWT.DROPDOWN not yet supported >+ boolean checked = button.getSelection(); >+ int style = button.getStyle(); >+ if( ( style & ( SWT.TOGGLE | SWT.CHECK ) ) != 0 ) { >+ if( action.getStyle() == IAction.AS_CHECK_BOX ) { >+ action.setChecked( checked ); >+ } >+ } else if( ( style & SWT.RADIO ) != 0 ) { >+ if( action.getStyle() == IAction.AS_RADIO_BUTTON ) { >+ action.setChecked( checked ); >+ } > } >+ action.run(); >+ } >+ } ); >+ // pulldown >+ if( menu != null ) { >+ FormData fdButton = new FormData(); >+ button.setLayoutData( fdButton ); >+ fdButton.left = new FormAttachment( 0 ); >+ fdButton.top = new FormAttachment( 0 ); >+ final Button arrow = new Button( parent, SWT.PUSH ); >+ FormData fdArrow = new FormData(); >+ arrow.setLayoutData( fdArrow ); >+ fdArrow.left = new FormAttachment( button, 0 ); >+ fdArrow.top = new FormAttachment( 0, 7 ); >+ ElementBuilder builder >+ = new DummyBuilder( null, StackInitializer.SET_ID ); >+ Image image = builder.getImage( StackInitializer.VIEW_PULLDOWN ); >+ arrow.setImage( image ); >+ arrow.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" ); >+ arrow.setMenu( menu ); >+ arrow.addSelectionListener( new SelectionAdapter() { >+ public void widgetSelected( final SelectionEvent e ) { >+ Display display = arrow.getDisplay(); >+ Point newLoc = display.map( arrow, null, 0, 10 ); >+ arrow.getMenu().setVisible( true ); >+ arrow.getMenu().setLocation( newLoc ); >+ }; >+ } ); >+ } >+ itemList.add( item.getId() ); >+ } >+ } >+ >+ private Composite getPulldownParent() { >+ final Composite pulldownParent = new Composite( control, SWT.NONE ); >+ pulldownParent.setLayout( new FormLayout() ); >+ pulldownParent.setData( WidgetUtil.CUSTOM_VARIANT, "compTrans" ); >+ >+ pulldownParent.addDisposeListener( new DisposeListener() { >+ public void widgetDisposed( final DisposeEvent event ) { >+ Control[] children = pulldownParent.getChildren(); >+ for( int i = 0; i < children.length; i++ ) { >+ Control control = children[ i ]; >+ control.dispose(); > } >- action.run(); > } > } ); >- >+ return pulldownParent; > } > > public void removePropertyChangeListener( >@@ -109,19 +206,22 @@ > } > > public void update( final boolean force ) { >- >+ itemList.clear(); > Control[] children = control.getChildren(); > for( int i = 0; i < children.length; i++ ) { >- if( children[ i ] instanceof Button ) { >- children[ i ].dispose(); >- } >+ children[ i ].dispose(); > } > > IContributionItem[] items = getItems(); > for( int i = 0; i < items.length; i++ ) { > IContributionItem item = items[ i ]; >- if( item.isVisible() && ( item instanceof ActionContributionItem ) ) { >- makeButton( item ); >+ if( item.isVisible() && item instanceof ActionContributionItem ) { >+ // actions >+ IAction action = ( ( ActionContributionItem ) item ).getAction(); >+ makeButton( ( Action ) action, item ); >+ } else if( item.isVisible() && item instanceof CommandContributionItem ) { >+ // commands >+ makeCommandButton( item ); > } > } > >@@ -129,6 +229,12 @@ > control.layout( true ); > } > >+ private void makeCommandButton( final IContributionItem item ) { >+ CommandContributionItem comamndItem = ( CommandContributionItem ) item; >+ final Action action = CommandUtil.wrapCommand( comamndItem, control ); >+ makeButton( action, item ); >+ } >+ > public void dispose() { > if( control != null && !control.isDisposed() ) { > control.dispose(); >Index: src/org/eclipse/rap/internal/design/business/stacks/ConfigurationDialog.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.design.business/src/org/eclipse/rap/internal/design/business/stacks/ConfigurationDialog.java,v >retrieving revision 1.2 >diff -u -r1.2 ConfigurationDialog.java >--- src/org/eclipse/rap/internal/design/business/stacks/ConfigurationDialog.java 5 May 2009 15:35:21 -0000 1.2 >+++ src/org/eclipse/rap/internal/design/business/stacks/ConfigurationDialog.java 22 May 2009 10:10:00 -0000 >@@ -43,9 +43,12 @@ > import org.eclipse.swt.widgets.Label; > import org.eclipse.swt.widgets.Listener; > import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.ToolBar; >+import org.eclipse.swt.widgets.ToolItem; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.menus.CommandContributionItem; > import org.eclipse.ui.presentations.IStackPresentationSite; > > /** >@@ -241,6 +244,7 @@ > String actionId = items[ i ].getId(); > > if( items[ i ] instanceof ActionContributionItem ) { >+ // commands > ActionContributionItem item > = ( ActionContributionItem) items[ i ]; > >@@ -267,7 +271,33 @@ > actionButtonMap.put( actionId, check ); > actionList.add( actionId ); > >- } >+ } else if( items[ i ] instanceof CommandContributionItem ) { >+ // commands >+ CommandContributionItem item >+ = ( CommandContributionItem ) items[ i ]; >+ Object[] commandInfo = getCommandInfo( item, container ); >+ if( commandInfo != null ) { >+ Label imageLabel = new Label( container, SWT.NONE ); >+ imageLabel.setImage( ( Image ) commandInfo[ 0 ] ); >+ Label textLabel = new Label( container, SWT.NONE ); >+ if( commandInfo[ 1 ] != null >+ && !commandInfo[ 1 ].equals( "" ) ) { >+ textLabel.setText( ( String ) commandInfo[ 1 ] ); >+ } else { >+ textLabel.setText( ( String ) commandInfo[ 2 ] ); >+ } >+ data = new GridData( GridData.FILL_HORIZONTAL ); >+ textLabel.setLayoutData( data ); >+ >+ Button check = new Button( container, SWT.CHECK ); >+ check.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); >+ boolean selected >+ = action.isViewActionVisibile( paneId, item.getId() ); >+ check.setSelection( selected ); >+ actionButtonMap.put( item.getId(), check ); >+ actionList.add( item.getId() ); >+ } >+ } > } > } > } >@@ -364,6 +394,25 @@ > // } > // } > >+ private Object[] getCommandInfo( >+ final CommandContributionItem item, >+ final Composite container ) >+ { >+ Object[] result = null; >+ ToolBar toolbar = new ToolBar( container, SWT.NONE ); >+ toolbar.setVisible( false ); >+ item.fill( toolbar, -1 ); >+ ToolItem[] items = toolbar.getItems(); >+ for( int i = 0; i < items.length; i++ ) { >+ result = new Object[ 3 ]; >+ result[ 0 ] = items[ i ].getImage(); >+ result[ 1 ] = items[ i ].getText(); >+ result[ 2 ] = items[ i ].getToolTipText(); >+ } >+ toolbar.dispose(); >+ return result; >+ } >+ > public int open() { > int result = super.open(); > closeListener = new Listener() { >Index: src/org/eclipse/rap/internal/design/business/stacks/ViewStackPresentation.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.ui/org.eclipse.rap.design.business/src/org/eclipse/rap/internal/design/business/stacks/ViewStackPresentation.java,v >retrieving revision 1.1 >diff -u -r1.1 ViewStackPresentation.java >--- src/org/eclipse/rap/internal/design/business/stacks/ViewStackPresentation.java 21 Apr 2009 17:35:21 -0000 1.1 >+++ src/org/eclipse/rap/internal/design/business/stacks/ViewStackPresentation.java 22 May 2009 10:10:00 -0000 >@@ -50,6 +50,7 @@ > import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.internal.PartPane; > import org.eclipse.ui.internal.presentations.PresentablePart; >+import org.eclipse.ui.presentations.IPartMenu; > import org.eclipse.ui.presentations.IPresentablePart; > > >@@ -72,6 +73,7 @@ > private Shell toolBarLayer; > private int state; > protected boolean deactivated; >+ private Button viewMenuButton; > > public ViewStackPresentation() { > state = AS_INACTIVE; >@@ -101,6 +103,7 @@ > private void createToolBarBg() { > Composite tabBar = getTabBar(); > toolbarBg = new Composite( tabBar.getParent(), SWT.NONE ); >+ toolbarBg.setLayout( new FormLayout() ); > Image bg = stackBuilder.getImage( StackInitializer.VIEW_TOOLBAR_BG ); > toolbarBg.setBackgroundImage( bg ); > FormData fdToolBar = new FormData(); >@@ -163,23 +166,54 @@ > private void layoutToolBar() { > if( toolbarBg == null && tabBg != null ) { > createToolBarBg(); >- } >- >+ } > if( currentPart != null ) { > Control toolBar = currentPart.getToolBar(); >+ final IPartMenu viewMenu = currentPart.getMenu(); >+ // viewmenu >+ if( viewMenu != null ) { >+ if( viewMenuButton == null ) { >+ viewMenuButton = new Button( toolbarBg, SWT.PUSH ); >+ viewMenuButton.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" ); >+ Image icon = stackBuilder.getImage( StackInitializer.VIEW_MENU_ICON ); >+ viewMenuButton.setImage( icon ); >+ FormData fdViewMenuButton = new FormData(); >+ viewMenuButton.setLayoutData( fdViewMenuButton ); >+ fdViewMenuButton.right = new FormAttachment( 100, -3 ); >+ fdViewMenuButton.top = new FormAttachment( 0, 7 ); >+ viewMenuButton.addSelectionListener( new SelectionAdapter() { >+ public void widgetSelected( final SelectionEvent e ) { >+ Display display = viewMenuButton.getDisplay(); >+ int height = viewMenuButton.getSize().y; >+ Point newLoc = display.map( viewMenuButton, null, 0, height ); >+ viewMenu.showMenu( newLoc ); >+ }; >+ } ); >+ } >+ } else if( viewMenuButton != null ) { >+ viewMenuButton.setVisible( false ); >+ viewMenuButton.dispose(); >+ viewMenuButton = null; >+ } >+ // toolbar >+ Point size = toolbarBg.getSize(); > if( toolBar != null ) { >- // Toolbar >- Point point = currentPart.getControl().getLocation(); >- Point size = toolbarBg.getSize(); >+ Point point = currentPart.getControl().getLocation(); > point.y -= ( size.y + 2 ); > point.x += ( size.x - toolBar.getSize().x ); >+ if( viewMenu != null ) { >+ point.x -= 20; >+ } > toolBar.setLocation( point ); > > toolBar.setVisible( true ); >- toolbarBg.setVisible( true ); >- toolbarBg.moveBelow( toolBar ); >- presentationControl.moveBelow( toolBar ); > >+ toolbarBg.moveBelow( toolBar ); >+ presentationControl.moveBelow( toolBar ); >+ } >+ // toolbarbg and layer >+ if( toolBar != null || viewMenu != null ) { >+ toolbarBg.setVisible( true ); > // Toolbar Layer > if( !deactivated ) { > getToolBarLayer(); >@@ -193,11 +227,10 @@ > size.y - 1 > ); > toolBarLayer.setVisible( true ); >- toolBarLayer.moveAbove( toolBar ); > } > } > } else { >- toolbarBg.setVisible( false ); >+ toolbarBg.setVisible( false ); > } > toolbarBg.layout( true ); > } >Index: src/org/eclipse/rap/internal/design/business/CommandUtil.java >=================================================================== >RCS file: src/org/eclipse/rap/internal/design/business/CommandUtil.java >diff -N src/org/eclipse/rap/internal/design/business/CommandUtil.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/rap/internal/design/business/CommandUtil.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,184 @@ >+/******************************************************************************* >+* Copyright (c) 2009 EclipseSource and others. All rights reserved. This >+* program and the accompanying materials are made available under the terms of >+* the Eclipse Public License v1.0 which accompanies this distribution, and is >+* available at http://www.eclipse.org/legal/epl-v10.html >+* >+* Contributors: >+* EclipseSource - initial API and implementation >+*******************************************************************************/ >+package org.eclipse.rap.internal.design.business; >+ >+import org.eclipse.core.commands.Command; >+import org.eclipse.core.commands.CommandManager; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+import org.eclipse.jface.action.Action; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.action.MenuManager; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.ToolBar; >+import org.eclipse.swt.widgets.ToolItem; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.commands.ICommandService; >+import org.eclipse.ui.menus.CommandContributionItem; >+import org.eclipse.ui.menus.IMenuService; >+ >+ >+public class CommandUtil { >+ >+ public static class CommandParameter { >+ private Menu menu; >+ private int style; >+ private Image icon; >+ private String id; >+ private Command command; >+ private String text; >+ private String tooltipText; >+ >+ public CommandParameter( >+ final Command command, >+ final String id, >+ final Image icon, >+ final int style, >+ final Menu menu, >+ final String text, >+ final String tooltipText ) >+ { >+ this.command = command; >+ this.id = id; >+ this.icon = icon; >+ this.style = style; >+ this.menu = menu; >+ this.text = text; >+ this.tooltipText = tooltipText; >+ } >+ >+ public Command getCommand() { >+ return command; >+ } >+ >+ public Menu getMenu() { >+ return menu; >+ } >+ >+ public int getStyle() { >+ return style; >+ } >+ >+ public Image getIcon() { >+ return icon; >+ } >+ >+ public String getText() { >+ return text; >+ } >+ >+ public String getTooltipText() { >+ return tooltipText; >+ } >+ } >+ >+ /* >+ * Wraps a command contrib item to an action >+ */ >+ public static Action wrapCommand( >+ final CommandContributionItem item, >+ final Composite parent ) >+ { >+ Action result = null; >+ final CommandParameter param = extractCommandInformation( item, parent ); >+ String text = param.getTooltipText(); >+ String toolTipText = param.getTooltipText(); >+ int style = IAction.AS_PUSH_BUTTON; >+ if( param.getStyle() == CommandContributionItem.STYLE_PULLDOWN ) { >+ style = IAction.AS_DROP_DOWN_MENU; >+ } else if( param.getStyle() == CommandContributionItem.STYLE_CHECK ) { >+ style = IAction.AS_CHECK_BOX; >+ } else if( param.getStyle() == CommandContributionItem.STYLE_RADIO ) { >+ style = IAction.AS_RADIO_BUTTON; >+ } >+ result = new Action( text, style ){ >+ public void run() { >+ Command command = param.getCommand(); >+ if( command != null ) { >+ try { >+ command.getHandler().execute( new ExecutionEvent() ); >+ } catch( final ExecutionException e ) { >+ e.printStackTrace(); >+ } >+ } >+ } >+ }; >+ ImageDescriptor desc = new ImageDescriptor() { >+ public Image createImage() { >+ return param.getIcon(); >+ } >+ }; >+ result.setImageDescriptor( desc ); >+ result.setToolTipText( toolTipText ); >+ return result; >+ } >+ >+ public static CommandParameter extractCommandInformation( >+ final CommandContributionItem item, >+ final Composite parent ) >+ { >+ // extract command >+ CommandParameter result = null; >+ CommandManager manager = new CommandManager(); >+ Command command = manager.getCommand( item.getId() ); >+ IWorkbench workbench = PlatformUI.getWorkbench(); >+ IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow(); >+ Object service = activeWindow.getService( ICommandService.class ); >+ if( !command.isDefined() ) { >+ if( service != null && service instanceof ICommandService ) { >+ ICommandService commandService = ( ICommandService ) service; >+ command = commandService.getCommand( item.getId() ); >+ } >+ } >+ // extract image >+ Image icon = null; >+ String text = ""; >+ String tooltipText = ""; >+ int style = CommandContributionItem.STYLE_PUSH; >+ ToolBar toolbar = new ToolBar( parent, SWT.NONE ); >+ toolbar.setVisible( false ); >+ item.fill( toolbar, -1 ); >+ ToolItem[] toolItems = toolbar.getItems(); >+ for( int i = 0; i < toolItems.length; i++ ) { >+ ToolItem toolItem = toolItems[ i ]; >+ style = toolItem.getStyle(); >+ icon = toolItem.getImage(); >+ text = toolItem.getToolTipText(); >+ tooltipText = toolItem.getToolTipText(); >+ } >+ // extract menu >+ Menu menu = null; >+ if( style == CommandContributionItem.STYLE_PULLDOWN ) { >+ final MenuManager menuManager = new MenuManager(); >+ Object abstractService = activeWindow.getService( IMenuService.class ); >+ IMenuService menuService = ( IMenuService ) abstractService; >+ String identifier = "menu:" + item.getId(); >+ menuService.populateContributionManager( menuManager, identifier ); >+ menu = menuManager.createContextMenu( parent ); >+ } >+ result = new CommandParameter( >+ command, >+ item.getId(), >+ icon, >+ style, >+ menu, >+ text, >+ tooltipText ); >+ >+ toolbar.dispose(); >+ return result; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 275648
: 136788 |
136791
|
136792
|
136793
|
136795