Search in sources :

Example 6 with PerunCheckboxCell

use of cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell in project perun by CESNET.

the class GetRequiredAttributes method getEmptyTable.

/**
 * 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);
    // remove row count change handler
    table.removeRowCountChangeHandler();
    // 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
    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 true to see a checked checkbox.
            return false;
        }
    };
    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("Attribute ID");
    // Name column
    Column<Attribute, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            return attribute.getFriendlyName();
        }
    }, this.tableFieldUpdater);
    // Create ENTITY column
    Column<Attribute, String> entityColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute g) {
            return g.getEntity();
        }
    }, this.tableFieldUpdater);
    // Create def type column
    Column<Attribute, String> defTypeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute g) {
            return g.getDefinition();
        }
    }, this.tableFieldUpdater);
    // Create type column.
    Column<Attribute, String> typeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            return renameContent(attribute.getType());
        }
    }, this.tableFieldUpdater);
    // Create value column.
    Column<Attribute, String> valueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            if (attribute.getValue() == null)
                return "";
            return attribute.getValue();
        }
    }, new FieldUpdater<Attribute, String>() {

        public void update(int index, Attribute object, String newText) {
            if (object.setValue(newText)) {
                selectionModel.setSelected(object, true);
            } else {
                selectionModel.setSelected(object, false);
                UiElements.cantSaveAttributeValueDialogBox(object);
            }
        }
    });
    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName());
        }
    });
    // Sorting type column
    typeColumn.setSortable(true);
    columnSortHandler.setComparator(typeColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getType().compareToIgnoreCase(o2.getType());
        }
    });
    // Sorting value column
    valueColumn.setSortable(true);
    columnSortHandler.setComparator(valueColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getValue().compareToIgnoreCase(o2.getValue());
        }
    });
    // Sorting value column
    entityColumn.setSortable(true);
    columnSortHandler.setComparator(entityColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getEntity().compareToIgnoreCase(o2.getEntity());
        }
    });
    // Sorting value column
    defTypeColumn.setSortable(true);
    columnSortHandler.setComparator(defTypeColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getDefinition().compareToIgnoreCase(o2.getDefinition());
        }
    });
    // Add the columns.
    this.table.addColumnSortHandler(columnSortHandler);
    // updates the columns size
    this.table.setColumnWidth(entityColumn, 100.0, Unit.PX);
    this.table.setColumnWidth(defTypeColumn, 110.0, Unit.PX);
    this.table.setColumnWidth(typeColumn, 100.0, Unit.PX);
    this.table.setColumnWidth(nameColumn, 200.0, Unit.PX);
    this.table.setColumnWidth(valueColumn, 200.0, Unit.PX);
    // Add the columns.
    this.table.addColumn(nameColumn, "Name");
    this.table.addColumn(entityColumn, "Entity");
    this.table.addColumn(defTypeColumn, "Definition");
    this.table.addColumn(typeColumn, "Value type");
    this.table.addColumn(valueColumn, "Value");
    this.table.addDescriptionColumn();
    return this.table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Attribute(cz.metacentrum.perun.webgui.model.Attribute) Header(com.google.gwt.user.cellview.client.Header) Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunCheckboxCell(cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 7 with PerunCheckboxCell

use of cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell in project perun by CESNET.

the class GetGroupUnions method getTable.

@Override
public CellTable<Group> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<Group>(list);
    // Cell table
    table = new PerunTable<>(list);
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ColumnSortEvent.ListHandler<Group> columnSortHandler = new ColumnSortEvent.ListHandler<>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Group>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("Group has no unions.");
    // checkbox column column
    Column<Group, Group> checkBoxColumn = new Column<Group, Group>(new PerunCheckboxCell<Group>(true, false, true)) {

        @Override
        public Group getValue(Group 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, Style.Unit.PX);
    // Add the columns
    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {

        public Boolean getValue() {
            // return true to see a checked checkbox.
            return false;
        }
    };
    checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {

        public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (Group obj : list) {
                selectionModel.setSelected(obj, value);
            }
        }
    });
    table.addColumn(checkBoxColumn, checkBoxHeader);
    table.addIdColumn("Group ID", tableFieldUpdater);
    table.addNameColumn(tableFieldUpdater);
    table.addDescriptionColumn(tableFieldUpdater);
    return table;
}
Also used : Group(cz.metacentrum.perun.webgui.model.Group) ColumnSortEvent(com.google.gwt.user.cellview.client.ColumnSortEvent) Header(com.google.gwt.user.cellview.client.Header) Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunCheckboxCell(cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 8 with PerunCheckboxCell

use of cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell in project perun by CESNET.

the class GetAttributes method getEmptyTable.

/**
 * 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);
    // remove row count change handler
    table.removeRowCountChangeHandler();
    // 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 tabindex
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    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 true to see a checked checkbox.
                return false;
            }
        };
        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("Attribute ID", this.tableFieldUpdater);
    // Name column
    Column<Attribute, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            return attribute.getFriendlyName();
        }
    }, this.tableFieldUpdater);
    // Create ENTITY column
    Column<Attribute, String> entityColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute a) {
            return a.getEntity();
        }
    }, this.tableFieldUpdater);
    // Create def type column
    Column<Attribute, String> defTypeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute a) {
            return a.getDefinition();
        }
    }, this.tableFieldUpdater);
    // Create type column.
    Column<Attribute, String> typeColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            return renameContent(attribute.getType());
        }
    }, this.tableFieldUpdater);
    Column<Attribute, String> valueColumn;
    if (editable) {
        valueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

            public String getValue(Attribute attribute) {
                return attribute.getValue();
            }
        }, new FieldUpdater<Attribute, String>() {

            public void update(int index, Attribute object, String newText) {
                if (object.setValue(newText)) {
                    selectionModel.setSelected(object, true);
                } else {
                    selectionModel.setSelected(object, false);
                    UiElements.cantSaveAttributeValueDialogBox(object);
                }
            }
        });
    } else {
        valueColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

            public String getValue(Attribute attribute) {
                return attribute.getValue();
            }
        }, this.tableFieldUpdater);
    }
    // Create description column.
    Column<Attribute, String> descriptionColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Attribute, String>() {

        public String getValue(Attribute attribute) {
            return attribute.getDescription();
        }
    }, this.tableFieldUpdater);
    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName());
        }
    });
    // Sorting type column
    typeColumn.setSortable(true);
    columnSortHandler.setComparator(typeColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getType().compareToIgnoreCase(o2.getType());
        }
    });
    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(descriptionColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getDescription().compareToIgnoreCase(o2.getDescription());
        }
    });
    // Sorting value column
    valueColumn.setSortable(true);
    columnSortHandler.setComparator(valueColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getValue().compareToIgnoreCase(o2.getValue());
        }
    });
    // Sorting value column
    entityColumn.setSortable(true);
    columnSortHandler.setComparator(entityColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getEntity().compareToIgnoreCase(o2.getEntity());
        }
    });
    // Sorting value column
    defTypeColumn.setSortable(true);
    columnSortHandler.setComparator(defTypeColumn, new Comparator<Attribute>() {

        public int compare(Attribute o1, Attribute o2) {
            return o1.getDefinition().compareToIgnoreCase(o2.getDefinition());
        }
    });
    // column size
    this.table.setColumnWidth(typeColumn, 120.0, Unit.PX);
    this.table.setColumnWidth(entityColumn, 100.0, Unit.PX);
    this.table.setColumnWidth(defTypeColumn, 110.0, Unit.PX);
    this.table.setColumnWidth(nameColumn, 200.0, Unit.PX);
    this.table.setColumnWidth(valueColumn, 200.0, Unit.PX);
    // Add the columns.
    this.table.addColumn(nameColumn, "Name");
    this.table.addColumn(entityColumn, "Entity");
    this.table.addColumn(defTypeColumn, "Definition");
    this.table.addColumn(typeColumn, "Value type");
    this.table.addColumn(valueColumn, "Value");
    this.table.addColumn(descriptionColumn, "Description");
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) Attribute(cz.metacentrum.perun.webgui.model.Attribute) Header(com.google.gwt.user.cellview.client.Header) Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunCheckboxCell(cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 9 with PerunCheckboxCell

use of cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell in project perun by CESNET.

the class GetAttributesV2 method getEmptyTable.

/**
 * 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);
    // remove row count change handler
    table.removeRowCountChangeHandler();
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Attribute> columnSortHandler = new ListHandler<Attribute>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No settings found. Use 'Add' button to add new setting.");
    // 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 true to see a checked checkbox.
                return false;
            }
        };
        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 selection
        table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Attribute>createCheckboxManager(0));
        table.addColumn(checkBoxColumn, checkBoxHeader);
    }
    // Create ID column.
    table.addIdColumn("Attr ID", null, 90);
    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());
    // Description column
    Column<Attribute, Attribute> descriptionColumn = JsonUtils.addColumn(new PerunAttributeDescriptionCell());
    // 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());
        }
    });
    // 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;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) Attribute(cz.metacentrum.perun.webgui.model.Attribute) PerunAttributeNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell) PerunAttributeDescriptionCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell) Header(com.google.gwt.user.cellview.client.Header) Column(com.google.gwt.user.cellview.client.Column) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunCheckboxCell(cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject)

Example 10 with PerunCheckboxCell

use of cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell in project perun by CESNET.

the class GetAllRichGroups method getEmptyTable.

/**
 * Returns table with groups in hierarchical structure and with custom field updater
 *
 * @return table widget
 */
public CellTable<RichGroup> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<RichGroup>(list);
    // Cell table
    table = new PerunTable<RichGroup>(list);
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<RichGroup> columnSortHandler = new ListHandler<RichGroup>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichGroup>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    if (!session.isVoAdmin(voId)) {
        loaderImage.setEmptyResultMessage("You are not manager of any group in this VO.");
    } else {
        loaderImage.setEmptyResultMessage("VO has no groups.");
    }
    Column<RichGroup, RichGroup> checkBoxColumn = new Column<RichGroup, RichGroup>(new PerunCheckboxCell<RichGroup>(true, false, coreGroupsCheckable)) {

        @Override
        public RichGroup getValue(RichGroup object) {
            // Get the value from the selection model.
            object.setChecked(selectionModel.isSelected(object));
            return object;
        }
    };
    // 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 true to see a checked checkbox.
            return false;
        }
    };
    checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {

        public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (RichGroup obj : list) {
                if (!obj.isCoreGroup()) {
                    selectionModel.setSelected(obj, value);
                }
            }
        }
    });
    if (checkable) {
        table.addColumn(checkBoxColumn, checkBoxHeader);
    }
    table.addIdColumn("Group ID", tableFieldUpdater);
    // Add a synchronization clicable icon column.
    final Column<RichGroup, RichGroup> syncColumn = new Column<RichGroup, RichGroup>(new CustomClickableInfoCellWithImageResource("click")) {

        @Override
        public RichGroup getValue(RichGroup object) {
            return object;
        }

        @Override
        public String getCellStyleNames(Cell.Context context, RichGroup object) {
            if (tableFieldUpdater != null) {
                return super.getCellStyleNames(context, object) + " pointer image-hover";
            } else {
                return super.getCellStyleNames(context, object);
            }
        }
    };
    syncColumn.setFieldUpdater(new FieldUpdater<RichGroup, RichGroup>() {

        @Override
        public void update(int index, final RichGroup object, RichGroup value) {
            GetEntityById get = new GetEntityById(PerunEntity.RICH_GROUP, object.getId(), new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    final RichGroup object = jso.cast();
                    String name, syncEnabled, syncInterval, syncStartTimestamp, syncTimestamp, syncSuccessTimestamp, syncState, authGroup, syncTimes, syncSuccessStartTimestamp;
                    name = object.getName();
                    if (object.isSyncEnabled()) {
                        syncEnabled = "enabled";
                    } else {
                        syncEnabled = "disabled";
                    }
                    if (object.getSynchronizationInterval() == null) {
                        syncInterval = "N/A";
                    } else {
                        if (JsonUtils.checkParseInt(object.getSynchronizationInterval())) {
                            int time = Integer.parseInt(object.getSynchronizationInterval()) * 5 / 60;
                            if (time == 0) {
                                time = Integer.parseInt(object.getSynchronizationInterval()) * 5;
                                syncInterval = time + " minute(s)";
                            } else {
                                syncInterval = time + " hour(s)";
                            }
                        } else {
                            syncInterval = object.getSynchronizationInterval();
                        }
                    }
                    if (object.getSynchronizationTimes() != null && object.getSynchronizationTimes().length() > 0) {
                        syncTimes = object.getSynchronizationTimes().join(", ");
                    } else {
                        syncTimes = "N/A";
                    }
                    if (object.getLastSynchronizationState() == null) {
                        if (object.getLastSuccessSynchronizationTimestamp() != null) {
                            syncState = "OK";
                        } else {
                            syncState = "Not synced yet";
                        }
                    } else {
                        if (session.isPerunAdmin()) {
                            syncState = object.getLastSynchronizationState();
                        } else {
                            syncState = "Internal Error";
                        }
                    }
                    if (object.getLastSynchronizationTimestamp() == null) {
                        syncTimestamp = "N/A";
                    } else {
                        syncTimestamp = object.getLastSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getStartOfLastSynchronizationTimestamp() == null) {
                        syncStartTimestamp = "N/A";
                    } else {
                        syncStartTimestamp = object.getStartOfLastSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getLastSuccessSynchronizationTimestamp() == null) {
                        syncSuccessTimestamp = "N/A";
                    } else {
                        syncSuccessTimestamp = object.getLastSuccessSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getStartOfLastSuccessfulSynchronization() == null) {
                        syncSuccessStartTimestamp = "N/A";
                    } else {
                        syncSuccessStartTimestamp = object.getStartOfLastSuccessfulSynchronization().split("\\.")[0];
                    }
                    if (Objects.equals(object.getAuthoritativeGroup(), "1")) {
                        authGroup = "Yes";
                    } else {
                        authGroup = "No";
                    }
                    String html = "Group name: <b>" + SafeHtmlUtils.fromString(name).asString() + "</b><br>";
                    html += "Authoritative group: <b>" + SafeHtmlUtils.fromString(authGroup).asString() + "</b><br>";
                    html += "Synchronization: <b>" + SafeHtmlUtils.fromString(syncEnabled).asString() + "</b><br>";
                    html += "Sync. Interval: <b>" + SafeHtmlUtils.fromString(syncInterval).asString() + "</b><br>";
                    html += "Sync. Times: <b>" + SafeHtmlUtils.fromString(syncTimes).asString() + "</b><br>-----------------<br>";
                    if (object.isSyncEnabled()) {
                        html += "Last sync. state: <b>" + SafeHtmlUtils.fromString(syncState).asString() + "</b><br>";
                        html += "Last sync. timestamp (start): <b>" + SafeHtmlUtils.fromString(syncStartTimestamp).asString() + "</b><br>";
                        html += "Last sync. timestamp (end): <b>" + SafeHtmlUtils.fromString(syncTimestamp).asString() + "</b><br>";
                        html += "Last successful sync. timestamp (start): <b>" + SafeHtmlUtils.fromString(syncSuccessStartTimestamp).asString() + "</b><br>";
                        html += "Last successful sync. timestamp (end): <b>" + SafeHtmlUtils.fromString(syncSuccessTimestamp).asString() + "</b><br>";
                    }
                    FlexTable layout = new FlexTable();
                    layout.setWidth("450px");
                    layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.informationIcon())));
                    layout.setHTML(0, 1, "<p style=\"line-height: 1.2;\">" + html);
                    layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                    layout.getFlexCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                    layout.getFlexCellFormatter().setStyleName(0, 0, "alert-box-image");
                    final CustomButton okButton = new CustomButton("Force synchronization", SmallIcons.INSTANCE.arrowRefreshIcon());
                    okButton.addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            ForceGroupSynchronization call = new ForceGroupSynchronization(JsonCallbackEvents.disableButtonEvents(okButton));
                            call.synchronizeGroup(object.getId());
                        }
                    });
                    okButton.setVisible(object.isSyncEnabled());
                    if (!session.isVoAdmin(object.getVoId()) && !session.isGroupAdmin(object.getId()))
                        okButton.setEnabled(false);
                    final Confirm c = new Confirm("Group synchronization info", layout, okButton, null, true);
                    c.setHideOnButtonClick(false);
                    c.setCancelIcon(SmallIcons.INSTANCE.acceptIcon());
                    c.setCancelButtonText("OK");
                    c.setCancelClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            c.hide();
                        }
                    });
                    c.show();
                }
            });
            get.retrieveData();
        }
    });
    syncColumn.setSortable(true);
    columnSortHandler.setComparator(syncColumn, new Comparator<RichGroup>() {

        @Override
        public int compare(RichGroup o1, RichGroup o2) {
            if (o1 != null && o2 != null) {
                int o1val = 0;
                int o2val = 0;
                if (o1.isSyncEnabled())
                    o1val = 5;
                if (o2.isSyncEnabled())
                    o2val = 5;
                if (Objects.equals(o1.getAuthoritativeGroup(), "1"))
                    o1val = o1val + 3;
                if (Objects.equals(o2.getAuthoritativeGroup(), "1"))
                    o2val = o2val + 3;
                return o1val - o2val;
            }
            return 0;
        }
    });
    table.addColumn(syncColumn, "Sync");
    table.setColumnWidth(syncColumn, "70px");
    // set row styles based on: isCoreGroup()
    table.setRowStyles(new RowStyles<RichGroup>() {

        public String getStyleNames(RichGroup row, int rowIndex) {
            if (row.isCoreGroup()) {
                return "bold";
            }
            return "";
        }
    });
    table.addNameColumn(tableFieldUpdater);
    table.addDescriptionColumn(tableFieldUpdater);
    return table;
}
Also used : RichGroup(cz.metacentrum.perun.webgui.model.RichGroup) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) Column(com.google.gwt.user.cellview.client.Column) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunCheckboxCell(cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Header(com.google.gwt.user.cellview.client.Header) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomClickableInfoCellWithImageResource(cz.metacentrum.perun.webgui.widgets.cells.CustomClickableInfoCellWithImageResource)

Aggregations

CheckboxCell (com.google.gwt.cell.client.CheckboxCell)16 Column (com.google.gwt.user.cellview.client.Column)16 Header (com.google.gwt.user.cellview.client.Header)16 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)16 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)14 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)9 Attribute (cz.metacentrum.perun.webgui.model.Attribute)7 Group (cz.metacentrum.perun.webgui.model.Group)5 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)4 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)3 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)3 ColumnSortEvent (com.google.gwt.user.cellview.client.ColumnSortEvent)2 IsClickableCell (cz.metacentrum.perun.webgui.json.columnProviders.IsClickableCell)2 MemberColumnProvider (cz.metacentrum.perun.webgui.json.columnProviders.MemberColumnProvider)2 RichMember (cz.metacentrum.perun.webgui.model.RichMember)2 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1