Search in sources :

Example 46 with TabMenu

use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.

the class CreateAttributeDefinitionTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // creates HTML elements
    final ExtendedTextBox attributeDisplayName = new ExtendedTextBox();
    final ExtendedTextBox attributeName = new ExtendedTextBox();
    final ExtendedTextBox attributeDescription = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (attributeName.getTextBox().getText().trim().isEmpty()) {
                attributeName.setError("Name of attribute can't be empty.");
            } else if (!attributeName.getTextBox().getText().trim().matches(Utils.ATTRIBUTE_FRIENDLY_NAME_MATCHER)) {
                attributeName.setError("Name of attribute can contain only letters, numbers, dash and colon.");
            } else {
                attributeName.setOk();
                return true;
            }
            return false;
        }
    };
    final ExtendedTextBox.TextBoxValidator descriptionValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!attributeDescription.getTextBox().getText().trim().isEmpty()) {
                attributeDescription.setOk();
                return true;
            } else {
                attributeDescription.setError("Description of attribute can't be empty.");
                return false;
            }
        }
    };
    final ExtendedTextBox.TextBoxValidator displayNameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (!attributeDisplayName.getTextBox().getText().trim().isEmpty()) {
                attributeDisplayName.setOk();
                return true;
            } else {
                attributeDisplayName.setError("Display name of attribute can't be empty.");
                return false;
            }
        }
    };
    attributeName.setValidator(nameValidator);
    attributeDisplayName.setValidator(displayNameValidator);
    attributeDescription.setValidator(descriptionValidator);
    final ListBox entityListBox = new ListBox();
    final ListBox definitionListBox = new ListBox();
    final ListBox typeListBox = new ListBox();
    // fill listboxs with pre-defined values
    entityListBox.addItem("facility", "urn:perun:facility:");
    entityListBox.addItem("resource", "urn:perun:resource:");
    entityListBox.addItem("group", "urn:perun:group:");
    entityListBox.addItem("group_resource", "urn:perun:group_resource:");
    entityListBox.addItem("host", "urn:perun:host:");
    entityListBox.addItem("member", "urn:perun:member:");
    entityListBox.addItem("member_group", "urn:perun:member_group:");
    entityListBox.addItem("member_resource", "urn:perun:member_resource:");
    entityListBox.addItem("user", "urn:perun:user:");
    entityListBox.addItem("user_ext_source", "urn:perun:ues:");
    entityListBox.addItem("user_facility", "urn:perun:user_facility:");
    entityListBox.addItem("vo", "urn:perun:vo:");
    entityListBox.addItem("entityless", "urn:perun:entityless:");
    definitionListBox.addItem("def", "attribute-def:def");
    definitionListBox.addItem("opt", "attribute-def:opt");
    definitionListBox.addItem("virt", "attribute-def:virt");
    definitionListBox.addItem("core", "attribute-def:core");
    typeListBox.addItem("String", "java.lang.String");
    typeListBox.addItem("Integer", "java.lang.Integer");
    typeListBox.addItem("Boolean", "java.lang.Boolean");
    typeListBox.addItem("Array", "java.util.ArrayList");
    typeListBox.addItem("LinkedHashMap", "java.util.LinkedHashMap");
    typeListBox.addItem("LargeString", Utils.largeStringClassName);
    typeListBox.addItem("LargeArrayList", Utils.largeArrayListClassName);
    // prepare layout for this tab
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    TabMenu menu = new TabMenu();
    // BUTTONS
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, buttonTranslation.createAttributeDefinition());
    menu.addWidget(createButton);
    // close tab events & enable, disable buttons
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(createButton, this);
    createButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (nameValidator.validateTextBox() && descriptionValidator.validateTextBox() && displayNameValidator.validateTextBox()) {
                String displayName = attributeDisplayName.getTextBox().getText().trim();
                String friendlyName = attributeName.getTextBox().getText().trim();
                String description = attributeDescription.getTextBox().getText().trim();
                String namespace = entityListBox.getValue(entityListBox.getSelectedIndex()) + definitionListBox.getValue(definitionListBox.getSelectedIndex());
                String type = typeListBox.getValue(typeListBox.getSelectedIndex());
                CreateAttribute request = new CreateAttribute(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        AttributeDefinition a = jso.cast();
                        ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
                        AttributeRights right = AttributeRights.create(a.getId(), "SELF");
                        list.add(getRightsFromWidgets(selfRead, selfWrite, right));
                        AttributeRights right2 = AttributeRights.create(a.getId(), "VOADMIN");
                        list.add(getRightsFromWidgets(voRead, voWrite, right2));
                        AttributeRights right3 = AttributeRights.create(a.getId(), "GROUPADMIN");
                        list.add(getRightsFromWidgets(groupRead, groupWrite, right3));
                        AttributeRights right4 = AttributeRights.create(a.getId(), "FACILITYADMIN");
                        list.add(getRightsFromWidgets(facilityRead, facilityWrite, right4));
                        // after update - update rights
                        SetAttributeRights request = new SetAttributeRights(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                enableDisableWidgets(true);
                                closeTabEvents.onFinished(jso);
                            }

                            @Override
                            public void onLoadingStart() {
                                enableDisableWidgets(false);
                            }

                            @Override
                            public void onError(PerunError error) {
                                enableDisableWidgets(true);
                            }
                        }));
                        request.setAttributeRights(list);
                    }
                }));
                request.createAttributeDefinition(displayName, friendlyName, description, namespace, type);
            }
        }
    });
    // insert layout
    layout.setHTML(0, 0, "Friendly name:");
    layout.setWidget(0, 1, attributeName);
    layout.setHTML(1, 0, "Display name:");
    layout.setWidget(1, 1, attributeDisplayName);
    layout.setHTML(2, 0, "Description:");
    layout.setWidget(2, 1, attributeDescription);
    layout.setHTML(3, 0, "Entity:");
    layout.setWidget(3, 1, entityListBox);
    layout.setHTML(4, 0, "Definition type:");
    layout.setWidget(4, 1, definitionListBox);
    layout.setHTML(5, 0, "Value type:");
    layout.setWidget(5, 1, typeListBox);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");
    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>VO</strong>");
    rightsTable.setHTML(0, 3, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 4, "<strong>FACILITY</strong>");
    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");
    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, voRead);
    rightsTable.setWidget(2, 2, voWrite);
    rightsTable.setWidget(1, 3, groupRead);
    rightsTable.setWidget(2, 3, groupWrite);
    rightsTable.setWidget(1, 4, facilityRead);
    rightsTable.setWidget(2, 4, facilityWrite);
    rightsTable.addStyleName("centeredTable");
    vp.add(layout);
    vp.add(rightsTable);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) CreateAttribute(cz.metacentrum.perun.webgui.json.attributesManager.CreateAttribute) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.webgui.model.AttributeDefinition) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) 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) AttributeRights(cz.metacentrum.perun.webgui.model.AttributeRights) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SetAttributeRights(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributeRights)

Example 47 with TabMenu

use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.

the class SetNewAttributeTabItem method draw.

public Widget draw() {
    VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    // correct IDS for getting attrDefs
    if (ids.containsKey("resourceToGetServicesFrom")) {
        if (!ids.containsKey("resource")) {
            ids.put("resource", ids.get("resourceToGetServicesFrom"));
            ids.remove("resourceToGetServicesFrom");
        }
    }
    if (ids.containsKey("workWithUserAttributes")) {
        ids.remove("workWithUserAttributes");
    }
    if (ids.containsKey("workWithGroupAttributes")) {
        ids.remove("workWithGroupAttributes");
    }
    // set tab name
    String label = titleWidget.getText() + " (";
    for (Map.Entry<String, Integer> entry : ids.entrySet()) {
        label += entry.getKey() + ":" + String.valueOf(entry.getValue()) + " ";
    }
    label = label.substring(0, label.length() - 1) + ")";
    titleWidget.setText(label);
    // helper text
    String entityIds = "";
    for (Map.Entry<String, Integer> item : ids.entrySet()) {
        entityIds = entityIds.concat(" " + item.getKey() + ": " + item.getValue());
    }
    HTML helper = new HTML();
    String helperInside = "<p>Enter new values and press Enter key. Save changes by clicking on \"Save changes\" button. Values will be set for<strong>" + entityIds + ".</strong></p>";
    helper.setHTML(helperInside);
    // callback
    final GetAttributesDefinitionWithRights attrDef = new GetAttributesDefinitionWithRights(ids);
    // remove already used attributes from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            if (!inUse.isEmpty()) {
                for (Attribute a : inUse) {
                    attrDef.removeFromTable(a);
                }
            }
        }
    };
    attrDef.setEvents(localEvents);
    // filter core attributes
    attrDef.switchCore();
    // which entities to show
    Set<String> namespaces = getNamespacesForEntities(ids.keySet());
    // show only these attributes
    attrDef.setEntities(namespaces);
    // get table
    CellTable<Attribute> table = attrDef.getTable();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    // add save button
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    final CustomButton saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, buttonTranslation.saveNewAttributes());
    final JsonCallbackEvents events = JsonCallbackEvents.closeTabDisableButtonEvents(saveButton, tab);
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // Save the attributes
            ArrayList<Attribute> list = attrDef.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // separated list by entity
                ArrayList<Attribute> facilityList = new ArrayList<Attribute>();
                ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
                ArrayList<Attribute> userList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberGroupList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> resourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> hostList = new ArrayList<Attribute>();
                ArrayList<Attribute> voList = new ArrayList<Attribute>();
                ArrayList<Attribute> uesList = new ArrayList<Attribute>();
                for (Attribute a : list) {
                    if (a.getEntity().equalsIgnoreCase("facility")) {
                        facilityList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("user_facility")) {
                        userFacilityList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("resource")) {
                        resourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("user")) {
                        userList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member_resource")) {
                        memberResourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member")) {
                        memberList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("group")) {
                        groupList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("group_resource")) {
                        groupResourceList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("host")) {
                        hostList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("vo")) {
                        voList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("member_group")) {
                        memberGroupList.add(a);
                    } else if (a.getEntity().equalsIgnoreCase("ues")) {
                        uesList.add(a);
                    }
                }
                // GROUPING BY IDS
                // GROUPING BY IDS
                SetAttributes request = new SetAttributes(events);
                if (ids.size() == 4 && ids.containsKey("facility") && ids.containsKey("user") && ids.containsKey("member") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(userList);
                    sendList.addAll(memberResourceList);
                    sendList.addAll(userFacilityList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("facility") && ids.containsKey("user")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(userList);
                    sendList.addAll(userFacilityList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("member") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(memberResourceList);
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 2 && ids.containsKey("group") && ids.containsKey("resource")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(groupList);
                    sendList.addAll(groupResourceList);
                    // call proper method in RPC
                    ids.put("workWithGroupAttributes", 1);
                    request.setAttributes(ids, sendList);
                    ids.remove("workWithGroupAttributes");
                } else if (ids.size() == 2 && ids.containsKey("member") && ids.containsKey("user")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberList);
                    sendList.addAll(userList);
                    // call proper method in RPC
                    ids.put("workWithUserAttributes", 1);
                    request.setAttributes(ids, sendList);
                    ids.remove("workWithUserAttributes");
                } else if (ids.size() == 2 && ids.containsKey("group") && ids.containsKey("member")) {
                    ArrayList sendList = new ArrayList();
                    sendList.addAll(memberGroupList);
                    // call proper method in RPC
                    request.setAttributes(ids, sendList);
                } else if (ids.size() == 1 && ids.containsKey("group")) {
                    request.setAttributes(ids, groupList);
                } else if (ids.size() == 1 && ids.containsKey("resource")) {
                    request.setAttributes(ids, resourceList);
                } else if (ids.size() == 1 && ids.containsKey("facility")) {
                    request.setAttributes(ids, facilityList);
                } else if (ids.size() == 1 && ids.containsKey("vo")) {
                    request.setAttributes(ids, voList);
                } else if (ids.size() == 1 && ids.containsKey("host")) {
                    request.setAttributes(ids, hostList);
                } else if (ids.size() == 1 && ids.containsKey("member")) {
                    request.setAttributes(ids, memberList);
                } else if (ids.size() == 1 && ids.containsKey("user")) {
                    request.setAttributes(ids, userList);
                } else if (ids.size() == 1 && ids.containsKey("userExtSource")) {
                    request.setAttributes(ids, uesList);
                } else {
                    String combination = "";
                    for (String key : ids.keySet()) {
                        combination += key + ": " + ids.get(key) + " | ";
                    }
                    UiElements.generateAlert("Wrong entities combination", "Unsupported combination of attributes to set: " + combination);
                }
            }
        }
    });
    menu.addWidget(saveButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addWidget(helper);
    mainTab.add(menu);
    mainTab.setCellHeight(menu, "30px");
    // table wrapper
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // do not resize like perun table to prevent wrong width in inner tab
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    // add table to the page
    mainTab.add(sp);
    //saveButton.setEnabled(false);
    //JsonUtils.addTableManagedButton(attrDef, table, saveButton);
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) GetAttributesDefinitionWithRights(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesDefinitionWithRights) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) 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)

Example 48 with TabMenu

use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.

the class AddAuthorTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add author");
    this.users = new FindCompleteRichUsers("", null);
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // PUB-INFO
    TabMenu info = new TabMenu();
    info.addWidget(new HTML("<strong>FULL&nbsp;CITE: </strong>" + publication.getMain()));
    firstTabPanel.add(info);
    // HORIZONTAL MENU
    TabMenu tabMenu = new TabMenu();
    // get the table
    final CellTable<User> table;
    if (session.isPerunAdmin()) {
        table = users.getTable(new FieldUpdater<User, String>() {

            public void update(int index, User object, String value) {
                session.getTabManager().addTab(new UserDetailTabItem(object));
            }
        });
    } else {
        table = users.getTable();
    }
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected user(s) as author(s) of publication: " + publication.getTitle());
    tabMenu.addWidget(addButton);
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(users, table, addButton);
    final TabItem tab = this;
    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<User> list = users.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // proceed
                for (int i = 0; i < list.size(); i++) {
                    final String name = list.get(i).getFullNameWithTitles();
                    // add name events
                    JsonCallbackEvents authorshipEvents = new JsonCallbackEvents() {

                        public void onFinished(JavaScriptObject jso) {
                            updateAlreadyAdded(name);
                        }
                    };
                    // merge with refresh?
                    if (i == list.size() - 1 && events != null) {
                        authorshipEvents = JsonCallbackEvents.mergeEvents(authorshipEvents, events);
                    }
                    // call
                    CreateAuthorship request = new CreateAuthorship(JsonCallbackEvents.disableButtonEvents(addButton, authorshipEvents));
                    request.createAuthorship(publicationId, list.get(i).getId());
                    if (i == list.size() - 1) {
                        users.clearTableSelectedSet();
                    }
                }
            }
        }
    });
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // trigger refresh of sub-tab via event
            events.onFinished(null);
            session.getTabManager().closeTab(tab, false);
        }
    }));
    tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            users.searchFor(text);
            searchString = text;
        }
    }, ButtonTranslation.INSTANCE.searchUsers());
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // add already added
    firstTabPanel.add(alreadyAddedAuthors);
    firstTabPanel.setCellHeight(alreadyAddedAuthors, "30px");
    // add table to the main panel
    firstTabPanel.add(sp);
    // do not resize like perun table to prevent wrong width in inner tab
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) User(cz.metacentrum.perun.webgui.model.User) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CreateAuthorship(cz.metacentrum.perun.webgui.json.cabinetManager.CreateAuthorship) FindCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) 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)

Example 49 with TabMenu

use of cz.metacentrum.perun.webgui.widgets.TabMenu 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)

Example 50 with TabMenu

use of cz.metacentrum.perun.webgui.widgets.TabMenu in project perun by CESNET.

the class FacilitiesSelectTabItem method draw.

public Widget draw() {
    // MAIN PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // TAB MENU
    TabMenu tabMenu = new TabMenu();
    // get RICH facilities request
    final GetFacilities facilities = new GetFacilities(true);
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(facilities);
    // retrieve data (table)
    final CellTable<Facility> table = facilities.getTable(new FieldUpdater<Facility, String>() {

        public void update(int index, Facility object, String value) {
            session.getTabManager().addTab(new FacilityDetailTabItem(object));
        }
    });
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // add new facility button
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, true, ButtonTranslation.INSTANCE.createFacility(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTab(new CreateFacilityTabItem(facilities.getFullBackupList(), events));
        }
    }));
    // add delete facilities button
    final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteFacilities());
    if (session.isPerunAdmin()) {
        tabMenu.addWidget(deleteButton);
    }
    deleteButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            final ArrayList<Facility> list = facilities.getTableSelectedList();
            String text = "Following facilities will be deleted.";
            UiElements.showDeleteConfirm(list, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < list.size(); i++) {
                        if (i == list.size() - 1) {
                            DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton, events));
                            request.deleteFacility(list.get(i).getId());
                        } else {
                            DeleteFacility request = new DeleteFacility(JsonCallbackEvents.disableButtonEvents(deleteButton));
                            request.deleteFacility(list.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    // filter box
    tabMenu.addFilterWidget(new ExtendedSuggestBox(facilities.getOracle()), new PerunSearchEvent() {

        public void searchFor(String text) {
            facilities.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterFacilities());
    tabMenu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
    tabMenu.addWidget(new HTML("<strong>Please select Facility you want to manage.</strong>"));
    deleteButton.setEnabled(false);
    JsonUtils.addTableManagedButton(facilities, table, deleteButton);
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu and the table to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    firstTabPanel.add(sp);
    firstTabPanel.setCellHeight(sp, "100%");
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) DeleteFacility(cz.metacentrum.perun.webgui.json.facilitiesManager.DeleteFacility) GetFacilities(cz.metacentrum.perun.webgui.json.facilitiesManager.GetFacilities) 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) DeleteFacility(cz.metacentrum.perun.webgui.json.facilitiesManager.DeleteFacility) Facility(cz.metacentrum.perun.webgui.model.Facility)

Aggregations

TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)143 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)124 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)124 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)115 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)99 ArrayList (java.util.ArrayList)89 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)68 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)67 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)48 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)33 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)27 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)27 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)27 PerunError (cz.metacentrum.perun.webgui.model.PerunError)27 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)21 HashMap (java.util.HashMap)20 User (cz.metacentrum.perun.webgui.model.User)18 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)17 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)17 Attribute (cz.metacentrum.perun.webgui.model.Attribute)15