Search in sources :

Example 46 with PerunError

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

the class AddDestinationsByHostsOnFacility method addDestinationByHosts.

/**
	 * Attempts to add new Destination to services and facility, it first tests the values and then
	 * submits them.
	 *
	 * @param services list of services to have destinations by hosts added
	 */
public void addDestinationByHosts(ArrayList<Service> services) {
    this.services = services;
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Adding destination for facility: " + facility.getName() + " failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Destination for facility: " + facility.getName() + " added.");
            events.onFinished(jso);
        }

        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 47 with PerunError

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

the class GroupDetailTabItem method open.

public void open() {
    session.getUiElements().getMenu().openMenu(MainMenu.GROUP_ADMIN);
    if (vo == null) {
        new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                vo = jso.cast();
                session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "VO: " + vo.getName(), VosTabs.URL + UrlMapper.TAB_NAME_SEPARATOR + "detail?id=" + vo.getId(), "Group: " + group.getName(), getUrlWithParameters());
            }

            @Override
            public void onError(PerunError error) {
                session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "Group: " + group.getName(), getUrlWithParameters());
            }
        }).retrieveData();
    } else {
        session.getUiElements().getBreadcrumbs().setLocation(MainMenu.GROUP_ADMIN, "VO: " + vo.getName(), VosTabs.URL + UrlMapper.TAB_NAME_SEPARATOR + "detail?id=" + vo.getId(), "Group: " + group.getName(), getUrlWithParameters());
    }
    if (group != null) {
        session.setActiveGroup(group);
    } else {
        session.setActiveGroupId(groupId);
    }
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetEntityById(cz.metacentrum.perun.webgui.json.GetEntityById) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 48 with PerunError

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

the class CreateFacilityResourceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Create resource");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // form inputs
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    final TextBox descriptionTextBox = new TextBox();
    final ListBoxWithObjects<VirtualOrganization> vosDropDown = new ListBoxWithObjects<VirtualOrganization>();
    // send button
    final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createResource());
    // local events fills the listbox of Vos and Slds
    JsonCallbackEvents event = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // fill VOs listbox
            vosDropDown.clear();
            ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
            vos = new TableSorter<VirtualOrganization>().sortByName(vos);
            for (VirtualOrganization vo : vos) {
                vosDropDown.addItem(vo);
            }
            if (!vos.isEmpty())
                createButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            vosDropDown.clear();
            vosDropDown.addItem("Loading...");
            createButton.setEnabled(false);
        }

        @Override
        public void onError(PerunError error) {
            vosDropDown.clear();
            vosDropDown.addItem("Error while loading");
            createButton.setEnabled(false);
        }
    };
    // load available VOs
    final GetVos vos = new GetVos(event);
    vos.setForceAll(true);
    vos.retrieveData();
    // layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // Add some standard form options
    layout.setHTML(0, 0, "On facility:");
    layout.setHTML(0, 1, facility.getName());
    layout.setHTML(1, 0, "For VO:");
    layout.setWidget(1, 1, vosDropDown);
    layout.setHTML(2, 0, "Name:");
    layout.setWidget(2, 1, nameTextBox);
    layout.setHTML(3, 0, "Description:");
    layout.setWidget(3, 1, descriptionTextBox);
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    layout.setWidth("350px");
    TabMenu menu = new TabMenu();
    final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
                nameTextBox.setError("Name can't be empty.");
                return false;
            }
            nameTextBox.setOk();
            return true;
        }
    };
    nameTextBox.setValidator(validator);
    createButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // loads new tab when creating successful, also disable button
            JsonCallbackEvents localEvents = new JsonCallbackEvents() {

                public void onLoadingStart() {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onLoadingStart();
                }

                public void onFinished(JavaScriptObject jso) {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onFinished(jso);
                    Resource res = (Resource) jso;
                    session.getTabManager().addTabToCurrentTab(new CreateFacilityResourceManageServicesTabItem(facility, res), true);
                }

                public void onError(PerunError error) {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onError(error);
                }
            };
            if (validator.validateTextBox()) {
                // request
                CreateResource request = new CreateResource(localEvents);
                request.createResource(nameTextBox.getTextBox().getText().trim(), descriptionTextBox.getText().trim(), facility.getId(), vosDropDown.getSelectedObject().getId());
            }
        }
    });
    menu.addWidget(createButton);
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) CreateResource(cz.metacentrum.perun.webgui.json.resourcesManager.CreateResource) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ImageResource(com.google.gwt.resources.client.ImageResource) Resource(cz.metacentrum.perun.webgui.model.Resource) CreateResource(cz.metacentrum.perun.webgui.json.resourcesManager.CreateResource) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) 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) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 49 with PerunError

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

the class ResourceSettingsTabItem method draw.

public Widget draw() {
    if (service != null) {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": " + service.getName() + " configuration");
    } else {
        titleWidget.setText(Utils.getStrippedStringWithEllipsis(resource.getName()) + ": service configuration");
    }
    vp.setSize("100%", "100%");
    vp.clear();
    // menu
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    // callback
    final GetRequiredAttributesV2 resAttrs = new GetRequiredAttributesV2();
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resource", resourceId);
    resAttrs.setIds(ids);
    final GetAttributesV2 attrs = new GetAttributesV2();
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        resAttrs.setCheckable(false);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        attrs.setCheckable(false);
    // puts first table
    final CellTable<Attribute> table = resAttrs.getEmptyTable();
    final CellTable<Attribute> table2 = attrs.getEmptyTable();
    // if for one service only modify empty table message
    if (service != null) {
        AjaxLoaderImage empty = (AjaxLoaderImage) table.getEmptyTableWidget();
        empty.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
        AjaxLoaderImage empty2 = (AjaxLoaderImage) table2.getEmptyTableWidget();
        empty2.setEmptyResultMessage("Service " + service.getName() + " requires no setting on resource.");
    }
    final ListBoxWithObjects<Service> servList = new ListBoxWithObjects<Service>();
    sp.setWidget(table);
    sp2.setWidget(table2);
    // switch between assigned and all
    final CheckBox chb = new CheckBox();
    chb.setText(WidgetTranslation.INSTANCE.offerAvailableServicesOnly());
    chb.setTitle(WidgetTranslation.INSTANCE.offerAvailableServicesOnlyTitle());
    // default true
    chb.setValue(lastOfferAvailableOnly);
    // event which fills the listbox and call getRequiredAttributes
    JsonCallbackEvents event = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // clear services list
            servList.clear();
            // process services
            ArrayList<Service> srv = JsonUtils.jsoAsList(jso);
            srv = new TableSorter<Service>().sortByName(srv);
            for (int i = 0; i < srv.size(); i++) {
                // fill listbox
                servList.addItem(srv.get(i));
            }
            if (servList.isEmpty()) {
                servList.addNotSelectedOption();
                lastSelectedService = 0;
                indexInList = 0;
                attrs.retrieveData();
                setTable(false);
                return;
            }
            if (lastSelectedService == 0 && chb.getValue() == true) {
                servList.addNotSelectedOption();
                servList.addAllOption();
                if (indexInList == 0) {
                    servList.setSelectedIndex(0);
                    attrs.retrieveData();
                    setTable(false);
                    return;
                } else if (indexInList == 1) {
                    servList.setSelectedIndex(1);
                }
            } else if (lastSelectedService == 0 && chb.getValue() == false) {
                servList.addNotSelectedOption();
                servList.setSelectedIndex(0);
                attrs.retrieveData();
                setTable(false);
                return;
            } else if (lastSelectedService != 0) {
                if (chb.getValue() == true) {
                    servList.addNotSelectedOption();
                    servList.addAllOption();
                } else {
                    servList.addNotSelectedOption();
                }
                // remove last service, we can't be sure it was loaded again
                ids.remove("service");
                // either all or specific service
                servList.setSelectedIndex(1);
                for (Service s : servList.getAllObjects()) {
                    if (s.getId() == lastSelectedService) {
                        // service selected last time was found in a list
                        servList.setSelected(s, true);
                        ids.put("service", s.getId());
                        break;
                    }
                }
            }
            // make call
            resAttrs.clearTable();
            resAttrs.setIds(ids);
            resAttrs.retrieveData();
            setTable(true);
        }

        ;

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

        ;

        @Override
        public void onLoadingStart() {
            servList.removeAllOption();
            servList.removeNotSelectedOption();
            servList.clear();
            servList.addItem("Loading...");
        }
    };
    final GetAssignedServices services = new GetAssignedServices(resourceId, event);
    final GetServices allServices = new GetServices(event);
    // offer services selection
    if (serviceId == 0) {
        // services listbox
        servList.setTitle("Services");
        attrs.setIds(ids);
        // on change of service update table
        servList.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                // if service selected
                if (servList.getSelectedIndex() == 0) {
                    attrs.retrieveData();
                    setTable(false);
                    lastSelectedService = 0;
                    indexInList = 0;
                    return;
                } else if (chb.getValue() == true && servList.getSelectedIndex() == 1) {
                    ids.remove("service");
                    lastSelectedService = 0;
                    indexInList = 1;
                } else if ((chb.getValue() == true && servList.getSelectedIndex() > 1) || (chb.getValue() == false && servList.getSelectedIndex() > 0)) {
                    ids.put("service", servList.getSelectedObject().getId());
                    lastSelectedService = servList.getSelectedObject().getId();
                }
                lastOfferAvailableOnly = chb.getValue();
                resAttrs.clearTable();
                resAttrs.setIds(ids);
                resAttrs.retrieveData();
                setTable(true);
            }
        });
        if (chb.getValue() == false) {
            allServices.retrieveData();
        } else {
            services.retrieveData();
        }
    } else {
        // retrieve data for selected service only
        lastSelectedService = serviceId;
        lastOfferAvailableOnly = chb.getValue();
        ids.put("service", serviceId);
        resAttrs.setIds(ids);
        resAttrs.retrieveData();
        setTable(true);
    }
    // refresh table event - refresh only on finished / on error keep selected
    final JsonCallbackEvents refreshTable = JsonCallbackEvents.refreshTableEvents(resAttrs);
    final JsonCallbackEvents refreshTable2 = JsonCallbackEvents.refreshTableEvents(attrs);
    // add save changes to menu
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(saveChangesButton);
    // set button disable event
    final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable);
    final JsonCallbackEvents saveChangesButtonEvent2 = JsonCallbackEvents.disableButtonEvents(saveChangesButton, refreshTable2);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getTableSelectedList();
            } else {
                list = attrs.getTableSelectedList();
            }
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                SetAttributes request = new SetAttributes((required) ? saveChangesButtonEvent : saveChangesButtonEvent2);
                request.setAttributes(ids, list);
            }
        }
    });
    // add set new to menu
    CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getList();
            } else {
                list = attrs.getList();
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("resource", resourceId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, list), true);
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        setNewAttributeButton.setEnabled(false);
    if (service == null) {
        menu.addWidget(setNewAttributeButton);
    }
    // fill button
    final CustomButton fillDefaultButton = TabMenu.getPredefinedButton(ButtonType.FILL, ButtonTranslation.INSTANCE.fillResourceAttributes());
    menu.addWidget(fillDefaultButton);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable);
    final JsonCallbackEvents removeButtonEvent2 = JsonCallbackEvents.disableButtonEvents(removeButton, refreshTable2);
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        removeButton.setEnabled(false);
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            if (required) {
                list = resAttrs.getTableSelectedList();
            } else {
                list = attrs.getTableSelectedList();
            }
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                RemoveAttributes request = new RemoveAttributes((required) ? removeButtonEvent : removeButtonEvent2);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(removeButton);
    // add service selection to menu and switcher
    if (serviceId == 0) {
        menu.addWidget(new HTML("<strong>Selected&nbsp;service: </strong>"));
        menu.addWidget(servList);
        menu.addWidget(chb);
    }
    // checkbox switcher on click
    chb.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (chb.getValue() == false) {
                lastOfferAvailableOnly = false;
                allServices.retrieveData();
            } else {
                lastOfferAvailableOnly = true;
                services.retrieveData();
            }
        }
    });
    fillDefaultButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // automatically try to fill all attributes
            ArrayList<Attribute> prepareList = new ArrayList<Attribute>();
            if (required) {
                prepareList = resAttrs.getTableSelectedList();
            } else {
                prepareList = attrs.getTableSelectedList();
            }
            final ArrayList<Attribute> list = prepareList;
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("resource", resourceId);
                FillAttributes request = new FillAttributes(JsonCallbackEvents.disableButtonEvents(fillDefaultButton, new JsonCallbackEvents() {

                    boolean wasRequiredTable = required;

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // remove attribute from original table and put new ones
                        ArrayList<Attribute> newList = JsonUtils.jsoAsList(jso);
                        for (Attribute a : newList) {
                            for (Attribute oldA : list) {
                                // deselect old
                                if (a.getId() == oldA.getId()) {
                                    if (wasRequiredTable) {
                                        resAttrs.getSelectionModel().setSelected(oldA, false);
                                        resAttrs.removeFromTable(oldA);
                                    } else {
                                        attrs.getSelectionModel().setSelected(oldA, false);
                                        attrs.removeFromTable(oldA);
                                    }
                                }
                            }
                            if (wasRequiredTable) {
                                //add new
                                resAttrs.addToTable(a);
                                // select returned
                                resAttrs.getSelectionModel().setSelected(a, true);
                            } else {
                                //add new
                                attrs.addToTable(a);
                                // select returned
                                attrs.getSelectionModel().setSelected(a, true);
                            }
                        }
                        if (wasRequiredTable) {
                            resAttrs.sortTable();
                        } else {
                            attrs.sortTable();
                        }
                    }
                }));
                request.fillAttributes(ids, list);
            }
        }
    });
    if (!session.isVoAdmin(resource.getVoId()) && !session.isFacilityAdmin(resource.getFacilityId()))
        fillDefaultButton.setEnabled(false);
    /* TODO - not implemented

			 Button checkValuesButton = new CustomButton("Check values", SmallIcons.INSTANCE.scriptGearIcon());
			 menu.addWidget(checkValuesButton);
			 checkValuesButton.setTitle("Checks inserted values against current Perun state - nothing is saved unless you click on 'Save changes'");


			 checkValuesButton.addClickHandler(new ClickHandler(){
			 public void onClick(ClickEvent event) {
			 Window.alert("not yet implemented");
			 }
			 });

*/
    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);
    // 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) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) 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) GetAssignedServices(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedServices) 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) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map)

Example 50 with PerunError

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

the class FindSimilarPublications method getEmptyTable.

/**
	 * Returns table of users publications
	 * @return table
	 */
public CellTable<Publication> getEmptyTable() {
    // Table data provider.
    dataProvider = new ListDataProvider<Publication>(list);
    // Cell table
    table = new PerunTable<Publication>(list);
    // display row-count for perun admin only
    if (!session.isPerunAdmin()) {
        table.removeRowCountChangeHandler();
    }
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<Publication> columnSortHandler = new ListHandler<Publication>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<Publication>createCheckboxManager());
    // set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    loaderImage.setEmptyResultMessage("No similar publications found.");
    // show checkbox column
    if (this.checkable) {
        // checkbox column column
        table.addCheckBoxColumn();
    }
    // ID COLUMN
    table.addIdColumn("Publication ID", tableFieldUpdater, 60);
    Column<Publication, ImageResource> lockedColumn = new Column<Publication, ImageResource>(new CustomImageResourceCell("click")) {

        public ImageResource getValue(Publication object) {
            if (object.getLocked() == true) {
                return SmallIcons.INSTANCE.lockIcon();
            } else {
                return SmallIcons.INSTANCE.lockOpenIcon();
            }
        }

        public void onBrowserEvent(final Context context, final Element elem, final Publication object, NativeEvent event) {
            // on click and for perun admin
            if ("click".equals(event.getType()) && session.isPerunAdmin()) {
                final ImageResource value;
                if (object.getLocked() == true) {
                    value = SmallIcons.INSTANCE.lockOpenIcon();
                    object.setLocked(false);
                } else {
                    value = SmallIcons.INSTANCE.lockIcon();
                    object.setLocked(true);
                }
                LockUnlockPublications request = new LockUnlockPublications(new JsonCallbackEvents() {

                    @Override
                    public void onLoadingStart() {
                        getCell().setValue(context, elem, SmallIcons.INSTANCE.updateIcon());
                    }

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // change picture (object already changed)
                        getCell().setValue(context, elem, value);
                    }

                    @Override
                    public void onError(PerunError error) {
                        // on error switch object back
                        if (object.getLocked() == true) {
                            object.setLocked(false);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockOpenIcon());
                        } else {
                            object.setLocked(true);
                            getCell().setValue(context, elem, SmallIcons.INSTANCE.lockIcon());
                        }
                    }
                });
                // send request
                ArrayList<Publication> list = new ArrayList<Publication>();
                list.add(object);
                request.lockUnlockPublications(object.getLocked(), list);
            }
        }
    };
    table.addColumn(lockedColumn, "Lock");
    // TITLE COLUMN
    Column<Publication, String> titleColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getTitle();
        }
    }, this.tableFieldUpdater);
    titleColumn.setSortable(true);
    columnSortHandler.setComparator(titleColumn, new PublicationComparator(PublicationComparator.Column.TITLE));
    table.addColumn(titleColumn, "Title");
    // if display authors
    if (ids.containsKey("authors")) {
        if ((Integer) ids.get("authors") == 1) {
            // AUTHORS COLUMN
            Column<Publication, String> authorColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

                public String getValue(Publication object) {
                    return object.getAuthorsFormatted();
                }
            }, this.tableFieldUpdater);
            authorColumn.setSortable(true);
            columnSortHandler.setComparator(authorColumn, new PublicationComparator(PublicationComparator.Column.AUTHORS));
            table.addColumn(authorColumn, "Reported by");
        }
    }
    // YEAR COLUMN
    Column<Publication, String> yearColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return String.valueOf(object.getYear());
        }
    }, this.tableFieldUpdater);
    yearColumn.setSortable(true);
    columnSortHandler.setComparator(yearColumn, new PublicationComparator(PublicationComparator.Column.YEAR));
    table.addColumn(yearColumn, "Year");
    // CATEGORY COLUMN
    Column<Publication, String> categoryColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return object.getCategoryName();
        }
    }, this.tableFieldUpdater);
    categoryColumn.setSortable(true);
    columnSortHandler.setComparator(categoryColumn, new PublicationComparator(PublicationComparator.Column.CATEGORY));
    table.addColumn(categoryColumn, "Category");
    // THANKS COLUMN
    Column<Publication, String> thanksColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            String result = "";
            JsArray<Thanks> thks = object.getThanks();
            for (int i = 0; i < thks.length(); i++) {
                result += thks.get(i).getOwnerName() + ", ";
            }
            if (result.length() >= 2) {
                result = result.substring(0, result.length() - 2);
            }
            return result;
        }
    }, this.tableFieldUpdater);
    thanksColumn.setSortable(true);
    columnSortHandler.setComparator(thanksColumn, new PublicationComparator(PublicationComparator.Column.THANKS));
    table.addColumn(thanksColumn, "Thanked to");
    // CITE COLUMN
    Column<Publication, String> citaceColumn = JsonUtils.addColumn(new JsonUtils.GetValue<Publication, String>() {

        public String getValue(Publication object) {
            return "Cite";
        }
    }, new FieldUpdater<Publication, String>() {

        public void update(int index, Publication object, String value) {
            SimplePanel sp = new SimplePanel();
            sp.add(new HTML(object.getMain()));
            Confirm cf = new Confirm("Cite publication", sp, true);
            cf.show();
        }

        ;
    });
    table.addColumn(citaceColumn, "Cite");
    return table;
}
Also used : PublicationComparator(cz.metacentrum.perun.webgui.json.comparators.PublicationComparator) Element(com.google.gwt.dom.client.Element) ArrayList(java.util.ArrayList) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) ImageResource(com.google.gwt.resources.client.ImageResource) Column(com.google.gwt.user.cellview.client.Column) Context(com.google.gwt.cell.client.Cell.Context) ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) CustomImageResourceCell(cz.metacentrum.perun.webgui.widgets.cells.CustomImageResourceCell) JsArray(com.google.gwt.core.client.JsArray) Publication(cz.metacentrum.perun.webgui.model.Publication) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

PerunError (cz.metacentrum.perun.webgui.model.PerunError)177 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)173 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)167 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)126 JSONObject (com.google.gwt.json.client.JSONObject)55 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)36 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)36 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)30 ArrayList (java.util.ArrayList)30 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)27 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)21 JSONNumber (com.google.gwt.json.client.JSONNumber)17 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)16 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)16 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)15 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)11 Attribute (cz.metacentrum.perun.webgui.model.Attribute)10 HashMap (java.util.HashMap)10 JSONString (com.google.gwt.json.client.JSONString)8 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)8