Example usage for com.vaadin.ui Button setEnabled

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

Introduction

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

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:com.etest.view.tq.itemanalysis.TQItemAnalysisUI.java

public Table populateDataTable() {
    removeAllItems();/*from  ww  w .j ava2s.c om*/
    int i = 0;
    for (TQCoverage t : tq.getAllTQCoverage()) {
        VerticalLayout v = new VerticalLayout();
        v.setWidth("100%");

        Button analyze = new Button();
        analyze.setWidthUndefined();
        analyze.setData(t.getTqCoverageId());
        analyze.setCaption((t.getAnalyzed() == 0) ? "Unanalyze" : "Analyzed");
        analyze.setIcon(FontAwesome.BULLSEYE);
        analyze.addStyleName(ValoTheme.BUTTON_LINK);
        analyze.addStyleName(ValoTheme.BUTTON_TINY);
        analyze.addStyleName(ValoTheme.BUTTON_QUIET);
        analyze.addStyleName("button-container");
        analyze.setEnabled(t.getAnalyzed() == 0);
        analyze.addClickListener(buttonClickListener);
        v.addComponent(analyze);
        v.setComponentAlignment(analyze, Alignment.MIDDLE_LEFT);

        Button view = new Button("View");
        view.setWidthUndefined();
        view.setData(t.getTqCoverageId());
        view.setIcon(FontAwesome.VIDEO_CAMERA);
        view.addStyleName(ValoTheme.BUTTON_LINK);
        view.addStyleName(ValoTheme.BUTTON_TINY);
        view.addStyleName(ValoTheme.BUTTON_QUIET);
        view.addStyleName("button-container");
        view.setVisible((t.getAnalyzed() != 0));
        view.addClickListener(buttonClickListener);
        v.addComponent(view);
        v.setComponentAlignment(view, Alignment.MIDDLE_LEFT);

        addItem(new Object[] { t.getExamTitle(), cs.getCurriculumById(t.getCurriculumId()).getSubject(),
                t.getDateCreated(), t.getTotalHoursCoverage(), t.getTotalItems(), v }, i);
        i++;
    }
    setPageLength(size());

    return this;
}

From source file:com.example.AbstractMongoDemo.java

License:Apache License

protected void disable(Button... btns) {
    for (Button b : btns)
        b.setEnabled(false);
}

From source file:com.example.AbstractMongoDemo.java

License:Apache License

protected void enable(Button... btns) {
    for (Button b : btns)
        b.setEnabled(true);
}

From source file:com.fatminds.vaadin_cmis_integration.demo.DemoPage.java

License:Apache License

protected void setupContentSaveButton() {
    btnSaveContent.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            b.setEnabled(false);
            // Ensure that a document is currently selected
            String selectedItemId = (String) cmisList_1.getValue();
            if (null == selectedItemId)
                return;
            CmisItem item = (CmisItem) cmisList_1.getContainerDataSource().getItem(selectedItemId);
            Document doc = (Document) item.getCmisObject();
            putContentToDocument(doc);/*  ww w  .j  a v a  2s  .co  m*/
            b.setEnabled(true);
        }
    });
}

From source file:com.haulmont.cuba.web.exception.ExceptionDialog.java

License:Apache License

public ExceptionDialog(Throwable throwable, @Nullable String caption, @Nullable String message) {
    final AppUI ui = AppUI.getCurrent();

    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);

    com.vaadin.event.ShortcutAction closeShortcutAction = new com.vaadin.event.ShortcutAction(
            "closeShortcutAction", closeCombination.getKey().getCode(),
            KeyCombination.Modifier.codes(closeCombination.getModifiers()));

    addActionHandler(new com.vaadin.event.Action.Handler() {
        @Override/*from   w  w w. ja v a  2  s . co m*/
        public com.vaadin.event.Action[] getActions(Object target, Object sender) {
            return new com.vaadin.event.Action[] { closeShortcutAction };
        }

        @Override
        public void handleAction(com.vaadin.event.Action action, Object sender, Object target) {
            if (Objects.equals(action, closeShortcutAction)) {
                close();
            }
        }
    });

    setCaption(caption != null ? caption : messages.getMainMessage("exceptionDialog.caption"));

    ThemeConstants theme = ui.getApp().getThemeConstants();
    setWidth(theme.get("cuba.web.ExceptionDialog.width"));
    center();

    final String text = message != null ? message : getText(throwable);
    Throwable exception = removeRemoteException(throwable);
    final String stackTrace = getStackTrace(exception);

    mainLayout = new VerticalLayout();
    mainLayout.setSpacing(true);

    TextArea textArea = new TextArea();
    textArea.setHeight(theme.get("cuba.web.ExceptionDialog.textArea.height"));
    textArea.setWidth(100, Unit.PERCENTAGE);

    boolean showExceptionDetails = userSessionSource.getUserSession() != null
            && security.isSpecificPermitted("cuba.gui.showExceptionDetails");

    if (showExceptionDetails) {
        textArea.setValue(text);
    } else {
        textArea.setValue(messages.getMainMessage("exceptionDialog.contactAdmin"));
    }
    textArea.setReadOnly(true);

    mainLayout.addComponent(textArea);

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSpacing(true);
    buttonsLayout.setWidth("100%");
    mainLayout.addComponent(buttonsLayout);

    Button closeButton = new CubaButton(messages.getMainMessage("exceptionDialog.closeBtn"));
    closeButton.addClickListener((Button.ClickListener) event -> this.close());
    buttonsLayout.addComponent(closeButton);

    showStackTraceButton = new CubaButton(messages.getMainMessage("exceptionDialog.showStackTrace"));
    showStackTraceButton
            .addClickListener((Button.ClickListener) event -> setStackTraceVisible(!isStackTraceVisible));
    buttonsLayout.addComponent(showStackTraceButton);
    showStackTraceButton.setVisible(showExceptionDetails);

    Label spacer = new Label();
    buttonsLayout.addComponent(spacer);
    buttonsLayout.setExpandRatio(spacer, 1);

    String cubaLogContentClass = "c-exception-dialog-log-content";
    String cubaCopyLogContentClass = cubaLogContentClass + "-" + UUID.randomUUID();

    if (browserSupportCopy()) {
        copyButton = new CubaButton(messages.getMainMessage("exceptionDialog.copyStackTrace"));
        copyButton.setVisible(false);
        CubaCopyButtonExtension copyExtension = CubaCopyButtonExtension.copyWith(copyButton,
                cubaCopyLogContentClass);
        copyExtension
                .addCopyListener(
                        event -> Notification.show(
                                messages.getMainMessage(event.isSuccess() ? "exceptionDialog.copingSuccessful"
                                        : "exceptionDialog.copingFailed"),
                                Notification.Type.TRAY_NOTIFICATION));
        buttonsLayout.addComponent(copyButton);
    }

    if (userSessionSource.getUserSession() != null) {
        if (!StringUtils.isBlank(clientConfig.getSupportEmail())) {
            Button reportButton = new CubaButton(messages.getMainMessage("exceptionDialog.reportBtn"));
            reportButton.addClickListener((Button.ClickListener) event -> {
                sendSupportEmail(text, stackTrace);
                reportButton.setEnabled(false);
            });
            buttonsLayout.addComponent(reportButton);

            if (ui.isTestMode()) {
                reportButton.setCubaId("errorReportButton");
            }
        }
    }

    Button logoutButton = new CubaButton(messages.getMainMessage("exceptionDialog.logout"));
    logoutButton.addClickListener((Button.ClickListener) event -> logoutPrompt());
    buttonsLayout.addComponent(logoutButton);

    stackTraceTextArea = new TextArea();
    stackTraceTextArea.setSizeFull();
    stackTraceTextArea.setWordwrap(false);
    stackTraceTextArea.setValue(stackTrace);
    stackTraceTextArea.setStyleName(cubaLogContentClass);
    stackTraceTextArea.addStyleName(cubaCopyLogContentClass);
    stackTraceTextArea.setReadOnly(true);

    setContent(mainLayout);
    setResizable(false);

    if (ui.isTestMode()) {
        setId(ui.getTestIdManager().getTestId("exceptionDialog"));
        setCubaId("exceptionDialog");

        closeButton.setCubaId("closeButton");
        if (copyButton != null) {
            copyButton.setCubaId("copyStackTraceButton");
        }
        showStackTraceButton.setCubaId("showStackTraceButton");
        stackTraceTextArea.setCubaId("stackTraceTextArea");
        logoutButton.setCubaId("logoutButton");
    }
}

From source file:com.moscaville.ui.CsvVaadinUI.java

private void buildTemplateGridHeader() {
    HorizontalLayout templateGridHeaderLayout = new HorizontalLayout();
    templateGridHeaderLayout.setSpacing(true);
    templateGridHeaderLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

    Button btnNew = new Button("New", FontAwesome.FILE);
    btnNew.setDescription("New template file");
    btnNew.addClickListener((Button.ClickEvent event) -> {
        templateManager.newTemplate();//from w  w  w  .j  a v a2  s  .co m
    });
    templateGridHeaderLayout.addComponent(btnNew);

    Button btnOpen = new Button("Open", FontAwesome.FILE_O);
    btnOpen.setDescription("Open template file");
    btnOpen.addClickListener((Button.ClickEvent event) -> {
        fileChooser.setFileExtension(FileChooser.FILE_EXTENSION_TEMPLATE);
        addWindow(fileChooser);
    });
    templateGridHeaderLayout.addComponent(btnOpen);

    Button btnSave = new Button("Save", FontAwesome.SAVE);
    tfTemplateFileName = new TextField();
    tfTemplateFileName.setDescription("template file name");
    tfTemplateFileName.setInputPrompt("template file name");
    tfTemplateFileName.setImmediate(true);
    tfTemplateFileName.addValueChangeListener((Property.ValueChangeEvent event) -> {
        btnSave.setEnabled(tfTemplateFileName.getValue() != null && tfTemplateFileName.getValue().length() > 0);
    });
    templateGridHeaderLayout.addComponent(tfTemplateFileName);

    FieldGroup binder = new FieldGroup(templateManager.getTemplateBeanItem());
    binder.setBuffered(false);
    binder.bind(tfTemplateFileName, "templateFileName");

    btnSave.setDescription("Save template file");
    btnSave.setImmediate(true);
    btnSave.setEnabled(false);
    btnSave.addClickListener((Button.ClickEvent event) -> {
        templateManager.saveTemplate();
    });
    templateGridHeaderLayout.addComponent(btnSave);

    Button btnData = new Button("Data", FontAwesome.DATABASE);
    btnData.setDescription("Load data");
    btnData.addClickListener((Button.ClickEvent event) -> {
        fileChooser.setFileExtension(FileChooser.FILE_EXTENSION_CSV);
        addWindow(fileChooser);
    });
    templateGridHeaderLayout.addComponent(btnData);

    Button btnImport = new Button("Import", FontAwesome.DOWNLOAD);

    templateGridHeaderLayout.addComponent(btnImport);
    mainLayout.addComponent(templateGridHeaderLayout);
}

From source file:com.mycollab.mobile.module.crm.ui.CrmPreviewFormControlsGenerator.java

License:Open Source License

public VerticalLayout createButtonControls(int buttonEnableFlags, final String permissionItem) {
    boolean canWrite = true;
    boolean canAccess = true;
    if (permissionItem != null) {
        canWrite = UserUIContext.canWrite(permissionItem);
        canAccess = UserUIContext.canAccess(permissionItem);
    }/*from www.j a v a2 s. co  m*/

    if ((buttonEnableFlags & EDIT_BTN_PRESENTED) == EDIT_BTN_PRESENTED) {
        MButton editBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_EDIT), clickEvent -> {
            final T item = previewForm.getBean();
            previewForm.fireEditForm(item);
        }).withVisible(canWrite);
        editButtons.addComponent(editBtn);
        editButtons.setComponentAlignment(editBtn, Alignment.MIDDLE_CENTER);
    }

    if ((buttonEnableFlags & DELETE_BTN_PRESENTED) == DELETE_BTN_PRESENTED) {
        Button deleteBtn = new Button(UserUIContext.getMessage(GenericI18Enum.BUTTON_DELETE), clickEvent -> {
            final T item = previewForm.getBean();
            previewForm.fireDeleteForm(item);
        });
        editButtons.addComponent(deleteBtn);
        editButtons.setComponentAlignment(deleteBtn, Alignment.MIDDLE_CENTER);
        deleteBtn.setEnabled(canAccess);
    }

    if ((buttonEnableFlags & CLONE_BTN_PRESENTED) == CLONE_BTN_PRESENTED) {
        Button cloneBtn = new Button(UserUIContext.getMessage(GenericI18Enum.BUTTON_CLONE), clickEvent -> {
            T item = previewForm.getBean();
            previewForm.fireCloneForm(item);
        });
        cloneBtn.setWidth("100%");
        editButtons.addComponent(cloneBtn);
        editButtons.setComponentAlignment(cloneBtn, Alignment.MIDDLE_CENTER);
        cloneBtn.setEnabled(canWrite);
    }

    return editButtons;
}

From source file:com.mycollab.mobile.module.project.ui.ProjectPreviewFormControlsGenerator.java

License:Open Source License

public VerticalLayout createButtonControls(int buttonEnableFlags, final String permissionItem) {
    boolean canWrite = true;
    boolean canAccess = true;
    if (permissionItem != null) {
        canWrite = UserUIContext.canWrite(permissionItem);
        canAccess = UserUIContext.canAccess(permissionItem);
    }//from  www  .j  a  v a2 s .c  o m

    if ((buttonEnableFlags & EDIT_BTN_PRESENTED) == EDIT_BTN_PRESENTED) {
        Button editBtn = new Button(UserUIContext.getMessage(GenericI18Enum.BUTTON_EDIT), clickEvent -> {
            T item = previewForm.getBean();
            previewForm.fireEditForm(item);
        });
        editBtn.setEnabled(canWrite);
        editButtons.addComponent(editBtn);
    }

    if ((buttonEnableFlags & DELETE_BTN_PRESENTED) == DELETE_BTN_PRESENTED) {
        Button deleteBtn = new Button(UserUIContext.getMessage(GenericI18Enum.BUTTON_DELETE), clickEvent -> {
            T item = previewForm.getBean();
            previewForm.fireDeleteForm(item);
        });
        deleteBtn.setEnabled(canAccess);
        editButtons.addComponent(deleteBtn);
    }

    if ((buttonEnableFlags & CLONE_BTN_PRESENTED) == CLONE_BTN_PRESENTED) {
        Button cloneBtn = new Button(UserUIContext.getMessage(GenericI18Enum.BUTTON_CLONE), clickEvent -> {
            T item = previewForm.getBean();
            previewForm.fireCloneForm(item);
        });
        cloneBtn.setEnabled(canWrite);
        editButtons.addComponent(cloneBtn);
    }

    if ((buttonEnableFlags & ASSIGN_BTN_PRESENTED) == ASSIGN_BTN_PRESENTED) {
        Button assignBtn = new Button(UserUIContext.getMessage(GenericI18Enum.BUTTON_ASSIGN), clickEvent -> {
            T item = previewForm.getBean();
            previewForm.fireAssignForm(item);
        });
        editButtons.setEnabled(canWrite);
        editButtons.addComponent(assignBtn);
    }

    return editButtons;
}

From source file:com.mycollab.module.crm.view.activity.ActivitySearchPanel.java

License:Open Source License

@Override
protected Component buildExtraControls() {
    final SplitButton splitBtn = new SplitButton();
    splitBtn.setSizeUndefined();/*w w  w . ja va  2 s  .c  o m*/
    splitBtn.setEnabled(UserUIContext.canWrite(RolePermissionCollections.CRM_CALL)
            || UserUIContext.canWrite(RolePermissionCollections.CRM_MEETING));
    splitBtn.addStyleName(WebThemes.BUTTON_ACTION);
    splitBtn.setIcon(FontAwesome.PLUS);
    splitBtn.setCaption(UserUIContext.getMessage(TaskI18nEnum.NEW));
    splitBtn.addClickListener(
            event -> EventBusFactory.getInstance().post(new ActivityEvent.TaskAdd(this, null)));

    OptionPopupContent btnControlsLayout = new OptionPopupContent();
    splitBtn.setContent(btnControlsLayout);

    Button createMeetingBtn = new Button(UserUIContext.getMessage(MeetingI18nEnum.NEW), clickEvent -> {
        splitBtn.setPopupVisible(false);
        EventBusFactory.getInstance().post(new ActivityEvent.MeetingAdd(this, null));
    });
    btnControlsLayout.addOption(createMeetingBtn);
    createMeetingBtn.setEnabled(UserUIContext.canWrite(RolePermissionCollections.CRM_MEETING));
    final Button createCallBtn = new Button(UserUIContext.getMessage(CallI18nEnum.NEW), clickEvent -> {
        splitBtn.setPopupVisible(false);
        EventBusFactory.getInstance().post(new ActivityEvent.CallAdd(this, null));
    });
    createCallBtn.setEnabled(UserUIContext.canWrite(RolePermissionCollections.CRM_CALL));
    btnControlsLayout.addOption(createCallBtn);

    ButtonGroup viewSwitcher = new ButtonGroup();

    Button calendarViewBtn = new Button("Calendar",
            clickEvent -> EventBusFactory.getInstance().post(new ActivityEvent.GotoCalendar(this, null)));
    calendarViewBtn.addStyleName(WebThemes.BUTTON_ACTION);
    viewSwitcher.addButton(calendarViewBtn);

    Button activityListBtn = new Button("Activities");
    activityListBtn.setStyleName("selected");
    activityListBtn.addStyleName(WebThemes.BUTTON_ACTION);
    viewSwitcher.addButton(activityListBtn);

    return new MHorizontalLayout(splitBtn, viewSwitcher);
}

From source file:com.ocs.dynamo.ui.composite.form.ModelBasedEditForm.java

License:Apache License

/**
 * Sets the state (enabled/disabled) of the save button. The button is enabled if the from is
 * valid and all of its detail tables are as well
 *//* w  w w  .j  a  v  a 2  s.c o m*/
private void checkSaveButtonState() {
    for (Button saveButton : saveButtons) {
        boolean valid = groups.get(isViewMode()).isValid();

        for (Boolean b : detailTablesValid.values()) {
            valid &= b;
        }
        saveButton.setEnabled(valid);
    }
}