view flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionGrid.java @ 211:b92281182c6b

Removed the FLYSMessages interface and replaced it with a FLYSConstants interface - this interface has the ability to lookup i18n strings with given keys. flys-client/trunk@1645 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 05 Apr 2011 08:13:48 +0000
parents 0bec0112c8b3
children
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;

import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;

import de.intevation.flys.client.shared.model.CollectionRecord;

import de.intevation.flys.client.client.FLYSConstants;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class CollectionGrid extends ListGrid {

    /** The message class that provides i18n strings.*/
    FLYSConstants messages = GWT.create(FLYSConstants.class);

    /**
     * The default constructor that creates a new ListGrid item.
     *
     * @param collection The artifact collection.
     */
    public CollectionGrid() {
    }

    @Override
    protected Canvas createRecordComponent(
        final ListGridRecord record, Integer col)
    {
        String field = getFieldName(col);

        if (field == null)                return null;
        if (field.equals("date"))         return createDateField(record);
        else if (field.equals("name"))    return createNameField(record);
        else if (field.equals("publish")) return createPublishField(record);
        else if (field.equals("delete"))  return createDeleteField(record);

        return null;
    }


    /**
     * This method creates the date field for the collection grid.
     *
     * @param record The record to be displayed.
     */
    protected Canvas createDateField(ListGridRecord record) {
        CollectionRecord rec = (CollectionRecord) record;

        Date date          = rec.getCreationTime();
        DateTimeFormat dtf = DateTimeFormat.getFormat(
            messages.datetime_format());

        String formatted   = dtf.format(date);

        Label label = new Label(formatted);
        label.setHeight(15);
        label.setWidth100();

        return label;
    }


    /**
     * This method creates the name field for the collection grid.
     *
     * @param record The record to be displayed.
     */
    protected Canvas createNameField(ListGridRecord record) {
        CollectionRecord rec = (CollectionRecord) record;

        String name = rec.getName();
        int len     = name.length();
        int sec     = len - 15;
        String sub  = name.substring(0, 14) + "..." + name.substring(sec, len-1);

        Label label = new Label(sub);
        label.setHeight(15);
        label.setWidth100();

        return label;
    }


    /**
     * This method creates the field for the collection grid that provides a
     * button to publish the collection.
     *
     * @param record The record to be displayed.
     */
    protected Canvas createPublishField(ListGridRecord record) {
        IButton button = new IButton();
        button.setHeight(15);
        button.setTitle("PUB");
        return button;
    }


    /**
     * This method creates the field for the collection grid that provides a
     * button to delete the collection.
     *
     * @param record The record to be displayed.
     */
    protected Canvas createDeleteField(ListGridRecord record) {
        IButton button = new IButton();
        button.setHeight(15);
        button.setTitle("DEL");
        return button;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org