001package org.deepamehta.plugins.littlehelpers;
002
003import de.deepamehta.core.JSONEnabled;
004import de.deepamehta.core.Topic;
005import java.util.logging.Level;
006import java.util.logging.Logger;
007import org.codehaus.jettison.json.JSONException;
008import org.codehaus.jettison.json.JSONObject;
009
010public class SuggestionViewModel implements JSONEnabled {
011    
012    Topic suggestion = null;
013    Topic workspace = null;
014    String workspaceMode = null;
015    // String[] commands = null;
016    
017    public SuggestionViewModel (Topic topic, Topic workspace) {
018        this.suggestion = topic;
019        this.workspace = workspace;
020        this.workspaceMode = workspace.loadChildTopics("dm4.workspaces.sharing_mode")
021                .getChildTopics().getString("dm4.workspaces.sharing_mode");
022    }
023    
024    public JSONObject toJSON() {
025        try {
026            return new JSONObject()
027                .put("topic", suggestion.toJSON())
028                .put("workspace", (workspace == null) ? "undefined" : workspace.toJSON())
029                .put("workspace_mode", workspaceMode);
030        } catch (JSONException ex) {
031            Logger.getLogger(SuggestionViewModel.class.getName()).log(Level.SEVERE, null, ex);
032        }
033        return new JSONObject();
034    }
035
036}