1 /* 2 * ApplicationTutorialEvent.java 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 16 package org.rstudio.studio.client.application; 17 18 import org.rstudio.core.client.js.JavaScriptSerializable; 19 import org.rstudio.studio.client.application.ApplicationTutorialEvent.Handler; 20 import org.rstudio.studio.client.application.events.CrossWindowEvent; 21 import jsinterop.annotations.JsType; 22 import jsinterop.annotations.JsPackage; 23 24 import com.google.gwt.event.shared.EventHandler; 25 import org.rstudio.studio.client.application.model.TutorialApiCallContext; 26 27 @JavaScriptSerializable 28 public class ApplicationTutorialEvent extends CrossWindowEvent<Handler> 29 { 30 public interface Handler extends EventHandler 31 { onApplicationTutorialEvent(ApplicationTutorialEvent event)32 void onApplicationTutorialEvent(ApplicationTutorialEvent event); 33 } 34 35 // Supported values for Data.message 36 37 // API request failed 38 // {"message": "error": "api": "<APINAME>", "result": "<API-SPECIFIC>", "callerID": "caller-supplied"} 39 public static final String API_ERROR = "error"; 40 41 // API request succeeded 42 // {"message": "success": "api": "<APINAME>", "callerID": "caller-supplied"} 43 public static final String API_SUCCESS = "success"; 44 45 // Some type of file save operation was initiated. Doesn't guarantee it was successful. 46 // {"message": "fileSave"} 47 public static final String FILE_SAVE = "fileSave"; 48 49 // The RPC connection between IDE and the RSession has been disconnected. 50 // {"message": "sessionDisconnect"} 51 public static final String SESSION_DISCONNECT = "sessionDisconnect"; 52 53 // The RSession has suspended. 54 // {"message": "sessionSuspend"} 55 public static final String SESSION_SUSPEND = "sessionSuspend"; 56 57 @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") 58 public static class Data 59 { 60 public String message; 61 public String api; 62 public String result; 63 public String callerID; 64 } 65 ApplicationTutorialEvent()66 public ApplicationTutorialEvent() 67 { 68 data_ = new Data(); 69 } 70 ApplicationTutorialEvent(Data data)71 public ApplicationTutorialEvent(Data data) 72 { 73 data_ = data; 74 } 75 ApplicationTutorialEvent(String message)76 public ApplicationTutorialEvent(String message) 77 { 78 data_ = new Data(); 79 data_.message = message; 80 } 81 ApplicationTutorialEvent(String message, TutorialApiCallContext callContext)82 public ApplicationTutorialEvent(String message, TutorialApiCallContext callContext) 83 { 84 data_ = new Data(); 85 data_.message = message; 86 data_.api = callContext.getApi(); 87 data_.callerID = callContext.getCallerID(); 88 } 89 ApplicationTutorialEvent(String message, String result, TutorialApiCallContext callContext)90 public ApplicationTutorialEvent(String message, String result, TutorialApiCallContext callContext) 91 { 92 data_ = new Data(); 93 data_.message = message; 94 data_.api = callContext.getApi(); 95 data_.result = result; 96 data_.callerID = callContext.getCallerID(); 97 } 98 99 @Override getAssociatedType()100 public com.google.gwt.event.shared.GwtEvent.Type<Handler> getAssociatedType() 101 { 102 return TYPE; 103 } 104 105 @Override dispatch(Handler handler)106 protected void dispatch(Handler handler) 107 { 108 handler.onApplicationTutorialEvent(this); 109 } 110 getData()111 public Data getData() 112 { 113 return data_; 114 } 115 116 private final Data data_; 117 118 public static final Type<Handler> TYPE = new Type<>(); 119 } 120