Example usage for com.vaadin.ui NativeButton setEnabled

List of usage examples for com.vaadin.ui NativeButton setEnabled

Introduction

In this page you can find the example usage for com.vaadin.ui NativeButton setEnabled.

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:ac.uk.icl.dell.vaadin.glycanbuilder.VaadinGlycanCanvas.java

License:Open Source License

public void appendGeneralToolBar(Panel theToolBarPanel) {
    HorizontalLayout toolBar = new HorizontalLayout();
    toolBar.setWidth("100%");

    toolBar.setStyleName("toolbar");

    NativeButton deleteButton = new NativeButton("Delete");
    deleteButton.setIcon(new ThemeResource("icons/deleteNew.png"));
    deleteButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 1289257412952359727L;

        @Override/*from   w w  w.  j av  a  2s  .  c o  m*/
        public void buttonClick(ClickEvent event) {
            theCanvas.delete();
        }
    });
    deleteButton.setEnabled(false);

    NativeButton copyButton = new NativeButton("Copy");
    final NativeButton pasteButton = new NativeButton("Paste");
    copyButton.setIcon(new ThemeResource("icons/editcopy.png"));
    copyButton.addListener(new ClickListener() {
        private static final long serialVersionUID = -1740735587078805580L;

        @Override
        public void buttonClick(ClickEvent event) {
            theCanvas.copy();
            pasteButton.setEnabled(true);
        }
    });
    copyButton.setEnabled(false);

    pasteButton.setIcon(new ThemeResource("icons/editpaste.png"));
    pasteButton.addListener(new ClickListener() {
        private static final long serialVersionUID = -8732259244009686729L;

        @Override
        public void buttonClick(ClickEvent event) {
            theCanvas.paste();
            pasteButton.setEnabled(false);
        }
    });
    pasteButton.setEnabled(false);

    final NativeButton bracketButton = new NativeButton("Bracket");
    bracketButton.setIcon(new ThemeResource("icons/bracket.png"));
    bracketButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 5201094306113759901L;

        @Override
        public void buttonClick(ClickEvent event) {
            theCanvas.addBracket();
        }
    });
    bracketButton.setEnabled(false);

    final NativeButton repeatButton = new NativeButton("Repeat");
    repeatButton.setIcon(new ThemeResource("icons/repeat.png"));
    repeatButton.addListener(new ClickListener() {
        private static final long serialVersionUID = -23302591439643695L;

        @Override
        public void buttonClick(ClickEvent event) {
            try {
                theCanvas.addRepeat();
            } catch (Exception ex) {
                showMessage(ex.getMessage(), "400px", "100px", "Error creating repeat");
            }
        }
    });
    repeatButton.setEnabled(false);

    componentsWithResidueSelectionDependency.add(repeatButton);
    componentsWithResidueSelectionDependency.add(bracketButton);
    componentsWithResidueSelectionDependency.add(deleteButton);
    componentsWithResidueSelectionDependency.add(copyButton);

    final NativeButton orientationButton = new NativeButton("Orientation");

    orientationButton.setIcon(new ThemeResource("icons/" + theCanvas.getOrientationIcon()));
    orientationButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 6621021858668446143L;

        @Override
        public void buttonClick(ClickEvent event) {
            theCanvas.changeOrientation();
            orientationButton.setIcon(new ThemeResource("icons/" + theCanvas.getOrientationIcon()));
        }
    });

    final NativeButton selectAllButton = new NativeButton("Select all");

    selectAllButton.setIcon(new ThemeResource("icons/selectall.png"));
    selectAllButton.addListener(new ClickListener() {
        private static final long serialVersionUID = -5848923636575805154L;

        @Override
        public void buttonClick(ClickEvent event) {
            theCanvas.selectAll();
            theCanvas.documentUpdated();
        }
    });

    final NativeButton deSelectAllButton = new NativeButton("Select none");

    deSelectAllButton.setIcon(new ThemeResource("icons/deselect.png"));
    deSelectAllButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 8339468775345706027L;

        @Override
        public void buttonClick(ClickEvent event) {
            theCanvas.resetSelection();
            theCanvas.documentUpdated();
        }
    });

    final NativeButton moveCWButton = new NativeButton("Move CW");

    moveCWButton.setIcon(new ThemeResource("icons/rotatecw.png"));
    moveCWButton.addListener(new ClickListener() {
        private static final long serialVersionUID = -6061975045440741204L;

        @Override
        public void buttonClick(ClickEvent event) {
            theCanvas.onMoveCW();
        }
    });

    componentsWithResidueSelectionDependency.add(moveCWButton);

    final NativeButton moveCCWButton = new NativeButton("Move CCW");

    moveCCWButton.setIcon(new ThemeResource("icons/rotateccw.png"));
    moveCCWButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 3555726070782377309L;

        @Override
        public void buttonClick(ClickEvent event) {
            theCanvas.onMoveCCW();
        }
    });

    componentsWithResidueSelectionDependency.add(moveCCWButton);

    toolBar.addComponent(deleteButton);
    toolBar.addComponent(copyButton);
    toolBar.addComponent(pasteButton);
    toolBar.addComponent(orientationButton);
    toolBar.addComponent(selectAllButton);
    toolBar.addComponent(deSelectAllButton);
    toolBar.addComponent(bracketButton);
    toolBar.addComponent(repeatButton);
    toolBar.addComponent(moveCWButton);
    toolBar.addComponent(moveCCWButton);

    HorizontalLayout layout = new HorizontalLayout();
    layout.setSizeFull();

    toolBar.addComponent(layout);
    toolBar.setExpandRatio(layout, 1);

    theToolBarPanel.setContent(toolBar);
}

From source file:edu.kit.dama.ui.commons.util.PaginationLayout.java

License:Apache License

/**
 * Update the layout. This method is either called internally when scrolling
 * or//  w w w . j av  a2  s .  c o m
 */
public final void update() {
    //remove all components (old result page and navigation)
    removeAllComponents();

    //add current results
    renderPage();

    //build pagination
    int pages = overallEntries / entriesPerPage;
    if (overallEntries % entriesPerPage > 0) {
        pages++;
    }

    final int overallPages = pages;
    HorizontalLayout navigation = new HorizontalLayout();
    //add "JumpToFirstPage" button
    final NativeButton first = new NativeButton();
    first.setIcon(firstIcon);
    if (firstIcon == null) {
        first.setCaption("<<");
    }
    first.setDescription("First Page");
    first.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = 0;
            update();
        }
    });
    //add "PreviousPage" button
    final NativeButton prev = new NativeButton();
    prev.setIcon(prevIcon);
    if (prevIcon == null) {
        prev.setCaption("<");
    }
    prev.setDescription("Previous Page");
    prev.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage > 0) {
                currentPage--;
                update();
            }
        }
    });
    //add "NextPage" button
    final NativeButton next = new NativeButton();
    next.setIcon(nextIcon);
    if (nextIcon == null) {
        next.setCaption(">");
    }
    next.setDescription("Next Page");
    next.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage + 1 < overallPages) {
                currentPage++;
                update();
            }
        }
    });
    //add "JumpToLastPage" button
    final NativeButton last = new NativeButton();
    last.setIcon(endIcon);
    if (endIcon == null) {
        next.setCaption(">>");
    }
    last.setDescription("Last Page");
    last.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = overallPages - 1;
            update();
        }
    });

    //enable/disable buttons depending on the current page
    if (overallPages == 0) {
        first.setEnabled(false);
        prev.setEnabled(false);
        next.setEnabled(false);
        last.setEnabled(false);
    } else {
        first.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        prev.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        next.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
        last.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
    }

    //at first, put the page size selection box into the navigation
    final ComboBox entriesPerPageBox = new ComboBox();
    entriesPerPageBox.setItemCaptionPropertyId("name");
    entriesPerPageBox.addContainerProperty("name", String.class, null);
    entriesPerPageBox.addItem(5);
    entriesPerPageBox.getContainerProperty(5, "name").setValue("5 Entries / Page");
    entriesPerPageBox.addItem(10);
    entriesPerPageBox.getContainerProperty(10, "name").setValue("10 Entries / Page");
    entriesPerPageBox.addItem(15);
    entriesPerPageBox.getContainerProperty(15, "name").setValue("15 Entries / Page");
    entriesPerPageBox.addItem(20);
    entriesPerPageBox.getContainerProperty(20, "name").setValue("20 Entries / Page");

    entriesPerPageBox.setValue(entriesPerPage);
    entriesPerPageBox.setNullSelectionAllowed(false);
    entriesPerPageBox.setImmediate(true);

    entriesPerPageBox.addListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            entriesPerPage = (Integer) entriesPerPageBox.getValue();
            update();
        }
    });

    navigation.addComponent(entriesPerPageBox);

    //filler labels are added to the beginning and to the end to keep the navigation in the middle
    Label leftFiller = new Label();
    leftFiller.setWidth("25px");
    navigation.addComponent(leftFiller);
    navigation.addComponent(first);
    navigation.addComponent(prev);

    //Show max. 10 pages at once for performance and layout reasons.
    //If there are more than 10 pages, "move" the to show 10 pages based on the current page.
    int start = currentPage - 5;
    start = (start < 0) ? 0 : start;
    int end = start + 10;
    end = (end > pages) ? pages : end;

    if (end - start < 10 && pages > 10) {
        start = end - 10;
    }

    if (overallPages == 0) {
        Label noEntryLabel = new Label("<i>No entries</i>", Label.CONTENT_XHTML);
        //noEntryLabel.setWidth("80px");
        noEntryLabel.setSizeUndefined();
        navigation.addComponent(noEntryLabel);
        navigation.setComponentAlignment(noEntryLabel, Alignment.MIDDLE_CENTER);
    }
    //build the actual page entries
    for (int i = start; i < end; i++) {
        if (i == currentPage) {
            //the current page is marked with a special style
            Label pageLink = new Label("<b>" + Integer.toString(i + 1) + "</b>", Label.CONTENT_XHTML);
            pageLink.setStyleName("currentpage");
            pageLink.setWidth("15px");
            navigation.addComponent(pageLink);
            navigation.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        } else {
            //otherwise normal links are added, click-events are handled via LayoutClickListener 
            Link pageLink = new Link(Integer.toString(i + 1), null);
            navigation.addComponent(pageLink);
            navigation.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        }
    }
    //add right navigation buttons
    navigation.addComponent(next);
    navigation.addComponent(last);
    //...and fill the remaining space 
    Label rightFiller = new Label();
    navigation.addComponent(rightFiller);
    //  navigation.setExpandRatio(leftFiller, 1.0f);
    navigation.setExpandRatio(rightFiller, 1.0f);
    navigation.setSpacing(true);

    //put everything ot the middle
    navigation.setComponentAlignment(first, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(prev, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(next, Alignment.MIDDLE_CENTER);
    navigation.setComponentAlignment(last, Alignment.MIDDLE_CENTER);

    //add layout click listener to be able to navigate by clicking the single pages
    navigation.addListener(new LayoutEvents.LayoutClickListener() {
        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent event) {

            // Get the child component which was clicked
            Component child = event.getChildComponent();

            if (child == null) {
                // Not over any child component
            } else {
                // Over a child component
                if (child instanceof Link) {
                    // Over a valid child element
                    currentPage = Integer.parseInt(((Link) child).getCaption()) - 1;
                    update();
                }
            }
        }
    });

    //finalize
    navigation.setWidth("100%");
    navigation.setHeight("25px");

    //add navigation and align it right below the result page
    addComponent(page);
    setExpandRatio(page, 1f);
    if (overallEntries > 0) {
        addComponent(navigation);
        setComponentAlignment(navigation, Alignment.BOTTOM_CENTER);
        setExpandRatio(navigation, .05f);
    }
    requestRepaint();
}

From source file:edu.kit.dama.ui.repo.components.PaginationPanel.java

License:Apache License

/**
 * Build the navigation layout including the appropriate buttons to navigate
 * through the pagination pages./*  w ww  .j  a  v  a  2  s .co m*/
 *
 * @return The navigation layout component.
 */
private HorizontalLayout buildNavigationComponent() {
    HorizontalLayout result = new HorizontalLayout();
    //add "JumpToFirstPage" button
    final NativeButton first = new NativeButton();
    first.setIcon(new ThemeResource("img/16x16/beginning.png"));
    first.setDescription("First Page");
    first.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = 0;
            updatePage();
        }
    });
    //add "PreviousPage" button
    final NativeButton prev = new NativeButton();
    prev.setIcon(new ThemeResource("img/16x16/prev.png"));
    prev.setDescription("Previous Page");
    prev.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage > 0) {
                currentPage--;
                updatePage();
            }
        }
    });
    //add "NextPage" button
    final NativeButton next = new NativeButton();
    next.setDescription("Next Page");
    next.setIcon(new ThemeResource("img/16x16/next.png"));
    next.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (currentPage + 1 < overallPages) {
                currentPage++;
                updatePage();
            }
        }
    });
    //add "JumpToLastPage" button
    final NativeButton last = new NativeButton();
    last.setDescription("Last Page");
    last.setIcon(new ThemeResource("img/16x16/end.png"));
    last.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            currentPage = overallPages - 1;
            updatePage();
        }
    });

    //enable/disable buttons depending on the current page
    if (overallPages == 0) {
        first.setEnabled(false);
        prev.setEnabled(false);
        next.setEnabled(false);
        last.setEnabled(false);
    } else {
        first.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        prev.setEnabled(!(currentPage == 0) || !(overallPages < 2));
        next.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
        last.setEnabled(!(currentPage == overallPages - 1) || !(overallPages < 2));
    }

    Label leftFiller = new Label();
    result.addComponent(leftFiller);
    result.setExpandRatio(leftFiller, 1.0f);
    result.addComponent(first);
    result.addComponent(prev);
    int start = currentPage - 5;
    start = (start < 0) ? 0 : start;
    int end = start + 10;
    end = (end > overallPages) ? overallPages : end;

    if (end - start < 10 && overallPages > 10) {
        start = end - 10;
    }

    if (overallPages == 0) {
        Label noEntryLabel = new Label("<i>No entries</i>", ContentMode.HTML);
        //noEntryLabel.setWidth("80px");
        noEntryLabel.setSizeUndefined();
        result.addComponent(noEntryLabel);
        result.setComponentAlignment(noEntryLabel, Alignment.MIDDLE_CENTER);
    }
    //build the actual page entries
    for (int i = start; i < end; i++) {
        if (i == currentPage) {
            //the current page is marked with a special style
            Label pageLink = new Label("<b>" + Integer.toString(i + 1) + "</b>", ContentMode.HTML);
            pageLink.setStyleName("currentpage");
            pageLink.setWidth("15px");
            result.addComponent(pageLink);
            result.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        } else {
            //otherwise normal links are added, click-events are handled via LayoutClickListener 
            Link pageLink = new Link(Integer.toString(i + 1), null);
            result.addComponent(pageLink);
            result.setComponentAlignment(pageLink, Alignment.MIDDLE_CENTER);
        }
    }
    //add right navigation buttons
    result.addComponent(next);
    result.addComponent(last);
    //...and fill the remaining space 
    Label rightFiller = new Label();
    result.addComponent(rightFiller);
    result.setExpandRatio(rightFiller, 1.0f);
    result.setSpacing(true);

    //put everything ot the middle
    result.setComponentAlignment(first, Alignment.MIDDLE_CENTER);
    result.setComponentAlignment(prev, Alignment.MIDDLE_CENTER);
    result.setComponentAlignment(next, Alignment.MIDDLE_CENTER);
    result.setComponentAlignment(last, Alignment.MIDDLE_CENTER);

    //add layout click listener to be able to navigate by clicking the single pages
    result.addLayoutClickListener(new LayoutEvents.LayoutClickListener() {
        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent event) {

            // Get the child component which was clicked
            Component child = event.getChildComponent();

            if (child == null) {
                // Not over any child component
            } else // Over a child component
            {
                if (child instanceof Link) {
                }
            }
        }
    });

    //finalize
    result.setWidth("100%");
    result.setHeight("25px");
    return result;
}

From source file:edu.nps.moves.mmowgli.modules.userprofile.DefineAwardsDialog.java

License:Open Source License

@HibernateSessionThreadLocalConstructor
public DefineAwardsDialog() {
    setCaption("Define Player Award Types");
    setModal(true);//from   w w  w  . j a  v a  2 s  .c o m
    setSizeUndefined();
    setWidth("700px");
    setHeight("400px");

    VerticalLayout vLay = new VerticalLayout();
    vLay.setMargin(true);
    vLay.setSpacing(true);
    vLay.setSizeFull();
    setContent(vLay);

    vLay.addComponent(new HtmlLabel("<b>This dialog is not yet functional</b>"));

    Panel p = new Panel();
    p.setWidth("99%");
    p.setHeight("100%");
    vLay.addComponent(p);
    vLay.setExpandRatio(p, 1.0f);

    gridLayout = new GridLayout();
    gridLayout.addStyleName("m-headgrid");
    gridLayout.setWidth("100%");
    p.setContent(gridLayout);
    fillPanelTL();

    HorizontalLayout buttPan = new HorizontalLayout();
    buttPan.setWidth("100%");
    buttPan.setSpacing(true);
    NativeButton addButt = new NativeButton("Add new type", new AddListener());
    NativeButton delButt = new NativeButton("Delete type", new DelListener());
    NativeButton saveButt = new NativeButton("Save", new SaveListener());
    NativeButton cancelButt = new NativeButton("Cancel", new CancelListener());
    buttPan.addComponent(addButt);
    buttPan.addComponent(delButt);

    Label lab;
    buttPan.addComponent(lab = new Label());
    buttPan.setExpandRatio(lab, 1.0f);
    buttPan.addComponent(cancelButt);
    buttPan.addComponent(saveButt);
    vLay.addComponent(buttPan);

    //temp
    saveButt.setEnabled(false);
    delButt.setEnabled(false);
}