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();
}
}
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();
}
Aggregations