本文介绍了Eclipse CDT:如何写入.cproject文件并回读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实现AbstractCPropertyTab的类具有复选框,并且这些的名称和布尔状态应该是保存到.cproject。
解决方案
我解决了自己的问题。也许有人认为这是有用的。
我将介绍两种方法:一种用于保存表上复选框的检查状态,另一种用于初始化复选框。
/ **
*保存包的检查状态。
* /
private void saveChecked(){
ICConfigurationDescription desc = getResDesc()。getConfiguration();
ICStorageElement strgElem = null;
try {
strgElem = desc.getStorage(PACKAGES,true);
} catch(CoreException e){
e.printStackTrace();
}
TableItem [] items = pkgCfgViewer.getTable()。getItems();
for(TableItem item:items){
if(item!= null){
String chkd;
if(item.getChecked()){
chkd =true;
} else {
chkd =false;
}
try {
String pkgName = item.getText();
strgElem.setAttribute(pkgName,chkd);
} catch(异常e){
/ *
* INVALID_CHARACTER_ERR:指定无效或
*非法的XML字符。
* /
}
}
}
}
/ **
*初始化包的检查状态存储。
* /
private void initializePackageStates(){
ICConfigurationDescription desc = getResDesc()。getConfiguration();
ICStorageElement strgElem = null;
try {
strgElem = desc.getStorage(PACKAGES,true);
} catch(CoreException e){
e.printStackTrace();
}
TableItem [] items = pkgCfgViewer.getTable()。getItems();
for(TableItem item:items){
String value = strgElem.getAttribute(item.getText());
if(value!= null){
if(value.equals(true)){
item.setChecked(true);
}
}
}
}
How to write programmatically to .cproject file and read back (in Eclipse CDT)?
A class implementing AbstractCPropertyTab has checkboxes and name and boolean state of these should be saved to .cproject.
解决方案
I solved my own question. Maybe someone finds this useful.
I will introduce two methods: one for saving checked state of the checkboxes on the table and one to initialize the checkbox values.
/**
* Saves checked state of the packages.
*/
private void saveChecked() {
ICConfigurationDescription desc = getResDesc().getConfiguration();
ICStorageElement strgElem = null;
try {
strgElem = desc.getStorage(PACKAGES, true);
} catch (CoreException e) {
e.printStackTrace();
}
TableItem[] items = pkgCfgViewer.getTable().getItems();
for(TableItem item : items) {
if(item != null) {
String chkd;
if(item.getChecked()) {
chkd = "true";
} else {
chkd = "false";
}
try {
String pkgName = item.getText();
strgElem.setAttribute(pkgName, chkd);
} catch (Exception e) {
/*
* INVALID_CHARACTER_ERR: An invalid or
* illegal XML character is specified.
*/
}
}
}
}
/**
* Initializes the check state of the packages from the storage.
*/
private void initializePackageStates() {
ICConfigurationDescription desc = getResDesc().getConfiguration();
ICStorageElement strgElem = null;
try {
strgElem = desc.getStorage(PACKAGES, true);
} catch (CoreException e) {
e.printStackTrace();
}
TableItem[] items = pkgCfgViewer.getTable().getItems();
for(TableItem item : items) {
String value = strgElem.getAttribute(item.getText());
if(value!=null) {
if(value.equals("true")) {
item.setChecked(true);
}
}
}
}
这篇关于Eclipse CDT:如何写入.cproject文件并回读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!