/** Called, when operation finishes successfully. */
 public void onFinished(JavaScriptObject jso) {
   clearTable();
   for (Attribute a : JsonUtils.<Attribute>jsoAsList(jso)) {
     if (!a.getDefinition().equals("core")) {
       addToTable(a);
     }
   }
   sortTable();
   loaderImage.loadingFinished();
   session.getUiElements().setLogText("Resource required attributes loaded: " + list.size());
   events.onFinished(jso);
 }
 /**
  * Return selected items from list
  *
  * @return return list of checked items
  */
 public ArrayList<Attribute> getTableSelectedList() {
   return JsonUtils.setToList(selectionModel.getSelectedSet());
 }
  /**
   * Returns empty table widget with attributes
   *
   * @return table widget
   */
  public CellTable<Attribute> getEmptyTable() {

    // Table data provider.
    dataProvider = new ListDataProvider<Attribute>(list);

    // Cell table
    table = new PerunTable<Attribute>(list);
    table.removeRowCountChangeHandler(); // remove row count change handler

    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);

    // Sorting
    ListHandler<Attribute> columnSortHandler = new ListHandler<Attribute>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);

    // table selection
    table.setSelectionModel(
        selectionModel, DefaultSelectionEventManager.<Attribute>createCheckboxManager());

    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);

    // because of tab index
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);

    // checkbox column
    if (checkable) {

      // checkbox column column
      Column<Attribute, Attribute> checkBoxColumn =
          new Column<Attribute, Attribute>(new PerunCheckboxCell<Attribute>(true, false, false)) {
            @Override
            public Attribute getValue(Attribute object) {
              // Get the value from the selection model.
              GeneralObject go = object.cast();
              go.setChecked(selectionModel.isSelected(object));
              return go.cast();
            }
          };

      // updates the columns size
      table.setColumnWidth(checkBoxColumn, 40.0, Unit.PX);

      // Add the columns

      // Checkbox column header
      CheckboxCell cb = new CheckboxCell();
      Header<Boolean> checkBoxHeader =
          new Header<Boolean>(cb) {
            public Boolean getValue() {
              return false; // return true to see a checked checkbox.
            }
          };
      checkBoxHeader.setUpdater(
          new ValueUpdater<Boolean>() {
            public void update(Boolean value) {
              // sets selected to all, if value = true, unselect otherwise
              for (Attribute obj : list) {
                if (obj.isWritable()) {
                  selectionModel.setSelected(obj, value);
                }
              }
            }
          });

      table.addColumn(checkBoxColumn, checkBoxHeader);
    }

    // Create ID column.
    table.addIdColumn("Attr ID", null, 90);

    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());

    // Value column
    Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell());
    valueColumn.setFieldUpdater(
        new FieldUpdater<Attribute, Attribute>() {
          public void update(int index, Attribute object, Attribute value) {
            object = value;
            selectionModel.setSelected(object, object.isAttributeValid());
          }
        });

    // Description column
    Column<Attribute, Attribute> descriptionColumn =
        JsonUtils.addColumn(new PerunAttributeDescriptionCell());

    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(
        nameColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_NAME));

    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(
        descriptionColumn,
        new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_DESCRIPTION));

    // Add sorting
    this.table.addColumnSortHandler(columnSortHandler);

    // updates the columns size
    this.table.setColumnWidth(nameColumn, 200.0, Unit.PX);

    // Add the columns.
    this.table.addColumn(nameColumn, "Name");
    this.table.addColumn(valueColumn, "Value");
    this.table.addColumn(descriptionColumn, "Description");

    return this.table;
  }