下面列出了怎么用org.eclipse.jface.action.IMenuCreator的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testGetMenuCreator() {
LaunchModeAction action = createLaunchModeAction();
IMenuCreator menuCreator = action.getMenuCreator();
assertThat( menuCreator ).isNull();
}
@Test
public void testMenuCreator() {
LaunchModeDropDownAction action = new LaunchModeDropDownAction( launchModeSetting );
IMenuCreator menuCreator = action.getMenuCreator();
assertThat( menuCreator ).isSameAs( action );
}
@Override
public IMenuCreator getMenuCreator() {
return fOpenAction.getMenuCreator();
}
@Override
public void setMenuCreator(IMenuCreator creator) {
fOpenAction.setMenuCreator(creator);
}
@Override
public IMenuCreator getMenuCreator() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setMenuCreator(IMenuCreator creator) {
// TODO Auto-generated method stub
}
@Override
public IMenuCreator getMenuCreator() {
return this;
}
@Override
public IMenuCreator getMenuCreator() {
return fOpenAction.getMenuCreator();
}
@Override
public void setMenuCreator(IMenuCreator creator) {
fOpenAction.setMenuCreator(creator);
}
private void handleWidgetSelection( Event e, ToolItem item )
{
boolean selection = item.getSelection( );
int style = item.getStyle( );
IAction action = (IAction) actionMap.get( item );
if ( ( style & ( SWT.TOGGLE | SWT.CHECK ) ) != 0 )
{
if ( action.getStyle( ) == IAction.AS_CHECK_BOX )
{
action.setChecked( selection );
}
}
else if ( ( style & SWT.RADIO ) != 0 )
{
if ( action.getStyle( ) == IAction.AS_RADIO_BUTTON )
{
action.setChecked( selection );
}
}
else if ( ( style & SWT.DROP_DOWN ) != 0 )
{
if ( e.detail == 4 )
{ // on drop-down button
if ( action.getStyle( ) == IAction.AS_DROP_DOWN_MENU )
{
IMenuCreator mc = action.getMenuCreator( );
ToolItem ti = (ToolItem) item;
if ( mc != null )
{
Menu m = mc.getMenu( ti.getParent( ) );
if ( m != null )
{
Point point = ti.getParent( )
.toDisplay( new Point( e.x, e.y ) );
m.setLocation( point.x, point.y ); // waiting
m.setVisible( true );
return; // we don't fire the action
}
}
}
}
}
action.runWithEvent( e );
}
public IMenuCreator getMenuCreator() {
return action.getMenuCreator();
}
public void setMenuCreator(IMenuCreator creator) {
action.setMenuCreator(creator);
}