What's new? | Help | Directory | Sign in
Google
                
Search
for
Updated Jan 10, 2008 by steam.fade
Labels: Featured
BasicUsage  
This tutorial will show to you the basic usage of GWT-Masterview library.

Basic usage

To use the library, you need gwt-masterview.jar on your classpath, as well as gwt-user.jar and platform-specific gwt-dev-os.jar (for example, gwt-dev-windows.jar or gwt-dev-linux).

Add <inherits name='org.masterview.user.Masterview'/> line to all modules that will use the library. Also add a reference to the one of available masterview's stylesheets, for example <stylesheet src="mastergrid-default.css"/>.

Resulting GWT module's xml will look like this:

<module>
    <inherits name='com.google.gwt.user.User'/>
    <inherits name='org.masterview.user.Masterview'/>

    <stylesheet src="mastergrid-default.css"/>   
    <entry-point class='com.mycompany.example.user.client.MyEntryPoint'/>
		
    <!-- other declarations -->
</module>

Now you are ready to write the code.

Create a bean like this:

package org.masterview.showcase.user.client;

public class Album
{
    private String name;
    private String artist;
    private int year;
    private String genre;

    public String getName() {
	return name;
    }
	
    public void setName(String name) {
        this.name = name;
    }
	
    public String getArtist() {
	return artist;
    }
	
    public void setArtist(String artist) {
	this.artist = artist;
    }

    public int getYear() {
	return year;
    }
	
    public void setYear(int year) {
	this.year = year;
    }
	
    public String getGenre() {
	return genre;
    }
	
    public void setGenre(String genre) {
	this.genre = genre;
    }
	
    public Album() {}

    public Album(String name, String artist, int year, String genre) {
        this.name = name;
	this.artist = artist;
	this.year = year;
	this.genre = genre;
    }
}

Mark it with IsMasterviewBean interface:

package org.masterview.showcase.user.client;

import org.masterview.user.client.IsMasterviewBean;

public class Album implements IsMasterviewBean {
    //code unchanged
}

Create a collection of albums:

List albums = new ArrayList();
for (int i = 0; i < 50; i++) {
    albums.add(new Album("Album #" + i, "Artist #" + i, i, "Some genre"));
}

Create a MasterView with the collection of albums as it's data source:

MasterView masterView = (MasterView) GWT.create(Album.class);
masterView.setItems(albums);

Add columns. To create a column you must at least specify a property of a bean that will be rendered in this column. Our Album bean has 4 properties: "name", "artist", "year" and "genre". We set the columns so that all 4 properties will be rendered:

masterView.appendColumn(new Column("name", "Name", true, "40%"));
masterView.appendColumn(new Column("artist", "Artist", true, "30%"));
masterView.appendColumn(new Column("year", "Year of recording", true, "20%"));
masterView.appendColumn(new Column("genre", "Genre", true, "20%"));	

In the code snippet above the first parameter of Column's constructor is the name of the album's property to render, the second parameter is the title of the column, the third parameter defines if the column is sortable and the fourth one is the width of the column.

Enable the filtering (disabled by default) and set how much items you want to be displayed per page.

masterView.setFilteringEnabled(true);
masterView.setPageSize(10);

Add MasterView to a container:

RootPanel.get().add(masterView); 

In result you should get something like this:

That's all for now.


Comment by aniketsay, Jan 28, 2008

How to add checkbox column in masterview?

Comment by rishi.bhargava, Mar 30, 2008

Also I cannot find the gwt-masterview.jar anywhere in the sources. Do I have to build it. I dont use maven which is what the build file is for.

Comment by dhruv.sakalley, Apr 30, 2008

This looks great, but would the content be editable? That should make a jsp look like a jsf, cutting away the heavy "things" :) will be waiting for the release, do let me know when it happens

Comment by rdean1970, Jun 26, 2008

First of all, this is exactly what I have been looking for. Simple and easy to implement.

Is there any way for you to post the latest version of the gwt-masterview.jar? I pulled the source code from SVN, but I was not successful building the jar file from the imported source. I am not sure if it is how Eclipse imported it into my workspace or what. I ended up using the "gwt-masterview-0.1-SNAPSHOT.jar" which was in the sample directory of the source. I have no idea if that is the latest and greatest version, but it does seem to be working. Thanks for the great work.

Comment by freemed, Jul 01, 2008

MasterView? doesn't seem to expose any obvious click catching methods... Is there a preferred way to catch a click to a row and pass that object on to a Listener of some sort?


Sign in to add a comment