// ============================================================================
//
// Copyright (C) 2006-2012 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.swtbot.finder.widgets;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.style.IStyle;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
/**
* DOC lwang class global comment. Detailled comment
*/
public class SWTBotNatTable extends AbstractSWTBotControl<NatTable> {
public SWTBotNatTable(NatTable natTable) {
super(natTable, null);
}
public SWTBotNatTable clickTableHeader(int columnIndex){
return clickCell(0, columnIndex);
}
public SWTBotNatTable clickCell(int rowIndex, int columnIndex){
assertEnabled();
// get the relative location of the table item
Rectangle cellBounds = widget.getBoundsByPosition(columnIndex, rowIndex);
int x = cellBounds.x + cellBounds.width/2;
int y = cellBounds.y + cellBounds.height/2;
Rectangle location = absoluteLocation();
click(location.x + x, location.y + y, true);
return this;
}
public Object getCellValue(final int rowIndex, final int columnIndex){
return UIThreadRunnable.syncExec(new Result<Object>() {
public Object run() {
return widget.getDataValueByPosition(columnIndex, rowIndex);
}
});
}
public List<String> columns(){
return UIThreadRunnable.syncExec(new Result<List<String>>() {
public List<String> run() {
List<String> headers = new ArrayList<String>();
int columnCount = widget.getColumnCount();
for(int i = 0; i < columnCount; i++){
String cellValue = (String)widget.getDataValueByPosition(i, 0);
if(cellValue == null){
System.err.println("NatTable didn't show complete!!!");
}
headers.add(cellValue);
}
return headers;
}
});
}
public int getXPositoinByValue(final int column, final String data){
return UIThreadRunnable.syncExec(new Result<Integer>() {
public Integer run() {
for(int i = 0; i < widget.getRowCount(); i++){
if(widget.getDataValueByPosition(column, i).equals(data)){
return i;
}
}
return -1;
}
});
}
public int getColumnCount(){
return UIThreadRunnable.syncExec(new Result<Integer>() {
public Integer run() {
return widget.getColumnCount();
}
});
}
public int getRowCount(){
return UIThreadRunnable.syncExec(new Result<Integer>() {
public Integer run() {
return widget.getRowCount();
}
});
}
public Color getHeaderFontColor(String headerText){
IStyle cellStyle = widget.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, headerText);
Color color = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
return color;
}
public void contextMenu(int index){
widget.getCellByPosition(columnPosition, rowPosition)
}
}
//
// Copyright (C) 2006-2012 Talend Inc. - www.talend.com
//
// This source code is available under agreement available at
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
//
// You should have received a copy of the agreement
// along with this program; if not, write to Talend SA
// 9 rue Pages 92150 Suresnes, France
//
// ============================================================================
package org.talend.swtbot.finder.widgets;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.nebula.widgets.nattable.NatTable;
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.style.CellStyleAttributes;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.style.IStyle;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
/**
* DOC lwang class global comment. Detailled comment
*/
public class SWTBotNatTable extends AbstractSWTBotControl<NatTable> {
public SWTBotNatTable(NatTable natTable) {
super(natTable, null);
}
public SWTBotNatTable clickTableHeader(int columnIndex){
return clickCell(0, columnIndex);
}
public SWTBotNatTable clickCell(int rowIndex, int columnIndex){
assertEnabled();
// get the relative location of the table item
Rectangle cellBounds = widget.getBoundsByPosition(columnIndex, rowIndex);
int x = cellBounds.x + cellBounds.width/2;
int y = cellBounds.y + cellBounds.height/2;
Rectangle location = absoluteLocation();
click(location.x + x, location.y + y, true);
return this;
}
public Object getCellValue(final int rowIndex, final int columnIndex){
return UIThreadRunnable.syncExec(new Result<Object>() {
public Object run() {
return widget.getDataValueByPosition(columnIndex, rowIndex);
}
});
}
public List<String> columns(){
return UIThreadRunnable.syncExec(new Result<List<String>>() {
public List<String> run() {
List<String> headers = new ArrayList<String>();
int columnCount = widget.getColumnCount();
for(int i = 0; i < columnCount; i++){
String cellValue = (String)widget.getDataValueByPosition(i, 0);
if(cellValue == null){
System.err.println("NatTable didn't show complete!!!");
}
headers.add(cellValue);
}
return headers;
}
});
}
public int getXPositoinByValue(final int column, final String data){
return UIThreadRunnable.syncExec(new Result<Integer>() {
public Integer run() {
for(int i = 0; i < widget.getRowCount(); i++){
if(widget.getDataValueByPosition(column, i).equals(data)){
return i;
}
}
return -1;
}
});
}
public int getColumnCount(){
return UIThreadRunnable.syncExec(new Result<Integer>() {
public Integer run() {
return widget.getColumnCount();
}
});
}
public int getRowCount(){
return UIThreadRunnable.syncExec(new Result<Integer>() {
public Integer run() {
return widget.getRowCount();
}
});
}
public Color getHeaderFontColor(String headerText){
IStyle cellStyle = widget.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, headerText);
Color color = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
return color;
}
public void contextMenu(int index){
widget.getCellByPosition(columnPosition, rowPosition)
}
}