Skip to content

Instantly share code, notes, and snippets.

@DinisCruz
Last active January 2, 2016 11:39
Show Gist options
  • Select an option

  • Save DinisCruz/8297606 to your computer and use it in GitHub Desktop.

Select an option

Save DinisCruz/8297606 to your computer and use it in GitHub Desktop.
Misc SWT Scripts
//based on answer from http://stackoverflow.com/questions/18151679/how-to-programmatically-access-an-eclipse-jdt-tooltip-icon
import org.eclipse.jdt.internal.ui.JavaPluginImages;
def image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_QUICK_ASSIST)
def newView = eclipse.views.create("a button with an image");
def button = newView.add_Button().setImage(image);
return button;
return "ok";
//Config:UIThread__False
import org.eclipse.jdt.ui.JavaUI
def activeEditor = eclipse.editors.active();
def javaCompilationUnit = eclipse.editors.javaCompilationUnit(activeEditor);
//inspect(activeEditor)
def compilationUnit = javaCompilationUnit.compilationUnit();
//inspect(compilationUnit)
def types = javaCompilationUnit.types();
def methods = javaCompilationUnit.methods();
def methodNames = javaCompilationUnit.method_Names();
def view = eclipse.views.create("Execute JUnitTests").clear();
view.layout_Grid();
def button = view.add_Button("execute");
def treeViewer = view.add.treeViewer().gridData_Fill();
for(def methodName in methodNames)
treeViewer.add_Node(methodName);
view.refresh();
def tree = treeViewer.getTree();
tree.setSelection(treeViewer.nodes()[2]);
return treeViewer.getTree().getSelection();
//Config:UIThread__False
import org.eclipse.jdt.ui.JavaUI
def activeEditor = eclipse.editors.active();
def javaCompilationUnit = eclipse.editors.javaCompilationUnit(activeEditor);
//inspect(activeEditor)
def compilationUnit = javaCompilationUnit.compilationUnit();
//inspect(compilationUnit)
def types = javaCompilationUnit.types();
def methods = javaCompilationUnit.methods();
def methodNames = javaCompilationUnit.method_Names();
def view = eclipse.views.create("Execute JUnitTests").clear();
view.layout_Grid();
def button = view.add_Button("execute");
def label = view.add.label("selected method: NA");
def treeViewer = view.add.treeViewer().gridData_Fill();
for(def methodName in methodNames)
treeViewer.add_Node(methodName);
def tree = treeViewer.getTree();
def execute = new Runnable() { public void run()
{
def selectedNode = treeViewer.getTree().getSelection().first();
label.text("executing method : " + selectedNode.text);
}}
treeViewer.onDoubleClick(execute);//.click();
button.onClick(execute)
view.refresh();
tree.setSelection(treeViewer.nodes()[2]);
button.click();
return treeViewer.getTree().getSelection();
import tm.eclipse.swt.controls.*
GroovyExecution groovyExecution = new GroovyExecution();
URL binFolder_TMCode = GroovyExecution.class.getProtectionDomain().getCodeSource().getLocation();
URL binFolder_TMJUnit;
binFolder_TMJUnit = new URL(binFolder_TMCode, "../../TeamMentor.Eclipse.UxTests/bin/");
groovyExecution.addRefToGroovyShell(binFolder_TMJUnit.getPath());
def compilationUnit = eclipse.editors.active_JavaCompilationUnit();
/*def name = "asArray";
def m = compilationUnit.method(name);;
//inspect(m.declaringType)
def tn = m.declaringType.fullyQualifiedName;
def script = String.format("""
return new %s().%s();
""",tn,name);
//groovyExecution.executeScript(script);
//return GroovyExecution.dev_Execute_TM_JUnit(typeName)
//return typeName;
return groovyExecution;
*/
//Config:UIThread__False
import org.eclipse.jdt.ui.JavaUI
def eclipse = eclipse
def view = eclipse.views.create("Execute JUnitTests").clear();
view.layout_Grid();
def loadData_Button = view.add_Button("load data");
def execute_Button = view.add_Button("execute");
def treeViewer = view.add.treeViewer().gridData_Fill();
view.add.label("result:");
def result = Text.add_Text_MultiLine(view.composite,"").fill();; // view.add.text().fill();
def loadData = new Runnable() { public void run()
{
def javaCompilationUnit = eclipse.editors.active_JavaCompilationUnit();
def methodNames = javaCompilationUnit.method_Names();
treeViewer.getTree().removeAll();
for(def methodName in methodNames)
treeViewer.add_Node(methodName);
}};
def tree = treeViewer.getTree();
def execute = new Runnable() { public void run()
{
def javaCompilationUnit = eclipse.editors.active_JavaCompilationUnit();
def selectedNode = treeViewer.getTree().getSelection().first();
def methodName = selectedNode.text;
def method = javaCompilationUnit.method(methodName);
def text = "executing method : " + method + "\n\n";
result.text(text);
def typeName = method.declaringType.fullyQualifiedName;
// text += GroovyExecution.dev_Execute_TM_JUnit(typeName)
def script = String.format("return new %s().%s();",typeName,methodName);
groovyExecution.executeScript(script);
text += "Unit Test OK";
result.text(text);
}}
treeViewer.onDoubleClick(execute);//.click();
execute_Button.onClick(execute)
loadData_Button.onClick(loadData);
view.refresh();
loadData.run();
tree.setSelection(treeViewer.nodes()[2]);
execute_Button.click();
return treeViewer.getTree().getSelection();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment