RCP中关于可选项(preferencePages)的使用

 在plugin.xml中添加preferencePages的相关配置:

自定义属性的配置:

 

   <extension
         point="org.eclipse.ui.preferencePages">
      <page
            class="com.vnvntrip.plugin.dev.preferences.CustomPreferencePage"
            id="com.vnvntrip.plugin.dev.preferences.CustomPreferencePage"
            name="Custom Preferences">
      </page>
   </extension>

 关于可选项中默认信息的加载必须实现一个AbstractPreferenceInitializer的类:

  plugin.xml中配置:

 

   <extension
         point="org.eclipse.core.runtime.preferences">
      <initializer
            class="com.vnvntrip.plugin.dev.preferences.PreferenceInitializer">
      </initializer>
   </extension>
   

 

  可选项的中初始化页面的方法:

package com.vnvntrip.plugin.dev.preferences;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import com.vnvntrip.plugin.dev.Activator;
/**
 * 初始化时调用此类的加载可选项中数据信息
 */
public class PreferenceInitializer extends AbstractPreferenceInitializer {
 /*
  * 
  * 加载系统中默认的可选的信息可选项的存储中
  * (non-Javadoc)
  * 
  * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
  */
 public void initializeDefaultPreferences() {
             //获取可选项的存储
     IPreferenceStore store = Activator.getDefault().getPreferenceStore();
     //设置各种默认值的信息
      store.setDefault(PreferenceConstants.P_BOOLEAN, true);
      store.setDefault(PreferenceConstants.P_CHOICE, "choice2");
      store.setDefault(PreferenceConstants.P_STRING,
    "Default value");
 }
}

 

使用的可选项的代码:

public class SampleHandler extends AbstractHandler {
    private static String CUSTOMPROPERTYPAGE = "com.vnvntrip.plugin.dev.properties.CustomPropertyPage";

    /**
     * The constructor.
     */
    public SampleHandler() {
    }

    /**
     * the command has been executed, so extract extract the needed information
     * from the application context.
     */
    public Object execute(ExecutionEvent event) throws ExecutionException {
	Shell shell = HandlerUtil.getActiveShell(event);
	// JfaceDialog dialog=new JfaceDialog(shell);
	// dialog.open();
	//WorkbenchPreferenceDialog.createDialogOn(shell, preferencePageId)
	WorkbenchPreferenceDialog dialog = WorkbenchPreferenceDialog
		.createDialogOn(shell, CUSTOMPROPERTYPAGE);
	dialog.showOnly(new String[] { CUSTOMPROPERTYPAGE });
	dialog.open();
	return null;
    }
}

 

 

 

 

 

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