Ejemplo n.º 1
0
  public void getAttributeDescriptions(
      ModelNode resourceAddress, final FormAdapter form, final AsyncCallback<HTML> callback) {

    final ModelNode operation = new ModelNode();
    operation.get(OP).set(READ_RESOURCE_DESCRIPTION_OPERATION);
    operation.get(ADDRESS).set(resourceAddress);
    operation.get(RECURSIVE).set(true);
    operation.get(LOCALE).set(getLocale());

    // build field name list

    List<String> formItemNames = form.getFormItemNames();
    BeanMetaData beanMetaData = propertyMetaData.getBeanMetaData(form.getConversionType());
    List<PropertyBinding> bindings = beanMetaData.getProperties();
    final List<String> fieldNames = new ArrayList<String>();

    for (PropertyBinding binding : bindings) {
      if (!binding.isKey() && formItemNames.contains(binding.getJavaName())) {
        String[] splitDetypedNames = binding.getDetypedName().split("/");
        // last one in the path is the attribute name
        fieldNames.add(splitDetypedNames[splitDetypedNames.length - 1]);
      }
    }

    dispatcher.execute(
        new DMRAction(operation),
        new AsyncCallback<DMRResponse>() {
          @Override
          public void onSuccess(DMRResponse result) {
            ModelNode response = result.get();

            if (response.isFailure()) {
              Log.debug(response.toString());
              onFailure(new Exception(response.getFailureDescription()));
            } else {

              final SafeHtmlBuilder html = new SafeHtmlBuilder();
              html.appendHtmlConstant("<table class='help-attribute-descriptions'>");

              ModelNode payload = response.get(RESULT);

              ModelNode descriptionModel = null;
              if (ModelType.LIST.equals(payload.getType()))
                descriptionModel = payload.asList().get(0);
              else descriptionModel = payload;

              matchSubElements(descriptionModel, fieldNames, html);

              html.appendHtmlConstant("</table>");
              callback.onSuccess(new HTML(html.toSafeHtml()));
            }
          }

          @Override
          public void onFailure(Throwable caught) {
            callback.onFailure(caught);
          }
        });
  }
Ejemplo n.º 2
0
  @Override
  public void edit(T bean) {
    for (FormAdapter<T> form : forms.values()) {
      form.edit(bean);
    }

    AutoBean autoBean = AutoBeanUtils.getAutoBean(bean);
    Map<String, Object> props = AutoBeanUtils.getAllProperties(autoBean);
    String triggerString = (String) props.get(this.triggerProperty);
    if (triggerString == null) triggerString = defaultForm;
    showWidget(triggerString);

    notifyListeners(bean);
  }
Ejemplo n.º 3
0
  @Override
  public void bind(CellTable<T> table) {
    for (FormAdapter<T> form : forms.values()) {
      form.bind(table);
    }

    SingleSelectionModel<T> selectionModel = (SingleSelectionModel<T>) table.getSelectionModel();
    final SingleSelectionModel<T> finalSelectionModel = selectionModel;

    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            edit(finalSelectionModel.getSelectedObject());
          }
        });
  }
Ejemplo n.º 4
0
 @Override
 public void setEnabled(boolean isEnabled) {
   for (FormAdapter form : forms.values()) {
     form.setEnabled(isEnabled);
   }
 }
Ejemplo n.º 5
0
 @Override
 public void cancel() {
   for (FormAdapter<T> form : forms.values()) {
     form.cancel();
   }
 }