Search in sources :

Example 16 with TabMenu

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

the class FacilitiesTabItem method draw.

public Widget draw() {
    // MAIN PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // TAB MENU
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // get RICH facilities request
    final GetFacilities facilities = new GetFacilities(true);
    // 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));
        }
    });
    // 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());
        }
    }));
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(facilities);
    // add delete facilities button
    final CustomButton deleteButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteFacilities());
    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());
    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) FacilityDetailTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem) 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) CreateFacilityTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.CreateFacilityTabItem) DeleteFacility(cz.metacentrum.perun.webgui.json.facilitiesManager.DeleteFacility) Facility(cz.metacentrum.perun.webgui.model.Facility)

Example 17 with TabMenu

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

the class GroupResourceRequiredAttributesTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings for " + Utils.getStrippedStringWithEllipsis(resource.getName()));
    if (JsonUtils.isExtendedInfoVisible()) {
        columnId = 3;
    } else {
        columnId = 2;
    }
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    final Label facilityId = new Label();
    JsonCallbackEvents events = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            Facility fac = (Facility) jso;
            facilityId.setText(String.valueOf(fac.getId()));
        }
    };
    GetFacility facility = new GetFacility(resourceId, events);
    facility.retrieveData();
    mainTab.add(new HTML("<hr size=\"2px\" />"));
    // set attributes type to group_resource
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resourceToGetServicesFrom", resourceId);
    ids.put("group", groupId);
    // gets all required group attributes for specified group and resource
    final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
    final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
    reqAttrsTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    // get all required group_resource attributes too
    ids.put("resource", resourceId);
    reqAttrs.setIds(ids);
    reqAttrs.retrieveData();
    final ListBoxWithObjects<RichMember> listBox = new ListBoxWithObjects<RichMember>();
    listBox.setTitle(WidgetTranslation.INSTANCE.selectingMember());
    // local event fills the listBox
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
            mems = new TableSorter<RichMember>().sortByName(mems);
            listBox.addNotSelectedOption();
            for (int i = 0; i < mems.size(); i++) {
                listBox.addItem(mems.get(i));
            }
            listBox.addAllOption();
        }
    };
    final GetGroupRichMembers getGroupRichMembers = new GetGroupRichMembers(groupId, localEvents);
    getGroupRichMembers.retrieveData();
    reqAttrsTable.addStyleName("perun-table");
    final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
    sp.addStyleName("perun-tableScrollPanel");
    // store for column with values
    final Column<Attribute, ?> columnStore = reqAttrsTable.getColumn(columnId);
    listBox.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            int selectedIndex = listBox.getSelectedIndex();
            // no member selected
            if (selectedIndex == 0) {
                // offer just group and group resource attributes
                reqAttrs.clearTable();
                ids.clear();
                ids.put("resourceToGetServicesFrom", resourceId);
                // get groups attributes
                ids.put("group", groupId);
                reqAttrs.setIds(ids);
                reqAttrs.retrieveData();
                // get group_resource attributes
                ids.put("resource", resourceId);
                reqAttrs.setIds(ids);
                reqAttrs.retrieveData();
                reqAttrs.sortTable();
            // some member is selected
            } else {
                reqAttrs.clearTable();
                ids.clear();
                ids.put("resourceToGetServicesFrom", resourceId);
                // get member, member-resource, user, user-facility  attributes
                ids.put("member", listBox.getSelectedObject().getId());
                ids.put("resource", resourceId);
                // to get user, user-facility attrs
                ids.put("workWithUserAttributes", 1);
                reqAttrs.setIds(ids);
                reqAttrs.retrieveData();
                // all members are selected
                if (selectedIndex == 1) {
                    // remove value column
                    reqAttrsTable.removeColumn(columnId);
                    // create own value column
                    // Value column
                    Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {

                        public Attribute getValue(Attribute attribute) {
                            attribute.setValueAsJso(null);
                            return attribute;
                        }
                    }, new FieldUpdater<Attribute, Attribute>() {

                        public void update(int index, Attribute object, Attribute value) {
                            object = value;
                            reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
                        }
                    });
                    // add to table
                    reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
                } else {
                    // member selected
                    // return original column
                    reqAttrsTable.removeColumn(columnId);
                    reqAttrsTable.insertColumn(columnId, columnStore, "Value");
                }
            }
        }
    });
    CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // send lists
                ArrayList<Attribute> groupList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberList = new ArrayList<Attribute>();
                ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
                ArrayList<Attribute> userList = new ArrayList<Attribute>();
                ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
                SetAttributes request = new SetAttributes();
                int selectedIndex = listBox.getSelectedIndex();
                // if all selected
                if (selectedIndex == 1) {
                    // TODO - USE NEW CONFIRM DESIGN
                    if (!Window.confirm("Same values for selected attributes will be set to all members in group." + "\n\nDo you want to continue ?")) {
                        return;
                    }
                }
                // get different attributes
                for (Attribute attr : list) {
                    if (attr.getNamespace().contains("urn:perun:group:")) {
                        groupList.add(attr);
                    } else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
                        groupResourceList.add(attr);
                    } else if (attr.getNamespace().contains("urn:perun:member:")) {
                        memberList.add(attr);
                    } else if (attr.getNamespace().contains("urn:perun:member_resource:")) {
                        memberResourceList.add(attr);
                    } else if (attr.getNamespace().contains("urn:perun:user:")) {
                        userList.add(attr);
                    } else if (attr.getNamespace().contains("urn:perun:user_facility:")) {
                        userFacilityList.add(attr);
                    }
                }
                // if not empty, send request
                if (!(groupList.isEmpty())) {
                    ids.clear();
                    ids.put("group", groupId);
                    request.setAttributes(ids, groupList);
                }
                if (!(groupResourceList.isEmpty())) {
                    ids.clear();
                    ids.put("group", groupId);
                    ids.put("resource", resourceId);
                    request.setAttributes(ids, groupResourceList);
                }
                if (!(memberList.isEmpty())) {
                    if (selectedIndex == 1) {
                        // for all members
                        for (int i = 0; i < listBox.getItemCount(); i++) {
                            ids.clear();
                            ids.put("member", (listBox.getObjectAt(i)).getId());
                            request.setAttributes(ids, memberList);
                        }
                    } else {
                        // for one member
                        ids.clear();
                        ids.put("member", listBox.getSelectedObject().getId());
                        request.setAttributes(ids, memberList);
                    }
                }
                if (!(memberResourceList.isEmpty())) {
                    if (selectedIndex == 1) {
                        // for all members
                        for (int i = 0; i < listBox.getItemCount(); i++) {
                            ids.clear();
                            ids.put("resource", resourceId);
                            ids.put("member", (listBox.getObjectAt(i)).getId());
                            request.setAttributes(ids, memberResourceList);
                        }
                    } else {
                        // for one member
                        ids.clear();
                        ids.put("resource", resourceId);
                        ids.put("member", listBox.getSelectedObject().getId());
                        request.setAttributes(ids, memberResourceList);
                    }
                }
                if (!(userList.isEmpty())) {
                    if (selectedIndex == 1) {
                        // for all members
                        for (int i = 0; i < listBox.getItemCount(); i++) {
                            ids.clear();
                            ids.put("user", (listBox.getObjectAt(i)).getUser().getId());
                            request.setAttributes(ids, userList);
                        }
                    } else {
                        // for one member
                        ids.clear();
                        ids.put("user", listBox.getSelectedObject().getUser().getId());
                        request.setAttributes(ids, userList);
                    }
                }
                if (!(userFacilityList.isEmpty())) {
                    if (selectedIndex == 1) {
                        // for all members
                        for (int i = 0; i < listBox.getItemCount(); i++) {
                            ids.clear();
                            ids.put("user", listBox.getObjectAt(i).getUser().getId());
                            ids.put("facility", Integer.parseInt(facilityId.getText()));
                            request.setAttributes(ids, userFacilityList);
                        }
                    } else {
                        // for one member
                        ids.clear();
                        ids.put("user", listBox.getSelectedObject().getUser().getId());
                        ids.put("facility", Integer.parseInt(facilityId.getText()));
                        request.setAttributes(ids, userFacilityList);
                    }
                }
                reqAttrs.clearTableSelectedSet();
            }
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        saveChangesButton.setEnabled(false);
    menu.addWidget(new HTML("<strong>Group members:</strong>"));
    menu.addWidget(listBox);
    // table content
    session.getUiElements().resizePerunTable(sp, 350, this);
    mainTab.add(menu);
    mainTab.add(sp);
    mainTab.setCellHeight(sp, "100%");
    mainTab.setCellHeight(menu, "30px");
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Column(com.google.gwt.user.cellview.client.Column) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetFacility(cz.metacentrum.perun.webgui.json.resourcesManager.GetFacility) PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetResourceRequiredAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetResourceRequiredAttributesV2) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetFacility(cz.metacentrum.perun.webgui.json.resourcesManager.GetFacility) GetGroupRichMembers(cz.metacentrum.perun.webgui.json.groupsManager.GetGroupRichMembers)

Example 18 with TabMenu

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

the class GroupResourcesTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": " + "resources");
    // main panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    // get VO resources
    final GetAssignedRichResources resources = new GetAssignedRichResources(groupId, PerunEntity.GROUP);
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        resources.setCheckable(false);
    // custom events for viewResource
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(resources);
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeGroupFromSelectedResources());
    // add / remove resource from group can be done by vo / perun admin only.
    if (session.isVoAdmin(group.getVoId())) {
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.assignGroupToResources(), new ClickHandler() {

            public void onClick(ClickEvent event) {
                session.getTabManager().addTabToCurrentTab(new AssignGroupTabItem(group, resources.getList()), true);
            }
        }));
        removeButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                final ArrayList<RichResource> toRemove = resources.getTableSelectedList();
                String text = "Following resources will be removed from group and it's members won't have access to them anymore.";
                UiElements.showDeleteConfirm(toRemove, text, new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent clickEvent) {
                        RemoveGroupFromResources request = new RemoveGroupFromResources(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                        request.removeGroupFromResources(group, toRemove);
                    }
                });
            }
        });
        menu.addWidget(removeButton);
    }
    // filter box
    menu.addFilterWidget(new ExtendedSuggestBox(resources.getOracle()), new PerunSearchEvent() {

        public void searchFor(String text) {
            resources.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterResources());
    // add menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<RichResource> table;
    // perun / vo admin can set attributes
    if (session.isVoAdmin(group.getVoId()) || session.isVoObserver(group.getVoId())) {
        table = resources.getTable(new FieldUpdater<RichResource, String>() {

            public void update(int index, RichResource object, String value) {
                session.getTabManager().addTab(new ResourceDetailTabItem(object, 0));
            }
        });
    } else {
        table = resources.getTable();
    }
    removeButton.setEnabled(false);
    if (session.isGroupAdmin(groupId) || session.isVoAdmin(group.getVoId()))
        JsonUtils.addTableManagedButton(resources, table, removeButton);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) RichResource(cz.metacentrum.perun.webgui.model.RichResource) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) RemoveGroupFromResources(cz.metacentrum.perun.webgui.json.resourcesManager.RemoveGroupFromResources) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetAssignedRichResources(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedRichResources) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) ResourceDetailTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem)

Example 19 with TabMenu

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

the class GroupsResourceRequiredAttributesTabItem method draw.

public Widget draw() {
    if (groups == null || groups.get(0) == null) {
        Window.alert("No groups in list.");
    }
    if (JsonUtils.isExtendedInfoVisible()) {
        columnId = 3;
    } else {
        columnId = 2;
    }
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    mainTab.add(new HTML("<hr size=\"2px\" />"));
    // set attributes type to group_resource
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resourceToGetServicesFrom", resourceId);
    ids.put("group", groups.get(0).getId());
    // gets all required group attributes for specified group and resource
    final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
    final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
    // remove value column
    reqAttrsTable.removeColumn(columnId);
    // create own value column
    Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {

        public Attribute getValue(Attribute attribute) {
            // set empty value
            attribute.setValueAsJso(null);
            return attribute;
        }
    }, new FieldUpdater<Attribute, Attribute>() {

        public void update(int index, Attribute object, Attribute value) {
            object = value;
            reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
        }
    });
    // add to table
    reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
    // get all required group_resource attributes too
    ids.put("resource", resourceId);
    reqAttrs.setIds(ids);
    reqAttrs.retrieveData();
    reqAttrsTable.addStyleName("perun-table");
    final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
    sp.addStyleName("perun-tableScrollPanel");
    CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                ArrayList<Attribute> groupList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
                SetAttributes request = new SetAttributes();
                // TODO - use new confirm dialog
                if (!Window.confirm("Same values for selected attributes will be set to all groups you are about to assign." + "\n\nDo you want to continue ?")) {
                    return;
                }
                // get different attributes
                for (Attribute attr : list) {
                    if (attr.getNamespace().contains("urn:perun:group:")) {
                        groupList.add(attr);
                    } else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
                        groupResourceList.add(attr);
                    }
                }
                if (!(groupList.isEmpty())) {
                    ids.clear();
                    for (int i = 0; i < groups.size(); i++) {
                        ids.put("group", groups.get(i).getId());
                        request.setAttributes(ids, groupList);
                    }
                }
                if (!(groupResourceList.isEmpty())) {
                    ids.clear();
                    ids.put("resource", resourceId);
                    for (int i = 0; i < groups.size(); i++) {
                        ids.put("group", groups.get(i).getId());
                        request.setAttributes(ids, groupResourceList);
                    }
                }
                reqAttrs.clearTableSelectedSet();
            }
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    if (!session.isGroupAdmin() && !session.isVoAdmin())
        saveChangesButton.setEnabled(false);
    // table content
    session.getUiElements().resizePerunTable(sp, 350, this);
    mainTab.add(menu);
    mainTab.add(sp);
    mainTab.setCellHeight(sp, "100%");
    mainTab.setCellHeight(menu, "30px");
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetResourceRequiredAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetResourceRequiredAttributesV2) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 20 with TabMenu

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

the class GroupRelationsTabItem method draw.

@Override
public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": unions");
    // main panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // if members group, hide
    if (group.isCoreGroup()) {
        vp.add(new HTML("<h2>Members group cannot have unions.</h2>"));
        this.contentWidget.setWidget(vp);
        return getWidget();
    }
    final GetGroupUnions unions = new GetGroupUnions(group, false);
    // Events for reloading when group is created
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(unions);
    // menu
    TabMenu menu = new TabMenu();
    final CheckBox subGroupsCheckBox = new CheckBox("Show sub-groups");
    final ListBox reverseDropdown = new ListBox();
    reverseDropdown.addItem("Normal");
    reverseDropdown.addItem("Reverse");
    reverseDropdown.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            switch(reverseDropdown.getSelectedIndex()) {
                case 1:
                    unions.setReverseAndRefresh(true);
                    subGroupsCheckBox.setVisible(false);
                    break;
                default:
                    unions.setReverseAndRefresh(false);
                    subGroupsCheckBox.setVisible(true);
            }
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addGroupUnion(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            // creates a new form
            session.getTabManager().addTabToCurrentTab(new AddGroupUnionTabItem(group), true);
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId())) {
        createButton.setEnabled(false);
        unions.setCheckable(false);
    }
    menu.addWidget(createButton);
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeGroupUnion());
    removeButton.addClickHandler(new ClickHandler() {

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

                @Override
                public void onClick(ClickEvent clickEvent) {
                    RemoveGroupUnions request = new RemoveGroupUnions(JsonCallbackEvents.disableButtonEvents(removeButton, events));
                    if (unions.isReverse()) {
                        request.deleteGroupUnions(itemsToRemove, group);
                    } else {
                        request.deleteGroupUnions(group, itemsToRemove);
                    }
                }
            });
        }
    });
    menu.addWidget(removeButton);
    // filter box
    final ExtendedSuggestBox box = new ExtendedSuggestBox(unions.getOracle());
    menu.addFilterWidget(box, new PerunSearchEvent() {

        public void searchFor(String text) {
            unions.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterGroup());
    subGroupsCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            unions.setShowSubgroupsAndRefresh(valueChangeEvent.getValue(), box.getSuggestBox().getText());
        }
    });
    menu.addWidget(new HTML("<strong>Direction: </strong>"));
    menu.addWidget(reverseDropdown);
    menu.addWidget(subGroupsCheckBox);
    // add menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<Group> table = unions.getTable(new FieldUpdater<Group, String>() {

        @Override
        public void update(int arg0, Group group, String arg2) {
            if (session.isGroupAdmin(group.getId()) || session.isVoAdmin(group.getId())) {
                session.getTabManager().addTab(new GroupDetailTabItem(group.getId()));
            } else {
                UiElements.generateInfo("Not privileged", "You are not manager of selected group or its VO.");
            }
        }
    });
    removeButton.setEnabled(false);
    if (session.isGroupAdmin(groupId) || session.isVoAdmin(group.getVoId()))
        JsonUtils.addTableManagedButton(unions, table, removeButton);
    // adds the table into the panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) HTML(com.google.gwt.user.client.ui.HTML) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) RemoveGroupUnions(cz.metacentrum.perun.webgui.json.groupsManager.RemoveGroupUnions) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) CheckBox(com.google.gwt.user.client.ui.CheckBox) GetGroupUnions(cz.metacentrum.perun.webgui.json.groupsManager.GetGroupUnions) ListBox(com.google.gwt.user.client.ui.ListBox) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

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