Example usage for com.vaadin.ui Button getCaption

List of usage examples for com.vaadin.ui Button getCaption

Introduction

In this page you can find the example usage for com.vaadin.ui Button getCaption.

Prototype

@Override
    public String getCaption() 

Source Link

Usage

From source file:org.azrul.langkuik.framework.webgui.PlainTableView.java

@Override
public void enter(final ViewChangeListener.ViewChangeEvent vcevent) {
    setCurrentView(vcevent.getViewName());
    this.removeAllComponents();

    //determine user details
    UserDetails userDetails = null;/*from   ww w  .  ja va2s.  c  om*/
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (!(auth instanceof AnonymousAuthenticationToken)) {
        userDetails = (UserDetails) auth.getPrincipal();
    } else {
        return;
    }

    final Set<String> currentUserRoles = new HashSet<>();
    for (GrantedAuthority grantedAuth : userDetails.getAuthorities()) {
        currentUserRoles.add(grantedAuth.getAuthority());
    }

    //determine entity rights 
    EntityRight entityRight = null;

    EntityUserMap[] entityUserMaps = classOfBean.getAnnotation(WebEntity.class).userMap();
    for (EntityUserMap e : entityUserMaps) {
        if (currentUserRoles.contains(e.role()) || ("*").equals(e.role())) {
            entityRight = e.right();
            break;
        }
    }
    if (entityRight == null) { //if entityRight=EntityRight.NONE, still allow to go through because field level might be accessible
        //Not accessible
        return;
    }

    //Build bread crumb
    BreadCrumbBuilder.buildBreadCrumb(vcevent.getNavigator(), pageParameter.getBreadcrumb(),
            pageParameter.getHistory());
    FindAnyEntityParameter<C> searchQuery = new FindAnyEntityParameter<>(classOfBean);

    //set form
    FormLayout form = new FormLayout();
    final SearchDataTableLayout<C> dataTable = new SearchDataTableLayout<>(searchQuery, classOfBean, dao,
            noBeansPerPage, pageParameter.getCustomTypeDaos(), pageParameter.getConfig(), currentUserRoles,
            entityRight);
    form.addComponent(dataTable);

    //Handle navigations and actions
    HorizontalLayout buttonLayout = new HorizontalLayout();

    //        Button addNewBtn = new Button("Add new",
    //                new Button.ClickListener() {
    //                    @Override
    //                    public void buttonClick(Button.ClickEvent event
    //                    ) {
    //                        C currentBean = dao.createAndSave();
    //                        BeanView<Object, C> beanView = new BeanView<Object, C>(currentBean,null, pageParameter.getRelationManagerFactory(), pageParameter.getEntityManagerFactory(), pageParameter.getHistory(), pageParameter.getBreadcrumb(), pageParameter.getConfig(), pageParameter.getCustomTypeDaos());
    //                        String targetView = "CHOOSE_ONE_TABLE_VIEW_" + UUID.randomUUID().toString();
    //                        WebEntity myObject = (WebEntity) currentBean.getClass().getAnnotation(WebEntity.class);
    //                        History his = new History(targetView, "Add new " + myObject.name());
    //                        pageParameter.getHistory().push(his);
    //                        vcevent.getNavigator().addView(targetView, beanView);
    //                        vcevent.getNavigator().navigateTo(targetView);
    //
    //                    }
    //                });
    //        buttonLayout.addComponent(addNewBtn);
    //        addNewBtn.setId(addNewBtn.getCaption());

    Button manageBtn = new Button("Manage", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Collection<C> currentBeans = (Collection<C>) dataTable.getTableValues();
            if (!currentBeans.isEmpty()) {
                C currentBean = currentBeans.iterator().next();
                if (currentBean != null) {
                    BeanView<Object, C> beanView = new BeanView<>(currentBean, null, null, pageParameter);
                    String targetView = "CHOOSE_ONE_TABLE_VIEW_" + UUID.randomUUID().toString();
                    WebEntity myObject = (WebEntity) currentBean.getClass().getAnnotation(WebEntity.class);
                    History his = new History(targetView, "Manage " + myObject.name());
                    pageParameter.getHistory().push(his);
                    vcevent.getNavigator().addView(targetView, beanView);
                    vcevent.getNavigator().navigateTo(targetView);
                }
            }

        }
    });
    buttonLayout.addComponent(manageBtn);
    manageBtn.setId(manageBtn.getCaption());

    Button deleteBtn = new Button("Delete", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            final Collection<C> currentBeans = (Collection<C>) dataTable.getTableValues();
            if (!currentBeans.isEmpty()) {
                ConfirmDialog.show(PlainTableView.this.getUI(), "Please Confirm:",
                        "Are you really sure you want to delete these entries?", "I am", "Not quite",
                        new ConfirmDialog.Listener() {
                            public void onClose(ConfirmDialog dialog) {
                                if (dialog.isConfirmed()) {
                                    //                                        dao.delete(currentBeans);
                                    //                                        Collection<C> data = dao.search(searchTerms, classOfBean, currentTableDataIndex, noBeansPerPage);
                                    //                                        if (data.isEmpty()) {
                                    //                                            data = new ArrayList<C>();
                                    //                                            data.add(dao.createNew());
                                    //                                        }
                                    //                                        tableDataIT.setBeans(data);
                                    //                                        tableDataIT.refreshItems();
                                    //                                        totalTableData = dao.countSearch(searchTerms, classOfBean);
                                    //                                        final Label pageLabel = new Label();
                                    //                                        int lastPage = (int) Math.floor(totalTableData / noBeansPerPage);
                                    //                                        if (totalTableData % noBeansPerPage == 0) {
                                    //                                            lastPage--;
                                    //                                        }
                                    //                                        int currentUpdatedPage = currentTableDataIndex / noBeansPerPage;
                                    //                                        pageLabel.setCaption(" " + (currentUpdatedPage + 1) + " of " + (lastPage + 1) + " ");
                                }
                            }
                        });
            }

        }
    });
    buttonLayout.addComponent(deleteBtn);
    deleteBtn.setId(deleteBtn.getCaption());

    buttonLayout.setSpacing(true);
    form.addComponent(buttonLayout);

    Button backBtn = new Button("Back", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (!pageParameter.getHistory().isEmpty()) {
                String currentView = pageParameter.getHistory().pop().getViewHandle();
                String lastView = pageParameter.getHistory().peek().getViewHandle();
                vcevent.getNavigator().removeView(currentView);
                vcevent.getNavigator().navigateTo(lastView);
            }
        }
    });
    form.addComponent(backBtn);
    backBtn.setId(backBtn.getCaption());
    this.addComponent(form);
}

From source file:org.azrul.langkuik.framework.webgui.SearchDataTableLayout.java

protected void createSearchPanel(final Class<C> classOfBean, final Configuration config,
        final Set<String> currentUserRoles, final EntityRight entityRight)
        throws UnsupportedOperationException, SecurityException, FieldGroup.BindException {
    final BeanFieldGroup fieldGroup = new BeanFieldGroup(classOfBean);
    final FindAnyEntityParameter searchQuery = (FindAnyEntityParameter) parameter;

    //collect all activechoices
    Map<com.vaadin.ui.ComboBox, ActiveChoiceTarget> activeChoicesWithFieldAsKey = new HashMap<>();
    Map<String, com.vaadin.ui.ComboBox> activeChoicesFieldWithHierarchyAsKey = new HashMap<>();

    BeanUtils beanUtils = new BeanUtils();
    Map<Integer, FieldContainer> fieldContainers = beanUtils.getOrderedFieldsByRank(classOfBean);

    final Map<Integer, com.vaadin.ui.Field> searchableFieldsByRank = new TreeMap<>();
    final Map<String, com.vaadin.ui.Field> searchableFieldsByName = new TreeMap<>();

    //Construct search form
    for (FieldContainer fieldContainer : fieldContainers.values()) {
        Field pojoField = fieldContainer.getPojoField();
        WebField webField = fieldContainer.getWebField();

        if (pojoField.isAnnotationPresent(org.hibernate.search.annotations.Field.class)) {
            if (webField.choices().length > 0) {
                //deal with choices

                com.vaadin.ui.ComboBox searchComboBox = new com.vaadin.ui.ComboBox(webField.name());

                searchComboBox.setImmediate(true);
                fieldGroup.bind(searchComboBox, pojoField.getName());
                for (Choice choice : webField.choices()) {
                    if (choice.value() == -1) {
                        searchComboBox.addItem(choice.textValue());
                        searchComboBox.setItemCaption(choice.textValue(), choice.display());
                    } else {
                        searchComboBox.addItem(choice.value());
                        searchComboBox.setItemCaption(choice.value(), choice.display());
                    }/*from   w  ww . jav  a 2 s.  c  o m*/
                }

                //allDataSearchForm.addComponent(searchComboBox);
                searchableFieldsByRank.put(webField.rank(), searchComboBox);
                searchableFieldsByName.put(pojoField.getName(), searchComboBox);
            } else if (webField.activeChoice().enumTree() != EmptyEnum.class) {
                //collect active choices - 
                com.vaadin.ui.ComboBox searchComboBox = new com.vaadin.ui.ComboBox(webField.name());
                searchComboBox.setImmediate(true);
                fieldGroup.bind(searchComboBox, pojoField.getName());
                String hierarchy = webField.activeChoice().hierarchy();
                Class<ActiveChoiceEnum> enumTree = (Class<ActiveChoiceEnum>) webField.activeChoice().enumTree();
                ActiveChoiceTarget activeChoiceTarget = ActiveChoiceUtils.build(enumTree, hierarchy);
                for (String choice : activeChoiceTarget.getSourceChoices()) {
                    searchComboBox.addItem(choice);
                    activeChoicesWithFieldAsKey.put(searchComboBox, activeChoiceTarget);
                    activeChoicesFieldWithHierarchyAsKey.put(hierarchy, searchComboBox);
                }
                searchableFieldsByRank.put(webField.rank(), searchComboBox);
                searchableFieldsByName.put(pojoField.getName(), searchComboBox);

            } else {
                com.vaadin.ui.Field searchField = fieldGroup.buildAndBind(webField.name(), pojoField.getName());
                if (pojoField.getType().equals(Date.class)) {
                    DateField dateField = (DateField) searchField;
                    dateField.setDateFormat(config.get("dateFormat"));
                    dateField.setWidth(100f, Sizeable.Unit.PIXELS);
                }

                //allDataSearchForm.addComponent(searchField);
                searchableFieldsByRank.put(webField.rank(), searchField);
                searchableFieldsByName.put(pojoField.getName(), searchField);
            }
        }

    }

    //build form
    int rowCount = (int) (Math.ceil(searchableFieldsByRank.size() / 2));
    rowCount = rowCount < 1 ? 1 : rowCount;
    GridLayout allDataSearchForm = new GridLayout(2, rowCount);
    allDataSearchForm.setSpacing(true);
    for (com.vaadin.ui.Field searchField : searchableFieldsByRank.values()) {
        allDataSearchForm.addComponent(searchField);
        searchField.setId(searchField.getCaption());
    }

    this.addComponent(allDataSearchForm);

    //deal with active choice
    for (final com.vaadin.ui.ComboBox sourceField : activeChoicesWithFieldAsKey.keySet()) {
        final ActiveChoiceTarget target = activeChoicesWithFieldAsKey.get(sourceField);
        final com.vaadin.ui.ComboBox targetField = activeChoicesFieldWithHierarchyAsKey
                .get(target.getTargetHierarchy());
        sourceField.addValueChangeListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                List<String> targetValues = target.getTargets().get(sourceField.getValue());
                if (targetValues != null && !targetValues.isEmpty() && targetField != null) {
                    targetField.removeAllItems();
                    for (String targetValue : targetValues) {
                        targetField.addItem(targetValue);
                    }
                }
            }
        });

    }

    //search button
    Button searchBtn = new Button("Search", new Button.ClickListener() {

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

            //reset previous searches
            searchQuery.getSearchTerms().clear();
            //read search terms from form
            try {
                for (Map.Entry<String, com.vaadin.ui.Field> entry : searchableFieldsByName.entrySet()) {
                    com.vaadin.ui.Field searchField = entry.getValue();
                    if (searchField.getValue() != null) {
                        if (searchField.getValue() instanceof String) {
                            String searchTerm = ((String) searchField.getValue()).trim();
                            if (!"".equals(searchTerm)) {
                                searchQuery.getSearchTerms().add(new SearchTerm(entry.getKey(),
                                        classOfBean.getDeclaredField(entry.getKey()), searchField.getValue()));
                            }
                        } else {
                            searchQuery.getSearchTerms().add(new SearchTerm(entry.getKey(),
                                    classOfBean.getDeclaredField(entry.getKey()), searchField.getValue()));
                        }
                    }
                }
            } catch (NoSuchFieldException | SecurityException ex) {
                Logger.getLogger(SearchDataTableLayout.class.getName()).log(Level.SEVERE, null, ex);
            }
            //do query
            Collection<C> allData = dao.runQuery(parameter, orderBy, asc, currentTableIndex, itemCountPerPage);
            if (allData.isEmpty()) {
                allData = new ArrayList<>();
                allData.add(dao.createNew());
            }
            bigTotal = dao.countQueryResult(parameter);
            itemContainer.setBeans(allData);
            itemContainer.refreshItems();
            table.setPageLength(itemCountPerPage);
            table.setPageLength(itemCountPerPage);
            currentTableIndex = 0;
            int lastPage = (int) Math.floor(bigTotal / itemCountPerPage);
            if (bigTotal % itemCountPerPage == 0) {
                lastPage--;
            }
            int currentUpdatedPage = currentTableIndex / itemCountPerPage;
            pageLabel.setCaption(" " + (currentUpdatedPage + 1) + " of " + (lastPage + 1) + " ");
        }
    });
    searchBtn.setId(searchBtn.getCaption());
    this.addComponent(searchBtn);
}

From source file:org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons.java

License:Open Source License

private Button createFilterButton(final Long id, final String name, final String description,
        final String color, final Object itemId) {
    /**
     * No icon displayed for "NO TAG" button.
     *///  w w  w .j  av a 2  s .c o m
    final Button button = SPUIComponentProvider.getButton("", name, description, "", false, null,
            SPUITagButtonStyle.class);
    button.setId(createButtonId(name));
    button.setCaptionAsHtml(true);
    if (id != null) {
        // Use button.getCaption() since the caption name is modified
        // according to the length
        // available in UI.
        button.setCaption(prepareFilterButtonCaption(button.getCaption(), color));
    }

    if (!StringUtils.isEmpty(description)) {
        button.setDescription(description);
    } else {
        button.setDescription(name);
    }
    button.setData(id == null ? SPUIDefinitions.NO_TAG_BUTTON_ID : itemId);

    return button;
}

From source file:org.jdal.vaadin.ui.ButtonBar.java

License:Apache License

/**
 * Find a button by caption/*from  w  w w .j av  a  2s  .  com*/
 * @param caption caption to search
 * @return the button, null if none
 */
private Button getButtonByCaption(String caption) {
    for (Button b : buttons) {
        if (caption.equals(b.getCaption()))
            return b;
    }

    return null;
}

From source file:org.lucidj.iconlist.renderer.IconListRenderer.java

License:Apache License

private void button_caption_wrap(Button b) {
    String caption = b.getCaption();
    int wrap_len = 12;

    if (caption.length() > wrap_len) {
        String[] words = caption.split("\\s");
        String twoliner = "";
        int space_left = 0;
        int lines = 0;
        caption = "";

        // Simple greedy wrapping
        for (String word : words) {
            int len = word.length();

            if (len + 1 > space_left) {
                if (lines++ == 2) {
                    twoliner = caption + "\u2026"; // Unicode ellipsis
                }//www . j  a va  2 s.  c  o  m
                caption += caption.isEmpty() ? word : "<br/>" + word;
                space_left = wrap_len - len;
            } else {
                caption += " " + word;
                space_left -= len + 1;
            }
        }
        b.setCaptionAsHtml(true);
        b.setCaption(twoliner.isEmpty() ? caption : twoliner);
    }
    b.setDescription(caption);
}

From source file:org.opennms.features.topology.app.internal.TopologyWidgetTestApplication.java

License:Open Source License

/**
 * Creates the west area layout including the
 * accordion and tree views.//from  w  ww.  ja  va  2 s  . c  o  m
 * 
 * @return
 */
@SuppressWarnings("serial")
private Layout createWestLayout() {
    m_tree = createTree();

    final TextField filterField = new TextField("Filter");
    filterField.setTextChangeTimeout(200);

    final Button filterBtn = new Button("Filter");
    filterBtn.addListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            GCFilterableContainer container = m_tree.getContainerDataSource();
            container.removeAllContainerFilters();

            String filterString = (String) filterField.getValue();
            if (!filterString.equals("") && filterBtn.getCaption().toLowerCase().equals("filter")) {
                container.addContainerFilter(LABEL_PROPERTY, (String) filterField.getValue(), true, false);
                filterBtn.setCaption("Clear");
            } else {
                filterField.setValue("");
                filterBtn.setCaption("Filter");
            }

        }
    });

    HorizontalLayout filterArea = new HorizontalLayout();
    filterArea.addComponent(filterField);
    filterArea.addComponent(filterBtn);
    filterArea.setComponentAlignment(filterBtn, Alignment.BOTTOM_CENTER);

    m_treeAccordion = new Accordion();
    m_treeAccordion.addTab(m_tree, m_tree.getTitle());
    m_treeAccordion.setWidth("100%");
    m_treeAccordion.setHeight("100%");

    AbsoluteLayout absLayout = new AbsoluteLayout();
    absLayout.setWidth("100%");
    absLayout.setHeight("100%");
    absLayout.addComponent(filterArea, "top: 25px; left: 15px;");
    absLayout.addComponent(m_treeAccordion, "top: 75px; left: 15px; right: 15px; bottom:25px;");

    return absLayout;
}

From source file:org.opennms.features.topology.app.internal.ui.breadcrumbs.BreadcrumbComponent.java

License:Open Source License

private static Button createButton(GraphContainer container, Breadcrumb breadcrumb) {
    final Button button = new Button();
    final String layerName = getLayerName(container, breadcrumb.getTargetNamespace());
    if (breadcrumb.getSourceVertices().isEmpty()) {
        button.setCaption(layerName);//from  ww w.  j a v  a 2s  . c om
    } else {
        String sourceLayerName = getLayerName(container, breadcrumb.getSourceVertices().get(0).getNamespace());
        if (breadcrumb.getSourceVertices().size() > 2) {
            button.setCaption("Multiple " + layerName);
            button.setDescription(String.format("Multiple vertices from %s", sourceLayerName));
        } else {
            button.setCaption(breadcrumb.getSourceVertices().stream().map(b -> b.getLabel())
                    .collect(Collectors.joining(", ")));
            button.setDescription(String.format("%s from %s", button.getCaption(), sourceLayerName));
        }
    }
    button.addStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener((event) -> breadcrumb.clicked(container));
    return button;
}

From source file:org.openthinclient.web.pkgmngr.ui.InstallationPlanSummaryDialog.java

/**
 * Creates a table with datasource of IndexedContainer
 * @return the Grid for InstallationSummary
 *///from w ww. j a  v  a  2  s .  c o m
private Grid<InstallationSummary> createTable(GridTypes type) {

    Grid<InstallationSummary> summary = new Grid<>();
    summary.setDataProvider(DataProvider.ofCollection(Collections.EMPTY_LIST));
    summary.setSelectionMode(Grid.SelectionMode.NONE);
    summary.addColumn(InstallationSummary::getPackageName)
            .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_NAME));
    summary.addColumn(InstallationSummary::getPackageVersion)
            .setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_VERSION));
    if (type == GridTypes.INSTALL_UNINSTALL && !packageManagerOperation.hasPackagesToUninstall()) { // license column
        summary.addComponentColumn(is -> {
            if (is.getLicense() != null) {
                Button button = new Button(
                        mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_SHOW));
                button.addClickListener(click -> {
                    // licence already clicked, re-set button caption
                    licenceButtons.stream().filter(b -> !b.equals(button)).forEach(b -> {
                        if (b.getCaption().equals(
                                mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_HIDE))) {
                            b.setCaption(
                                    mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_SHOW));
                        }
                    });
                    // display licence
                    if (button.getCaption()
                            .equals(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_SHOW))) {
                        licenceTextArea.setVisible(true);
                        licenceTextArea.setValue(is.getLicense());
                    } else {
                        licenceTextArea.setVisible(false);
                    }
                    button.setCaption(licenceTextArea.isVisible()
                            ? mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_HIDE)
                            : mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE_SHOW));
                });
                button.addStyleName("package_install_summary_display_license_button");
                licenceButtons.add(button);
                return button;
            } else {
                return null;
            }
        }).setCaption(mc.getMessage(ConsoleWebMessages.UI_PACKAGEMANAGER_PACKAGE_LICENSE));
    }

    summary.addStyleName(ValoTheme.TABLE_BORDERLESS);
    summary.addStyleName(ValoTheme.TABLE_NO_HEADER);
    summary.addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
    summary.addStyleName(ValoTheme.TABLE_NO_HORIZONTAL_LINES);
    summary.setHeightMode(HeightMode.ROW);

    return summary;
}

From source file:pl.edu.agh.samm.testapp.SAMMTestApplication.java

License:Apache License

private Button createGenerationControlButton() {
    final Button generationControl = new Button(START_WORKLOAD);
    generationControl.addClickListener(new Button.ClickListener() {
        @Override/*from  w w  w  .  j  a  va 2 s.  c  om*/
        public void buttonClick(ClickEvent event) {
            try {
                WorkloadGeneratorFacade workloadGeneratorFacade = WorkloadGeneratorFacade.getInstance();
                if (generationControl.getCaption().equals(START_WORKLOAD)) {
                    publishMessage("Starting expressions generation...");
                    workloadGeneratorFacade
                            .startGenerating(Long.parseLong(expressionsPerMinuteTextField.getValue()));
                    publishMessage("Started expressions generation");
                    generationControl.setCaption(STOP_WORKLOAD);
                } else {
                    publishMessage("Stopping expressions generation...");
                    workloadGeneratorFacade.stopGenerating();
                    publishMessage("Stopped expressions generation");
                    generationControl.setCaption(START_WORKLOAD);
                }
            } catch (InterruptedException e) {
                publishMessage("Error! " + e.getMessage());
                e.printStackTrace();
            }
        }
    });
    return generationControl;
}