/**
   * 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;
  }
  /**
   * Returns table with publications
   *
   * @return table
   */
  public CellTable<Publication> getEmptyTable() {

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

    // Cell table
    table = new PerunTable<Publication>(list);
    table.removeRowCountChangeHandler();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);

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

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

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

    // set empty content & loader
    table.setEmptyTableWidget(
        loaderImage.prepareToSearch(
            "Please select external pub. system and year range to search for publications for import."));

    // show checkbox column
    if (this.checkable) {
      table.addCheckBoxColumn();
    }

    /*
    // CATEGORY COLUMN
    ArrayList<String> categories = new ArrayList<String>();
    categories.add("Bodované v RIVu");
    categories.add("Nebodované v RIVu");
    categories.add("Příspěvek do ročenky");
    categories.add("Výjimečné výsledky");
    categories.add("Jiné");

    Column<Publication, String> categoryColumn = new Column<Publication, String>(new SelectionCell(categories)){
    	@Override
    	public String getValue(Publication object) {
    		// category ID as string, 0 if not set
    		int id = object.getCategoryId();
    		if (id == 0) {
    			// set default == 21/Bodované v RIVu to object
    			object.setCategoryId(21);
    		}
    		if (id == 21) {
    			return "Bodované v RIVu";
    		} else if (id == 22) {
    			return "Nebodované v RIVu";
    		} else if (id == 23) {
    			return "Výjimečné výsledky";
    		} else if (id == 24) {
    			return "Příspěvek do ročenky";
    		} else if (id == 25) {
    			return "Jiné";
    		} else {
    			return String.valueOf(id); // return ID if no match
    		}
    	}
    };
    categoryColumn.setFieldUpdater(new FieldUpdater<Publication, String>() {
    	public void update(int index, Publication object, String value) {

    		int id = 0;
    		if (value.equalsIgnoreCase("Bodované v RIVu")) {
    			id = 21;
    		} else if (value.equalsIgnoreCase("Nebodované v RIVu")) {
    			id = 22;
    		} else if (value.equalsIgnoreCase("Příspěvek do ročenky")) {
    			id = 24;
    		} else if (value.equalsIgnoreCase("Výjimečné výsledky")) {
    			id = 23;
    		} else if (value.equalsIgnoreCase("Jiné")) {
    			id = 25;
    		}
    		object.setCategoryId(id);
    		selectionModel.setSelected(object, true);

    	}
    });
    table.addColumn(categoryColumn, "Category");

    // NOT USEFULL => DISABLED
    // EXTERNAL ID
    TextColumn<Publication> externalIdColumn = new TextColumn<Publication>() {
    	public String getValue(Publication object) {
    		return String.valueOf(object.getExternalId());
    	};
    };
    externalIdColumn.setSortable(true);
    columnSortHandler.setComparator(externalIdColumn, new PublicationComparator(PublicationComparator.Column.EXTERNAL_ID));
    table.addColumn(externalIdColumn, "External Id");
     */

    // TITLE COLUMN
    TextColumn<Publication> titleColumn =
        new TextColumn<Publication>() {
          public String getValue(Publication object) {
            return object.getTitle();
          };
        };
    titleColumn.setSortable(true);
    columnSortHandler.setComparator(
        titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
    table.addColumn(titleColumn, "Title");

    // AUTHORS COLUMN
    TextColumn<Publication> authorColumn =
        new TextColumn<Publication>() {
          public String getValue(Publication object) {
            return object.getAuthorsFormatted();
          };
        };
    authorColumn.setSortable(true);
    columnSortHandler.setComparator(
        authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
    table.addColumn(authorColumn, "Authors");

    // YEAR COLUMN
    TextColumn<Publication> yearColumn =
        new TextColumn<Publication>() {
          public String getValue(Publication object) {
            return String.valueOf(object.getYear());
          };
        };
    yearColumn.setSortable(true);
    columnSortHandler.setComparator(
        yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
    table.addColumn(yearColumn, "Year");

    // ISBN COLUMN
    TextColumn<Publication> isbnColumn =
        new TextColumn<Publication>() {
          public String getValue(Publication object) {
            return object.getIsbn();
          };
        };
    isbnColumn.setSortable(true);
    columnSortHandler.setComparator(
        isbnColumn, new PublicationComparator(PublicationComparator.Column.ISBN));
    table.addColumn(isbnColumn, "ISBN");

    // CITE COLUMN
    Column<Publication, String> citaceColumn =
        JsonUtils.addColumn(
            new JsonUtils.GetValue<Publication, String>() {
              public String getValue(Publication object) {
                return "Cite";
              }
            },
            new FieldUpdater<Publication, String>() {
              public void update(int index, Publication object, String value) {
                SimplePanel sp = new SimplePanel();
                sp.add(new HTML(object.getMain()));
                Confirm cf = new Confirm("Cite publication", sp, true);
                cf.show();
              };
            });

    table.addColumn(citaceColumn, "Cite");

    return table;
  }
  /**
   * Return table definition
   *
   * @return table widget
   */
  public CellTable<TaskResult> getEmptyTable() {

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

    // Cell table
    table = new PerunTable<TaskResult>(list);
    table.removeRowCountChangeHandler();

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

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

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

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

    table.addIdColumn("Result Id", null, 85);

    // destination column
    TextColumn<TaskResult> destinationColumn =
        new TextColumn<TaskResult>() {
          @Override
          public String getValue(TaskResult object) {
            return String.valueOf(object.getDestination().getDestination());
          }
        };

    destinationColumn.setSortable(true);
    columnSortHandler.setComparator(
        destinationColumn,
        new Comparator<TaskResult>() {
          public int compare(TaskResult o1, TaskResult o2) {
            return o1.getDestination()
                .getDestination()
                .compareToIgnoreCase((o2.getDestination().getDestination()));
          }
        });

    // Type column
    TextColumn<TaskResult> typeColumn =
        new TextColumn<TaskResult>() {
          @Override
          public String getValue(TaskResult object) {
            return String.valueOf(object.getDestination().getType());
          }
        };

    typeColumn.setSortable(true);
    columnSortHandler.setComparator(
        typeColumn,
        new Comparator<TaskResult>() {
          public int compare(TaskResult o1, TaskResult o2) {
            return o1.getDestination().getType().compareToIgnoreCase(o2.getDestination().getType());
          }
        });

    TextColumn<TaskResult> servColumn =
        new TextColumn<TaskResult>() {
          @Override
          public String getValue(TaskResult taskResult) {
            return taskResult.getService().getName();
          }
        };
    servColumn.setSortable(true);
    columnSortHandler.setComparator(
        servColumn,
        new Comparator<TaskResult>() {
          public int compare(TaskResult o1, TaskResult o2) {
            return o1.getService().getName().compareToIgnoreCase(o2.getService().getName());
          }
        });

    // status column
    TextColumn<TaskResult> statusColumn =
        new TextColumn<TaskResult>() {
          @Override
          public String getValue(TaskResult object) {
            return String.valueOf(object.getStatus());
          }
        };

    statusColumn.setSortable(true);
    columnSortHandler.setComparator(
        statusColumn,
        new Comparator<TaskResult>() {
          public int compare(TaskResult o1, TaskResult o2) {
            return o1.getStatus().compareToIgnoreCase(o2.getStatus());
          }
        });

    // time column
    TextColumn<TaskResult> timeColumn =
        new TextColumn<TaskResult>() {
          @Override
          public String getValue(TaskResult object) {
            return object.getTimestamp();
          }
        };

    timeColumn.setSortable(true);
    columnSortHandler.setComparator(
        timeColumn,
        new Comparator<TaskResult>() {
          public int compare(TaskResult o1, TaskResult o2) {
            return o1.getTimestamp().compareToIgnoreCase(o2.getTimestamp());
          }
        });

    // returnCode column
    TextColumn<TaskResult> returnCodeColumn =
        new TextColumn<TaskResult>() {
          @Override
          public String getValue(TaskResult object) {
            return String.valueOf(object.getReturnCode());
          }
        };

    // standardMessageCode column
    TextColumn<TaskResult> standardMessageColumn =
        new TextColumn<TaskResult>() {
          @Override
          public void render(Context context, TaskResult object, SafeHtmlBuilder sb) {
            if (object != null) {
              sb.appendEscapedLines(object.getStandardMessage());
            }
          }

          @Override
          public String getValue(TaskResult object) {
            return String.valueOf(object.getStandardMessage());
          }
        };

    // errorMessageCode column
    TextColumn<TaskResult> errorMessageColumn =
        new TextColumn<TaskResult>() {
          @Override
          public void render(Context context, TaskResult object, SafeHtmlBuilder sb) {
            if (object != null) {
              sb.appendEscapedLines(object.getErrorMessage());
            }
          }

          @Override
          public String getValue(TaskResult object) {
            return String.valueOf(object.getErrorMessage());
          }
        };

    // Add the other columns.
    table.addColumn(destinationColumn, "Destination");
    table.addColumn(typeColumn, "Type");
    table.addColumn(servColumn, "Service");
    table.addColumn(statusColumn, "Status");
    table.addColumn(timeColumn, "Time");
    table.addColumn(returnCodeColumn, "Return code");
    table.addColumn(standardMessageColumn, "Standard Message");
    table.addColumn(errorMessageColumn, "Error Message");

    // set row styles based on task state
    table.setRowStyles(
        new RowStyles<TaskResult>() {
          public String getStyleNames(TaskResult row, int rowIndex) {

            if (row.getStatus().equalsIgnoreCase("DONE")) {
              return "rowgreen";
            } else if (row.getStatus().equalsIgnoreCase("DENIED")) {
              return "rowyellow";
            } else if (row.getStatus().equalsIgnoreCase("FATAL_ERROR")) {
              return "rowred";
            } else if (row.getStatus().equalsIgnoreCase("ERROR")) {
              return "roworange";
            }
            return "";
          }
        });

    return table;
  }