Example usage for com.vaadin.ui CheckBox CheckBox

List of usage examples for com.vaadin.ui CheckBox CheckBox

Introduction

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

Prototype

public CheckBox(String caption, boolean initialState) 

Source Link

Document

Creates a new checkbox with a caption and a set initial state.

Usage

From source file:com.scipionyx.butterflyeffect.frontend.configuration.ui.view.AccessControlView.java

License:Apache License

/**
 * //w ww.j av a  2s . co m
 * @param caption
 * @param viewName
 * @return
 */
private CheckBox createViewCheckbox(String caption, final String viewName) {
    final CheckBox checkBox = new CheckBox(caption, allowedViews.contains(viewName));
    checkBox.addValueChangeListener(event -> changeValue(event, viewName));
    return checkBox;
}

From source file:com.trender.user.component.wizard.LastStepWizardStudy.java

@Override
public Component getContent() {
    if (layout == null) {
        allowBack = new CheckBox(" ?   ?", false);

        layout = new VerticalLayout();
        layout.setMargin(true);/*from   w w w.j a  v a  2s. co  m*/
        layout.addComponent(new Label("<h2>? ? ?</h2>", ContentMode.HTML));
        //            layout.addComponent(new Button("Add new steps",
        //                    new Button.ClickListener() {
        //
        //                private static final long serialVersionUID = 1L;
        //
        //                @Override
        //                public void buttonClick(Button.ClickEvent event) {
        //                    owner.addStep(new WizardStep() {
        //
        //                        private final Date createdAt = new Date();
        //
        //                        public boolean onBack() {
        //                            return true;
        //                        }
        //
        //                        public boolean onAdvance() {
        //                            return true;
        //                        }
        //
        //                        public Component getContent() {
        //                            VerticalLayout layout = new VerticalLayout();
        //                            layout.setMargin(true);
        //                            layout.addComponent(new Label(
        //                                    "This step was created on "
        //                                    + createdAt));
        //                            return layout;
        //                        }
        //
        //                        public String getCaption() {
        //                            return "Generated step";
        //                        }
        //                    });
        //                }
        //            }));
        //
        //            layout.addComponent(new Label(
        //                    "<h2>Want to go back?</h2><p>This step is also an example of conditionally allowing you to go back.<br />"
        //                    + "Try to click the back button and then again after checking the checkbox below.</p>",
        //                    ContentMode.HTML));
        layout.addComponent(allowBack);
    }
    return layout;
}

From source file:com.wintindustries.pfserver.interfaces.view.dashboard.LoginView.java

private Component buildLoginForm() {
    final VerticalLayout loginPanel = new VerticalLayout();
    loginPanel.setSizeUndefined();/*  ww w.  j av a2s  .c  o m*/
    loginPanel.setSpacing(true);
    Responsive.makeResponsive(loginPanel);
    loginPanel.addStyleName("login-panel");

    loginPanel.addComponent(buildLabels());
    loginPanel.addComponent(buildFields());
    loginPanel.addComponent(new CheckBox("Remember me", true));
    return loginPanel;
}

From source file:de.catma.ui.analyzer.MarkupResultPanel.java

License:Open Source License

private void initComponents() {
    setSizeFull();//from   w ww .j  a  va2  s  .c om

    HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
    splitPanel.setSizeFull();
    VerticalLayout leftComponent = new VerticalLayout();
    leftComponent.setSpacing(true);
    leftComponent.setSizeFull();

    resultTable = new TreeTable();
    resultTable.setSelectable(true);
    resultTable.setMultiSelect(true);
    HierarchicalContainer container = new HierarchicalContainer();
    container.setItemSorter(new PropertyDependentItemSorter(TreePropertyName.caption,
            new PropertyToTrimmedStringCIComparator()));

    resultTable.setContainerDataSource(container);

    resultTable.addContainerProperty(TreePropertyName.caption, String.class, null);
    resultTable.setColumnHeader(TreePropertyName.caption, "Tag Definition");

    resultTable.addContainerProperty(TreePropertyName.sourcedocument, String.class, null);
    resultTable.setColumnHeader(TreePropertyName.sourcedocument, "Source Document");

    resultTable.addContainerProperty(TreePropertyName.markupcollection, String.class, null);
    resultTable.setColumnHeader(TreePropertyName.markupcollection, "Markup Collection");

    resultTable.addContainerProperty(TreePropertyName.phrase, String.class, null);
    resultTable.setColumnHeader(TreePropertyName.phrase, "Phrase");

    resultTable.addContainerProperty(TreePropertyName.propertyname, String.class, null);
    resultTable.setColumnHeader(TreePropertyName.propertyname, "Property");

    resultTable.addContainerProperty(TreePropertyName.propertyvalue, String.class, null);
    resultTable.setColumnHeader(TreePropertyName.propertyvalue, "Property value");

    resultTable.addContainerProperty(TreePropertyName.frequency, Integer.class, null);
    resultTable.setColumnHeader(TreePropertyName.frequency, "Frequency");
    resultTable.addContainerProperty(TreePropertyName.visible, AbstractComponent.class, null);
    resultTable.setColumnHeader(TreePropertyName.visible, "Visible in Kwic");

    resultTable.setItemCaptionPropertyId(TreePropertyName.caption);
    resultTable.setPageLength(10); //TODO: config
    resultTable.setSizeFull();
    resultTable.setColumnCollapsingAllowed(true);
    resultTable.setColumnCollapsible(TreePropertyName.caption, false);
    resultTable.setColumnCollapsible(TreePropertyName.sourcedocument, true);
    resultTable.setColumnCollapsible(TreePropertyName.markupcollection, true);
    resultTable.setColumnCollapsible(TreePropertyName.phrase, true);
    resultTable.setColumnCollapsible(TreePropertyName.propertyname, true);
    resultTable.setColumnCollapsible(TreePropertyName.propertyvalue, true);
    resultTable.setColumnCollapsible(TreePropertyName.frequency, false);
    resultTable.setColumnCollapsible(TreePropertyName.visible, false);

    //TODO: a description generator that shows the version of a Tag
    //      resultTable.setItemDescriptionGenerator(generator);

    leftComponent.addComponent(resultTable);
    leftComponent.setExpandRatio(resultTable, 1.0f);

    HorizontalLayout buttonPanel = new HorizontalLayout();
    buttonPanel.setSpacing(true);
    buttonPanel.setWidth("100%");

    btDist = new Button();
    btDist.setIcon(new ClassResource("ui/analyzer/resources/chart.gif", getApplication()));
    buttonPanel.addComponent(btDist);

    btResultExcelExport = new Button();
    btResultExcelExport.setIcon(new ThemeResource("../images/table-excel.png"));
    btResultExcelExport.setDescription("Export all Query result data as an Excel spreadsheet.");
    buttonPanel.addComponent(btResultExcelExport);

    cbFlatTable = new CheckBox("flat table", false);
    cbFlatTable.setImmediate(true);

    buttonPanel.addComponent(cbFlatTable);
    buttonPanel.setComponentAlignment(cbFlatTable, Alignment.MIDDLE_RIGHT);
    buttonPanel.setExpandRatio(cbFlatTable, 1f);

    btSelectAll = new Button("Select all for Kwic");

    buttonPanel.addComponent(btSelectAll);
    buttonPanel.setComponentAlignment(btSelectAll, Alignment.MIDDLE_RIGHT);
    //      buttonPanel.setExpandRatio(btSelectAll, 1f);
    btDeselectAll = new Button("Deselect all for Kwic");
    buttonPanel.addComponent(btDeselectAll);
    buttonPanel.setComponentAlignment(btDeselectAll, Alignment.MIDDLE_RIGHT);

    leftComponent.addComponent(buttonPanel);

    splitPanel.addComponent(leftComponent);

    VerticalLayout rightComponent = new VerticalLayout();
    rightComponent.setSpacing(true);
    rightComponent.setSizeFull();

    this.kwicPanel = new KwicPanel(repository, relevantUserMarkupCollectionProvider, true);
    rightComponent.addComponent(kwicPanel);
    rightComponent.setExpandRatio(kwicPanel, 1f);

    HorizontalLayout kwicButtonPanel = new HorizontalLayout();
    kwicButtonPanel.setSpacing(true);
    kwicButtonPanel.setWidth("100%");

    btKwicExcelExport = new Button();
    btKwicExcelExport.setIcon(new ThemeResource("../images/table-excel.png"));
    btKwicExcelExport.setDescription("Export all Query result data as an Excel spreadsheet.");
    kwicButtonPanel.addComponent(btKwicExcelExport);
    kwicButtonPanel.setComponentAlignment(btKwicExcelExport, Alignment.MIDDLE_LEFT);

    btUntagResults = new Button("Untag selected Kwics");
    kwicButtonPanel.addComponent(btUntagResults);
    kwicButtonPanel.setComponentAlignment(btUntagResults, Alignment.MIDDLE_RIGHT);
    kwicButtonPanel.setExpandRatio(btUntagResults, 1f);

    Label helpLabel = new Label();
    helpLabel.setIcon(new ClassResource("ui/resources/icon-help.gif", getApplication()));
    helpLabel.setWidth("20px");

    helpLabel.setDescription("<h3>Hints</h3>" + "<h4>Tagging search results</h4>"
            + "You can tag the search results in the Kwic-view: "
            + "<p>First select one or more rows and then drag the desired "
            + "Tag from the Tag Manager over the Kwic-results.</p>" + "<h4>Take a closer look</h4>"
            + "You can jump to the location in the full text by double "
            + "clicking on a row in the Kwic-view.");
    kwicButtonPanel.addComponent(helpLabel);

    kwicButtonPanel.setComponentAlignment(helpLabel, Alignment.MIDDLE_RIGHT);

    rightComponent.addComponent(kwicButtonPanel);
    rightComponent.setComponentAlignment(kwicButtonPanel, Alignment.MIDDLE_RIGHT);

    splitPanel.addComponent(rightComponent);

    addComponent(splitPanel);
}

From source file:de.catma.ui.analyzer.TagKwicDialog.java

License:Open Source License

private CheckBox createUmcRefCheckBox(final UserMarkupCollectionReference umcRef, final SourceDocument sd,
        boolean isTarget) {
    if (isTarget) {
        btOk.setEnabled(true);//w ww  .  j a va  2  s .  c  om
    }
    CheckBox cb = new CheckBox(null, isTarget);
    cb.setImmediate(true);
    cb.addListener(new ValueChangeListener() {

        public void valueChange(ValueChangeEvent event) {
            if (!valueChangeEventActive) {
                valueChangeEventActive = true;
                btOk.setEnabled(true);
                @SuppressWarnings("unchecked")
                Collection<UserMarkupCollectionReference> children = (Collection<UserMarkupCollectionReference>) umcTable
                        .getChildren(sd);
                for (UserMarkupCollectionReference curChild : children) {
                    if (!umcRef.equals(curChild)) {
                        ((CheckBox) (umcTable.getItem(curChild).getItemProperty(UmcTableProperty.TARGET))
                                .getValue()).setValue(false);
                    }

                }
                valueChangeEventActive = false;
            }

        }
    });
    return cb;
}

From source file:de.catma.ui.tagger.PropertyEditDialog.java

License:Open Source License

private CheckBox createCheckBox(final Property p, final String pValue) {
    final CheckBox cb = new CheckBox(null, p.getPropertyValueList().getValues().contains(pValue));

    cb.addValueChangeListener(new ValueChangeListener() {

        @Override//from w  w w  .j a  v a 2  s  .  co m
        public void valueChange(ValueChangeEvent event) {
            propertyValueChanged(p, pValue, cb.getValue());
        }
    });
    return cb;
}

From source file:de.fatalix.bookery.view.admin.BatchJobCard.java

private FormLayout createContent() {
    batchJobTypeCombo = new ComboBox("Batch Type");
    for (BatchJobType type : BatchJobType.values()) {
        batchJobTypeCombo.addItem(type);
    }//from  ww  w. j av a  2  s  .  c om
    batchJobTypeCombo.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (!noUpdate) {
                BatchJobType newType = ((BatchJobType) batchJobTypeCombo.getValue());

                batchJobConfiguration.setValue(newType.getDefaultConfig());

                updateBean();
                setFields();
            }
        }
    });

    description = new Label("description");
    nextRuntime = new Label("---");
    batchJobActive = new CheckBox("active", false);
    cronjobExpression = new TextField("Cronjob", "*******");
    status = new TextField("Status", "-");
    batchJobConfiguration = new TextArea("Configuration");

    Button updateButton = new Button("update", new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            updateBean();
            jobConfig = presenter.updateBatchJob(jobConfig);
            setFields();
            logger.debug("Updated Batch Job...");
        }
    });
    updateButton.addStyleName(ValoTheme.BUTTON_FRIENDLY);

    FormLayout batchJobCardContent = new FormLayout(batchJobTypeCombo, description, cronjobExpression,
            batchJobActive, batchJobConfiguration, nextRuntime, status, updateButton);
    batchJobCardContent.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    batchJobCardContent.setMargin(true);
    return batchJobCardContent;
}

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

License:Open Source License

@SuppressWarnings("serial")
private InstallImageDialog(String topText, InstallImageResultListener lis, boolean showExisting,
        String nameFilter) {//from   ww w  .j  av  a2 s. com
    Object sessKey = HSess.checkInit();
    listener = lis;

    setCaption(showExisting ? "Choose Existing or Upload New Image" : "Upload New Image");
    setModal(true);
    setWidth("350px");
    VerticalLayout vl;

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

    if (topText != null && topText.length() > 0) {
        HtmlLabel lab = new HtmlLabel(topText);
        lab.setWidth("100%");
        vLay.addComponent(lab);
    }

    if (showExisting) { // put the existing selector in the dialog

        Criteria crit = HSess.get().createCriteria(Media.class)
                .add(Restrictions.eq("source", Media.Source.DATABASE)).addOrder(Order.asc("url"));

        if (nameFilter != null)
            crit.add(Restrictions.like("handle", nameFilter, MatchMode.ANYWHERE));

        @SuppressWarnings({ "unchecked" })
        List<Media> mlis = crit.list();

        BeanItemContainer<Media> beanContainer = new BeanItemContainer<Media>(Media.class, mlis);

        vLay.addComponent(existingCB = new CheckBox("Choose from existing images", true));

        vLay.addComponent(vl = new VerticalLayout());
        vl.addStyleName("m-greyborder");
        vl.addStyleName("m-greybackground");
        vl.setMargin(true);
        vl.setSpacing(true);

        vl.addComponent(sel = new ListSelect());
        sel.setWidth("100%");
        sel.setNullSelectionAllowed(false);
        sel.setContainerDataSource(beanContainer);
        sel.setItemCaptionPropertyId("url");

        vl.addComponent(saveExistingButt = new NativeButton("Return selected image", new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                HSess.init();
                mediaImage = new MediaImage((Media) sel.getValue(), null);
                doneHereTL();
                HSess.close();
            }
        }));
        vLay.addComponent(newCB = new CheckBox("Upload new image", false));
    }

    // Here for the file chooser
    vLay.addComponent(vl = new VerticalLayout());
    vl.addStyleName("m-greyborder");
    vl.addStyleName("m-greybackground");
    vl.setSpacing(true);
    vl.setMargin(true);

    ImgReceiver rec;
    uploadFileWidget = new Upload();// "Image name", rec = new ImgReceiver());
    uploadFileWidget.setReceiver(rec = new ImgReceiver());
    uploadFileWidget.setButtonCaption("Browse");
    uploadFileWidget.setImmediate(true);
    uploadFileWidget.addFailedListener(rec);
    uploadFileWidget.addFinishedListener(rec);
    uploadFileWidget.setEnabled(showExisting ? false : true);
    vl.addComponent(uploadFileWidget);
    vl.addComponent(fileNameTF = new TextField());
    fileNameTF.setWidth("100%");
    fileNameTF.setEnabled(showExisting ? false : true);
    fileNameTFState = false;
    HorizontalLayout hLay;
    vl.addComponent(hLay = new HorizontalLayout());
    hLay.setSpacing(true);
    hLay.addComponent(saveImageButt = new NativeButton("Save image with above name", rec));
    // hLay.addComponent(savedLab = new HtmlLabel("<i>saved</i>"));

    saveImageButt.setImmediate(true);
    saveImageButt.addClickListener(rec);
    saveImageButt.setEnabled(false);
    saveImageButtState = false;

    vLay.addComponent(new NativeButton("Close", new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            HSess.init();
            doneHereTL();
            HSess.close();
        }
    }));

    if (showExisting) {
        existingCB.addValueChangeListener(new CheckBoxListener(existingCB));
        newCB.addValueChangeListener(new CheckBoxListener(newCB));
    }

    HSess.checkClose(sessKey);
}

From source file:eu.maxschuster.vaadin.signaturefield.demo.DemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    getPage().setTitle(pageTitle);//from  ww  w .  java2s. c om

    final VerticalLayout margin = new VerticalLayout();
    setContent(margin);

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth("658px");
    margin.addComponent(layout);
    margin.setComponentAlignment(layout, Alignment.TOP_CENTER);

    final Label header1 = new Label(pageTitle);
    header1.addStyleName("h1");
    header1.setSizeUndefined();
    layout.addComponent(header1);
    layout.setComponentAlignment(header1, Alignment.TOP_CENTER);

    final TabSheet tabSheet = new TabSheet();
    tabSheet.setWidth("100%");
    layout.addComponent(tabSheet);
    layout.setComponentAlignment(tabSheet, Alignment.TOP_CENTER);

    final Panel signaturePanel = new Panel();
    signaturePanel.addStyleName("signature-panel");
    signaturePanel.setWidth("100%");
    tabSheet.addTab(signaturePanel, "Demo");

    final VerticalLayout signatureLayout = new VerticalLayout();
    signatureLayout.setMargin(true);
    signatureLayout.setSpacing(true);
    signatureLayout.setSizeFull();
    signaturePanel.setContent(signatureLayout);

    final SignatureField signatureField = new SignatureField();
    signatureField.setWidth("100%");
    signatureField.setHeight("318px");
    signatureField.setPenColor(Color.ULTRAMARINE);
    signatureField.setBackgroundColor("white");
    signatureField.setConverter(new StringToDataUrlConverter());
    signatureField.setPropertyDataSource(dataUrlProperty);
    signatureField.setVelocityFilterWeight(0.7);
    signatureLayout.addComponent(signatureField);
    signatureLayout.setComponentAlignment(signatureField, Alignment.MIDDLE_CENTER);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    signatureLayout.addComponent(buttonLayout);

    final Button clearButton = new Button("Clear", new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            signatureField.clear();
        }
    });
    buttonLayout.addComponent(clearButton);
    buttonLayout.setComponentAlignment(clearButton, Alignment.MIDDLE_LEFT);

    final Label message = new Label("Sign above");
    message.setSizeUndefined();
    buttonLayout.addComponent(message);
    buttonLayout.setComponentAlignment(message, Alignment.MIDDLE_CENTER);

    final ButtonLink saveButtonLink = new ButtonLink("Save", null);
    saveButtonLink.setTargetName("_blank");
    buttonLayout.addComponent(saveButtonLink);
    buttonLayout.setComponentAlignment(saveButtonLink, Alignment.MIDDLE_RIGHT);

    final Panel optionsPanel = new Panel();
    optionsPanel.setSizeFull();
    tabSheet.addTab(optionsPanel, "Options");

    final FormLayout optionsLayout = new FormLayout();
    optionsLayout.setMargin(true);
    optionsLayout.setSpacing(true);
    optionsPanel.setContent(optionsLayout);

    final ComboBox mimeTypeComboBox = new ComboBox(null, mimeTypeContainer);
    optionsLayout.addComponent(mimeTypeComboBox);
    mimeTypeComboBox.setItemCaptionPropertyId("mimeType");
    mimeTypeComboBox.setNullSelectionAllowed(false);
    mimeTypeComboBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            MimeType mimeType = (MimeType) event.getProperty().getValue();
            signatureField.setMimeType(mimeType);
        }
    });
    mimeTypeComboBox.setValue(MimeType.PNG);
    mimeTypeComboBox.setCaption("Result MIME-Type");

    final CheckBox immediateCheckBox = new CheckBox("immediate", false);
    optionsLayout.addComponent(immediateCheckBox);
    immediateCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean immediate = (Boolean) event.getProperty().getValue();
            signatureField.setImmediate(immediate);
        }
    });

    final CheckBox readOnlyCheckBox = new CheckBox("readOnly", false);
    optionsLayout.addComponent(readOnlyCheckBox);
    readOnlyCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean readOnly = (Boolean) event.getProperty().getValue();
            signatureField.setReadOnly(readOnly);
            mimeTypeComboBox.setReadOnly(readOnly);
            clearButton.setEnabled(!readOnly);
        }
    });

    final CheckBox requiredCheckBox = new CheckBox("required (causes bug that clears field)", false);
    optionsLayout.addComponent(requiredCheckBox);
    requiredCheckBox.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean required = (Boolean) event.getProperty().getValue();
            signatureField.setRequired(required);
        }
    });

    final CheckBox clearButtonEnabledButton = new CheckBox("clearButtonEnabled", false);
    optionsLayout.addComponent(clearButtonEnabledButton);
    clearButtonEnabledButton.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean clearButtonEnabled = (Boolean) event.getProperty().getValue();
            signatureField.setClearButtonEnabled(clearButtonEnabled);
        }
    });

    final Panel resultPanel = new Panel("Results:");
    resultPanel.setWidth("100%");
    layout.addComponent(resultPanel);

    final VerticalLayout resultLayout = new VerticalLayout();
    resultLayout.setMargin(true);
    resultPanel.setContent(resultLayout);

    final Image stringPreviewImage = new Image("String preview image:");
    stringPreviewImage.setWidth("500px");
    resultLayout.addComponent(stringPreviewImage);

    final Image dataUrlPreviewImage = new Image("DataURL preview image:");
    dataUrlPreviewImage.setWidth("500px");
    resultLayout.addComponent(dataUrlPreviewImage);

    final TextArea textArea = new TextArea("DataURL:");
    textArea.setWidth("100%");
    textArea.setHeight("300px");
    resultLayout.addComponent(textArea);

    final Label emptyLabel = new Label();
    emptyLabel.setCaption("Is Empty:");
    emptyLabel.setValue(String.valueOf(signatureField.isEmpty()));
    resultLayout.addComponent(emptyLabel);

    signatureField.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            String signature = (String) event.getProperty().getValue();
            stringPreviewImage.setSource(signature != null ? new ExternalResource(signature) : null);
            textArea.setValue(signature);
            emptyLabel.setValue(String.valueOf(signatureField.isEmpty()));
        }
    });
    dataUrlProperty.addValueChangeListener(new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            try {
                final DataUrl signature = (DataUrl) event.getProperty().getValue();
                dataUrlPreviewImage.setSource(
                        signature != null ? new ExternalResource(serializer.serialize(signature)) : null);
                StreamResource streamResource = null;
                if (signature != null) {
                    StreamSource streamSource = new StreamSource() {

                        @Override
                        public InputStream getStream() {
                            return new ByteArrayInputStream(signature.getData());
                        }
                    };
                    MimeType mimeType = MimeType.valueOfMimeType(signature.getMimeType());
                    String extension = null;

                    switch (mimeType) {
                    case JPEG:
                        extension = "jpg";
                        break;
                    case PNG:
                        extension = "png";
                        break;
                    }

                    streamResource = new StreamResource(streamSource, "signature." + extension);
                    streamResource.setMIMEType(signature.getMimeType());
                    streamResource.setCacheTime(0);
                }
                saveButtonLink.setResource(streamResource);
            } catch (MalformedURLException e) {
                logger.error(e.getMessage(), e);
            }
        }
    });
}

From source file:fi.jasoft.simplecalendar.demo.SimpleCalendarDemoUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {

    setLocale(DEFAULT_LOCALE);//w w  w. j  av  a2 s . co m

    VerticalLayout content = new VerticalLayout();
    content.setMargin(true);
    content.setSpacing(true);

    Label lbl = new Label("SimpleCalendar");
    lbl.setStyleName(Reindeer.LABEL_H1);
    content.addComponent(lbl);

    HorizontalLayout layout = new HorizontalLayout();
    layout.setWidth("100%");
    layout.setSpacing(true);

    final SimpleCalendar calendar = new SimpleCalendar();
    calendar.setImmediate(true);
    calendar.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            Notification.show(calendar.getValue().toString());
        }
    });

    calendar.setMultiSelect(true);

    layout.addComponent(calendar);

    Label description = new Label("A calendar component that supports the following features:<ul>"
            + "<li>Selecting multiple dates by control click</li>" + "<li>Range selection with shift click</li>"
            + "<li>Keyboard navigation with arrow keys</li>" + "<li>Possibility to disable certain dates</li>"
            + "<li>Date tooltips</li>" + "<li>Limit start and end dates of calendar</li>"
            + "<li>Selecting multiple locales", ContentMode.HTML);
    layout.addComponent(description);
    layout.setExpandRatio(description, 1);

    content.addComponent(layout);

    BeanItemContainer<Locale> locales = new BeanItemContainer<Locale>(Locale.class);
    locales.addAll(Arrays.asList(Locale.getAvailableLocales()));

    NativeSelect localeSelect = new NativeSelect();
    localeSelect.setContainerDataSource(locales);
    localeSelect.setValue(DEFAULT_LOCALE);
    localeSelect.setImmediate(true);
    localeSelect.setItemCaptionMode(ItemCaptionMode.PROPERTY);
    localeSelect.setItemCaptionPropertyId("displayName");
    localeSelect.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            calendar.setLocale((Locale) event.getProperty().getValue());
        }
    });
    content.addComponent(new HorizontalLayout(new Label("Locale:"), localeSelect));

    final CheckBox disableWeekends = new CheckBox("Disable weekends", false);
    disableWeekends.setImmediate(true);
    disableWeekends.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (disableWeekends.getValue()) {
                calendar.setDisabledWeekDays(Weekday.SATURDAY, Weekday.SUNDAY);
            } else {
                calendar.setDisabledWeekDays();
            }
        }
    });
    content.addComponent(disableWeekends);

    final CheckBox disable15th = new CheckBox("Disable 15th each month", false);
    disable15th.setImmediate(true);
    disable15th.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (disable15th.getValue()) {
                calendar.setDisabledMonthlyDates(15);
            } else {
                calendar.setDisabledMonthlyDates();
            }
        }
    });
    content.addComponent(disable15th);

    final CheckBox disableToday = new CheckBox("Disable todays date", false);
    disableToday.setImmediate(true);
    disableToday.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (disableToday.getValue()) {
                calendar.setDisabledDates(new Date());
            } else {
                calendar.setDisabledDates();
            }
        }
    });
    content.addComponent(disableToday);

    final CheckBox allowFutureDate = new CheckBox("Only allow future dates", false);
    allowFutureDate.setImmediate(true);
    allowFutureDate.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (allowFutureDate.getValue()) {
                calendar.setStartDate(new Date());
            } else {
                calendar.setStartDate(null);
            }
        }
    });
    content.addComponent(allowFutureDate);

    final CheckBox allowPastDate = new CheckBox("Only allow past dates", false);
    allowPastDate.setImmediate(true);
    allowPastDate.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (allowPastDate.getValue()) {
                calendar.setEndDate(new Date());
            } else {
                calendar.setEndDate(null);
            }
        }
    });
    content.addComponent(allowPastDate);

    setContent(content);
}