Example usage for com.vaadin.ui TabSheet addTab

List of usage examples for com.vaadin.ui TabSheet addTab

Introduction

In this page you can find the example usage for com.vaadin.ui TabSheet addTab.

Prototype

public Tab addTab(Component c, String caption, Resource icon) 

Source Link

Document

Adds a new tab into TabSheet.

Usage

From source file:org.opennms.features.vaadin.nodemaps.internal.NodeMapsApplication.java

License:Open Source License

/**
 * Gets a {@link TabSheet} view for all widgets in this manager.
 * /* w  w  w  .  j av  a  2  s  .  c  o m*/
 * @return TabSheet
 */
private Component getTabSheet() {
    // Use an absolute layout for the bottom panel
    AbsoluteLayout bottomLayout = new AbsoluteLayout();
    bottomLayout.setSizeFull();

    final TabSheet tabSheet = new TabSheet();
    tabSheet.setSizeFull();

    for (final SelectionAwareTable view : new SelectionAwareTable[] { m_alarmTable, m_nodeTable }) {
        // Icon can be null
        tabSheet.addTab(view, (view == m_alarmTable ? "Alarms" : "Nodes"), null);

        // If the component supports the HasExtraComponents interface, then add the extra 
        // components to the tab bar
        try {
            final Component[] extras = ((HasExtraComponents) view).getExtraComponents();
            if (extras != null && extras.length > 0) {
                // For any extra controls, add a horizontal layout that will float
                // on top of the right side of the tab panel
                final HorizontalLayout extraControls = new HorizontalLayout();
                extraControls.setHeight(32, Unit.PIXELS);
                extraControls.setSpacing(true);

                // Add the extra controls to the layout
                for (final Component component : extras) {
                    extraControls.addComponent(component);
                    extraControls.setComponentAlignment(component, Alignment.MIDDLE_RIGHT);
                }

                // Add a TabSheet.SelectedTabChangeListener to show or hide the extra controls
                tabSheet.addSelectedTabChangeListener(new SelectedTabChangeListener() {
                    @Override
                    public void selectedTabChange(final SelectedTabChangeEvent event) {
                        final TabSheet source = (TabSheet) event.getSource();
                        if (source == tabSheet) {
                            // Bizarrely enough, getSelectedTab() returns the contained
                            // Component, not the Tab itself.
                            //
                            // If the first tab was selected...
                            if (source.getSelectedTab() == view) {
                                extraControls.setVisible(true);
                            } else {
                                extraControls.setVisible(false);
                            }
                        }
                    }
                });

                // Place the extra controls on the absolute layout
                bottomLayout.addComponent(extraControls, "top:0px;right:5px;z-index:100");
            }
        } catch (ClassCastException e) {
        }
        view.setSizeFull();
    }

    // Add the tabsheet to the layout
    bottomLayout.addComponent(tabSheet, "top: 0; left: 0; bottom: 0; right: 0;");

    return bottomLayout;
}

From source file:ro.zg.netcell.vaadin.action.UserActionListHandler.java

License:Apache License

@Override
public void handle(final ActionContext actionContext) throws Exception {
    ComponentContainer displayArea = actionContext.getTargetContainer();
    displayArea.removeAllComponents();//from www .java  2s  .  com

    UserActionList ual = (UserActionList) actionContext.getUserAction();
    final OpenGroupsApplication app = actionContext.getApp();
    final Entity entity = actionContext.getEntity();

    final TabSheet actionsTabSheet = new TabSheet();
    actionsTabSheet.addStyleName(Reindeer.TABSHEET_MINIMAL);
    //   actionsTabSheet.addStyleName(OpenGroupsStyles.USER_ACTION_CONTENT_PANE);
    actionsTabSheet.addStyleName(OpenGroupsStyles.USER_ACTIONS_TABSHEET);
    //   final CssLayout contentArea = new CssLayout();
    //   contentArea.setWidth("100%");
    //   contentArea.setStyleName(OpenGroupsStyles.USER_ACTION_CONTENT_PANE);
    //   displayArea.addComponent(contentArea);

    /* add listener */
    actionsTabSheet.addListener(new SelectedTabChangeListener() {

        @Override
        public void selectedTabChange(SelectedTabChangeEvent event) {
            TabSheet tabSheet = event.getTabSheet();

            AbstractComponentContainer selectedTabContent = (AbstractComponentContainer) tabSheet
                    .getSelectedTab();
            UserAction ua = (UserAction) selectedTabContent.getData();
            if (entity != null) {
                Deque<String> desiredActionsQueue = entity.getState().getDesiredActionTabsQueue();
                /*
                 * if a desired action exists, it will be set afterwards, otherwise allow the first action from the
                 * list to be selected by default
                 */
                if (desiredActionsQueue.size() != 0) {
                    String nextAction = desiredActionsQueue.peek();
                    if (nextAction.equals(ua.getActionName())) {
                        /* remove action from the queue */
                        desiredActionsQueue.remove();
                    } else {
                        /*
                         * if this action does not match with the next desired action, do nothing
                         */
                        return;
                    }
                } else {
                    entity.getState().resetPageInfo();
                }
            }

            if (ua instanceof UserActionList) {
                //          selectedTabContent.removeStyleName(OpenGroupsStyles.USER_ACTION_CONTENT_PANE);
                //          contentArea.setWidth("100%");
                //          contentArea.setMargin(false);
                //          selectedTabContent.setMargin(false);

                ua.executeHandler(entity, app, selectedTabContent, false, actionContext);

            } else {
                //          selectedTabContent.addStyleName(OpenGroupsStyles.USER_ACTION_CONTENT_PANE);
                //          contentArea.setWidth("99.5%");
                //          contentArea.setMargin(true);
                //          selectedTabContent.setMargin(true);
                //          selectedTabContent.setWidth("100%");
                if (entity != null) {
                    entity.getState().setCurrentTabAction(ua);
                    entity.getState().setCurrentTabActionContainer(selectedTabContent);
                    entity.getState().setCurrentActionsPath(ua.getFullActionPath());
                    //         entity.getState().getDesiredActionTabsQueue().clear();
                    //         entity.getState().resetPageInfoForCurrentAction();
                    actionContext.getWindow().setFragmentToEntity(entity);
                }
                ua.executeHandler(entity, app, selectedTabContent, false, actionContext);

            }

        }
    });
    /* add the tabsheet to the target component */

    //   List<String> currentUserTypes = getCurrentUserTypes(entity, app);
    Map<String, ComponentContainer> actionPathContainers = new HashMap<String, ComponentContainer>();
    List<UserAction> actionsList = new ArrayList<UserAction>(ual.getActions().values());
    for (UserAction cua : actionsList) {

        /* display only the actions that the user is allowed to see */
        //       if (!cua.allowRead(currentUserTypes)) {
        if (!cua.isVisible(actionContext)) {
            continue;
        }

        CssLayout tabContent = new CssLayout();
        if (cua instanceof UserActionList) {
            //      tabContent.setMargin(false);
            //      contentArea.setMargin(false);
            //      tabContent.addStyleName(OpenGroupsStyles.USER_ACTION_CONTENT_PANE);
            //      tabContent.setWidth("100%");

        } else {
            //      tabContent.addStyleName(OpenGroupsStyles.USER_ACTION_CONTENT_PANE);
            tabContent.setMargin(true);
            //      contentArea.addStyleName(OpenGroupsStyles.USER_ACTION_CONTENT_PANE);
            //      contentArea.setMargin(true);
        }
        tabContent.addStyleName(OpenGroupsStyles.USER_ACTION_CONTENT_PANE);
        actionPathContainers.put(cua.getActionName(), tabContent);
        tabContent.setData(cua);
        actionsTabSheet.addTab(tabContent, cua.getDisplayName(), null);
    }

    displayArea.addComponent(actionsTabSheet);
    if (entity != null) {
        Deque<String> desiredActionsQueue = entity.getState().getDesiredActionTabsQueue();

        if (desiredActionsQueue.size() != 0) {
            // System.out.println("desired actions: " +
            // entity.getState().getDesiredActionsPath());
            // System.out.println("full url: "+app.getFullUrl());
            /* select the tab specified by the next desired action */
            actionsTabSheet.setSelectedTab(actionPathContainers.get(desiredActionsQueue.peek()));
        }
    }
}

From source file:ru.codeinside.gses.webui.components.UserInfoPanel.java

License:Mozilla Public License

public static UserInfoPanel addClosableToTabSheet(TabSheet tabSheet, String login) {
    UserInfoPanel uip = new UserInfoPanel(login);
    Tab tab = tabSheet.addTab(uip, login, new ThemeResource("../runo/icons/16/user.png"));
    tab.setDescription("     ??");
    tab.setClosable(true);// w w w.  ja v a  2 s  .com
    return uip;
}