关于属性页的使用

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

 

   <extension
         point="org.eclipse.ui.propertyPages">
      <page
            class="com.unutrip.plugin.dev.properties.SamplePropertyPage"
            id="com.unutrip.plugin.dev.properties.samplePropertyPage"
            name="自定义属性页"
            nameFilter="*.*"
            objectClass="com.unutrip.plugin.dev.model.Person">
      </page>
   </extension>

 

 

samplePropertyPage代码如下:

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();
			}
		};

 

你可能感兴趣的:(eclipse,xml,UI)