java - Eclipse CDT : How to write to . cproject 文件并读回

标签 java eclipse plugins eclipse-cdt

如何以编程方式写入 .cproject 文件并读回(在 Eclipse CDT 中)?

实现 AbstractCPropertyTab 的类具有复选框,并且这些复选框的名称和 boolean 状态应保存到 .cproject。

最佳答案

我解决了我自己的问题。也许有人觉得这很有用。

我将介绍两种方法:一种用于保存表格上复选框的选中状态,另一种用于初始化复选框值。

/**
 * 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);
            }
        }
    }
}

关于java - Eclipse CDT : How to write to . cproject 文件并读回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6186185/

相关文章:

java - 在Eclipse中,使用另一种数据类型定义一种数据类型,只有后一个测试客户端main()运行,如何只运行第一个?

android - "fatal error: Eigen/Dense: No such file or directory"//特征库

api - Windows Live Mesh 提供程序设置同步;我可以添加对我的软件的支持吗?

jquery - 覆盖 jQuery 插件方法,默认情况下和单个实例

java - G1 的 Android 设备更新

java - Monotouch 上的 IKVM 是受支持/经过测试的 VM 部署吗?

eclipse - 如何在 Eclipse 中使用现有的 .target 文件?

javascript - 使用 JavaScript 在 Dynamics CRM 中检索法语翻译

java - JTable - 复选框添加 Action 监听器

java - 从角落绘制图像的某些部分偏移?