简体   繁体   English

如何使用ISecurePreferences初始化首选项页面字段?

[英]How to initialize preference page fields using ISecurePreferences?

I want to use ISecurePreferences instead of normal IPreferenceStore and the problem occurs when I'm trying to update the fields with stored values. 我想使用ISecurePreferences代替普通的IPreferenceStore,并且在尝试使用存储的值更新字段时出现问题。

I don't find a method other than performOk, performApply, performDefaults, performCancel, and performHelp that runs in the UI thread in order to update the fields with the stored values. 我找不到在UI线程中运行的performOk,performApply,performDefaults,performCancel和performHelp以外的方法,以便使用存储的值更新字段。

Currently I'm doing this using asyncExec once I create the fields. 当前,一旦创建字段,我就使用asyncExec进行此操作。

CODE: 码:

@Override
protected void createFieldEditors() {
    // TODO Auto-generated method stub      
    usernameField = new StringFieldEditor("username","Username:",getFieldEditorParent());
    addField(usernameField);
    //Create password field
    passwordField = new StringFieldEditor("password","Password:",getFieldEditorParent()){
        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns);
            getTextControl().setEchoChar('*');
        }
    };      
    addField(passwordField);    
    try{
    ISecurePreferences root = SecurePreferencesFactory.getDefault();
    final ISecurePreferences node = root.node("nodeName");

    System.out.println("Username initialized: "+node.get("username",""));
    System.out.println("Password initialized: "+node.get("password",""));


    Display.getCurrent().asyncExec(new Runnable(){

        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
                usernameField.setStringValue(node.get("username", ""));
                passwordField.setStringValue(node.get("password", ""));
            } catch (StorageException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }               
        }
    });                     
    }
    catch(StorageException ex)
    {
        System.out.println("Exception storage...");
        ex.printStackTrace();
    }
}   

I'm looking for a correct solution in order to update the created fields. 我正在寻找正确的解决方案以更新创建的字段。 Is there a method which runs in UI thread and is called after createFieldEditors ? 是否存在在UI线程中运行并在createFieldEditors之后调用的方法?

Field editors don't support ISecurePreferences . 字段编辑器不支持ISecurePreferences They will try and load and save the preference values in the normal preference store which may cause errors (especially if you have not set one). 他们将尝试将优先级值加载并保存到普通优先级存储中,这可能会导致错误(尤其是如果您未设置一个)。

So using field editors is not gaining you anything. 因此,使用字段编辑器不会给您带来任何好处。 It is probably simpler just to use an ordinary preference page rather than a field editor preference page and use normal controls like Text , Button , .... 仅使用普通的首选项页面而不是字段编辑器首选项页面并使用诸如TextButton ,...之类的常规控件可能会更简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM