Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ private Object constructObject(Class<?> type, Object[] args,
// clean up, prevent memory leak
This.registerConstructorContext(null, null);
}
com.codenameone.playground.PlaygroundContext.notifyConstructed(obj);
String className = type.getName();
// Is it an inner class?
if ( className.indexOf("$") == -1 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ private static void fillMethodIndex9(Map<String, String[]> index) {
index.put("com.codename1.xml.XMLParser", splitMembers(""));
index.put("com.codename1.xml.XMLWriter", splitMembers(""));
index.put("com.codenameone.playground.CN1Playground", splitMembers("destroy()getTheme()init(Object)runApp()start()stop()"));
index.put("com.codenameone.playground.PlaygroundContext", splitMembers("captureShownForm(Form)clearPreview()clearShownForm()getHostForm()getPreviewRoot()getShownForm()getTheme()log(String)refreshPreview()setTitle(String)debug(String)getCurrent()interceptMethodInvocation(Object, String, Object[])"));
index.put("com.codenameone.playground.PlaygroundContext", splitMembers("captureShownForm(Form)clearCreatedComponents()clearPreview()clearShownForm()getCreatedComponents()getFirstCreatedComponent()getFirstCreatedForm()getHostForm()getPreviewRoot()getShownForm()getTheme()log(String)recordCreatedComponent(Component)refreshPreview()setTitle(String)debug(String)getCurrent()interceptMethodInvocation(Object, String, Object[])notifyConstructed(Object)"));
index.put("com.codenameone.playground.PlaygroundContext.Logger", splitMembers("log(String)"));
index.put("com.codenameone.playground.PlaygroundLambdaBridge", splitMembers("lambda(Object[], String)lambda(String[], String)"));
index.put("com.codenameone.playground.PlaygroundListenerBridge", splitMembers("actionListener(Object)networkListener(Object)onComplete(Object)runnable(Object)"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ private static Object invokeStatic0(String name, Object[] safeArgs) throws Excep
return com.codenameone.playground.PlaygroundContext.interceptMethodInvocation((java.lang.Object) adaptedArgs[0], (java.lang.String) adaptedArgs[1], (java.lang.Object[]) adaptedArgs[2]);
}
}
if ("notifyConstructed".equals(name)) {
if (matches(safeArgs, new Class<?>[]{java.lang.Object.class}, false)) {
Object[] adaptedArgs = adaptArgs(safeArgs, new Class<?>[]{java.lang.Object.class}, false);
com.codenameone.playground.PlaygroundContext.notifyConstructed((java.lang.Object) adaptedArgs[0]); return null;
}
}
throw unsupportedStatic(com.codenameone.playground.PlaygroundContext.class, name, safeArgs);
}

Expand Down Expand Up @@ -175,6 +181,11 @@ private static Object invoke1(com.codenameone.playground.PlaygroundContext typed
typedTarget.captureShownForm((com.codename1.ui.Form) adaptedArgs[0]); return null;
}
}
if ("clearCreatedComponents".equals(name)) {
if (safeArgs.length == 0) {
typedTarget.clearCreatedComponents(); return null;
}
}
if ("clearPreview".equals(name)) {
if (safeArgs.length == 0) {
typedTarget.clearPreview(); return null;
Expand All @@ -185,6 +196,21 @@ private static Object invoke1(com.codenameone.playground.PlaygroundContext typed
typedTarget.clearShownForm(); return null;
}
}
if ("getCreatedComponents".equals(name)) {
if (safeArgs.length == 0) {
return typedTarget.getCreatedComponents();
}
}
if ("getFirstCreatedComponent".equals(name)) {
if (safeArgs.length == 0) {
return typedTarget.getFirstCreatedComponent();
}
}
if ("getFirstCreatedForm".equals(name)) {
if (safeArgs.length == 0) {
return typedTarget.getFirstCreatedForm();
}
}
if ("getHostForm".equals(name)) {
if (safeArgs.length == 0) {
return typedTarget.getHostForm();
Expand All @@ -211,6 +237,12 @@ private static Object invoke1(com.codenameone.playground.PlaygroundContext typed
typedTarget.log((java.lang.String) adaptedArgs[0]); return null;
}
}
if ("recordCreatedComponent".equals(name)) {
if (matches(safeArgs, new Class<?>[]{com.codename1.ui.Component.class}, false)) {
Object[] adaptedArgs = adaptArgs(safeArgs, new Class<?>[]{com.codename1.ui.Component.class}, false);
typedTarget.recordCreatedComponent((com.codename1.ui.Component) adaptedArgs[0]); return null;
}
}
if ("refreshPreview".equals(name)) {
if (safeArgs.length == 0) {
typedTarget.refreshPreview(); return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.codenameone.playground;

import com.codename1.ui.CN;
import com.codename1.ui.Component;
import com.codename1.ui.Container;
import com.codename1.ui.Dialog;
import com.codename1.ui.Form;
import com.codename1.ui.CN;
import com.codename1.ui.util.Resources;

import java.util.ArrayList;
import java.util.List;

/**
* Host objects and helpers exposed to user scripts.
*/
Expand All @@ -21,6 +25,9 @@ public interface Logger {
private final Resources theme;
private final Logger logger;
private Form shownForm;
private final List<Component> createdComponents = new ArrayList<Component>();
private Form firstCreatedForm;
private Component firstCreatedComponent;

public PlaygroundContext(Form hostForm, Container previewRoot, Resources theme, Logger logger) {
this.hostForm = hostForm;
Expand Down Expand Up @@ -56,6 +63,17 @@ public static PlaygroundContext getCurrent() {
public static void debug(String message) {
}

public static void notifyConstructed(Object instance) {
if (!(instance instanceof Component)) {
return;
}
PlaygroundContext context = CURRENT.get();
if (context == null) {
return;
}
context.recordCreatedComponent((Component) instance);
}

public static boolean interceptMethodInvocation(Object target, String methodName, Object[] args) {
PlaygroundContext context = CURRENT.get();
if (context == null) {
Expand Down Expand Up @@ -91,6 +109,37 @@ public void clearShownForm() {
shownForm = null;
}

public void recordCreatedComponent(Component component) {
if (component == null || component == hostForm || component == previewRoot) {
return;
}
if (firstCreatedComponent == null) {
firstCreatedComponent = component;
}
if (firstCreatedForm == null && component instanceof Form) {
firstCreatedForm = (Form) component;
}
createdComponents.add(component);
}

public Component getFirstCreatedComponent() {
return firstCreatedComponent;
}

public Form getFirstCreatedForm() {
return firstCreatedForm;
}

public List<Component> getCreatedComponents() {
return createdComponents;
}

public void clearCreatedComponents() {
createdComponents.clear();
firstCreatedForm = null;
firstCreatedComponent = null;
}

public void clearPreview() {
previewRoot.removeAll();
previewRoot.revalidate();
Expand Down
Loading
Loading