Last active
January 2, 2016 00:39
-
-
Save DinisCruz/8225438 to your computer and use it in GitHub Desktop.
Misc Eclipse SWT scripts
This file contains hidden or 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
| import org.eclipse.swt.*; | |
| import org.eclipse.swt.events.*; | |
| import org.eclipse.swt.widgets.*; | |
| def e = new Event(); | |
| e.type = SWT.MouseMove | |
| for(int i : 1..50) | |
| { | |
| e.x = 100 + i * 10; | |
| e.y = 200 + i; | |
| eclipse.display.post(e); | |
| Thread.sleep(10) | |
| } | |
| return | |
| return e; | |
| return SWT.MouseMove |
This file contains hidden or 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
| executing Javascript code from Groovy plugin | |
| def scriptManager = new javax.script.ScriptEngineManager() | |
| def engine = scriptManager.getEngineByName("JavaScript"); | |
| def javascript = """ | |
| var newTitle = 'This was executed from Javascript ....'; | |
| var workbench = org.eclipse.ui.PlatformUI.getWorkbench(); | |
| var shell = workbench.getActiveWorkbenchWindow().getShell() | |
| function setText() | |
| { | |
| shell.text= newTitle; | |
| } | |
| setText(); | |
| shell; | |
| """ | |
| return engine.eval(javascript) |
This file contains hidden or 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
| import tm.eclipse.ui.pluginPreferences.pages.*; | |
| import org.eclipse.swt.*; | |
| import org.eclipse.swt.widgets.*; | |
| final def propertyPage = new MainPreferences(); | |
| //def propertyPage = new Config(); | |
| def viewId = "test login preferences_2"; | |
| eclipseUI.add_View(viewId).close() | |
| def view = eclipseUI.add_View(viewId); | |
| propertyPage.control = view.composite; | |
| propertyPage.createContents(view.composite) | |
| def text = propertyPage.username_Text; | |
| text.addListener(SWT.Verify, new Listener() | |
| { | |
| public void handleEvent(Event e) { | |
| String string = e.text; | |
| char[] chars = new char[string.length()]; | |
| string.getChars(0, chars.length, chars, 0); | |
| for (int i = 0; i < chars.length; i++) { | |
| if (!('0' <= chars[i] && chars[i] <= '9')) { | |
| e.doit = false; | |
| return; | |
| } | |
| } | |
| } | |
| }); | |
| return text |
This file contains hidden or 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
| import org.eclipse.jface.resource.ImageDescriptor; | |
| import org.eclipse.jface.viewers.ITreeContentProvider; | |
| import org.eclipse.jface.viewers.LabelProvider; | |
| import org.eclipse.jface.viewers.Viewer; | |
| def viewId = "file browser 23" | |
| def view = eclipseUI.add_View(viewId); | |
| view.clear() | |
| def treeViewer = view.add.treeViewer(); | |
| class ViewContentProvider implements ITreeContentProvider { | |
| public void inputChanged(Viewer v, Object oldInput, Object newInput) { | |
| } | |
| @Override | |
| public void dispose() { | |
| } | |
| @Override | |
| public Object[] getElements(Object inputElement) { | |
| return (File[]) inputElement; | |
| } | |
| @Override | |
| public Object[] getChildren(Object parentElement) { | |
| File file = (File) parentElement; | |
| return file.listFiles(); | |
| } | |
| @Override | |
| public Object getParent(Object element) { | |
| File file = (File) element; | |
| return file.getParentFile(); | |
| } | |
| @Override | |
| public boolean hasChildren(Object element) { | |
| File file = (File) element; | |
| if (file.isDirectory()) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| } | |
| class ViewLabelProvider extends LabelProvider { | |
| @Override | |
| public String getText(Object element) { | |
| File file = (File) element; | |
| String name = file.getName(); | |
| return name.isEmpty() ? file.getPath() : name; | |
| } | |
| } | |
| treeViewer.setContentProvider(new ViewContentProvider()); | |
| treeViewer.setLabelProvider(new ViewLabelProvider()); | |
| treeViewer.setInput(File.listRoots()); | |
| view.refresh(); | |
| return treeViewer |
This file contains hidden or 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
| import org.eclipse.swt.*; | |
| import org.eclipse.jface.resource.ImageDescriptor; | |
| import org.eclipse.jface.viewers.ITreeContentProvider; | |
| import org.eclipse.jface.viewers.LabelProvider; | |
| import org.eclipse.jface.viewers.Viewer; | |
| import org.eclipse.jface.fieldassist.*; | |
| import org.eclipse.swt.layout.*; | |
| def viewId = "test ControlDecoration 1" | |
| def view = eclipseUI.add_View(viewId); | |
| view.clear() | |
| view.set.layout_Grid(2) | |
| view.add.label("Text to the right should have a ControlDecoration"); | |
| def image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage() | |
| def text = view.add.text("some text"); | |
| def gridData = new GridData(SWT.FILL , SWT.CENTER, true,false); | |
| gridData.horizontalIndent = 8; | |
| text.setLayoutData(gridData); | |
| def deco = new ControlDecoration(text,SWT.TOP | SWT.LEFT) | |
| deco.setDescriptionText("this is a decoration"); | |
| deco.setImage(image); | |
| deco.setShowOnlyOnFocus(false); | |
| deco.marginWidth = 2; | |
| deco.show(); | |
| //inspect(deco) | |
| view.add.button("a new button"); | |
| view.add.text("another text") | |
| view.refresh(); | |
| return deco |
This file contains hidden or 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 viewId = "test ControlDecoration 1" | |
| def view = eclipseUI.add_View(viewId); | |
| view.clear() | |
| view.set.layout_Grid(2) | |
| view.add.button("a new button"); | |
| view.add.text("another text") | |
| view.add.label("Text to the right should have a ControlDecoration"); | |
| def text = view.add.text("some text").fill_Horizontal(); | |
| text.controlDecoration_Set("This is an error message", true); //true shows with error icon (vs info icon) | |
| text.controlDecoration_Hide(); | |
| Thread.sleep(1000); | |
| text.controlDecoration_Show(); | |
| //view.refresh(); | |
| return "done" |
This file contains hidden or 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 viewId = "test ControlDecoration 1" | |
| def view = eclipseUI.add_View(viewId); | |
| view.clear() | |
| view.set.layout_Grid(2) | |
| view.add.label("Text with valid URL:"); | |
| def text = view.add.text().fill_Horizontal(); | |
| text.controlDecoration_Validate_Url("You must enter a valid URL") | |
| return "done" | |
| //Config:UIThread_False |
This file contains hidden or 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
| import tm.eclipse.ui.pluginPreferences.pages.*; | |
| def propertyPage = new MainPreferences(); | |
| //def propertyPage = new Config(); | |
| def viewId = "test login preferences_2"; | |
| eclipseUI.add_View(viewId).close() | |
| def view = eclipseUI.add_View(viewId); | |
| eclipseUI.syncExec( new Runnable() | |
| { | |
| public void run() { | |
| propertyPage.control = view.composite; | |
| propertyPage.createContents(view.composite) | |
| } | |
| }); | |
| view.mouse.GLIDE_DELAY_MILISECONDS = 10 | |
| view.mouse.GLIDE_DELAY_STEP=5 | |
| view.refresh(); | |
| eclipseUI.syncExec( new Runnable() | |
| { | |
| public void run() | |
| { | |
| def controls = propertyPage.control.children[0].children[3].children; | |
| //inspect(controls[3]) | |
| //inspect(controls[5]) | |
| // return controls[3].children[1].toDisplay(1, 1) | |
| for(def control : controls) | |
| { | |
| def position = control.toDisplay(1, 1) | |
| view.mouse.glide(position); | |
| Thread.sleep(200); | |
| } | |
| }}) | |
| return "done"; |
This file contains hidden or 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
| import tm.eclipse.ui.pluginPreferences.pages.*; | |
| def propertyPage = new MainPreferences(); | |
| //def propertyPage = new Config(); | |
| def viewId = "test login preferences_2"; | |
| eclipseUI.add_View(viewId).close() | |
| def view = eclipseUI.add_View(viewId); | |
| eclipseUI.syncExec( new Runnable() | |
| { | |
| public void run() { | |
| propertyPage.control = view.composite; | |
| propertyPage.createContents(view.composite) | |
| } | |
| }); | |
| view.refresh(); | |
| view.mouse.glide(propertyPage.authenticate_Button) | |
| .moveBy(20,10) | |
| .click(); | |
| return "done"; | |
| // code that does the click | |
| public Mouse click() | |
| { | |
| click(SWT.MouseDown,1); | |
| sleep(MOUSE_CLICK_DELAY); | |
| click(SWT.MouseUp,1); | |
| return this; | |
| } | |
| public Mouse click(final int type, final int button) | |
| { | |
| UIThreadRunnable.syncExec(display, new VoidResult() { public void run() | |
| { | |
| Event e = new Event(); | |
| e.type = type; | |
| e.button = button; | |
| display.post(e); | |
| }}); | |
| return this; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment