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:de.metas.ui.web.vaadin.window.components.ATabToolbar.java

License:Open Source License

private void addToolbarButton(final ActionInfo actionInfo) {
    final String action = actionInfo.getAction();

    final Button button = new Button();
    button.setCaption(action);//from   www.  j  a va2 s  . c o m
    button.setData(actionInfo);
    button.setEnabled(model.isActionEnabled(action));
    button.addClickListener(actionButtonListener);

    action2button.put(action, button);

    addComponent(button);
}

From source file:de.metas.ui.web.vaadin.window.editor.LocationEditorPopup.java

License:Open Source License

public LocationEditorPopup(final LookupValue lookupValue) {
    super();//w ww  . j  av  a  2  s.  c o  m
    VaadinClientApplication.autowire(this);

    addStyleName(STYLE);

    setWidth(300, Unit.PIXELS); // FIXME: CSS hardcoded
    setModal(true);
    setCaption("Location");
    setIcon(FontAwesome.LOCATION_ARROW);
    setDraggable(true);
    setResizable(false);

    this.lookupValue = lookupValue;

    this.locationPresenter = new WindowPresenter();

    final EditorView locationView = new EditorView();
    locationPresenter.setView(locationView);
    locationPresenter.setRootPropertyDescriptorFromWindow(WindowConstants.AD_WINDOW_ID_Location);

    final WindowModel locationModel = locationPresenter.getModel();
    locationModel.newRecordAsCopyById(lookupValue == null ? null : lookupValue.getId());

    final Button btnSave = new Button("Save");
    btnSave.addClickListener(event -> saveAndClose());

    final VerticalLayout content = new VerticalLayout(locationPresenter.getViewComponent(), btnSave);
    setContent(content);

    setErrorHandler(event -> locationPresenter.onError(event.getThrowable()));
}

From source file:de.metas.ui.web.vaadin.window.view.WindowPanelsBar.java

License:Open Source License

public void addNavigationShortcut(final Editor editor) {
    if (editor == null) {
        return;//from  w  w w.j  a v  a2  s.c  o m
    }

    final Component editorComp = editor.getComponent();
    if (editorComp == null) {
        return;
    }

    final Button button = new Button();
    button.setPrimaryStyleName("mf-tabbar-button");
    button.setCaption(editor.getCaption());
    content.addComponent(button);

    button.addClickListener(event -> UI.getCurrent().scrollIntoView(editorComp));
}

From source file:de.metas.ui.web.vaadin.window.view.WindowViewImpl.java

License:Open Source License

@Override
public void setActions(final ActionsList actions) {
    if (Objects.equals(this._actions, actions)) {
        return;/*from   ww  w  .  java  2 s  . c o m*/
    }

    this._actions = ActionsList.copyOf(actions);

    //
    // Toolbar actions
    actionsPanel.removeAllComponents();
    for (final Action action : _actions) {
        if (!action.isToolbarAction()) {
            continue;
        }

        final String actionId = action.getActionId();

        final Button btn = new Button();
        btn.setCaption(action.getCaption());
        btn.setIcon(Theme.getVaadinResource(action.getIcon()));
        btn.addClickListener(event -> getWindowViewListener().onActionClicked(actionId));
        actionsPanel.addComponent(btn);

    }
}

From source file:de.sebastianrothbucher.vaadin.meetup.ui.std.view.FirstPageViewImplEx.java

License:Apache License

@Override
public void showImprint(String imprintHtml) {
    popover = new Popover();
    popover.setSizeFull();/*  ww  w.j  a  v  a 2s  .co m*/
    popover.setModal(false);
    VerticalLayout imprintLayout = new VerticalLayout();
    Label imprintLabel = new Label(imprintHtml, ContentMode.HTML);
    imprintLabel.addStyleName("styleid-FirstPageViewImplEx-imprintLabel");
    imprintLayout.addComponent(imprintLabel);
    Button closeButton = new Button("Schlieen");
    closeButton.addClickListener(new ClickListener() {

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

        @Override
        public void buttonClick(ClickEvent event) {
            popoverSchliessen();
        }
    });
    imprintLayout.addComponent(closeButton);
    popover.setContent(imprintLayout);
    UI.getCurrent().addWindow(popover);
}

From source file:de.steinwedel.messagebox.MessageBox.java

License:Apache License

/**
 * Adds a button. If an event listener (java.lang.Runnable) should be applied, the Runnable must be
 * assigned to the object attribute data.
 *
 * @param button  The button/* w  w  w .  java  2  s .c  o m*/
 * @param options Some optional {@link ButtonOption}s
 * @return The {@link MessageBox} instance
 */
public MessageBox withButton(Button button, ButtonOption... options) {
    if (immutable) {
        throw new IllegalStateException(
                "The dialog cannot be enhanced with a button after it has been opened.");
    }
    if (button != null) {
        buttonLayout.addComponent(button);

        buttonAdded = true;

        if (button.getData() != null && button.getData() instanceof Runnable) {
            button.addClickListener(new ClickListener() {

                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    Runnable runnable = (Runnable) event.getButton().getData();
                    runnable.run();
                }

            });
        }

        boolean autoCloseNotFound = true;
        for (ButtonOption option : options) {
            option.apply(this, button);
            if (option instanceof ButtonOption.CloseOnClick) {
                autoCloseNotFound = false;
            }
        }
        if (autoCloseNotFound) {
            new ButtonOption.CloseOnClick(true).apply(this, button);
        }
    }
    return this;
}

From source file:de.symeda.sormas.ui.caze.AbstractTableField.java

License:Open Source License

protected Button createAddButton() {

    Button button = new Button(I18nProperties.getCaption(Captions.actionNewEntry));
    button.addStyleName(ValoTheme.BUTTON_LINK);

    button.addClickListener(new ClickListener() {

        @Override// w w  w . ja  va2  s  . co m
        public void buttonClick(ClickEvent event) {
            addEntry();
        }
    });

    return button;
}

From source file:de.symeda.sormas.ui.caze.CaseController.java

License:Open Source License

private void appendSpecialCommands(CaseDataDto caze,
        CommitDiscardWrapperComponent<? extends Component> editView) {
    if (UserProvider.getCurrent().hasUserRole(UserRole.ADMIN)) {
        editView.addDeleteListener(new DeleteListener() {
            @Override//w w  w  .j a  v  a  2  s .c  o m
            public void onDelete() {
                FacadeProvider.getCaseFacade().deleteCase(caze.toReference(),
                        UserProvider.getCurrent().getUserReference().getUuid());
                UI.getCurrent().getNavigator().navigateTo(CasesView.VIEW_NAME);
            }
        }, I18nProperties.getString(Strings.entityCase));
    }

    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_ARCHIVE)) {
        boolean archived = FacadeProvider.getCaseFacade().isArchived(caze.getUuid());
        Button archiveCaseButton = new Button();
        archiveCaseButton.addStyleName(ValoTheme.BUTTON_LINK);
        if (archived) {
            archiveCaseButton.setCaption(I18nProperties.getCaption(Captions.actionDearchive));
        } else {
            archiveCaseButton.setCaption(I18nProperties.getCaption(Captions.actionArchive));
        }
        archiveCaseButton.addClickListener(e -> {
            editView.commit();
            archiveOrDearchiveCase(caze.getUuid(), !archived);
        });

        editView.getButtonsPanel().addComponentAsFirst(archiveCaseButton);
        editView.getButtonsPanel().setComponentAlignment(archiveCaseButton, Alignment.BOTTOM_LEFT);
    }

    // Initialize 'Transfer case' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_TRANSFER) && !caze.isUnreferredPortHealthCase()) {
        Button transferCaseButton = new Button();
        transferCaseButton.setCaption(I18nProperties.getCaption(Captions.caseTransferCase));
        transferCaseButton.addClickListener(new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(ClickEvent event) {
                editView.commit();
                CaseDataDto cazeDto = findCase(caze.getUuid());
                transferCase(cazeDto);
            }
        });

        editView.getButtonsPanel().addComponentAsFirst(transferCaseButton);
        editView.getButtonsPanel().setComponentAlignment(transferCaseButton, Alignment.BOTTOM_LEFT);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_REFER_FROM_POE)
            && caze.isUnreferredPortHealthCase()) {
        Button btnReferToFacility = new Button();
        btnReferToFacility.setCaption(I18nProperties.getCaption(Captions.caseReferToFacility));
        btnReferToFacility.addClickListener(e -> {
            editView.commit();
            CaseDataDto caseDto = findCase(caze.getUuid());
            referFromPointOfEntry(caseDto);
        });

        editView.getButtonsPanel().addComponentAsFirst(btnReferToFacility);
        editView.getButtonsPanel().setComponentAlignment(btnReferToFacility, Alignment.BOTTOM_LEFT);
    }
}

From source file:de.symeda.sormas.ui.caze.CaseController.java

License:Open Source License

public void transferCase(CaseDataDto caze) {
    CaseFacilityChangeForm facilityChangeForm = new CaseFacilityChangeForm(UserRight.CASE_TRANSFER);
    facilityChangeForm.setValue(caze);/* ww  w . j av a2s  .c o  m*/
    CommitDiscardWrapperComponent<CaseFacilityChangeForm> facilityChangeView = new CommitDiscardWrapperComponent<CaseFacilityChangeForm>(
            facilityChangeForm, facilityChangeForm.getFieldGroup());
    facilityChangeView.getCommitButton().setCaption(I18nProperties.getCaption(Captions.caseTransferCase));
    facilityChangeView.setMargin(true);

    Window popupWindow = VaadinUiUtil.showPopupWindow(facilityChangeView);
    popupWindow.setCaption(I18nProperties.getString(Strings.headingTransferCase));

    facilityChangeView.addCommitListener(new CommitListener() {
        @Override
        public void onCommit() {
            if (!facilityChangeForm.getFieldGroup().isModified()) {
                CaseDataDto dto = facilityChangeForm.getValue();
                FacadeProvider.getCaseFacade().saveAndTransferCase(dto);
                popupWindow.close();
                Notification.show(I18nProperties.getString(Strings.messageCaseTransfered),
                        Type.WARNING_MESSAGE);
                SormasUI.refreshView();
            }
        }
    });

    Button cancelButton = new Button(I18nProperties.getCaption(Captions.actionCancel));
    cancelButton.setStyleName(ValoTheme.BUTTON_LINK);
    cancelButton.addClickListener(e -> {
        popupWindow.close();
    });
    facilityChangeView.getButtonsPanel().replaceComponent(facilityChangeView.getDiscardButton(), cancelButton);
}

From source file:de.symeda.sormas.ui.caze.CaseController.java

License:Open Source License

public void referFromPointOfEntry(CaseDataDto caze) {
    CaseFacilityChangeForm form = new CaseFacilityChangeForm(UserRight.CASE_REFER_FROM_POE);
    form.setValue(caze);//from   w w  w  .  j  a v a2s  .c o  m
    CommitDiscardWrapperComponent<CaseFacilityChangeForm> view = new CommitDiscardWrapperComponent<CaseFacilityChangeForm>(
            form, form.getFieldGroup());
    view.getCommitButton().setCaption(I18nProperties.getCaption(Captions.caseReferToFacility));

    Window window = VaadinUiUtil.showPopupWindow(view);
    window.setCaption(I18nProperties.getString(Strings.headingReferCaseFromPointOfEntry));

    view.addCommitListener(() -> {
        if (!form.getFieldGroup().isModified()) {
            CaseDataDto dto = form.getValue();
            dto.getHospitalization().setAdmissionDate(new Date());
            FacadeProvider.getCaseFacade().saveCase(dto);
            window.close();
            Notification.show(I18nProperties.getString(Strings.messageCaseReferredFromPoe),
                    Type.ASSISTIVE_NOTIFICATION);
            SormasUI.refreshView();
        }
    });

    Button btnCancel = new Button(I18nProperties.getCaption(Captions.actionCancel));
    btnCancel.addClickListener(e -> {
        window.close();
    });
    view.getButtonsPanel().replaceComponent(view.getDiscardButton(), btnCancel);
}