Search in sources :

Example 51 with Attribute

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

the class RichUserComparator method compareByOrganization.

/**
	 * Compares RichMembers by organizations
	 * @param o1
	 * @param o2
	 * @return
	 */
private int compareByOrganization(User o1, User o2) {
    Attribute at1 = o1.getAttribute("urn:perun:user:attribute-def:def:organization");
    Attribute at2 = o2.getAttribute("urn:perun:user:attribute-def:def:organization");
    String at1value = "";
    String at2value = "";
    if (at1 != null && at1.getValue() != null && !"null".equalsIgnoreCase(at1.getValue())) {
        at1value = at1.getValue();
    }
    if (at2 != null && at2.getValue() != null && !"null".equalsIgnoreCase(at2.getValue())) {
        at2value = at2.getValue();
    }
    return Collator.getInstance().compare(at1value, at2value);
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 52 with Attribute

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

the class FacilitySettingsTabItem method draw.

public Widget draw() {
    // set title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Service settings");
    // content
    vp.setSize("100%", "100%");
    vp.clear();
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    // Get Attributes method
    final GetRequiredAttributesV2 reqAttrs = new GetRequiredAttributesV2();
    final GetAttributesV2 attrs = new GetAttributesV2();
    attrs.getFacilityAttributes(facilityId);
    // get empty table
    final CellTable<Attribute> table = reqAttrs.getEmptyTable();
    final CellTable<Attribute> table2 = attrs.getEmptyTable();
    sp.setWidget(table);
    sp2.setWidget(table2);
    // ids to retrieve data from rpc
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("facility", facility.getId());
    // service switcher checkbox
    final CheckBox switchServicesChb = new CheckBox(WidgetTranslation.INSTANCE.offerAvailableServicesOnly(), false);
    // selected by default - unselected if switch hidden
    switchServicesChb.setValue(lastCheckBoxValue);
    switchServicesChb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
    // services listbox
    final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
    // on change of service update table
    servList.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            if (servList.getSelectedIndex() == 0) {
                // show all facility attributes
                attrs.retrieveData();
                setTable(false);
                lastServiceId = 0;
                indexInList = 0;
                return;
            }
            if (switchServicesChb.getValue() == true && servList.getSelectedIndex() == 1) {
                // show required attrs for all assigned services
                ids.remove("service");
                lastServiceId = 0;
                indexInList = 1;
            } else if ((switchServicesChb.getValue() == true && servList.getSelectedIndex() > 1) || (switchServicesChb.getValue() == false && servList.getSelectedIndex() > 0)) {
                // show required attrs for selected service
                // >0 when listing all services
                // >1 when listing assigned services
                ids.put("service", servList.getSelectedObject().getId());
                lastServiceId = servList.getSelectedObject().getId();
            }
            // load req attrs
            reqAttrs.setIds(ids);
            reqAttrs.clearTable();
            reqAttrs.retrieveData();
            setTable(true);
        }
    });
    // event which fills the listbox and call getRequiredAttributes
    final JsonCallbackEvents event = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            servList.clear();
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            for (int i = 0; i < srv.size(); i++) {
                servList.addItem(srv.get(i));
            }
            // no services available - load all facility attrs
            if (servList.isEmpty()) {
                servList.addNotSelectedOption();
                lastServiceId = 0;
                indexInList = 0;
                attrs.retrieveData();
                setTable(false);
                return;
            }
            // offer only available
            if (switchServicesChb.getValue() == true) {
                servList.addNotSelectedOption();
                servList.addAllOption();
                if (lastServiceId == 0) {
                    if (indexInList == 1) {
                        // all
                        servList.setSelectedIndex(1);
                    } else if (indexInList == 0) {
                        // not selected - load all fac attrs
                        servList.setSelectedIndex(0);
                        attrs.retrieveData();
                        setTable(false);
                        return;
                    }
                }
            } else {
                // offer all services
                servList.addNotSelectedOption();
                if (lastServiceId == 0) {
                    // if no service selected, load all fac attrs
                    servList.setSelectedIndex(0);
                    attrs.retrieveData();
                    setTable(false);
                    return;
                }
            }
            // if some service was selected
            if (lastServiceId != 0) {
                // remove service since we can't be sure, it was loaded again
                ids.remove("service");
                // either all or first service in a list
                servList.setSelectedIndex(1);
                for (Service s : servList.getAllObjects()) {
                    if (s.getId() == lastServiceId) {
                        // if found, select it
                        servList.setSelected(s, true);
                        ids.put("service", lastServiceId);
                        break;
                    }
                }
            }
            // get required attrs for service
            reqAttrs.clearTable();
            reqAttrs.setIds(ids);
            reqAttrs.retrieveData();
            setTable(true);
        }

        @Override
        public void onError(PerunError error) {
            servList.clear();
            if (required) {
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
            } else {
                ((AjaxLoaderImage) table2.getEmptyTableWidget()).loadingError(error);
            }
            servList.addItem("Error while loading");
        }

        @Override
        public void onLoadingStart() {
            servList.removeAllOption();
            servList.removeNotSelectedOption();
            servList.clear();
            servList.addItem("Loading...");
        }
    };
    final GetServices allServices = new GetServices(event);
    final GetFacilityAssignedServices assignedServices = new GetFacilityAssignedServices(facility.getId(), event);
    // if hide and unchecked or just unchecked
    if (!lastCheckBoxValue) {
        allServices.retrieveData();
    } else {
        assignedServices.retrieveData();
    }
    // Save changes button
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    final JsonCallbackEvents refreshEvents = JsonCallbackEvents.refreshTableEvents(reqAttrs);
    final JsonCallbackEvents refreshEvents2 = JsonCallbackEvents.refreshTableEvents(attrs);
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents);
    final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshEvents2);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
                request.setAttributes(ids, list);
            }
        }
    });
    // Remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents);
    final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvents2);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = (required) ? reqAttrs.getTableSelectedList() : attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("facility", facilityId);
                RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
                request.removeAttributes(ids, list);
            }
        }
    });
    // switch serv checkbox
    switchServicesChb.addClickHandler(new ClickHandler() {

        // load proper set of services on click
        public void onClick(ClickEvent event) {
            lastCheckBoxValue = switchServicesChb.getValue();
            if (switchServicesChb.getValue() == true) {
                assignedServices.retrieveData();
            } else {
                allServices.retrieveData();
            }
        }
    });
    // allow to set new (currently unused facility attribute)
    CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("facility", facility.getId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, (required) ? reqAttrs.getList() : attrs.getList()), true);
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    menu.addWidget(setNewAttributeButton);
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Service: </strong>"));
    menu.addWidget(servList);
    if (!hide) {
        menu.addWidget(switchServicesChb);
    }
    /* TODO - not yet implemented

			 CustomButton fillDefaultButton = new CustomButton("Fill default values", SmallIcons.INSTANCE.scriptGoIcon(), new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });
			 fillDefaultButton.setTitle("Fill default values for this service/facility - nothing is saved unless you click on 'Save changes'");
			 CustomButton checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon(), new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });
			 checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");

			 menu.addWidget(fillDefaultButton);
			 menu.addWidget(checkValuesButton);

*/
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    table.setWidth("100%");
    table2.addStyleName("perun-table");
    table2.setWidth("100%");
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    sp2.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp2, 350, this);
    // add menu and the table to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // default is required attributes
    setTable(true);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) Attribute(cz.metacentrum.perun.webgui.model.Attribute) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) GetServices(cz.metacentrum.perun.webgui.json.servicesManager.GetServices) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetRequiredAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetRequiredAttributesV2) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) Service(cz.metacentrum.perun.webgui.model.Service) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) GetFacilityAssignedServices(cz.metacentrum.perun.webgui.json.servicesManager.GetFacilityAssignedServices) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 53 with Attribute

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

the class FacilityHostsSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts settings");
    // main panel
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    final GetAttributesV2 attrs = new GetAttributesV2();
    final ListBoxWithObjects<Host> listbox = new ListBoxWithObjects<Host>();
    // refresh attributes for hosts
    listbox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            if (listbox.getSelectedObject() != null) {
                lastSelectedHostId = listbox.getSelectedObject().getId();
                attrs.getHostAttributes(lastSelectedHostId);
                attrs.retrieveData();
            } else {
                lastSelectedHostId = 0;
            }
        }
    });
    // retrieve hosts
    final GetHosts hosts = new GetHosts(facilityId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            listbox.clear();
            ArrayList<Host> result = JsonUtils.jsoAsList(jso);
            if (result != null && !result.isEmpty()) {
                for (Host h : result) {
                    listbox.addItem(h);
                    if (h.getId() == lastSelectedHostId) {
                        listbox.setSelected(h, true);
                    }
                }
                if (lastSelectedHostId == 0) {
                    lastSelectedHostId = listbox.getSelectedObject().getId();
                }
                attrs.getHostAttributes(lastSelectedHostId);
                attrs.retrieveData();
            }
        }

        @Override
        public void onError(PerunError error) {
            listbox.clear();
            listbox.addItem("Error while loading");
        }

        @Override
        public void onLoadingStart() {
            listbox.clear();
            listbox.addItem("Loading...");
        }
    });
    hosts.retrieveData();
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(attrs);
    // menu
    TabMenu menu = new TabMenu();
    // Save changes button
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, events);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("host", lastSelectedHostId);
                SetAttributes request = new SetAttributes(saveChangesButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    // Remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("host", lastSelectedHostId);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("host", lastSelectedHostId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attrs.getList()), true);
        }
    }));
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Select host:</strong>"));
    menu.addWidget(listbox);
    // attrs table
    CellTable<Attribute> table = attrs.getEmptyTable();
    // 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(menu);
    firstTabPanel.setCellHeight(menu, "30px");
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) 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) GetHosts(cz.metacentrum.perun.webgui.json.facilitiesManager.GetHosts) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) Host(cz.metacentrum.perun.webgui.model.Host) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 54 with Attribute

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

the class ShellChangeTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    final FlexTable ft = new FlexTable();
    ft.setWidth("350px");
    ft.setStyleName("inputFormFlexTable");
    ft.setHTML(0, 0, "Available shells:");
    ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    final ListBox shells = new ListBox();
    shells.setWidth("200px");
    ft.setWidget(0, 1, shells);
    vp.add(ft);
    final CustomButton selectShellButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save preferred shell");
    // callback for available shells
    GetAttributes attrs = new GetAttributes(new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            shells.clear();
            shells.addItem("Error while loading");
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            shells.clear();
            ArrayList<Attribute> list = JsonUtils.jsoAsList(jso);
            if (list.isEmpty() || list == null) {
                shells.addItem("No shells available");
                return;
            }
            // fill shells
            for (Attribute a : list) {
                if (a.getFriendlyName().equalsIgnoreCase("shells")) {
                    for (int i = 0; i < a.getValueAsJsArray().length(); i++) {
                        // fill shell values
                        shells.addItem(a.getValueAsJsArray().get(i));
                    }
                    break;
                }
            }
            // set selected
            for (int i = 0; i < shells.getItemCount(); i++) {
                if (shells.getValue(i).equals(a.getValue())) {
                    shells.setSelectedIndex(i);
                    break;
                }
            }
            if (shells.getValue(shells.getSelectedIndex()).equals(a.getValue())) {
                selectShellButton.setEnabled(false);
            } else {
                selectShellButton.setEnabled(true);
            }
        }

        @Override
        public void onLoadingStart() {
            shells.clear();
            shells.addItem("Loading...");
        }
    });
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    selectShellButton.setEnabled(false);
    selectShellButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // OK click button
            // set new value
            a.setValue(shells.getValue(shells.getSelectedIndex()));
            // send request
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", resource.getFacilityId());
            SetAttribute request = new SetAttribute(JsonCallbackEvents.disableButtonEvents(selectShellButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // refresh only what's necessary
                    events.onFinished(jso);
                    // don't refresh underlaying tab
                    session.getTabManager().closeTab(tab, false);
                }
            }));
            request.setAttribute(ids, a);
        }
    });
    attrs.getResourceAttributes(resource.getId());
    attrs.retrieveData();
    shells.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (shells.getValue(shells.getSelectedIndex()).equals(a.getValue())) {
                selectShellButton.setEnabled(false);
            } else {
                selectShellButton.setEnabled(true);
            }
        }
    });
    final CustomButton defaultButton = new CustomButton("Use default", "", SmallIcons.INSTANCE.lightningIcon());
    defaultButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", resource.getFacilityId());
            RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(defaultButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // refresh only what's necessary
                    events.onFinished(jso);
                    // don't refresh underlaying tab
                    session.getTabManager().closeTab(tab, false);
                }
            }));
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            list.add(a);
            request.removeAttributes(ids, list);
        }
    });
    menu.addWidget(selectShellButton);
    menu.addWidget(defaultButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    contentWidget.setWidget(vp);
    return getWidget();
}
Also used : GetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) SetAttribute(cz.metacentrum.perun.webgui.json.attributesManager.SetAttribute) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttribute(cz.metacentrum.perun.webgui.json.attributesManager.SetAttribute) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 55 with Attribute

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

the class TestDataGridAttributesTabItem method draw.

public Widget draw() {
    //contentWidget.setSize("100%", "100%");
    DockLayoutPanel ft = new DockLayoutPanel(Style.Unit.PX);
    contentWidget.setWidget(ft);
    final DataGrid gridTable = new DataGrid();
    gridTable.setSize("100%", "100%");
    final ArrayList<Attribute> vosList = new ArrayList<Attribute>();
    final GetAttributesV2 getVos = new GetAttributesV2(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosList.addAll(new TableSorter<Attribute>().sortByAttrNameTranslation(JsonUtils.<Attribute>jsoAsList(jso)));
            gridTable.setRowData(vosList);
            gridTable.redraw();
        }
    });
    getVos.getUserAttributes(3411);
    getVos.retrieveData();
    gridTable.setSelectionModel(new MultiSelectionModel<Attribute>(new GeneralKeyProvider<Attribute>()));
    final SelectionModel<Attribute> selectionModel = gridTable.getSelectionModel();
    gridTable.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    Column<Attribute, Boolean> checkBoxColumn = new Column<Attribute, Boolean>(new CheckboxCell(true, true)) {

        @Override
        public Boolean getValue(Attribute object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkBoxColumn.setFieldUpdater(new FieldUpdater<Attribute, Boolean>() {

        @Override
        public void update(int i, Attribute Attribute, Boolean aBoolean) {
            selectionModel.setSelected(Attribute, aBoolean);
        }
    });
    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {

        public Boolean getValue() {
            //return true to see a checked checkbox.
            return false;
        }
    };
    checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {

        public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (Attribute obj : vosList) {
                selectionModel.setSelected(obj, value);
            }
        }
    });
    gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
    gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
    TextColumn<Attribute> idColumn = new TextColumn<Attribute>() {

        @Override
        public String getValue(Attribute object) {
            return String.valueOf(object.getId());
        }
    };
    if (JsonUtils.isExtendedInfoVisible()) {
        gridTable.addColumn(idColumn, "Id", "Id");
        gridTable.setColumnWidth(idColumn, "90px");
    }
    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());
    // Description column
    Column<Attribute, Attribute> descriptionColumn = JsonUtils.addColumn(new PerunAttributeDescriptionCell());
    // Value column
    Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), new FieldUpdater<Attribute, Attribute>() {

        public void update(int index, Attribute object, Attribute value) {
            object = value;
            selectionModel.setSelected(object, object.isAttributeValid());
        }
    });
    ColumnSortEvent.ListHandler<Attribute> columnSortHandler = new ColumnSortEvent.ListHandler<Attribute>(vosList);
    gridTable.addColumnSortHandler(columnSortHandler);
    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_NAME));
    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(descriptionColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_DESCRIPTION));
    // Add sorting
    gridTable.addColumnSortHandler(columnSortHandler);
    // updates the columns size
    gridTable.setColumnWidth(nameColumn, 200.0, Style.Unit.PX);
    gridTable.setColumnWidth(valueColumn, 420.0, Style.Unit.PX);
    gridTable.addColumn(nameColumn, "Name");
    gridTable.addColumn(valueColumn, "Value");
    gridTable.addColumn(descriptionColumn, "Description");
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().addTabToCurrentTab(new TestDataGridTabItem(), true);
        }
    }));
    ft.addNorth(tabMenu, 50);
    ft.add(gridTable);
    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) ArrayList(java.util.ArrayList) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) GeneralKeyProvider(cz.metacentrum.perun.webgui.json.keyproviders.GeneralKeyProvider) PerunAttributeNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) PerunAttributeDescriptionCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) DockLayoutPanel(com.google.gwt.user.client.ui.DockLayoutPanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

Attribute (cz.metacentrum.perun.webgui.model.Attribute)58 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)17 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)17 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)16 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)16 ArrayList (java.util.ArrayList)16 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)15 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)15 HashMap (java.util.HashMap)14 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)12 PerunError (cz.metacentrum.perun.webgui.model.PerunError)10 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)9 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)9 Map (java.util.Map)9 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)8 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)7 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)7 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)7 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)7 Column (com.google.gwt.user.cellview.client.Column)6