Skip to content

Commit 63bae06

Browse files
author
jossonsmith
committed
Support asynchronous Class.forName with net.sf.j2s.ajax.AClass.load (clazzName, ...).
See ControlExamples' loading tabs by Java reflections.
1 parent bd9f8a5 commit 63bae06

13 files changed

Lines changed: 126 additions & 37 deletions

File tree

tests/org.eclipse.swt.examples/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
55
<classpathentry kind="con" path="SWT_CONTAINER/PLATFORM"/>
6+
<classpathentry sourcepath="/AJAX_SWT_SRC" kind="var" path="AJAX_SWT"/>
67
<classpathentry kind="output" path="bin"/>
78
</classpath>

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ButtonTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ButtonTab extends AlignableTab {
3535
/**
3636
* Creates the Tab within a given instance of ControlExample.
3737
*/
38-
ButtonTab(ControlExample instance) {
38+
public ButtonTab(ControlExample instance) {
3939
super(instance);
4040
}
4141

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ComboTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ComboTab extends Tab {
3838
/**
3939
* Creates the Tab within a given instance of ControlExample.
4040
*/
41-
ComboTab(ControlExample instance) {
41+
public ComboTab(ControlExample instance) {
4242
super(instance);
4343
}
4444

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ControlExample.java

Lines changed: 114 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package org.eclipse.swt.examples.controlexample;
1212

1313

14+
import net.sf.j2s.ajax.ASWTClass;
1415
import org.eclipse.swt.*;
1516
import org.eclipse.swt.events.SelectionAdapter;
1617
import org.eclipse.swt.events.SelectionEvent;
@@ -19,6 +20,7 @@
1920
import org.eclipse.swt.widgets.*;
2021

2122
import java.io.*;
23+
import java.lang.reflect.Constructor;
2224
import java.text.*;
2325
import java.util.*;
2426

@@ -28,6 +30,7 @@
2830
*
2931
* 2006-7-9
3032
*
33+
* @j2sRequireImport java.lang.reflect.Constructor
3134
* @j2sIgnoreImport java.text.MessageFormat
3235
*/
3336
public class ControlExample {
@@ -54,6 +57,86 @@ public class ControlExample {
5457
public ControlExample(Composite parent) {
5558
initResources();
5659
tabFolder = new TabFolder (parent, SWT.NONE);
60+
String[] tabs = new String[] {
61+
"Button",
62+
"Label",
63+
// "Canvas",
64+
"Combo",
65+
// "CoolBar",
66+
// "Dialog",
67+
"Group",
68+
"Label",
69+
"Link",
70+
// "List",
71+
// "Menu",
72+
"ProgressBar",
73+
"Sash",
74+
// shellTab = new ShellTab(this),
75+
"Shell",
76+
"Slider",
77+
"Spinner",
78+
"TabFolder",
79+
// "Table",
80+
"Text"
81+
// "ToolBar",
82+
// "Tree"
83+
};
84+
for (int i=0; i<tabs.length; i++) {
85+
TabItem item = new TabItem (tabFolder, SWT.NONE);
86+
item.setText (tabs [i]);
87+
//item.setControl (tabs [i].createTabFolderPage (tabFolder));
88+
item.setData ("org.eclipse.swt.examples.controlexample." + tabs [i] + "Tab");
89+
}
90+
if (tabs.length > 0) {
91+
final TabItem item = tabFolder.getItem(0);
92+
ASWTClass.shellLoad(parent.getShell(), (String) item.getData(), new Runnable() {
93+
public void run() {
94+
try {
95+
Constructor constructor = Class.forName((String) item.getData()).getConstructor(new Class[] {ControlExample.class});
96+
Object inst = constructor.newInstance(new Object[] {ControlExample.this});
97+
Tab tab = (Tab) inst;
98+
item.setControl(tab.createTabFolderPage(tabFolder));
99+
//item.getParent().getShell().pack();
100+
} catch (Throwable e) {
101+
//e.printStackTrace();
102+
throw (Error) e;
103+
}
104+
}
105+
});
106+
}
107+
if (tabs.length > 1) {
108+
tabFolder.addSelectionListener(new SelectionAdapter() {
109+
public void widgetSelected(SelectionEvent e) {
110+
int idx = tabFolder.getSelectionIndex();
111+
if (idx != -1) {
112+
final TabItem item = tabFolder.getItem(idx);
113+
if (item.getControl() == null) {
114+
Object data = item.getData();
115+
if (data != null) {
116+
ASWTClass.shellLoad(tabFolder.getShell(), (String) data, new Runnable() {
117+
public void run() {
118+
try {
119+
Constructor constructor = Class.forName((String) item.getData()).getConstructor(new Class[] {ControlExample.class});
120+
Object inst = constructor.newInstance(new Object[] {ControlExample.this});
121+
Tab tab = (Tab) inst;
122+
if (((String) item.getData()).indexOf("Shell") != -1) {
123+
shellTab = (ShellTab) tab;
124+
}
125+
item.setControl(tab.createTabFolderPage(tabFolder));
126+
} catch (Throwable e) {
127+
//e.printStackTrace();
128+
throw (Error) e;
129+
}
130+
}
131+
});
132+
}
133+
}
134+
}
135+
}
136+
});
137+
}
138+
139+
/*
57140
Tab [] tabs = createTabs();
58141
for (int i=0; i<tabs.length; i++) {
59142
TabItem item = new TabItem (tabFolder, SWT.NONE);
@@ -82,36 +165,37 @@ public void widgetSelected(SelectionEvent e) {
82165
}
83166
});
84167
}
168+
*/
85169
startup = false;
86170
}
87171

88172
/**
89173
* Answers the set of example Tabs
90174
*/
91-
Tab[] createTabs() {
92-
return new Tab [] {
93-
new ButtonTab (this),
94-
// new CanvasTab (this),
175+
// Tab[] createTabs() {
176+
// return new Tab [] {
177+
// new ButtonTab (this),
178+
//// new CanvasTab (this),
95179
// new ComboTab (this),
96-
// new CoolBarTab (this),
97-
// new DialogTab (this),
98-
new GroupTab (this),
99-
new LabelTab (this),
100-
new LinkTab (this),
101-
// new ListTab (this),
102-
// new MenuTab (this),
180+
//// new CoolBarTab (this),
181+
//// new DialogTab (this),
182+
// new GroupTab (this),
183+
// new LabelTab (this),
184+
// new LinkTab (this),
185+
//// new ListTab (this),
186+
//// new MenuTab (this),
103187
// new ProgressBarTab (this),
104-
// new SashTab (this),
105-
shellTab = new ShellTab(this),
106-
// new SliderTab (this),
188+
//// new SashTab (this),
189+
// shellTab = new ShellTab(this),
190+
//// new SliderTab (this),
107191
// new SpinnerTab (this),
108-
new TabFolderTab (this),
109-
// new TableTab (this),
110-
new TextTab (this),
111-
// new ToolBarTab (this),
112-
// new TreeTab (this),
113-
};
114-
}
192+
// new TabFolderTab (this),
193+
//// new TableTab (this),
194+
// new TextTab (this),
195+
//// new ToolBarTab (this),
196+
//// new TreeTab (this),
197+
// };
198+
// }
115199

116200
/**
117201
* Disposes of all resources associated with a particular
@@ -216,17 +300,21 @@ public static void main(String[] args) {
216300
int styleNone = SWT.NONE;
217301
int style = styleNone;
218302
style = SWT.SHELL_TRIM;
219-
/**
220-
* @j2sNative
221-
* style = styleNone;
222-
*/ {}
303+
// /**
304+
// * @j2sNative
305+
// * style = styleNone;
306+
// */ {}
223307

224308
Shell shell = new Shell(display, style);
225309
shell.setLayout(new FillLayout());
226310
ControlExample instance = new ControlExample(shell);
227311
shell.setText(getResourceString("window.title"));
228312
// setShellSize(display, shell);
229-
shell.setMaximized(true);
313+
/**
314+
* @j2sNative
315+
* shell.setMaximized(true);
316+
*/ {}
317+
230318
shell.open();
231319
while (! shell.isDisposed()) {
232320
if (! display.readAndDispatch()) display.sleep();

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/GroupTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class GroupTab extends Tab {
2929
/**
3030
* Creates the Tab within a given instance of ControlExample.
3131
*/
32-
GroupTab(ControlExample instance) {
32+
public GroupTab(ControlExample instance) {
3333
super(instance);
3434
}
3535

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LabelTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LabelTab extends AlignableTab {
2727
/**
2828
* Creates the Tab within a given instance of ControlExample.
2929
*/
30-
LabelTab(ControlExample instance) {
30+
public LabelTab(ControlExample instance) {
3131
super(instance);
3232
}
3333

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/LinkTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LinkTab extends Tab {
2323
/**
2424
* Creates the Tab within a given instance of ControlExample.
2525
*/
26-
LinkTab(ControlExample instance) {
26+
public LinkTab(ControlExample instance) {
2727
super(instance);
2828
}
2929

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ProgressBarTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ProgressBarTab extends RangeTab {
2727
/**
2828
* Creates the Tab within a given instance of ControlExample.
2929
*/
30-
ProgressBarTab(ControlExample instance) {
30+
public ProgressBarTab(ControlExample instance) {
3131
super(instance);
3232
}
3333

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ShellTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ShellTab extends Tab {
3232
/**
3333
* Creates the Tab within a given instance of ControlExample.
3434
*/
35-
ShellTab(ControlExample instance) {
35+
public ShellTab(ControlExample instance) {
3636
super(instance);
3737
}
3838

tests/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/SliderTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SliderTab extends RangeTab {
2828
/**
2929
* Creates the Tab within a given instance of ControlExample.
3030
*/
31-
SliderTab(ControlExample instance) {
31+
public SliderTab(ControlExample instance) {
3232
super(instance);
3333
}
3434

0 commit comments

Comments
 (0)