RCP--自定义DialogCellEditor可directEdit

来源:互联网 发布:田岛美工刀片 编辑:程序博客网 时间:2024/06/03 15:13
 

自定义DialogCellEditor可directEdit

Eclipse的DialogCellEditor是由一个Label和一个Button组成的,不能直接进行编辑,必须通过弹出对话框才能编辑和输入,于是我通过继承DialogCellEditor实现自定义控件。

1、首先重载createContents

    @Override
    protected Control createContents(final Composite cell) {
        // return the control on an edit-request
        //this.label = new Label(cell, SWT.NONE);
     //this.setValue(""+12);
     this.text=new Text(cell,SWT.NONE);
     this.text.addFocusListener(new FocusListener(){

   public void focusGained(FocusEvent e) {
    // TODO Auto-generated method stub

   }

   public void focusLost(FocusEvent e) {
    // TODO Auto-generated method stub
    doSetValue(text.getText());
   }

     });
     this.text.addKeyListener(new KeyListener(){

   public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    if(e.keyCode==13){
     doSetValue(text.getText());
    }
   }

   public void keyReleased(KeyEvent e) {
    // TODO Auto-generated method stub

   }

     });
 
        return this.text;
    }
光重载它还不能实现DirectEdit

2、重载doSetFocus()

   @Override
 protected void doSetFocus() {
  // TODO Auto-generated method stub
  if(text!=null){
   text.selectAll();
   text.setFocus();
  }
 }

通过上面步骤可以实现既可以DirectEdit又可通过点击Button弹出对话框实现输入和编辑。

原创粉丝点击