Exemplo n.º 1
0
  public ComboBox(String cssSuffix) {

    cellList =
        new CellList<String>(
            new TextCell() {
              @Override
              public void render(Context context, String data, SafeHtmlBuilder sb) {
                String cssName =
                    (context.getIndex() % 2 > 0)
                        ? "combobox-item combobox-item-odd"
                        : "combobox-item";

                if (data.equals(currentValue.getText())) cssName += " combobox-item-selected";

                sb.append(TEMPLATE.item(cssName, data));
              }
            });

    final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();
    cellList.setSelectionModel(selectionModel);

    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          public void onSelectionChange(SelectionChangeEvent event) {
            String selectedValue = selectionModel.getSelectedObject();

            currentValue.setHTML(selectedValue);
            popup.hide();

            onSelection(selectedValue);
          }
        });

    final String panelId = "popup_" + HTMLPanel.createUniqueId();
    popup =
        new PopupPanel(true, true) {

          @Override
          protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            if (Event.ONKEYUP == event.getTypeInt()) {
              if (event.getNativeEvent().getKeyCode() == ESCAPE) {
                // Dismiss when escape is pressed
                popup.hide();
              }
            }
          }

          public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
          }
        };

    popup.getElement().setId(panelId);

    popup.setStyleName("default-popup");

    popup.setWidget(cellList);

    currentValue = new HTML("&nbsp;");
    currentValue.setStyleName("combobox-value" + cssSuffix);

    header = new HorizontalPanel();
    header.setStyleName("combobox" + cssSuffix);
    header.add(currentValue);

    Image img = new Image(Icons.INSTANCE.comboPicker());
    header.add(img);

    currentValue.getElement().getParentElement().setAttribute("width", "100%");

    img.getParent().getElement().setAttribute("width", "18");

    header.getElement().setAttribute("width", "100%");
    header.getElement().setAttribute("cellspacing", "0");
    header.getElement().setAttribute("cellpadding", "0");
    header.getElement().setAttribute("border", "0");

    ClickHandler clickHandler =
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent clickEvent) {
            openPanel();
          }
        };

    currentValue.addClickHandler(clickHandler);
    img.addClickHandler(clickHandler);
  }
Exemplo n.º 2
0
 /**
  * Create and return a SelectedItem populated with the option
  *
  * @param option - an Option bean that will be down cast to a FancyOption
  * @return the SelectedItem to be pushed
  */
 protected SelectedItem createSelectedItem(Option option) {
   return new FancySelectedItem(HTMLPanel.createUniqueId(), (FancyOption) option);
 }
Exemplo n.º 3
0
  public Widget asWidget() {

    if (null == cellTable.getSelectionModel())
      cellTable.setSelectionModel(new SingleSelectionModel<T>());

    cellTable
        .getSelectionModel()
        .addSelectionChangeHandler(
            new SelectionChangeEvent.Handler() {
              @Override
              public void onSelectionChange(SelectionChangeEvent selectionChangeEvent) {
                T selection =
                    ((SingleSelectionModel<T>) cellTable.getSelectionModel()).getSelectedObject();
                String displayValue = renderer.render(selection);
                currentDisplayedValue.setText(displayValue);
              }
            });

    final String panelId = "popup_" + HTMLPanel.createUniqueId();
    popup =
        new PopupPanel(true, true) {

          @Override
          protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
            if (Event.ONKEYUP == event.getTypeInt()) {
              if (event.getNativeEvent().getKeyCode() == ESCAPE) {
                // Dismiss when escape is pressed
                popup.hide();
              }
            }
          }

          public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
          }
        };

    popup.getElement().setId(panelId);

    popup.setStyleName("default-popup");

    /*popup.addCloseHandler(new CloseHandler<PopupPanel>() {
        public void onClose(CloseEvent<PopupPanel> event) {

        }
    });*/

    VerticalPanel layout = new VerticalPanel();
    layout.setStyleName("fill-layout-width");
    layout.addStyleName("tablepicker-popup");

    if (description != null) layout.add(new Label(description));

    layout.add(cellTable);

    DefaultPager pager = new DefaultPager();
    pager.setDisplay(cellTable);
    layout.add(pager);

    popup.setWidget(layout);

    currentDisplayedValue = new HTML("&nbsp;");
    currentDisplayedValue.setStyleName("table-picker-value");

    header = new HorizontalPanel();
    header.setStyleName("table-picker");
    header.add(currentDisplayedValue);

    Image img = new Image(ConsoleIcons.INSTANCE.tablePicker());
    header.add(img);

    currentDisplayedValue.getElement().getParentElement().setAttribute("width", "100%");

    img.getParent().getElement().setAttribute("width", "18");

    header.getElement().setAttribute("width", "100%");
    header.getElement().setAttribute("cellspacing", "0");
    header.getElement().setAttribute("cellpadding", "0");
    header.getElement().setAttribute("border", "0");

    ClickHandler clickHandler =
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent clickEvent) {
            openPanel();
          }
        };

    currentDisplayedValue.addClickHandler(clickHandler);
    img.addClickHandler(clickHandler);

    return header;
  }