@Override
  public void onDeleteAttribute(List<JsArray<AttributeDto>> selectedItems) {
    VariableDto dto = getVariableDto();

    JsArray<AttributeDto> filteredAttributes = JsArrays.create().cast();
    List<AttributeDto> allAttributes = JsArrays.toList(dto.getAttributesArray());

    for (AttributeDto attribute : allAttributes) {
      boolean keep = true;
      for (JsArray<AttributeDto> toRemove : selectedItems) {
        if (attribute.getName().equals(toRemove.get(0).getName())
            && attribute.getNamespace().equals(toRemove.get(0).getNamespace())) {
          keep = false;
          break;
        }
      }

      if (keep) {
        filteredAttributes.push(attribute);
      }
    }

    dto.setAttributesArray(filteredAttributes);

    UriBuilder uriBuilder =
        table.hasViewLink()
            ? UriBuilders.DATASOURCE_VIEW_VARIABLE.create()
            : UriBuilders.DATASOURCE_TABLE_VARIABLE.create();

    ResourceRequestBuilderFactory.newBuilder() //
        .forResource(
            uriBuilder.build(table.getDatasourceName(), table.getName(), variable.getName())) //
        .withResourceBody(VariableDto.stringify(dto)) //
        .withCallback(
            SC_OK,
            new ResponseCodeCallback() {
              @Override
              public void onResponseCode(Request request, Response response) {
                fireEvent(new VariableRefreshEvent());
              }
            }) //
        .withCallback(SC_BAD_REQUEST, new ErrorResponseCallback(getView().asWidget())) //
        .put()
        .send();
  }
 @Override
 public void onEditAttributes(final List<JsArray<AttributeDto>> selectedItems) {
   if (selectedItems == null || selectedItems.isEmpty()) return;
   boolean sameNamespace = true;
   String namespace = null;
   for (JsArray<AttributeDto> selectedArray : selectedItems) {
     for (AttributeDto attr : JsArrays.toIterable(selectedArray)) {
       if (namespace == null) {
         namespace = attr.hasNamespace() ? attr.getNamespace() : null;
       } else {
         sameNamespace = attr.hasNamespace() ? attr.getNamespace().equals(namespace) : true;
       }
     }
   }
   if (!sameNamespace || namespace == null) {
     showEditCustomAttributes(selectedItems);
   } else {
     final String ns = namespace;
     ResourceRequestBuilderFactory.<TaxonomiesDto>newBuilder()
         .forResource(UriBuilders.SYSTEM_CONF_TAXONOMIES_SUMMARIES.create().build())
         .get()
         .withCallback(
             new ResourceCallback<TaxonomiesDto>() {
               @Override
               public void onResource(Response response, TaxonomiesDto resource) {
                 for (TaxonomiesDto.TaxonomySummaryDto summary :
                     JsArrays.toIterable(resource.getSummariesArray())) {
                   if (summary.getName().equals(ns)) {
                     showEditTaxonomyAttributes(selectedItems);
                     return;
                   }
                 }
                 showEditCustomAttributes(selectedItems);
               }
             })
         .send();
   }
 }
示例#3
0
 @Override
 protected String getAttributeName(AttributeDto object) {
   return object.getName();
 }