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

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

系統(tǒng) 1735 0

有的時候我們需要這樣的功能,記下Dialog中的值,當(dāng)再次打開這個Dialog的時候,還原這些值。這就需要把這些Dialog的值保存起來。Dialog的IDialogSettings類提供了這個功能。下邊是使用方法:
在上例"自定義Dialog"的代碼上加入三個函數(shù):

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函數(shù)中調(diào)用save

protected ? void ?buttonPressed( int ?button) {
????????saveState();
????}

在createDialogArea函數(shù)中加入取出數(shù)據(jù)

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;
????}

最后,記得建立需要的文件,在當(dāng)前workspace下建立文件夾content,然后在文件夾下建立system.xml文件。當(dāng)然你也可以利用程序來實(shí)現(xiàn)。
運(yùn)行一下看看吧,是不是記住了上次填入的內(nèi)容.

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


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 南川市| 琼结县| 拉萨市| 云阳县| 南溪县| 得荣县| 白朗县| 汾西县| 仁化县| 德惠市| 秦皇岛市| 镇江市| 宣城市| 禹城市| 南通市| 平谷区| 汉源县| 来宾市| 义乌市| 班玛县| 临清市| 惠水县| 七台河市| 板桥市| 横峰县| 元江| 阳新县| 蓝田县| 襄垣县| 宜良县| 邵东县| 安平县| 泊头市| 昆山市| 临江市| 读书| 宿迁市| 广宗县| 辛集市| 湟源县| 汽车|