List of usage examples for com.google.gwt.user.client.ui TabPanel addSelectionHandler
public HandlerRegistration addSelectionHandler(SelectionHandler<Integer> handler)
From source file:ro.zg.opengroups.gwt.client.views.EntityUserActionsTabView.java
License:Apache License
private void addCommandDefinitionsList(final CommandDefinitionsList cdl, final List<Integer> desiredActionPath, final TabPanel tabPanel) { final Map<Integer, CommandDefinition> commandsMap = new LinkedHashMap<Integer, CommandDefinition>(); final Map<Integer, BaseGwtView> viewsMap = new HashMap<Integer, BaseGwtView>(); if (cdl != null) { int tabIndex = 0; for (CommandDefinition cd : cdl.getCommandDefinitions().values()) { commandsMap.put(tabIndex, cd); if (cd instanceof CommandDefinitionsList) { EntityUserActionsTabView newView = (EntityUserActionsTabView) createViewForType( ViewsTypes.ENTITY_USER_ACTIONS_TAB_VIEW, this); TabPanel currentTabPanel = newView.construct(); currentTabPanel.getTabBar().setStylePrimaryName("og-CommandsTabBar"); currentTabPanel.getDeckPanel().setStylePrimaryName("og-CommandsTabPanelBottom"); tabPanel.add(currentTabPanel, cd.getDisplayName()); viewsMap.put(tabIndex, newView); } else { BaseGwtView newView = (BaseGwtView) createViewForCommand(cd.getActionName(), this); tabPanel.add(newView.construct(), cd.getDisplayName()); viewsMap.put(tabIndex, newView); }//from w w w . j av a2s. c o m tabIndex++; } /* set the selection listener */ handlerReg = tabPanel.addSelectionHandler(new SelectionHandler<Integer>() { public void onSelection(SelectionEvent<Integer> event) { Integer si = event.getSelectedItem(); updateCurrentActionPath(si); BaseGwtView view = viewsMap.get(si); if (view instanceof EntityUserActionsTabView) { ((EntityUserActionsTabView) view).update((CommandDefinitionsList) commandsMap.get(si), desiredActionPath, new ArrayList<Integer>(currentActionPath)); } else { CommandDefinition cd = commandsMap.get(si); UserEvent userEvent = new UserEvent(); userEvent.setSourceViewType(getViewType()); userEvent.setElementId(COMMANDS_TAB); userEvent.setEventType(UserEvent.CLICK); userEvent.addEventParam(UserEventParams.COMMAND_ID, cd.getUniqueCommandDesc()); userEvent.addEventParam(OpenGroupsParams.CURRENT_TAB_ACTION_PATH, new ArrayList<Integer>(currentActionPath)); userEvent.setTargetViewId(view.getId()); System.out.println(userEvent.getFullEventType()); dispatchEventToManager(userEvent); } } }); /* if didn't tell otherwise, select the first action */ int nextIndex = 0; /* select the desired action */ if (desiredActionPath != null && desiredActionPath.size() > 0) { nextIndex = desiredActionPath.remove(0); } currentActionPath.add(nextIndex); tabPanel.selectTab(nextIndex); } }