Example usage for com.vaadin.ui Panel setContent

List of usage examples for com.vaadin.ui Panel setContent

Introduction

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

Prototype

@Override
public void setContent(Component content) 

Source Link

Document

Sets the content of this container.

Usage

From source file:info.magnolia.ui.framework.overlay.OverlayPresenter.java

License:Open Source License

/**
 * Opens a notification of given {@link MessageStyleType type}, with given body; it can close automatically after a timeout.
 *//*from   w w  w.ja va 2  s  .co m*/
@Override
public void openNotification(final MessageStyleType type, boolean doesTimeout, View viewToShow) {
    final Notification notification = new Notification(type);
    notification.setContent(viewToShow.asVaadinComponent());

    Panel shortcutPanel = new Panel();
    shortcutPanel.setStyleName("shortcut-panel");
    shortcutPanel.setWidth(null);
    shortcutPanel.setContent(notification.asVaadinComponent());
    final OverlayCloser closer = openOverlay(new ViewAdapter(shortcutPanel), ModalityLevel.NON_MODAL);

    final ShortcutListener escapeShortcut = new ShortcutListener("Escape shortcut",
            ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            closer.close();
        }
    };
    shortcutPanel.addShortcutListener(escapeShortcut);

    notification.addCloseButtonListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent clickEvent) {
            closer.close();
        }
    });

    notification.addNotificationBodyClickListener(new LayoutEvents.LayoutClickListener() {
        @Override
        public void layoutClick(LayoutEvents.LayoutClickEvent layoutClickEvent) {
            closer.setCloseTimeout(-1);
        }
    });

    if (doesTimeout) {
        closer.setCloseTimeout(TIMEOUT_SECONDS_DEFAULT);
    }

}

From source file:it.vige.greenarea.bpm.custom.ui.LoginPanel.java

License:Apache License

private void addInputField() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);//w  w w. j a v a 2  s. c  o m
    layout.setWidth(100, UNITS_PERCENTAGE);
    loginPanel.addComponent(layout);

    Panel textFieldPanel = new Panel(); // Hack: actionHandlers can only be
    // attached to panels or windows
    textFieldPanel.addStyleName(PANEL_LIGHT);
    textFieldPanel.setContent(new VerticalLayout());
    textFieldPanel.setWidth(100, UNITS_PERCENTAGE);
    layout.addComponent(textFieldPanel);
    layout.setExpandRatio(textFieldPanel, 1.0f);

    Label labelUserName = new Label(i18nManager.getMessage(USER_NAME_TITLE));
    labelUserName.addStyleName(LABEL_SMALL);
    userNameInputField = new TextField();
    userNameInputField.setWidth(100, UNITS_PERCENTAGE);
    Label labelPassword = new Label(i18nManager.getMessage(PASSWORD_TITLE));
    labelPassword.addStyleName(LABEL_SMALL);
    passwordInputField = new PasswordField();
    passwordInputField.setWidth(100, UNITS_PERCENTAGE);
    textFieldPanel.addComponent(labelUserName);
    textFieldPanel.addComponent(userNameInputField);
    textFieldPanel.addComponent(labelPassword);
    textFieldPanel.addComponent(passwordInputField);

    // Hack to catch keyboard 'enter'
    textFieldPanel.addActionHandler(new Handler() {
        private static final long serialVersionUID = 6928598745792215505L;

        public void handleAction(Action action, Object sender, Object target) {
            login(userNameInputField.getValue().toString(), passwordInputField.getValue().toString());
        }

        public Action[] getActions(Object target, Object sender) {
            return new Action[] { new ShortcutAction("enter", ENTER, null) };
        }
    });

    Button loginButton = new Button(i18nManager.getMessage(LOGIN));
    layout.addComponent(loginButton);
    layout.setComponentAlignment(loginButton, MIDDLE_LEFT);
    loginButton.addListener(new ClickListener() {
        private static final long serialVersionUID = 7781253151592188006L;

        public void buttonClick(ClickEvent event) {
            login(userNameInputField.getValue().toString(), passwordInputField.getValue().toString());
        }
    });
}

From source file:life.qbic.components.OfferGeneratorTab.java

License:Open Source License

/**
 * creates the tab to generate the offers with the respective packages
 * @return vaadin component holding the offer generator
 *//*from   w w  w  .  j  ava2 s  .c  om*/
static Component createOfferGeneratorTab() {

    Database db = qOfferManager.getDb();
    TabSheet managerTabs = qOfferManager.getManagerTabs();

    ComboBox selectedProjectComboBox = new ComboBox("Select Project");
    selectedProjectComboBox.setInputPrompt("No project selected!");
    selectedProjectComboBox.setDescription("Please select a project before its too late! :P");
    selectedProjectComboBox.addItems(db.getProjects());
    selectedProjectComboBox.setWidth("300px");

    Button completeButton = new Button("Complete");
    completeButton.setDescription("Click here to finalize the offer and save it into the DB!");
    completeButton.setIcon(FontAwesome.CHECK_CIRCLE);
    completeButton.setEnabled(false);

    // get the package ids and names as a bean container
    final BeanItemContainer<String> packageIdsAndNamesContainer = new BeanItemContainer<>(String.class);
    packageIdsAndNamesContainer.addAll(db.getPackageIdsAndNames());

    TwinColSelect selectPackagesTwinColSelect = new TwinColSelect();
    selectPackagesTwinColSelect.setContainerDataSource(packageIdsAndNamesContainer);
    selectPackagesTwinColSelect.setLeftColumnCaption("Available packages");
    selectPackagesTwinColSelect.setRightColumnCaption("Selected packages");
    selectPackagesTwinColSelect.setSizeFull();

    // text field which functions as a filter for the left side of the twin column select
    TextField twinColSelectFilter = new TextField();
    twinColSelectFilter.setCaption("Filter available packages");
    twinColSelectFilter.addTextChangeListener((FieldEvents.TextChangeListener) event -> {
        packageIdsAndNamesContainer.removeAllContainerFilters();
        packageIdsAndNamesContainer.addContainerFilter(new Container.Filter() {

            @Override
            public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
                return ((String) itemId).toLowerCase().contains(event.getText().toLowerCase())
                        || ((Collection) selectPackagesTwinColSelect.getValue()).contains(itemId);
            }

            @Override
            public boolean appliesToProperty(Object propertyId) {
                return true;
            }
        });
    });

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

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

    Panel packageDescriptionPanel = new Panel("Package Details");
    packageDescriptionPanel.setContent(right);

    @SuppressWarnings("deprecation")
    Label packageDetailsLabel = new Label("Package details will appear here!", Label.CONTENT_XHTML);
    packageDetailsLabel.addStyleName(ValoTheme.LABEL_BOLD);
    right.addComponent(packageDetailsLabel);

    addListeners(db, managerTabs, selectedProjectComboBox, completeButton, addPackLayout,
            selectPackagesTwinColSelect, packageDescriptionPanel, packageDetailsLabel, twinColSelectFilter);

    addPackLayout.addComponent(selectedProjectComboBox);

    return addPackLayout;
}

From source file:lu.uni.lassy.excalibur.examples.icrash.dev.web.java.views.AdminAuthView.java

License:Open Source License

public AdminAuthView() {

    setSizeFull();/* w  w w  . ja va2 s.  c o  m*/

    VerticalLayout header = new VerticalLayout();
    header.setSizeFull();

    HorizontalLayout content = new HorizontalLayout();
    content.setSizeFull();

    addComponents(header, content);
    setExpandRatio(header, 1);
    setExpandRatio(content, 6);

    welcomeText.setValue("<h1>Welcome to the iCrash Administrator console!</h1>");
    welcomeText.setContentMode(ContentMode.HTML);
    welcomeText.setSizeUndefined();
    header.addComponent(welcomeText);
    header.setComponentAlignment(welcomeText, Alignment.MIDDLE_CENTER);

    Panel controlPanel = new Panel("Administrator control panel");
    controlPanel.setSizeUndefined();

    Panel addCoordPanel = new Panel("Create a new coordinator");
    addCoordPanel.setSizeUndefined();

    Panel messagesPanel = new Panel("Administrator messages");
    messagesPanel.setWidth("580px");

    Table adminMessagesTable = new Table();

    adminMessagesTable.setContainerDataSource(actAdmin.getMessagesDataSource());

    adminMessagesTable.setColumnWidth("inputEvent", 180);
    adminMessagesTable.setSizeFull();

    VerticalLayout controlLayout = new VerticalLayout(controlPanel);
    controlLayout.setSizeFull();
    controlLayout.setMargin(false);
    controlLayout.setComponentAlignment(controlPanel, Alignment.TOP_CENTER);

    VerticalLayout coordOperationsLayout = new VerticalLayout(addCoordPanel);
    coordOperationsLayout.setSizeFull();
    coordOperationsLayout.setMargin(false);
    coordOperationsLayout.setComponentAlignment(addCoordPanel, Alignment.TOP_CENTER);

    /******************************************/
    coordOperationsLayout.setVisible(true); // main layout in the middle
    addCoordPanel.setVisible(false); // ...which contains the panel "Create a new coordinator"
    /******************************************/

    HorizontalLayout messagesExternalLayout = new HorizontalLayout(messagesPanel);
    VerticalLayout messagesInternalLayout = new VerticalLayout(adminMessagesTable);

    messagesExternalLayout.setSizeFull();
    messagesExternalLayout.setMargin(false);
    messagesExternalLayout.setComponentAlignment(messagesPanel, Alignment.TOP_CENTER);

    messagesInternalLayout.setMargin(false);
    messagesInternalLayout.setSizeFull();
    messagesInternalLayout.setComponentAlignment(adminMessagesTable, Alignment.TOP_CENTER);

    messagesPanel.setContent(messagesInternalLayout);

    TextField idCoordAdd = new TextField();
    TextField loginCoord = new TextField();
    PasswordField pwdCoord = new PasswordField();

    Label idCaptionAdd = new Label("ID");
    Label loginCaption = new Label("Login");
    Label pwdCaption = new Label("Password");

    idCaptionAdd.setSizeUndefined();
    idCoordAdd.setSizeUndefined();

    loginCaption.setSizeUndefined();
    loginCoord.setSizeUndefined();

    pwdCaption.setSizeUndefined();
    pwdCoord.setSizeUndefined();

    Button validateNewCoord = new Button("Validate");
    validateNewCoord.setClickShortcut(KeyCode.ENTER);
    validateNewCoord.setStyleName(ValoTheme.BUTTON_PRIMARY);

    GridLayout addCoordinatorLayout = new GridLayout(2, 4);
    addCoordinatorLayout.setSpacing(true);
    addCoordinatorLayout.setMargin(true);
    addCoordinatorLayout.setSizeFull();

    addCoordinatorLayout.addComponents(idCaptionAdd, idCoordAdd, loginCaption, loginCoord, pwdCaption,
            pwdCoord);

    addCoordinatorLayout.addComponent(validateNewCoord, 1, 3);

    addCoordinatorLayout.setComponentAlignment(idCaptionAdd, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(idCoordAdd, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(loginCaption, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(loginCoord, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(pwdCaption, Alignment.MIDDLE_LEFT);
    addCoordinatorLayout.setComponentAlignment(pwdCoord, Alignment.MIDDLE_LEFT);

    addCoordPanel.setContent(addCoordinatorLayout);

    content.addComponents(controlLayout, coordOperationsLayout, messagesExternalLayout);
    content.setComponentAlignment(messagesExternalLayout, Alignment.TOP_CENTER);
    content.setComponentAlignment(controlLayout, Alignment.TOP_CENTER);
    content.setComponentAlignment(messagesExternalLayout, Alignment.TOP_CENTER);

    content.setExpandRatio(controlLayout, 20);
    content.setExpandRatio(coordOperationsLayout, 10);
    content.setExpandRatio(messagesExternalLayout, 28);

    Button addCoordinator = new Button("Add coordinator");
    Button deleteCoordinator = new Button("Delete coordinator");

    addCoordinator.addStyleName(ValoTheme.BUTTON_HUGE);
    deleteCoordinator.addStyleName(ValoTheme.BUTTON_HUGE);
    logoutBtn.addStyleName(ValoTheme.BUTTON_HUGE);

    VerticalLayout buttons = new VerticalLayout();

    buttons.setMargin(true);
    buttons.setSpacing(true);
    buttons.setSizeFull();

    buttons.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

    controlPanel.setContent(buttons);

    buttons.addComponents(addCoordinator, deleteCoordinator, logoutBtn);

    /******* DELETE COORDINATOR PANEL BEGIN *********/
    Label idCaptionDel = new Label("ID");
    TextField idCoordDel = new TextField();

    Panel delCoordPanel = new Panel("Delete a coordinator");

    coordOperationsLayout.addComponent(delCoordPanel);
    delCoordPanel.setVisible(false);

    coordOperationsLayout.setComponentAlignment(delCoordPanel, Alignment.TOP_CENTER);
    delCoordPanel.setSizeUndefined();

    GridLayout delCoordinatorLayout = new GridLayout(2, 2);
    delCoordinatorLayout.setSpacing(true);
    delCoordinatorLayout.setMargin(true);
    delCoordinatorLayout.setSizeFull();

    Button deleteCoordBtn = new Button("Delete");
    deleteCoordBtn.setClickShortcut(KeyCode.ENTER);
    deleteCoordBtn.setStyleName(ValoTheme.BUTTON_PRIMARY);

    delCoordinatorLayout.addComponents(idCaptionDel, idCoordDel);

    delCoordinatorLayout.addComponent(deleteCoordBtn, 1, 1);

    delCoordinatorLayout.setComponentAlignment(idCaptionDel, Alignment.MIDDLE_LEFT);
    delCoordinatorLayout.setComponentAlignment(idCoordDel, Alignment.MIDDLE_LEFT);

    delCoordPanel.setContent(delCoordinatorLayout);
    /******* DELETE COORDINATOR PANEL END *********/

    /************************************************* MAIN BUTTONS LOGIC BEGIN *************************************************/

    addCoordinator.addClickListener(event -> {
        if (!addCoordPanel.isVisible()) {
            delCoordPanel.setVisible(false);
            addCoordPanel.setVisible(true);
            idCoordAdd.focus();
        } else
            addCoordPanel.setVisible(false);
    });

    deleteCoordinator.addClickListener(event -> {
        if (!delCoordPanel.isVisible()) {
            addCoordPanel.setVisible(false);
            delCoordPanel.setVisible(true);
            idCoordDel.focus();
        } else
            delCoordPanel.setVisible(false);
    });

    /************************************************* MAIN BUTTONS LOGIC END *************************************************/

    /************************************************* ADD COORDINATOR FORM LOGIC BEGIN *************************************************/
    validateNewCoord.addClickListener(event -> {

        String currentURL = Page.getCurrent().getLocation().toString();
        int strIndexCreator = currentURL.lastIndexOf(AdministratorLauncher.adminPageName);
        String iCrashURL = currentURL.substring(0, strIndexCreator);
        String googleShebang = "#!";
        String coordURL = iCrashURL + CoordinatorServlet.coordinatorsName + googleShebang;

        try {
            sys.oeAddCoordinator(new DtCoordinatorID(new PtString(idCoordAdd.getValue())),
                    new DtLogin(new PtString(loginCoord.getValue())),
                    new DtPassword(new PtString(pwdCoord.getValue())));

            // open new browser tab with the newly created coordinator console...
            // "_blank" instructs the browser to open a new tab instead of a new window...
            // unhappily not all browsers interpret it correctly,
            // some versions of some browsers might still open a new window instead (notably Firefox)!
            Page.getCurrent().open(coordURL + idCoordAdd.getValue(), "_blank");

        } catch (Exception e) {
            e.printStackTrace();
        }

        idCoordAdd.setValue("");
        loginCoord.setValue("");
        pwdCoord.setValue("");

        idCoordAdd.focus();
    });
    /************************************************* ADD COORDINATOR FORM LOGIC END *************************************************/
    /************************************************* DELETE COORDINATOR FORM LOGIC BEGIN *************************************************/
    deleteCoordBtn.addClickListener(event -> {
        IcrashSystem sys = IcrashSystem.getInstance();

        try {
            sys.oeDeleteCoordinator(new DtCoordinatorID(new PtString(idCoordDel.getValue())));
        } catch (Exception e) {
            e.printStackTrace();
        }

        idCoordDel.setValue("");
        idCoordDel.focus();
    });
    /************************************************* DELETE COORDINATOR FORM LOGIC END *************************************************/
}

From source file:net.antoinecomte.regex.RegExTesterApplication.java

License:Apache License

@Override
public void init() {
    setTheme("chameleon");
    final TextField text = new TextField();

    final TextField regex = new TextField();

    Panel mainPanel = new Panel("Simple Java regular expression tool ");
    mainPanel.setWidth("460px");
    VerticalLayout mainPanelLayout = new VerticalLayout();
    mainPanelLayout.setSpacing(true);// ww w. ja v a2 s . c o  m
    mainPanelLayout.setMargin(true);
    mainPanel.setContent(mainPanelLayout);
    regex.setCaption("Regular Expression");
    regex.setWidth("400px");
    regex.addStyleName("big");
    regex.setInputPrompt("enter a regular expression here");
    regex.setTextChangeEventMode(TextChangeEventMode.TIMEOUT);
    regex.setImmediate(true);

    text.setCaption("Test input");
    text.setInputPrompt("Enter a test string here");
    text.setTextChangeEventMode(TextChangeEventMode.TIMEOUT);
    text.setImmediate(true);
    text.setWidth("400px");
    text.addStyleName("big");
    result.setSizeUndefined();
    result.setWidth("460px");
    result.setStyleName("light");
    result.setVisible(false);

    regex.addListener(new TextChangeListener() {
        private static final long serialVersionUID = 7783333579512074097L;

        @Override
        public void textChange(TextChangeEvent event) {
            showResult(event.getText(), text.getValue().toString());

        }
    });
    text.addListener(new TextChangeListener() {
        private static final long serialVersionUID = -2294521048305268959L;

        @Override
        public void textChange(TextChangeEvent event) {
            showResult(regex.getValue().toString(), event.getText());
        }
    });
    Window mainWindow = new Window();
    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSpacing(true);
    mainLayout.setMargin(true);
    mainWindow.setContent(mainLayout);
    mainWindow.addComponent(mainPanel);
    mainPanel.addComponent(regex);
    mainPanel.addComponent(text);
    mainWindow.addComponent(result);
    setMainWindow(mainWindow);
}

From source file:net.sf.gazpachoquest.questionnaires.views.QuestionnaireView.java

License:Open Source License

@Override
public void enter(ViewChangeEvent event) {
    logger.debug("Entering {} view ", QuestionnaireView.NAME);
    addStyleName(Reindeer.LAYOUT_BLUE);/*from   w w  w  . ja  v  a2  s.c om*/
    addStyleName("questionnaires");

    WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
    Integer screenWidth = webBrowser.getScreenWidth();
    Integer heightWidth = webBrowser.getScreenHeight();

    logger.debug("Browser screen settings  {} x {}", screenWidth, heightWidth);

    if (heightWidth <= 480) {
        renderingMode = RenderingMode.QUESTION_BY_QUESTION;
    }

    // centralLayout.addStyleName("questionnaires");
    // new Responsive(centralLayout);

    RespondentAccount respondent = (RespondentAccount) VaadinServletService.getCurrentServletRequest()
            .getUserPrincipal();
    if (respondent.hasPreferredLanguage()) {
        preferredLanguage = Language.fromString(respondent.getPreferredLanguage());
    } else {
        preferredLanguage = Language.fromLocale(webBrowser.getLocale());
    }
    questionnaireId = respondent.getGrantedquestionnaireIds().iterator().next();
    logger.debug("Trying to fetch questionnair identified with id  = {} ", questionnaireId);
    QuestionnaireDefinitionDTO definition = questionnaireResource.getDefinition(questionnaireId);
    sectionInfoVisible = definition.isSectionInfoVisible();
    QuestionnairePageDTO page = questionnaireResource.getPage(questionnaireId, renderingMode, preferredLanguage,
            NavigationAction.ENTERING);

    logger.debug("Displaying page {}/{} with {} questions", page.getMetadata().getNumber(),
            page.getMetadata().getCount(), page.getQuestions().size());
    questionsLayout = new VerticalLayout();
    update(page);

    Label questionnaireTitle = new Label(definition.getLanguageSettings().getTitle());
    questionnaireTitle.addStyleName(Reindeer.LABEL_H1);

    VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();
    mainLayout.setMargin(true);
    mainLayout.addComponent(questionnaireTitle);
    mainLayout.addComponent(questionsLayout);
    // Add the responsive capabilities to the components

    Panel centralLayout = new Panel();
    centralLayout.setContent(mainLayout);
    centralLayout.setSizeFull();
    centralLayout.getContent().setSizeUndefined();

    Responsive.makeResponsive(questionnaireTitle);
    setCompositionRoot(centralLayout);
    setSizeFull();
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java

License:Apache License

private Component displaySetting(VmSetting s, boolean edit) {
    Panel form = new Panel(TRANSLATOR.translate("setting.detail"));
    FormLayout layout = new FormLayout();
    form.setContent(layout);
    form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT);
    BeanFieldGroup binder = new BeanFieldGroup(s.getClass());
    binder.setItemDataSource(s);/*  www. j  a v a 2s . c o  m*/
    Field<?> id = (TextField) binder.buildAndBind(TRANSLATOR.translate("general.setting"), "setting");
    layout.addComponent(id);
    Field bool = binder.buildAndBind(TRANSLATOR.translate("bool.value"), "boolVal");
    bool.setSizeFull();
    layout.addComponent(bool);
    Field integerVal = binder.buildAndBind(TRANSLATOR.translate("int.value"), "intVal");
    integerVal.setSizeFull();
    layout.addComponent(integerVal);
    Field longVal = binder.buildAndBind(TRANSLATOR.translate("long.val"), "longVal");
    longVal.setSizeFull();
    layout.addComponent(longVal);
    Field stringVal = binder.buildAndBind(TRANSLATOR.translate("string.val"), "stringVal", TextArea.class);
    stringVal.setSizeFull();
    layout.addComponent(stringVal);
    Button cancel = new Button(TRANSLATOR.translate("general.cancel"));
    cancel.addClickListener((Button.ClickEvent event) -> {
        binder.discard();
    });
    //Editing existing one
    Button update = new Button(TRANSLATOR.translate("general.update"));
    update.addClickListener((Button.ClickEvent event) -> {
        try {
            binder.commit();
            displaySetting(s);
        } catch (FieldGroup.CommitException ex) {
            LOG.log(Level.SEVERE, null, ex);
            Notification.show(TRANSLATOR.translate("general.error.record.update"), ex.getLocalizedMessage(),
                    Notification.Type.ERROR_MESSAGE);
        }
    });
    boolean blocked = !s.getSetting().startsWith("version.");
    if (blocked) {
        HorizontalLayout hl = new HorizontalLayout();
        hl.addComponent(update);
        hl.addComponent(cancel);
        layout.addComponent(hl);
    }
    binder.setBuffered(true);
    binder.setReadOnly(edit);
    binder.bindMemberFields(form);
    //The version settigns are not modifiable from the GUI
    binder.setEnabled(blocked);
    //Id is always blocked.
    id.setEnabled(false);
    form.setSizeFull();
    return form;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.DataEntryComponent.java

License:Apache License

@Override
protected Component initContent() {
    Panel p = new Panel();
    FormLayout layout = new FormLayout();
    p.setContent(layout);
    getInternalValue().forEach(de -> {
        BeanFieldGroup binder = new BeanFieldGroup(de.getClass());
        binder.setItemDataSource(de);/*w w  w. j  a va2 s . c  o  m*/
        TextField name = new TextField(TRANSLATOR.translate("general.name"));
        binder.bind(name, "entryName");
        name.setConverter(new TranslationConverter());
        layout.addComponent(name);
        TextField type = new TextField(TRANSLATOR.translate("general.type"));
        type.setConverter(new Converter<String, DataEntryType>() {

            @Override
            public DataEntryType convertToModel(String value, Class<? extends DataEntryType> targetType,
                    Locale locale) throws Converter.ConversionException {
                for (DataEntryType det : DataEntryTypeServer.getTypes()) {
                    if (TRANSLATOR.translate(det.getTypeName()).equals(value)) {
                        return det;
                    }
                }
                return null;
            }

            @Override
            public String convertToPresentation(DataEntryType value, Class<? extends String> targetType,
                    Locale locale) throws Converter.ConversionException {
                return TRANSLATOR.translate(value.getTypeName());
            }

            @Override
            public Class<DataEntryType> getModelType() {
                return DataEntryType.class;
            }

            @Override
            public Class<String> getPresentationType() {
                return String.class;
            }
        });
        DataEntryPropertyComponent properties = new DataEntryPropertyComponent(edit);
        binder.bind(type, "dataEntryType");
        layout.addComponent(type);
        binder.bind(properties, "dataEntryPropertyList");
        layout.addComponent(properties);
        binder.setReadOnly(!edit);
        type.setReadOnly(true);
    });
    return p;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.DataEntryPropertyComponent.java

License:Apache License

@Override
protected Component initContent() {
    Panel p = new Panel();
    FormLayout l = new FormLayout();
    getInternalValue().forEach(prop -> {
        if (!prop.getPropertyName().equals("property.expected.result")) {
            HorizontalLayout hl = new HorizontalLayout();
            TextField tf = new TextField(TRANSLATOR.translate(prop.getPropertyName()), prop.getPropertyValue());
            hl.addComponent(tf);/*from  ww  w  .  j a v a 2s.c  o  m*/
            if (edit) {
                //Add button for deleting this property.
                Button delete = new Button();
                delete.setIcon(VaadinIcons.MINUS);
                delete.addClickListener(listener -> {
                    getInternalValue().remove(prop);
                    l.removeComponent(hl);
                });
                hl.addComponent(delete);
            }
            l.addComponent(hl);
        }
    });
    p.setContent(l);
    return p;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.DataEntryTypeComponent.java

License:Apache License

@Override
protected Component initContent() {
    Panel p = new Panel();
    FormLayout l = new FormLayout();
    p.setContent(l);
    BeanFieldGroup binder = new BeanFieldGroup(getInternalValue().getClass());
    binder.setItemDataSource(getInternalValue());
    l.addComponent(binder.buildAndBind(TRANSLATOR.translate("general.name"), "typeName"));
    l.addComponent(binder.buildAndBind(TRANSLATOR.translate("general.description"), "typeDescription"));
    binder.setReadOnly(!edit);// w  w  w . java2 s  . c  o  m
    return p;
}