Search in sources :

Example 1 with AddRequiredAttribute

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

the class AddRequiredAttributesTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add required attributes");
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    final GetAttributesDefinition attrDefs = new GetAttributesDefinition();
    attrDefs.setEditable(false);
    CellTable<AttributeDefinition> table = attrDefs.getTable();
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedRequiredAttribute());
    final ExtendedSuggestBox box = new ExtendedSuggestBox(attrDefs.getOracle());
    menu.addFilterWidget(box, new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            attrDefs.filterTable(text);
            if (attrDefs.getList().size() == 1) {
                attrDefs.getSelectionModel().setSelected(attrDefs.getList().get(0), true);
            }
        }
    }, ButtonTranslation.INSTANCE.filterAttributeDefinition());
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<AttributeDefinition> attributesToAdd = attrDefs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(attributesToAdd)) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                for (int i = 0; i < attributesToAdd.size(); i++) {
                    final int n = i;
                    AddRequiredAttribute request = new AddRequiredAttribute(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // unselect added attribute
                            attrDefs.getSelectionModel().setSelected(attributesToAdd.get(n), false);
                            alreadyAddedList.add(attributesToAdd.get(n));
                            rebuildAlreadyAddedWidget();
                            // clear search
                            box.getSuggestBox().setText("");
                        }
                    }));
                    request.addRequiredAttribute(serviceId, attributesToAdd.get(i).getId());
                }
            }
        }
    });
    menu.addWidget(addButton);
    // cancel button
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
        }
    }));
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(attrDefs, table, addButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    mainTab.add(menu);
    mainTab.setCellHeight(menu, "30px");
    mainTab.add(alreadyAdded);
    mainTab.add(sp);
    mainTab.setCellHeight(sp, "100%");
    // add tabs to the main panel
    this.contentWidget.setWidget(mainTab);
    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) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) AddRequiredAttribute(cz.metacentrum.perun.webgui.json.servicesManager.AddRequiredAttribute) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) GetAttributesDefinition(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 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 GetAttributesDefinition (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition)1 AddRequiredAttribute (cz.metacentrum.perun.webgui.json.servicesManager.AddRequiredAttribute)1 AttributeDefinition (cz.metacentrum.perun.webgui.model.AttributeDefinition)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)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