Skip to content

Commit 087d87b

Browse files
author
jossonsmith
committed
Fix bug that TreeItem is not inserted into correct position of tree
1 parent fa98105 commit 087d87b

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*******************************************************************************
2+
* Java2Script Pacemaker (http://j2s.sourceforge.net)
3+
*
4+
* Copyright (c) 2006 ognize.com and others.
5+
* All rights reserved. This program and the accompanying materials
6+
* are made available under the terms of the Eclipse Public License v1.0
7+
* which accompanies this distribution, and is available at
8+
* http://www.eclipse.org/legal/epl-v10.html
9+
*
10+
* Contributors:
11+
* ognize.com - initial API and implementation
12+
*******************************************************************************/
13+
14+
package net.sf.j2s.test.swt.ajunit;
15+
16+
import net.sf.j2s.ajax.junit.AsyncSWT;
17+
import net.sf.j2s.ajax.junit.AsyncTestCase;
18+
import net.sf.j2s.ajax.junit.AsyncTestRunnable;
19+
import net.sf.j2s.ajax.junit.AsyncTestRunner;
20+
import org.eclipse.swt.SWT;
21+
import org.eclipse.swt.layout.FillLayout;
22+
import org.eclipse.swt.widgets.Display;
23+
import org.eclipse.swt.widgets.Shell;
24+
import org.eclipse.swt.widgets.Tree;
25+
import org.eclipse.swt.widgets.TreeItem;
26+
27+
/**
28+
* @author josson smith
29+
*
30+
* 2006-8-1
31+
*/
32+
public class TreeStructureTest2 extends AsyncTestCase {
33+
34+
35+
public void testStruct4() {
36+
Display display = new Display ();
37+
Shell shell = new Shell (display);
38+
shell.setLayout(new FillLayout());
39+
final Tree tree = new Tree (shell, SWT.BORDER | SWT.CHECK);
40+
tree.setSize (100, 100);
41+
shell.setSize (300, 200);
42+
for (int i = 0; i < 4; i++) {
43+
TreeItem item = new TreeItem (tree, SWT.NONE);
44+
item.setText("Node." + (i + 1));
45+
if (i < 3) {
46+
TreeItem subitem = new TreeItem (item, SWT.NONE);
47+
subitem.setText("Node." + (i + 1) + ".1");
48+
}
49+
}
50+
TreeItem treeRoots[] = tree.getItems ();
51+
for (int i = 0; i < treeRoots.length; i++) {
52+
System.out.println(treeRoots[i].getText());
53+
}
54+
TreeItem item = new TreeItem (treeRoots[1], SWT.NONE);
55+
item.setText("Node 2.2");
56+
item = new TreeItem (item, SWT.NONE);
57+
item.setText("Node 2.2.1");
58+
shell.open ();
59+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
60+
public void run() {
61+
}
62+
});
63+
display.dispose ();
64+
}
65+
66+
public void testStruct3() {
67+
Display display = new Display ();
68+
Shell shell = new Shell (display);
69+
shell.setLayout(new FillLayout());
70+
final Tree tree = new Tree (shell, SWT.BORDER | SWT.CHECK);
71+
tree.setSize (100, 100);
72+
shell.setSize (300, 200);
73+
for (int i = 0; i < 4; i++) {
74+
TreeItem item = new TreeItem (tree, SWT.NONE);
75+
item.setText("Node." + (i + 1));
76+
if (i < 3) {
77+
TreeItem subitem = new TreeItem (item, SWT.NONE);
78+
subitem.setText("Node." + (i + 1) + ".1");
79+
}
80+
}
81+
TreeItem treeRoots[] = tree.getItems ();
82+
for (int i = 0; i < treeRoots.length; i++) {
83+
System.out.println(treeRoots[i].getText());
84+
}
85+
TreeItem item = new TreeItem (treeRoots[1].getItems()[0], SWT.NONE);
86+
item.setText("Node 2.1.1");
87+
// item = new TreeItem (item, SWT.NONE);
88+
// item.setText("Node 2.2.1");
89+
shell.open ();
90+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
91+
public void run() {
92+
}
93+
});
94+
display.dispose ();
95+
}
96+
97+
public void testStruct2() {
98+
Display display = new Display ();
99+
Shell shell = new Shell (display);
100+
shell.setLayout(new FillLayout());
101+
final Tree tree = new Tree (shell, SWT.BORDER | SWT.CHECK);
102+
tree.setSize (100, 100);
103+
shell.setSize (300, 200);
104+
for (int i = 0; i < 4; i++) {
105+
TreeItem item = new TreeItem (tree, SWT.NONE);
106+
item.setText("Node." + (i + 1));
107+
if (i < 3) {
108+
TreeItem subitem = new TreeItem (item, SWT.NONE);
109+
subitem.setText("Node." + (i + 1) + ".1");
110+
}
111+
}
112+
TreeItem treeRoots[] = tree.getItems ();
113+
for (int i = 0; i < treeRoots.length; i++) {
114+
System.out.println(treeRoots[i].getText());
115+
}
116+
TreeItem item = new TreeItem (treeRoots[1], SWT.NONE);
117+
item.setText("Node 2.2");
118+
// item = new TreeItem (item, SWT.NONE);
119+
// item.setText("Node 2.2.1");
120+
shell.open ();
121+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
122+
public void run() {
123+
}
124+
});
125+
display.dispose ();
126+
}
127+
128+
public void testStruct1() {
129+
Display display = new Display ();
130+
Shell shell = new Shell (display);
131+
shell.setLayout(new FillLayout());
132+
final Tree tree = new Tree (shell, SWT.BORDER | SWT.CHECK);
133+
tree.setSize (100, 100);
134+
shell.setSize (300, 200);
135+
for (int i = 0; i < 4; i++) {
136+
TreeItem item = new TreeItem (tree, SWT.NONE);
137+
item.setText("Node." + (i + 1));
138+
if (i < 3) {
139+
TreeItem subitem = new TreeItem (item, SWT.NONE);
140+
subitem.setText("Node." + (i + 1) + ".1");
141+
}
142+
}
143+
// TreeItem treeRoots[] = tree.getItems ();
144+
// TreeItem item = new TreeItem (treeRoots[1], SWT.NONE);
145+
// item.setText("Node 2.2");
146+
// item = new TreeItem (item, SWT.NONE);
147+
// item.setText("Node 2.2.1");
148+
shell.open ();
149+
AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) {
150+
public void run() {
151+
}
152+
});
153+
display.dispose ();
154+
}
155+
156+
public static void main(String[] args) {
157+
AsyncSWT.setShellAutoClose(false);
158+
AsyncTestRunner.asyncRun (TreeStructureTest2.class);
159+
}
160+
}

0 commit comments

Comments
 (0)