EAS BOS 代码获取DEP添加的控件

import java.awt.Component;
import java.awt.Container;
import java.util.Hashtable;
import com.kingdee.bos.ctrl.extendcontrols.KDBizPromptBox;
import com.kingdee.bos.ctrl.swing.KDTextField;
private KDBizPromptBox prmtTestF7 = null;
private KDTextField txtText = null;

// 获取DEP界面所添加字段控件对象
private void getDEPWidget() {
    Hashtable uiTable = new Hashtable();
    //通过控件的名称和所属的界面对象来获取dep新增的控件对象
    findComponent(this, new String[] {"prmtTestF7", "txtText"}, uiTable);
    if (uiTable.size() > 0) {
        Object obj1 = uiTable.get("prmtTestF7");
        if (obj1 != null) {
            if (obj1 instanceof KDBizPromptBox) {
                prmtTestF7 = (KDBizPromptBox) obj1;
                ...
                ...
            }
        }
        
        Object obj2 = uiTable.get("txtText");
        if (obj2 != null) {
            if (obj2 instanceof KDTextField ) {
                txtText = (KDTextField) obj2;
                ...
                ...
            }
        }

        //其他类型控件获取方法类似
    }
}

/**
*遍历comp界面的控件
*/
public static void findComponent(Component comp, String[] controls, Hashtable<String, Component> found) {
    Container con = null;
    boolean nameEquals = false;
    String CompName = null;
    if (comp instanceof Container) {
        CompName = comp.getName();
        if (CompName != null) {
            for (int i = 0; i < controls.length; i++) {
                if (CompName.equals(controls[i])) {
                    if (!found.containsKey(CompName)) {
                        found.put(CompName, comp);
                        nameEquals = true;
                        break;
                    }
                }
            }
        }

        if (found.size() != controls.length) {
            con = (Container) comp;
            int count = con.getComponentCount();

            for (int i = 0; i < count; i++) {
                findComponent(con.getComponent(i), controls, found);
                if (found.size() == controls.length)
                    return;
            }
        }
    }        
}

猜你喜欢

转载自blog.csdn.net/qq_25170493/article/details/82700773