Search in sources :

Example 1 with UpdateResourceTag

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

the class VoResourcesTagsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": resources tags");
    // MAIN PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    // refresh
    menu.addWidget(UiElements.getRefreshButton(this));
    // members request
    final GetAllResourcesTags resTags = new GetAllResourcesTags(PerunEntity.VIRTUAL_ORGANIZATION, voId);
    if (!session.isVoAdmin(voId))
        resTags.setCheckable(false);
    if (session.isVoAdmin(voId))
        resTags.setEditable(true);
    // Events for reloading when finished
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(resTags);
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createResourceTag(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateVoResourceTagTabItem(voId));
        }
    });
    menu.addWidget(addButton);
    if (!session.isVoAdmin(voId))
        addButton.setEnabled(false);
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteResourceTag());
    if (!session.isVoAdmin(voId))
        removeButton.setEnabled(false);
    menu.addWidget(removeButton);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<ResourceTag> tagsToRemove = resTags.getTableSelectedList();
            String text = "Following tags will be deleted and won't be used to tag VO resources.";
            UiElements.showDeleteConfirm(tagsToRemove, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < tagsToRemove.size(); i++) {
                        DeleteResourceTag request;
                        if (i == tagsToRemove.size() - 1) {
                            request = new DeleteResourceTag(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                        } else {
                            request = new DeleteResourceTag(JsonCallbackEvents.disableButtonEvents(removeButton));
                        }
                        request.deleteResourceTag(tagsToRemove.get(i));
                    }
                }
            });
        }
    });
    menu.addFilterWidget(new ExtendedSuggestBox(resTags.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            resTags.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterTags());
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.updateResourceTag());
    menu.addWidget(saveButton);
    if (!session.isVoAdmin(voId))
        saveButton.setEnabled(false);
    saveButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<ResourceTag> tagsToUpdate = resTags.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(tagsToUpdate)) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                for (int i = 0; i < tagsToUpdate.size(); i++) {
                    UpdateResourceTag request;
                    if (i == tagsToUpdate.size() - 1) {
                        request = new UpdateResourceTag(JsonCallbackEvents.disableButtonEvents(saveButton, events));
                    } else {
                        request = new UpdateResourceTag(JsonCallbackEvents.disableButtonEvents(saveButton));
                    }
                    request.updateResourceTag(tagsToUpdate.get(i));
                }
            }
        }
    });
    // get the table
    CellTable<ResourceTag> table = resTags.getTable();
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu and the table to the main panel
    firstTabPanel.add(menu);
    firstTabPanel.setCellHeight(menu, "30px");
    firstTabPanel.add(sp);
    removeButton.setEnabled(false);
    if (session.isVoAdmin(voId))
        JsonUtils.addTableManagedButton(resTags, table, removeButton);
    saveButton.setEnabled(false);
    if (session.isVoAdmin(voId))
        JsonUtils.addTableManagedButton(resTags, table, saveButton);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) UpdateResourceTag(cz.metacentrum.perun.webgui.json.resourcesManager.UpdateResourceTag) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) DeleteResourceTag(cz.metacentrum.perun.webgui.json.resourcesManager.DeleteResourceTag) GetAllResourcesTags(cz.metacentrum.perun.webgui.json.resourcesManager.GetAllResourcesTags) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) DeleteResourceTag(cz.metacentrum.perun.webgui.json.resourcesManager.DeleteResourceTag) ResourceTag(cz.metacentrum.perun.webgui.model.ResourceTag) UpdateResourceTag(cz.metacentrum.perun.webgui.json.resourcesManager.UpdateResourceTag) 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 DeleteResourceTag (cz.metacentrum.perun.webgui.json.resourcesManager.DeleteResourceTag)1 GetAllResourcesTags (cz.metacentrum.perun.webgui.json.resourcesManager.GetAllResourcesTags)1 UpdateResourceTag (cz.metacentrum.perun.webgui.json.resourcesManager.UpdateResourceTag)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