Groovy脚本
import com.intellij.database.model.DasTable
import com.intellij.database.model.ObjectKind
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil
import com.intellij.database.psi.DbColumn;
FILES.chooseDirectoryAndSave("Choose directory", "Choose where to store generated files") { dir ->
def schemaMap = new LinkedHashMap<String,Map<String,String>>();
SELECTION.filter { (it.getKind() == ObjectKind.TABLE || it.getKind() == ObjectKind.SCHEMA) }.each {
def schemaName = DasUtil.getSchema(it);
if(!schemaMap.containsKey(schemaName)){
schemaMap.put(schemaName,new LinkedHashMap<String,String>());
}
LOG.print("SELECTION type:"+it.getKind());
if(it.getKind() == ObjectKind.TABLE){
def tableName = it.getName();
if(!schemaMap.get(schemaName).containsKey(tableName)){
schemaMap.get(schemaName).put(tableName,generateTableHTMLStyle(it));
}
}else if(it.getKind() == ObjectKind.SCHEMA){
LOG.print("DasChildren:"+it.getDasChildren(ObjectKind.TABLE));
it.getDasChildren(ObjectKind.TABLE).each { table ->
def tableName = table.getName();
if(!schemaMap.get(schemaName).containsKey(tableName)){
schemaMap.get(schemaName).put(tableName,generateTableHTMLStyle(table));
}
}
}
}
def outlineHtml = '';
def tableHtml = '';
LOG.print("schemaMap:"+schemaMap);
schemaMap.each { schema ->
outlineHtml += '<div id="_ul">';
outlineHtml += '<a href="#'+schema.key+'">'+schema.key+'</a>';
outlineHtml += ' <div id="_ul">';
tableHtml += '<h2 id="'+schema.key+'"><a class="anchor" name="'+schema.key+'" href="#'+schema.key+'"><span class="octicon octicon-link"></span></a>'+schema.key+'</h2>';
schema.value.each { t ->
outlineHtml += '<a href="#'+(schema.key+'.'+t.key)+'">'+(schema.key+'.'+t.key)+'</a>';
tableHtml += (t.value);
}
outlineHtml += ' </div>';
outlineHtml += '</div>';
};
def styleCss = '@font-face{font-family: octicons-link; src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAZwABAAAAAACFQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEU0lHAAAGaAAAAAgAAAAIAAAAAUdTV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