Skip to content

Commit

Permalink
Issue XXX - Stupid PR
Browse files Browse the repository at this point in the history
  • Loading branch information
lcaron committed May 4, 2024
1 parent 851e4b0 commit 13c78f6
Showing 1 changed file with 61 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* compeople AG - initial API and implementation
* compeople AG - initial API and implementation
******************************************************************************/
package org.eclipse.nebula.widgets.compositetable;

import junit.framework.TestCase;

import org.eclipse.nebula.widgets.compositetable.CompositeTable;
import org.eclipse.nebula.widgets.compositetable.IRowContentProvider;
import org.eclipse.nebula.widgets.compositetable.ResizableGridRowLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
Expand All @@ -27,29 +22,32 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import junit.framework.TestCase;

public class CompositeTableTest extends TestCase {
private boolean createdDisplay = false;

private static final class Row extends Composite {
private Text text;
private static final class Row extends Composite {
private final Text text;

public Row(Composite parent, int style) {
super(parent, style);
setLayout(new ResizableGridRowLayout());
text = new Text(this, SWT.BORDER | SWT.SINGLE);
}
public Row(final Composite parent, final int style) {
super(parent, style);
setLayout(new ResizableGridRowLayout());
text = new Text(this, SWT.BORDER | SWT.SINGLE);
}

public String toString() {
return text.getText();
@Override
public String toString() {
return text.getText();
}
}
}

private Display display;
private Shell shell;
private CompositeTable table;
private String[] words;
private Display display;
private Shell shell;
private CompositeTable table;
private String[] words;

@Override
@Override
protected void setUp() throws Exception {
display = Display.getCurrent();
if (display == null) {
Expand All @@ -63,79 +61,74 @@ protected void setUp() throws Exception {
table = new CompositeTable(shell, SWT.NONE);
new Row(table, SWT.NONE);

words = new String[] { "Basic", "Bash", "C", "C++", "Clipper", "Cobol",
"Java", "ML", "Pascal", "Perl", "Python", "Ruby", "Scheme",
"Smalltalk", };
table.addRowContentProvider(new IRowContentProvider() {
public void refresh(CompositeTable sender, int currentObjectOffset,
Control rowControl) {
Row row = (Row) rowControl;
String word = words[currentObjectOffset];
// System.out.println("refresh: " + currentObjectOffset + " " +
// word);
row.text.setText(word);
}
words = new String[] { "Basic", "Bash", "C", "C++", "Clipper", "Cobol", "Java", "ML", "Pascal", "Perl", "Python", "Ruby", "Scheme", "Smalltalk", };
table.addRowContentProvider((sender, currentObjectOffset, rowControl) -> {
final Row row = (Row) rowControl;
final String word = words[currentObjectOffset];
// System.out.println("refresh: " + currentObjectOffset + " " +
// word);
row.text.setText(word);
});
table.setNumRowsInCollection(words.length);
table.setRunTime(true);

shell.open();
}

@Override
@Override
protected void tearDown() throws Exception {
shell.dispose();
if (createdDisplay) {
display.dispose();
}
}

// test methods
// /////////////
// test methods
// /////////////

public void testGetRowControlsWithTopRowZero() throws Exception {
assertEquals(0, table.getTopRow());
Control[] rowControls = table.getRowControls();
for (int i = 0; i < rowControls.length; i++) {
Row row = (Row) rowControls[i];
assertEquals(words[i], row.toString());
public void testGetRowControlsWithTopRowZero() throws Exception {
assertEquals(0, table.getTopRow());
final Control[] rowControls = table.getRowControls();
for (int i = 0; i < rowControls.length; i++) {
final Row row = (Row) rowControls[i];
assertEquals(words[i], row.toString());
}
}
}

public void testSetSelection() {
table.setSelection(0, 0);
readAndDispatch();
public void testSetSelection() {
table.setSelection(0, 0);
readAndDispatch();

assertEquals(new Point(0, 0), table.getSelection());
assertEquals(new Point(0, 0), table.getSelection());

table.setSelection(0, 1);
readAndDispatch();
table.setSelection(0, 1);
readAndDispatch();

assertEquals(new Point(0, 1), table.getSelection());
assertEquals(new Point(0, 1), table.getSelection());

table.setSelection(0, 10);
readAndDispatch();
table.setSelection(0, 10);
readAndDispatch();

assertEquals(new Point(0, 10 - table.getTopRow()), table.getSelection());
}
assertEquals(new Point(0, 10 - table.getTopRow()), table.getSelection());
}

public void testClearSelection() {
// shell.open() will set the selection to the first row
assertEquals(new Point(-1, 0), table.getSelection());
public void testClearSelection() {
// shell.open() will set the selection to the first row
assertEquals(new Point(-1, 0), table.getSelection());

table.clearSelection();
readAndDispatch();
table.clearSelection();
readAndDispatch();

assertEquals(null, table.getSelection());
}
assertEquals(null, table.getSelection());
}

// helping methods
// ////////////////
// helping methods
// ////////////////

private void readAndDispatch() {
while (display.readAndDispatch()) {
// next
private void readAndDispatch() {
while (display.readAndDispatch()) {
// next
}
}
}

}

0 comments on commit 13c78f6

Please sign in to comment.