Hi Gordon,
Since the component creation must be in the AWT thread and is done in a
callback, the user cannot do stuff in this callback that assumes that
the component is already in-place, visible. The user could - in principle -
do this through an AWT HierarchyListener. But we want something that is
easy to use. So I feel it's better to provide a hook for it. Or better,
two hooks: one for each thread.
I need it already for one of the test views.
Applying this.
Index: src/org/eclipse/albireo/core/SwingControl.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.core/src/org/eclipse/albireo/core/SwingControl.java,v
retrieving revision 1.1
diff -c -3 -r1.1 SwingControl.java
*** src/org/eclipse/albireo/core/SwingControl.java 7 Dec 2007 21:14:28 -0000 1.1
--- src/org/eclipse/albireo/core/SwingControl.java 23 Jan 2008 18:09:33 -0000
***************
*** 1,5 ****
/*******************************************************************************
! * Copyright (c) 2007 SAS Institute Inc., ILOG S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
--- 1,5 ----
/*******************************************************************************
! * Copyright (c) 2007-2008 SAS Institute Inc., ILOG S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
***************
*** 117,122 ****
--- 117,145 ----
RootPaneContainer container = addRootPaneContainer(frame);
swingComponent = createSwingComponent();
container.getRootPane().getContentPane().add(swingComponent);
+ // Invoke hooks, for use by the application.
+ afterComponentCreatedAWTThread();
+ try {
+ // TODO: Use IlvSWTUtil.asyncExec or have the spurious NPE
+ // fixed in SWT proper.
+ getDisplay().asyncExec(
+ new Runnable() {
+ public void run() {
+ try {
+ afterComponentCreatedSWTThread();
+ } catch (Throwable e) {
+ // Be friendly to the developer:
+ // Show stack trace.
+ e.printStackTrace();
+ }
+ }
+ });
+ } catch (SWTException e) {
+ if (e.code == SWT.ERROR_WIDGET_DISPOSED)
+ return;
+ else
+ throw e;
+ }
}
});
}
***************
*** 169,173 ****
* @return a non-null Swing component
*/
protected abstract JComponent createSwingComponent();
}
-
\ No newline at end of file
--- 192,213 ----
* @return a non-null Swing component
*/
protected abstract JComponent createSwingComponent();
+
+ /**
+ * This callback is invoked after the embedded Swing component has been
+ * added to this control.
+ * <p>
+ * This method is executed on the AWT thread.
+ */
+ protected void afterComponentCreatedAWTThread() {
+ }
+
+ /**
+ * This callback is invoked after the embedded Swing component has been
+ * added to this control.
+ * <p>
+ * This method is executed on the SWT thread.
+ */
+ protected void afterComponentCreatedSWTThread() {
+ }
}
_______________________________________________
albireo-dev mailing list
albireo-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/albireo-dev