eas之事件

选择事件

选择事件是在选择块发生变化后发出。
table.addKDTSelectListener(new KDTSelectListener()
{
    public void tableSelectChanged(KDTSelectEvent e){
    // 获取上一个选择块
    KDTSelectBlock sbPrev = e.getPrevSelectBlock();
    // 获取当前选择块
    KDTSelectBlock sbCurr = e.getSelectBlock();
    // ...do something
    }
});

    鼠标单击双击事件

单击事件是在鼠标单击某个单元格后发出。
双击事件是在鼠标双击某个单元格后发出。
table.addKDTMouseListener(new KDTMouseListener()
{
    public void tableClicked(KDTMouseEvent e)
{
    // 单击
        if (e.getClickCount() == 1)
{
            // ...do something
        }
        // 双击
        else if (e.getClickCount() == 2)
        {
            // ...do something
}
    }
});

激活单元即指当前处于准备进入编辑状态的单元。
激活单元变化事件是在激活单元发生变化后发出。
添加激活单元变化事件侦听者
table.addKDTActiveCellListener(new KDTActiveCellListener()
{
    public void activeCellChanged(KDTActiveCellEvent e)
{
    // 获取上一个激活单元的行列索引
        int prevRow = e.getPrevRowIndex();
        int prevCol = e.getPrevColumnIndex();
        // 获取当前激活单元的行列索引
        int currRow = e.getRowIndex();
        int currCol = e.getColumnIndex();
        // ...do something
    }
});

    编辑事件

编辑事件KDTEditListener包括以下几个方法:
editStarting 编辑器启动中,在编辑器启动之前发出,通过设置返回值可以取消启动编辑器。
editStarted 编辑启动后,在编辑启动之后发出。
editValueChanged 编辑器值变化,在编辑器的值发生变化后发出。
editStopping 编辑器结束中,在编辑器结束之前发出,通过设置返回值可以取消结束编辑器。
editStopped 编辑器结束后,在编辑器结束之后发出。
KDTEditListener提供了适配器KDTEditAdapter
// 示例
table.addKDTEditListener(new KDTEditAdapter()
{
    // 编辑器启动前
    public void editStarting(KDTEditEvent e)
  {
        System.out.println("editStarting");
        // 如果当前行是第三行,将取消编辑
        if (e.getRowIndex() == 3)
            e.setCancel(true);
    }
    
    // 编辑启动后
    public void editStarted(KDTEditEvent e)
  {
        System.out.println("editStarted");
    // 如果当前单元处于第4行第0列,并且单元值为字符串,则在字符串前加上$符
    if ((e.getRowIndex() == 4) && (e.getColIndex() == 0))
    {
            KDTable tbl = (KDTable)e.getSource();
            Object value =tbl.getEditManager().getEditor().getValue();
            if (value instanceof String)
tbl.getEditManager().getEditor().setValue("$" + value.toString());
        }
    }
    
    // 编辑器值变化(注意:此时编辑器还未结束,KDTable实际上是转发编辑器的
   // change事件)
    public void editValueChanged(KDTEditEvent e){
        System.out.println("editValueChanged");
    }
    
    // 编辑器结束前
    public void editStopping(KDTEditEvent e)
{
        System.out.println("editStopping");
        //如果当前单元处于第4行第0列,则在退出前将$符去掉
        if ((e.getRowIndex() == 4) && (e.getColIndex() == 0))
{
            KDTable tbl = (KDTable)e.getSource();
            String value = (String)tbl.getEditManager().getEditor().getValue();
            // 如果单元格的值长度小于5,则不允许退出编辑状态
            if (value.length() < 5)
                e.setCancel(true);
            // 否则,取得$符并退出编辑
else
    tbl.getEditManager().getEditor().setValue(value.substring(1, value.length()));
        }
    }
    
    // 编辑结束后
    public void editStopped(KDTEditEvent e) {
        System.out.println("editStopped");
    }
});

    BeforeActionListener事件

这个事件在table增删行列以及copy、paste、cut时触发,通过设置事件参数的返回值可以取消相应的动作。
// 给table设置action
table.setBeforeAction(new TableBeforeAction());
// action的实现
    class TableBeforeAction implements BeforeActionListener
    {       
        /**
         *@see com.kingdee.bos.ctrl.kdf.table.event.BeforeActionListener#beforeAction(com.kingdee.bos.ctrl.kdf.table.event.BeforeActionEvent)
         */
        public void beforeAction(BeforeActionEvent e)
        {
            // 添加行
            if (e.getType() == BeforeActionEvent.ACTION_ADD_ROW)
            {
                // 获取插入行的位置
                int rowIndex = ((Integer)e.getParameter()).intValue();
                
                if (rowIndex > 5)
                {
                    WindowUtil.msgboxInfo("不能添加行", "title", table);
                    
                    // 取消动作
                    e.setCancel(true);
                }
            }
            // 添加列
            else if (e.getType() == BeforeActionEvent.ACTION_ADD_COLUMN)
            {
                int colIndex = ((Integer)e.getParameter()).intValue();
                
                if (colIndex > 3)
                {
                    WindowUtil.msgboxInfo("不能添加列", "title", table);
                    
                    // 取消动作
                    e.setCancel(true);
                }
            }
            // paste
            else if (e.getType() == BeforeActionEvent.ACTION_PASTE)
            {
                // 获取paste的项
                int mark = ((Integer)e.getParameter()).intValue();
                
                // 如果paste项中包含userObject,则
                if (KDTEditHelper.isUserObject(mark))
                {
                    WindowUtil.msgboxInfo("paste", "title", table);
                    
                    // paste除userObject外的内容
                    table.getEditHelper().paste(KDTEditHelper.STYLE | KDTEditHelper.VALUE | KDTEditHelper.FORMULA);
                    // 取消动作
                    e.setCancel(true);
                }
            }
            // cut
            else if (e.getType() == BeforeActionEvent.ACTION_CUT)
            {
                // 获取cut的项
                int mark = ((Integer)e.getParameter()).intValue();
                
                // 如果cut项中包含userObject,则
                if (KDTEditHelper.isUserObject(mark))
                {
                    WindowUtil.msgboxInfo("cut", "title", table);
                    
                    // cut除userObject外的内容
                    table.getEditHelper().paste(KDTEditHelper.STYLE | KDTEditHelper.VALUE | KDTEditHelper.FORMULA);
                    
                    // 取消动作
                    e.setCancel(true);
                }
            }
        }
       }

原文地址:https://www.cnblogs.com/luojiabao/p/10963822.html