SWTBOtNatTable

// ============================================================================
//
// 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)
        
        
    }
    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值