import org.eclipse.jface.action.Action; //导入方法依赖的package包/类
@Override
public void menuAboutToShow(final IMenuManager menuManager) {
// add the navigate to HOME page command.
final TeamExplorerNavigationItemConfig homeNavItem = configuration.getHomeNavigationItem();
final Action homeAction = new Action(configuration.getHomeNavigationItem().getTitle()) {
@Override
public void run() {
navigator.navigateToItem(configuration.getHomeNavigationItem());
}
};
homeAction.setId(homeNavItem.getID());
menuManager.add(homeAction);
// Add navigate commands for each visible page except Settings (it
// goes at the end)
for (final TeamExplorerNavigationItemConfig navItem : configuration.getNavigationItems()) {
// Determine if the navigation item is visible in the current
// context and and create an action item if it is.
final ITeamExplorerNavigationItem instance = navItem.createInstance();
if (instance.isVisible(context)) {
final Action action = new Action(navItem.getTitle()) {
@Override
public void run() {
final String viewID = navItem.getViewID();
// do specific if targetPageID is null
if (navItem.getTargetPageID() == null) {
instance.clicked(context);
}
// viewID not null -> check undocked views
else if (viewID != null && TeamExplorerHelpers.isViewUndocked(viewID)) {
TeamExplorerHelpers.showView(viewID);
}
// other cases -> navigate in Team Explorer view
else {
navigator.navigateToItem(navItem);
}
}
};
/*
* The navigation item ID is used to determine which action
* matches the currently shown navigation item so that the
* menu listener can properly set the check mark on the
* currently displayed navigation item.
*/
action.setId(navItem.getID());
// Add the action to the context menu.
menuManager.add(action);
}
}
menuManager.add(new Separator());
// create the project/team fly out menu. "Connect to server" is
// always
// present so the menu won't be empty and omitted when disconnected.
String subMenuTitle;
if (TeamExplorerHelpers.supportsTeam(context)) {
subMenuTitle = Messages.getString("TeamExplorerControl.ProjectsAndMyTeamsSubMenuText"); //$NON-NLS-1$
} else {
subMenuTitle = Messages.getString("TeamExplorerControl.ProjectsSubMenuText"); //$NON-NLS-1$
}
final IMenuManager subMenu = new MenuManager(subMenuTitle);
subMenu.setRemoveAllWhenShown(true);
subMenu.addMenuListener(projectsMenuListener);
subMenu.add(new ConnectToServerAction());
menuManager.add(subMenu);
setCheckedItem(menuManager);
}