Created
October 15, 2011 14:40
-
-
Save hokorobi/1289656 to your computer and use it in GitHub Desktop.
アイコンの付いているノードからテキストを持ってきて、アイコンノードに展開
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rootNode = getRootNode(node); | |
def iconMaps = [:]; | |
iconMaps = getIcons(rootNode, iconMaps); | |
createTodo(iconMaps, rootNode); | |
def createTodo(map, rootNode) { | |
map.each { key ,value -> | |
keyNode = createFirstNode(rootNode, key); | |
value.each { | |
createFirstNode(keyNode, it) | |
} | |
} | |
} | |
def createFirstNode(node, text) { | |
def firstNode; | |
node.children.each { | |
if (it.getText() == text) { | |
firstNode = it; | |
} | |
} | |
if (firstNode) { | |
return firstNode; | |
} else { | |
return node.createChild(text); | |
} | |
} | |
def getIcons(node, map) { | |
node.children.each { | |
if (it.icons.getFirst() != null) { | |
println it.icons.getFirst(); | |
map = addMap(map, it.icons.getFirst(), it.getText()); | |
} | |
if (node.children.size != 0) { | |
map = getIcons(it, map); | |
} | |
} | |
return map; | |
} | |
def addMap(map, icon, text) { | |
if (map[icon]) { | |
map[icon] = map[icon] + text; | |
println(map[icon]); | |
} else { | |
map[icon] = [text]; | |
println map[icon]; | |
} | |
return map; | |
} | |
def getRootNode(node) { | |
if (node.isRoot()) { | |
return node; | |
} else { | |
return getRootNode(node.getParentNode()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment