Search in sources :

Example 1 with UpdateCategory

use of cz.metacentrum.perun.webgui.json.cabinetManager.UpdateCategory in project perun by CESNET.

the class AllCategoriesTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final GetCategories callback = new GetCategories();
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback);
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add new category", new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateCategoryTabItem());
        }
    }));
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, "Delete selected categories");
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Category> delete = callback.getTableSelectedList();
            String text = "Following categories will be deleted";
            UiElements.showDeleteConfirm(delete, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < delete.size(); i++) {
                        if (i == delete.size() - 1) {
                            DeleteCategory request = new DeleteCategory(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                            request.deleteCategory(delete.get(i).getId());
                        } else {
                            DeleteCategory request = new DeleteCategory(JsonCallbackEvents.disableButtonEvents(removeButton));
                            request.deleteCategory(delete.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    menu.addWidget(removeButton);
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in category ranks");
    saveButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<Category> list = callback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                for (int i = 0; i < list.size(); i++) {
                    if (i == list.size() - 1) {
                        UpdateCategory request = new UpdateCategory(JsonCallbackEvents.disableButtonEvents(saveButton, events));
                        request.updateCategory(list.get(i));
                    } else {
                        UpdateCategory request = new UpdateCategory(JsonCallbackEvents.disableButtonEvents(saveButton));
                        request.updateCategory(list.get(i));
                    }
                }
            }
        }
    });
    menu.addWidget(saveButton);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<Category> table = callback.getTable();
    removeButton.setEnabled(false);
    saveButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeButton);
    JsonUtils.addTableManagedButton(callback, table, saveButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    // resize perun table to correct size on screen
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) UpdateCategory(cz.metacentrum.perun.webgui.json.cabinetManager.UpdateCategory) DeleteCategory(cz.metacentrum.perun.webgui.json.cabinetManager.DeleteCategory) UpdateCategory(cz.metacentrum.perun.webgui.json.cabinetManager.UpdateCategory) Category(cz.metacentrum.perun.webgui.model.Category) DeleteCategory(cz.metacentrum.perun.webgui.json.cabinetManager.DeleteCategory) 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) GetCategories(cz.metacentrum.perun.webgui.json.cabinetManager.GetCategories) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

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 DeleteCategory (cz.metacentrum.perun.webgui.json.cabinetManager.DeleteCategory)1 GetCategories (cz.metacentrum.perun.webgui.json.cabinetManager.GetCategories)1 UpdateCategory (cz.metacentrum.perun.webgui.json.cabinetManager.UpdateCategory)1 Category (cz.metacentrum.perun.webgui.model.Category)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1