Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Add setText for TableItem (fixes # 2132) #2134

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
}