Example usage for com.vaadin.ui TabSheet setSelectedTab

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

Introduction

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

Prototype

public void setSelectedTab(int index) 

Source Link

Document

Sets the selected tab, identified by its index.

Usage

From source file:dhbw.clippinggorilla.userinterface.windows.PreferencesWindow.java

public PreferencesWindow(User user) {
    //setHeight("480px");
    //setWidth("720px");

    VerticalLayout windowContent = new VerticalLayout();
    windowContent.setWidth("100%");
    windowContent.setHeight("100%");
    windowContent.setMargin(new MarginInfo(true, false, false, false));

    TabSheet preferencesCategories = new TabSheet();
    preferencesCategories.setWidth("100%");
    preferencesCategories.setHeight("100%");
    preferencesCategories.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
    preferencesCategories.addStyleName(ValoTheme.TABSHEET_ICONS_ON_TOP);
    preferencesCategories.addStyleName(ValoTheme.TABSHEET_CENTERED_TABS);
    windowContent.addComponent(preferencesCategories);
    windowContent.setExpandRatio(preferencesCategories, 1f);

    preferencesCategories.addComponent(buildUserTab(user));
    preferencesCategories.addComponent(buildClippingsTab(user));
    preferencesCategories.addComponent(buildSupportTab(user));
    preferencesCategories.setSelectedTab(0);

    windowContent.addComponent(buildFooter(user));

    setContent(windowContent);// w  w w .  j av  a  2 s  .  com
    setModal(true);
    addCloseShortcut(KeyCode.ENTER, null);
    setResizable(false);
    setClosable(false);
    setHeight("480px");
    setWidth("720px");
}

From source file:life.qbic.components.OfferGeneratorTab.java

License:Open Source License

/**
 * adds all the listeners to the offer generator tab
 * @param db: database instance to query
 * @param managerTabs: TabSheet holding the three tabs (Offer Generator, Offer Manager and Package Manager)
 * @param selectedProjectComboBox: ComboBox for selecting the project for the offer to generate
 * @param completeButton: button to complete the offer
 * @param addPackLayout: vertical layout which holds the twin select for selecting the packages, the package
 *                     description panel and the button to complete the offer
 * @param selectPackagesTwinColSelect: TwinSelect to select the packages for the current offer
 * @param packageDescriptionPanel: panel holding the descriptions labels for the selected packages
 * @param packageDescriptionLabel: label holding the description for the packages
 * @param twinColSelectFilter: text field for filtering the left side of the TwinColSelect
 *///w  ww . java 2s  .  com
private static void addListeners(Database db, TabSheet managerTabs, ComboBox selectedProjectComboBox,
        Button completeButton, VerticalLayout addPackLayout, TwinColSelect selectPackagesTwinColSelect,
        Panel packageDescriptionPanel, Label packageDescriptionLabel, TextField twinColSelectFilter) {

    final float[] totalPrice = new float[1];
    final String[] descriptionText = new String[1];
    final String[][] offerGeneratorPackageNames = new String[1][1];
    final String[][] offerGeneratorPackageIds = new String[1][1];

    selectedProjectComboBox.addValueChangeListener(new Property.ValueChangeListener() {

        /**
         *
         */
        private static final long serialVersionUID = 6871999698387032993L;

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (selectedProjectComboBox.getValue() == null) {
                displayNotification("oO! No project selected!",
                        "Please select a project to proceed, otherwise we are going to have a situation here! ;)",
                        "error");
            } else {
                addPackLayout.addComponent(twinColSelectFilter);
                addPackLayout.addComponent(selectPackagesTwinColSelect);
                addPackLayout.addComponent(packageDescriptionPanel);
                addPackLayout.addComponent(completeButton);
            }
        }
    });

    selectPackagesTwinColSelect.addValueChangeListener(new Property.ValueChangeListener() {

        /**
         *
         */
        private static final long serialVersionUID = -5813954665588509117L;

        @Override
        public void valueChange(Property.ValueChangeEvent event) {

            // get the packages (package_id: package_name) as comma separated string and remove the leading and trailing bracket
            String selectedPackages = selectPackagesTwinColSelect.getValue().toString().substring(1);
            selectedPackages = selectedPackages.substring(0, selectedPackages.length() - 1);

            // in case there is no package selected, we do nothing
            if (selectedPackages.length() == 0) {
                return;
            }

            // init the arrays holding the package names and package ids
            offerGeneratorPackageNames[0] = selectedPackages.split(",");
            offerGeneratorPackageIds[0] = selectedPackages.split(",");

            // split the package id and the package name
            for (int i = 0; i < offerGeneratorPackageNames[0].length; i++) {
                offerGeneratorPackageIds[0][i] = offerGeneratorPackageIds[0][i].split(": ", 2)[0];
                offerGeneratorPackageNames[0][i] = offerGeneratorPackageNames[0][i].split(": ", 2)[1];
            }

            // TODO: value change listener does not trigger if the last element from the twin col select gets deselected
            System.out.println("packages in twin col select:");
            System.out.println(selectPackagesTwinColSelect.getValue());

            // there is a package for the current project, so we enable the complete offer button
            if (selectPackagesTwinColSelect.getValue() != null) {
                completeButton.setEnabled(true);
            } else {
                completeButton.setEnabled(false);
            }

            assert offerGeneratorPackageNames[0].length == offerGeneratorPackageIds[0].length;

            // iterate over all of the packages for the current offer and add their price and description to the view
            descriptionText[0] = "";
            totalPrice[0] = 0;
            for (int i = 0; i < offerGeneratorPackageNames[0].length; i++) {

                int currentPackageId = Integer.valueOf(offerGeneratorPackageIds[0][i].trim());

                // calculate the total offer price
                try {
                    totalPrice[0] += Float.parseFloat(db.getPriceFromPackageId(currentPackageId, "internal"));
                } catch (NullPointerException e) {
                    displayNotification("Package price is null!",
                            "The package price of the package " + offerGeneratorPackageIds[0][i] + ": "
                                    + offerGeneratorPackageNames[0][i] + " is null. Please remove the "
                                    + "package from the offer or update the "
                                    + "package price on the package manager tab. Otherwise "
                                    + "bad stuff is expected to happen..",
                            "error");
                }

                // get the description for the current package
                descriptionText[0] = descriptionText[0] + "<tr><td><p><b>" + offerGeneratorPackageIds[0][i]
                        + ": " + offerGeneratorPackageNames[0][i] + "</b><br>"
                        + db.getPackageDescriptionFromPackageId(currentPackageId)
                        + "</td><td align='right' valign='top'>"
                        + db.getPriceFromPackageId(currentPackageId, "internal") + "</td>" + "</p></tr>";

                // add the description and the total price to the view
                if (offerGeneratorPackageNames[0][i].length() != 0)
                    packageDescriptionLabel.setValue(
                            "<table width='100%'><tr><td><p style='color:red;'><b>Package Name and Description</b></p>"
                                    + "</td><td align='right'><p style='color:red;'><b>Price</b></p></td></tr><tr> </tr>"
                                    + descriptionText[0]
                                    + "<tr><td><p style='color:red;'><b>Grand Total</b> (excl. Taxes)</p></td><td align='right'>"
                                    + "<p style='color:red;'><b>" + totalPrice[0]
                                    + "</b></p></td></tr></table>");
                else
                    packageDescriptionLabel.setValue("No description available!");
            }
        }

    });

    completeButton.addClickListener(new Button.ClickListener() {

        /**
         *
         */
        private static final long serialVersionUID = 8181926819540586585L;

        @Override
        public void buttonClick(Button.ClickEvent event) {

            // get some fields for the current offer
            String offerProjectReference = selectedProjectComboBox.getValue().toString();
            String dateToday = new SimpleDateFormat("yyyyMMdd").format(new Date());
            String offerNumber = dateToday + "_" + offerProjectReference;
            String offerFacility = db.getPIFromProjectRef(offerProjectReference);
            String offerName = db.getShortTitleFromProjectRef(offerProjectReference);
            String offerDescription = db.getLongDescFromProjectRef(offerProjectReference);

            // register the new offer in the database; NOTE: internal has no functionality anymore, so we simply set it to
            // true
            int offerId = db.registerNewOffer(offerNumber, offerProjectReference, offerFacility, offerName,
                    offerDescription, totalPrice[0], new Date(), "temp", true);

            // TODO: if a liferay instance is running uncomment this and remove the call to db.registerNewOffer above
            /*        offerId =
                        db.registerNewOffer(offerNumber, offerProjectReference, offerFacility, offerName,
                            offerDescription, totalPrice, dNow,
                            LiferayAndVaadinUtils.getUser().getScreenName(), externalPriceSelectedCheckBox.getValue());
                    */

            // iterate over the packages from the current offer and insert them also in the database
            for (String packageId : offerGeneratorPackageIds[0]) {
                int currentPackageId = Integer.valueOf(packageId);
                float packageUnitPrice = Float.valueOf(db.getPriceFromPackageId(currentPackageId, "internal"));
                db.insertOrUpdateOffersPackages(offerId, currentPackageId, packageUnitPrice);
            }

            displayNotification("Perfect! Offer successfully saved in the Database!",
                    "Next step is to modify, finalize and send it to the customer. Keep in mind that the "
                            + "description of the offer is still missing. Please go ahead and complete it. Fingers crossed!",
                    "success");

            // change view to offer manager
            managerTabs.setSelectedTab(1);
        }
    });
}

From source file:org.lunifera.runtime.web.vaadin.databinding.component.internal.TabSheetSelectedTabProperty.java

License:Open Source License

@Override
protected void doSetValue(Object source, Object value) {
    TabSheet component = (TabSheet) source;
    component.setSelectedTab((Component) value);
}

From source file:org.openeos.services.ui.vaadin.internal.OpenWindowCommand.java

License:Apache License

@Override
public void menuSelected(MenuItem selectedItem) {
    if (windowComponent == null)
        windowComponent = windowFactory.createWindowComponent(window, application);
    final TabSheet tabSheet = application.getConcreteApplication().getMainTabSheet();
    tabSheet.addListener(new ComponentContainer.ComponentDetachListener() {

        private static final long serialVersionUID = 1L;

        @Override// www  . j  av a2  s. c om
        public void componentDetachedFromContainer(ComponentDetachEvent event) {
            if (event.getDetachedComponent() == windowComponent) {
                windowComponent = null;
                tabSheet.removeListener(this);
            }
        }
    });
    Tab tab = tabSheet.addTab(windowComponent, window.getName());
    tab.setClosable(true);
    tab.setDescription(window.getDescription());
    tabSheet.setSelectedTab(tab);
}

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>.
 * //w w  w  .ja  v a 2  s .  c om
 * @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.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 .  j a  va  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: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();//w  w  w.  j  a  v a 2  s. co m

    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.adm.ui.AdminApp.java

License:Mozilla Public License

@Override
public void init() {
    setUser(Flash.login());/*from  www .j  a v a 2 s  .  co  m*/
    setTheme("custom");

    TabSheet t = new TabSheet();
    t.addStyleName(Reindeer.TABSHEET_MINIMAL);
    t.setSizeFull();
    t.setCloseHandler(new DelegateCloseHandler());
    UserInfoPanel.addClosableToTabSheet(t, getUser().toString());
    TreeTableOrganization treeTableOrganization = new TreeTableOrganization();
    CrudNews showNews = new CrudNews();
    table = treeTableOrganization.getTreeTable();
    Tab orgsTab = t.addTab(treeTableOrganization, "");
    t.setSelectedTab(orgsTab);
    t.addTab(new GroupTab(), "");

    GwsSystemTab systemTab = new GwsSystemTab();
    t.addTab(systemTab, " ??");
    t.addListener(systemTab);

    GwsLazyTab gwsLazyTab = new GwsLazyTab();
    t.addTab(gwsLazyTab, "?  ??");
    t.addListener(gwsLazyTab);

    t.addTab(createEmployeeWidget(), "");
    RefreshableTab settings = createSettings();
    t.addTab(settings, "??");
    t.addListener(settings);

    Component businessCalendar = createBusinessCalendar();
    t.addTab(businessCalendar, "? ");

    LogTab logTab = new LogTab();
    t.addListener(logTab);
    t.addTab(logTab, "");
    t.addTab(showNews, "??");
    t.addTab(registryTab(), "?");
    setMainWindow(new Window(
            getUser() + " |  | -" + Activator.getContext().getBundle().getVersion(),
            t));
    AdminServiceProvider.get().createLog(Flash.getActor(), "Admin application", (String) getUser(), "login",
            null, true);
}

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 av a 2s.  c  o  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);
}

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);
                return;
            }//from  w w w  .j  a v a 2s.  c  om
        }
        Tab t = tabs.addTab(new ReviewTab((ObjectId) iid));
        t.setClosable(true);

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