Search in sources :

Example 1 with RemoveGroupFromResources

use of cz.metacentrum.perun.webgui.json.resourcesManager.RemoveGroupFromResources in project perun by CESNET.

the class GroupResourcesTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": " + "resources");
    // main panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    // get VO resources
    final GetAssignedRichResources resources = new GetAssignedRichResources(groupId, PerunEntity.GROUP);
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        resources.setCheckable(false);
    // custom events for viewResource
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(resources);
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeGroupFromSelectedResources());
    // add / remove resource from group can be done by vo / perun admin only.
    if (session.isVoAdmin(group.getVoId())) {
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.assignGroupToResources(), new ClickHandler() {

            public void onClick(ClickEvent event) {
                session.getTabManager().addTabToCurrentTab(new AssignGroupTabItem(group, resources.getList()), true);
            }
        }));
        removeButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                final ArrayList<RichResource> toRemove = resources.getTableSelectedList();
                String text = "Following resources will be removed from group and it's members won't have access to them anymore.";
                UiElements.showDeleteConfirm(toRemove, text, new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent clickEvent) {
                        RemoveGroupFromResources request = new RemoveGroupFromResources(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                        request.removeGroupFromResources(group, toRemove);
                    }
                });
            }
        });
        menu.addWidget(removeButton);
    }
    // filter box
    menu.addFilterWidget(new ExtendedSuggestBox(resources.getOracle()), new PerunSearchEvent() {

        public void searchFor(String text) {
            resources.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterResources());
    // add menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<RichResource> table;
    // perun / vo admin can set attributes
    if (session.isVoAdmin(group.getVoId()) || session.isVoObserver(group.getVoId())) {
        table = resources.getTable(new FieldUpdater<RichResource, String>() {

            public void update(int index, RichResource object, String value) {
                session.getTabManager().addTab(new ResourceDetailTabItem(object, 0));
            }
        });
    } else {
        table = resources.getTable();
    }
    removeButton.setEnabled(false);
    if (session.isGroupAdmin(groupId) || session.isVoAdmin(group.getVoId()))
        JsonUtils.addTableManagedButton(resources, table, removeButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) RichResource(cz.metacentrum.perun.webgui.model.RichResource) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) RemoveGroupFromResources(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveGroupFromResources) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetAssignedRichResources(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedRichResources) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) ResourceDetailTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem)

Aggregations

FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetAssignedRichResources (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedRichResources)1 RemoveGroupFromResources (cz.metacentrum.perun.webgui.json.resourcesManager.RemoveGroupFromResources)1 RichResource (cz.metacentrum.perun.webgui.model.RichResource)1 ResourceDetailTabItem (cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1