Search in sources :

Example 16 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class CreateCompleteService method createCompleteService.

/**
	 * Attempts to create a new Service including both ExecServices with dependency,
	 * it first tests the values and then submits them.
	 *
	 * @param name service Name
	 * @param scriptPath Path to the service script, default "./service_name"
	 * @param defaultDelay Delay in minutes when service is rescheduled (10 min is default)
	 * @param enabled TRUE if service should be enabled
	 */
public void createCompleteService(final String name, final String scriptPath, final int defaultDelay, final boolean enabled) {
    this.serviceName = name;
    this.scriptPath = scriptPath;
    this.defaultDelay = defaultDelay;
    this.enabled = enabled;
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

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

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Service " + serviceName + " 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 17 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class DeleteTask method deleteTask.

/**
	 * Deletes Task from DB
	 *
	 * @param taskId id of Task to be deleted
	 */
public void deleteTask(final int taskId) {
    this.taskId = taskId;
    // test arguments
    if (!this.testArguments()) {
        return;
    }
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("task", new JSONNumber(taskId));
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Deleting of Task: " + taskId + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Task: " + taskId + " deleted successfully.");
            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 18 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class AddGroupManagerTabItem method startSearching.

/**
	 * Starts the search for users
	 */
protected void startSearching(String text) {
    users.clearTable();
    // IS searched string IDs?
    if (JsonUtils.isStringWithIds(text)) {
        FindUsersByIdsNotInRpc req = new FindUsersByIdsNotInRpc(new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                ArrayList<User> usersList = JsonUtils.jsoAsList(jso);
                for (User u : usersList) {
                    users.addToTable(u);
                }
            }
        }, text);
        req.retrieveData();
        return;
    }
    users.searchFor(text);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) User(cz.metacentrum.perun.webgui.model.User) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ArrayList(java.util.ArrayList) FindUsersByIdsNotInRpc(cz.metacentrum.perun.webgui.json.usersManager.FindUsersByIdsNotInRpc)

Example 19 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class AddDependencyTabItem method draw.

public Widget draw() {
    // TITLE
    titleWidget.setText("Add dependency");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    final ListBoxWithObjects<ExecService> listBox = new ListBoxWithObjects<ExecService>();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDependantExecService());
    // fill listbox after callback finishes
    final JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            listBox.clear();
            ArrayList<ExecService> execs = JsonUtils.jsoAsList(jso);
            if (execs != null && !execs.isEmpty()) {
                execs = new TableSorter<ExecService>().sortByService(execs);
                for (int i = 0; i < execs.size(); i++) {
                    listBox.addItem(execs.get(i));
                    if (execService.getService().getName().equals(execs.get(i).getService().getName()) && !execService.getType().equals(execs.get(i).getType())) {
                        // preselect different type of exec service from same service
                        listBox.setSelected(execs.get(i), true);
                    }
                }
                addButton.setEnabled(true);
            } else {
                listBox.addItem("No exec service available");
            }
        }

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

        @Override
        public void onError(PerunError error) {
            listBox.addItem("Error while loading");
            addButton.setEnabled(false);
        }
    };
    // callback for all services
    ListExecServices callback = new ListExecServices(0, localEvents);
    callback.retrieveData();
    // layout
    layout.setHTML(0, 0, "ExecService:");
    layout.setHTML(1, 0, "Depend On:");
    layout.setHTML(0, 1, execService.getService().getName() + " " + execService.getType());
    layout.setWidget(1, 1, listBox);
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab);
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            CreateDependency request = new CreateDependency(closeTabEvents);
            request.createDependancy(execServiceId, listBox.getSelectedObject().getId());
        }
    });
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(addButton);
    menu.addWidget(cancelButton);
    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) ExecService(cz.metacentrum.perun.webgui.model.ExecService) CreateDependency(cz.metacentrum.perun.webgui.json.generalServiceManager.CreateDependency) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ListExecServices(cz.metacentrum.perun.webgui.json.generalServiceManager.ListExecServices) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 20 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project gerrit by GerritCodeReview.

the class ProjectGlue method onAction.

public static void onAction(Project.NameKey project, BranchInfo branch, ActionInfo action, ActionButton button) {
    RestApi api = ProjectApi.project(project).view("branches").id(branch.ref()).view(action.id());
    JavaScriptObject f = branchAction(action.id());
    if (f != null) {
        ActionContext c = ActionContext.create(api);
        c.set(action);
        c.set(project);
        c.set(branch);
        c.button(button);
        ApiGlue.invoke(f, c);
    } else {
        DefaultActions.invoke(project, action, api);
    }
}
Also used : RestApi(com.google.gerrit.client.rpc.RestApi) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)436 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)333 PerunError (cz.metacentrum.perun.webgui.model.PerunError)212 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)181 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)110 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)110 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)104 ArrayList (java.util.ArrayList)95 JSONObject (com.google.gwt.json.client.JSONObject)79 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)73 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)58 HashMap (java.util.HashMap)34 JSONNumber (com.google.gwt.json.client.JSONNumber)32 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)31 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)31 Map (java.util.Map)25 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)24 JSONString (com.google.gwt.json.client.JSONString)22 Attribute (cz.metacentrum.perun.webgui.model.Attribute)20 Group (cz.metacentrum.perun.webgui.model.Group)19