站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Eclipse 专题GEF,EMF,RCP,Eclipse's plugin的几个问题(3) 让eclipse的properies view实现disabled效果

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

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

由于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);


}



↑返回目录
前一篇: Eclipse3.0的swt编程
后一篇: Eclipse3.1+Lomboz3.1RC1+Tomcat5.5.9编写简单动态网页实践