Posts

Showing posts from September, 2017

How to Edit Vaadin 8 Grid.

Image
Here goes the short snippet of the code for Editing Grid in Vaadin Code does following. Takes Grid. populates Grid. makes Grid editable property true. sets component what one needs to add when grid is edited. identifies column at the time of adding column or getting column. grid = new Grid<> (); lst = new ArrayList<> (); provider = new ListDataProvider < >(lst) ; lst.add(new Company(1, "Java" )) ; grid.setDataProvider(provider) ; grid.addColumn(Company::getSerialNo).setCaption( "Sr.no" ) ; TextField tf = new TextField (); grid.getEditor ().setEnabled( true ); HorizontalLayout hlyt = new HorizontalLayout (); grid.addColumn(Company::getName).setEditorComponent(tf, Company::setName).setCaption( "Name" ).setExpandRatio(2) ; hlyt.addComponent(grid) ; Hope it works cheers .

Vaadin 8 Sub Window by using an Addon messagebox

Image
Code is as Follows TextField name = new TextField("Name");         TextField country = new TextField("country");         TextField network = new TextField("Network");         SubWindow subWindow = new SubWindow();         subWindow.setCaption("Sub-window");         VerticalLayout subcontent = new VerticalLayout();         subWindow.setContent(subcontent);               subWindow.setHeight("350px");         subWindow.setWidth("500px");         subcontent.addComponents(name, country, network);         subWindow.center();  grid.addItemClickListener(e -> {             String putName = e.getItem().name.toString();             name.setValue(putName);             name.focus();             String putCountry = e.getItem().country.toString();             country.setValue(putCountry);             String putNetwork = e.getItem().network.toString();             network.setValue(putNetwork);             if (

Filtering Grid (Vaadin 8)

Image
We saw how to work with Grid now moving on to Example of How to Filter a Grid. Here is the Code Snippet For the Gird Filter We  have our  File we have created in the previous Post in which we had a Grid and ListDataProvider in it keep it as it is, Create a new Java File say FilterGrid.java. and It write the folowing Code. public class FilterGrid extends CustomComponent  {    private VerticalLayout vlytbase;     private TextField search;                              //for searching the Respctive Text     TestGrid tstgrid = new TestGrid();     String input;     public TestFilter() {         vlytbase = new VerticalLayout();         vlytbase.setMargin(true);         vlytbase.setSizeFull();         search = new TextField();         search.setPlaceholder("Search");         vlytbase.addComponents(search, tstgrid);         vlytbase.setSpacing(true);         vlytbase.setMargin(true);         vlytbase.setSizeFull();         setCompositionRoot(vlytbase);    

Simple Rating Stars in Vaadin

package com.example.DemoProject; import java.util.ArrayList; import java.util.List; import com.vaadin.annotations.Theme; import com.vaadin.icons.VaadinIcons; import com.vaadin.navigator.View; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CssLayout; import com.vaadin.ui.CustomComponent; import com.vaadin.ui.Label; @Theme("RatingStars") public class RatingStars extends CustomComponent implements View {     Button b1 = new Button();     Button b2 = new Button();     Button b3 = new Button();     Button b4 = new Button();     Button b5 = new Button();     Label status = new Label("Review us");     private ClickListener listener;     public RatingStars() {         listener = this::test;               b1.setIcon(VaadinIcons.STAR_O);         b2.setIcon(VaadinIcons.STAR_O);         b3.setIcon(VaadinIcons.STAR_O);         b4.setIcon(VaadinIcons.STAR_O);  

chat App(Vaadin)

package com.example.ChatAPP ; import java.util.ArrayList ; import java.util.Date ; import java.util.List ; import com.vaadin.data.provider.ListDataProvider ; import com.vaadin.event.ShortcutAction.KeyCode ; import com.vaadin.navigator.View ; import com.vaadin.ui.Button ; import com.vaadin.ui.CustomComponent ; import com.vaadin.ui.Grid ; import com.vaadin.ui.HorizontalLayout ; import com.vaadin.ui.Label ; import com.vaadin.ui.TextField ; import com.vaadin.ui.VerticalLayout ; public class Chatapp extends CustomComponent implements View { /** * */ private static final long serialVersionUID = 1L; private static final List< Msg > MSGS = new ArrayList<> (); private static final ListDataProvider< Msg > DP = new ListDataProvider<> (MSGS); private static int UCOUNT = 1; private VerticalLayout vlytbaseLayout; int counter; Button send; public Chata

A Complete Example Integrating the Rating Star with Grid

Image
package com.example.DemoProject ; import com.vaadin.server.ThemeResource ; public class Company { private int serialNo; private String name; private RatingStars rtstars; private ThemeResource rsrc; public Company () { } public Company ( int serialNo, String name, RatingStars rtstars) { this . serialNo = serialNo; this . name = name; this . rtstars = rtstars; } public ThemeResource getRsrc () { return rsrc; } public void setRsrc ( ThemeResource rsrc) { this . rsrc = rsrc; } public Company ( int serialNo, String name, RatingStars rtstars, ThemeResource rsrc) { this . serialNo = serialNo; this . name = name; this . rtstars = rtstars; this . rsrc = rsrc; } public RatingStars getRtstars () { return rtstars; } public void setRtstars ( RatingStars rtstars) { this . rtstars = rtstars

How to add images in Vaadin 8 Grid in Respective Rows

Here goes the Code for it Column< Company , ThemeResource > imageColumn = grid . addColumn( p - > new ThemeResource (p . getName() + ".jpg" ), new ImageRenderer< Company > ()) . setCaption( "Image" ); Set the name of Image as you have set in the List while Populating your Pojo.

Drag and drop items from one Grid to another

Following is a short example to drag and drop similar type of items from one Grid to another Grid in Vaadin 8 . package com . example . demo ; import java . util . ArrayList ; import java . util . List ; import java . util . Optional ; import com . vaadin . data . provider . ListDataProvider ; import com . vaadin . shared . ui . dnd . DropEffect ; import com . vaadin . shared . ui . dnd . EffectAllowed ; import com . vaadin . shared . ui . grid . DropMode ; import com . vaadin . ui . CustomComponent ; import com . vaadin . ui . Grid ; import com . vaadin . ui . HorizontalLayout ; import com . vaadin . ui . components . grid . GridDragSource ; import com . vaadin . ui . components . grid . GridDropTarget ; import com . vaadin . ui . renderers . ButtonRenderer ; public class DragAndDropFromGrid extends CustomComponent { /**       *      */ private static final long serialVersionUID = 1 L ; private HorizontalLayout hlytbase ;