首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

关于属性页的运用

2012-10-08 
关于属性页的使用? 在RCP应用程序中Plugin.xml配置如下:?extensionpointorg.eclipse.ui.propertyPages

关于属性页的使用

? 在RCP应用程序中Plugin.xml配置如下:

?

   <extension         point="org.eclipse.ui.propertyPages">      <page            name="code">package com.unutrip.plugin.dev.properties;import org.eclipse.jface.preference.PreferencePage;import org.eclipse.swt.SWT;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Text;import org.eclipse.ui.dialogs.PropertyPage;import com.unutrip.plugin.dev.model.Person;/** *  * @author longgangbai * */public class SamplePropertyPage extends PropertyPage {private Text sexText;private Text addrText;private Text ageText;private Text nameText;private Text idText;/** * Constructor for SamplePropertyPage. */public SamplePropertyPage() {super();setDescription("个人详细信息修改");setTitle("个人信息");noDefaultAndApplyButton();}/** * @see PreferencePage#createContents(Composite) */protected Control createContents(Composite parent) {Composite composite = new Composite(parent, SWT.NONE);GridLayout layout = new GridLayout();layout.numColumns=4;composite.setLayout(layout);final Label stuNo=new Label(composite,SWT.NONE);stuNo.setText("学号");idText=new Text(composite,SWT.BORDER);GridData data = new GridData(GridData.FILL,SWT.CENTER,true,false);data.grabExcessHorizontalSpace = true;idText.setLayoutData(data);final Label stuName=new Label(composite,SWT.NONE);stuName.setText("姓名");nameText=new Text(composite,SWT.BORDER);GridData namedata = new GridData(GridData.FILL,SWT.CENTER,true,false);namedata.grabExcessHorizontalSpace = true;nameText.setLayoutData(namedata);final Label stusex=new Label(composite,SWT.NONE);stusex.setText("性别");sexText=new Text(composite,SWT.BORDER);GridData sexdata = new GridData(GridData.FILL,SWT.CENTER,true,false);sexdata.grabExcessHorizontalSpace = true;sexText.setLayoutData(sexdata);final Label addrName=new Label(composite,SWT.NONE);addrName.setText("家庭地址");addrText=new Text(composite,SWT.BORDER);GridData addrdata = new GridData(GridData.FILL,SWT.CENTER,true,false);addrdata.grabExcessHorizontalSpace = true;addrText.setLayoutData(addrdata);updatePersonText();return composite;}protected void performDefaults() {// Populate the owner text field with the default value        super.performDefaults();}public boolean performOk() {return true;}/** * Person sp=(Person)getElement().getAdapter(Person.class); * 这段代码取得数据提供者,通过适配一个Student对象,得到传入到属性页中的对象,然后就填充相应的属性了 */    private void updatePersonText(){     Person sp=(Person)getElement().getAdapter(Person.class);     if(null==sp){      return ;     }     this.idText.setText(sp.getStuNo());     this.ageText.setText(sp.getStuAge());     this.addrText.setText(sp.getStuAddr());     this.nameText.setText(sp.getStuName());     this.sexText.setText(sp.getStuSex());    }}

?在一个TableViewer中点击打开属性页:

doubleClickAction = new Action() {@SuppressWarnings("restriction")public void run() {//获取一个选中的对象ISelection selection = viewer.getSelection();Object obj = ((IStructuredSelection)selection).getFirstElement();//打开属性页面PropertyDialog dialog = PropertyDialog.createDialogOn(getSite().getShell(), "com.unutrip.plugin.dev.properties.SamplePropertyPage", obj);dialog.open();}};

?

热点排行