<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    DANCE WITH JAVA

    開發出高質量的系統

    常用鏈接

    統計

    積分與排名

    好友之家

    最新評論

    給自定義Dialog加入保留對話框值的功能

    有的時候我們需要這樣的功能,記下Dialog中的值,當再次打開這個Dialog的時候,還原這些值。這就需要把這些Dialog的值保存起來。Dialog的IDialogSettings類提供了這個功能。下邊是使用方法:
    在上例"自定義Dialog"的代碼上加入三個函數:
    public void saveState(){
            
    if (text.getText() == null || text.getText().equals("")){
                
    return ;
            }

            IDialogSettings topSettings 
    = getTopSettings();
            IDialogSettings settings 
    =  topSettings.getSection("TestDialog");
            
    if(settings == null)settings = topSettings.addNewSection("TestDialog");
            settings.put(
    "value", text.getText());
            
    try{
                topSettings.save(
    "content/system.xml");
            }
    catch(IOException e){
                System.out.println(e.getMessage());
            }

        }

        
    public void restoreState(){
            IDialogSettings topSettings 
    = getTopSettings();
            IDialogSettings settings 
    =  topSettings.getSection("TestDialog");
            
    if(settings == nullreturn;
            
    if (text.getText() == null || text.getText().equals("")){
                text.setText(settings.get(
    "value"));
            }

        }

        
    public IDialogSettings getTopSettings(){
            IDialogSettings topSettings 
    = new DialogSettings("system");
            
    try{
                topSettings.load(
    "content/system.xml");
            }
    catch(IOException e){
                System.out.println(e.getMessage());
            }

            
    return topSettings;
        }

    然后在覆寫的buttonPressed函數中調用save
    protected void buttonPressed(int button){
            saveState();
        }
    在createDialogArea函數中加入取出數據
    protected Control createDialogArea(Composite parent) {
            Composite container 
    = (Composite) super.createDialogArea(parent);
            container.setLayout(
    new RowLayout());
            text 
    = new Text(container, SWT.BORDER);
            text.setLayoutData(
    new RowData(100,-1));
            
    //加入這一句
            if (text.getText() == null || text.getText().equals("")){
                restoreState();
            }

            
    return container;
        }
    最后,記得建立需要的文件,在當前workspace下建立文件夾content,然后在文件夾下建立system.xml文件。當然你也可以利用程序來實現。
    運行一下看看吧,是不是記住了上次填入的內容.
    source下載:http://www.tkk7.com/Files/dreamstone/jface-record.rar

    posted on 2007-08-09 18:13 dreamstone 閱讀(2541) 評論(1)  編輯  收藏 所屬分類: SWT和插件開發

    評論

    # re: 給自定義Dialog加入保留對話框值的功能 2007-10-25 06:34 QuandeLiu

    謝謝你,寫的非常好 .

    簡單易懂,又很實用  回復  更多評論   

    主站蜘蛛池模板: 亚洲一区二区观看播放| 亚洲三级电影网址| 豆国产96在线|亚洲| 无码免费午夜福利片在线| 亚洲国产成人在线视频| 亚洲大片免费观看| 亚洲综合亚洲国产尤物| 97国产免费全部免费观看| 亚洲国产精品线观看不卡| 欧洲精品成人免费视频在线观看| 亚洲一线产区二线产区精华| 亚洲精品中文字幕麻豆| 67194国产精品免费观看| 亚洲高清无在码在线无弹窗| 中文字幕免费视频| 亚洲色在线无码国产精品不卡| 18禁超污无遮挡无码免费网站国产 | 久久久久久夜精品精品免费啦| 亚洲精品人成在线观看| 99久久综合国产精品免费| 亚洲熟妇无码AV| 亚洲AV无码不卡在线观看下载| 二个人看的www免费视频| 亚洲日本一区二区| 成人无码区免费A片视频WWW| 毛片亚洲AV无码精品国产午夜| 亚洲精品成人片在线观看| 亚洲日韩在线观看免费视频| 亚洲日本一区二区| 日本黄色免费观看| 国产精品亚洲精品| 99re热免费精品视频观看| 久久精品亚洲日本波多野结衣| 不卡精品国产_亚洲人成在线| 久久免费线看线看| 中文字幕 亚洲 有码 在线| 亚洲?V无码乱码国产精品| 亚洲综合小说另类图片动图| 亚洲精品视频免费| 久久成人国产精品免费软件| 99亚洲精品卡2卡三卡4卡2卡|