GEF,EMF,RCP,Eclipse's plugin的几个问题(3) 让eclipse的properies view实现disabled效果

因Eclipse自带的TextPropertyDescrptor无disabled属性,实现属性只读较难。本文修改了TextPropertyDescrptor,创建MyTextPropertyDescriptor类,通过设置控件Enabled属性实现只读效果,在IPropertySource继承类中用其替换原描述符。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  由于eclipse自己的TextPropertyDescrptor没有disabled属性,所以,在程序中要求
  实现某个属性只读比较困难(可能是我没有找到:)),所以,修改了一下
  TextPropertyDescrptor,以实现该效果,具体如下:

  package com.companyname.projectname.modulename.model.properties;

  import org.eclipse.jface.viewers.CellEditor;
  import org.eclipse.jface.viewers.TextCellEditor;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.ui.views.properties.TextPropertyDescriptor;

  public class MyTextPropertyDescriptor extends TextPropertyDescriptor {

 private boolean readonly;
 
 public boolean isReadonly() {
  return readonly;
 }

 public void setReadonly(boolean readonly) {
  this.readonly = readonly;
 }

 public MyTextPropertyDescriptor(Object id, String displayName) {
  super(id, displayName);
 }
 
    public CellEditor createPropertyEditor(Composite parent) {
        CellEditor editor = new TextCellEditor(parent);
 //-->这是关键,设置控件的Enabled属性来实现...
        if (this.readonly){
            editor.getControl().setEnabled(false);
        }
 //<--
        if (getValidator() != null)
            editor.setValidator(getValidator());
        return editor;
    }

    其它的PropertyDescriptor类似

    在IPropertySource的继承类中,就用这个MyTextPropertyDescriptor替换原来的
    TextPropertyDescriptor即可:

    PropertyDescriptor descriptor = null;

    descriptor = new MyTextPropertyDescriptor(ID_X, ID_X);
    //设置分类
    descriptor.setCategory("Basic Info");
    descriptors.add(descriptor);


  } 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值