Search in sources :

Example 1 with GetAttributesDefinition

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition in project perun by CESNET.

the class EditFormItemTabItem method basicInformationTab.

/**
 * Returns flex table with basic information and textboxes
 *
 * @return
 */
private Widget basicInformationTab() {
    // item application types
    ArrayList<String> itemApplicationTypes = JsonUtils.listFromJsArrayString(item.getApplicationTypes());
    // federation attributes to select from
    federationAttributes.addItem("No item selected (empty value)", "");
    federationAttributes.addItem("--- Custom value ---", "custom");
    federationAttributes.addItem("Display name", "displayName");
    federationAttributes.addItem("Common name", "cn");
    federationAttributes.addItem("Mail", "mail");
    federationAttributes.addItem("Organization", "o");
    federationAttributes.addItem("Level of Assurance (LoA)", "loa");
    federationAttributes.addItem("First name", "givenName");
    federationAttributes.addItem("Surname", "sn");
    federationAttributes.addItem("EPPN", "eppn");
    federationAttributes.addItem("IdP Category", "md_entityCategory");
    federationAttributes.addItem("IdP Affiliation", "affiliation");
    federationAttributes.addItem("EduPersonScopedAffiliation", "eduPersonScopedAffiliation");
    federationAttributes.addItem("Forwarded Affiliation from Proxy", "voPersonExternalAffiliation");
    federationAttributes.addItem("schacHomeOrganization", "schacHomeOrganization");
    federationAttributes.addItem("Login", "uid");
    federationAttributes.addItem("Alternative login name", "alternativeLoginName");
    hiddenBox.addItem("Never", "NEVER");
    hiddenBox.addItem("Always", "ALWAYS");
    hiddenBox.addItem("If prefilled (self or other item, if dependency specified)", "IF_PREFILLED");
    hiddenBox.addItem("If empty (self or other item, if dependency specified)", "IF_EMPTY");
    disabledBox.addItem("Never", "NEVER");
    disabledBox.addItem("Always", "ALWAYS");
    disabledBox.addItem("If prefilled (self or other item, if dependency specified)", "IF_PREFILLED");
    disabledBox.addItem("If empty (self or other item, if dependency specified)", "IF_EMPTY");
    disabledDependencyItemIdBox.addItem("-- Not selected --", "null");
    hiddenDependencyItemIdBox.addItem("-- Not selected --", "null");
    for (ApplicationFormItem otherItem : otherItems) {
        if (otherItem.getId() != 0 && otherItem.getId() != item.getId() && (otherItem.getType().equals("PASSWORD") || otherItem.getType().equals("VALIDATED_EMAIL") || otherItem.getType().equals("TEXTFIELD") || otherItem.getType().equals("TEXTAREA") || otherItem.getType().equals("CHECKBOX") || otherItem.getType().equals("RADIO") || otherItem.getType().equals("SELECTIONBOX") || otherItem.getType().equals("COMBOBOX") || otherItem.getType().equals("USERNAME"))) {
            disabledDependencyItemIdBox.addItem(otherItem.getShortname(), String.valueOf(otherItem.getId()));
            hiddenDependencyItemIdBox.addItem(otherItem.getShortname(), String.valueOf(otherItem.getId()));
        }
    }
    // application types
    GetAttributesDefinition attrDef = new GetAttributesDefinition(new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            // SOURCE LIST BOX
            perunSourceAttributeListBox.clear();
            perunSourceAttributeListBox.addItem("No item selected (empty value)", "");
            if (item.getPerunSourceAttribute() != null && !item.getPerunSourceAttribute().isEmpty()) {
                // add and select returned perun dest attr
                perunSourceAttributeListBox.addItem(item.getPerunSourceAttribute(), item.getPerunSourceAttribute());
                perunSourceAttributeListBox.setSelectedIndex(1);
            }
            // DESTINATION LIST BOX
            perunDestinationAttributeListBox.clear();
            perunDestinationAttributeListBox.addItem("No item selected (empty value)", "");
            if (item.getPerunDestinationAttribute() != null && !item.getPerunDestinationAttribute().isEmpty()) {
                // add and select returned perun dest attr
                perunDestinationAttributeListBox.addItem(item.getPerunDestinationAttribute(), item.getPerunDestinationAttribute());
                perunDestinationAttributeListBox.setSelectedIndex(1);
            }
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            // clear
            perunSourceAttributeListBox.clear();
            perunDestinationAttributeListBox.clear();
            // set empty possibility
            perunSourceAttributeListBox.addItem("No item selected (empty value)", "");
            perunDestinationAttributeListBox.addItem("No item selected (empty value)", "");
            ArrayList<AttributeDefinition> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                // sort
                list = new TableSorter<AttributeDefinition>().sortByFriendlyName(list);
                for (AttributeDefinition def : list) {
                    // add only member and user attributes
                    if (def.getEntity().equalsIgnoreCase("user") || def.getEntity().equalsIgnoreCase("member")) {
                        perunSourceAttributeListBox.addItem(def.getFriendlyName() + " (" + def.getEntity() + " / " + def.getDefinition() + ")", def.getName());
                        perunDestinationAttributeListBox.addItem(def.getFriendlyName() + " (" + def.getEntity() + " / " + def.getDefinition() + ")", def.getName());
                    } else if (def.getEntity().equalsIgnoreCase("vo")) {
                        // source attributes can be VO too
                        perunSourceAttributeListBox.addItem(def.getFriendlyName() + " (" + def.getEntity() + " / " + def.getDefinition() + ")", def.getName());
                    } else if (def.getEntity().equalsIgnoreCase("group") && groupId != 0) {
                        // source attributes can be Group too if form is for group
                        perunSourceAttributeListBox.addItem(def.getFriendlyName() + " (" + def.getEntity() + " / " + def.getDefinition() + ")", def.getName());
                    }
                }
            } else {
                // no attr def loaded, keep as it is set
                if (item.getPerunSourceAttribute() != null && !item.getPerunSourceAttribute().isEmpty()) {
                    perunSourceAttributeListBox.addItem(item.getPerunSourceAttribute(), item.getPerunSourceAttribute());
                }
                if (item.getPerunDestinationAttribute() != null && !item.getPerunDestinationAttribute().isEmpty()) {
                    perunDestinationAttributeListBox.addItem(item.getPerunDestinationAttribute(), item.getPerunDestinationAttribute());
                }
            }
            // set selected
            for (int i = 0; i < perunDestinationAttributeListBox.getItemCount(); i++) {
                // set proper value as "selected"
                if (perunDestinationAttributeListBox.getValue(i).equalsIgnoreCase(item.getPerunDestinationAttribute())) {
                    perunDestinationAttributeListBox.setSelectedIndex(i);
                    break;
                }
            }
            for (int i = 0; i < perunSourceAttributeListBox.getItemCount(); i++) {
                // set proper value as "selected"
                if (perunSourceAttributeListBox.getValue(i).equalsIgnoreCase(item.getPerunSourceAttribute())) {
                    perunSourceAttributeListBox.setSelectedIndex(i);
                    break;
                }
            }
        }

        @Override
        public void onLoadingStart() {
            perunSourceAttributeListBox.addItem("Loading...");
            perunDestinationAttributeListBox.addItem("Loading...");
        }
    });
    // layout
    FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");
    FlexCellFormatter ftf = ft.getFlexCellFormatter();
    // fill values
    shortNameTextBox.setText(item.getShortname());
    boolean found = false;
    for (int i = 0; i < federationAttributes.getItemCount(); i++) {
        if (federationAttributes.getValue(i).equals(item.getFederationAttribute())) {
            federationAttributes.setSelectedIndex(i);
            found = true;
            break;
        }
    }
    if (!found && item.getFederationAttribute() != null && !item.getFederationAttribute().isEmpty()) {
        // custom value
        federationAttributes.setSelectedIndex(1);
        federationAttributeCustomValue.setEnabled(true);
    } else {
        federationAttributeCustomValue.setEnabled(false);
    }
    federationAttributeCustomValue.setText(item.getFederationAttribute());
    federationAttributes.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (federationAttributes.getSelectedValue().equals("custom")) {
                federationAttributeCustomValue.setEnabled(true);
                federationAttributeCustomValue.setText(item.getFederationAttribute());
            } else {
                federationAttributeCustomValue.setEnabled(false);
                federationAttributeCustomValue.setText(federationAttributes.getSelectedValue());
            }
        }
    });
    for (int i = 0; i < hiddenBox.getItemCount(); i++) {
        String value = hiddenBox.getValue(i);
        if (value.equals(item.getHidden())) {
            hiddenBox.setSelectedIndex(i);
        }
    }
    for (int i = 0; i < disabledBox.getItemCount(); i++) {
        String value = disabledBox.getValue(i);
        if (value.equals(item.getDisabled())) {
            disabledBox.setSelectedIndex(i);
        }
    }
    for (int i = 0; i < hiddenDependencyItemIdBox.getItemCount(); i++) {
        if (hiddenDependencyItemIdBox.getValue(i).equals("null")) {
            if (item.getHiddenDependencyItemId() == 0) {
                hiddenDependencyItemIdBox.setSelectedIndex(i);
            }
        } else {
            int value = Integer.parseInt(hiddenDependencyItemIdBox.getValue(i));
            if (value == item.getHiddenDependencyItemId()) {
                hiddenDependencyItemIdBox.setSelectedIndex(i);
            }
        }
    }
    for (int i = 0; i < disabledDependencyItemIdBox.getItemCount(); i++) {
        if (disabledDependencyItemIdBox.getValue(i).equals("null")) {
            if (item.getDisabledDependencyItemId() == 0) {
                disabledDependencyItemIdBox.setSelectedIndex(i);
            }
        } else {
            int value = Integer.parseInt(disabledDependencyItemIdBox.getValue(i));
            if (value == item.getDisabledDependencyItemId()) {
                disabledDependencyItemIdBox.setSelectedIndex(i);
            }
        }
    }
    requiredCheckBox.setValue(item.isRequired());
    updatableCheckBox.setValue(item.isUpdatable());
    regexTextBox.setText(item.getRegex());
    for (Application.ApplicationType type : Application.ApplicationType.values()) {
        CheckBox cb = new CheckBox();
        boolean checked = itemApplicationTypes.contains(type.toString());
        cb.setValue(checked);
        applicationTypesCheckBoxes.add(cb);
    }
    // sizes
    shortNameTextBox.setWidth("200px");
    federationAttributes.setWidth("200px");
    perunSourceAttributeListBox.setWidth("300px");
    perunDestinationAttributeListBox.setWidth("300px");
    regexTextBox.setWidth("200px");
    // basic info
    int row = 0;
    Label shortNameLabel = new Label("Short name:");
    ft.setWidget(row, 0, shortNameLabel);
    ft.setWidget(row, 1, shortNameTextBox);
    row++;
    ft.setHTML(row, 1, "Internal item identification (used as fallback when you forgot to set \"Label\" for some language).");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    row++;
    Label inputLabel = new Label("Input widget:");
    ft.setWidget(row, 0, inputLabel);
    ft.setHTML(row, 1, CreateFormItemTabItem.inputTypes.get(item.getType()));
    row++;
    ft.setHTML(row, 1, "Specify what input widget is used for this item.");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    // set colspan for tops
    for (int i = 0; i < ft.getRowCount(); i++) {
        ftf.setColSpan(i, 1, 2);
    }
    row++;
    Label l = new Label("Display on application:");
    l.setTitle("");
    ft.setWidget(row, 0, l);
    ftf.setWidth(row, 0, "160px");
    Application.ApplicationType.values();
    int i = 0;
    for (Application.ApplicationType type : Application.ApplicationType.values()) {
        CheckBox cb = applicationTypesCheckBoxes.get(i);
        cb.setText(Application.getTranslatedType(type.toString()));
        if (type.equals(Application.ApplicationType.INITIAL)) {
            cb.setTitle("If checked, display form item on INITIAL application");
        } else {
            cb.setTitle("If checked, display form item on EXTENSION application");
        }
        ft.setWidget(row, i + 1, cb);
        i++;
    }
    row++;
    ft.setHTML(row, 1, "Define on which application types is this item displayed.");
    ftf.setStyleName(row, 1, "inputFormInlineComment");
    ftf.setColSpan(row, 1, 2);
    row++;
    // IF BUTTON OR COMMENT, don't show these
    if (!item.getType().equals("SUBMIT_BUTTON") && !item.getType().equals("AUTO_SUBMIT_BUTTON") && !item.getType().equals("HTML_COMMENT") && !item.getType().equals("HEADING")) {
        // load attr defs only when showed
        attrDef.retrieveData();
        Label requiredLabel = new Label("Required:");
        ft.setWidget(row, 0, requiredLabel);
        ft.setWidget(row, 1, requiredCheckBox);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "If checked, user can`t submit empty value (doesn't apply to non-editable fields).");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        if (!item.getType().equals("USERNAME") && !item.getType().equals("PASSWORD")) {
            row++;
            Label updatableLabel = new Label("Updatable:");
            ft.setWidget(row, 0, updatableLabel);
            ft.setWidget(row, 1, updatableCheckBox);
            ftf.setColSpan(row, 1, 2);
            row++;
            ft.setHTML(row, 1, "If checked, user can update the submitted value.");
            ftf.setStyleName(row, 1, "inputFormInlineComment");
            ftf.setColSpan(row, 1, 2);
        }
        row++;
        Label srcAttrLabel = new Label("Source attribute:");
        ft.setWidget(row, 0, srcAttrLabel);
        ft.setWidget(row, 1, perunSourceAttributeListBox);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "Select attribute, which will be used to pre-fill form value. You can select also VO " + (groupId != 0 ? "and group " : "") + "attributes.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        row++;
        Label destAttrLabel = new Label("Destination attribute:");
        ft.setWidget(row, 0, destAttrLabel);
        ft.setWidget(row, 1, perunDestinationAttributeListBox);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "Select attribute, where will be submitted value stored after accepting user`s application.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        row++;
        Label fedAttrLabel = new Label("Federation attribute:");
        ft.setWidget(row, 0, fedAttrLabel);
        ft.setWidget(row, 1, federationAttributes);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 0, "&nbsp;");
        ft.setWidget(row, 1, federationAttributeCustomValue);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "Select federation attribute to get pre-filed value from.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        if (!item.getType().equals("VALIDATED_EMAIL") && !item.getType().equals("TIMEZONE")) {
            row++;
            Label regexLabel = new Label("Regular expression:");
            ft.setWidget(row, 0, regexLabel);
            ft.setWidget(row, 1, regexTextBox);
            ftf.setColSpan(row, 1, 2);
            row++;
            ft.setHTML(row, 1, "Regular expression used for item value validation (before submitting by user).");
            ftf.setStyleName(row, 1, "inputFormInlineComment");
            ftf.setColSpan(row, 1, 2);
        }
        row++;
        ft.setWidget(row, 0, new Label("Hidden:"));
        ft.setWidget(row, 1, hiddenBox);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "When the item should be hidden during the submission.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setWidget(row, 0, new Label("Hidden dependency:"));
        ft.setWidget(row, 1, hiddenDependencyItemIdBox);
        ftf.setColSpan(row, 1, 2);
        row++;
        ft.setHTML(row, 1, "Other form item, which is used to decide, if this one should be hidden.");
        ftf.setStyleName(row, 1, "inputFormInlineComment");
        ftf.setColSpan(row, 1, 2);
        if (!item.getType().equals("PASSWORD")) {
            row++;
            ft.setWidget(row, 0, new Label("Disabled:"));
            ft.setWidget(row, 1, disabledBox);
            ftf.setColSpan(row, 1, 2);
            row++;
            ft.setHTML(row, 1, "When the item should be disabled during the submission.");
            ftf.setStyleName(row, 1, "inputFormInlineComment");
            ftf.setColSpan(row, 1, 2);
            row++;
            ft.setWidget(row, 0, new Label("Disabled dependency:"));
            ft.setWidget(row, 1, disabledDependencyItemIdBox);
            ftf.setColSpan(row, 1, 2);
            row++;
            ft.setHTML(row, 1, "Other form item, which is used to decide, if this one should be disabled.");
            ftf.setStyleName(row, 1, "inputFormInlineComment");
            ftf.setColSpan(row, 1, 2);
        }
    }
    // set styles
    for (int n = 0; n < ft.getRowCount(); n++) {
        ftf.setStyleName(n, 0, "itemName");
    }
    // scroll panel
    ScrollPanel sp = new ScrollPanel(ft);
    sp.addStyleName("perun-tableScrollPanel");
    sp.setSize("560px", "320px");
    sp.scrollToTop();
    return sp;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ArrayList(java.util.ArrayList) JSONString(com.google.gwt.json.client.JSONString) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) GetAttributesDefinition(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition)

Example 2 with GetAttributesDefinition

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition in project perun by CESNET.

the class AttributeDefinitionsTabItem method draw.

public Widget draw() {
    // create main panel for content
    VerticalPanel mainPage = new VerticalPanel();
    mainPage.setWidth("100%");
    // create new instance for jsonCall
    final GetAttributesDefinition attrDef = new GetAttributesDefinition();
    final ExtendedSuggestBox box = new ExtendedSuggestBox(attrDef.getOracle());
    // custom events for reloading when created or deleted
    final JsonCallbackEvents refreshTabEvents = JsonCallbackEvents.mergeEvents(JsonCallbackEvents.refreshTableEvents(attrDef), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            if (box.getSuggestBox().getValue() != null)
                attrDef.filterTable(box.getSuggestBox().getValue());
        }
    });
    // TAB MENU
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // create buttons
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, buttonTranslation.createAttributeDefinition(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new CreateAttributeDefinitionTabItem());
        }
    }));
    // remove button
    final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, buttonTranslation.deleteAttributeDefinition());
    deleteButton.setEnabled(false);
    deleteButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<AttributeDefinition> attrDefToBeDeleted = attrDef.getTableSelectedList();
            String text = "Following attribute definitions will be deleted.</p><p style=\"color: red;\">All stored values of such attributes will be deleted too!";
            UiElements.showDeleteConfirm(attrDefToBeDeleted, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < attrDefToBeDeleted.size(); i++) {
                        final int x = i;
                        DeleteAttribute request = new DeleteAttribute(JsonCallbackEvents.disableButtonEvents(deleteButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                // remove deleted attrs from table
                                attrDef.removeFromBackupTable(attrDefToBeDeleted.get(x));
                            }
                        }));
                        request.deleteAttributeDefinition(attrDefToBeDeleted.get(i).getId());
                    }
                }
            });
        }
    });
    tabMenu.addWidget(deleteButton);
    // filter box
    tabMenu.addFilterWidget(box, new PerunSearchEvent() {

        public void searchFor(String text) {
            attrDef.filterTable(text);
        }
    }, buttonTranslation.filterAttributeDefinition());
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    saveButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            final ArrayList<AttributeDefinition> list = attrDef.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                for (int i = 0; i < list.size(); i++) {
                    final int x = i;
                    UpdateAttribute request = new UpdateAttribute(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            attrDef.getSelectionModel().setSelected(list.get(x), false);
                        }
                    }));
                    request.updateAttribute(list.get(i));
                }
            }
        }
    });
    tabMenu.addWidget(saveButton);
    // if checkbox is checked only entityless attributes will be shown
    CheckBox showEntitylessBox = new CheckBox("Show only Entityless Attributes");
    showEntitylessBox.setValue(false);
    showEntitylessBox.addValueChangeHandler(valueChangeEvent -> {
        if (showEntitylessBox.getValue()) {
            attrDef.setEntity("entityless");
        } else {
            attrDef.setEntities(new HashSet<>());
        }
        attrDef.retrieveData();
    });
    tabMenu.addWidget(showEntitylessBox);
    // add menu to page
    mainPage.add(tabMenu);
    mainPage.setCellHeight(tabMenu, "30px");
    CellTable<AttributeDefinition> attrDefTable = attrDef.getTable(new FieldUpdater<AttributeDefinition, String>() {

        @Override
        public void update(int index, AttributeDefinition object, String value) {
            if (object.getEntity().equals("entityless")) {
                session.getTabManager().addTabToCurrentTab(new EntitylessAttributesDetailTabItem(object), true);
            } else {
                session.getTabManager().addTabToCurrentTab(new AttributeDefinitionDetailTabItem(object), true);
            }
        }
    });
    attrDefTable.setStyleName("perun-table");
    ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
    scrollTable.addStyleName("perun-tableScrollPanel");
    JsonUtils.addTableManagedButton(attrDef, attrDefTable, deleteButton);
    // put page into scroll panel
    mainPage.add(scrollTable);
    session.getUiElements().resizePerunTable(scrollTable, 350, this);
    this.contentWidget.setWidget(mainPage);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) UpdateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) EntitylessAttributesDetailTabItem(cz.metacentrum.perun.webgui.tabs.entitylessattributestabs.EntitylessAttributesDetailTabItem) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) DeleteAttribute(cz.metacentrum.perun.webgui.json.attributesManager.DeleteAttribute) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetAttributesDefinition(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition)

Example 3 with GetAttributesDefinition

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition 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, isRefreshParentOnClose());
        }
    }));
    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)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 GetAttributesDefinition (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition)3 ArrayList (java.util.ArrayList)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 AttributeDefinition (cz.metacentrum.perun.webgui.model.AttributeDefinition)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 JSONString (com.google.gwt.json.client.JSONString)1 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 DeleteAttribute (cz.metacentrum.perun.webgui.json.attributesManager.DeleteAttribute)1 UpdateAttribute (cz.metacentrum.perun.webgui.json.attributesManager.UpdateAttribute)1 AddRequiredAttribute (cz.metacentrum.perun.webgui.json.servicesManager.AddRequiredAttribute)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 EntitylessAttributesDetailTabItem (cz.metacentrum.perun.webgui.tabs.entitylessattributestabs.EntitylessAttributesDetailTabItem)1