Example usage for com.google.gwt.user.client.ui HasWidgets add

List of usage examples for com.google.gwt.user.client.ui HasWidgets add

Introduction

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

Prototype

void add(Widget w);

Source Link

Document

Adds a child widget.

Usage

From source file:cc.alcina.framework.gwt.client.widget.SelectWithSearch.java

License:Apache License

private void updateItemsCellList(String filterText, HasWidgets itemHolder) {
    emptyItems = true;//from   w  w  w  .  j a v a2 s . c o  m
    Cell<T> cell = new AbstractCell<T>() {
        @Override
        public void render(com.google.gwt.cell.client.Cell.Context context, T value, SafeHtmlBuilder sb) {
            sb.appendEscaped((String) renderer.apply(value));
        }
    };
    CellList<T> cellList = new CellList<T>(cell);
    cellList.setPageSize(9999);
    cellList.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    // Add a selection model so we can select cells.
    final SingleSelectionModel<T> selectionModel = new SingleSelectionModel<T>(new SimpleKeyProvider<T>());
    cellList.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            itemSelected(selectionModel.getSelectedObject());
        }
    });
    List<T> items = new ArrayList<>();
    for (G c : keys) {
        if (!itemMap.containsKey(c)) {
            continue;
        }
        for (T item : itemMap.get(c)) {
            String filterable = CommonUtils.nullToEmpty(((String) renderer.apply(item))).toLowerCase();
            if (itemFilter.allow(item, filterable, filterText) && !selectedItems.contains(item)) {
                items.add(item);
            }
        }
    }
    ListDataProvider<T> dataProvider = new ListDataProvider<T>();
    dataProvider.getList().addAll(items);
    dataProvider.addDataDisplay(cellList);
    emptyItems = items.isEmpty();
    itemHolder.clear();
    itemHolder.add(cellList);
    afterUpdateItems(emptyItems);
}

From source file:cc.alcina.framework.gwt.client.widget.SelectWithSearch.java

License:Apache License

protected void addDefaultSeparator(HasWidgets itemHolder) {
    itemHolder.add(new InlineHTML(" "));
}

From source file:cc.alcina.framework.gwt.client.widget.SelectWithSearch.java

License:Apache License

protected void addGroupHeading(HasWidgets itemHolder, Label l) {
    itemHolder.add(l);
}

From source file:cc.alcina.framework.gwt.client.widget.SelectWithSearch.java

License:Apache License

protected void updateItems() {
    boolean recreateItemHolder = isRecreateItemHolderOnRefresh() && itemHolder.getParent() != null;
    if (recreateItemHolder) {
        itemHolder.removeFromParent();//from   w  w  w.j  a v a  2 s. c om
        createItemHolder();
    }
    HasWidgets itemHolder = itemHolderAsHasWidgets();
    itemHolder.clear();
    if (isUseCellList()) {
        updateItemsCellList("", itemHolder);
        return;
    }
    emptyItems = true;
    if (hintLabel != null) {
        itemHolder.add(hintLabel);
        emptyItems = false;
    }
    for (G c : keys) {
        if (!itemMap.containsKey(c)) {
            continue;
        }
        Label l = new Label(c.toString().toUpperCase());
        l.setStyleName("group-heading");
        groupCaptions.add(l);
        addGroupHeading(itemHolder, l);
        if (c.toString().trim().isEmpty()) {
            l.getElement().getStyle().setVisibility(Visibility.HIDDEN);
        } else {
            emptyItems = false;
        }
        int ctr = itemMap.get(c).size();
        for (T item : itemMap.get(c)) {
            emptyItems = false;
            String sep = (--ctr != 0 && separatorText.length() != 1) ? separatorText : "";
            HasClickHandlers hch = createItem(item, false, charWidth, itemsHaveLinefeeds, l, sep);
            hch.addClickHandler(clickHandler);
            if (popdown) {
                hch.addClickHandler(popdownHider);
            }
            itemHolder.add((Widget) hch);
            if (ctr != 0 && sep.length() == 0) {
                addDefaultSeparator(itemHolder);
            }
        }
    }
    if (!itemHolder.iterator().hasNext() && emptyItemsText != null) {
        Label empty = new Label(emptyItemsText);
        empty.setStyleName("empty-items");
        itemHolder.add(empty);
    }
    if (recreateItemHolder) {
        scroller.setWidget(this.itemHolder);
    }
    afterUpdateItems(emptyItems);
}

From source file:ch.unifr.pai.twice.multipointer.client.widgets.NewMultiFocusTextBox.java

License:Apache License

@Override
protected void onAttach() {
    super.onAttach();
    if (getParent() == null || getParent() != panel) {
        HasWidgets toAppend = null;
        if (getParent() instanceof HasWidgets) {
            toAppend = ((HasWidgets) getParent());
        }// w w  w .  j  a va2  s.  c  o m
        mf.setWidth(this.getOffsetWidth() + "px");
        mf.setHeight(this.getOffsetHeight() + "px");
        GWT.log(this.getOffsetWidth() + "x" + this.getOffsetHeight());
        panel.add(this);
        panel.add(mf);
        if (toAppend != null)
            toAppend.add(getParent());
    }
}

From source file:com.eas.widgets.boxes.DecoratorBox.java

public DecoratorBox(HasValue<T> aDecorated) {
    super();/*from  w  w  w . j  a  va  2s . c  o  m*/
    decorated = aDecorated;
    if (decorated instanceof HasValue<?>) {
        decorated.addValueChangeHandler(new ValueChangeHandler<T>() {

            @Override
            public void onValueChange(ValueChangeEvent<T> event) {
                setClearButtonVisible(nullable && event.getValue() != null);
            }
        });
    }
    if (decorated instanceof HasDecorations) {
        HasWidgets container = ((HasDecorations) decorated).getContainer();
        ((Widget) container).addStyleName("decorator");
        container.add(selectButton);
        container.add(clearButton);
        initWidget((Widget) decorated);
    } else {
        CommonResources.INSTANCE.commons().ensureInjected();
        ((Widget) decorated).getElement().addClassName(CommonResources.INSTANCE.commons().borderSized());
        Style style = ((Widget) decorated).getElement().getStyle();
        style.setMargin(0, Style.Unit.PX);
        style.setPosition(Style.Position.ABSOLUTE);
        style.setDisplay(Style.Display.INLINE_BLOCK);
        style.setLeft(0, Style.Unit.PX);
        style.setTop(0, Style.Unit.PX);
        style.setHeight(100, Style.Unit.PCT);
        style.setWidth(100, Style.Unit.PCT);
        style.setOutlineStyle(Style.OutlineStyle.NONE);
        FlowPanel panel = new FlowPanel();
        panel.addStyleName("decorator");
        initWidget(panel);
        panel.add((Widget) decorated);
        panel.add(selectButton);
        panel.add(clearButton);
    }

    ((Widget) decorated).addStyleName("decorator-content");

    selectButton.getElement().addClassName("decorator-select");
    selectButton.getElement().getStyle().setDisplay(Style.Display.NONE);
    selectButton.getElement().getStyle().setHeight(100, Style.Unit.PCT);
    selectButton.getElement().getStyle().setPosition(Style.Position.RELATIVE);
    clearButton.getElement().addClassName("decorator-clear");
    clearButton.getElement().getStyle().setDisplay(Style.Display.NONE);
    clearButton.getElement().getStyle().setHeight(100, Style.Unit.PCT);
    clearButton.getElement().getStyle().setPosition(Style.Position.RELATIVE);

    selectButton.addDomHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            selectValue();
        }
    }, ClickEvent.getType());
    clearButton.addDomHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            clearValue();
            setFocus(true);
        }
    }, ClickEvent.getType());
    organizeButtonsContent();

    getElement().<XElement>cast().addResizingTransitionEnd(this);

    if (decorated instanceof HasValue<?>) {
        changeValueHandler = decorated.addValueChangeHandler(new ValueChangeHandler<T>() {

            @Override
            public void onValueChange(ValueChangeEvent<T> event) {
                fireValueChangeEvent();
            }
        });
    }

    if (decorated instanceof HasKeyDownHandlers) {
        keyDownHandler = ((HasKeyDownHandlers) decorated).addKeyDownHandler(new KeyDownHandler() {

            @Override
            public void onKeyDown(KeyDownEvent event) {
                KeyDownEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }
        });
    }
    if (decorated instanceof HasKeyUpHandlers) {
        keyUpHandler = ((HasKeyUpHandlers) decorated).addKeyUpHandler(new KeyUpHandler() {

            @Override
            public void onKeyUp(KeyUpEvent event) {
                KeyUpEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }
        });
    }
    if (decorated instanceof HasKeyPressHandlers) {
        keyPressHandler = ((HasKeyPressHandlers) decorated).addKeyPressHandler(new KeyPressHandler() {

            @Override
            public void onKeyPress(KeyPressEvent event) {
                KeyPressEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }
        });
    }
    if (decorated instanceof HasFocusHandlers) {
        focusHandler = ((HasFocusHandlers) decorated).addFocusHandler(new FocusHandler() {

            @Override
            public void onFocus(FocusEvent event) {
                FocusEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }

        });
    }
    if (decorated instanceof HasBlurHandlers) {
        blurHandler = ((HasBlurHandlers) decorated).addBlurHandler(new BlurHandler() {

            @Override
            public void onBlur(BlurEvent event) {
                BlurEvent.fireNativeEvent(event.getNativeEvent(), DecoratorBox.this);
            }

        });
    }

}

From source file:com.facebook.tsdb.tsdash.client.presenter.AutoreloadPresenter.java

License:Apache License

@Override
public void go(HasWidgets container, ApplicationState appState) {
    container.add((Widget) widget);
    selectPeriodOption(appState.reloadPeriod);
    setByState(appState);/*from  w ww  .j a v  a 2 s  .  c om*/
}

From source file:com.facebook.tsdb.tsdash.client.presenter.ErrorPresenter.java

License:Apache License

@Override
public void go(HasWidgets container, ApplicationState appState) {
    container.add((Widget) widget);
}

From source file:com.facebook.tsdb.tsdash.client.presenter.GraphPresenter.java

License:Apache License

@Override
public void go(HasWidgets container, final ApplicationState appState) {
    Widget w = (Widget) widget;/*from  w ww .  j  a  va 2s  . co  m*/
    resetDimensions(appState);
    container.add(w);
    plot = appState.interactive ? interactivePlot : imagePlot;
    imagePlot.setOptions(appState.surface, appState.palette);
    if (!initialized) {
        w.addAttachHandler(new AttachEvent.Handler() {
            @Override
            public void onAttachOrDetach(AttachEvent event) {
                if (event.isAttached()) {
                    renderPlot(appState);
                    initialized = true;
                }
            }
        });
    }
}

From source file:com.facebook.tsdb.tsdash.client.presenter.LogPresenter.java

License:Apache License

@Override
public void go(final HasWidgets container, final ApplicationState appState) {
    container.clear();//from w  w w  . j a  v  a2s . c  o m
    container.add((Widget) widget);
}