2121import java .util .EnumMap ;
2222import java .util .List ;
2323import java .util .Map ;
24+ import java .util .Optional ;
2425import java .util .concurrent .ConcurrentLinkedQueue ;
2526import java .util .stream .Collectors ;
2627
28+ import org .atmosphere .cpr .AtmosphereResource ;
29+ import org .slf4j .Logger ;
30+ import org .slf4j .LoggerFactory ;
31+
2732import com .fasterxml .jackson .databind .ObjectMapper ;
2833import com .vaadin .base .devserver .stats .DevModeUsageStatistics ;
2934import com .vaadin .experimental .FeatureFlags ;
35+ import com .vaadin .flow .component .Component ;
36+ import com .vaadin .flow .dom .Element ;
3037import com .vaadin .flow .internal .BrowserLiveReload ;
3138import com .vaadin .flow .server .VaadinContext ;
39+ import com .vaadin .flow .server .VaadinSession ;
40+ import com .vaadin .flow .server .startup .ApplicationConfiguration ;
3241import com .vaadin .pro .licensechecker .BuildType ;
3342import com .vaadin .pro .licensechecker .LicenseChecker ;
43+ import com .vaadin .pro .licensechecker .LocalProKey ;
3444import com .vaadin .pro .licensechecker .Product ;
3545
36- import org .atmosphere .cpr .AtmosphereResource ;
37- import org .slf4j .Logger ;
38- import org .slf4j .LoggerFactory ;
39-
4046import elemental .json .Json ;
4147import elemental .json .JsonObject ;
4248
@@ -62,6 +68,8 @@ public class DebugWindowConnection implements BrowserLiveReload {
6268
6369 private final ObjectMapper objectMapper = new ObjectMapper ();
6470
71+ private IdeIntegration ideIntegration ;
72+
6573 static {
6674 IDENTIFIER_CLASSES .put (Backend .JREBEL , Collections .singletonList (
6775 "org.zeroturnaround.jrebel.vaadin.JRebelClassEventListener" ));
@@ -79,6 +87,8 @@ public class DebugWindowConnection implements BrowserLiveReload {
7987 DebugWindowConnection (ClassLoader classLoader , VaadinContext context ) {
8088 this .classLoader = classLoader ;
8189 this .context = context ;
90+ this .ideIntegration = new IdeIntegration (
91+ ApplicationConfiguration .get (context ));
8292 }
8393
8494 @ Override
@@ -126,6 +136,10 @@ public void onConnect(AtmosphereResource resource) {
126136 .get (context ).getFeatures ().stream ()
127137 .filter (feature -> !feature .equals (FeatureFlags .EXAMPLE ))
128138 .collect (Collectors .toList ())));
139+
140+ if (LocalProKey .get () != null ) {
141+ send (resource , "vaadin-dev-tools-code-ok" , null );
142+ }
129143 }
130144
131145 private void send (AtmosphereResource resource , String command ,
@@ -166,6 +180,7 @@ public void reload() {
166180 });
167181 }
168182
183+ @ SuppressWarnings ("FutureReturnValueIgnored" )
169184 @ Override
170185 public void onMessage (AtmosphereResource resource , String message ) {
171186 if (message .isEmpty ()) {
@@ -174,15 +189,13 @@ public void onMessage(AtmosphereResource resource, String message) {
174189 }
175190 JsonObject json = Json .parse (message );
176191 String command = json .getString ("command" );
192+ JsonObject data = json .getObject ("data" );
177193 if ("setFeature" .equals (command )) {
178- JsonObject data = json .getObject ("data" );
179194 FeatureFlags .get (context ).setEnabled (data .getString ("featureId" ),
180195 data .getBoolean ("enabled" ));
181196 } else if ("reportTelemetry" .equals (command )) {
182- JsonObject data = json .getObject ("data" );
183197 DevModeUsageStatistics .handleBrowserData (data );
184198 } else if ("checkLicense" .equals (command )) {
185- JsonObject data = json .getObject ("data" );
186199 String name = data .getString ("name" );
187200 String version = data .getString ("version" );
188201 Product product = new Product (name , version );
@@ -207,6 +220,25 @@ public void onMessage(AtmosphereResource resource, String message) {
207220 errorMessage );
208221 send (resource , "license-check-failed" , pm );
209222 }
223+ } else if ("showComponentCreateLocation" .equals (command )
224+ || "showComponentAttachLocation" .equals (command )) {
225+ int nodeId = (int ) data .getNumber ("nodeId" );
226+ int uiId = (int ) data .getNumber ("uiId" );
227+ VaadinSession session = VaadinSession .getCurrent ();
228+ session .access (() -> {
229+ Element element = session .findElement (uiId , nodeId );
230+ Optional <Component > c = element .getComponent ();
231+ if (c .isPresent ()) {
232+ if ("showComponentCreateLocation" .equals (command )) {
233+ ideIntegration .showComponentCreateInIde (c .get ());
234+ } else {
235+ ideIntegration .showComponentAttachInIde (c .get ());
236+ }
237+ } else {
238+ getLogger ().error (
239+ "Only component locations are tracked. The given node id refers to an element and not a component" );
240+ }
241+ });
210242 } else {
211243 getLogger ().info ("Unknown command from the browser: " + command );
212244 }
0 commit comments