Search in sources :

Example 1 with RemoveRequiredAttribute

use of cz.metacentrum.perun.webgui.json.servicesManager.RemoveRequiredAttribute in project perun by CESNET.

the class ServiceRequiredAttributesTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(service.getName()) + ": Required attributes");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // create new json call for required attributes of service with id=?
    final GetServiceRequiredAttributes servReqAttr = new GetServiceRequiredAttributes(serviceId);
    // menu
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    // custom event
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(servReqAttr);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addRequiredAttribute(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().addTabToCurrentTab(new AddRequiredAttributesTabItem(service), true);
        }
    }));
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedRequiredAttributes());
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            final ArrayList<AttributeDefinition> attrsForRemoving = servReqAttr.getTableSelectedList();
            UiElements.showDeleteConfirm(attrsForRemoving, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < attrsForRemoving.size(); i++) {
                        if (i == attrsForRemoving.size() - 1) {
                            RemoveRequiredAttribute request = new RemoveRequiredAttribute(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                            request.removeRequiredAttribute(serviceId, attrsForRemoving.get(i).getId());
                        } else {
                            RemoveRequiredAttribute request = new RemoveRequiredAttribute(JsonCallbackEvents.disableButtonEvents(removeButton));
                            request.removeRequiredAttribute(serviceId, attrsForRemoving.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    menu.addWidget(removeButton);
    final ExtendedSuggestBox box = new ExtendedSuggestBox(servReqAttr.getOracle());
    menu.addFilterWidget(box, new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            servReqAttr.filterTable(text);
        }
    }, "Filter required attributes by name");
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // get table = make call
    CellTable<AttributeDefinition> reqAttrTable = servReqAttr.getTable();
    // create scroll panel for table
    reqAttrTable.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(reqAttrTable);
    sp.addStyleName("perun-tableScrollPanel");
    sp.setWidth("100%");
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(servReqAttr, reqAttrTable, removeButton);
    session.getUiElements().resizePerunTable(sp, 350, this);
    // add tabs to the main panel
    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) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) GetServiceRequiredAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetServiceRequiredAttributes) RemoveRequiredAttribute(cz.metacentrum.perun.webgui.json.servicesManager.RemoveRequiredAttribute) 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 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetServiceRequiredAttributes (cz.metacentrum.perun.webgui.json.attributesManager.GetServiceRequiredAttributes)1 RemoveRequiredAttribute (cz.metacentrum.perun.webgui.json.servicesManager.RemoveRequiredAttribute)1 AttributeDefinition (cz.metacentrum.perun.webgui.model.AttributeDefinition)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