Find Datatypes

I like reusing/extending data types that already exist, however it is not always easy to find them. The following job lets you search the existing data types for a keyword:

static void findEDT(Args _args)
{
    #AOT
    Dialog              dialog = new Dialog('Find EDT');
    SearchString        searchString;
    DialogField         dialogField = dialog.addField('SearchString');
    boolean             stopAfterFound;
    void searchNodes(boolean _extendedDataTypes)
    {
        TreeNode            treeNode;
        TreeNodeIterator    treeNodeIterator;
        SysDictType         sysDictType;
        SysDictEnum         sysDictEnum;
        Boolean             found;
        ;
        if(_extendedDataTypes)
        {
            treeNode = TreeNode::findNode(#ExtendedDataTypesPath);
        }
        else
        {
            treeNode = TreeNode::findNode(#BaseEnumsPath);
        }
        treeNodeIterator = treenode.AOTiterator();
        treeNode = treeNode.AOTfirstChild();
        treeNode = treeNodeIterator.next();
        while(treeNode)
        {
            if(treeNode.treeNodeName() like "*" + searchString + "*")
            {
                if(_extendedDataTypes)
                {
                    sysDictType = sysDictType::newTreeNode(treeNode);
                }
                if(sysDictType)
                {
                    if (sysDictType.extend() && sysDictType.enumId())
                    {
                        info(strfmt("%1 (%2 - %3 -> %4)",treeNode.treeNodeName(), sysDictType.baseType()
                            , extendedTypeId2name(sysDictType.extend()), enumId2Name(sysDictType.enumId()) ));

                    }
                    if(sysDictType.extend())
                    {
                        info(strfmt("%1 (%2 - %3)",treeNode.treeNodeName(), sysDictType.baseType()
                            , extendedTypeId2name(sysDictType.extend()) ));

                    }
                    else if (sysDictType.enumId())
                    {
                        info(strfmt("%1 (%2 - %3)",treeNode.treeNodeName(), sysDictType.baseType()
                            , enumId2Name(sysDictType.enumId()) ));

                    }
                    else
                    {
                        info(strfmt("%1 (%2)",treeNode.treeNodeName(), sysDictType.baseType()));
                    }
                }
                else
                {
                    info(strfmt("%1",treeNode.treeNodeName()));
                }
                found = true;
            }
            else if(stopAfterFound && found)
            {
                return;
            }
            treeNode = treeNodeIterator.next();
        }
    }
    ;
    if(dialog.run())
    {
        searchString = dialogField.value();
        if(!strScan(searchString, "*", 1, 999)) //no "*"
        {
            searchString = "*" + searchString + "*";
        }
        else if(strKeep(searchString,"*") == "*" && subStr(searchString,strLen(searchString),1)=="*") //just one final "*": beginns with
        {
            stopAfterFound = true;
        }
        info(strfmt("Find %1",searchString));
        if(searchString)
        {
            setPrefix('Extended Data Types');
            searchNodes(true);
            setPrefix('Base Enums');
            searchNodes(false);
        }
    }
}

Update: slight improvement “stopAfterFound”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s