Search in sources :

Example 11 with Column

use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.

the class GetAllRichSubGroups method getTable.

/**
	 * Returns the table with subgroups.
	 * @return
	 */
public CellTable<RichGroup> getTable() {
    // retrieve data
    retrieveData();
    // 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);
    loaderImage.setEmptyResultMessage("Group has no sub-groups.");
    // checkbox column column
    table.addCheckBoxColumn();
    table.addIdColumn("Group ID", tableFieldUpdater);
    // Add a synchronization clicable icon column.
    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, syncTimestamp, syncSuccessTimestamp, syncState, authGroup;
                    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.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.getLastSuccessSynchronizationTimestamp() == null) {
                        syncSuccessTimestamp = "N/A";
                    } else {
                        syncSuccessTimestamp = object.getLastSuccessSynchronizationTimestamp().split("\\.")[0];
                    }
                    if (object.getAuthoritativeGroup() != null && object.getAuthoritativeGroup().equals("1")) {
                        authGroup = "Yes";
                    } else {
                        authGroup = "No";
                    }
                    String html = "Group name: <b>" + name + "</b><br>";
                    html += "Synchronization: <b>" + syncEnabled + "</b><br>";
                    if (object.isSyncEnabled()) {
                        html += "Last sync. state: <b>" + syncState + "</b><br>";
                        html += "Last sync. timestamp: <b>" + syncTimestamp + "</b><br>";
                        html += "Last successful sync. timestamp: <b>" + syncSuccessTimestamp + "</b><br>";
                        html += "Sync. Interval: <b>" + syncInterval + "</b><br>";
                        html += "Authoritative group: <b>" + authGroup + "</b><br>";
                    }
                    FlexTable layout = new FlexTable();
                    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());
                        }
                    });
                    if (!session.isVoAdmin(object.getVoId()) && !session.isGroupAdmin(object.getId()))
                        okButton.setEnabled(false);
                    okButton.setVisible(object.isSyncEnabled());
                    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 (o1.getAuthoritativeGroup() != null && o1.getAuthoritativeGroup().equalsIgnoreCase("1"))
                    o1val = o1val + 3;
                if (o2.getAuthoritativeGroup() != null && o2.getAuthoritativeGroup().equalsIgnoreCase("1"))
                    o2val = o2val + 3;
                return o1val - o2val;
            }
            return 0;
        }
    });
    table.addColumn(syncColumn, "Sync");
    table.setColumnWidth(syncColumn, "70px");
    table.addNameColumn(tableFieldUpdater);
    table.addDescriptionColumn(tableFieldUpdater);
    return table;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RichGroup(cz.metacentrum.perun.webgui.model.RichGroup) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) Image(com.google.gwt.user.client.ui.Image) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) Column(com.google.gwt.user.cellview.client.Column) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) FlexTable(com.google.gwt.user.client.ui.FlexTable) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomClickableInfoCellWithImageResource(cz.metacentrum.perun.webgui.widgets.cells.CustomClickableInfoCellWithImageResource)

Example 12 with Column

use of com.google.gwt.user.cellview.client.Column 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 13 with Column

use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.

the class GetAllowedGroups method getEmptyTable.

/**
	 * Returns table with groups in hierarchical structure and with custom field updater
	 *
	 * @return table widget
	 */
public CellTable<Group> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Group>(list);
    // Cell table
    table = new PerunTable<Group>(list);
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Group> columnSortHandler = new ListHandler<Group>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Group>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No groups are allowed to access/use this facility.");
    if (checkable) {
        table.addCheckBoxColumn();
    }
    table.addIdColumn("Group ID", tableFieldUpdater);
    table.addNameColumn(tableFieldUpdater);
    table.addDescriptionColumn(tableFieldUpdater);
    Column<Group, String> vosColumn = new Column<Group, String>(new CustomClickableTextCell()) {

        @Override
        public String getValue(Group group) {
            for (VirtualOrganization v : vos) {
                if (group.getVoId() == v.getId()) {
                    return v.getName();
                }
            }
            return String.valueOf(group.getVoId());
        }
    };
    vosColumn.setFieldUpdater(tableFieldUpdater);
    columnSortHandler.setComparator(vosColumn, new Comparator<Group>() {

        @Override
        public int compare(Group o1, Group o2) {
            return o1.getVoId() - o2.getVoId();
        }
    });
    vosColumn.setSortable(true);
    table.addColumn(vosColumn, "Virtual organization");
    return table;
}
Also used : CustomClickableTextCell(cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell) Group(cz.metacentrum.perun.webgui.model.Group) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) Column(com.google.gwt.user.cellview.client.Column) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization)

Example 14 with Column

use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.

the class GetAllResourcesTags method getTable.

/**
	 * Returns just the celltable
	 * @return
	 */
public CellTable<ResourceTag> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<ResourceTag>(list);
    // Cell table
    table = new PerunTable<ResourceTag>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<ResourceTag> columnSortHandler = new ListHandler<ResourceTag>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<ResourceTag>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    if (PerunEntity.VIRTUAL_ORGANIZATION.equals(entity)) {
        loaderImage.setEmptyResultMessage("VO has no resource tags defined.");
    } else if (PerunEntity.RESOURCE.equals(entity)) {
        loaderImage.setEmptyResultMessage("Resource has no tags assigned.");
    }
    // columns
    if (checkable) {
        table.addCheckBoxColumn();
    }
    table.addIdColumn("Tag ID", tableFieldUpdater);
    if (editable) {
        // DISPLAY NAME COLUMN
        final Column<ResourceTag, String> nameColumn = new Column<ResourceTag, String>(new TextInputCell()) {

            public String getValue(ResourceTag tag) {
                return tag.getName();
            }
        };
        nameColumn.setFieldUpdater(new FieldUpdater<ResourceTag, String>() {

            @Override
            public void update(int i, final ResourceTag tag, final String s) {
                tag.setName(s.trim());
                selectionModel.setSelected(tag, true);
            }
        });
        nameColumn.setSortable(true);
        columnSortHandler.setComparator(nameColumn, new Comparator<ResourceTag>() {

            public int compare(ResourceTag arg0, ResourceTag arg1) {
                return (arg0.getName().compareToIgnoreCase(arg1.getName()));
            }
        });
        table.addColumn(nameColumn, "Tag name");
    } else {
        // name column
        Column<ResourceTag, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<ResourceTag, String>() {

            public String getValue(ResourceTag object) {
                return object.getName();
            }
        }, tableFieldUpdater);
        nameColumn.setSortable(true);
        columnSortHandler.setComparator(nameColumn, new Comparator<ResourceTag>() {

            public int compare(ResourceTag arg0, ResourceTag arg1) {
                return (arg0.getName().compareToIgnoreCase(arg1.getName()));
            }
        });
        table.addColumn(nameColumn, "Tag name");
    }
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) TextInputCell(com.google.gwt.cell.client.TextInputCell) ResourceTag(cz.metacentrum.perun.webgui.model.ResourceTag) Column(com.google.gwt.user.cellview.client.Column)

Example 15 with Column

use of com.google.gwt.user.cellview.client.Column in project perun by CESNET.

the class GetAssignedGroups method getTable.

/**
	 * Returns table with assigned groups
	 *
	 * @return table widget
	 */
public CellTable<Group> getTable() {
    // retrieve data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<Group>(list);
    // Cell table
    table = new PerunTable<Group>(list);
    table.setHyperlinksAllowed(false);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Group> columnSortHandler = new ListHandler<Group>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    if (singleSelection) {
        table.setSelectionModel(singleSelectionModel, DefaultSelectionEventManager.<Group>createCheckboxManager());
    } else {
        table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Group>createCheckboxManager());
    }
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("Resource has no groups assigned.");
    // checkbox column column
    if (checkable) {
        Column<Group, Group> checkBoxColumn = new Column<Group, Group>(new PerunCheckboxCell<Group>(true, false, coreGroupsCheckable)) {

            @Override
            public Group getValue(Group object) {
                // Get the value from the selection model.
                if (singleSelection) {
                    object.setChecked(singleSelectionModel.isSelected(object));
                } else {
                    object.setChecked(selectionModel.isSelected(object));
                }
                return object;
            }
        };
        // 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) {
                    if (!obj.isCoreGroup()) {
                        selectionModel.setSelected(obj, value);
                    }
                }
            }
        });
        // updates the columns size
        table.setColumnWidth(checkBoxColumn, 60.0, Style.Unit.PX);
        if (singleSelection) {
            // single selection withou "check all"
            table.addColumn(checkBoxColumn);
        } else {
            // multi selection with header
            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) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) 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)

Aggregations

Column (com.google.gwt.user.cellview.client.Column)51 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)28 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)18 Header (com.google.gwt.user.cellview.client.Header)15 PerunCheckboxCell (cz.metacentrum.perun.webgui.widgets.cells.PerunCheckboxCell)14 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)10 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)10 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)9 TextCell (com.google.gwt.cell.client.TextCell)8 CustomClickableTextCell (cz.metacentrum.perun.webgui.widgets.cells.CustomClickableTextCell)8 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 TextColumn (com.google.gwt.user.cellview.client.TextColumn)6 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)6 Attribute (cz.metacentrum.perun.webgui.model.Attribute)6 Group (cz.metacentrum.perun.webgui.model.Group)6 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)6 ImageResource (com.google.gwt.resources.client.ImageResource)5 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)5