Giter Site home page Giter Site logo

dmicol / crudui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alejandro-du/crudui

0.0 0.0 0.0 180 KB

Automatically generate CRUD-like Vaadin components for any Java Bean

Home Page: https://vaadin.com/directory#!addon/crud-ui-add-on

License: Apache License 2.0

Java 100.00%

crudui's Introduction

CRUD UI add-on for Vaadin

Crud UI Add-on provides an API to automatically generate CRUD-like UIs for any Java Bean at runtime.

API

The API is defined through 4 interfaces:

  • CrudComponent: A Vaadin Component that can be added into any ComponentContainer. This is the actual CRUD final users will see on the browser.

  • CrudListener: Encapsulates the CRUD operations. You can implement this interface to delegate CRUD operations to your back-end.

  • CrudLayout: Encapsulates layout-related behaviour.

  • CrudFormFactory: Builds the forms required by the CRUD UI.

Crud UI Add-on includes atnleast one implementation for each of these interfaces (except CrudListener which is an optional "connection point" to your application.

Basic sage

Create a new CrudComponent and add it to a layout (currently, Crud UI Add-on provides only one implementation of the CrudComponent interface: GridBasedCrudComponent):

GridBasedCrudComponent<User> crud = new GridBasedCrudComponent<>(User.class);
layout.addComponent(crud);

Use lambda expressions or method references to delegate CRUD operations to your backend:

crud.setFindAllOperation(() -> backend.findAll());
crud.setAddOperation(backend::add);
crud.setUpdateOperation(backend::update);
crud.setDeleteOperation(backend::delete);

Advanced usage

As an alternative to lambada expressions you can implement the CrudListener interface to delegate CRUD operations to your backend:

crud.setCrudListener(new CrudListener<User>() {
    @Override
    public Collection<User> findAll() {
        return backend.findAllUsers();
    }
    @Override
    public User add(User user) {
        return backend.add(user);
    }

    @Override
    public User update(User user) {
        return backend.update(user);
    }

    @Override
    public void delete(User user) {
        backend.remove(user);
    }
});

Use a different CrudLayout implementation:

GridBasedCrudComponent<User> crud = new GridBasedCrudComponent<>(User.class, new HorizontalSplitCrudLayout());

Set a different CrudFormFactory implementation:

GridLayoutCrudFormFactory<User> formFactory = new GridLayoutCrudFormFactory<>(User.class, 2, 2);
crud.setCrudFormFactory(formFactory);

Configure the visibility of the fields in the forms:

formFactory.setVisiblePropertyIds(CrudOperation.READ, "name", "birthDate", "email", "groups", "mainGroup", "active");
formFactory.setVisiblePropertyIds(CrudOperation.ADD, "name", "birthDate", "email", "password", "groups", "mainGroup", "active");
formFactory.setVisiblePropertyIds(CrudOperation.UPDATE, "name", "birthDate", "email", "groups", "mainGroup", "active");
formFactory.setVisiblePropertyIds(CrudOperation.DELETE, "name", "email");

Use nested properties:

crud.getGridContainer().addNestedContainerBean("mainGroup");
crud.getGrid().setColumns("name", "birthDate", "email", "mainGroup.name", "active");
crud.getGrid().getColumn("mainGroup.name").setHeaderCaption("Main group");

Configure Grid renderers:

crud.getGrid().getColumn("birthDate").setRenderer(new DateRenderer("%1$tY-%1$tm-%1$te"));

Configure the type of a field:

formFactory.setFieldType("password", PasswordField.class);

Customize fields after their creation:

formFactory.setFieldCreationListener("birthDate", field -> ((DateField) field).setDateFormat("yyyy-MM-dd"));

Define a provider to manually create a field:

formFactory.setFieldProvider("groups", () -> {
    OptionGroup optionGroup = new OptionGroup();
    optionGroup.setMultiSelect(true);
    optionGroup.setContainerDataSource(new BeanItemContainer<>(Group.class, groups));
    optionGroup.setItemCaptionPropertyId("name");
    return optionGroup;
});

Customize captions:

formFactory.setButtonCaption(CrudOperation.ADD, "Add new user");
crud.setRowCountCaption("%d user(s) found");

License

Add-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt.

crudui's People

Contributors

alejandro-du avatar dmicol avatar jurajmazari avatar amagnolo avatar bonifacechacha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.