Example usage for com.vaadin.ui Button addClickListener

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

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Adds the button click listener.

Usage

From source file:biz.eelis.translation.EntriesFlowlet.java

License:Apache License

@Override
public void initialize() {
    final List<FieldDescriptor> fieldDescriptors = TranslationSiteFields.getFieldDescriptors(Entry.class);

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();

    filterDefinitions.add(new FilterDescriptor("basename", "basename", "Basename", new TextField(), 200, "like",
            String.class, ""));

    filterDefinitions.add(new FilterDescriptor("language", "language", "Language", new TextField(), 30, "=",
            String.class, ""));

    filterDefinitions.add(// ww w.j  av a  2 s .  c o m
            new FilterDescriptor("country", "country", "Country", new TextField(), 30, "=", String.class, ""));

    filterDefinitions
            .add(new FilterDescriptor("key", "key", "Key", new TextField(), 200, "like", String.class, ""));

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    container = new LazyEntityContainer<Entry>(entityManager, true, true, false, Entry.class, 1000,
            new String[] { "basename", "key", "language", "country" }, new boolean[] { true, true, true, true },
            "entryId");

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setSizeUndefined();
    gridLayout.addComponent(buttonLayout, 0, 0);

    final Table table = new FormattingTable();
    grid = new Grid(table, container);
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);

    table.setColumnCollapsed("entryId", true);
    table.setColumnCollapsed("path", true);
    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    gridLayout.addComponent(grid, 0, 1);

    final Button addButton = getSite().getButton("add");
    buttonLayout.addComponent(addButton);
    addButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Entry entry = new Entry();
            entry.setCreated(new Date());
            entry.setModified(entry.getCreated());
            entry.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
            final EntryFlowlet entryView = getViewSheet().forward(EntryFlowlet.class);
            entryView.edit(entry, true);
        }
    });

    final Button editButton = getSite().getButton("edit");
    buttonLayout.addComponent(editButton);
    editButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Entry entity = container.getEntity(grid.getSelectedItemId());
            final EntryFlowlet entryView = getViewSheet().forward(EntryFlowlet.class);
            entryView.edit(entity, false);
        }
    });

    final Button removeButton = getSite().getButton("remove");
    buttonLayout.addComponent(removeButton);
    removeButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            container.removeItem(grid.getSelectedItemId());
            container.commit();
        }
    });

    final Company company = getSite().getSiteContext().getObject(Company.class);
    container.removeDefaultFilters();
    container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId()));
    grid.refresh();
}

From source file:by.bigvova.ui.LoginUI.java

License:Apache License

private Component buildFields() {
    final VerticalLayout layout = new VerticalLayout();
    HorizontalLayout fields = new HorizontalLayout();
    fields.setSpacing(true);/*w  w  w.j a va2  s.  c o  m*/
    fields.addStyleName("fields");

    final TextField username = new TextField("Username");
    username.setIcon(FontAwesome.USER);
    username.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final PasswordField password = new PasswordField("Password");
    password.setIcon(FontAwesome.LOCK);
    password.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);

    final Button signin = new Button("Sign In");
    signin.addStyleName(ValoTheme.BUTTON_PRIMARY);
    signin.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    signin.focus();

    final CheckBox checkBox = new CheckBox("Remember me", true);

    signin.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(final Button.ClickEvent event) {
            login(username.getValue(), password.getValue(), checkBox.getValue());
        }
    });

    fields.addComponents(username, password, signin);
    fields.setComponentAlignment(signin, Alignment.BOTTOM_LEFT);

    layout.setSpacing(true);
    layout.addComponent(fields);
    layout.addComponent(checkBox);
    return layout;
}

From source file:cb_server.SettingsWindow.java

License:Open Source License

private void addSaveCancelButtons() {
    HorizontalLayout hl = new HorizontalLayout();
    final Button btnSave = new Button(Translation.Get("save".hashCode()));
    final Button btnCancel = new Button(Translation.Get("cancel".hashCode()));

    hl.addComponent(btnSave);//w  w  w .j  a  va 2s .  c  om
    hl.addComponent(btnCancel);

    btnCancel.addClickListener(new ClickListener() {

        private static final long serialVersionUID = -4799987364890297976L;

        @Override
        public void buttonClick(ClickEvent event) {
            Config.settings.LoadFromLastValue();
            SettingsWindow.this.close();
        }
    });

    btnSave.addClickListener(new ClickListener() {

        private static final long serialVersionUID = -878673538684730570L;

        @Override
        public void buttonClick(ClickEvent event) {
            String lang = (String) langSpinner.getValue();

            for (Lang tmp : Translation.GetLangs(SettingsClass.LanguagePath.getValue())) {
                if (lang.equals(tmp.Name)) {
                    CB_UI_Base_Settings.Sel_LanguagePath.setValue(tmp.Path);
                    try {
                        Translation.LoadTranslation(tmp.Path);
                    } catch (Exception e) {
                        try {
                            Translation.LoadTranslation(CB_UI_Base_Settings.Sel_LanguagePath.getDefaultValue());
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                    }
                    break;
                }

            }

            Config.settings.WriteToDB();
            Config.settings.SaveToLastValue();

            SettingsWindow.this.close();
        }
    });

    content.addComponent(hl);
}

From source file:cb_server.SettingsWindow.java

License:Open Source License

private Component getLogInButton(int i) {
    com.vaadin.ui.HorizontalLayout box = new HorizontalLayout();
    com.vaadin.ui.Button button = new com.vaadin.ui.Button();
    button.setCaption("Get API Key");

    button.addClickListener(new ClickListener() {

        private static final long serialVersionUID = -1417363407758383092L;

        @Override/*ww  w  .j a va2s . c  o  m*/
        public void buttonClick(ClickEvent event) {
            LogInWindow sub = LogInWindow.getInstanz();

            if (!UI.getCurrent().getWindows().contains(sub))

                // Add it to the root component
                UI.getCurrent().addWindow(sub);
        }
    });

    box.addComponent(button);

    return box;
}

From source file:ch.bfh.ti.soed.hs16.srs.black.view.reservationView.ReservationController.java

License:Open Source License

public void createList(String customer) throws Exception {
    reservationView.getReservationList().removeAllItems();
    List<Reservation> reservationList = dataModel.getReservations(dataModel.getCustomer(customer));

    for (Reservation reservation : reservationList) {
        Button button = new Button("X");
        Object newItemId = reservationView.getReservationList().addItem();

        button.addClickListener(new Button.ClickListener() {
            @Override/*from ww  w.j  a va 2s  . c o  m*/
            public void buttonClick(Button.ClickEvent clickEvent) {
                dataModel.cancelReservation(reservation);
                reservationView.getReservationList().removeItem(newItemId);
            }
        });

        Item row1 = reservationView.getReservationList().getItem(newItemId);
        row1.getItemProperty("Room").setValue(reservation.getRoom().getRoomNr());
        row1.getItemProperty("Start Time").setValue(reservation.getBegin());
        row1.getItemProperty("End Time").setValue(reservation.getEnd());
        row1.getItemProperty("Cancel").setValue(button);
    }
}

From source file:ch.bfh.ti.soed.hs16.srs.green.view.MyUI.java

License:Open Source License

/**
 * Method which actually creates the whole UI.
 *///from   w w w .j  a v a 2  s  . c o m
@Override
protected void init(VaadinRequest vaadinRequest) {

    VerticalLayout layout = new VerticalLayout();

    Panel panel = new Panel("Login");
    panel.setSizeUndefined();

    FormLayout content = new FormLayout();
    userName = new TextField("Username");
    content.addComponent(userName);

    PasswordField password = new PasswordField("Password");
    content.addComponent(password);

    Button login = new Button("Login");
    register = new Button("Register");
    CheckBox askBox = new CheckBox("Are you a Roommanager?");

    login.setStyleName(Reindeer.BUTTON_SMALL);
    login.setWidth("86px");

    register.setStyleName(Reindeer.BUTTON_SMALL);
    register.setWidth("86px");
    askBox.setStyleName(Reindeer.BUTTON_SMALL);

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    hl.addComponent(login);
    hl.addComponent(register);
    hl.addComponent(askBox);

    content.addComponent(hl);
    content.setSizeUndefined();
    content.setMargin(true);

    panel.setContent(content);

    login.addClickListener(e -> {
        System.out.println(userName.getValue());
        System.out.println(password.getValue());
        try {
            if (controller.login(userName.getValue(), password.getValue())
                    || userName.equals(userName.getValue()) && password.equals(password.getValue())) {
                setContent(new ReservationUI());
            }
        } catch (Throwable e1) {
            e1.printStackTrace();
        }
    });

    register.addClickListener(e -> {
        try {
            Role x = askBox.getValue() ? Role.ROOMMANAGER : Role.CUSTOMER;
            controller.register(userName.getValue(), password.getValue(), x);
        } catch (Throwable e1) {
            e1.printStackTrace();
        }
    });

    layout.setMargin(true);
    layout.setSpacing(true);
    layout.addComponent(panel);
    setContent(layout);
}

From source file:ch.bfh.ti.soed.hs16.srs.kandr3.view.MyUI.java

License:Open Source License

@Override
protected void init(VaadinRequest vaadinRequest) {
    final VerticalLayout layout = new VerticalLayout();

    final TextField name = new TextField();
    name.setCaption("Type your name here:");

    Button button = new Button("Click Me");
    button.addClickListener(e -> {
        layout.addComponent(new Label("Thanks " + name.getValue() + ", it works!"));
    });/*  www  .  j  a v  a  2 s  . c  o  m*/

    layout.addComponents(name, button);
    layout.setMargin(true);
    layout.setSpacing(true);

    setContent(layout);
}

From source file:com.anothernode.ballkontrolle.BallkontrolleUI.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);/*from   w w w . java 2  s  . c  o  m*/
    setContent(layout);

    Label team1Player1 = new Label("");
    Label team1Player2 = new Label("");
    Label team2Player1 = new Label("");
    Label team2Player2 = new Label("");

    final Button button = new Button("Draw Teams");
    button.addClickListener(event -> {

        final Drawing drawing = new Drawing(Data.summonPlayers());

        team1Player1.setValue(drawing.getTeam1().getPlayer1().toString());
        team1Player2.setValue(drawing.getTeam1().getPlayer2().toString());
        team2Player1.setValue(drawing.getTeam2().getPlayer1().toString());
        team2Player2.setValue(drawing.getTeam2().getPlayer2().toString());

    });

    layout.addComponent(button);
    layout.addComponent(new Label("Team 1:"));
    layout.addComponent(team1Player1);
    layout.addComponent(team1Player2);
    layout.addComponent(new Label("Team 2:"));
    layout.addComponent(team2Player1);
    layout.addComponent(team2Player2);
}

From source file:com.anphat.customer.controller.CustomerContactController.java

private void addEditButtonForTableCareCust() {
    panelTblHistory.getMainTable().addGeneratedColumn("btnEdit", new CustomTable.ColumnGenerator() {
        @Override/* w w w  . ja v a  2  s .  c om*/
        public Object generateCell(CustomTable source, Object itemId, Object columnId) {
            final CustomerCareHistoryDTO editDTO = (CustomerCareHistoryDTO) itemId;
            Button btnEdit = new Button();
            btnEdit.addStyleName("v-button-link");
            btnEdit.setIcon(FontAwesome.EDIT);
            //                btnEdit.setCaption("Sa");
            btnEdit.addClickListener(new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    CustomerContactDialog contactDialog = new CustomerContactDialog(
                            BundleUtils.getString("customerCareHistoryForm"), lstCustomerServiceStatus,
                            lstCustContact);
                    contactDialog.fillData2Dialog(editDTO);
                    contactDialog.setIsEdit(Boolean.TRUE);
                    UI.getCurrent().addWindow(contactDialog);
                    addListenerBtnSaveContactWhenEditCare(contactDialog, editDTO);
                    event.getButton().setEnabled(true);
                }
            });
            return btnEdit;
        }
    });
}

From source file:com.anphat.customer.controller.CustomerContactController.java

private void addBtnReportClickListener(Button btn, final TermInformationDTO term) {
    btn.addClickListener(new Button.ClickListener() {
        @Override//from w  ww. j  a  v  a2s. c  om
        public void buttonClick(Button.ClickEvent event) {
            CustomerCareHistoryDTO careHistoryDTO = getCustomerStatus(term);
            event.getButton().setEnabled(true);
        }
    });
}