@Override
  public void onClick(ClickEvent event) {
    if (event.getSource() instanceof VCheckBox) {
      VCheckBox source = (VCheckBox) event.getSource();
      if (!source.isEnabled()) {
        // Click events on the text are received even though the
        // checkbox is disabled
        return;
      }

      Boolean selected = source.getValue();

      JsonObject item = optionsToItems.get(source);
      assert item != null;

      new ArrayList<>(selectionChangeListeners)
          .forEach(listener -> listener.accept(item, selected));
    }
  }
  private void updateItem(VCheckBox widget, JsonObject item, boolean requireInitialization) {
    String itemHtml = item.getString(ListingJsonConstants.JSONKEY_ITEM_VALUE);
    if (!isHtmlContentAllowed()) {
      itemHtml = WidgetUtil.escapeHTML(itemHtml);
    }

    String iconUrl = item.getString(ListingJsonConstants.JSONKEY_ITEM_ICON);
    if (iconUrl != null && iconUrl.length() != 0) {
      Icon icon = client.getIcon(iconUrl);
      itemHtml = icon.getElement().getString() + itemHtml;
    }

    widget.setHTML(itemHtml);
    widget.setValue(item.getBoolean(ListingJsonConstants.JSONKEY_ITEM_SELECTED));
    setOptionEnabled(widget, item);

    if (requireInitialization) {
      widget.addStyleName(CLASSNAME_OPTION);
      widget.addClickHandler(this);
      getWidget().add(widget);
    }
    optionsToItems.put(widget, item);
  }
 /**
  * Updates the checkbox's enabled state according to the widget's enabled, read only and the
  * item's enabled.
  *
  * @param checkBox the checkbox to update
  * @param item the item for the checkbox
  */
 protected void setOptionEnabled(VCheckBox checkBox, JsonObject item) {
   boolean optionEnabled = !item.getBoolean(ListingJsonConstants.JSONKEY_ITEM_DISABLED);
   boolean enabled = optionEnabled && !isReadonly() && isEnabled();
   checkBox.setEnabled(enabled);
 }
Example #4
0
  public RElement createRGGElement(Element element, RGG rggInstance) {
    if (element.getNodeType() != Element.ELEMENT_NODE) {
      throw new IllegalArgumentException("elements node type must be ELEMENT_NODE");
    }

    RCheckBox rcheckbox = new RCheckBox();
    VCheckBox vcheckbox = new VCheckBox();

    /**
     * **************** initialize and set attributes values *************************************
     */
    String var = element.getAttribute(RGG.getConfiguration().getString("VAR"));
    String label = element.getAttribute(RGG.getConfiguration().getString("LABEL"));
    String colspan = element.getAttribute(RGG.getConfiguration().getString("COLUMN-SPAN"));
    String selected = element.getAttribute(RGG.getConfiguration().getString("SELECTED"));
    String returnValueBySelected =
        element.getAttribute(RGG.getConfiguration().getString("RETURN-VALUE-BY-SELECTED"));
    String returnValueByNotSelected =
        element.getAttribute(RGG.getConfiguration().getString("RETURN-VALUE-BY-NOTSELECTED"));
    String labelPosition = element.getAttribute(RGG.getConfiguration().getString("LABELPOSITION"));
    String id = element.getAttribute(RGG.getConfiguration().getString("ID"));
    String enabled = element.getAttribute(RGG.getConfiguration().getString("ENABLED"));
    /**
     * ********************************************************************************************
     */
    if (StringUtils.isNotBlank(var)) {
      rcheckbox.setVar(var);
    }

    if (StringUtils.isNotBlank(label)) {
      vcheckbox.setLabelText(label);
    }

    if (StringUtils.isNotBlank(colspan) && StringUtils.isNumeric(colspan)) {
      vcheckbox.setColumnSpan(Integer.parseInt(colspan));
    }

    if (StringUtils.isNotBlank(selected)) {
      if (StringUtils.equalsIgnoreCase("TRUE", selected)
          || StringUtils.equalsIgnoreCase("T", selected)) {
        vcheckbox.setSelected(true);
      }
    }

    if (StringUtils.isNotBlank(returnValueBySelected)) {
      rcheckbox.setReturnValueBySelected(returnValueBySelected);
    }

    if (StringUtils.isNotBlank(returnValueByNotSelected)) {
      rcheckbox.setReturnValueByNotSelected(returnValueByNotSelected);
    }

    if (StringUtils.isNotBlank(labelPosition)) {
      if (StringUtils.equalsIgnoreCase(labelPosition, RGG.getConfiguration().getString("LEFT"))) {
        vcheckbox.setHorizontalLabelPosition(javax.swing.SwingConstants.LEFT);
      } else if (StringUtils.equalsIgnoreCase(
          labelPosition, RGG.getConfiguration().getString("RIGHT"))) {
        vcheckbox.setHorizontalLabelPosition(javax.swing.SwingConstants.RIGHT);
      } else {
        throw new IllegalArgumentException("labelpositon takes only \"left\" or \"right\"!");
      }
    }
    if (StringUtils.isNotBlank(id)) {
      rggInstance.addObject(id, vcheckbox);
    }

    if (StringUtils.isNotBlank(enabled)) {
      if (util.match("/(\\w+)\\./", enabled)) {
        String sourceid = util.group(1);
        enabled = util.substitute("s/" + sourceid + "\\.//g", enabled);
        AutoBinding<Object, Object, Object, Object> binding =
            Bindings.createAutoBinding(
                AutoBinding.UpdateStrategy.READ, // one-way binding
                rggInstance.getObject(sourceid), // source of value
                ELProperty.create(enabled), // the property to get
                vcheckbox, // the "backing bean"
                BeanProperty.create("enabled") // property to set
                );
        binding.bind();
      }
    }

    rcheckbox.setCheckBox(vcheckbox);

    return rcheckbox;
  }