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

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

Introduction

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

Prototype

public ImageCell() 

Source Link

Document

Construct a new ImageCell.

Usage

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

License:Apache License

/**
 * Initialize this example./*from  w w  w  .  j a  va 2 s  .  com*/
 */
@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:eu.europeana.uim.gui.cp.client.europeanawidgets.ImportResourcesWidget.java

License:EUPL

/**
 * Add the columns to the table.//from  w  ww  .  j a  v  a 2 s.  co  m
 */
private void initTableColumns(final SelectionModel<SugarCRMRecordDTO> selectionModel,
        ListHandler<SugarCRMRecordDTO> sortHandler) {

    // Checkbox column. This table will uses a checkbox column for
    // selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to
    // enable
    // mouse selection.
    Column<SugarCRMRecordDTO, Boolean> checkColumn = new Column<SugarCRMRecordDTO, Boolean>(
            new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(SugarCRMRecordDTO object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    cellTable.setColumnWidth(checkColumn, 40, Unit.PX);

    // IsImported column
    Column<SugarCRMRecordDTO, String> isImportedColumn = new Column<SugarCRMRecordDTO, String>(
            new ImageCell()) {
        @Override
        public String getValue(SugarCRMRecordDTO object) {
            return object.getImportedIMG();
        }
    };
    isImportedColumn.setSortable(true);

    sortHandler.setComparator(isImportedColumn, new Comparator<SugarCRMRecordDTO>() {
        public int compare(SugarCRMRecordDTO o1, SugarCRMRecordDTO o2) {
            return o1.getImportedIMG().compareTo(o2.getImportedIMG());
        }
    });
    cellTable.addColumn(isImportedColumn, EuropeanaClientConstants.UIMSTATELABEL);
    isImportedColumn.setFieldUpdater(new FieldUpdater<SugarCRMRecordDTO, String>() {
        public void update(int index, SugarCRMRecordDTO object, String value) {

            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(isImportedColumn, 7, Unit.PCT);

    // Collection Name Column
    Column<SugarCRMRecordDTO, Anchor> collectionColumn = new Column<SugarCRMRecordDTO, Anchor>(
            new AnchorCell()) {
        @Override
        public Anchor getValue(SugarCRMRecordDTO object) {

            Anchor hyper = new Anchor();
            hyper.setName(object.getName());
            hyper.setText(object.getName());
            hyper.setHref(sugarLocation + object.getId());
            hyper.setTarget("TOP");

            return hyper;
        }
    };
    collectionColumn.setSortable(true);

    sortHandler.setComparator(collectionColumn, new Comparator<SugarCRMRecordDTO>() {
        public int compare(SugarCRMRecordDTO o1, SugarCRMRecordDTO o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    cellTable.addColumn(collectionColumn, EuropeanaClientConstants.DSNAMESEARCHLABEL);
    collectionColumn.setFieldUpdater(new FieldUpdater<SugarCRMRecordDTO, Anchor>() {
        public void update(int index, SugarCRMRecordDTO object, Anchor value) {

            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(collectionColumn, 40, Unit.PCT);

    // Organization Name Column
    Column<SugarCRMRecordDTO, String> organizationColumn = new Column<SugarCRMRecordDTO, String>(
            new TextCell()) {
        @Override
        public String getValue(SugarCRMRecordDTO object) {
            return object.getOrganization_name();
        }
    };

    collectionColumn.setSortable(true);

    sortHandler.setComparator(organizationColumn, new Comparator<SugarCRMRecordDTO>() {
        public int compare(SugarCRMRecordDTO o1, SugarCRMRecordDTO o2) {
            return o1.getOrganization_name().compareTo(o2.getOrganization_name());
        }
    });

    cellTable.addColumn(organizationColumn, EuropeanaClientConstants.ORGANIZATIONSEARCHLABEL);
    organizationColumn.setFieldUpdater(new FieldUpdater<SugarCRMRecordDTO, String>() {
        public void update(int index, SugarCRMRecordDTO object, String value) {

            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(organizationColumn, 20, Unit.PCT);

    // Country Column

    Column<SugarCRMRecordDTO, String> countryColumn = new Column<SugarCRMRecordDTO, String>(new TextCell()) {
        @Override
        public String getValue(SugarCRMRecordDTO object) {
            return object.getCountry_c();
        }
    };
    countryColumn.setSortable(true);

    sortHandler.setComparator(countryColumn, new Comparator<SugarCRMRecordDTO>() {
        public int compare(SugarCRMRecordDTO o1, SugarCRMRecordDTO o2) {
            return o1.getCountry_c().compareTo(o2.getCountry_c());
        }
    });
    cellTable.addColumn(countryColumn, EuropeanaClientConstants.COUNTRYSEARCHLABEL);
    countryColumn.setFieldUpdater(new FieldUpdater<SugarCRMRecordDTO, String>() {
        public void update(int index, SugarCRMRecordDTO object, String value) {

            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(countryColumn, 5, Unit.PCT);

    // Status Column
    Column<SugarCRMRecordDTO, String> statusColumn = new Column<SugarCRMRecordDTO, String>(new TextCell()) {
        @Override
        public String getValue(SugarCRMRecordDTO object) {
            return object.getStatus();
        }
    };
    statusColumn.setSortable(true);

    sortHandler.setComparator(statusColumn, new Comparator<SugarCRMRecordDTO>() {
        public int compare(SugarCRMRecordDTO o1, SugarCRMRecordDTO o2) {
            return o1.getStatus().compareTo(o2.getStatus());
        }
    });
    cellTable.addColumn(statusColumn, EuropeanaClientConstants.STATUSSEARCHLABEL);
    statusColumn.setFieldUpdater(new FieldUpdater<SugarCRMRecordDTO, String>() {
        public void update(int index, SugarCRMRecordDTO object, String value) {

            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(statusColumn, 20, Unit.PCT);

    // Amount Column

    Column<SugarCRMRecordDTO, String> amountColumn = new Column<SugarCRMRecordDTO, String>(new TextCell()) {
        @Override
        public String getValue(SugarCRMRecordDTO object) {
            return object.getIngested_total_c();
        }
    };
    amountColumn.setSortable(true);

    sortHandler.setComparator(amountColumn, new Comparator<SugarCRMRecordDTO>() {
        public int compare(SugarCRMRecordDTO o1, SugarCRMRecordDTO o2) {
            return o1.getIngested_total_c().compareTo(o2.getIngested_total_c());
        }
    });
    cellTable.addColumn(amountColumn, EuropeanaClientConstants.AMOUNTSEARCHLABEL);
    amountColumn.setFieldUpdater(new FieldUpdater<SugarCRMRecordDTO, String>() {
        public void update(int index, SugarCRMRecordDTO object, String value) {

            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(amountColumn, 20, Unit.PCT);

    // Ingestion Date Column
    Column<SugarCRMRecordDTO, String> ingestionDateColumn = new Column<SugarCRMRecordDTO, String>(
            new TextCell()) {
        @Override
        public String getValue(SugarCRMRecordDTO object) {
            return object.getExpected_ingestion_date();
        }
    };
    ingestionDateColumn.setSortable(true);

    sortHandler.setComparator(ingestionDateColumn, new Comparator<SugarCRMRecordDTO>() {
        public int compare(SugarCRMRecordDTO o1, SugarCRMRecordDTO o2) {
            return o1.getExpected_ingestion_date().compareTo(o2.getExpected_ingestion_date());
        }
    });
    cellTable.addColumn(ingestionDateColumn, EuropeanaClientConstants.INGESTDATESEARCHLABEL);
    ingestionDateColumn.setFieldUpdater(new FieldUpdater<SugarCRMRecordDTO, String>() {
        public void update(int index, SugarCRMRecordDTO object, String value) {

            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(ingestionDateColumn, 20, Unit.PCT);

    // User Column

    Column<SugarCRMRecordDTO, String> userColumn = new Column<SugarCRMRecordDTO, String>(new TextCell()) {
        @Override
        public String getValue(SugarCRMRecordDTO object) {
            return object.getAssigned_user_name();
        }
    };
    userColumn.setSortable(true);

    sortHandler.setComparator(userColumn, new Comparator<SugarCRMRecordDTO>() {
        public int compare(SugarCRMRecordDTO o1, SugarCRMRecordDTO o2) {

            return o1.getAssigned_user_name().compareTo(o2.getAssigned_user_name());
        }
    });

    cellTable.addColumn(userColumn, EuropeanaClientConstants.USERSEARCHLABEL);
    userColumn.setFieldUpdater(new FieldUpdater<SugarCRMRecordDTO, String>() {
        public void update(int index, SugarCRMRecordDTO object, String value) {

            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(userColumn, 20, Unit.PCT);

}

From source file:org.glom.web.client.ui.list.ListTable.java

License:Open Source License

private void addColumn(final LayoutItemField layoutItemField) {
    // Setup the default alignment of the column.
    HorizontalAlignmentConstant columnAlignment;
    Formatting formatting = layoutItemField.getFormatting();
    if (formatting == null) {
        GWT.log("addColumn(): Formatting is null for field=" + layoutItemField.getLayoutDisplayName());
        formatting = new Formatting(); // Just to avoid null dereferencing later.
    }//from w w w.  j av  a 2  s .co m

    switch (formatting.getHorizontalAlignment()) {
    case HORIZONTAL_ALIGNMENT_LEFT:
        columnAlignment = HasHorizontalAlignment.ALIGN_LEFT;
        break;
    case HORIZONTAL_ALIGNMENT_RIGHT:
        columnAlignment = HasHorizontalAlignment.ALIGN_RIGHT;
        break;
    case HORIZONTAL_ALIGNMENT_AUTO:
    default:
        columnAlignment = HasHorizontalAlignment.ALIGN_DEFAULT;
        break;
    }

    // create a new column
    Column<DataItem[], ?> column = null;
    final int j = cellTable.getColumnCount();
    switch (layoutItemField.getGlomType()) {

    case TYPE_BOOLEAN:
        column = new Column<DataItem[], Boolean>(new BooleanCell()) {
            @Override
            public Boolean getValue(final DataItem[] row) {
                if (row.length == 1 && row[0] == null) {
                    // an empty row
                    return null;
                }

                if (j >= row.length) {
                    GWT.log("addColumn(): j=" + j + " is out of range. length=" + row.length);
                    return null;
                } else {
                    return row[j].getBoolean();
                }
            }
        };
        // override the configured horizontal alignment
        columnAlignment = HasHorizontalAlignment.ALIGN_CENTER;
        break;

    case TYPE_NUMERIC:
        // create a GWT NumberFormat for the column
        final NumericFormat numericFormat = formatting.getNumericFormat();
        final NumberFormat gwtNumberFormat = Utils.getNumberFormat(numericFormat);

        // create the actual column
        column = new Column<DataItem[], Double>(new NumericCell(
                formatting.getTextFormatColorForegroundAsHTMLColor(),
                formatting.getTextFormatColorBackgroundAsHTMLColor(), gwtNumberFormat,
                numericFormat.getUseAltForegroundColorForNegatives(), numericFormat.getCurrencySymbol())) {
            @Override
            public Double getValue(final DataItem[] row) {
                if (row.length == 1 && row[0] == null) {
                    // an empty row
                    return null;
                }

                if (j >= row.length) {
                    GWT.log("addColumn(): j=" + j + " is out of range. length=" + row.length);
                    return null;
                } else {
                    return row[j].getNumber();
                }
            }
        };
        break;
    case TYPE_IMAGE:
        column = new Column<DataItem[], String>(new ImageCell()) {
            @Override
            public String getValue(final DataItem[] row) {
                if (row.length == 1 && row[0] == null) {
                    // an empty row
                    return null;
                }

                if (j >= row.length) {
                    GWT.log("addColumn(): j=" + j + " is out of range. length=" + row.length);
                    return null;
                } else {
                    return row[j].getImageDataUrl();
                }
            }
        };
        // override the configured horizontal alignment
        columnAlignment = HasHorizontalAlignment.ALIGN_CENTER;
        break;

    default:
        // use a text rendering cell for types we don't know about but log an error
        // TODO log error here
    case TYPE_DATE:
    case TYPE_INVALID:
    case TYPE_TIME:
    case TYPE_TEXT:
        column = new Column<DataItem[], String>(
                new TextCell(formatting.getTextFormatColorForegroundAsHTMLColor(),
                        formatting.getTextFormatColorBackgroundAsHTMLColor())) {
            @Override
            public String getValue(final DataItem[] row) {
                if (row.length == 1 && row[0] == null) {
                    // an empty row
                    return null;
                }

                if (j >= row.length) {
                    GWT.log("addColumn(): j=" + j + " is out of range. length=" + row.length);
                    return null;
                } else {
                    return row[j].getText();
                }
            }
        };
        break;
    }

    // set column properties and add to cell cellTable
    column.setHorizontalAlignment(columnAlignment);
    column.setSortable(true);
    cellTable.addColumn(column, new SafeHtmlHeader(SafeHtmlUtils.fromString(layoutItemField.getTitle())));
}

From source file:org.lorislab.smonitor.gwt.uc.table.column.EntityImageColumn.java

License:Apache License

/**
 * The default constructor.
 */
public EntityImageColumn() {
    super(new ImageCell());
}