Search in sources :

Example 11 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition 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 12 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.

the class PerunSearchParametersWidget method addParameter.

/**
 * Adds a parameter
 */
protected void addParameter() {
    TextBox tb = new TextBox();
    final ListBoxWithObjects<AttributeDefinition> lb = new ListBoxWithObjects<AttributeDefinition>();
    inputs.put(lb, tb);
    lb.addAllItems(availableAttrDefs);
    rebuild();
}
Also used : AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) TextBox(com.google.gwt.user.client.ui.TextBox)

Example 13 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition in project perun by CESNET.

the class PerunSearchParametersWidget method rebuild.

/**
 * Method which rebuild whole searcher widget when number of params changes
 */
protected void rebuild() {
    ft.clear();
    // ft.setHTML(0, 0, "<h3>" + "Search by parameters:" + "</h3>");
    // ft.getFlexCellFormatter().setColSpan(0, 0, 4);
    int row = 1;
    for (Map.Entry<ListBoxWithObjects<AttributeDefinition>, TextBox> entry : inputs.entrySet()) {
        final ListBoxWithObjects<AttributeDefinition> lb = entry.getKey();
        int selectedItem = lb.getSelectedIndex();
        lb.clear();
        lb.addAllItems(availableAttrDefs);
        lb.setSelectedIndex(selectedItem);
        CustomButton rb = new CustomButton("", SmallIcons.INSTANCE.deleteIcon());
        ft.setWidget(row, 0, lb);
        ft.setText(row, 1, "=");
        ft.setWidget(row, 2, entry.getValue());
        ft.setWidget(row, 3, rb);
        if (inputs.entrySet().size() <= 1) {
            // allow remove if more than 1
            rb.setEnabled(false);
            rb.setTitle("Enabled only when more than 1 parameter is used.");
        }
        rb.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent clickEvent) {
                inputs.keySet().remove(lb);
                rebuild();
            }
        });
        row++;
    }
    ft.setWidget(row, 0, addParameterButton);
    ft.setHTML(row, 1, "");
    ft.setWidget(row, 2, searchButton);
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) TextBox(com.google.gwt.user.client.ui.TextBox) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with AttributeDefinition

use of cz.metacentrum.perun.webgui.model.AttributeDefinition 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

AttributeDefinition (cz.metacentrum.perun.webgui.model.AttributeDefinition)14 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)5 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)4 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)4 ArrayList (java.util.ArrayList)4 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)3 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)2 TextBox (com.google.gwt.user.client.ui.TextBox)2 GetAttributesDefinition (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinition)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 PerunAttributeFriendlyNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeFriendlyNameCell)2 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 TextInputCell (com.google.gwt.cell.client.TextInputCell)1 Column (com.google.gwt.user.cellview.client.Column)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1