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
查看全文
相关阅读:
MySQL百万级、千万级数据多表关联SQL语句调优
不就是SELECT COUNT语句吗,居然有这么多学问
分布式锁讲解
Java 中堆和栈的区别
Java中的回调机制
在Eclipse上Maven环境配置使用
项目忽然出现 The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 解决方法
HttpServletResponse
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
深入浅出java常量池
原文地址:https://www.cnblogs.com/kentyshang/p/858307.html
最新文章
Sourcetree 集成 Azure DevOps Server(Git)
在Git中设置自己的姓名
制作Visual Studio 2019 (VS 2019) 离线安装包
Azure DevOps Server(TFS): 在Excel中解除服务器同步
在Azure DevOps Server(TFS系统)中部署回退/回滚方案(Rollback)
受邀参加北京某企业组织的一次研发流程沟通
分享Azure DevOps技术,来微信群吧!
使用TheFolderSpy监控文件夹的变化-邮件通知
还原Azure DevOps Server (TFS)中误删除的生成流水线
在Azure DevOps Server的代理服务器安装Python环境
热门文章
Mysql实战45讲 06讲全局锁和表锁:给表加个字段怎么有这么多阻碍 极客时间 读书笔记
Mysql实战45讲 05讲深入浅出索引(下)极客时间 读书笔记
mysql实战45讲读书笔记(二) 一条SQL更新语句是如何执行的 极客时间
mysql实战45讲 (三) 事务隔离:为什么你改了我还看不见 极客时间读书笔记
mysql实战45讲读书笔记(一) 一条SQL查询语句是如何执行的
进程间通信-管道
linux进程控制函数详解
环境变量详解
Linux进程精讲
su和sudo的区别与使用,su命令,linux命令
Copyright © 2011-2022 走看看