how to add column of ClickableTextCells to cellTable
Asked Answered
P

3

6

hi all i need a simple example show me how to add column of ClickableTextCells to cellTable

thanks.

Pyromancy answered 21/3, 2011 at 23:17 Comment(1)
Hi Ahmed. Please revert the questions to its original form and post the solution as an answer. Read the stackoverflow.com/faq if you still have questions about stackoverflow. Thanks.Prig
P
3

this is the solution if you need to add clickableTextCell to cellTable

// ClickableTextCell

ClickableTextCell anchorcolumn = new ClickableTextCell();
table.addColumn(addColumn(anchorcolumn, new GetValue<String>() {
        public String getValue(Contact contact) {
            return "Click " + contact.anchor;
        }
    }, new FieldUpdater<Contact, String>() {
        public void update(int index, Contact object, String value) {
            Window.alert("You clicked " + object.name);
        }
    }), "Anchor");



private <C> Column<Contact, C> addColumn(Cell<C> cell,final GetValue<C> getter,
FieldUpdater<Contact, C> fieldUpdater) {
        Column<Contact, C> column = new Column<Contact, C>(cell) {

        @Override
        public C getValue(Contact object) {
            return getter.getValue(object);
        }
    };
    column.setFieldUpdater(fieldUpdater);

    return column;
}

private static interface GetValue<C> {
    C getValue(Contact contact);
}


// A simple data type that represents a contact.
    private static class Contact {
        private final String address;
        private final String name;
        private final String anchor;

        public Contact(String name, String address, String anchor) {
            this.name = name;
            this.address = address;
            this.anchor = anchor;
        }
    }
Pyromancy answered 22/3, 2011 at 10:47 Comment(1)
This is a really convoluted way of creating a ClickableTextCell. I like pigpig's answer below a lot better.Jalisajalisco
S
9
Column<YerValueObject, String> newCol = new Column<YerValueObject, String>(new  ClickableTextCell()) {
    @Override
    public String getValue(YearValueObject obj) {
        return obj.someMethod();
    }

};

newCol.setFieldUpdater(new FieldUpdater<YerValueObject, String>() {
    @Override
    public void update(int index, YerValueObject obj, String value) {
        //do whatever you need to here...
    }
});

table.addColumn(newCol, "ClickColumn");
Strophanthus answered 14/12, 2011 at 15:46 Comment(0)
P
3

this is the solution if you need to add clickableTextCell to cellTable

// ClickableTextCell

ClickableTextCell anchorcolumn = new ClickableTextCell();
table.addColumn(addColumn(anchorcolumn, new GetValue<String>() {
        public String getValue(Contact contact) {
            return "Click " + contact.anchor;
        }
    }, new FieldUpdater<Contact, String>() {
        public void update(int index, Contact object, String value) {
            Window.alert("You clicked " + object.name);
        }
    }), "Anchor");



private <C> Column<Contact, C> addColumn(Cell<C> cell,final GetValue<C> getter,
FieldUpdater<Contact, C> fieldUpdater) {
        Column<Contact, C> column = new Column<Contact, C>(cell) {

        @Override
        public C getValue(Contact object) {
            return getter.getValue(object);
        }
    };
    column.setFieldUpdater(fieldUpdater);

    return column;
}

private static interface GetValue<C> {
    C getValue(Contact contact);
}


// A simple data type that represents a contact.
    private static class Contact {
        private final String address;
        private final String name;
        private final String anchor;

        public Contact(String name, String address, String anchor) {
            this.name = name;
            this.address = address;
            this.anchor = anchor;
        }
    }
Pyromancy answered 22/3, 2011 at 10:47 Comment(1)
This is a really convoluted way of creating a ClickableTextCell. I like pigpig's answer below a lot better.Jalisajalisco
M
2

Create a Column overriding the onBrowserEvent method.

Like this:

new Column<T, String>(new TextCell()) {
    @Override
    public String getValue(T object) {
        return object.getProperty();
    }

    @Override
    public void onBrowserEvent(Context context, Element elem, T object, NativeEvent event) {
        // TODO You can check which event you want to catch
        Window.open("http://www.stackoverflow.com", "StackOverFlow", "");
    }
};
Maecenas answered 15/4, 2011 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.