throw new IllegalStateException("Failed to create a Shell!");
}
@Override
public Object run(Object[] args) throws Exception {
// We need to synchronize: a non-UI thread may send a message thinking the component is valid, but the message would be invalid as the control is not yet in the registry.
ObjectRegistry controlRegistry = SWTNativeComponent.getControlRegistry();
synchronized(controlRegistry) {
final int componentID = (Integer)args[0];
Object canvasHandle = args[1];
final Shell shell = createShell(canvasHandle);
shell.addControlListener(new ControlAdapter() {
private boolean isAdjusting;
@Override
public void controlMoved(ControlEvent e) {
if(isAdjusting) {
return;
}
Shell shell = (Shell)e.widget;
Point location = shell.getLocation();
if(location.x != 0 || location.y != 0) {
// On Linux Ubuntu, I found that the location cannot be forced and this would cause a stack overflow.
isAdjusting = true;
shell.setLocation(0, 0);
isAdjusting = false;
}
}
});
shell.setLayout(new FillLayout());
Composite controlComposite = new Composite(shell, SWT.NONE);
controlComposite.setLayout(new FillLayout());
Control control = (Control)controlRegistry.get(componentID);
if(control != null) {
Shell oldShell = control.getShell();
control.setParent(controlComposite);
oldShell.dispose();
} else {
String nativeComponentClassName = (String)args[2];
Object nativePeerCreationParameters = args[3];
Method createControlMethod = Class.forName(nativeComponentClassName).getDeclaredMethod("createControl", Composite.class, Object[].class);
createControlMethod.setAccessible(true);
control = (Control)createControlMethod.invoke(null, controlComposite, nativePeerCreationParameters);
if(Boolean.parseBoolean(NSSystemPropertySWT.COMPONENTS_DEBUG_PRINTCREATION.get())) {
System.err.println("Created control: " + componentID);
}
control.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if(Boolean.parseBoolean(NSSystemPropertySWT.COMPONENTS_DEBUG_PRINTDISPOSAL.get())) {
System.err.println("Disposed control: " + componentID);
}
}
});
controlRegistry.add(control, componentID);
configureControl(control, componentID);
}
shell.setVisible (true);
shell.getDisplay().asyncExec(new Runnable() {
public void run() {