Example usage for com.vaadin.ui TabSheet getTabPosition

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

Introduction

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

Prototype

public int getTabPosition(Tab tab) 

Source Link

Document

Gets the position of the tab.

Usage

From source file:org.eclipse.hawkbit.ui.rollout.rollout.AddUpdateRolloutWindowLayout.java

License:Open Source License

private static int getPositionOfSelectedTab(final TabSheet tabSheet) {
    return tabSheet.getTabPosition(tabSheet.getTab(tabSheet.getSelectedTab()));
}

From source file:org.opennms.features.jmxconfiggenerator.webui.ui.UIHelper.java

License:Open Source License

private static int getSelectedTabPosition(final TabSheet tabSheet) {
    if (tabSheet == null)
        return 0;
    if (tabSheet.getSelectedTab() == null)
        return 0;
    if (tabSheet.getTab(tabSheet.getSelectedTab()) == null)
        return 0;
    return tabSheet.getTabPosition(tabSheet.getTab(tabSheet.getSelectedTab()));
}

From source file:org.sensorhub.ui.GenericConfigForm.java

License:Mozilla Public License

protected Component buildTabs(final String propId, final ContainerProperty prop, final FieldGroup fieldGroup) {
    GridLayout layout = new GridLayout();
    layout.setWidth(100.0f, Unit.PERCENTAGE);

    // title bar//from w  w w  .ja v a 2s.c om
    HorizontalLayout titleBar = new HorizontalLayout();
    titleBar.setMargin(new MarginInfo(true, false, false, false));
    titleBar.setSpacing(true);
    String label = prop.getLabel();
    if (label == null)
        label = DisplayUtils.getPrettyName((String) propId);

    Label sectionLabel = new Label(label);
    sectionLabel.setDescription(prop.getDescription());
    sectionLabel.addStyleName(STYLE_H3);
    sectionLabel.addStyleName(STYLE_COLORED);
    titleBar.addComponent(sectionLabel);
    layout.addComponent(titleBar);

    // create one tab per item in container
    final MyBeanItemContainer<Object> container = prop.getValue();
    final TabSheet tabs = new TabSheet();
    tabs.setSizeFull();
    int i = 1;
    for (Object itemId : container.getItemIds()) {
        MyBeanItem<Object> childBeanItem = (MyBeanItem<Object>) container.getItem(itemId);
        IModuleConfigForm subform = AdminUI.getInstance().generateForm(childBeanItem.getBean().getClass());
        subform.build(null, childBeanItem);
        ((MarginHandler) subform).setMargin(new MarginInfo(true, false, true, false));
        allForms.add(subform);
        Tab tab = tabs.addTab(subform, "Item #" + (i++));
        tab.setClosable(true);

        // store item id so we can map a tab with the corresponding bean item
        ((AbstractComponent) subform).setData(itemId);
    }

    // draw icon on last tab to add new items
    tabs.addTab(new VerticalLayout(), "", UIConstants.ADD_ICON);

    // catch close event to delete item
    tabs.setCloseHandler(new CloseHandler() {
        private static final long serialVersionUID = 1L;

        @Override
        public void onTabClose(TabSheet tabsheet, Component tabContent) {
            final Tab tab = tabs.getTab(tabContent);

            final ConfirmDialog popup = new ConfirmDialog(
                    "Are you sure you want to delete " + tab.getCaption() + "?</br>All settings will be lost.");
            popup.addCloseListener(new CloseListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void windowClose(CloseEvent e) {
                    if (popup.isConfirmed()) {
                        // retrieve id of item shown on tab
                        AbstractComponent tabContent = (AbstractComponent) tab.getComponent();
                        Object itemId = tabContent.getData();

                        // remove from UI
                        int deletedTabPos = tabs.getTabPosition(tab);
                        tabs.removeTab(tab);
                        tabs.setSelectedTab(deletedTabPos - 1);

                        // remove from container
                        container.removeItem(itemId);
                    }
                }
            });

            popup.setModal(true);
            AdminUI.getInstance().addWindow(popup);
        }
    });

    // catch select event on '+' tab to add new item
    tabs.addSelectedTabChangeListener(new SelectedTabChangeListener() {
        private static final long serialVersionUID = 1L;

        public void selectedTabChange(SelectedTabChangeEvent event) {
            Component selectedTab = event.getTabSheet().getSelectedTab();
            final Tab tab = tabs.getTab(selectedTab);
            final int selectedTabPos = tabs.getTabPosition(tab);

            // case of + tab to add new item
            if (tab.getCaption().equals("")) {
                tabs.setSelectedTab(selectedTabPos - 1);

                try {
                    // show popup to select among available module types
                    String title = "Please select the desired option";
                    Map<String, Class<?>> typeList = GenericConfigForm.this.getPossibleTypes(propId);
                    ObjectTypeSelectionPopup popup = new ObjectTypeSelectionPopup(title, typeList,
                            new ObjectTypeSelectionCallback() {
                                public void typeSelected(Class<?> objectType) {
                                    try {
                                        // add new item to container
                                        MyBeanItem<Object> childBeanItem = container.addBean(
                                                objectType.newInstance(), ((String) propId) + PROP_SEP);

                                        // generate form for new item
                                        IModuleConfigForm subform = AdminUI.getInstance()
                                                .generateForm(childBeanItem.getBean().getClass());
                                        subform.build(null, childBeanItem);
                                        ((MarginHandler) subform)
                                                .setMargin(new MarginInfo(true, false, true, false));
                                        allForms.add(subform);

                                        // add new tab and select it
                                        Tab newTab = tabs.addTab(subform, "Item #" + (selectedTabPos + 1), null,
                                                selectedTabPos);
                                        newTab.setClosable(true);
                                        tabs.setSelectedTab(newTab);
                                    } catch (Exception e) {
                                        Notification.show("Error", e.getMessage(),
                                                Notification.Type.ERROR_MESSAGE);
                                    }
                                }
                            });
                    popup.setModal(true);
                    AdminUI.getInstance().addWindow(popup);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    // also register commit handler
    fieldGroup.addCommitHandler(new CommitHandler() {
        private static final long serialVersionUID = 1L;

        @Override
        public void preCommit(CommitEvent commitEvent) throws CommitException {
        }

        @Override
        public void postCommit(CommitEvent commitEvent) throws CommitException {
            // make sure new items are transfered to model
            prop.setValue(prop.getValue());
        }
    });

    layout.addComponent(tabs);
    return layout;
}

From source file:org.vaadin.addon.twitter.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    Responsive.makeResponsive(this);
    CssLayout info = new CssLayout();
    info.setStyleName("tw-docs");
    info.addComponent(markdown.get(0));/* w w  w.ja  v  a  2 s .  c o  m*/

    TabSheet tabSheet = new TabSheet();
    tabSheet.setStyleName("tw-demo-tab");
    tabSheet.addStyleName(ValoTheme.TABSHEET_CENTERED_TABS);
    tabSheet.setSizeFull();
    tabSheet.addTab(new TimelineDemo()).setCaption("Timeline");
    tabSheet.addTab(new TweetDemo()).setCaption("Single Tweet");
    tabSheet.addTab(new ButtonDemo(TweetButton.Type.Follow)).setCaption("Follow Button");
    tabSheet.addTab(new ButtonDemo(TweetButton.Type.Share)).setCaption("Share Button");
    tabSheet.addTab(new ButtonDemo(TweetButton.Type.Hashtag)).setCaption("Hashtag Button");
    tabSheet.addTab(new ButtonDemo(TweetButton.Type.Mention)).setCaption("Mention Button");
    tabSheet.addSelectedTabChangeListener(event -> {
        Component old = info.getComponent(0);
        Component newComp = markdown.get(tabSheet.getTabPosition(tabSheet.getTab(tabSheet.getSelectedTab())));
        info.replaceComponent(old, newComp);
    });
    final MHorizontalLayout layout = new MHorizontalLayout(info, tabSheet).withExpand(info, 4)
            .withExpand(tabSheet, 6).withFullWidth().withFullHeight().withMargin(false).withSpacing(true);
    setContent(new MPanel(layout).withFullWidth().withFullHeight().withStyleName(ValoTheme.PANEL_WELL,
            "root-container"));

}

From source file:ru.codeinside.gses.webui.executor.ExecutorFactory.java

License:Mozilla Public License

static private void showForm(final TabSheet tabs, final String taskId) {
    // ?   /*  ww  w .j a v  a  2s .  co  m*/
    for (int i = tabs.getComponentCount(); i > 0; i--) {
        final Tab tab = tabs.getTab(i - 1);
        if (tab.getComponent() instanceof WithTaskId) {
            if (taskId.equals(((WithTaskId) tab.getComponent()).getTaskId())) {
                tabs.setSelectedTab(tab);
                return;
            }
        }
    }
    DataAccumulator accumulator = new DataAccumulator();
    ExecutorService executorService = Flash.flash().getExecutorService();
    final FormDescription formDescription = Functions
            .withEngine(new FormDescriptionBuilder(FormID.byTaskId(taskId), executorService, accumulator));
    final TaskForm taskForm = new TaskForm(formDescription, new TaskForm.CloseListener() {

        private static final long serialVersionUID = 3726145663843346543L;

        @Override
        public void onFormClose(final TaskForm form) {
            final TabSheet.Tab tab = tabs.getTab(tabs.getSelectedTab());
            int pos = tabs.getTabPosition(tab);
            tabs.removeTab(tab);
            int count = tabs.getComponentCount();
            tabs.setSelectedTab(count == pos ? pos - 1 : pos);
        }
    }, accumulator);
    final Tab tab = tabs.addTab(taskForm, formDescription.task.getName());
    tab.setDescription("? \"" + formDescription.processDefinition.getName() + "\"");
    tabs.setSelectedTab(tab);
}