Ejemplo n.º 1
0
  /**
   * Return table widget with external sources
   *
   * @return table widget containing ext sources
   */
  public CellTable<ExtSource> getTable() {

    // retrieve data
    retrieveData();

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

    // Cell table
    table = new PerunTable<ExtSource>(list);

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

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

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

    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No external sources found in Perun.");

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

    // ID column
    table.addIdColumn("Ext. source ID", null);

    // Name column
    table.addNameColumn(null);

    // Type column
    TextColumn<ExtSource> typeColumn =
        new TextColumn<ExtSource>() {
          @Override
          public String getValue(ExtSource extSource) {
            return String.valueOf(renameContent(extSource.getType()));
          }
        };
    table.addColumn(typeColumn, "Type");

    // return cellTable
    return table;
  }
  /**
   * 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;
  }
Ejemplo n.º 3
0
  /**
   * Returns empty table
   *
   * @return table widget
   */
  public CellTable<Destination> getEmptyTable() {

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

    // Cell table
    table = new PerunTable<Destination>(list);

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

    if (showFac) {
      loaderImage.setEmptyResultMessage("Service has no destination.");
    } else {
      loaderImage.setEmptyResultMessage(
          "Facility has no services destinations. Service configuration can't be propagated.");
    }

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

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

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

    if (this.checkable) {
      table.addCheckBoxColumn();
    }

    // add id column
    table.addIdColumn("Destination ID", null);

    // DESTINATION COLUMN
    TextColumn<Destination> destinationColumn =
        new TextColumn<Destination>() {
          public String getValue(Destination object) {
            return object.getDestination();
          }
        };

    // TYPE COLUMN
    TextColumn<Destination> typeColumn =
        new TextColumn<Destination>() {
          public String getValue(Destination object) {
            return object.getType().toUpperCase();
          }
        };

    // SERVICE COLUMN
    TextColumn<Destination> serviceColumn =
        new TextColumn<Destination>() {
          public String getValue(Destination object) {
            return object.getService().getName();
          }
        };

    // FACILITY COLUMN
    TextColumn<Destination> facilityColumn =
        new TextColumn<Destination>() {
          public String getValue(Destination object) {
            return object.getFacility().getName();
          }
        };

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

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

    serviceColumn.setSortable(true);
    columnSortHandler.setComparator(
        serviceColumn,
        new Comparator<Destination>() {
          public int compare(Destination o1, Destination o2) {
            return o1.getService().getName().compareToIgnoreCase(o2.getService().getName());
          }
        });

    facilityColumn.setSortable(true);
    columnSortHandler.setComparator(
        facilityColumn,
        new Comparator<Destination>() {
          public int compare(Destination o1, Destination o2) {
            return o1.getFacility().getName().compareToIgnoreCase(o2.getFacility().getName());
          }
        });

    // updates the columns size
    table.setColumnWidth(serviceColumn, 250.0, Unit.PX);
    table.setColumnWidth(facilityColumn, 250.0, Unit.PX);

    // Add the columns.

    if (showServ) {
      table.addColumn(serviceColumn, "Service");
    }
    if (showFac) {
      table.addColumn(facilityColumn, "Facility");
    }

    table.addColumn(destinationColumn, "Destination");
    table.addColumn(typeColumn, "Type");

    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;
  }
Ejemplo n.º 5
0
  /**
   * Return table with tasks
   *
   * @return table widget
   */
  public CellTable<Task> getEmptyTable() {

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

    // Cell table
    table = new PerunTable<Task>(list);

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

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

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

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

    // checkbox column column
    table.addCheckBoxColumn();

    table.addIdColumn("Task Id", tableFieldUpdater);

    // Service column
    Column<Task, String> serviceColumn =
        JsonUtils.addColumn(
            new JsonUtils.GetValue<Task, String>() {
              public String getValue(Task task) {
                return String.valueOf(task.getExecService().getService().getName());
              }
            },
            tableFieldUpdater);

    // Service Type column
    Column<Task, String> serviceTypeColumn =
        JsonUtils.addColumn(
            new JsonUtils.GetValue<Task, String>() {
              public String getValue(Task task) {
                return String.valueOf(task.getExecService().getType());
              }
            },
            tableFieldUpdater);

    // status column
    Column<Task, String> statusColumn =
        JsonUtils.addColumn(
            new JsonUtils.GetValue<Task, String>() {
              public String getValue(Task task) {
                return String.valueOf(task.getStatus());
              }
            },
            tableFieldUpdater);

    // start COLUMN
    TextColumn<Task> startTimeColumn =
        new TextColumn<Task>() {
          public String getValue(Task result) {
            return result.getStartTime();
          }
        };

    // end COLUMN
    TextColumn<Task> endTimeColumn =
        new TextColumn<Task>() {
          public String getValue(Task result) {
            return result.getEndTime();
          }
        };

    // schedule COLUMN
    TextColumn<Task> scheduleColumn =
        new TextColumn<Task>() {
          public String getValue(Task result) {
            return result.getSchedule();
          }
        };

    // Add the columns.
    table.addColumn(serviceColumn, "Service");
    table.addColumn(serviceTypeColumn, "Type");
    table.addColumn(statusColumn, "Status");
    table.addColumn(scheduleColumn, "Scheduled");
    table.addColumn(startTimeColumn, "Started");
    table.addColumn(endTimeColumn, "Ended");

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

            if (row.getStatus().equalsIgnoreCase("NONE")) {
              return "rowdarkgreen";
            } else if (row.getStatus().equalsIgnoreCase("DONE")) {
              return "rowgreen";
            } else if (row.getStatus().equalsIgnoreCase("PROCESSING")) {
              return "rowyellow";
            } else if (row.getStatus().equalsIgnoreCase("ERROR")) {
              return "rowred";
            }
            return "";
          }
        });

    return table;
  }