日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

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

系統 1838 0

有的時候我們需要這樣的功能,記下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? == ? null )? return ;
????????
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文件。當然你也可以利用程序來實現。
運行一下看看吧,是不是記住了上次填入的內容.

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


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 乐山市| 陈巴尔虎旗| 房产| 和平县| 星座| 嘉定区| 沁阳市| 临城县| 财经| 夏津县| 大丰市| 米泉市| 吉木乃县| 峨山| 红桥区| 兴安县| 洮南市| 沙雅县| 丰顺县| 松原市| 怀宁县| 八宿县| 桐城市| 永春县| 仲巴县| 隆尧县| 崇文区| 银川市| 临沧市| 定西市| 石景山区| 平罗县| 肇庆市| 新津县| 易门县| 岳池县| 三门峡市| 三明市| 鹤庆县| 德安县| 江阴市|