zoukankan
html css js c++ java
给自定义Dialog加入保留对话框值的功能
给自定义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
==
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文件。当然你也可以利用程序来实现。
运行一下看看吧,是不是记住了上次填入的内容.
SourceCODE
查看全文
相关阅读:
svn中trunk、branches、tags
支付宝支付对接过程
分享插件
ES6学习笔记
VS code
Angular45
React笔记
查询Table name, Column name, 拼接执行sql文本, 游标, 存储过程, 临时表
通过脚本把远程服务器上的表和数据拷贝到本地数据库
mongo客户端mongo VUE增删改查
原文地址:https://www.cnblogs.com/kentyshang/p/858307.html
最新文章
C/C++基础知识总结
SVN命令行使用总结
Linux(CentOS)搭建SVN服务器
SVN使用总结
django 2 ORM操作 ORM进阶 cookie和session 中间件
django 1
django
python 使微信自动回复
前端
mysql
热门文章
python笔记9 线程进程 threading多线程模块 GIL锁 multiprocessing多进程模块 同步锁Lock 队列queue IO模型
python笔记8 socket(TCP) subprocess模块 粘包现象 struct模块 基于UDP的套接字协议
安卓打包apk
python笔记7 logging模块 hashlib模块 异常处理 datetime模块 shutil模块 xml模块(了解)
IIS文件上传大小
生成视图重新编译的指令
04 vue
03 vue组件技术
02 vue数据绑定与指令
01 vue语法基础
Copyright © 2011-2022 走看看