Search in sources :

Example 86 with PerunError

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

the class GetGroupRichMembers method getTable.

/**
	 * Returns the table with rich members of group
	 *
	 * @return table widget
	 */
public CellTable<RichMember> getTable() {
    // retrieves data
    retrieveData();
    // Table data provider.
    dataProvider = new ListDataProvider<RichMember>(list);
    // Cell table
    table = new PerunTable<RichMember>(list);
    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);
    // Sorting
    ListHandler<RichMember> columnSortHandler = new ListHandler<RichMember>(dataProvider.getList());
    table.addColumnSortHandler(columnSortHandler);
    // Table selection
    table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichMember>createCheckboxManager());
    // Set empty content & loader
    table.setEmptyTableWidget(loaderImage);
    // Checkbox column column
    table.addCheckBoxColumn();
    // Status column
    Column<RichMember, String> statusColumn = new Column<RichMember, String>(new PerunStatusCell()) {

        @Override
        public String getValue(RichMember object) {
            return object.getStatus();
        }
    };
    // own onClick tab for changing member's status
    statusColumn.setFieldUpdater(new FieldUpdater<RichMember, String>() {

        public void update(int index, final RichMember object, String value) {
            FlexTable widget = new FlexTable();
            final ListBox lb = new ListBox(false);
            lb.addItem("VALID", "VALID");
            lb.addItem("INVALID", "INVALID");
            lb.addItem("SUSPENDED", "SUSPENDED");
            lb.addItem("EXPIRED", "EXPIRED");
            lb.addItem("DISABLED", "DISABLED");
            widget.setHTML(0, 0, "<strong>Status: </strong>");
            widget.setWidget(0, 1, lb);
            // pick which one is already set
            for (int i = 0; i < lb.getItemCount(); i++) {
                if (lb.getItemText(i).equalsIgnoreCase(object.getStatus())) {
                    lb.setSelectedIndex(i);
                }
            }
            Confirm conf = new Confirm("Change member's status: " + object.getUser().getFullName(), widget, true);
            conf.setCancelButtonText("Cancel");
            conf.setOkButtonText("Change status");
            conf.setOkClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    SetStatus call = new SetStatus(object.getId(), new JsonCallbackEvents() {

                        public void onFinished(JavaScriptObject jso) {
                            clearTable();
                            retrieveData();
                        }

                        public void onError(PerunError error) {
                            clearTable();
                            retrieveData();
                        }
                    });
                    call.setStatus(lb.getValue(lb.getSelectedIndex()));
                }
            });
            conf.show();
        }
    });
    // status column sortable
    statusColumn.setSortable(true);
    columnSortHandler.setComparator(statusColumn, new GeneralComparator<RichMember>(GeneralComparator.Column.STATUS));
    table.addColumn(statusColumn, "Status");
    table.setColumnWidth(statusColumn, 20, Unit.PX);
    // Create member ID column.
    Column<RichMember, String> memberIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<RichMember, String>() {

        public String getValue(RichMember object) {
            return String.valueOf(object.getId());
        }
    }, this.tableFieldUpdater);
    // Create User ID column.
    Column<RichMember, String> userIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<RichMember, String>() {

        public String getValue(RichMember object) {
            return String.valueOf(object.getUser().getId());
        }
    }, this.tableFieldUpdater);
    columnSortHandler.setComparator(memberIdColumn, new RichMemberComparator(RichMemberComparator.Column.MEMBER_ID));
    memberIdColumn.setSortable(true);
    userIdColumn.setSortable(true);
    columnSortHandler.setComparator(userIdColumn, new RichMemberComparator(RichMemberComparator.Column.USER_ID));
    table.setColumnWidth(memberIdColumn, 110.0, Unit.PX);
    table.setColumnWidth(userIdColumn, 110.0, Unit.PX);
    // headers
    if (JsonUtils.isExtendedInfoVisible()) {
        table.addColumn(memberIdColumn, "Member ID");
        table.addColumn(userIdColumn, "User ID");
    }
    table.addNameColumn(tableFieldUpdater);
    return table;
}
Also used : ListHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FlexTable(com.google.gwt.user.client.ui.FlexTable) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) RichMember(cz.metacentrum.perun.webgui.model.RichMember) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Column(com.google.gwt.user.cellview.client.Column) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunStatusCell(cz.metacentrum.perun.webgui.widgets.cells.PerunStatusCell) SetStatus(cz.metacentrum.perun.webgui.json.membersManager.SetStatus) RichMemberComparator(cz.metacentrum.perun.webgui.json.comparators.RichMemberComparator) PerunError(cz.metacentrum.perun.webgui.model.PerunError) ListBox(com.google.gwt.user.client.ui.ListBox)

Example 87 with PerunError

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

the class CopyManagers method copyFacilityManagers.

/**
	 * Attempts to copy managers from one facility to another
	 *
	 * @param sourceFacility ID of source facility to get managers from
	 * @param destinationFacility ID of destination facility to copy managers to
	 */
public void copyFacilityManagers(int sourceFacility, int destinationFacility) {
    this.sourceFacility = sourceFacility;
    this.destinationFacility = destinationFacility;
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // json object
    JSONObject jsonQuery = prepareJSONObject();
    // local events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Copying facility managers failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Facility managers copied.");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // create request
    JsonPostClient request = new JsonPostClient(newEvents);
    request.sendData(JSON_URL, jsonQuery);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 88 with PerunError

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

the class CreateFacility method createFacility.

/**
	 * Attempts to create a new Facility, it first tests the values and then submits them.
	 *
	 * @param name Facility name
	 */
public void createFacility(final String name, final String description) {
    this.name = name;
    this.description = description;
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // json object
    JSONObject jsonQuery = prepareJSONObject();
    // local events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Creating facility " + name + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Facility " + name + " created.");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // create request
    JsonPostClient request = new JsonPostClient(newEvents);
    request.sendData(JSON_URL, jsonQuery);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 89 with PerunError

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

the class UpdateExecService method updateExecService.

/**
	 * Creates exec service in DB and associate it with service
	 *
	 * @param execService ExecService to update to
	 */
public void updateExecService(ExecService execService) {
    JSONObject execOrig = new JSONObject(execService);
    // reconstruct exec service
    JSONObject exec = new JSONObject();
    exec.put("id", execOrig.get("id"));
    exec.put("execServiceType", execOrig.get("execServiceType"));
    exec.put("enabled", execOrig.get("enabled"));
    exec.put("defaultDelay", execOrig.get("defaultDelay"));
    exec.put("defaultRecurrence", execOrig.get("defaultRecurrence"));
    // insert service into exec service
    exec.put("service", execOrig.get("service"));
    exec.put("script", execOrig.get("script"));
    exec.put("beanName", execOrig.get("beanName"));
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("execService", exec);
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Update of exec service failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Exec service successfully updated!");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

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

Example 90 with PerunError

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

the class CreateGroup method createGroup.

/**
	 * Creates a new GROUP
	 * @param jsonQuery A JSON object prepared by createGroupInGroup and createGroupInVo methods.
	 */
private void createGroup(JSONObject jsonQuery) {
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Creating group failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            Group gp = jso.cast();
            // if group admin, grant access in GUI !!
            if (session.isGroupAdmin() && gp != null) {
                session.addEditableGroup(gp.getId());
                session.getUiElements().setLogSuccessText("Group " + gp.getName() + " successfully created!");
            }
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

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

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