Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
RHBRMS-349: New Item Menu: No Project selected, all items enabled aft…
Browse files Browse the repository at this point in the history
…er Perspective reset (#483)
  • Loading branch information
manstis authored and ederign committed Sep 5, 2016
1 parent 1cce54c commit 0e0a2f8
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 96 deletions.
Expand Up @@ -19,12 +19,13 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import org.jboss.errai.ioc.client.container.IOC;
import org.jboss.errai.security.shared.api.identity.User;
import org.uberfire.client.menu.AuthFilterMenuVisitor;
Expand All @@ -51,9 +52,6 @@
import org.uberfire.workbench.model.menu.Menus;
import org.uberfire.workbench.model.menu.impl.BaseMenuVisitor;

import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

/**
* Presenter for WorkbenchMenuBar that mediates changes to the Workbench MenuBar
* in response to changes to the selected WorkbenchPart. The menu structure is
Expand Down Expand Up @@ -261,9 +259,9 @@ public void enabledStateChanged( final boolean enabled ) {
} );
}

}
} ) );

) );
synchronizeUIWithMenus( addedMenu.getItems() );
}

private String getMenuItemId( final MenuItem menuItem ) {
Expand All @@ -274,70 +272,72 @@ private void addPerspectiveMenus( final PerspectiveActivity perspective ) {
final String perspectiveId = perspective.getIdentifier();
final Menus menus = perspective.getMenus();
view.clearContextMenu();
if( menus != null ) {
menus.accept(new AuthFilterMenuVisitor(authzManager, identity, new BaseMenuVisitor() {
if ( menus != null ) {
menus.accept( new AuthFilterMenuVisitor( authzManager, identity, new BaseMenuVisitor() {

private String parentId = null;

@Override
public boolean visitEnter(final MenuGroup menuGroup) {
parentId = getMenuItemId(menuGroup);
view.addContextGroupMenuItem(perspectiveId, parentId, menuGroup.getCaption(), menuGroup.getPosition());
public boolean visitEnter( final MenuGroup menuGroup ) {
parentId = getMenuItemId( menuGroup );
view.addContextGroupMenuItem( perspectiveId, parentId, menuGroup.getCaption(), menuGroup.getPosition() );
return true;
}

@Override
public void visitLeave(MenuGroup menuGroup) {
public void visitLeave( MenuGroup menuGroup ) {
parentId = null;
}

@Override
public void visit(final MenuItemPlain menuItemPlain) {
view.addContextMenuItem(perspectiveId, getMenuItemId(menuItemPlain), menuItemPlain.getCaption(), parentId, null, menuItemPlain.getPosition());
setupEnableDisableContextMenuItem(menuItemPlain);
public void visit( final MenuItemPlain menuItemPlain ) {
view.addContextMenuItem( perspectiveId, getMenuItemId( menuItemPlain ), menuItemPlain.getCaption(), parentId, null, menuItemPlain.getPosition() );
setupEnableDisableContextMenuItem( menuItemPlain );
}

@Override
public void visit(final MenuCustom<?> menuCustom) {
view.addContextMenuItem(perspectiveId, getMenuItemId(menuCustom), menuCustom.getCaption(), parentId, null, menuCustom.getPosition());
setupEnableDisableContextMenuItem(menuCustom);
public void visit( final MenuCustom<?> menuCustom ) {
view.addContextMenuItem( perspectiveId, getMenuItemId( menuCustom ), menuCustom.getCaption(), parentId, null, menuCustom.getPosition() );
setupEnableDisableContextMenuItem( menuCustom );
}

@Override
public void visit(final MenuItemCommand menuItemCommand) {
view.addContextMenuItem(perspectiveId, getMenuItemId(menuItemCommand), menuItemCommand.getCaption(), parentId, menuItemCommand.getCommand(), menuItemCommand.getPosition());
setupEnableDisableContextMenuItem(menuItemCommand);
public void visit( final MenuItemCommand menuItemCommand ) {
view.addContextMenuItem( perspectiveId, getMenuItemId( menuItemCommand ), menuItemCommand.getCaption(), parentId, menuItemCommand.getCommand(), menuItemCommand.getPosition() );
setupEnableDisableContextMenuItem( menuItemCommand );
}

@Override
public void visit(final MenuItemPerspective menuItemPerspective) {
view.addContextMenuItem(perspectiveId, menuItemPerspective.getPlaceRequest().getIdentifier(), menuItemPerspective.getCaption(), parentId, new Command() {
public void visit( final MenuItemPerspective menuItemPerspective ) {
view.addContextMenuItem( perspectiveId, menuItemPerspective.getPlaceRequest().getIdentifier(), menuItemPerspective.getCaption(), parentId, new Command() {
@Override
public void execute() {
IOC.getBeanManager().lookupBean(PlaceManager.class).getInstance().goTo(menuItemPerspective.getPlaceRequest());
IOC.getBeanManager().lookupBean( PlaceManager.class ).getInstance().goTo( menuItemPerspective.getPlaceRequest() );
}
}, menuItemPerspective.getPosition());
setupEnableDisableContextMenuItem(menuItemPerspective);
}, menuItemPerspective.getPosition() );
setupEnableDisableContextMenuItem( menuItemPerspective );
}

private void setupEnableDisableContextMenuItem(final MenuItem menuItem) {
menuItem.addEnabledStateChangeListener(new EnabledStateChangeListener() {
private void setupEnableDisableContextMenuItem( final MenuItem menuItem ) {
menuItem.addEnabledStateChangeListener( new EnabledStateChangeListener() {
@Override
public void enabledStateChanged(final boolean enabled) {
view.enableContextMenuItem(getMenuItemId(menuItem),
enabled);
public void enabledStateChanged( final boolean enabled ) {
view.enableContextMenuItem( getMenuItemId( menuItem ),
enabled );
}
});
} );
}

}));
} ) );

synchronizeUIWithMenus( menus.getItems() );
}
}

protected void onPerspectiveChange( @Observes final PerspectiveChange perspectiveChange ) {
final Activity activity = activityManager.getActivity(perspectiveChange.getPlaceRequest());
if( activity!= null && activity.isType( ActivityResourceType.PERSPECTIVE.name() ) ) {
addPerspectiveMenus( (PerspectiveActivity) activity);
final Activity activity = activityManager.getActivity( perspectiveChange.getPlaceRequest() );
if ( activity != null && activity.isType( ActivityResourceType.PERSPECTIVE.name() ) ) {
addPerspectiveMenus( (PerspectiveActivity) activity );
}
view.selectMenuItem( perspectiveChange.getPlaceRequest().getIdentifier() );
}
Expand Down Expand Up @@ -392,4 +392,17 @@ public void addExpandHandler( final Command command ) {
List<Menus> getAddedMenus() {
return this.addedMenus;
}

//Force UI to update to state of MenuItems. Should be called after MenuItems are configured with EnabledStateChangeListener's.
void synchronizeUIWithMenus( final List<MenuItem> menuItems ) {
for ( MenuItem menuItem : menuItems ) {
if ( menuItem instanceof MenuGroup ) {
synchronizeUIWithMenus( ( (MenuGroup) menuItem ).getItems() );

} else {
menuItem.setEnabled( menuItem.isEnabled() );
}
}

}
}

0 comments on commit 0e0a2f8

Please sign in to comment.