【问题标题】:Eclipse CDT: How to write to .cproject file and read backEclipse CDT:如何写入 .cproject 文件并回读
【发布时间】:2011-09-05 09:12:31
【问题描述】:

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

实现 AbstractCPropertyTab 的类具有复选框,它们的名称和布尔状态应保存到 .cproject。

【问题讨论】:

    标签: java eclipse plugins eclipse-cdt


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 2013-09-21
      相关资源
      最近更新 更多