Implement Grid cell and column header/footer word wrap
This is server-side implementation only. The client-side is implemented
in RAP core with change 29031.
- Add GridColumn#set/getWordWrap
- Add GridColumn#set/getHeaderWordWrap
diff --git a/bundles/org.eclipse.rap.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridColumn.java b/bundles/org.eclipse.rap.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridColumn.java
index 41946bb..846d08f 100644
--- a/bundles/org.eclipse.rap.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridColumn.java
+++ b/bundles/org.eclipse.rap.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/GridColumn.java
@@ -68,6 +68,8 @@
private Image footerImage;
private Font footerFont;
private boolean packed;
+ private boolean wordWrap;
+ private boolean headerWordWrap;
int imageCount;
int textCount;
@@ -774,6 +776,44 @@
}
/**
+ * Returns the true if the cells in receiver wrap their text.
+ *
+ * @return true if the cells wrap their text.
+ * @throws org.eclipse.swt.SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * </li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ */
+ public boolean getWordWrap() {
+ checkWidget();
+ return wordWrap;
+ }
+
+ /**
+ * If the argument is true, wraps the text in the receiver's cells. This
+ * feature will not cause the row height to expand to accommodate the
+ * wrapped text. Please use <code>Grid#setItemHeight</code> to change the
+ * height of each row.
+ *
+ * @param wordWrap
+ * true to make cells wrap their text.
+ * @throws org.eclipse.swt.SWTException
+ * <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
+ * </li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
+ * thread that created the receiver</li>
+ * </ul>
+ */
+ public void setWordWrap( boolean wordWrap ) {
+ checkWidget();
+ this.wordWrap = wordWrap;
+ }
+
+ /**
* Sets the Font to be used when displaying the Header text.
*
* @param font
@@ -860,6 +900,32 @@
}
/**
+ * Sets whether or not text is word-wrapped in the header for this column.
+ * If Grid.setAutoHeight(true) is set, the row height is adjusted to
+ * accommodate word-wrapped text.
+ *
+ * @param wordWrap
+ * Set to true to wrap the text, false otherwise
+ * @see #getHeaderWordWrap()
+ */
+ public void setHeaderWordWrap( boolean wordWrap ) {
+ checkWidget();
+ this.headerWordWrap = wordWrap;
+ }
+
+ /**
+ * Returns whether or not text is word-wrapped in the header for this
+ * column.
+ *
+ * @return true if the header wraps its text.
+ * @see GridColumn#setHeaderWordWrap(boolean)
+ */
+ public boolean getHeaderWordWrap() {
+ checkWidget();
+ return headerWordWrap;
+ }
+
+ /**
* Sets the receiver's footer text.
*
* @param text
diff --git a/bundles/org.eclipse.rap.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/internal/gridcolumnkit/GridColumnLCA.java b/bundles/org.eclipse.rap.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/internal/gridcolumnkit/GridColumnLCA.java
index 6cc7930..79fb605 100644
--- a/bundles/org.eclipse.rap.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/internal/gridcolumnkit/GridColumnLCA.java
+++ b/bundles/org.eclipse.rap.nebula.widgets.grid/src/org/eclipse/nebula/widgets/grid/internal/gridcolumnkit/GridColumnLCA.java
@@ -51,6 +51,8 @@
private static final String PROP_FOOTER_FONT = "footerFont";
private static final String PROP_FOOTER_TEXT = "footerText";
private static final String PROP_FOOTER_IMAGE = "footerImage";
+ private static final String PROP_WORD_WRAP = "wordWrap";
+ private static final String PROP_HEADER_WORD_WRAP = "headerWordWrap";
private static final String PROP_SELECTION_LISTENER = "Selection";
private static final int ZERO = 0;
@@ -86,6 +88,8 @@
preserveProperty( column, PROP_FOOTER_FONT, column.getFooterFont() );
preserveProperty( column, PROP_FOOTER_TEXT, column.getFooterText() );
preserveProperty( column, PROP_FOOTER_IMAGE, column.getFooterImage() );
+ preserveProperty( column, PROP_WORD_WRAP, column.getWordWrap() );
+ preserveProperty( column, PROP_HEADER_WORD_WRAP, column.getHeaderWordWrap() );
preserveListener( column, PROP_SELECTION_LISTENER, isListening( column, SWT.Selection ) );
}
@@ -107,6 +111,8 @@
renderFont( column, PROP_FOOTER_FONT, column.getFooterFont() );
renderProperty( column, PROP_FOOTER_TEXT, column.getFooterText(), "" );
renderProperty( column, PROP_FOOTER_IMAGE, column.getFooterImage(), null );
+ renderProperty( column, PROP_WORD_WRAP, column.getWordWrap(), false );
+ renderProperty( column, PROP_HEADER_WORD_WRAP, column.getHeaderWordWrap(), false );
renderListener( column, PROP_SELECTION_LISTENER, isListening( column, SWT.Selection ), false );
}
diff --git a/examples/org.eclipse.rap.nebula.widgets.grid.demo.standalone/.settings/GridSnippets.launch b/examples/org.eclipse.rap.nebula.widgets.grid.demo.standalone/.settings/GridSnippets.launch
index 3a12f24..4c46557 100644
--- a/examples/org.eclipse.rap.nebula.widgets.grid.demo.standalone/.settings/GridSnippets.launch
+++ b/examples/org.eclipse.rap.nebula.widgets.grid.demo.standalone/.settings/GridSnippets.launch
@@ -21,7 +21,7 @@
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -console -consolelog"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dorg.eclipse.equinox.http.jetty.log.stderr.threshold=info"/>
-<stringAttribute key="org.eclipse.rap.launch.browserMode" value="INTERNAL"/>
+<stringAttribute key="org.eclipse.rap.launch.browserMode" value="EXTERNAL"/>
<stringAttribute key="org.eclipse.rap.launch.contextpath" value=""/>
<stringAttribute key="org.eclipse.rap.launch.dataLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.rap.tools.launch/GridSnippets"/>
<booleanAttribute key="org.eclipse.rap.launch.developmentMode" value="true"/>
diff --git a/examples/org.eclipse.rap.nebula.widgets.grid.demo.standalone/src/org/eclipse/rap/nebula/widgets/grid/snippets/GridSnippet.java b/examples/org.eclipse.rap.nebula.widgets.grid.demo.standalone/src/org/eclipse/rap/nebula/widgets/grid/snippets/GridSnippet.java
index bac26f0..ae75290 100644
--- a/examples/org.eclipse.rap.nebula.widgets.grid.demo.standalone/src/org/eclipse/rap/nebula/widgets/grid/snippets/GridSnippet.java
+++ b/examples/org.eclipse.rap.nebula.widgets.grid.demo.standalone/src/org/eclipse/rap/nebula/widgets/grid/snippets/GridSnippet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 EclipseSource and others.
+ * Copyright (c) 2012, 2014 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -58,6 +58,8 @@
createShowColumnGroup( parent );
createShowHeaderButton( parent );
createShowFooterButton( parent );
+ createWordWrapButton( parent );
+ createHeaderWordWrapButton( parent );
createQueryFocusItem( parent );
}
@@ -352,6 +354,34 @@
} );
}
+ private void createWordWrapButton( Composite parent ) {
+ final Button button = new Button( parent, SWT.CHECK );
+ button.setText( "Word wrap cells text" );
+ button.setSelection( false );
+ button.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( SelectionEvent event ) {
+ for( GridColumn column : grid.getColumns() ) {
+ column.setWordWrap( button.getSelection() );
+ }
+ }
+ } );
+ }
+
+ private void createHeaderWordWrapButton( Composite parent ) {
+ final Button button = new Button( parent, SWT.CHECK );
+ button.setText( "Word wrap headers text" );
+ button.setSelection( false );
+ button.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected( SelectionEvent event ) {
+ for( GridColumn column : grid.getColumns() ) {
+ column.setHeaderWordWrap( button.getSelection() );
+ }
+ }
+ } );
+ }
+
private void createQueryFocusItem( Composite parent ) {
Button button = new Button( parent, SWT.PUSH );
button.setText( "Query focusItem" );
diff --git a/tests/org.eclipse.rap.nebula.widgets.grid.test/src/org/eclipse/nebula/widgets/grid/GridColumn_Test.java b/tests/org.eclipse.rap.nebula.widgets.grid.test/src/org/eclipse/nebula/widgets/grid/GridColumn_Test.java
index 345df30..de1587c 100644
--- a/tests/org.eclipse.rap.nebula.widgets.grid.test/src/org/eclipse/nebula/widgets/grid/GridColumn_Test.java
+++ b/tests/org.eclipse.rap.nebula.widgets.grid.test/src/org/eclipse/nebula/widgets/grid/GridColumn_Test.java
@@ -13,12 +13,16 @@
import static org.eclipse.nebula.widgets.grid.GridTestUtil.createGridColumns;
import static org.eclipse.nebula.widgets.grid.GridTestUtil.createGridItems;
import static org.eclipse.nebula.widgets.grid.GridTestUtil.loadImage;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
-
import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.internal.lifecycle.PhaseId;
import org.eclipse.rap.rwt.internal.service.ContextProvider;
@@ -38,21 +42,23 @@
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
@SuppressWarnings({
"restriction", "deprecation"
})
-public class GridColumn_Test extends TestCase {
+public class GridColumn_Test {
private Display display;
private Shell shell;
private Grid grid;
private List<Event> eventLog;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() {
Fixture.setUp();
Fixture.fakePhase( PhaseId.PROCESS_ACTION );
display = new Display();
@@ -61,12 +67,13 @@
eventLog = new ArrayList<Event>();
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() {
Fixture.tearDown();
}
- public void testGridColumnCreation_GridParent() {
+ @Test
+ public void testGridColumnCreation_withGridParent() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertSame( grid, column.getParent() );
@@ -75,7 +82,8 @@
assertEquals( 1, grid.getColumnCount() );
}
- public void testGridColumnCreation_GroupParent() {
+ @Test
+ public void testGridColumnCreation_withGroupParent() {
GridColumnGroup group = new GridColumnGroup( grid, SWT.NONE );
GridColumn column = new GridColumn( group, SWT.NONE );
@@ -85,6 +93,7 @@
assertEquals( 1, grid.getColumnCount() );
}
+ @Test
public void testGridColumnCreation_AtIndexWithGridParent() {
createGridColumns( grid, 5, SWT.NONE );
@@ -95,6 +104,7 @@
assertEquals( 6, grid.getColumnCount() );
}
+ @Test
public void testGridColumnCreation_AtIndexWithGroupParent() {
createGridColumns( grid, 2, SWT.NONE );
GridColumnGroup group = new GridColumnGroup( grid, SWT.NONE );
@@ -107,6 +117,7 @@
assertSame( column, group.getColumns()[ 1 ] );
}
+ @Test
public void testDispose() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -116,6 +127,7 @@
assertEquals( 0, grid.getColumnCount() );
}
+ @Test
public void testDispose_WithGroup() {
GridColumnGroup group = new GridColumnGroup( grid, SWT.NONE );
GridColumn column1 = new GridColumn( group, SWT.NONE );
@@ -127,6 +139,7 @@
assertSame( column2, group.getColumns()[ 0 ] );
}
+ @Test
public void testSendDisposeEvent() {
final List<DisposeEvent> log = new ArrayList<DisposeEvent>();
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -142,6 +155,7 @@
assertSame( column, log.get( 0 ).widget );
}
+ @Test
public void testSendDisposeEventOnGridDispose() {
final List<DisposeEvent> log = new ArrayList<DisposeEvent>();
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -157,6 +171,7 @@
assertSame( column, log.get( 0 ).widget );
}
+ @Test
public void testIsCheck() {
GridColumn column1 = new GridColumn( grid, SWT.NONE );
GridColumn column2 = new GridColumn( grid, SWT.CHECK );
@@ -167,6 +182,7 @@
assertFalse( column3.isCheck() );
}
+ @Test
public void testIsCheck_TableCheck() {
grid = new Grid( shell, SWT.CHECK );
GridColumn column1 = new GridColumn( grid, SWT.NONE );
@@ -181,6 +197,7 @@
assertFalse( column3.isCheck() );
}
+ @Test
public void testIsCheck_OnColumnAddRemove() {
grid = new Grid( shell, SWT.CHECK );
GridColumn[] columns = createGridColumns( grid, 3, SWT.NONE );
@@ -193,12 +210,14 @@
assertTrue( columns[ 0 ].isCheck() );
}
+ @Test
public void testGetWidth_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertEquals( 10, column.getWidth() );
}
+ @Test
public void testGetWidth() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -207,6 +226,7 @@
assertEquals( 100, column.getWidth() );
}
+ @Test
public void testSetWidth_BelowMinimumWidth() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -216,12 +236,14 @@
assertEquals( 20, column.getWidth() );
}
+ @Test
public void testGetMinimumWidth_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertEquals( 0, column.getMinimumWidth() );
}
+ @Test
public void testGetMinimumWidth() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -230,6 +252,7 @@
assertEquals( 10, column.getMinimumWidth() );
}
+ @Test
public void testSetMinimumWidth_AdjustWidth() {
GridColumn column = new GridColumn( grid, SWT.NONE );
column.setWidth( 10 );
@@ -239,12 +262,14 @@
assertEquals( 20, column.getWidth() );
}
+ @Test
public void testGetSort_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertEquals( SWT.NONE, column.getSort() );
}
+ @Test
public void testGetSort() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -253,6 +278,7 @@
assertEquals( SWT.DOWN, column.getSort() );
}
+ @Test
public void testSetSort_OnlyOneSortColumn() {
GridColumn[] columns = createGridColumns( grid, 3, SWT.NONE );
columns[ 0 ].setSort( SWT.UP );
@@ -262,6 +288,7 @@
assertEquals( SWT.NONE, columns[ 0 ].getSort() );
}
+ @Test
public void testGetVisible_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -269,6 +296,7 @@
assertTrue( column.isVisible() );
}
+ @Test
public void testGetVisible() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -277,6 +305,7 @@
assertFalse( column.getVisible() );
}
+ @Test
public void testSetVisible_FireHideEvent() {
GridColumn column = new GridColumn( grid, SWT.NONE );
column.addListener( SWT.Hide, new LoggingListener() );
@@ -289,6 +318,7 @@
assertSame( column, event.widget );
}
+ @Test
public void testSetVisible_FireShowEvent() {
GridColumn column = new GridColumn( grid, SWT.NONE );
column.setVisible( false );
@@ -302,6 +332,7 @@
assertSame( column, event.widget );
}
+ @Test
public void testSetVisible_FireMoveEventOnNextColumns() {
GridColumn[] columns = createGridColumns( grid, 3, SWT.NONE );
columns[ 0 ].addListener( SWT.Move, new LoggingListener() );
@@ -315,6 +346,7 @@
assertSame( columns[ 2 ], event.widget );
}
+ @Test
public void testSetVisible_FireEventOnlyOnce() {
GridColumn column = new GridColumn( grid, SWT.NONE );
column.addListener( SWT.Hide, new LoggingListener() );
@@ -325,6 +357,7 @@
assertEquals( 1, eventLog.size() );
}
+ @Test
public void testIsTree_WithoutSubItems() {
GridColumn[] columns = createGridColumns( grid, 3, SWT.NONE );
createGridItems( grid, 3, 0 );
@@ -334,6 +367,7 @@
assertFalse( columns[ 2 ].isTree() );
}
+ @Test
public void testIsTree_WithSubItems() {
GridColumn[] columns = createGridColumns( grid, 3, SWT.NONE );
createGridItems( grid, 3, 1 );
@@ -343,6 +377,7 @@
assertFalse( columns[ 2 ].isTree() );
}
+ @Test
public void testIsTree_AddColumn() {
GridColumn[] columns = createGridColumns( grid, 3, SWT.NONE );
createGridItems( grid, 3, 1 );
@@ -355,6 +390,7 @@
assertFalse( columns[ 2 ].isTree() );
}
+ @Test
public void testIsTree_RemoveColumn() {
GridColumn[] columns = createGridColumns( grid, 3, SWT.NONE );
createGridItems( grid, 3, 1 );
@@ -365,18 +401,21 @@
assertFalse( columns[ 2 ].isTree() );
}
+ @Test
public void testGetAlignment_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertEquals( SWT.LEFT, column.getAlignment() );
}
+ @Test
public void testGetAlignment_WithStyleFlag() {
GridColumn column = new GridColumn( grid, SWT.RIGHT );
assertEquals( SWT.RIGHT, column.getAlignment() );
}
+ @Test
public void testSetAlignment() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -385,6 +424,7 @@
assertEquals( SWT.CENTER, column.getAlignment() );
}
+ @Test
public void testSetAlignment_InvalidValue() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -393,12 +433,14 @@
assertEquals( SWT.LEFT, column.getAlignment() );
}
+ @Test
public void testGetMoveable_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertFalse( column.getMoveable() );
}
+ @Test
public void testGetMoveable() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -407,12 +449,14 @@
assertTrue( column.getMoveable() );
}
+ @Test
public void testGetResizeable_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertTrue( column.getResizeable() );
}
+ @Test
public void testGetResizeable() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -421,12 +465,14 @@
assertFalse( column.getResizeable() );
}
+ @Test
public void testGetCheckable_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertTrue( column.getCheckable() );
}
+ @Test
public void testGetCheckable() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -435,12 +481,14 @@
assertFalse( column.getCheckable() );
}
+ @Test
public void testIsDetail_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertTrue( column.isDetail() );
}
+ @Test
public void testIsDetail() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -449,12 +497,14 @@
assertFalse( column.isDetail() );
}
+ @Test
public void testIsSummary_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertTrue( column.isSummary() );
}
+ @Test
public void testIsSummary() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -463,6 +513,7 @@
assertFalse( column.isSummary() );
}
+ @Test
public void testAddRemoveSelectionListener() {
GridColumn column = new GridColumn( grid, SWT.NONE );
SelectionListener listener = new SelectionAdapter() { };
@@ -475,26 +526,21 @@
assertFalse( column.isListening( SWT.Selection ) );
}
+ @Test( expected = IllegalArgumentException.class )
public void testAddSelectionListener_NullArgument() {
GridColumn column = new GridColumn( grid, SWT.NONE );
- try {
- column.addSelectionListener( null );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.addSelectionListener( null );
}
+ @Test( expected = IllegalArgumentException.class )
public void testRemoveSelectionListener_NullArgument() {
GridColumn column = new GridColumn( grid, SWT.NONE );
- try {
- column.removeSelectionListener( null );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.removeSelectionListener( null );
}
+ @Test
public void testAddRemoveControlListener() {
GridColumn column = new GridColumn( grid, SWT.NONE );
ControlListener listener = new ControlAdapter() { };
@@ -510,32 +556,28 @@
assertFalse( column.isListening( SWT.Resize ) );
}
+ @Test( expected = IllegalArgumentException.class )
public void testAddControlListener_NullArgument() {
GridColumn column = new GridColumn( grid, SWT.NONE );
- try {
- column.addControlListener( null );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.addControlListener( null );
}
+ @Test( expected = IllegalArgumentException.class )
public void testRemoveControlListener_NullArgument() {
GridColumn column = new GridColumn( grid, SWT.NONE );
- try {
- column.removeControlListener( null );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.removeControlListener( null );
}
+ @Test
public void testGetHeaderText_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertEquals( "", column.getText() );
}
+ @Test
public void testGetHeaderText() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -544,22 +586,21 @@
assertEquals( "foo", column.getText() );
}
+ @Test( expected = IllegalArgumentException.class )
public void testSetHeaderText_NullArgument() {
GridColumn column = new GridColumn( grid, SWT.NONE );
- try {
- column.setText( null );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.setText( null );
}
+ @Test
public void testGetHeaderImage_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertNull( column.getImage() );
}
+ @Test
public void testGetHeaderImage() {
GridColumn column = new GridColumn( grid, SWT.NONE );
Image image = loadImage( display, Fixture.IMAGE1 );
@@ -569,24 +610,23 @@
assertSame( image, column.getImage() );
}
+ @Test( expected = IllegalArgumentException.class )
public void testSetHeaderImage_DisposedImage() {
GridColumn column = new GridColumn( grid, SWT.NONE );
Image image = loadImage( display, Fixture.IMAGE1 );
image.dispose();
- try {
- column.setImage( image );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.setImage( image );
}
+ @Test
public void testGetHeaderFont_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertSame( grid.getFont(), column.getHeaderFont() );
}
+ @Test
public void testGetHeaderFont() {
GridColumn column = new GridColumn( grid, SWT.NONE );
Font font = new Font( display, "Arial", 20, SWT.BOLD );
@@ -596,24 +636,23 @@
assertSame( font, column.getHeaderFont() );
}
+ @Test( expected = IllegalArgumentException.class )
public void testSetHeaderFont_DisposedFont() {
GridColumn column = new GridColumn( grid, SWT.NONE );
Font font = new Font( display, "Arial", 20, SWT.BOLD );
font.dispose();
- try {
- column.setHeaderFont( font );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.setHeaderFont( font );
}
+ @Test
public void testGetFooterText_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertEquals( "", column.getFooterText() );
}
+ @Test
public void testGetFooterText() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -622,22 +661,21 @@
assertEquals( "foo", column.getFooterText() );
}
+ @Test( expected = IllegalArgumentException.class )
public void testSetFooterText_NullArgument() {
GridColumn column = new GridColumn( grid, SWT.NONE );
- try {
- column.setFooterText( null );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.setFooterText( null );
}
+ @Test
public void testGetFooterImage_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertNull( column.getFooterImage() );
}
+ @Test
public void testGetFooterImage() {
GridColumn column = new GridColumn( grid, SWT.NONE );
Image image = loadImage( display, Fixture.IMAGE1 );
@@ -647,24 +685,23 @@
assertSame( image, column.getFooterImage() );
}
+ @Test( expected = IllegalArgumentException.class )
public void testSetFooterImage_DisposedImage() {
GridColumn column = new GridColumn( grid, SWT.NONE );
Image image = loadImage( display, Fixture.IMAGE1 );
image.dispose();
- try {
- column.setFooterImage( image );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.setFooterImage( image );
}
+ @Test
public void testGetFooterFont_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertSame( grid.getFont(), column.getFooterFont() );
}
+ @Test
public void testGetFooterFont() {
GridColumn column = new GridColumn( grid, SWT.NONE );
Font font = new Font( display, "Arial", 20, SWT.BOLD );
@@ -674,18 +711,16 @@
assertSame( font, column.getFooterFont() );
}
+ @Test( expected = IllegalArgumentException.class )
public void testSetFooterFont_DisposedFont() {
GridColumn column = new GridColumn( grid, SWT.NONE );
Font font = new Font( display, "Arial", 20, SWT.BOLD );
font.dispose();
- try {
- column.setFooterFont( font );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.setFooterFont( font );
}
+ @Test
public void testPack_TreeColumnEmpty() {
GridColumn[] columns = createGridColumns( grid, 2, SWT.NONE );
GridItem item = new GridItem( grid, SWT.NONE );
@@ -698,6 +733,7 @@
assertEquals( 38, columns[ 0 ].getWidth() );
}
+ @Test
public void testPack_NonTreeColumnEmpty() {
GridColumn[] columns = createGridColumns( grid, 2, SWT.NONE );
GridItem item = new GridItem( grid, SWT.NONE );
@@ -710,6 +746,7 @@
assertEquals( 16, columns[ 1 ].getWidth() );
}
+ @Test
public void testPack_TreeColumn() {
grid = new Grid( shell, SWT.CHECK );
GridColumn[] columns = createGridColumns( grid, 2, SWT.NONE );
@@ -727,6 +764,7 @@
assertEquals( 139, columns[ 0 ].getWidth() );
}
+ @Test
public void testPack_NonTreeColumn() {
grid = new Grid( shell, SWT.CHECK );
GridColumn[] columns = createGridColumns( grid, 2, SWT.NONE );
@@ -744,6 +782,7 @@
assertEquals( 90, columns[ 1 ].getWidth() );
}
+ @Test
public void testPack_WithHeaderVisible() {
grid.setHeaderVisible( true );
GridColumn[] columns = createGridColumns( grid, 2, SWT.CHECK );
@@ -763,6 +802,7 @@
assertEquals( 353, columns[ 0 ].getWidth() );
}
+ @Test
public void testPack_WithFooterVisible() {
grid.setFooterVisible( true );
GridColumn[] columns = createGridColumns( grid, 2, SWT.CHECK );
@@ -782,6 +822,7 @@
assertEquals( 353, columns[ 0 ].getWidth() );
}
+ @Test
public void testRepackAfterTextSizeDetermination() {
grid.setHeaderVisible( true );
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -801,12 +842,14 @@
assertTrue( repackedWidth > packedWidth );
}
+ @Test
public void testGetHeaderTooltip_Initial() {
GridColumn column = new GridColumn( grid, SWT.NONE );
assertNull( column.getHeaderTooltip() );
}
+ @Test
public void testGetHeaderTooltip() {
GridColumn column = new GridColumn( grid, SWT.NONE );
@@ -815,6 +858,39 @@
assertEquals( "foo", column.getHeaderTooltip() );
}
+ @Test
+ public void testGetHeaderWordWrap_Initial() {
+ GridColumn column = new GridColumn( grid, SWT.NONE );
+
+ assertFalse( column.getHeaderWordWrap() );
+ }
+
+ @Test
+ public void testGetHeaderWordWrap() {
+ GridColumn column = new GridColumn( grid, SWT.NONE );
+
+ column.setHeaderWordWrap( true );
+
+ assertTrue( column.getHeaderWordWrap() );
+ }
+
+ @Test
+ public void testGetWordWrap_Initial() {
+ GridColumn column = new GridColumn( grid, SWT.NONE );
+
+ assertFalse( column.getWordWrap() );
+ }
+
+ @Test
+ public void testGetWordWrap() {
+ GridColumn column = new GridColumn( grid, SWT.NONE );
+
+ column.setWordWrap( true );
+
+ assertTrue( column.getWordWrap() );
+ }
+
+ @Test
public void testIsVisible_Initial() {
GridColumnGroup group = new GridColumnGroup( grid, SWT.NONE );
GridColumn column = new GridColumn( group, SWT.NONE );
@@ -822,6 +898,7 @@
assertTrue( column.isVisible() );
}
+ @Test
public void testIsVisible_ExpandedGroup() {
GridColumnGroup group = new GridColumnGroup( grid, SWT.NONE );
group.setExpanded( true );
@@ -831,6 +908,7 @@
assertFalse( column.isVisible() );
}
+ @Test
public void testIsVisible_CollapsedGroup() {
GridColumnGroup group = new GridColumnGroup( grid, SWT.NONE );
group.setExpanded( false );
@@ -852,16 +930,12 @@
}
}
- @Test
+ @Test( expected = IllegalArgumentException.class )
public void testMarkupToolTipTextWithMarkupEnabled() {
GridColumn column = new GridColumn( grid, SWT.NONE );
column.setData( RWT.TOOLTIP_MARKUP_ENABLED, Boolean.TRUE );
- try {
- column.setHeaderTooltip( "invalid xhtml: <<&>>" );
- fail();
- } catch( IllegalArgumentException expected ) {
- }
+ column.setHeaderTooltip( "invalid xhtml: <<&>>" );
}
@Test
diff --git a/tests/org.eclipse.rap.nebula.widgets.grid.test/src/org/eclipse/nebula/widgets/grid/internal/gridcolumnkit/GridColumnLCA_Test.java b/tests/org.eclipse.rap.nebula.widgets.grid.test/src/org/eclipse/nebula/widgets/grid/internal/gridcolumnkit/GridColumnLCA_Test.java
index c4badf1..5954f67 100644
--- a/tests/org.eclipse.rap.nebula.widgets.grid.test/src/org/eclipse/nebula/widgets/grid/internal/gridcolumnkit/GridColumnLCA_Test.java
+++ b/tests/org.eclipse.rap.nebula.widgets.grid.test/src/org/eclipse/nebula/widgets/grid/internal/gridcolumnkit/GridColumnLCA_Test.java
@@ -20,6 +20,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
import java.io.IOException;
import java.util.LinkedList;
@@ -41,8 +42,6 @@
import org.eclipse.rap.rwt.testfixture.Fixture;
import org.eclipse.rap.rwt.testfixture.TestMessage;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.internal.graphics.ImageFactory;
@@ -563,7 +562,7 @@
Fixture.markInitialized( column );
Fixture.preserveWidgets();
- column.addSelectionListener( new SelectionAdapter() { } );
+ column.addListener( SWT.Selection, mock( Listener.class ) );
lca.renderChanges( column );
TestMessage message = Fixture.getProtocolMessage();
@@ -572,13 +571,13 @@
@Test
public void testRenderRemoveSelectionListener() throws Exception {
- SelectionListener listener = new SelectionAdapter() { };
- column.addSelectionListener( listener );
+ Listener listener = mock( Listener.class );
+ column.addListener( SWT.Selection, listener );
Fixture.markInitialized( display );
Fixture.markInitialized( column );
Fixture.preserveWidgets();
- column.removeSelectionListener( listener );
+ column.removeListener( SWT.Selection, listener );
lca.renderChanges( column );
TestMessage message = Fixture.getProtocolMessage();
@@ -591,7 +590,7 @@
Fixture.markInitialized( column );
Fixture.preserveWidgets();
- column.addSelectionListener( new SelectionAdapter() { } );
+ column.addListener( SWT.Selection, mock( Listener.class ) );
Fixture.preserveWidgets();
lca.renderChanges( column );
@@ -801,6 +800,68 @@
assertEquals( JsonObject.NULL, message.findSetProperty( column, "footerImage" ) );
}
+ @Test
+ public void testRenderInitialWordWrap() throws IOException {
+ lca.render( column );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ CreateOperation operation = message.findCreateOperation( column );
+ assertTrue( operation.getProperties().names().indexOf( "wordWrap" ) == -1 );
+ }
+
+ @Test
+ public void testRenderWordWrap() throws IOException {
+ column.setWordWrap( true );
+ lca.renderChanges( column );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertEquals( JsonValue.TRUE, message.findSetProperty( column, "wordWrap" ) );
+ }
+
+ @Test
+ public void testRenderWordWrapUnchanged() throws IOException {
+ Fixture.markInitialized( display );
+ Fixture.markInitialized( column );
+
+ column.setWordWrap( true );
+ Fixture.preserveWidgets();
+ lca.renderChanges( column );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertNull( message.findSetOperation( column, "wordWrap" ) );
+ }
+
+ @Test
+ public void testRenderInitialHeaderWordWrap() throws IOException {
+ lca.render( column );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ CreateOperation operation = message.findCreateOperation( column );
+ assertTrue( operation.getProperties().names().indexOf( "headerWordWrap" ) == -1 );
+ }
+
+ @Test
+ public void testRenderHeaderWordWrap() throws IOException {
+ column.setHeaderWordWrap( true );
+ lca.renderChanges( column );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertEquals( JsonValue.TRUE, message.findSetProperty( column, "headerWordWrap" ) );
+ }
+
+ @Test
+ public void testRenderHeaderWordWrapUnchanged() throws IOException {
+ Fixture.markInitialized( display );
+ Fixture.markInitialized( column );
+
+ column.setHeaderWordWrap( true );
+ Fixture.preserveWidgets();
+ lca.renderChanges( column );
+
+ TestMessage message = Fixture.getProtocolMessage();
+ assertNull( message.findSetOperation( column, "headerWordWrap" ) );
+ }
+
//////////////////
// Helping classes