Search in sources :

Example 1 with CallbackIDAwareMessageHandler

use of org.eclipse.flux.client.CallbackIDAwareMessageHandler in project flux by eclipse.

the class InitializeServiceEnvironment method start.

public void start() {
    getProjectsResponseHandler = new CallbackIDAwareMessageHandler("getProjectsResponse", GET_PROJECTS_CALLBACK) {

        @Override
        public void handle(String messageType, JSONObject message) {
            handleGetProjectsResponse(message);
        }
    };
    messagingConnector.addMessageHandler(getProjectsResponseHandler);
    projectConnectedHandler = new MessageHandler("projectConnected") {

        @Override
        public void handle(String messageType, JSONObject message) {
            handleProjectConnected(message);
        }
    };
    messagingConnector.addMessageHandler(projectConnectedHandler);
    try {
        JSONObject message = new JSONObject();
        message.put("username", repository.getUsername());
        message.put("callback_id", GET_PROJECTS_CALLBACK);
        this.messagingConnector.send("getProjectsRequest", message);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) MessageHandler(org.eclipse.flux.client.MessageHandler) IMessageHandler(org.eclipse.flux.client.IMessageHandler) CallbackIDAwareMessageHandler(org.eclipse.flux.client.CallbackIDAwareMessageHandler) CallbackIDAwareMessageHandler(org.eclipse.flux.client.CallbackIDAwareMessageHandler) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException)

Example 2 with CallbackIDAwareMessageHandler

use of org.eclipse.flux.client.CallbackIDAwareMessageHandler in project flux by eclipse.

the class SyncDownloadSelectionDialog method open.

@Override
public int open() {
    try {
        int callbackID = this.hashCode();
        projects.clear();
        responseHandler = new CallbackIDAwareMessageHandler("getProjectsResponse", callbackID) {

            @Override
            public void handle(String messageType, JSONObject response) {
                try {
                    boolean newProjects = false;
                    JSONArray projectsList = response.getJSONArray("projects");
                    for (int i = 0; i < projectsList.length(); i++) {
                        JSONObject project = projectsList.getJSONObject(i);
                        String projectName = project.getString("name");
                        newProjects |= projects.add(projectName);
                    }
                    if (newProjects) {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                setListElements((String[]) projects.toArray(new String[projects.size()]));
                            }
                        });
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        this.messagingConnector.addMessageHandler(responseHandler);
        JSONObject message = new JSONObject();
        message.put("callback_id", callbackID);
        message.put("username", username);
        this.messagingConnector.send("getProjectsRequest", message);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    return super.open();
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) CallbackIDAwareMessageHandler(org.eclipse.flux.client.CallbackIDAwareMessageHandler) JSONException(org.json.JSONException)

Aggregations

CallbackIDAwareMessageHandler (org.eclipse.flux.client.CallbackIDAwareMessageHandler)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 CoreException (org.eclipse.core.runtime.CoreException)1 IMessageHandler (org.eclipse.flux.client.IMessageHandler)1 MessageHandler (org.eclipse.flux.client.MessageHandler)1 JSONArray (org.json.JSONArray)1