Skip to content

Commit

Permalink
Add setText for TableItem (fixes # 2132)
Browse files Browse the repository at this point in the history
Signed-off-by: Josef Kopriva <jkopriva@redhat.com>
  • Loading branch information
jkopriva authored and odockal committed Aug 25, 2021
1 parent e1d2537 commit c03c23d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,52 @@ public void run() {
});
}

/**
* Sets text in specified table item in column 0.
*
* @param tableItem table item to handle
* @param text text to set
*/
public void setText (final TableItem tableItem, String text) {
Display.syncExec(new Runnable() {
@Override
public void run() {
tableItem.setText(text);
}
});
}

/**
* Sets text in specified table item and in specific column.
*
* @param tableItem table item to handle
* @param column column to click on
* @param text text to set
*/
public void setText (final TableItem tableItem, int column, String text) {
Display.syncExec(new Runnable() {
@Override
public void run() {
tableItem.setText(column, text);
}
});
}

/**
* Sets texts in specified table item.
*
* @param tableItem table item to handle
* @param strings string to set in table item
*/
public void setText (final TableItem tableItem, String [] strings) {
Display.syncExec(new Runnable() {
@Override
public void run() {
tableItem.setText(strings);
}
});
}


private class TableCheckListener implements Listener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,26 @@ public interface TableItem extends Item<org.eclipse.swt.widgets.TableItem> {
* @param column to click on
*/
void doubleClick(int column);

/**
* Sets text
*
* @param string the new text
*/
void setText (String text);

/**
* Sets text at a column
*
* @param index the column index
* @param string the new text
*/
void setText (int index, String text);

/**
* Sets the text for multiple columns in the table.
*
* @param strings the array of new strings
*/
void setText (String [] strings);
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ public void doubleClick(int column){
TableItemHandler.getInstance().doubleClick(swtWidget, column);
}

/* (non-Javadoc)
* @see org.eclipse.reddeer.swt.api.TableItem#setText(String)
*/
@Override
public void setText (String text) {
log.info("Set text " + text);
TableItemHandler.getInstance().setText(swtWidget, text);
}

/* (non-Javadoc)
* @see org.eclipse.reddeer.swt.api.TableItem#setText(String, int)
*/
@Override
public void setText (int index, String text){
log.info("Set text " + text + "in column " + index);
TableItemHandler.getInstance().setText(swtWidget, index, text);
}

/* (non-Javadoc)
* @see org.eclipse.reddeer.swt.api.TableItem#setText(String [])
*/
@Override
public void setText (String [] strings) {
log.info("Set text array: " + strings.toString());
TableItemHandler.getInstance().setText(swtWidget, strings);
}

@Override
public Control<?> getParentControl() {
return getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,28 @@ public void click(){
ti.click();
assertEquals("single click",ti.getText());
}

@Test
public void setText(){
new DefaultTableItem(new DefaultTable(0), 6).setText("some text");
assertThat(new DefaultTableItem(6).getText(), is("some text"));
}

@Test
public void setTextColumn(){
new DefaultTableItem(7).setText(6, "some text in column");
assertThat(new DefaultTableItem(7).getText(6), is("some text in column"));
}

@Test
public void setTextStrings(){
String[] strings = new String[] {"some", "texts", "in", "columns"};
DefaultTableItem tableItem = new DefaultTableItem(new DefaultTable(0), 7);
tableItem.setText(strings);

for (int i=0; i<strings.length; i++) {
String string = strings [i];
assertThat(tableItem.getText(i), is(string));
}
}
}

0 comments on commit c03c23d

Please sign in to comment.