View | Details | Raw Unified | Return to bug 205864
Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 10-16 Link Here
10
 org.eclipse.ui.forms.events,
10
 org.eclipse.ui.forms.events,
11
 org.eclipse.ui.forms.widgets,
11
 org.eclipse.ui.forms.widgets,
12
 org.eclipse.ui.internal.forms;x-internal:=true,
12
 org.eclipse.ui.internal.forms;x-internal:=true,
13
 org.eclipse.ui.internal.forms.widgets;x-friends:="org.eclipse.ua.tests"
13
 org.eclipse.ui.internal.forms.widgets;x-friends:="org.eclipse.ui.tests.forms"
14
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)",
14
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)",
15
 org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
15
 org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
16
 org.eclipse.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional
16
 org.eclipse.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional
(-).project (+28 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.eclipse.ui.tests.forms</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
(-)forms/org/eclipse/ui/tests/forms/layout/AllLayoutTests.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.tests.forms.layout;
13
14
import junit.framework.Test;
15
import junit.framework.TestSuite;
16
17
public class AllLayoutTests {
18
19
	public static Test suite() {
20
		TestSuite suite = new TestSuite(
21
				"org.eclipse.ua.tests.forms.AllLayoutTests");
22
		//$JUnit-BEGIN$
23
		suite.addTestSuite(TestTableWrapLayout.class);
24
		//$JUnit-END$
25
		return suite;
26
	}
27
28
}
(-)META-INF/MANIFEST.MF (+14 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Forms Test
4
Bundle-SymbolicName: org.eclipse.ui.tests.forms;singleton:=true
5
Bundle-Version: 3.3.100.qualifier
6
Bundle-Activator: org.eclipse.ui.tests.forms.plugin.FormsTestPlugin
7
Require-Bundle: org.eclipse.ui,
8
 org.eclipse.core.runtime,
9
 org.eclipse.test.performance,
10
 org.eclipse.ui.forms,
11
 org.junit
12
Eclipse-LazyStart: true
13
Bundle-Vendor: Eclipse.org
14
Bundle-ClassPath: forms-tests.jar
(-)forms/org/eclipse/ui/tests/forms/AllFormsTests.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.tests.forms;
13
14
import junit.framework.Test;
15
import junit.framework.TestSuite;
16
17
import org.eclipse.ui.tests.forms.layout.AllLayoutTests;
18
import org.eclipse.ui.tests.forms.util.AllUtilityTests;
19
20
/*
21
 * Tests all cheat sheet functionality (automated).
22
 */
23
public class AllFormsTests extends TestSuite {
24
25
	/*
26
	 * Returns the entire test suite.
27
	 */
28
	public static Test suite() {
29
		return new AllFormsTests();
30
	}
31
32
	/*
33
	 * Constructs a new test suite.
34
	 */
35
	public AllFormsTests() {
36
		addTest(AllLayoutTests.suite());
37
		addTest(AllUtilityTests.suite());
38
	}
39
}
(-)forms/org/eclipse/ui/tests/forms/performance/FormsPerformanceTest.java (+231 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.tests.forms.performance;
13
14
import org.eclipse.jface.resource.JFaceResources;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.layout.FillLayout;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Display;
21
import org.eclipse.swt.widgets.Label;
22
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.widgets.Text;
24
import org.eclipse.test.performance.Dimension;
25
import org.eclipse.test.performance.Performance;
26
import org.eclipse.test.performance.PerformanceTestCase;
27
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.forms.events.ExpansionAdapter;
29
import org.eclipse.ui.forms.events.ExpansionEvent;
30
import org.eclipse.ui.forms.events.HyperlinkAdapter;
31
import org.eclipse.ui.forms.events.HyperlinkEvent;
32
import org.eclipse.ui.forms.widgets.ExpandableComposite;
33
import org.eclipse.ui.forms.widgets.FormText;
34
import org.eclipse.ui.forms.widgets.FormToolkit;
35
import org.eclipse.ui.forms.widgets.Hyperlink;
36
import org.eclipse.ui.forms.widgets.ImageHyperlink;
37
import org.eclipse.ui.forms.widgets.ScrolledForm;
38
import org.eclipse.ui.forms.widgets.Section;
39
import org.eclipse.ui.forms.widgets.TableWrapData;
40
import org.eclipse.ui.forms.widgets.TableWrapLayout;
41
42
public class FormsPerformanceTest extends PerformanceTestCase {
43
	
44
	public void test_createForm() {
45
		tagAsSummary("Create Form", Dimension.ELAPSED_PROCESS);
46
	    Performance.getDefault();
47
		
48
		// Warm up.
49
50
		Display display = PlatformUI.getWorkbench().getDisplay();
51
52
		FormToolkit toolkit;
53
		toolkit = new FormToolkit(display);
54
		for(int samples = 0; samples < 2; samples++) {
55
			Shell shell = new Shell(display);
56
			shell.setSize(400, 300);
57
			shell.setLayout(new FillLayout());
58
			shell.open();
59
60
			for (int i = 0; i < 5; i++) {
61
				Composite c = new Composite(shell, SWT.H_SCROLL + SWT.V_SCROLL);
62
				c.setLayout(new FillLayout());
63
                createPartControl(c, toolkit);
64
                shell.layout(true); 
65
                while(display.readAndDispatch()){/*empty*/}
66
				c.dispose();
67
			}
68
			shell.dispose();
69
			while(display.readAndDispatch()){/*empty*/}
70
		}
71
72
		for(int samples = 0; samples < 50; samples++) {
73
			Shell shell = new Shell(display);
74
			shell.setSize(400, 300);
75
			shell.setLayout(new FillLayout());
76
			shell.open();
77
			startMeasuring();
78
			for (int i = 0; i < 3; i++) {
79
				Composite c = new Composite(shell, SWT.H_SCROLL + SWT.V_SCROLL);
80
				c.setLayout(new FillLayout());
81
                createPartControl(c, toolkit);
82
                shell.layout(true);
83
                while(display.readAndDispatch()){/*empty*/}
84
				c.dispose();
85
			}
86
			stopMeasuring(); 
87
			shell.dispose();
88
			while(display.readAndDispatch()){/*empty*/}
89
		}	
90
		toolkit.dispose();
91
		commitMeasurements();
92
		assertPerformance();
93
	}
94
	
95
	public void createPartControl(Composite parent, FormToolkit toolkit) {
96
		//Label l = new Label(parent, SWT.NULL);
97
		//l.setText ("a label");
98
		ScrolledForm form;
99
		form = toolkit.createScrolledForm(parent);
100
		form.setText("Hello, Eclipse Forms");
101
		TableWrapLayout layout = new TableWrapLayout();
102
		form.getBody().setLayout(layout);
103
		
104
		Hyperlink link = toolkit.createHyperlink(form.getBody(), "Click here.",
105
				SWT.WRAP);
106
		link.addHyperlinkListener(new HyperlinkAdapter() {
107
			public void linkActivated(HyperlinkEvent e) {
108
				System.out.println("Link activated!");
109
			}
110
		});
111
		link.setText("This is an example of a form that is much longer and will need to wrap.");
112
		layout.numColumns = 2;
113
		TableWrapData td = new TableWrapData();
114
		td.colspan = 2;
115
		link.setLayoutData(td);
116
		toolkit.createLabel(form.getBody(), "Text field label:");
117
		Text text = toolkit.createText(form.getBody(), "");
118
		td = new TableWrapData(TableWrapData.FILL_GRAB);
119
		text.setLayoutData(td);
120
		Button button = toolkit.createButton(form.getBody(),
121
				"An example of a checkbox in a form", SWT.CHECK);
122
		td = new TableWrapData();
123
		td.colspan = 2;
124
		button.setLayoutData(td);
125
		
126
		ImageHyperlink ih = toolkit.createImageHyperlink(form.getBody(), SWT.NULL);
127
		ih.setText("Image link with no image");
128
		ih = toolkit.createImageHyperlink(form.getBody(), SWT.NULL);
129
		//ih.setImage(ExamplesPlugin.getDefault().getImageRegistry().get(ExamplesPlugin.IMG_SAMPLE));
130
		ih.setText("Link with image and text");
131
		
132
		ExpandableComposite ec = toolkit.createExpandableComposite(form.getBody(), ExpandableComposite.TREE_NODE|ExpandableComposite.CLIENT_INDENT);
133
		ImageHyperlink eci = toolkit.createImageHyperlink(ec, SWT.NULL);
134
		//eci.setImage(ExamplesPlugin.getDefault().getImageRegistry().get(ExamplesPlugin.IMG_SAMPLE));
135
		ec.setTextClient(eci);
136
		ec.setText("Expandable Composite title");
137
		String ctext = "We will now create a somewhat long text so that "+
138
		"we can use it as content for the expandable composite. "+
139
		"Expandable composite is used to hide or show the text using the "+
140
		"toggle control";
141
		Label client = toolkit.createLabel(ec, ctext, SWT.WRAP);
142
		ec.setClient(client);
143
		td = new TableWrapData();
144
		td.colspan = 2;
145
		ec.setLayoutData(td);
146
		ec.addExpansionListener(new ExpansionAdapter() {
147
			public void expansionStateChanged(ExpansionEvent e) {
148
				//form.reflow(true);
149
			}
150
		});
151
		Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TWISTIE|Section.EXPANDED);
152
		td = new TableWrapData(TableWrapData.FILL);
153
		td.colspan = 2;
154
		section.setLayoutData(td);
155
		section.addExpansionListener(new ExpansionAdapter() {
156
			public void expansionStateChanged(ExpansionEvent e) {
157
				//form.reflow(true);
158
			}
159
		});
160
		section.setText("Section title");
161
		toolkit.createCompositeSeparator(section);
162
		section.setDescription("This is the description that goes below the title");
163
		Composite sectionClient = toolkit.createComposite(section);
164
		sectionClient.setLayout(new GridLayout());
165
		button = toolkit.createButton(sectionClient, "Radio 1", SWT.RADIO);
166
		button = toolkit.createButton(sectionClient, "Radio 2", SWT.RADIO);
167
		section.setClient(sectionClient);
168
169
		StringBuffer buf = new StringBuffer();
170
		buf.append("<form>");
171
		buf.append("<p>");
172
		buf.append("Here is some plain text for the text to render; ");
173
		buf.append("this text is at <a href=\"http://www.eclipse.org\" nowrap=\"true\">http://www.eclipse.org</a> web site.");
174
		buf.append("</p>");
175
		buf.append("<p>");
176
		buf.append("<span color=\"header\" font=\"header\">This text is in header font.</span>");
177
		buf.append("</p>");
178
		buf.append("<p>This line will contain some <b>bold</b> and some <span font=\"code\">source</span> text. ");
179
		buf.append("We can also add <img href=\"image\"/> an image. ");
180
		buf.append("</p>");
181
		buf.append("<li>A default (bulleted) list item.</li>");
182
		buf.append("<li>Another bullet list item.</li>");
183
		buf.append("<li style=\"text\" value=\"1.\">A list item with text.</li>");
184
		buf.append("<li style=\"text\" value=\"2.\">Another list item with text</li>");
185
		buf.append("<li style=\"image\" value=\"image\">List item with an image bullet</li>");
186
		buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"3.\">A list item with text.</li>");
187
		buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"4.\">A list item with text.</li>");
188
		buf.append("<p>     leading blanks;      more white \n\n new lines   <br/><br/><br/> \n more <b>   bb   </b>  white  . </p>");
189
		buf.append("</form>");
190
		FormText rtext = toolkit.createFormText(form.getBody(), false);
191
		//rtext.setWhitespaceNormalized(false);
192
		td = new TableWrapData(TableWrapData.FILL);
193
		td.colspan = 2;
194
		rtext.setLayoutData(td);
195
		//rtext.setImage("image", ExamplesPlugin.getDefault().getImageRegistry().get(ExamplesPlugin.IMG_SAMPLE));
196
		//rtext.setColor("header", JFaceColors.getErrorText(display));
197
		rtext.setFont("header", JFaceResources.getHeaderFont());
198
		rtext.setFont("code", JFaceResources.getTextFont());
199
		rtext.setText(buf.toString(), true, false);
200
		rtext.addHyperlinkListener(new HyperlinkAdapter() {
201
			public void linkActivated(HyperlinkEvent e) {
202
				System.out.println("Link active: "+e.getHref());
203
			}
204
		});
205
/*		layout.numColumns = 3;
206
		Label label;
207
		TableWrapData td;
208
		
209
		label = toolkit.createLabel(form.getBody(), "Some text to put in the first column", SWT.WRAP);
210
		label = toolkit.createLabel(form.getBody() ,"Some text to put in the second column and make it a bit longer so that we can see what happens with column distribution. This text must be the longest so that it can get more space allocated to the columns it belongs to.", SWT.WRAP);
211
		td = new TableWrapData();
212
		td.colspan = 2;
213
		label.setLayoutData(td);
214
		label = toolkit.createLabel(form.getBody(), "This text will span two rows and should not grow the column.", SWT.WRAP);
215
		td = new TableWrapData();
216
		td.rowspan = 2;
217
		label.setLayoutData(td);
218
		label = toolkit.createLabel(form.getBody(), "This text goes into column 2 and consumes only one cell", SWT.WRAP);
219
		label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
220
		label = toolkit.createLabel(form.getBody(), "This text goes into column 3 and consumes only one cell too", SWT.WRAP);
221
		label.setLayoutData(new TableWrapData(TableWrapData.FILL));
222
		label = toolkit.createLabel(form.getBody(), "This text goes into column 2 and consumes only one cell", SWT.WRAP);
223
		label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
224
		label = toolkit.createLabel(form.getBody(), "This text goes into column 3 and consumes only one cell too", SWT.WRAP);
225
		label.setLayoutData(new TableWrapData(TableWrapData.FILL));
226
		form.getBody().setBackground(form.getBody().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));*/
227
		
228
		toolkit.paintBordersFor(form.getBody());
229
	}
230
231
}
(-)forms/org/eclipse/ui/tests/forms/AllFormsPerformanceTests.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.forms;
12
13
import org.eclipse.ui.tests.forms.performance.FormsPerformanceTest;
14
15
import junit.framework.Test;
16
import junit.framework.TestSuite;
17
18
/*
19
 * Tests forms performance (automated).
20
 */
21
public class AllFormsPerformanceTests extends TestSuite {
22
23
	/*
24
	 * Returns the entire test suite.
25
	 */
26
	public static Test suite() {
27
		return new AllFormsPerformanceTests();
28
	}
29
30
	/*
31
	 * Constructs a new performance test suite.
32
	 */
33
	public AllFormsPerformanceTests() {
34
		addTestSuite(FormsPerformanceTest.class);
35
	}
36
}
(-)about.html (+28 lines)
Added Link Here
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
6
<title>About</title>
7
</head>
8
<body lang="EN-US">
9
<h2>About This Content</h2>
10
 
11
<p>June 2, 2006</p>	
12
<h3>License</h3>
13
14
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;).  Unless otherwise 
15
indicated below, the Content is provided to you under the terms and conditions of the
16
Eclipse Public License Version 1.0 (&quot;EPL&quot;).  A copy of the EPL is available 
17
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
18
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
19
20
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is 
21
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
22
apply to your use of any object code in the Content.  Check the Redistributor's license that was 
23
provided with the Content.  If no such license exists, contact the Redistributor.  Unless otherwise
24
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
25
and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
26
27
</body>
28
</html>
(-)build.properties (+16 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2005, 2006 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
# 
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
bin.includes = forms-tests.jar,\
12
               META-INF/,\
13
               about.html
14
jars.compile.order = forms-tests.jar
15
output.forms-tests.jar = bin/
16
source.forms-tests.jar = forms/
(-)forms/org/eclipse/ui/tests/forms/layout/TestTableWrapLayout.java (+210 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.tests.forms.layout;
13
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.layout.FillLayout;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.forms.widgets.TableWrapData;
23
import org.eclipse.ui.forms.widgets.TableWrapLayout;
24
25
import junit.framework.TestCase;
26
27
public class TestTableWrapLayout extends TestCase {
28
29
	private final String A1 = "A";
30
	private final String A10 = "A A A A A A A A A A";
31
	private final String A20 = A10 + " " + A10;
32
	private final String A40 = A20 + " " + A20;
33
	private final String A80 = A40 + " " + A40;
34
	
35
	// Returns the width + left
36
	private int rightEdge(Label lab) {
37
		Rectangle r = lab.getBounds();
38
		return r.x + r.width;
39
	}
40
	
41
	/**
42
	 * Test that labels with the WRAP property set do indeed wrap.
43
	 */
44
	public void testTableWrapLayoutNonWrappingLabels() {
45
		Display display = PlatformUI.getWorkbench().getDisplay();
46
		Shell shell = new Shell(display);
47
		shell.setSize(100, 300);
48
		shell.setLayout(new FillLayout());
49
		Composite inner = new Composite(shell, SWT.V_SCROLL);
50
		inner.setLayout(new TableWrapLayout());
51
		Label l1 = new Label(inner, SWT.NULL);
52
		l1.setText(A10);
53
		Label l2 = new Label(inner, SWT.NULL);
54
		l2.setText(A80);
55
		shell.layout();
56
		assertEquals(l1.getSize().y, l2.getSize().y);
57
		assertTrue(l2.getSize().x > 100);
58
		shell.dispose();
59
	}
60
	
61
	/**
62
	 * Test that labels with the WRAP property set do indeed wrap.
63
	 */
64
    // Test suppressed for now - does not pass but not sure if this is a bug
65
	public void suppressed_testWrappingPoint() {
66
		Display display = PlatformUI.getWorkbench().getDisplay();
67
		Shell shell = new Shell(display);
68
		shell.setSize(300, 300);
69
		shell.setLayout(new FillLayout());
70
		Composite inner = new Composite(shell, SWT.V_SCROLL);
71
		TableWrapLayout tableWrapLayout = new TableWrapLayout();
72
		tableWrapLayout.leftMargin = 0;
73
		tableWrapLayout.rightMargin = 0;
74
		inner.setLayout(tableWrapLayout);
75
		Label l1 = new Label(inner, SWT.WRAP);
76
		l1.setText(A10);
77
		shell.layout();
78
		int originalWidth = l1.getSize().x;
79
		int originalHeight = l1.getSize().y;
80
		shell.setSize(originalWidth, 300);
81
		shell.layout();
82
		assertEquals(l1.getSize().y, originalHeight);
83
		shell.setSize(originalWidth / 2, 300);
84
		shell.layout();
85
		inner.layout();
86
		assertTrue(l1.getSize().y > originalHeight);
87
		shell.dispose();
88
	}
89
	
90
	/**
91
	 * Test that labels with the WRAP property set do indeed wrap.
92
	 */
93
	// Test suppressed for now, see Bug 196686 
94
	public void suppressed_testTableWrapLayoutWrappingLabels() {
95
		Display display = PlatformUI.getWorkbench().getDisplay();
96
		Shell shell = new Shell(display);
97
		shell.setSize(100, 300);
98
		shell.setLayout(new FillLayout());
99
		Composite inner = new Composite(shell, SWT.V_SCROLL);
100
		inner.setLayout(new TableWrapLayout());
101
		Label l1 = new Label(inner, SWT.WRAP);
102
		l1.setText(A10);
103
		Label l2 = new Label(inner, SWT.WRAP);
104
		l2.setText(A80);
105
		shell.layout();
106
		assertTrue(l1.getSize().y < l2.getSize().y);
107
		assertTrue("Label is too wide for layout ", l1.getSize().x <= 100);
108
		assertTrue("Label is too wide for layout ", l2.getSize().x <= 100);
109
		assertTrue("Labels overlap", l2.getBounds().y >= l1.getBounds().y + l1.getBounds().height);
110
		shell.dispose();
111
	}
112
	
113
	/**
114
	 * Test a 2x2 grid with unequal sizes
115
	 */
116
	public void testTableWrapLayoutTwoColumnsWrappingLabels() {
117
		Display display = PlatformUI.getWorkbench().getDisplay();
118
		Shell shell = new Shell(display);
119
		shell.setSize(100, 300);
120
		shell.setLayout(new FillLayout());
121
		Composite inner = new Composite(shell, SWT.V_SCROLL);
122
		TableWrapLayout tableWrapLayout = new TableWrapLayout();
123
		tableWrapLayout.numColumns = 2;
124
		inner.setLayout(tableWrapLayout);
125
		Label l1 = new Label(inner, SWT.WRAP);
126
		l1.setText(A10);
127
		Label l2 = new Label(inner, SWT.WRAP);
128
		l2.setText(A20);
129
		Label l3 = new Label(inner, SWT.WRAP);
130
		l3.setText(A40);
131
		Label l4 = new Label(inner, SWT.WRAP);
132
		l4.setText(A80);
133
		shell.layout();
134
		assertTrue(l1.getSize().x < l2.getSize().x);
135
		assertTrue(l1.getSize().y < l3.getSize().y);
136
		assertTrue(l1.getSize().x < l4.getSize().x);
137
		assertTrue(l2.getSize().y < l3.getSize().y);
138
		assertTrue("Label is too wide for layout ", l1.getSize().x + l2.getSize().x <= 100);
139
		assertTrue("Labels overlap", l2.getBounds().x >= l1.getBounds().x + l1.getBounds().width);
140
		assertTrue("Labels overlap", l3.getBounds().y >= l1.getBounds().y + l1.getBounds().height);
141
		assertTrue("Labels overlap", l4.getBounds().x >= l3.getBounds().x + l3.getBounds().width);
142
		assertTrue("Labels overlap", l4.getBounds().y >= l2.getBounds().y + l2.getBounds().height);
143
		shell.dispose();
144
	}
145
	
146
	/**
147
	 * Test alignments and margins
148
	 */
149
	// Suppressed for now - see Bug 196686 
150
	public void suppressed_testTableWrapLayoutAlignment() {
151
		Display display = PlatformUI.getWorkbench().getDisplay();
152
		Shell shell = new Shell(display);
153
		shell.setSize(100, 300);
154
		shell.setLayout(new FillLayout());
155
		Composite inner = new Composite(shell, SWT.V_SCROLL);
156
		TableWrapLayout tableWrapLayout = new TableWrapLayout();
157
		final int LEFT_MARGIN = 1;
158
		final int RIGHT_MARGIN = 2;
159
		final int TOP_MARGIN = 3;
160
		final int BOTTOM_MARGIN = 4;
161
		tableWrapLayout.leftMargin = LEFT_MARGIN;
162
		tableWrapLayout.rightMargin = RIGHT_MARGIN;
163
		tableWrapLayout.topMargin = TOP_MARGIN;
164
		tableWrapLayout.bottomMargin = BOTTOM_MARGIN;
165
		inner.setLayout(tableWrapLayout);
166
		Label lab0 = new Label(inner, SWT.WRAP);
167
		lab0.setText(A80);
168
		Label labLeft = new Label(inner, SWT.NULL);
169
		labLeft.setText(A1);
170
		TableWrapData dataLeft = new TableWrapData();
171
		dataLeft.align = TableWrapData.LEFT;
172
		labLeft.setLayoutData(dataLeft);
173
		Label labRight = new Label(inner, SWT.NULL);
174
		labRight.setText(A1);
175
		TableWrapData dataRight = new TableWrapData();
176
		dataRight.align = TableWrapData.RIGHT;
177
		labRight.setLayoutData(dataRight);
178
		Label labCenter = new Label(inner, SWT.NULL);
179
		labCenter.setText(A1);
180
		TableWrapData dataCenter = new TableWrapData();
181
		dataCenter.align = TableWrapData.CENTER;
182
		labCenter.setLayoutData(dataCenter);
183
		Label labFill = new Label(inner, SWT.NULL);
184
		labFill.setText(A1);
185
		TableWrapData dataFill = new TableWrapData();
186
		dataFill.align = TableWrapData.FILL;
187
		labFill.setLayoutData(dataFill);
188
		shell.layout();
189
		// Check layout
190
		assertEquals(LEFT_MARGIN , labLeft.getBounds().x);
191
		assertTrue(rightEdge(lab0) > rightEdge(labLeft));
192
		assertTrue(rightEdge(labLeft) + tableWrapLayout.rightMargin < 100);
193
		
194
		assertEquals(rightEdge(labRight), rightEdge(lab0));
195
		assertTrue(labRight.getBounds().x > LEFT_MARGIN);
196
		
197
		assertTrue(labCenter.getBounds().x > LEFT_MARGIN);
198
		assertTrue(rightEdge(lab0) > rightEdge(labCenter));
199
		
200
		int offCenter = rightEdge(labCenter) + labCenter.getBounds().x 
201
		   - rightEdge(lab0) + lab0.getBounds().x;
202
		assertTrue(offCenter >= -2);
203
		assertTrue(offCenter <= 2);
204
		
205
		assertEquals(LEFT_MARGIN , labFill.getBounds().x);
206
		assertEquals(rightEdge(labFill), rightEdge(lab0));
207
		shell.dispose();
208
	}
209
210
}
(-)forms/org/eclipse/ui/tests/forms/util/FormImagesTests.java (+159 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
 
12
package org.eclipse.ui.tests.forms.util;
13
14
import org.eclipse.swt.graphics.Color;
15
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.ui.internal.forms.widgets.FormImages;
18
19
import junit.framework.Assert;
20
import junit.framework.TestCase;
21
22
public class FormImagesTests extends TestCase {
23
	public void testSingleton() {
24
		Display display = Display.getCurrent();
25
		FormImages instance = FormImages.getInstance();
26
		// ensure the singleton is returning the same instance
27
		Assert.assertTrue("getInstance() returned a different FormImages instance", instance.equals(FormImages.getInstance()));
28
		Image gradient = instance.getGradient(display, new Color(display, 1, 1, 1), new Color(display, 7, 7, 7), 21, 21, 0);
29
		instance.markFinished(gradient);
30
		// ensure the singleton is returning the same instance after creating and disposing one gradient
31
		Assert.assertTrue("getInstance() returned a different FormImages instance after creation and disposal of one image", instance.equals(FormImages.getInstance()));
32
	}
33
	
34
	public void testDisposeOne() {
35
		Display display = Display.getCurrent();
36
		Image gradient = FormImages.getInstance().getGradient(display, new Color(display, 255, 255, 255), new Color(display, 0, 0, 0), 21, 21, 0);
37
		FormImages.getInstance().markFinished(gradient);
38
		// ensure that getting a single gradient and marking it as finished disposed it
39
		Assert.assertTrue("markFinished(...) did not dispose an image after a single getGradient()", gradient.isDisposed());
40
	}
41
	
42
	public void testMultipleSimpleInstances() {
43
		Display display = Display.getCurrent();
44
		Image gradient = FormImages.getInstance().getGradient(display, new Color(display, 200, 200, 200), new Color(display, 0, 0, 0), 30, 16, 3);
45
		int count;
46
		// ensure that the same image is returned for many calls with the same parameter
47
		for (count = 1; count < 20; count ++)
48
			Assert.assertEquals("getGradient(...) returned a different image for the same params on iteration "+count,
49
					gradient, FormImages.getInstance().getGradient(display, new Color(display, 200, 200, 200), new Color(display, 0, 0, 0), 30, 16, 3));
50
		for ( ;count > 0; count--) {
51
			FormImages.getInstance().markFinished(gradient);
52
			if (count != 1)
53
				// ensure that the gradient is not disposed early
54
				Assert.assertFalse("markFinished(...) disposed a shared image early on iteration "+count,gradient.isDisposed());
55
			else
56
				// ensure that the gradient is disposed on the last markFinished
57
				Assert.assertTrue("markFinished(...) did not dispose a shared image on the last call",gradient.isDisposed());
58
		}
59
	}
60
	
61
	public void testMultipleComplexInstances() {
62
		Display display = Display.getCurrent();
63
		Image gradient = FormImages.getInstance().getGradient(display, new Color[] {new Color(display, 200, 200, 200), new Color(display, 0, 0, 0)},
64
				new int[] {100}, 31, true, null);
65
		int count;
66
		// ensure that the same image is returned for many calls with the same parameter
67
		for (count = 1; count < 20; count ++)
68
			Assert.assertEquals("getGradient(...) returned a different image for the same params on iteration "+count,
69
					gradient, FormImages.getInstance().getGradient(display, new Color[] {new Color(display, 200, 200, 200), new Color(display, 0, 0, 0)},
70
							new int[] {100}, 31, true, null));
71
		for ( ;count > 0; count--) {
72
			FormImages.getInstance().markFinished(gradient);
73
			if (count != 1)
74
				// ensure that the gradient is not disposed early
75
				Assert.assertFalse("markFinished(...) disposed a shared image early on iteration "+count,gradient.isDisposed());
76
			else
77
				// ensure that the gradient is disposed on the last markFinished
78
				Assert.assertTrue("markFinished(...) did not dispose a shared image on the last call",gradient.isDisposed());
79
		}
80
	}
81
	
82
	public void testMultipleUniqueInstances() {
83
		Display display = Display.getCurrent();
84
		Image[] images = new Image[24];
85
		images[0] = FormImages.getInstance().getGradient(display, new Color(display, 1, 0, 0), new Color(display, 100, 100, 100), 25, 23, 1);
86
		images[1] = FormImages.getInstance().getGradient(display, new Color(display, 0, 1, 0), new Color(display, 100, 100, 100), 25, 23, 1);
87
		images[2] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 1), new Color(display, 100, 100, 100), 25, 23, 1);
88
		images[3] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 101, 100, 100), 25, 23, 1);
89
		images[4] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 101, 100), 25, 23, 1);
90
		images[5] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 101), 25, 23, 1);
91
		images[6] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 20, 23, 1);
92
		images[7] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 25, 10, 1);
93
		images[8] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 25, 23, 2);
94
		images[9] = FormImages.getInstance().getGradient(display, new Color(display, 1, 1, 1), new Color(display, 101, 101, 101), 20, 10, 2);
95
		images[10] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0)}, new int[] {}, 31, true, null);
96
		images[11] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,1,1,1)},
97
				new int[] {80}, 31, true, new Color(display,255,255,255));
98
		images[12] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,1,1,1)},
99
				new int[] {80}, 31, true, new Color(display,0,0,0));
100
		images[13] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)},
101
				new int[] {100}, 31, true, null);
102
		images[14] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,1,0,0), new Color(display,100,100,100)},
103
				new int[] {100}, 31, true, null);
104
		images[15] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,1,0), new Color(display,100,100,100)},
105
				new int[] {100}, 31, true, null);
106
		images[16] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,1), new Color(display,100,100,100)},
107
				new int[] {100}, 31, true, null);
108
		images[17] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,101,100,100)},
109
				new int[] {100}, 31, true, null);
110
		images[18] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,101,100)},
111
				new int[] {100}, 31, true, null);
112
		images[19] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,101)},
113
				new int[] {100}, 31, true, null);
114
		images[20] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)},
115
				new int[] {100}, 20, true, null);
116
		images[21] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)},
117
				new int[] {100}, 31, false, null);
118
		images[22] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)},
119
				new int[] {50}, 31, true, new Color(display,1,1,1));
120
		images[23] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,1,1,1), new Color(display,101,101,101)},
121
				new int[] {50}, 20, false, new Color(display,1,1,1));
122
		// ensure none of the images are the same
123
		for (int i = 0; i < images.length - 1; i++) {
124
			for (int j = i+1; j < images.length; j++) {
125
				Assert.assertNotSame("getGradient(...) returned the same image for different parameters: i = " + i + "; j = " + j, images[i], images[j]);
126
			}
127
		}
128
		// ensure all of the images are disposed with one call to markFinished
129
		for (int i = 0; i < images.length; i++) {
130
			FormImages.getInstance().markFinished(images[i]);
131
			Assert.assertTrue("markFinished(...) did not dispose an image that was only requested once: i = " + i, images[i].isDisposed());
132
		}
133
	}
134
	
135
	public void testComplexEquality() {
136
		Display display = Display.getCurrent();
137
		Image image1 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)},
138
				new int[] {100}, 20, true, new Color(display,100,100,100));
139
		Image image2 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)},
140
				new int[] {100}, 20, true, new Color(display,0,0,0));
141
		Assert.assertEquals("different images were created with only the background color differing when that difference is irrelevant", image1, image2);
142
		FormImages.getInstance().markFinished(image1);
143
		FormImages.getInstance().markFinished(image2);
144
		image1 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)},
145
				new int[] {80}, 20, true, new Color(display,100,100,100));
146
		image2 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)},
147
				new int[] {80}, 20, true, new Color(display,0,0,0));
148
		Assert.assertNotSame("the same image was used when different background colors were specified", image1, image2);
149
		FormImages.getInstance().markFinished(image1);
150
		FormImages.getInstance().markFinished(image2);
151
	}
152
	
153
	public void testDisposeUnknown() {
154
		Display display = Display.getCurrent();
155
		Image image = new Image(display, 10, 10);
156
		FormImages.getInstance().markFinished(image);
157
		Assert.assertTrue("markFinished(...) did not dispose of an unknown image", image.isDisposed());
158
	}
159
}
(-).classpath (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="forms"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
(-)forms/org/eclipse/ui/tests/forms/plugin/FormsTestPlugin.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.forms.plugin;
12
13
import org.eclipse.ui.plugin.AbstractUIPlugin;
14
import org.osgi.framework.BundleContext;
15
16
/**
17
 * The activator class controls the plug-in life cycle
18
 */
19
public class FormsTestPlugin extends AbstractUIPlugin {
20
21
	// The plug-in ID
22
	public static final String PLUGIN_ID = "org.eclipse.ui.tests.forms";
23
24
	// The shared instance
25
	private static FormsTestPlugin plugin;
26
	
27
	/**
28
	 * The constructor
29
	 */
30
	public FormsTestPlugin() {
31
	}
32
33
	/*
34
	 * (non-Javadoc)
35
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
36
	 */
37
	public void start(BundleContext context) throws Exception {
38
		super.start(context);
39
		plugin = this;
40
	}
41
42
	/*
43
	 * (non-Javadoc)
44
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
45
	 */
46
	public void stop(BundleContext context) throws Exception {
47
		plugin = null;
48
		super.stop(context);
49
	}
50
51
	/**
52
	 * Returns the shared instance
53
	 *
54
	 * @return the shared instance
55
	 */
56
	public static FormsTestPlugin getDefault() {
57
		return plugin;
58
	}
59
60
}
(-)forms/org/eclipse/ui/tests/forms/util/AllUtilityTests.java (+34 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.forms.util;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
/*
17
 * Tests forms performance (automated).
18
 */
19
public class AllUtilityTests extends TestSuite {
20
21
	/*
22
	 * Returns the entire test suite.
23
	 */
24
	public static Test suite() {
25
		return new AllUtilityTests();
26
	}
27
28
	/*
29
	 * Constructs a new performance test suite.
30
	 */
31
	public AllUtilityTests() {
32
		addTestSuite(FormImagesTests.class);
33
	}
34
}
(-)forms/org/eclipse/ua/tests/forms/layout/AllLayoutTests.java (-28 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ua.tests.forms.layout;
13
14
import junit.framework.Test;
15
import junit.framework.TestSuite;
16
17
public class AllLayoutTests {
18
19
	public static Test suite() {
20
		TestSuite suite = new TestSuite(
21
				"org.eclipse.ua.tests.forms.AllLayoutTests");
22
		//$JUnit-BEGIN$
23
		suite.addTestSuite(TestTableWrapLayout.class);
24
		//$JUnit-END$
25
		return suite;
26
	}
27
28
}
(-)forms/org/eclipse/ua/tests/forms/layout/TestTableWrapLayout.java (-210 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ua.tests.forms.layout;
13
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.layout.FillLayout;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.swt.widgets.Label;
20
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.forms.widgets.TableWrapData;
23
import org.eclipse.ui.forms.widgets.TableWrapLayout;
24
25
import junit.framework.TestCase;
26
27
public class TestTableWrapLayout extends TestCase {
28
29
	private final String A1 = "A";
30
	private final String A10 = "A A A A A A A A A A";
31
	private final String A20 = A10 + " " + A10;
32
	private final String A40 = A20 + " " + A20;
33
	private final String A80 = A40 + " " + A40;
34
	
35
	// Returns the width + left
36
	private int rightEdge(Label lab) {
37
		Rectangle r = lab.getBounds();
38
		return r.x + r.width;
39
	}
40
	
41
	/**
42
	 * Test that labels with the WRAP property set do indeed wrap.
43
	 */
44
	public void testTableWrapLayoutNonWrappingLabels() {
45
		Display display = PlatformUI.getWorkbench().getDisplay();
46
		Shell shell = new Shell(display);
47
		shell.setSize(100, 300);
48
		shell.setLayout(new FillLayout());
49
		Composite inner = new Composite(shell, SWT.V_SCROLL);
50
		inner.setLayout(new TableWrapLayout());
51
		Label l1 = new Label(inner, SWT.NULL);
52
		l1.setText(A10);
53
		Label l2 = new Label(inner, SWT.NULL);
54
		l2.setText(A80);
55
		shell.layout();
56
		assertEquals(l1.getSize().y, l2.getSize().y);
57
		assertTrue(l2.getSize().x > 100);
58
		shell.dispose();
59
	}
60
	
61
	/**
62
	 * Test that labels with the WRAP property set do indeed wrap.
63
	 */
64
    // Test suppressed for now - does not pass but not sure if this is a bug
65
	public void suppressed_testWrappingPoint() {
66
		Display display = PlatformUI.getWorkbench().getDisplay();
67
		Shell shell = new Shell(display);
68
		shell.setSize(300, 300);
69
		shell.setLayout(new FillLayout());
70
		Composite inner = new Composite(shell, SWT.V_SCROLL);
71
		TableWrapLayout tableWrapLayout = new TableWrapLayout();
72
		tableWrapLayout.leftMargin = 0;
73
		tableWrapLayout.rightMargin = 0;
74
		inner.setLayout(tableWrapLayout);
75
		Label l1 = new Label(inner, SWT.WRAP);
76
		l1.setText(A10);
77
		shell.layout();
78
		int originalWidth = l1.getSize().x;
79
		int originalHeight = l1.getSize().y;
80
		shell.setSize(originalWidth, 300);
81
		shell.layout();
82
		assertEquals(l1.getSize().y, originalHeight);
83
		shell.setSize(originalWidth / 2, 300);
84
		shell.layout();
85
		inner.layout();
86
		assertTrue(l1.getSize().y > originalHeight);
87
		shell.dispose();
88
	}
89
	
90
	/**
91
	 * Test that labels with the WRAP property set do indeed wrap.
92
	 */
93
	// Test suppressed for now, see Bug 196686 
94
	public void suppressed_testTableWrapLayoutWrappingLabels() {
95
		Display display = PlatformUI.getWorkbench().getDisplay();
96
		Shell shell = new Shell(display);
97
		shell.setSize(100, 300);
98
		shell.setLayout(new FillLayout());
99
		Composite inner = new Composite(shell, SWT.V_SCROLL);
100
		inner.setLayout(new TableWrapLayout());
101
		Label l1 = new Label(inner, SWT.WRAP);
102
		l1.setText(A10);
103
		Label l2 = new Label(inner, SWT.WRAP);
104
		l2.setText(A80);
105
		shell.layout();
106
		assertTrue(l1.getSize().y < l2.getSize().y);
107
		assertTrue("Label is too wide for layout ", l1.getSize().x <= 100);
108
		assertTrue("Label is too wide for layout ", l2.getSize().x <= 100);
109
		assertTrue("Labels overlap", l2.getBounds().y >= l1.getBounds().y + l1.getBounds().height);
110
		shell.dispose();
111
	}
112
	
113
	/**
114
	 * Test a 2x2 grid with unequal sizes
115
	 */
116
	public void testTableWrapLayoutTwoColumnsWrappingLabels() {
117
		Display display = PlatformUI.getWorkbench().getDisplay();
118
		Shell shell = new Shell(display);
119
		shell.setSize(100, 300);
120
		shell.setLayout(new FillLayout());
121
		Composite inner = new Composite(shell, SWT.V_SCROLL);
122
		TableWrapLayout tableWrapLayout = new TableWrapLayout();
123
		tableWrapLayout.numColumns = 2;
124
		inner.setLayout(tableWrapLayout);
125
		Label l1 = new Label(inner, SWT.WRAP);
126
		l1.setText(A10);
127
		Label l2 = new Label(inner, SWT.WRAP);
128
		l2.setText(A20);
129
		Label l3 = new Label(inner, SWT.WRAP);
130
		l3.setText(A40);
131
		Label l4 = new Label(inner, SWT.WRAP);
132
		l4.setText(A80);
133
		shell.layout();
134
		assertTrue(l1.getSize().x < l2.getSize().x);
135
		assertTrue(l1.getSize().y < l3.getSize().y);
136
		assertTrue(l1.getSize().x < l4.getSize().x);
137
		assertTrue(l2.getSize().y < l3.getSize().y);
138
		assertTrue("Label is too wide for layout ", l1.getSize().x + l2.getSize().x <= 100);
139
		assertTrue("Labels overlap", l2.getBounds().x >= l1.getBounds().x + l1.getBounds().width);
140
		assertTrue("Labels overlap", l3.getBounds().y >= l1.getBounds().y + l1.getBounds().height);
141
		assertTrue("Labels overlap", l4.getBounds().x >= l3.getBounds().x + l3.getBounds().width);
142
		assertTrue("Labels overlap", l4.getBounds().y >= l2.getBounds().y + l2.getBounds().height);
143
		shell.dispose();
144
	}
145
	
146
	/**
147
	 * Test alignments and margins
148
	 */
149
	// Suppressed for now - see Bug 196686 
150
	public void suppressed_testTableWrapLayoutAlignment() {
151
		Display display = PlatformUI.getWorkbench().getDisplay();
152
		Shell shell = new Shell(display);
153
		shell.setSize(100, 300);
154
		shell.setLayout(new FillLayout());
155
		Composite inner = new Composite(shell, SWT.V_SCROLL);
156
		TableWrapLayout tableWrapLayout = new TableWrapLayout();
157
		final int LEFT_MARGIN = 1;
158
		final int RIGHT_MARGIN = 2;
159
		final int TOP_MARGIN = 3;
160
		final int BOTTOM_MARGIN = 4;
161
		tableWrapLayout.leftMargin = LEFT_MARGIN;
162
		tableWrapLayout.rightMargin = RIGHT_MARGIN;
163
		tableWrapLayout.topMargin = TOP_MARGIN;
164
		tableWrapLayout.bottomMargin = BOTTOM_MARGIN;
165
		inner.setLayout(tableWrapLayout);
166
		Label lab0 = new Label(inner, SWT.WRAP);
167
		lab0.setText(A80);
168
		Label labLeft = new Label(inner, SWT.NULL);
169
		labLeft.setText(A1);
170
		TableWrapData dataLeft = new TableWrapData();
171
		dataLeft.align = TableWrapData.LEFT;
172
		labLeft.setLayoutData(dataLeft);
173
		Label labRight = new Label(inner, SWT.NULL);
174
		labRight.setText(A1);
175
		TableWrapData dataRight = new TableWrapData();
176
		dataRight.align = TableWrapData.RIGHT;
177
		labRight.setLayoutData(dataRight);
178
		Label labCenter = new Label(inner, SWT.NULL);
179
		labCenter.setText(A1);
180
		TableWrapData dataCenter = new TableWrapData();
181
		dataCenter.align = TableWrapData.CENTER;
182
		labCenter.setLayoutData(dataCenter);
183
		Label labFill = new Label(inner, SWT.NULL);
184
		labFill.setText(A1);
185
		TableWrapData dataFill = new TableWrapData();
186
		dataFill.align = TableWrapData.FILL;
187
		labFill.setLayoutData(dataFill);
188
		shell.layout();
189
		// Check layout
190
		assertEquals(LEFT_MARGIN , labLeft.getBounds().x);
191
		assertTrue(rightEdge(lab0) > rightEdge(labLeft));
192
		assertTrue(rightEdge(labLeft) + tableWrapLayout.rightMargin < 100);
193
		
194
		assertEquals(rightEdge(labRight), rightEdge(lab0));
195
		assertTrue(labRight.getBounds().x > LEFT_MARGIN);
196
		
197
		assertTrue(labCenter.getBounds().x > LEFT_MARGIN);
198
		assertTrue(rightEdge(lab0) > rightEdge(labCenter));
199
		
200
		int offCenter = rightEdge(labCenter) + labCenter.getBounds().x 
201
		   - rightEdge(lab0) + lab0.getBounds().x;
202
		assertTrue(offCenter >= -2);
203
		assertTrue(offCenter <= 2);
204
		
205
		assertEquals(LEFT_MARGIN , labFill.getBounds().x);
206
		assertEquals(rightEdge(labFill), rightEdge(lab0));
207
		shell.dispose();
208
	}
209
210
}
(-)forms/org/eclipse/ua/tests/forms/util/FormImagesTests.java (-159 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
 
12
package org.eclipse.ua.tests.forms.util;
13
14
import org.eclipse.swt.graphics.Color;
15
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.ui.internal.forms.widgets.FormImages;
18
19
import junit.framework.Assert;
20
import junit.framework.TestCase;
21
22
public class FormImagesTests extends TestCase {
23
	public void testSingleton() {
24
		Display display = Display.getCurrent();
25
		FormImages instance = FormImages.getInstance();
26
		// ensure the singleton is returning the same instance
27
		Assert.assertTrue("getInstance() returned a different FormImages instance", instance.equals(FormImages.getInstance()));
28
		Image gradient = instance.getGradient(display, new Color(display, 1, 1, 1), new Color(display, 7, 7, 7), 21, 21, 0);
29
		instance.markFinished(gradient);
30
		// ensure the singleton is returning the same instance after creating and disposing one gradient
31
		Assert.assertTrue("getInstance() returned a different FormImages instance after creation and disposal of one image", instance.equals(FormImages.getInstance()));
32
	}
33
	
34
	public void testDisposeOne() {
35
		Display display = Display.getCurrent();
36
		Image gradient = FormImages.getInstance().getGradient(display, new Color(display, 255, 255, 255), new Color(display, 0, 0, 0), 21, 21, 0);
37
		FormImages.getInstance().markFinished(gradient);
38
		// ensure that getting a single gradient and marking it as finished disposed it
39
		Assert.assertTrue("markFinished(...) did not dispose an image after a single getGradient()", gradient.isDisposed());
40
	}
41
	
42
	public void testMultipleSimpleInstances() {
43
		Display display = Display.getCurrent();
44
		Image gradient = FormImages.getInstance().getGradient(display, new Color(display, 200, 200, 200), new Color(display, 0, 0, 0), 30, 16, 3);
45
		int count;
46
		// ensure that the same image is returned for many calls with the same parameter
47
		for (count = 1; count < 20; count ++)
48
			Assert.assertEquals("getGradient(...) returned a different image for the same params on iteration "+count,
49
					gradient, FormImages.getInstance().getGradient(display, new Color(display, 200, 200, 200), new Color(display, 0, 0, 0), 30, 16, 3));
50
		for ( ;count > 0; count--) {
51
			FormImages.getInstance().markFinished(gradient);
52
			if (count != 1)
53
				// ensure that the gradient is not disposed early
54
				Assert.assertFalse("markFinished(...) disposed a shared image early on iteration "+count,gradient.isDisposed());
55
			else
56
				// ensure that the gradient is disposed on the last markFinished
57
				Assert.assertTrue("markFinished(...) did not dispose a shared image on the last call",gradient.isDisposed());
58
		}
59
	}
60
	
61
	public void testMultipleComplexInstances() {
62
		Display display = Display.getCurrent();
63
		Image gradient = FormImages.getInstance().getGradient(display, new Color[] {new Color(display, 200, 200, 200), new Color(display, 0, 0, 0)},
64
				new int[] {100}, 31, true, null);
65
		int count;
66
		// ensure that the same image is returned for many calls with the same parameter
67
		for (count = 1; count < 20; count ++)
68
			Assert.assertEquals("getGradient(...) returned a different image for the same params on iteration "+count,
69
					gradient, FormImages.getInstance().getGradient(display, new Color[] {new Color(display, 200, 200, 200), new Color(display, 0, 0, 0)},
70
							new int[] {100}, 31, true, null));
71
		for ( ;count > 0; count--) {
72
			FormImages.getInstance().markFinished(gradient);
73
			if (count != 1)
74
				// ensure that the gradient is not disposed early
75
				Assert.assertFalse("markFinished(...) disposed a shared image early on iteration "+count,gradient.isDisposed());
76
			else
77
				// ensure that the gradient is disposed on the last markFinished
78
				Assert.assertTrue("markFinished(...) did not dispose a shared image on the last call",gradient.isDisposed());
79
		}
80
	}
81
	
82
	public void testMultipleUniqueInstances() {
83
		Display display = Display.getCurrent();
84
		Image[] images = new Image[24];
85
		images[0] = FormImages.getInstance().getGradient(display, new Color(display, 1, 0, 0), new Color(display, 100, 100, 100), 25, 23, 1);
86
		images[1] = FormImages.getInstance().getGradient(display, new Color(display, 0, 1, 0), new Color(display, 100, 100, 100), 25, 23, 1);
87
		images[2] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 1), new Color(display, 100, 100, 100), 25, 23, 1);
88
		images[3] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 101, 100, 100), 25, 23, 1);
89
		images[4] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 101, 100), 25, 23, 1);
90
		images[5] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 101), 25, 23, 1);
91
		images[6] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 20, 23, 1);
92
		images[7] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 25, 10, 1);
93
		images[8] = FormImages.getInstance().getGradient(display, new Color(display, 0, 0, 0), new Color(display, 100, 100, 100), 25, 23, 2);
94
		images[9] = FormImages.getInstance().getGradient(display, new Color(display, 1, 1, 1), new Color(display, 101, 101, 101), 20, 10, 2);
95
		images[10] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0)}, new int[] {}, 31, true, null);
96
		images[11] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,1,1,1)},
97
				new int[] {80}, 31, true, new Color(display,255,255,255));
98
		images[12] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,1,1,1)},
99
				new int[] {80}, 31, true, new Color(display,0,0,0));
100
		images[13] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)},
101
				new int[] {100}, 31, true, null);
102
		images[14] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,1,0,0), new Color(display,100,100,100)},
103
				new int[] {100}, 31, true, null);
104
		images[15] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,1,0), new Color(display,100,100,100)},
105
				new int[] {100}, 31, true, null);
106
		images[16] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,1), new Color(display,100,100,100)},
107
				new int[] {100}, 31, true, null);
108
		images[17] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,101,100,100)},
109
				new int[] {100}, 31, true, null);
110
		images[18] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,101,100)},
111
				new int[] {100}, 31, true, null);
112
		images[19] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,101)},
113
				new int[] {100}, 31, true, null);
114
		images[20] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)},
115
				new int[] {100}, 20, true, null);
116
		images[21] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)},
117
				new int[] {100}, 31, false, null);
118
		images[22] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,0,0,0), new Color(display,100,100,100)},
119
				new int[] {50}, 31, true, new Color(display,1,1,1));
120
		images[23] = FormImages.getInstance().getGradient(display, new Color[]{new Color(display,1,1,1), new Color(display,101,101,101)},
121
				new int[] {50}, 20, false, new Color(display,1,1,1));
122
		// ensure none of the images are the same
123
		for (int i = 0; i < images.length - 1; i++) {
124
			for (int j = i+1; j < images.length; j++) {
125
				Assert.assertNotSame("getGradient(...) returned the same image for different parameters: i = " + i + "; j = " + j, images[i], images[j]);
126
			}
127
		}
128
		// ensure all of the images are disposed with one call to markFinished
129
		for (int i = 0; i < images.length; i++) {
130
			FormImages.getInstance().markFinished(images[i]);
131
			Assert.assertTrue("markFinished(...) did not dispose an image that was only requested once: i = " + i, images[i].isDisposed());
132
		}
133
	}
134
	
135
	public void testComplexEquality() {
136
		Display display = Display.getCurrent();
137
		Image image1 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)},
138
				new int[] {100}, 20, true, new Color(display,100,100,100));
139
		Image image2 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)},
140
				new int[] {100}, 20, true, new Color(display,0,0,0));
141
		Assert.assertEquals("different images were created with only the background color differing when that difference is irrelevant", image1, image2);
142
		FormImages.getInstance().markFinished(image1);
143
		FormImages.getInstance().markFinished(image2);
144
		image1 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)},
145
				new int[] {80}, 20, true, new Color(display,100,100,100));
146
		image2 = FormImages.getInstance().getGradient(display, new Color[] {new Color(display,0,0,0), new Color(display,255,255,255)},
147
				new int[] {80}, 20, true, new Color(display,0,0,0));
148
		Assert.assertNotSame("the same image was used when different background colors were specified", image1, image2);
149
		FormImages.getInstance().markFinished(image1);
150
		FormImages.getInstance().markFinished(image2);
151
	}
152
	
153
	public void testDisposeUnknown() {
154
		Display display = Display.getCurrent();
155
		Image image = new Image(display, 10, 10);
156
		FormImages.getInstance().markFinished(image);
157
		Assert.assertTrue("markFinished(...) did not dispose of an unknown image", image.isDisposed());
158
	}
159
}
(-)forms/org/eclipse/ua/tests/forms/util/AllUtilityTests.java (-34 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.forms.util;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
/*
17
 * Tests forms performance (automated).
18
 */
19
public class AllUtilityTests extends TestSuite {
20
21
	/*
22
	 * Returns the entire test suite.
23
	 */
24
	public static Test suite() {
25
		return new AllUtilityTests();
26
	}
27
28
	/*
29
	 * Constructs a new performance test suite.
30
	 */
31
	public AllUtilityTests() {
32
		addTestSuite(FormImagesTests.class);
33
	}
34
}
(-)forms/org/eclipse/ua/tests/forms/AllFormsTests.java (-39 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ua.tests.forms;
13
14
import junit.framework.Test;
15
import junit.framework.TestSuite;
16
17
import org.eclipse.ua.tests.forms.layout.AllLayoutTests;
18
import org.eclipse.ua.tests.forms.util.AllUtilityTests;
19
20
/*
21
 * Tests all cheat sheet functionality (automated).
22
 */
23
public class AllFormsTests extends TestSuite {
24
25
	/*
26
	 * Returns the entire test suite.
27
	 */
28
	public static Test suite() {
29
		return new AllFormsTests();
30
	}
31
32
	/*
33
	 * Constructs a new test suite.
34
	 */
35
	public AllFormsTests() {
36
		addTest(AllLayoutTests.suite());
37
		addTest(AllUtilityTests.suite());
38
	}
39
}
(-)META-INF/MANIFEST.MF (-2 / +2 lines)
Lines 15-22 Link Here
15
 org.eclipse.ui,
15
 org.eclipse.ui,
16
 org.eclipse.ui.cheatsheets,
16
 org.eclipse.ui.cheatsheets,
17
 org.eclipse.ui.intro,
17
 org.eclipse.ui.intro,
18
 org.eclipse.ui.forms,
18
 org.eclipse.ui.intro.universal,
19
 org.eclipse.ui.intro.universal
19
 org.eclipse.ui.forms
20
Eclipse-LazyStart: true
20
Eclipse-LazyStart: true
21
Bundle-Vendor: Eclipse.org
21
Bundle-Vendor: Eclipse.org
22
Bundle-ClassPath: ua-tests.jar
22
Bundle-ClassPath: ua-tests.jar
(-)build.properties (-2 / +1 lines)
Lines 21-25 Link Here
21
source.ua-tests.jar = base/,\
21
source.ua-tests.jar = base/,\
22
                      cheatsheet/,\
22
                      cheatsheet/,\
23
                      help/,\
23
                      help/,\
24
                      intro/,\
24
                      intro/
25
                      forms/
(-).classpath (-8 / +7 lines)
Lines 1-11 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
	<classpathentry path="base" kind="src"/>
3
	<classpathentry kind="src" path="base"/>
4
	<classpathentry path="cheatsheet" kind="src"/>
4
	<classpathentry kind="src" path="cheatsheet"/>
5
	<classpathentry path="intro" kind="src"/>
5
	<classpathentry kind="src" path="intro"/>
6
	<classpathentry path="help" kind="src"/>
6
	<classpathentry kind="src" path="help"/>
7
	<classpathentry path="forms" kind="src"/>
7
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
8
	<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
8
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
9
	<classpathentry path="org.eclipse.pde.core.requiredPlugins" kind="con"/>
9
	<classpathentry kind="output" path="bin"/>
10
	<classpathentry path="bin" kind="output"/>
11
</classpath>
10
</classpath>
(-)forms/org/eclipse/ua/tests/forms/performance/FormsPerformanceTest.java (-231 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ua.tests.forms.performance;
13
14
import org.eclipse.jface.resource.JFaceResources;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.layout.FillLayout;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Display;
21
import org.eclipse.swt.widgets.Label;
22
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.widgets.Text;
24
import org.eclipse.test.performance.Dimension;
25
import org.eclipse.test.performance.Performance;
26
import org.eclipse.test.performance.PerformanceTestCase;
27
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.forms.events.ExpansionAdapter;
29
import org.eclipse.ui.forms.events.ExpansionEvent;
30
import org.eclipse.ui.forms.events.HyperlinkAdapter;
31
import org.eclipse.ui.forms.events.HyperlinkEvent;
32
import org.eclipse.ui.forms.widgets.ExpandableComposite;
33
import org.eclipse.ui.forms.widgets.FormText;
34
import org.eclipse.ui.forms.widgets.FormToolkit;
35
import org.eclipse.ui.forms.widgets.Hyperlink;
36
import org.eclipse.ui.forms.widgets.ImageHyperlink;
37
import org.eclipse.ui.forms.widgets.ScrolledForm;
38
import org.eclipse.ui.forms.widgets.Section;
39
import org.eclipse.ui.forms.widgets.TableWrapData;
40
import org.eclipse.ui.forms.widgets.TableWrapLayout;
41
42
public class FormsPerformanceTest extends PerformanceTestCase {
43
	
44
	public void test_createForm() {
45
		tagAsSummary("Create Form", Dimension.ELAPSED_PROCESS);
46
	    Performance.getDefault();
47
		
48
		// Warm up.
49
50
		Display display = PlatformUI.getWorkbench().getDisplay();
51
52
		FormToolkit toolkit;
53
		toolkit = new FormToolkit(display);
54
		for(int samples = 0; samples < 2; samples++) {
55
			Shell shell = new Shell(display);
56
			shell.setSize(400, 300);
57
			shell.setLayout(new FillLayout());
58
			shell.open();
59
60
			for (int i = 0; i < 5; i++) {
61
				Composite c = new Composite(shell, SWT.H_SCROLL + SWT.V_SCROLL);
62
				c.setLayout(new FillLayout());
63
                createPartControl(c, toolkit);
64
                shell.layout(true); 
65
                while(display.readAndDispatch()){/*empty*/}
66
				c.dispose();
67
			}
68
			shell.dispose();
69
			while(display.readAndDispatch()){/*empty*/}
70
		}
71
72
		for(int samples = 0; samples < 50; samples++) {
73
			Shell shell = new Shell(display);
74
			shell.setSize(400, 300);
75
			shell.setLayout(new FillLayout());
76
			shell.open();
77
			startMeasuring();
78
			for (int i = 0; i < 3; i++) {
79
				Composite c = new Composite(shell, SWT.H_SCROLL + SWT.V_SCROLL);
80
				c.setLayout(new FillLayout());
81
                createPartControl(c, toolkit);
82
                shell.layout(true);
83
                while(display.readAndDispatch()){/*empty*/}
84
				c.dispose();
85
			}
86
			stopMeasuring(); 
87
			shell.dispose();
88
			while(display.readAndDispatch()){/*empty*/}
89
		}	
90
		toolkit.dispose();
91
		commitMeasurements();
92
		assertPerformance();
93
	}
94
	
95
	public void createPartControl(Composite parent, FormToolkit toolkit) {
96
		//Label l = new Label(parent, SWT.NULL);
97
		//l.setText ("a label");
98
		ScrolledForm form;
99
		form = toolkit.createScrolledForm(parent);
100
		form.setText("Hello, Eclipse Forms");
101
		TableWrapLayout layout = new TableWrapLayout();
102
		form.getBody().setLayout(layout);
103
		
104
		Hyperlink link = toolkit.createHyperlink(form.getBody(), "Click here.",
105
				SWT.WRAP);
106
		link.addHyperlinkListener(new HyperlinkAdapter() {
107
			public void linkActivated(HyperlinkEvent e) {
108
				System.out.println("Link activated!");
109
			}
110
		});
111
		link.setText("This is an example of a form that is much longer and will need to wrap.");
112
		layout.numColumns = 2;
113
		TableWrapData td = new TableWrapData();
114
		td.colspan = 2;
115
		link.setLayoutData(td);
116
		toolkit.createLabel(form.getBody(), "Text field label:");
117
		Text text = toolkit.createText(form.getBody(), "");
118
		td = new TableWrapData(TableWrapData.FILL_GRAB);
119
		text.setLayoutData(td);
120
		Button button = toolkit.createButton(form.getBody(),
121
				"An example of a checkbox in a form", SWT.CHECK);
122
		td = new TableWrapData();
123
		td.colspan = 2;
124
		button.setLayoutData(td);
125
		
126
		ImageHyperlink ih = toolkit.createImageHyperlink(form.getBody(), SWT.NULL);
127
		ih.setText("Image link with no image");
128
		ih = toolkit.createImageHyperlink(form.getBody(), SWT.NULL);
129
		//ih.setImage(ExamplesPlugin.getDefault().getImageRegistry().get(ExamplesPlugin.IMG_SAMPLE));
130
		ih.setText("Link with image and text");
131
		
132
		ExpandableComposite ec = toolkit.createExpandableComposite(form.getBody(), ExpandableComposite.TREE_NODE|ExpandableComposite.CLIENT_INDENT);
133
		ImageHyperlink eci = toolkit.createImageHyperlink(ec, SWT.NULL);
134
		//eci.setImage(ExamplesPlugin.getDefault().getImageRegistry().get(ExamplesPlugin.IMG_SAMPLE));
135
		ec.setTextClient(eci);
136
		ec.setText("Expandable Composite title");
137
		String ctext = "We will now create a somewhat long text so that "+
138
		"we can use it as content for the expandable composite. "+
139
		"Expandable composite is used to hide or show the text using the "+
140
		"toggle control";
141
		Label client = toolkit.createLabel(ec, ctext, SWT.WRAP);
142
		ec.setClient(client);
143
		td = new TableWrapData();
144
		td.colspan = 2;
145
		ec.setLayoutData(td);
146
		ec.addExpansionListener(new ExpansionAdapter() {
147
			public void expansionStateChanged(ExpansionEvent e) {
148
				//form.reflow(true);
149
			}
150
		});
151
		Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TWISTIE|Section.EXPANDED);
152
		td = new TableWrapData(TableWrapData.FILL);
153
		td.colspan = 2;
154
		section.setLayoutData(td);
155
		section.addExpansionListener(new ExpansionAdapter() {
156
			public void expansionStateChanged(ExpansionEvent e) {
157
				//form.reflow(true);
158
			}
159
		});
160
		section.setText("Section title");
161
		toolkit.createCompositeSeparator(section);
162
		section.setDescription("This is the description that goes below the title");
163
		Composite sectionClient = toolkit.createComposite(section);
164
		sectionClient.setLayout(new GridLayout());
165
		button = toolkit.createButton(sectionClient, "Radio 1", SWT.RADIO);
166
		button = toolkit.createButton(sectionClient, "Radio 2", SWT.RADIO);
167
		section.setClient(sectionClient);
168
169
		StringBuffer buf = new StringBuffer();
170
		buf.append("<form>");
171
		buf.append("<p>");
172
		buf.append("Here is some plain text for the text to render; ");
173
		buf.append("this text is at <a href=\"http://www.eclipse.org\" nowrap=\"true\">http://www.eclipse.org</a> web site.");
174
		buf.append("</p>");
175
		buf.append("<p>");
176
		buf.append("<span color=\"header\" font=\"header\">This text is in header font.</span>");
177
		buf.append("</p>");
178
		buf.append("<p>This line will contain some <b>bold</b> and some <span font=\"code\">source</span> text. ");
179
		buf.append("We can also add <img href=\"image\"/> an image. ");
180
		buf.append("</p>");
181
		buf.append("<li>A default (bulleted) list item.</li>");
182
		buf.append("<li>Another bullet list item.</li>");
183
		buf.append("<li style=\"text\" value=\"1.\">A list item with text.</li>");
184
		buf.append("<li style=\"text\" value=\"2.\">Another list item with text</li>");
185
		buf.append("<li style=\"image\" value=\"image\">List item with an image bullet</li>");
186
		buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"3.\">A list item with text.</li>");
187
		buf.append("<li style=\"text\" bindent=\"20\" indent=\"40\" value=\"4.\">A list item with text.</li>");
188
		buf.append("<p>     leading blanks;      more white \n\n new lines   <br/><br/><br/> \n more <b>   bb   </b>  white  . </p>");
189
		buf.append("</form>");
190
		FormText rtext = toolkit.createFormText(form.getBody(), false);
191
		//rtext.setWhitespaceNormalized(false);
192
		td = new TableWrapData(TableWrapData.FILL);
193
		td.colspan = 2;
194
		rtext.setLayoutData(td);
195
		//rtext.setImage("image", ExamplesPlugin.getDefault().getImageRegistry().get(ExamplesPlugin.IMG_SAMPLE));
196
		//rtext.setColor("header", JFaceColors.getErrorText(display));
197
		rtext.setFont("header", JFaceResources.getHeaderFont());
198
		rtext.setFont("code", JFaceResources.getTextFont());
199
		rtext.setText(buf.toString(), true, false);
200
		rtext.addHyperlinkListener(new HyperlinkAdapter() {
201
			public void linkActivated(HyperlinkEvent e) {
202
				System.out.println("Link active: "+e.getHref());
203
			}
204
		});
205
/*		layout.numColumns = 3;
206
		Label label;
207
		TableWrapData td;
208
		
209
		label = toolkit.createLabel(form.getBody(), "Some text to put in the first column", SWT.WRAP);
210
		label = toolkit.createLabel(form.getBody() ,"Some text to put in the second column and make it a bit longer so that we can see what happens with column distribution. This text must be the longest so that it can get more space allocated to the columns it belongs to.", SWT.WRAP);
211
		td = new TableWrapData();
212
		td.colspan = 2;
213
		label.setLayoutData(td);
214
		label = toolkit.createLabel(form.getBody(), "This text will span two rows and should not grow the column.", SWT.WRAP);
215
		td = new TableWrapData();
216
		td.rowspan = 2;
217
		label.setLayoutData(td);
218
		label = toolkit.createLabel(form.getBody(), "This text goes into column 2 and consumes only one cell", SWT.WRAP);
219
		label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
220
		label = toolkit.createLabel(form.getBody(), "This text goes into column 3 and consumes only one cell too", SWT.WRAP);
221
		label.setLayoutData(new TableWrapData(TableWrapData.FILL));
222
		label = toolkit.createLabel(form.getBody(), "This text goes into column 2 and consumes only one cell", SWT.WRAP);
223
		label.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
224
		label = toolkit.createLabel(form.getBody(), "This text goes into column 3 and consumes only one cell too", SWT.WRAP);
225
		label.setLayoutData(new TableWrapData(TableWrapData.FILL));
226
		form.getBody().setBackground(form.getBody().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));*/
227
		
228
		toolkit.paintBordersFor(form.getBody());
229
	}
230
231
}
(-)forms/org/eclipse/ua/tests/forms/performance/AllFormsPerformanceTests.java (-34 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ua.tests.forms.performance;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
/*
17
 * Tests forms performance (automated).
18
 */
19
public class AllFormsPerformanceTests extends TestSuite {
20
21
	/*
22
	 * Returns the entire test suite.
23
	 */
24
	public static Test suite() {
25
		return new AllFormsPerformanceTests();
26
	}
27
28
	/*
29
	 * Constructs a new performance test suite.
30
	 */
31
	public AllFormsPerformanceTests() {
32
		addTestSuite(FormsPerformanceTest.class);
33
	}
34
}
(-)base/org/eclipse/ua/tests/AllPerformanceTests.java (-2 lines)
Lines 14-20 Link Here
14
import junit.framework.TestSuite;
14
import junit.framework.TestSuite;
15
15
16
import org.eclipse.ua.tests.cheatsheet.AllCheatSheetPerformanceTests;
16
import org.eclipse.ua.tests.cheatsheet.AllCheatSheetPerformanceTests;
17
import org.eclipse.ua.tests.forms.performance.AllFormsPerformanceTests;
18
17
19
/*
18
/*
20
 * Tests all user assistance performance (automated).
19
 * Tests all user assistance performance (automated).
Lines 47-52 Link Here
47
		 */
46
		 */
48
		//addTest(AllIntroPerformanceTests.suite());
47
		//addTest(AllIntroPerformanceTests.suite());
49
48
50
		addTest(AllFormsPerformanceTests.suite());
51
	}
49
	}
52
}
50
}
(-)base/org/eclipse/ua/tests/AllTests.java (-2 lines)
Lines 14-20 Link Here
14
import junit.framework.TestSuite;
14
import junit.framework.TestSuite;
15
15
16
import org.eclipse.ua.tests.cheatsheet.AllCheatSheetTests;
16
import org.eclipse.ua.tests.cheatsheet.AllCheatSheetTests;
17
import org.eclipse.ua.tests.forms.AllFormsTests;
18
import org.eclipse.ua.tests.help.AllHelpTests;
17
import org.eclipse.ua.tests.help.AllHelpTests;
19
import org.eclipse.ua.tests.intro.AllIntroTests;
18
import org.eclipse.ua.tests.intro.AllIntroTests;
20
19
Lines 37-42 Link Here
37
		addTest(AllCheatSheetTests.suite());
36
		addTest(AllCheatSheetTests.suite());
38
		addTest(AllIntroTests.suite());
37
		addTest(AllIntroTests.suite());
39
		addTest(AllHelpTests.suite());
38
		addTest(AllHelpTests.suite());
40
		addTest(AllFormsTests.suite());
41
	}
39
	}
42
}
40
}

Return to bug 205864