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
查看全文
相关阅读:
电话号码的字母组合(力扣第17题)
太平洋大西洋水流问题(力扣第417题)
被围绕的区域(力扣第130题)
ZooKeeper的本地安装和分布式安装
朋友圈(力扣第547题)
岛屿数量(力扣第200题)
岛屿的最大面积(力扣第695题)
再论力扣第279题--完全平方数
.net core使用CSRedisCore连接哨兵集群,并用作redis使用分布式缓存。
使用docker搭建reids主从,哨兵。
原文地址:https://www.cnblogs.com/kentyshang/p/858307.html
最新文章
Chrome/Firefox:Selenium启动浏览器,绕过验证码登陆
mooc机器学习第七天-分类支持向量机svm.svc
numpy花式索引与ix_()
详解pandas的read_csv()
mac常见使用
pycharm批量查找与替换快捷键
numpy的shape(0)简单摸索
mooc机器学习第六天-K近邻,决策树,朴素贝叶斯分类器简单尝试
classification_report&精确度/召回率/F1值
python的random简单使用
热门文章
mooc机器学习第五天-分类实例分析(理论)
「LibreOJ NOI Round #2」黄金矿工
0627训练记录
JOISC2020补题记
2020 0626 训练记录
NOI2020联合省选A卷题解
NOI2020联合省选自闭游记
CSP2019-S自闭游记
单词搜索(力扣第79题)
Hive学习----查询操作基础练习
Copyright © 2011-2022 走看看