有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaEclipseCDT:如何编写。cproject文件并读回

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

实现AbstractCPropertyTab的类具有复选框,这些复选框的名称和布尔状态应保存到。C项目


共 (1) 个答案

  1. # 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);
                }
            }
        }
    }