Search in sources :

Example 1 with DeleteOwner

use of cz.metacentrum.perun.webgui.json.ownersManager.DeleteOwner in project perun by CESNET.

the class OwnersTabItem method draw.

public Widget draw() {
    // tab content
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    // horizontal menu
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    final GetOwners owners = new GetOwners();
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(owners);
    // create button
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createOwner(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateOwnerTabItem());
        }
    }));
    // remove button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteOwner());
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Owner> itemsToRemove = owners.getTableSelectedList();
            String text = "Following owners will be removed.";
            UiElements.showDeleteConfirm(itemsToRemove, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < itemsToRemove.size(); i++) {
                        DeleteOwner request;
                        if (i == itemsToRemove.size() - 1) {
                            request = new DeleteOwner(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                        } else {
                            request = new DeleteOwner(JsonCallbackEvents.disableButtonEvents(removeButton));
                        }
                        request.deleteOwner(itemsToRemove.get(i).getId());
                    }
                }
            });
        }
    });
    tabMenu.addWidget(removeButton);
    tabMenu.addFilterWidget(new ExtendedSuggestBox(owners.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            owners.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterOwners());
    // adding menu to the page
    mainTab.add(tabMenu);
    mainTab.setCellHeight(tabMenu, "30px");
    CellTable<Owner> table = owners.getTable();
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    sp.addStyleName("perun-tableScrollPanel");
    mainTab.add(sp);
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(owners, table, removeButton);
    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Owner(cz.metacentrum.perun.webgui.model.Owner) DeleteOwner(cz.metacentrum.perun.webgui.json.ownersManager.DeleteOwner) DeleteOwner(cz.metacentrum.perun.webgui.json.ownersManager.DeleteOwner) GetOwners(cz.metacentrum.perun.webgui.json.ownersManager.GetOwners) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) 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 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 DeleteOwner (cz.metacentrum.perun.webgui.json.ownersManager.DeleteOwner)1 GetOwners (cz.metacentrum.perun.webgui.json.ownersManager.GetOwners)1 Owner (cz.metacentrum.perun.webgui.model.Owner)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