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

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

Introduction

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

Prototype

public AbstractCell(Set<String> consumedEvents) 

Source Link

Document

Construct a new AbstractCell with the specified consumed events.

Usage

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

private static HasCell<ContactInfo, Boolean> createStar(final CwCellList.Images images) {
    return new HasCell<ContactInfo, Boolean>() {
        @Override/*w w  w.j a va 2  s .c o m*/
        public Cell<Boolean> getCell() {
            return new AbstractCell<Boolean>(BrowserEvents.CLICK) {

                private ImageResourceRenderer renderer = new ImageResourceRenderer();

                @Override
                public void render(Cell.Context context, Boolean value, SafeHtmlBuilder sb) {
                    if (value != null) {
                        sb.append(renderer.render(value ? images.star() : images.starOutline()));
                    }
                }

                @Override
                public void onBrowserEvent(Cell.Context context, Element parent, Boolean value,
                        NativeEvent event, ValueUpdater<Boolean> valueUpdater) {
                    // Let AbstractCell handle the keydown event.
                    super.onBrowserEvent(context, parent, value, event, valueUpdater);

                    // Handle the click event.
                    if (BrowserEvents.CLICK.equals(event.getType())) {
                        // Ignore clicks that occur outside of the outermost element.
                        EventTarget eventTarget = event.getEventTarget();
                        if (parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))) {
                            boolean newValue = !value;
                            valueUpdater.update(newValue);
                            SafeHtmlBuilder sb = new SafeHtmlBuilder();
                            render(context, newValue, sb);
                            parent.setInnerSafeHtml(sb.toSafeHtml());
                        }
                    }
                }
            };
        }

        @Override
        public FieldUpdater<ContactInfo, Boolean> getFieldUpdater() {
            return new FieldUpdater<ContactInfo, Boolean>() {

                @Override
                public void update(int index, ContactInfo contact, Boolean value) {
                    contact.setStarred(value);
                }
            };
        }

        @Override
        public Boolean getValue(ContactInfo contact) {
            return contact.isStarred();
        }
    };
}

From source file:com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel.java

License:sencha.com license

/**
 * Creates a CheckBoxSelectionModel with a custom ValueProvider and appearance.
 * /*from ww w .j a v a2 s .com*/
 * @param valueProvider the ValueProvider to use when constructing a ColumnConfig
 * @param appearance the appearance that should be used to render and update the checkbox
 */
public CheckBoxSelectionModel(ValueProvider<M, M> valueProvider, final CheckBoxColumnAppearance appearance) {
    this.appearance = appearance;
    config = newColumnConfig(valueProvider);
    config.setCellPadding(false);
    config.setWidth(20);
    config.setSortable(false);
    config.setHideable(false);
    config.setResizable(false);
    config.setFixed(true);
    config.setMenuDisabled(true);
    config.setCellClassName(appearance.getCellClassName());
    config.setColumnHeaderClassName(appearance.getCellInnerClassName());

    config.setHeader(appearance.renderHeadCheckBox());
    // allow touch events in
    Set<String> consumedEvents = new HashSet<String>(Arrays.asList(BrowserEvents.TOUCHSTART,
            BrowserEvents.TOUCHMOVE, BrowserEvents.TOUCHCANCEL, BrowserEvents.TOUCHEND));
    if (PointerEventsSupport.impl.isSupported()) {
        consumedEvents.add(PointerEvents.POINTERDOWN.getEventName());
    }
    config.setCell(new AbstractCell<M>(consumedEvents) {
        @Override
        public void onBrowserEvent(Context context, Element parent, M value, NativeEvent event,
                ValueUpdater<M> valueUpdater) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);

            // If the incoming event is touch, then selection is already taken care of
            // Don't let mouse events to pass through
            String eventType = event.getType();
            if (BrowserEvents.TOUCHSTART.equals(eventType) || BrowserEvents.TOUCHMOVE.equals(eventType)
                    || BrowserEvents.TOUCHCANCEL.equals(eventType) || BrowserEvents.TOUCHEND.equals(eventType)
                    || PointerEventsSupport.impl.isPointerEvent(event)) {
                event.preventDefault();
            }
        }

        @Override
        public void render(Context context, M value, SafeHtmlBuilder sb) {
            CheckBoxSelectionModel.this.render(context, value, sb);
        }
    });

    deselectOnSimpleClick = false;
}

From source file:org.kie.workbench.common.stunner.bpmn.client.forms.fields.notificationsEditor.widget.NotificationWidgetViewImpl.java

License:Apache License

private void initDelete() {
    AbstractCell<NotificationRow> buttonCell = new AbstractCell<NotificationRow>(
            ClickEvent.getType().getName()) {
        @Override//from  ww w  .j a v a  2s  . c om
        public void render(Context context, NotificationRow value, SafeHtmlBuilder sb) {
            Button button = new Button();
            button.setSize(ButtonSize.SMALL);
            button.add(new Icon(IconType.TRASH));
            sb.append(SafeHtmlUtils.fromTrustedString(button.toString()));
        }

        @Override
        public void onBrowserEvent(Context context, Element parent, NotificationRow value, NativeEvent event,
                ValueUpdater<NotificationRow> valueUpdater) {
            if (!readOnly) {
                delete(value);
            }
        }
    };

    Column<NotificationRow, NotificationRow> deleteColumn = new Column<NotificationRow, NotificationRow>(
            buttonCell) {
        @Override
        public NotificationRow getValue(NotificationRow object) {
            return object;
        }
    };
    deleteColumn.setSortable(false);
    table.addColumn(deleteColumn, presenter.getDeleteLabel());
    table.setColumnWidth(deleteColumn, 60, Style.Unit.PX);
}

From source file:org.kie.workbench.common.stunner.bpmn.client.forms.fields.notificationsEditor.widget.NotificationWidgetViewImpl.java

License:Apache License

private void initEdit() {
    AbstractCell<NotificationRow> buttonCell = new AbstractCell<NotificationRow>(
            ClickEvent.getType().getName()) {
        @Override//from w  w w . ja  v a  2s.  co m
        public void render(Context context, NotificationRow value, SafeHtmlBuilder sb) {
            Button button = new Button();
            button.setSize(ButtonSize.SMALL);
            button.add(new Icon(IconType.EDIT));
            sb.append(SafeHtmlUtils.fromTrustedString(button.toString()));
        }

        @Override
        public void onBrowserEvent(Context context, Element parent, NotificationRow value, NativeEvent event,
                ValueUpdater<NotificationRow> valueUpdater) {
            if (!readOnly) {
                addOrEdit(value);
            }
        }
    };

    Column<NotificationRow, NotificationRow> editColumn = new Column<NotificationRow, NotificationRow>(
            buttonCell) {
        @Override
        public NotificationRow getValue(NotificationRow object) {
            return object;
        }
    };
    editColumn.setSortable(false);
    table.addColumn(editColumn, StunnerFormsClientFieldsConstants.INSTANCE.Edit());
    table.setColumnWidth(editColumn, 50, Style.Unit.PX);
}

From source file:org.kie.workbench.common.stunner.bpmn.client.forms.fields.reassignmentsEditor.widget.ReassignmentWidgetViewImpl.java

License:Apache License

private void initDelete() {
    AbstractCell<ReassignmentRow> buttonCell = new AbstractCell<ReassignmentRow>(
            ClickEvent.getType().getName()) {
        @Override/*from   w w  w. j ava  2 s . c  o m*/
        public void render(Context context, ReassignmentRow value, SafeHtmlBuilder sb) {
            Button button = new Button();
            button.setSize(ButtonSize.SMALL);
            button.add(new Icon(IconType.REMOVE));
            sb.append(SafeHtmlUtils.fromTrustedString(button.toString()));
        }

        @Override
        public void onBrowserEvent(Context context, Element parent, ReassignmentRow value, NativeEvent event,
                ValueUpdater<ReassignmentRow> valueUpdater) {
            if (!readOnly) {
                delete(value);
            }
        }
    };

    Column<ReassignmentRow, ReassignmentRow> deleteColumn = new Column<ReassignmentRow, ReassignmentRow>(
            buttonCell) {
        @Override
        public ReassignmentRow getValue(ReassignmentRow object) {
            return object;
        }
    };
    deleteColumn.setSortable(false);
    table.addColumn(deleteColumn, presenter.getDeleteLabel());
    table.setColumnWidth(deleteColumn, 60, Style.Unit.PX);
}

From source file:org.kie.workbench.common.stunner.bpmn.client.forms.fields.reassignmentsEditor.widget.ReassignmentWidgetViewImpl.java

License:Apache License

private void initEdit() {
    AbstractCell<ReassignmentRow> buttonCell = new AbstractCell<ReassignmentRow>(
            ClickEvent.getType().getName()) {
        @Override// w ww. j a  v  a 2  s .  co m
        public void render(Context context, ReassignmentRow value, SafeHtmlBuilder sb) {
            Button button = new Button();
            button.setSize(ButtonSize.SMALL);
            button.add(new Icon(IconType.EDIT));
            sb.append(SafeHtmlUtils.fromTrustedString(button.toString()));
        }

        @Override
        public void onBrowserEvent(Context context, Element parent, ReassignmentRow value, NativeEvent event,
                ValueUpdater<ReassignmentRow> valueUpdater) {
            if (!readOnly) {
                addOrEdit(value);
            }
        }
    };

    Column<ReassignmentRow, ReassignmentRow> editColumn = new Column<ReassignmentRow, ReassignmentRow>(
            buttonCell) {
        @Override
        public ReassignmentRow getValue(ReassignmentRow object) {
            return object;
        }
    };
    editColumn.setSortable(false);
    table.addColumn(editColumn, StunnerFormsClientFieldsConstants.INSTANCE.Edit());
    table.setColumnWidth(editColumn, 50, Style.Unit.PX);
}