Search in sources :

Example 1 with RemoveResourceTag

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

the class ResourceTagsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": manage assigned tags");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    final GetAllResourcesTags tags = new GetAllResourcesTags(PerunEntity.RESOURCE, resourceId);
    final JsonCallbackEvents localEvents = JsonCallbackEvents.refreshTableEvents(tags);
    CustomButton assignTagsButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.assignTagsToResource(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AssignTagTabItem(resource), true);
        }
    });
    final CustomButton removeTagsButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedTagsFromResource());
    removeTagsButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ResourceTag> tagsToRemove = tags.getTableSelectedList();
            String text = "Following groups will be removed from resource.";
            UiElements.showDeleteConfirm(tagsToRemove, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD USE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < tagsToRemove.size(); i++) {
                        if (i == tagsToRemove.size() - 1) {
                            RemoveResourceTag request = new RemoveResourceTag(resource.getId(), JsonCallbackEvents.disableButtonEvents(removeTagsButton, localEvents));
                            request.removeResourceTag(tagsToRemove.get(i));
                        } else {
                            RemoveResourceTag request = new RemoveResourceTag(resource.getId(), JsonCallbackEvents.disableButtonEvents(removeTagsButton));
                            request.removeResourceTag(tagsToRemove.get(i));
                        }
                    }
                }
            });
        }
    });
    if (!session.isVoAdmin(resource.getVoId())) {
        assignTagsButton.setEnabled(false);
        removeTagsButton.setEnabled(false);
        tags.setCheckable(false);
    }
    menu.addWidget(assignTagsButton);
    menu.addWidget(removeTagsButton);
    menu.addFilterWidget(new ExtendedSuggestBox(tags.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            tags.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterTags());
    // display menu to vo admin only
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // table with field updater which leads to group detail
    CellTable<ResourceTag> table = tags.getTable();
    removeTagsButton.setEnabled(false);
    JsonUtils.addTableManagedButton(tags, table, removeTagsButton);
    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) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) RemoveResourceTag(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveResourceTag) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetAllResourcesTags(cz.metacentrum.perun.webgui.json.resourcesManager.GetAllResourcesTags) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ResourceTag(cz.metacentrum.perun.webgui.model.ResourceTag) RemoveResourceTag(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveResourceTag) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)

Aggregations

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 GetAllResourcesTags (cz.metacentrum.perun.webgui.json.resourcesManager.GetAllResourcesTags)1 RemoveResourceTag (cz.metacentrum.perun.webgui.json.resourcesManager.RemoveResourceTag)1 ResourceTag (cz.metacentrum.perun.webgui.model.ResourceTag)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