Skip to content

Instantly share code, notes, and snippets.

@tyama
Forked from kiy0taka/MongoConsole.groovy
Created April 10, 2012 03:56
Show Gist options
  • Save tyama/2348225 to your computer and use it in GitHub Desktop.
Save tyama/2348225 to your computer and use it in GitHub Desktop.
@Grab('com.gmongo:gmongo:0.9.5')
@GrabConfig(systemClassLoader=true)
import com.gmongo.GMongo
import com.mongodb.*
import javax.swing.UIManager
import groovy.ui.Console
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ImportCustomizer
import groovy.transform.*
def mongoMenu = {
menu('Mongo') {
menu('Templates') {
menuItem('group')
}
}
}
Console.metaClass.newScript = { ClassLoader parent, Binding binding ->
def config = new CompilerConfiguration()
def importCustomizer = new ImportCustomizer()
importCustomizer.addImports('com.gmongo.GMongo')
config.addCompilationCustomizers(importCustomizer)
binding.mongo = new GMongo()
delegate.shell = new GroovyShell(parent, binding, config)
}
UIManager.lookAndFeel = UIManager.systemLookAndFeelClassName
new Console(Console.class.classLoader.getRootLoader()).run(
Console.frameConsoleDelegates << [menuBarDelegate: {arg->
current.JMenuBar = build(arg)
current.JMenuBar.add(build(mongoMenu))
}]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment