Search in sources :

Example 46 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents 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 47 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class BlockUnblockServiceOnDestination method unblockServiceOnDestination.

/**
 * Attempts to ban selected service for specified facility
 *
 * @param serviceId
 * @param destinationId
 */
public void unblockServiceOnDestination(int serviceId, int destinationId) {
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("destination", new JSONNumber(destinationId));
    jsonQuery.put("service", new JSONNumber(serviceId));
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Allowing service " + serviceId + " failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Service " + serviceId + " allowed on destination.");
            events.onFinished(jso);
        }

        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL_UNBLOCK, 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) JSONNumber(com.google.gwt.json.client.JSONNumber) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 48 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class BlockUnblockServiceOnDestination method blockServiceOnDestination.

/**
 * Attempts to ban selected service for specified facility
 *
 * @param serviceId
 * @param destinationId
 */
public void blockServiceOnDestination(int serviceId, int destinationId) {
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("destination", new JSONNumber(destinationId));
    jsonQuery.put("service", new JSONNumber(serviceId));
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Blocking service " + serviceId + " failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Service " + serviceId + " blocked on destination.");
            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) JSONNumber(com.google.gwt.json.client.JSONNumber) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 49 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class CreateServicePackage method createServicePackage.

/**
 * Attempts to create a new ServicesPackage, it first tests the values and then submits them.
 *
 * @param name service package name
 * @param description service package description
 */
public void createServicePackage(final String name, final String description) {
    this.packageName = name;
    this.packageDescription = description;
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Creating service package " + packageName + " failed.");
            // custom events
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Service package " + packageName + " created.");
            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 50 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class DeleteServicePackage method deleteServicePackage.

/**
 * Attempts to delete a service, tests values first
 *
 * @param packageId id of service to be deleted
 */
public void deleteServicePackage(final int packageId) {
    this.packageId = packageId;
    // test arguments
    if (!this.testDeleting()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Deleting service package: " + packageId + " failed.");
            events.onError(error);
        }

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Service package: " + packageId + " deleted !");
            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)

Aggregations

JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)380 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)333 PerunError (cz.metacentrum.perun.webgui.model.PerunError)206 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)181 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)143 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)143 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)142 ArrayList (java.util.ArrayList)125 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)108 JSONObject (com.google.gwt.json.client.JSONObject)69 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)60 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)41 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)34 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)34 HashMap (java.util.HashMap)33 JSONNumber (com.google.gwt.json.client.JSONNumber)30 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)24 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)24 Group (cz.metacentrum.perun.webgui.model.Group)23 Map (java.util.Map)23