Example usage for com.google.gwt.cell.client ActionCell ActionCell

List of usage examples for com.google.gwt.cell.client ActionCell ActionCell

Introduction

In this page you can find the example usage for com.google.gwt.cell.client ActionCell ActionCell.

Prototype

public ActionCell(String text, Delegate<C> delegate) 

Source Link

Document

Construct a new ActionCell with a text String that does not contain HTML markup.

Usage

From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellSampler.java

License:Apache License

/**
 * Initialize this example./*from  w  w w  . ja va2  s  . c o  m*/
 */
@ShowcaseSource
@Override
public Widget onInitialize() {
    Images images = GWT.create(Images.class);

    // Create the table.
    editableCells = new ArrayList<AbstractEditableCell<?, ?>>();
    contactList = new DataGrid<ContactInfo>(25, ContactInfo.KEY_PROVIDER);
    contactList.setMinimumTableWidth(140, Unit.EM);
    ContactDatabase.get().addDataDisplay(contactList);

    // CheckboxCell.
    final Category[] categories = ContactDatabase.get().queryCategories();
    addColumn(new CheckboxCell(), "Checkbox", new GetValue<Boolean>() {
        @Override
        public Boolean getValue(ContactInfo contact) {
            // Checkbox indicates that the contact is a relative.
            // Index 0 = Family.
            return contact.getCategory() == categories[0];
        }
    }, new FieldUpdater<ContactInfo, Boolean>() {
        @Override
        public void update(int index, ContactInfo object, Boolean value) {
            if (value) {
                // If a relative, use the Family Category.
                pendingChanges.add(new CategoryChange(object, categories[0]));
            } else {
                // If not a relative, use the Contacts Category.
                pendingChanges.add(new CategoryChange(object, categories[categories.length - 1]));
            }
        }
    });

    // TextCell.
    addColumn(new TextCell(), "Text", new GetValue<String>() {
        @Override
        public String getValue(ContactInfo contact) {
            return contact.getFullName();
        }
    }, null);

    // EditTextCell.
    Column<ContactInfo, String> editTextColumn = addColumn(new EditTextCell(), "EditText",
            new GetValue<String>() {
                @Override
                public String getValue(ContactInfo contact) {
                    return contact.getFirstName();
                }
            }, new FieldUpdater<ContactInfo, String>() {
                @Override
                public void update(int index, ContactInfo object, String value) {
                    pendingChanges.add(new FirstNameChange(object, value));
                }
            });
    contactList.setColumnWidth(editTextColumn, 16.0, Unit.EM);

    // TextInputCell.
    Column<ContactInfo, String> textInputColumn = addColumn(new TextInputCell(), "TextInput",
            new GetValue<String>() {
                @Override
                public String getValue(ContactInfo contact) {
                    return contact.getLastName();
                }
            }, new FieldUpdater<ContactInfo, String>() {
                @Override
                public void update(int index, ContactInfo object, String value) {
                    pendingChanges.add(new LastNameChange(object, value));
                }
            });
    contactList.setColumnWidth(textInputColumn, 16.0, Unit.EM);

    // ClickableTextCell.
    addColumn(new ClickableTextCell(), "ClickableText", new GetValue<String>() {
        @Override
        public String getValue(ContactInfo contact) {
            return "Click " + contact.getFirstName();
        }
    }, new FieldUpdater<ContactInfo, String>() {
        @Override
        public void update(int index, ContactInfo object, String value) {
            Window.alert("You clicked " + object.getFullName());
        }
    });

    // ActionCell.
    addColumn(new ActionCell<ContactInfo>("Click Me", new ActionCell.Delegate<ContactInfo>() {
        @Override
        public void execute(ContactInfo contact) {
            Window.alert("You clicked " + contact.getFullName());
        }
    }), "Action", new GetValue<ContactInfo>() {
        @Override
        public ContactInfo getValue(ContactInfo contact) {
            return contact;
        }
    }, null);

    // ButtonCell.
    addColumn(new ButtonCell(), "Button", new GetValue<String>() {
        @Override
        public String getValue(ContactInfo contact) {
            return "Click " + contact.getFirstName();
        }
    }, new FieldUpdater<ContactInfo, String>() {
        @Override
        public void update(int index, ContactInfo object, String value) {
            Window.alert("You clicked " + object.getFullName());
        }
    });

    // DateCell.
    DateTimeFormat dateFormat = DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM);
    addColumn(new DateCell(dateFormat), "Date", new GetValue<Date>() {
        @Override
        public Date getValue(ContactInfo contact) {
            return contact.getBirthday();
        }
    }, null);

    // DatePickerCell.
    addColumn(new DatePickerCell(dateFormat), "DatePicker", new GetValue<Date>() {
        @Override
        public Date getValue(ContactInfo contact) {
            return contact.getBirthday();
        }
    }, new FieldUpdater<ContactInfo, Date>() {
        @Override
        public void update(int index, ContactInfo object, Date value) {
            pendingChanges.add(new BirthdayChange(object, value));
        }
    });

    // NumberCell.
    Column<ContactInfo, Number> numberColumn = addColumn(new NumberCell(), "Number", new GetValue<Number>() {
        @Override
        public Number getValue(ContactInfo contact) {
            return contact.getAge();
        }
    }, null);
    numberColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LOCALE_END);

    // IconCellDecorator.
    addColumn(new IconCellDecorator<String>(images.contactsGroup(), new TextCell()), "Icon",
            new GetValue<String>() {
                @Override
                public String getValue(ContactInfo contact) {
                    return contact.getCategory().getDisplayName();
                }
            }, null);

    // ImageCell.
    addColumn(new ImageCell(), "Image", new GetValue<String>() {
        @Override
        public String getValue(ContactInfo contact) {
            return "contact.jpg";
        }
    }, null);

    // SelectionCell.
    List<String> options = new ArrayList<String>();
    for (Category category : categories) {
        options.add(category.getDisplayName());
    }
    addColumn(new SelectionCell(options), "Selection", new GetValue<String>() {
        @Override
        public String getValue(ContactInfo contact) {
            return contact.getCategory().getDisplayName();
        }
    }, new FieldUpdater<ContactInfo, String>() {
        @Override
        public void update(int index, ContactInfo object, String value) {
            for (Category category : categories) {
                if (category.getDisplayName().equals(value)) {
                    pendingChanges.add(new CategoryChange(object, category));
                    break;
                }
            }
        }
    });

    // Create the UiBinder.
    Binder uiBinder = GWT.create(Binder.class);
    Widget widget = uiBinder.createAndBindUi(this);

    // Add handlers to redraw or refresh the table.
    redrawButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            contactList.redraw();
        }
    });
    commitButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            // Commit the changes.
            for (PendingChange<?> pendingChange : pendingChanges) {
                pendingChange.commit();
            }
            pendingChanges.clear();

            // Push the changes to the views.
            ContactDatabase.get().refreshDisplays();
        }
    });

    return widget;
}

From source file:com.gsr.myschool.back.client.web.application.settings.widget.MatiereExamenView.java

License:Apache License

private void initDataGrid() {
    TextColumn<MatiereExamenProxy> nomPrenomColumn = new TextColumn<MatiereExamenProxy>() {
        @Override/*w  w  w  .j  a va  2 s  . c  o  m*/
        public String getValue(MatiereExamenProxy object) {
            return object.getNom();
        }
    };
    nomPrenomColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    matiereExamenTable.addColumn(nomPrenomColumn, "Nom");
    matiereExamenTable.setColumnWidth(nomPrenomColumn, 70, Style.Unit.PCT);

    ActionCell<MatiereExamenProxy> actionCell = new ActionCell<MatiereExamenProxy>("Supprimer",
            new ActionCell.Delegate<MatiereExamenProxy>() {
                @Override
                public void execute(MatiereExamenProxy object) {
                    getUiHandlers().deleteMatiereExamen(object);
                }
            });
    Column<MatiereExamenProxy, MatiereExamenProxy> actionColumn = new Column<MatiereExamenProxy, MatiereExamenProxy>(
            actionCell) {
        @Override
        public MatiereExamenProxy getValue(MatiereExamenProxy object) {
            return object;
        }
    };
    actionColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    matiereExamenTable.addColumn(actionColumn, "Action");
    matiereExamenTable.setColumnWidth(actionColumn, 30, Style.Unit.PCT);
}

From source file:com.gsr.myschool.back.client.web.application.settings.widget.PiecesJustifView.java

License:Apache License

private void initDataGrid() {
    TextColumn<PieceJustifProxy> nomPrenomColumn = new TextColumn<PieceJustifProxy>() {
        @Override/*from w  ww .  j  a v a  2s  .c  o m*/
        public String getValue(PieceJustifProxy object) {
            return object.getNom();
        }
    };
    nomPrenomColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    piecesJustifTable.addColumn(nomPrenomColumn, "Nom");
    piecesJustifTable.setColumnWidth(nomPrenomColumn, 70, Style.Unit.PCT);

    ActionCell<PieceJustifProxy> actionCell = new ActionCell<PieceJustifProxy>("Supprimer",
            new ActionCell.Delegate<PieceJustifProxy>() {
                @Override
                public void execute(PieceJustifProxy object) {
                    getUiHandlers().deletePieceJustif(object);
                }
            });
    Column<PieceJustifProxy, PieceJustifProxy> actionColumn = new Column<PieceJustifProxy, PieceJustifProxy>(
            actionCell) {
        @Override
        public PieceJustifProxy getValue(PieceJustifProxy object) {
            return object;
        }
    };
    actionColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    piecesJustifTable.addColumn(actionColumn, "Action");
    piecesJustifTable.setColumnWidth(actionColumn, 30, Style.Unit.PCT);
}

From source file:com.gwtplatform.carstore.client.application.cars.CarsView.java

License:Apache License

private void initActionColumns() {
    Cell<CarDto> editCell = new ActionCell<CarDto>("Edit", new Delegate<CarDto>() {
        @Override// w w  w  .  j a  va 2s.  co m
        public void execute(CarDto carDto) {
            getUiHandlers().onEdit(carDto);
        }
    });

    Cell<CarDto> deleteCell = new ActionCell<CarDto>("Delete", new Delegate<CarDto>() {
        @Override
        public void execute(CarDto carDto) {
            Boolean confirm = Window.confirm("Are you sure you want to delete " + carDto.getModel() + "?");

            if (confirm) {
                getUiHandlers().onDelete(carDto);
            }
        }
    });

    IdentityColumn<CarDto> editColumn = new IdentityColumn<CarDto>(editCell);
    IdentityColumn<CarDto> deleteColumn = new IdentityColumn<CarDto>(deleteCell);

    carGrid.addColumn(editColumn, "Edit");
    carGrid.addColumn(deleteColumn, "Delete");

    carGrid.setColumnWidth(editColumn, 75, Unit.PX);
    carGrid.setColumnWidth(deleteColumn, 75, Unit.PX);
}

From source file:com.gwtplatform.carstore.client.application.manufacturer.ManufacturerView.java

License:Apache License

private void initActionColumns() {
    Cell<ManufacturerDto> editCell = new ActionCell<ManufacturerDto>("Edit", new Delegate<ManufacturerDto>() {
        @Override/*from   w  w w  .ja v  a2 s  .co m*/
        public void execute(ManufacturerDto manufacturerDto) {
            getUiHandlers().onEdit(manufacturerDto);
        }
    });

    Cell<ManufacturerDto> deleteCell = new ActionCell<ManufacturerDto>("Delete",
            new Delegate<ManufacturerDto>() {
                @Override
                public void execute(ManufacturerDto manufacturerDto) {
                    Boolean confirm = Window
                            .confirm("Are you sure you want to delete " + manufacturerDto.getName() + "?");

                    if (confirm) {
                        getUiHandlers().onDelete(manufacturerDto);
                    }
                }
            });

    IdentityColumn<ManufacturerDto> editColumn = new IdentityColumn<ManufacturerDto>(editCell);
    IdentityColumn<ManufacturerDto> deleteColumn = new IdentityColumn<ManufacturerDto>(deleteCell);

    manufacturerGrid.addColumn(editColumn, "Edit");
    manufacturerGrid.addColumn(deleteColumn, "Delete");

    manufacturerGrid.setColumnWidth(editColumn, 75, Unit.PX);
    manufacturerGrid.setColumnWidth(deleteColumn, 75, Unit.PX);
}

From source file:com.gwtplatform.carstore.client.application.rating.RatingView.java

License:Apache License

private void initActionColumns() {
    Cell<RatingDto> deleteCell = new ActionCell<RatingDto>("Delete", new ActionCell.Delegate<RatingDto>() {
        @Override//from ww w. ja va 2 s.c om
        public void execute(RatingDto ratingDto) {
            Boolean confirm = Window.confirm("Are you sure you want to delete" + ratingDto.toString() + "?");

            if (confirm) {
                getUiHandlers().onDelete(ratingDto);
            }
        }
    });

    IdentityColumn<RatingDto> deleteColumn = new IdentityColumn<RatingDto>(deleteCell);
    ratingGrid.addColumn(deleteColumn, "Delete");
    ratingGrid.setColumnWidth(deleteColumn, 75, Style.Unit.PX);
}

From source file:eu.zeigermann.gwt.demo.client.item.DefaultItemView.java

License:Apache License

private void addEditColumn() {
    Column<ItemDto, ItemDto> deleteColumn = new Column<ItemDto, ItemDto>(new ActionCell<ItemDto>(
            SafeHtmlUtils.fromSafeConstant("<i class='icon-edit'></i>"), new Delegate<ItemDto>() {
                @Override/*from ww  w.ja v  a 2 s.co  m*/
                public void execute(final ItemDto item) {
                    presenter.edit(item);
                }
            })) {
        @Override
        public ItemDto getValue(ItemDto object) {
            return object;
        }
    };
    cellTable.addColumn(deleteColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
}

From source file:eu.zeigermann.gwt.demo.client.item.DefaultItemView.java

License:Apache License

private void addDeleteColumn() {
    Column<ItemDto, ItemDto> deleteColumn = new Column<ItemDto, ItemDto>(new ActionCell<ItemDto>(
            SafeHtmlUtils.fromSafeConstant("<i class='icon-remove'></i>"), new Delegate<ItemDto>() {
                @Override//from  w ww . j  a va  2  s . co m
                public void execute(final ItemDto item) {
                    presenter.delete(item);
                    reset();
                }
            })) {
        @Override
        public ItemDto getValue(ItemDto object) {
            return object;
        }
    };
    cellTable.addColumn(deleteColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
}

From source file:eu.zeigermann.gwt.demo.client.list.DefaultShoppingListView.java

License:Apache License

private void addEditColumn() {
    Delegate<ShoppingList> delegate = new Delegate<ShoppingList>() {
        @Override/*from   w w  w  .  j  a v a 2s  .  c  o  m*/
        public void execute(final ShoppingList list) {
            presenter.edit(list);
        }
    };
    ActionCell<ShoppingList> actionCell = new ActionCell<ShoppingList>(
            SafeHtmlUtils.fromSafeConstant("<i class='icon-edit'></i>"), delegate);
    Column<ShoppingList, ShoppingList> deleteColumn = new Column<ShoppingList, ShoppingList>(actionCell) {
        @Override
        public ShoppingList getValue(ShoppingList object) {
            return object;
        }

    };
    cellTable.addColumn(deleteColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
}

From source file:eu.zeigermann.gwt.demo.client.list.DefaultShoppingListView.java

License:Apache License

private void addDeleteColumn() {
    Column<ShoppingList, ShoppingList> deleteColumn = new Column<ShoppingList, ShoppingList>(
            new ActionCell<ShoppingList>(SafeHtmlUtils.fromSafeConstant("<i class='icon-remove'></i>"),
                    new Delegate<ShoppingList>() {
                        @Override
                        public void execute(final ShoppingList list) {
                            presenter.delete(list);
                            reset();/*from w w  w. ja v  a2  s .co  m*/
                        }
                    })) {
        @Override
        public ShoppingList getValue(ShoppingList object) {
            return object;
        }
    };
    cellTable.addColumn(deleteColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
}