Example usage for com.vaadin.ui TabSheet getTab

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

Introduction

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

Prototype

public Tab getTab(int index) 

Source Link

Document

Returns the Tab (metadata) with the given index.

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.esn.esobase.view.tab.ChangePasswordTab.java

private void changePasswordAction() {
    sysAccountService.updateUserPassword(SpringSecurityHelper.getSysAccount(), password.getValue());
    Notification n = new Notification(" ?", " ? ",
            Notification.Type.HUMANIZED_MESSAGE);
    n.setDelayMsec(2000);//from w  ww. j  a v  a  2  s .  co m
    n.show(getUI().getPage());
    TabSheet tabs = (TabSheet) this.getParent();
    tabs.removeTab(tabs.getTab(this));

}

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

License:Open Source License

/**
 * This method enables or disables all tabs in a tabSheet. Therefore the
 * <code>ViewStatechangedEvent</code> is used. If the new view state is Edit
 * the method returns the last selected tab position. If the new view state
 * is not Edit the " <code>oldSelectedTabPosition</code>" is selected in the
 * given <code>tabSheet</code>.
 * /*from w w w . j  av  a 2 s.  c  o  m*/
 * @param tabSheet
 *            the tabsheet to enable or disable all tabs in
 * @param event
 * @param oldSelectedTabPosition
 *            which tab was selected before view state was Edit
 * @return
 */
public static int enableTabs(final TabSheet tabSheet, final ViewStateChangedEvent event,
        final int oldSelectedTabPosition) {
    boolean editMode = event.getNewState().isEdit();
    boolean enabled = !editMode;
    int newSelectedTabPosition = 0;
    // remember which tab was selected (before editing)
    if (editMode)
        newSelectedTabPosition = getSelectedTabPosition(tabSheet);
    // disable or enable
    for (int i = 0; i < tabSheet.getComponentCount(); i++)
        tabSheet.getTab(i).setEnabled(enabled);
    // select tab depending on selection (after editing)
    if (!editMode)
        tabSheet.setSelectedTab(tabSheet.getTab(oldSelectedTabPosition));
    // return currently selected tab
    return editMode ? newSelectedTabPosition : getSelectedTabPosition(tabSheet);
}

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.opennms.features.vaadin.datacollection.DataCollectionGroupPanel.java

License:Open Source License

@Override
public void selectedTabChange(SelectedTabChangeEvent event) {
    TabSheet tabsheet = event.getTabSheet();
    Tab tab = tabsheet.getTab(tabsheet.getSelectedTab());
    if (tab != null) {
        Notification.show("Selected tab: " + tab.getCaption());
    }/*from   w  w  w .  ja v a2  s  .  c  o  m*/
}

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/* w w w . jav  a 2 s  . co  m*/
    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));//from w  w  w.j  av a  2s .  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) {
    // ?   /*from ww  w .  j  a  v  a2 s . c  om*/
    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);
}

From source file:uicomponents.PoolingTable.java

License:Open Source License

public PoolingTable(String name, TabSheet selectionTables, Map<Integer, Integer> usedTimes,
        List<String> factorLabels) {
    this.selectionTables = selectionTables;
    all = (Table) selectionTables.getTab(0).getComponent();
    used = (Table) selectionTables.getTab(1).getComponent();
    labels = factorLabels;/*from w ww .ja v a  2 s .  co  m*/

    this.usedTimes = usedTimes;
    setSpacing(true);

    HorizontalLayout tableButtonComponent = new HorizontalLayout();
    tableButtonComponent.setCaption("Sample Pool");
    tableButtonComponent.setSpacing(true);
    secondaryName = new StandardTextField("Secondary Name");
    secondaryName.setValue(name);
    secondaryName.setStyleName(Styles.fieldTheme);
    moveLeft = new Button();
    Styles.iconButton(moveLeft, FontAwesome.ARROW_CIRCLE_LEFT);

    moveLeft.addStyleName("large_font_awesome");
    addComponent(secondaryName);
    poolIDs = new HashSet<Integer>();
    poolTable = new Table();
    initTable();
    tableButtonComponent.addComponent(poolTable);
    tableButtonComponent.addComponent(moveLeft);
    addComponent(Styles.questionize(tableButtonComponent,
            "You can add samples to the active pool by " + "selecting them from the right and clicking "
                    + FontAwesome.ARROW_CIRCLE_LEFT.getHtml() + " or by dragging them over with your mouse.",
            "Adding Samples to Pools"));

    initDragAndDrop(new Or(new SourceIs(all), new SourceIs(used)));
    initButtonMover(all, used);
}

From source file:v7cr.ReviewList.java

License:Open Source License

public void itemClick(ItemClickEvent event) {
    TabSheet tabs = (TabSheet) getParent();
    Object iid = event.getItemId();
    if (iid instanceof ObjectId) {
        // find existing tab
        int count = tabs.getComponentCount();
        for (int i = 0; i < count; i++) {
            Component x = tabs.getTab(i).getComponent();
            if (x instanceof ReviewTab && ((ReviewTab) x).reviewId.equals(iid)) {
                tabs.setSelectedTab(x);/*from  www  .  j  a  va2s .  com*/
                return;
            }
        }
        Tab t = tabs.addTab(new ReviewTab((ObjectId) iid));
        t.setClosable(true);

        tabs.setSelectedTab(t.getComponent());
    }
}