Example usage for com.vaadin.ui TextArea setValue

List of usage examples for com.vaadin.ui TextArea setValue

Introduction

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

Prototype

@Override
public void setValue(String value) 

Source Link

Document

Sets the value of this text field.

Usage

From source file:com.foo01.ui.ReservationDetailView.java

@Override
protected final void onBecomingVisible() {
    getNavigationBar().setCaption("Detail Rezervace");

    //buttony pod navbarem
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setStyleName("buttonToolBarLayout");
    buttonsLayout.setWidth("100%");

    Button deleteButton = new Button();
    deleteButton.setCaption("SMAZAT");
    deleteButton.setWidth(null);/*  ww w. j a va2 s. c om*/
    buttonsLayout.addComponent(deleteButton);

    Label plug = new Label();
    buttonsLayout.addComponent(plug);

    Button saveButton = new Button();
    saveButton.setCaption("ULOIT");
    saveButton.setWidth(null);
    buttonsLayout.addComponent(saveButton);
    buttonsLayout.setExpandRatio(plug, 1.0f);
    List<Source> sourcesList = MockSource.mockSources();

    //combobox na zdroje a jmeno uzivatele
    HorizontalLayout sourceAndNameLayout = new HorizontalLayout();
    sourceAndNameLayout.setWidth("100%");
    sourceAndNameLayout.setStyleName("sourceAndNameLayout");

    NativeSelect select = new NativeSelect();
    select.setNullSelectionAllowed(false);
    System.out.println(Page.getCurrent().getBrowserWindowWidth());
    String width = Page.getCurrent().getBrowserWindowWidth() / 2.5 + "px";
    select.setWidth(width);
    select.addItems(sourcesList);
    for (Source s : sourcesList) {
        if (reservation.getSource().equals(s)) {
            select.select(s);
            break;
        }
    }
    sourceAndNameLayout.addComponent(select);

    Label plug2 = new Label();
    sourceAndNameLayout.addComponent(plug2);

    Label name = new Label(reservation.getUser());
    name.setWidth(null);
    sourceAndNameLayout.addComponent(name);
    sourceAndNameLayout.setExpandRatio(plug2, 1.0f);

    //datepickery
    DatePicker dateFrom = new DatePicker();
    dateFrom.setStyleName("datePickerDetailView");
    dateFrom.setValue(reservation.getBeginning());
    dateFrom.setUseNative(true);
    dateFrom.setResolution(Resolution.TIME);
    dateFrom.setWidth("100%");

    DatePicker dateTo = new DatePicker();
    dateTo.setStyleName("datePickerDetailView");
    dateTo.setValue(reservation.getEnding());
    dateTo.setUseNative(true);
    dateTo.setResolution(Resolution.TIME);
    dateTo.setWidth("100%");

    //layout pro slider a popisky
    HorizontalLayout sliderLayout = new HorizontalLayout();
    sliderLayout.setStyleName("sliderLayout");
    sliderLayout.setWidth("100%");
    sliderLayout.setSpacing(true);

    Label sliderCaption = new Label("Po?et: ");
    sliderCaption.addStyleName("sliderCaption");
    sliderCaption.setWidth(null);
    sliderLayout.addComponent(sliderCaption);

    final Label horvalue = new Label();
    horvalue.setWidth("45px");
    horvalue.setStyleName("value");
    sliderLayout.addComponent(horvalue);

    final Slider horslider = new Slider(1, 10);
    horslider.setOrientation(SliderOrientation.HORIZONTAL);
    horslider.setValue(Double.valueOf(1));
    horslider.getState();
    horslider.getValue();
    horslider.setImmediate(true);
    horslider.setWidth("100%");
    sliderLayout.addComponent(horslider);
    sliderLayout.setExpandRatio(horslider, 1.0f);

    horvalue.setValue(String.valueOf(horslider.getValue().intValue()));

    horslider.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            int value = horslider.getValue().intValue();

            horvalue.setValue(String.valueOf(value));
        }
    });

    //switch schvaleno
    HorizontalLayout switchLayout = new HorizontalLayout();
    switchLayout.setStyleName("switchLayout");
    switchLayout.addComponent(new Label("Schvleno:"));
    switchLayout.setSpacing(true);
    Switch checkbox = new Switch(null, true);
    switchLayout.addComponent(checkbox);

    //popis rezervace
    TextArea description = new TextArea();
    description.setStyleName("descriptionDetailView");

    description.setWidth("100%");
    description.setImmediate(false);
    description.setCaption("Popis:");
    description.setValue(reservation.getDescription());
    //description.setRequired(true);
    description.setRequiredError("Popis mus bt zadn!");
    description.setNullRepresentation("");
    description.setReadOnly(true);
    //description.setRows(0);

    final VerticalLayout content = new VerticalLayout();
    content.setMargin(true);
    content.setSpacing(true);
    content.setStyleName(width);
    content.addComponent(buttonsLayout);
    content.addComponent(sourceAndNameLayout);
    content.addComponent(dateFrom);
    content.addComponent(dateTo);

    content.addComponent(sliderLayout);
    content.addComponent(switchLayout);
    content.addComponent(description);

    setContent(content);
}

From source file:com.foo01.ui.ReservationView.java

@Override
protected final void onBecomingVisible() {
    getNavigationBar().setCaption("Detail Rezervace");

    //buttony pod navbarem
    //        HorizontalLayout buttonsLayout = new HorizontalLayout();
    //        buttonsLayout.setStyleName("buttonToolBarLayout");
    //        buttonsLayout.setWidth("100%");
    ////  w  w w .  j  a  v a  2 s.  c o  m
    //        Button deleteButton = new Button();
    //        deleteButton.setCaption("SMAZAT");
    //        deleteButton.setWidth(null);
    //        buttonsLayout.addComponent(deleteButton);
    //
    //        Label plug = new Label();
    //        buttonsLayout.addComponent(plug);
    //
    //        Button saveButton = new Button();
    //        saveButton.setCaption("ULOIT");
    //        saveButton.setWidth(null);
    //        buttonsLayout.addComponent(saveButton);
    //        buttonsLayout.setExpandRatio(plug, 1.0f);  

    //combobox na zdroje a jmeno uzivatele
    List<Source> sourcesList = MockSource.mockSources();
    HorizontalLayout sourceAndNameLayout = new HorizontalLayout();
    sourceAndNameLayout.setWidth("100%");
    sourceAndNameLayout.setStyleName("sourceAndNameLayout");

    NativeSelect select = new NativeSelect();
    select.setNullSelectionAllowed(false);
    System.out.println(Page.getCurrent().getBrowserWindowWidth());
    String width = Page.getCurrent().getBrowserWindowWidth() / 2.5 + "px";
    select.setWidth(width);
    select.addItems(sourcesList);
    for (Source s : sourcesList) {
        if (reservation.getSource().equals(s)) {
            select.select(s);
            break;
        }
    }
    sourceAndNameLayout.addComponent(select);

    Label plug2 = new Label();
    sourceAndNameLayout.addComponent(plug2);

    Label name = new Label(reservation.getUser());
    name.setWidth(null);
    sourceAndNameLayout.addComponent(name);
    sourceAndNameLayout.setExpandRatio(plug2, 1.0f);

    //datepickery
    DatePicker dateFrom = new DatePicker();
    dateFrom.setStyleName("datePickerDetailView");
    dateFrom.setValue(reservation.getBeginning());
    dateFrom.setUseNative(true);
    dateFrom.setResolution(Resolution.TIME);
    dateFrom.setWidth("100%");

    DatePicker dateTo = new DatePicker();
    dateTo.setStyleName("datePickerDetailView");
    dateTo.setValue(reservation.getEnding());
    dateTo.setUseNative(true);
    dateTo.setResolution(Resolution.TIME);
    dateTo.setWidth("100%");

    //layout pro slider a popisky
    HorizontalLayout sliderLayout = new HorizontalLayout();
    sliderLayout.setStyleName("sliderLayout");
    sliderLayout.setWidth("100%");
    sliderLayout.setSpacing(true);

    Label sliderCaption = new Label("Po?et: ");
    sliderCaption.addStyleName("sliderCaption");
    sliderCaption.setWidth(null);
    sliderLayout.addComponent(sliderCaption);

    final Label horvalue = new Label();
    horvalue.setWidth("45px");
    horvalue.setStyleName("value");
    sliderLayout.addComponent(horvalue);

    final Slider horslider = new Slider(1, 10);
    horslider.setOrientation(SliderOrientation.HORIZONTAL);
    horslider.setValue(Double.valueOf(1));
    horslider.getState();
    horslider.getValue();
    horslider.setImmediate(true);
    horslider.setWidth("100%");
    sliderLayout.addComponent(horslider);
    sliderLayout.setExpandRatio(horslider, 1.0f);

    horvalue.setValue(String.valueOf(horslider.getValue().intValue()));

    horslider.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            int value = horslider.getValue().intValue();

            horvalue.setValue(String.valueOf(value));
        }
    });

    //switch schvaleno
    HorizontalLayout switchLayout = new HorizontalLayout();
    switchLayout.setStyleName("switchLayout");
    switchLayout.addComponent(new Label("Schvleno:"));
    switchLayout.setSpacing(true);
    Switch checkbox = new Switch(null, true);
    switchLayout.addComponent(checkbox);

    //popis rezervace
    TextArea description = new TextArea();
    description.setStyleName("descriptionDetailView");

    description.setWidth("100%");
    description.setImmediate(false);
    description.setCaption("Popis:");
    description.setValue(reservation.getDescription());
    //description.setRequired(true);
    description.setRequiredError("Popis mus bt zadn!");
    description.setNullRepresentation("");
    description.setReadOnly(true);
    //description.setRows(0);

    final VerticalLayout content = new VerticalLayout();
    content.setMargin(true);
    content.setSpacing(true);
    content.addComponent(new ButtonToolBarLayout(this));
    content.addComponent(sourceAndNameLayout);
    content.addComponent(dateFrom);
    content.addComponent(dateTo);

    content.addComponent(sliderLayout);
    content.addComponent(switchLayout);
    content.addComponent(description);

    setContent(content);
}

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.java 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.klwork.explorer.ui.task.TaskDetailPanel.java

License:Apache License

protected void initDescription(HorizontalLayout layout) {
    final CssLayout descriptionLayout = new CssLayout();
    descriptionLayout.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(descriptionLayout);
    layout.setExpandRatio(descriptionLayout, 1.0f);
    layout.setComponentAlignment(descriptionLayout, Alignment.MIDDLE_LEFT);

    String descriptionText = null;
    if (task.getDescription() != null && !"".equals(task.getDescription())) {
        descriptionText = task.getDescription();
    } else {//??
        descriptionText = i18nManager.getMessage(Messages.TASK_NO_DESCRIPTION);
    }//ww w.j  a v a  2s  . c  om
    final Label descriptionLabel = new Label(descriptionText);
    descriptionLabel.addStyleName(ExplorerLayout.STYLE_CLICKABLE);
    descriptionLayout.addComponent(descriptionLabel);

    descriptionLayout.addLayoutClickListener(new LayoutClickListener() {
        public void layoutClick(LayoutClickEvent event) {
            if (event.getClickedComponent() != null && event.getClickedComponent().equals(descriptionLabel)) {
                // layout for textarea + ok button
                final VerticalLayout editLayout = new VerticalLayout();
                editLayout.setSpacing(true);

                // textarea
                final TextArea descriptionTextArea = new TextArea();
                //
                descriptionTextArea.setNullRepresentation("");
                descriptionTextArea.setWidth(100, Unit.PERCENTAGE);
                descriptionTextArea.setValue(task.getDescription());
                editLayout.addComponent(descriptionTextArea);

                // ok button
                Button okButton = new Button(i18nManager.getMessage(Messages.BUTTON_OK));
                editLayout.addComponent(okButton);
                editLayout.setComponentAlignment(okButton, Alignment.BOTTOM_RIGHT);

                // replace
                descriptionLayout.replaceComponent(descriptionLabel, editLayout);

                // When OK is clicked -> update task data + ui
                okButton.addClickListener(new ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        // Update data
                        task.setDescription(descriptionTextArea.getValue().toString());
                        taskService.saveTask(task);

                        // Update UI
                        descriptionLabel.setValue(task.getDescription());
                        descriptionLayout.replaceComponent(editLayout, descriptionLabel);
                    }
                });
            }
        }
    });
}

From source file:com.salsaw.msalsa.PhylogeneticTreeView.java

License:Apache License

public PhylogeneticTreeView(ClustalFileMapper clustalFileMapper) throws IOException {
    initializeUiComponents();//from  w ww.  java 2 s  .  c  o m

    // Download alignment file
    Button aligmentButton = new Button("Download alignment");
    Resource resAlignment = new FileResource(new File(clustalFileMapper.getAlignmentFilePath()));
    FileDownloader fdAln = new FileDownloader(resAlignment);
    fdAln.extend(aligmentButton);
    mainLayout.addComponent(aligmentButton);
    mainLayout.setComponentAlignment(aligmentButton, Alignment.MIDDLE_CENTER);

    // Download tree file
    Button downloadTreeButton = new Button("Download phylogentic tree");
    Resource resTree = new FileResource(new File(clustalFileMapper.getTreeFilePath()));
    FileDownloader fdTree = new FileDownloader(resTree);
    fdTree.extend(downloadTreeButton);
    mainLayout.addComponent(downloadTreeButton);
    mainLayout.setComponentAlignment(downloadTreeButton, Alignment.MIDDLE_CENTER);

    // Add and center with HTML div
    svgHTMLPhylogenticTree = new Label("<div id='svgCanvas'></div>", ContentMode.HTML);
    svgHTMLPhylogenticTree.setWidth("-1px");
    svgHTMLPhylogenticTree.setHeight("-1px");
    mainLayout.addComponent(svgHTMLPhylogenticTree);
    mainLayout.setComponentAlignment(svgHTMLPhylogenticTree, Alignment.MIDDLE_CENTER);

    // Add tab with aligment content
    String aligmentFileContent = new String(
            Files.readAllBytes(Paths.get(clustalFileMapper.getAlignmentFilePath())));
    TextArea aligmentFileTextArea = new TextArea("M-SALSA Aligment");
    aligmentFileTextArea.setWordwrap(false);
    aligmentFileTextArea.setValue(aligmentFileContent);
    aligmentFileTextArea.setWidth("100%");
    aligmentFileTextArea.setHeight("100%");
    mainLayout.addComponent(aligmentFileTextArea);
    mainLayout.setComponentAlignment(aligmentFileTextArea, Alignment.MIDDLE_CENTER);

    // Add JavaScript component to generate phylogentic tree
    JsPhyloSVG jsPhyloSVG = new JsPhyloSVG(getPhylogeneticTreeFileContent(clustalFileMapper));
    mainLayout.addComponent(jsPhyloSVG);

    setCompositionRoot(mainLayout);
}

From source file:com.skysql.manager.ui.ErrorDialog.java

License:Open Source License

/**
 * Instantiates a new error dialog./*from  ww w  .j ava 2  s . c om*/
 *
 * @param e the exception
 * @param humanizedError the humanized error
 */
public ErrorDialog(Exception e, String humanizedError) {

    if (e != null) {
        ManagerUI.error(e.getMessage());
    }

    dialogWindow = new ModalWindow("An Error has occurred", "775px");
    dialogWindow.setHeight("340px");
    dialogWindow.addCloseListener(this);
    UI current = UI.getCurrent();
    if (current.getContent() == null) {
        current.setContent(new ErrorView(Notification.Type.ERROR_MESSAGE, null));
    }
    current.addWindow(dialogWindow);

    HorizontalLayout wrapper = new HorizontalLayout();
    wrapper.setSizeFull();
    wrapper.setMargin(true);

    VerticalLayout iconLayout = new VerticalLayout();
    iconLayout.setWidth("100px");
    wrapper.addComponent(iconLayout);
    Embedded image = new Embedded(null, new ThemeResource("img/error.png"));
    iconLayout.addComponent(image);

    VerticalLayout textLayout = new VerticalLayout();
    textLayout.setHeight("100%");
    textLayout.setSpacing(true);
    wrapper.addComponent(textLayout);
    wrapper.setExpandRatio(textLayout, 1.0f);

    if (humanizedError != null || e != null) {
        String error = (humanizedError != null) ? humanizedError : e.toString();
        ManagerUI.error(error);
        Label label = new Label(error, ContentMode.HTML);
        label.addStyleName("warning");
        textLayout.addComponent(label);
        textLayout.setComponentAlignment(label, Alignment.TOP_CENTER);
    }

    if (e != null) {
        TextArea stackTrace = new TextArea("Error Log");
        stackTrace.setSizeFull();
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        stackTrace.setValue(sw.toString());
        textLayout.addComponent(stackTrace);
        textLayout.setComponentAlignment(stackTrace, Alignment.TOP_LEFT);
        textLayout.setExpandRatio(stackTrace, 1.0f);
    }

    HorizontalLayout buttonsBar = new HorizontalLayout();
    buttonsBar.setStyleName("buttonsBar");
    buttonsBar.setSizeFull();
    buttonsBar.setSpacing(true);
    buttonsBar.setMargin(true);
    buttonsBar.setHeight("49px");

    Label filler = new Label();
    buttonsBar.addComponent(filler);
    buttonsBar.setExpandRatio(filler, 1.0f);

    Button cancelButton = new Button("Close");
    buttonsBar.addComponent(cancelButton);
    buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT);

    cancelButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            dialogWindow.close();
            //UI.getCurrent().close();
        }
    });

    Button okButton = new Button("Send Error");
    okButton.setEnabled(false);
    okButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            dialogWindow.close();
        }
    });
    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

    VerticalLayout windowLayout = (VerticalLayout) dialogWindow.getContent();
    windowLayout.setHeight("100%");
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);
    windowLayout.addComponent(wrapper);
    windowLayout.setExpandRatio(wrapper, 1.0f);
    windowLayout.addComponent(buttonsBar);

}

From source file:com.skysql.manager.ui.MonitorsSettings.java

License:Open Source License

/**
 * Monitor form.//from  w ww .j  av  a2s  .  c o  m
 *
 * @param monitor the monitor
 * @param title the title
 * @param description the description
 * @param button the button
 */
public void monitorForm(final MonitorRecord monitor, String title, String description, String button) {
    final TextField monitorName = new TextField("Monitor Name");
    final TextField monitorDescription = new TextField("Description");
    final TextField monitorUnit = new TextField("Measurement Unit");
    final TextArea monitorSQL = new TextArea("SQL Statement");
    final CheckBox monitorDelta = new CheckBox("Is Delta");
    final CheckBox monitorAverage = new CheckBox("Is Average");
    final NativeSelect validationTarget = new NativeSelect("Validate SQL on");
    final NativeSelect monitorInterval = new NativeSelect("Sampling interval");
    final NativeSelect monitorChartType = new NativeSelect("Default display");

    secondaryDialog = new ModalWindow(title, null);
    UI.getCurrent().addWindow(secondaryDialog);
    secondaryDialog.addCloseListener(this);

    final VerticalLayout formContainer = new VerticalLayout();
    formContainer.setMargin(new MarginInfo(true, true, false, true));
    formContainer.setSpacing(false);

    final Form form = new Form();
    formContainer.addComponent(form);
    form.setImmediate(false);
    form.setFooter(null);
    form.setDescription(description);

    String value;

    if ((value = monitor.getName()) != null) {
        monitorName.setValue(value);
    }
    form.addField("monitorName", monitorName);
    form.getField("monitorName").setRequired(true);
    form.getField("monitorName").setRequiredError("Monitor Name is missing");
    monitorName.focus();
    monitorName.setImmediate(true);
    monitorName.addValidator(new MonitorNameValidator(monitor.getName()));

    if ((value = monitor.getDescription()) != null) {
        monitorDescription.setValue(value);
    }
    monitorDescription.setWidth("24em");
    form.addField("monitorDescription", monitorDescription);

    if ((value = monitor.getUnit()) != null) {
        monitorUnit.setValue(value);
    }
    form.addField("monitorUnit", monitorUnit);

    if ((value = monitor.getSql()) != null) {
        monitorSQL.setValue(value);
    }
    monitorSQL.setWidth("24em");
    monitorSQL.addValidator(new SQLValidator());
    form.addField("monitorSQL", monitorSQL);

    final String noValidation = "None - Skip Validation";
    validationTarget.setImmediate(true);
    validationTarget.setNullSelectionAllowed(false);
    validationTarget.addItem(noValidation);
    validationTarget.select(noValidation);
    OverviewPanel overviewPanel = getSession().getAttribute(OverviewPanel.class);
    ArrayList<NodeInfo> nodes = overviewPanel.getNodes();

    if (nodes == null || nodes.isEmpty()) {
        SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class);
        String systemID = systemInfo.getCurrentID();
        String systemType = systemInfo.getCurrentSystem().getSystemType();
        if (systemID.equals(SystemInfo.SYSTEM_ROOT)) {
            ClusterComponent clusterComponent = VaadinSession.getCurrent().getAttribute(ClusterComponent.class);
            systemID = clusterComponent.getID();
            systemType = clusterComponent.getSystemType();
        }
        nodes = new ArrayList<NodeInfo>();
        for (String nodeID : systemInfo.getSystemRecord(systemID).getNodes()) {
            NodeInfo nodeInfo = new NodeInfo(systemID, systemType, nodeID);
            nodes.add(nodeInfo);
        }

    }

    for (NodeInfo node : nodes) {
        validationTarget.addItem(node.getID());
        validationTarget.setItemCaption(node.getID(), node.getName());
    }
    validationTarget.addValueChangeListener(new ValueChangeListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void valueChange(ValueChangeEvent event) {
            nodeID = (String) event.getProperty().getValue();
            validateSQL = nodeID.equals(noValidation) ? false : true;
        }

    });
    form.addField("validationTarget", validationTarget);

    monitorDelta.setValue(monitor.isDelta());
    form.addField("monitorDelta", monitorDelta);

    monitorAverage.setValue(monitor.isAverage());
    form.addField("monitorAverage", monitorAverage);

    SettingsValues intervalValues = new SettingsValues(SettingsValues.SETTINGS_MONITOR_INTERVAL);
    String[] intervals = intervalValues.getValues();
    for (String interval : intervals) {
        monitorInterval.addItem(Integer.parseInt(interval));
    }

    Collection<?> validIntervals = monitorInterval.getItemIds();
    if (validIntervals.contains(monitor.getInterval())) {
        monitorInterval.select(monitor.getInterval());
    } else {
        SystemInfo systemInfo = getSession().getAttribute(SystemInfo.class);
        String defaultInterval = systemInfo.getSystemRecord(systemID).getProperties()
                .get(SystemInfo.PROPERTY_DEFAULTMONITORINTERVAL);
        if (defaultInterval != null && validIntervals.contains(Integer.parseInt(defaultInterval))) {
            monitorInterval.select(Integer.parseInt(defaultInterval));
        } else if (!validIntervals.isEmpty()) {
            monitorInterval.select(validIntervals.toArray()[0]);
        } else {
            new ErrorDialog(null, "No set of permissible monitor intervals found");
        }

        monitorInterval.setNullSelectionAllowed(false);
        form.addField("monitorInterval", monitorInterval);
    }

    for (UserChart.ChartType type : UserChart.ChartType.values()) {
        monitorChartType.addItem(type.name());
    }
    monitorChartType
            .select(monitor.getChartType() == null ? UserChart.ChartType.values()[0] : monitor.getChartType());
    monitorChartType.setNullSelectionAllowed(false);
    form.addField("monitorChartType", monitorChartType);

    HorizontalLayout buttonsBar = new HorizontalLayout();
    buttonsBar.setStyleName("buttonsBar");
    buttonsBar.setSizeFull();
    buttonsBar.setSpacing(true);
    buttonsBar.setMargin(true);
    buttonsBar.setHeight("49px");

    Label filler = new Label();
    buttonsBar.addComponent(filler);
    buttonsBar.setExpandRatio(filler, 1.0f);

    Button cancelButton = new Button("Cancel");
    buttonsBar.addComponent(cancelButton);
    buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT);

    cancelButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            form.discard();
            secondaryDialog.close();
        }
    });

    Button okButton = new Button(button);
    okButton.addClickListener(new Button.ClickListener() {
        private static final long serialVersionUID = 0x4C656F6E6172646FL;

        public void buttonClick(ClickEvent event) {
            try {
                form.setComponentError(null);
                form.commit();
                monitor.setName(monitorName.getValue());
                monitor.setDescription(monitorDescription.getValue());
                monitor.setUnit(monitorUnit.getValue());
                monitor.setSql(monitorSQL.getValue());
                monitor.setDelta(monitorDelta.getValue());
                monitor.setAverage(monitorAverage.getValue());
                monitor.setInterval((Integer) monitorInterval.getValue());
                monitor.setChartType((String) monitorChartType.getValue());
                String ID;
                if ((ID = monitor.getID()) == null) {
                    if (Monitors.setMonitor(monitor)) {
                        ID = monitor.getID();
                        select.addItem(ID);
                        select.select(ID);
                        Monitors.reloadMonitors();
                        monitorsAll = Monitors.getMonitorsList(systemType);
                    }
                } else {
                    Monitors.setMonitor(monitor);
                    ChartProperties chartProperties = getSession().getAttribute(ChartProperties.class);
                    chartProperties.setDirty(true);
                    settingsDialog.setRefresh(true);
                }

                if (ID != null) {
                    select.setItemCaption(ID, monitor.getName());
                    displayMonitorRecord(ID);
                    secondaryDialog.close();
                }

            } catch (EmptyValueException e) {
                return;
            } catch (InvalidValueException e) {
                return;
            } catch (Exception e) {
                ManagerUI.error(e.getMessage());
                return;
            }
        }
    });
    buttonsBar.addComponent(okButton);
    buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

    VerticalLayout windowLayout = (VerticalLayout) secondaryDialog.getContent();
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);
    windowLayout.addComponent(formContainer);
    windowLayout.addComponent(buttonsBar);

}

From source file:com.trivago.mail.pigeon.web.components.templates.ModalAddTemplate.java

License:Apache License

public ModalAddTemplate(final TemplateList tl, final Long templateId) {
    setResizable(true);//from  w w w .jav  a2 s . com
    setWidth("972px");
    setHeight("700px");
    Panel rootPanel = new Panel("Add new Template");
    TabSheet tSheet = new TabSheet();
    HorizontalLayout hLayout = new HorizontalLayout();

    final TextField title = new TextField("Template description");
    final TextField subject = new TextField("Newsletter Subject");

    final TextArea textContent = new TextArea("Text Version");
    textContent.setRows(40);
    textContent.setColumns(100);

    final CKEditorTextField htmlContent = new CKEditorTextField();
    htmlContent.setWidth("100%");
    htmlContent.setHeight("650px");

    // Load the content, if we receive a template id
    if (templateId != null) {
        MailTemplate mt = new MailTemplate(templateId);
        title.setValue(mt.getTitle());
        subject.setValue(mt.getSubject());
        textContent.setValue(mt.getText());
        htmlContent.setValue(mt.getHtml());
    }

    Button saveButton = new Button("Save");
    Button cancel = new Button("Cancel");

    saveButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            boolean hasError = false;
            if (title.getValue().equals("")) {
                title.setComponentError(new UserError("Name must not be empty"));
                hasError = true;
            } else {
                title.setComponentError(null);
            }

            if (subject.getValue().equals("")) {
                subject.setComponentError(new UserError("Subject must not be empty"));
                hasError = true;
            } else {
                subject.setComponentError(null);
            }

            if (htmlContent.getValue().equals("")) {
                htmlContent.setComponentError(new UserError("Please provide some HTML content"));
                hasError = true;
            } else {
                htmlContent.setComponentError(null);
            }

            if (textContent.getValue().equals("")) {
                textContent.setComponentError(new UserError("Please provide some text content"));
                hasError = true;
            } else {
                textContent.setComponentError(null);
            }

            if (!hasError) {
                if (templateId == null) {
                    long templateId = Util.generateId();
                    try {
                        MailTemplate mt = new MailTemplate(templateId, title.getValue().toString(),
                                textContent.getValue().toString(), htmlContent.getValue().toString(),
                                subject.getValue().toString());
                        event.getButton().getWindow().setVisible(false);
                        event.getButton().getWindow().getParent()
                                .removeComponent(event.getButton().getWindow());
                        event.getButton().getWindow().getParent().showNotification("Saved successfully",
                                Notification.TYPE_HUMANIZED_MESSAGE);
                        tl.getBeanContainer().addItem(mt.getId(), mt);
                    } catch (RuntimeException e) {
                        // Should never happen ... hopefully :D
                    }
                } else {
                    MailTemplate mt = new MailTemplate(templateId);

                    mt.setHtml(htmlContent.getValue().toString());
                    mt.setSubject(subject.getValue().toString());
                    mt.setText(textContent.getValue().toString());
                    mt.setTitle(title.getValue().toString());

                    event.getButton().getWindow().setVisible(false);
                    event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow());
                    event.getButton().getWindow().getParent().showNotification("Saved successfully",
                            Notification.TYPE_HUMANIZED_MESSAGE);

                    final int beanIndex = tl.getBeanContainer().indexOfId(mt.getId());
                    tl.getBeanContainer().removeItem(mt.getId());
                    tl.getBeanContainer().addItemAt(beanIndex, mt.getId(), mt);
                }
                TemplateSelectBox.reloadSelect();
            }
        }
    });

    hLayout.addComponent(saveButton);
    hLayout.addComponent(cancel);
    hLayout.setSpacing(true);

    VerticalLayout metaDataLayout = new VerticalLayout();

    Panel textFieldPanel = new Panel("Meta Data");
    VerticalLayout metaLayout = new VerticalLayout();
    metaLayout.addComponent(title);
    metaLayout.addComponent(subject);
    textFieldPanel.addComponent(metaLayout);

    Panel helpPanel = new Panel("Template Documentation");
    assembleHelpComponents(helpPanel);

    metaDataLayout.addComponent(textFieldPanel);
    metaDataLayout.addComponent(helpPanel);

    tSheet.addTab(metaDataLayout).setCaption("Meta Data");

    VerticalLayout textLayout = new VerticalLayout();
    textLayout.addComponent(textContent);
    tSheet.addTab(textLayout).setCaption("Text Content");

    VerticalLayout htmlLayout = new VerticalLayout();
    htmlLayout.addComponent(htmlContent);
    tSheet.addTab(htmlLayout).setCaption("HTML Content");

    rootPanel.addComponent(tSheet);
    rootPanel.addComponent(hLayout);
    addComponent(rootPanel);
}

From source file:de.mendelson.comm.as2.webclient2.TransactionDetailsDialog.java

private TextArea createLogTab() {
    DateFormat format = SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    TextArea textArea = new TextArea();
    textArea.setRows(7);//from   ww w.  j ava 2 s. c  om
    textArea.setSizeFull();
    List<LogEntry> entries = this.logAccess.getLog(this.messageId);
    StringBuilder log = new StringBuilder();
    for (LogEntry entry : entries) {
        log.append("[").append(format.format(entry.getMillis())).append("] ");
        log.append(entry.getMessage());
        log.append("\n");
    }
    textArea.setValue(log.toString());
    textArea.setReadOnly(true);
    return (textArea);
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.ChangeProjectMetadataComponent.java

License:Open Source License

private void buildFormLayout() {
    final FieldGroup fieldGroup = new FieldGroup();
    final FormLayout form2 = new FormLayout();

    TextArea tf = new TextArea("Description");
    tf.setWidth("50%");
    tf.setHeight("50%");
    fieldGroup.bind(tf, "Description");
    tf.setCaption("Description");
    tf.setDescription("Description of this project.");
    tf.setValue(currentDescription);
    form2.addComponent(tf);//from  w w  w .  j  av  a  2  s  .co m

    this.fieldGroup = fieldGroup;
    this.form = form2;
}