Example usage for com.google.gwt.user.client.ui HasHorizontalAlignment ALIGN_LOCALE_END

List of usage examples for com.google.gwt.user.client.ui HasHorizontalAlignment ALIGN_LOCALE_END

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui HasHorizontalAlignment ALIGN_LOCALE_END.

Prototype

HorizontalAlignmentConstant ALIGN_LOCALE_END

To view the source code for com.google.gwt.user.client.ui HasHorizontalAlignment ALIGN_LOCALE_END.

Click Source Link

Document

In a RTL layout, specifies that the widget's contents should be aligned to the left.

Usage

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

License:Apache License

/**
 * Initialize this example./*  w  w w. ja v  a 2s . 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;
}