SWT Table and Date columns

View: New views
2 Messages — Rating Filter:   Alert me  

SWT Table and Date columns

by Matt P :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Everyone,

I am new to glazed lists, and already I have seen how useful they are to quickly set up tables in my SWT/JFACE application.

However, I am having one problem displaying and sorting Dates (java.util.Date) in my SWT Table.  Is there a way to add a custom renderer to change how the Date object is rendered into the string that is displayed in the table cell? and also keep the sorting to sort by the true date, regardless of the way its rendered?

The FAQ says to return java.util.Date to ensure proper sorting, which I am doing, but it doesnt sort by true date, but sorts by the toString of the Date.

Any help will be appreciated.

Thanks

Parent Message unknown Re: SWT Table and Date columns

by Holger Brands :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>
> Hi Everyone,
>
> I am new to glazed lists, and already I have seen how useful they are to
> quickly set up tables in my SWT/JFACE application.
>
> However, I am having one problem displaying and sorting Dates
> (java.util.Date) in my SWT Table.  Is there a way to add a custom renderer
> to change how the Date object is rendered into the string that is displayed
> in the table cell? and also keep the sorting to sort by the true date,
> regardless of the way its rendered?

You could provide a TableItemConfigurer to the constructor of the EventTableViewer or via the corresponding setter method.
A ca.odell.glazedlists.swt.TableItemConfigurer allows you to customize the appearance of the displayed TableItems.
Here is an example implementation:

public class IssueTableItemConfigurer implements TableItemConfigurer<Issue> {

    /** DateFormatter. */
    private final DateFormat dateFormatter = DateFormat.getDateInstance();

    /** {@inheritDoc} */
    public void configure(TableItem item, Issue rowValue, Object columnValue, int row, int column) {
        switch (column) {
            case 2: item.setText(column, dateToString(columnValue)); break;
            case 3: item.setText(column, dateToString(columnValue)); break;
            default: TableItemConfigurer.DEFAULT.configure(item, rowValue, columnValue, row, column);
        }
    }

    /**
     * Converts a Date to a String with the default {@link DateFormat}.
     */
    private String dateToString(Object value) {
        String result = "";
        if (value instanceof Date) {
            result = dateFormatter.format((Date) value);
        }
        return result;
    }
}


>
> The FAQ says to return java.util.Date to ensure proper sorting, which I am
> doing, but it doesnt sort by true date, but sorts by the toString of the
> Date.

Hmm, this should work. Could you post an example that demonstrates the issue?

Thanks,
Holger

__________________________________________________________________________
Verschicken Sie SMS direkt vom Postfach aus - in alle deutschen und viele
ausländische Netze zum gleichen Preis!
https://produkte.web.de/webde_sms/sms




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...