Eclipse Plugin Development: How to open a TextEditor in java programmatically? - eclipse

IPath path; //has some path
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
IWorkbenchPage page; //get current active page
try {
IJavaElement sourceJavaElement = JavaCore.create(file);
ITextEditor editor = (ITextEditor)JavaUI.openInEditor(sourceJavaElement); //illegal argument exception here
} catch (PartInitException | JavaModelException e1) {
e1.printStackTrace();
}
I am using this code code to open the editor but it gives an illegal argument exception when openInEditor is called on sourceJavaElement.

Related

How to format JSP code in Eclipse with Java SWT?

I'm generating a plugin in Eclipse. My plugin generates source JSP code in an open Editor so I would like to format the whole code, just as if I pressed Ctrl+Shift+F.
I try to do that with Eclipse JDT:
Properties prefs = new Properties();
prefs.setProperty(JavaCore.COMPILER_SOURCE, CompilerOptions.VERSION_1_8);
prefs.setProperty(JavaCore.COMPILER_COMPLIANCE, CompilerOptions.VERSION_1_8);
prefs.setProperty(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_8);
CodeFormatter formatter = ToolFactory.createCodeFormatter(prefs);
String texto2 = texto;
IDocument dc = new Document(texto2);
//ICompilationUnit cu = (ICompilationUnit)JavaCore.create(texto_editor);
TextEdit edit_formatear =
formatter.format(CodeFormatter.K_COMPILATION_UNIT,
texto2, 0, texto2.length(), 0, null);
if(edit_formatear!=null){
edit_formatear.apply(dc);
System.out.println("Edit: "+dc.get());
}
} catch (BadLocationException e) {
e.printStackTrace();
}
But I think this code only work with java code...
Any idea?

Issue while opening Marker in an editor programatically

I am trying to open a marker, while double-clicking on an entry from a TableViewer, inside an eclipse plug-in. I am able to get the associated resource from the marker, however nothing is happening while the openEditor method is executed.
The code is as below:
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
ReviewIssue reviewIssue = (ReviewIssue) sel.getFirstElement();
if(reviewIssue != null){
MessageDialog.openError(window.getShell(), "Insta Review", reviewIssue.getMarker().getResource());
try {
IDE.openEditor(window.getActivePage(), reviewIssue.getMarker(), true);
} catch (PartInitException e) {
MessageDialog.openError(window.getShell(), "Insta Review", e.getMessage());
}
}
} catch (Exception e) {
MessageDialog.openError(window.getShell(), "Insta Review", e.getMessage());
}
}
});
Please let me know, if am missing something here. Thanks in advance.
Also ignore the message dialogs, as I plan to implement the logging functionality later.
UPDATE:
Even though I created the marker on IFile, I was getting the same behaviour. I was finally able to open the editor by using the IFile, instead of the marker.
IFile iFile = markerProject.getFile(path);
//IMarker marker = iFile.createMarker("id.myMarker");
.....
IDE.openEditor(window.getActivePage(), reviewIssue.getiFile(), true);
//IDE.openEditor(window.getActivePage(), reviewIssue.getMarker()), true);
For this to work the IMarker.getResource() method must return an IFile. The code in IDE.openEditor is:
// get the marker resource file
if (!(marker.getResource() instanceof IFile)) {
IDEWorkbenchPlugin
.log("Open editor on marker failed; marker resource not an IFile"); //$NON-NLS-1$
return null;
}
so look in the .log file in the workspace .metadata directory to see if you are getting that log message.
Normally you would create a marker for a file using the IFile.createMarker method (createMarker is actually an IResource method).

Open a file in an Eclipse editor and set the focus on this editor

I have a strange problem which puzzles me. I open a file in an editor in Eclipse with this code:
final IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
wb.getProgressService().runInUI( window, new IRunnableWithProgress() {
#Override
public void run( IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException {
if( null == monitor ) {
monitor = new NullProgressMonitor();
}
try {
monitor.beginTask( "Append to file", 2 );
ITextEditor editor = (ITextEditor) IDE.openEditor( page, file );
monitor.worked( 1 );
// TODO Bug: Editor is active, it has the focus but doesn't process keypress events :-(
} catch( Exception e ) {
throw new InvocationTargetException( e, "Error appending to file " + file );
} finally {
monitor.done();
}
}
}, null );
I collected the bits and pieces from several sources on the Internet.
The strange problem is that the editor seems to have the focus (the tab is highlighted and I see the blue border around it)
But there is no cursor visible in the editor and when I type something, nothing happens (also nothing happens elsewhere in the workbench).
I also tried ITextEditor editor = (ITextEditor) IDE.openEditor( page, file, true ); but with the same result.
When I click on the tab, the cursor appears and I can use the editor. Pressing F12 has no effect, though.
And ideas?
Try page.activate(editor); (even though it should already be active).

Eclipse HotKey: how to switch between tabs?

How can I switch between opened windows in Eclipse? There is Ctrl+F6, but it's asking me which one I want, but I want switch it like tabs in browser or window in operating system (Cmd/Win+Tab) without file-selection from the list. How to do this easy thing in Eclipse?
I've tried to assign hotkey for events:
forward
forward history
next page
but it doesn't work the way I want.
CTRL+E (for a list of editor)
CTRL+F6 (for switching to the next editor through a list)
You can assign another shortcut to the 'Next Editor' key.
are the two official shortcuts, but they both involve a list being displayed.
CTRL+Page Up / CTRL+Page Down can cycle through editors without displaying a list.
What is interesting with that last set of shortcuts is:
they are not listed in the Eclipse Keys shortcuts to be defined.
They may be inherited from the multipage editor, making them an OS specific shortcut.
Regarding shortcuts on Mac OS (OSX), Matt Ball complained in Sept. 2011 to not being able to remap CTRL+Page Up/CTRL+Page Down:
It drives me nuts to not be able to flip through open tabs as I can in pretty much every other tabbed program in OS X (⌘-Left and ⌘-Right).
Well, in March 2012, Arthur replied:
, I've just downloaded the latest version of Eclipse (3.7+). I've been able to bind "Previous/Next tab" to (⌘-Left and ⌘-Right) when in Editor, which I'm pretty sure I couldn't do before.
So I guess they heard you.
It works just as you expect, tabs going from left to right and vice-versa, not on a history basis or some nonsense like that.
Matt Ball confirms:
oh wow, selecting "Editing Java Source" actually worked!
Now, unfortunately this means that I'm SOL if I nav into a non-Java file (JSP, XML, JS, etc.).
The fix for this is to "copy command" for this pair, and select all the "whens" that I want.
So far it's at least working beautifully for Java and JSP files.
This is a major PITA to set up, but it's just a one-time thing.
His exported preferences are available here for you to try.
Once imported, you should see, for all the relevant types of document:
If you go to Preferences (e.g. Window→Preferences) and view General→Keys
and then search for “Next Tab” and “Previous Tab”, you can remap them.
Switch like Windows in OS (go to window which last had focus)
CTRL-F6 in Eclipse, like ALT-TAB (on windows), brings up a list of tabs/windows available (if you keep the CTRL / ALT key depressed) and highlights the one you will jump to when you let go of this key. You do not have to select the window. If you want to traverse several tabs at once hold down the CTRL button and tap the TAB button. This is identical behaviour to ALT-TAB on Windows.
In this sense, CTRL-SHIFT-F6 in eclipse is the ALT-SHIFT-TAB analog. Personally, I change these bindings in Eclipse to be like Visual Studio. I.e. CTRL-TAB and CTRL-SHIFT-TAB and I do it like this:
Window>Preferences>General>Keys
Then set "Next Editor"=Ctrl+Tab and "Previous Editor"=Ctrl+Shift+Tab. Don't forget to click "Unbind Command" before setting the new binding.
Switch like browser (go to tab on the right of current tab)
This is CTRL-PageDown to go right, CTRL-PageUp to go left. Frustratingly, when you get to the end of the list of tabs (say far right hand tab) and then try to go right again Eclipse does not cycle round to the first tab (far left) like most browsers would.
You can use ALT+Left to go to your previous tab, or ALT+Right to go to forward. This method is using tab-switching like history, though, so it will go to the previous tab you had open, and forward if you've gone "back" once or more. A bit weird, I know, but it works. You can always "reset" the history by clicking through every tab once.
Right side move : Ctrl + page Down
Left side move : CTRL + page Up
Additional
get list of open tabs : Ctrl + F6
Eclipse others Short Cuts
Link : http://www.shortcutworld.com/en/win/Eclipse.html
Pdf : http://eclipse-tools.sourceforge.net/Keyboard_shortcuts_%283.0%29.pdf
CTRL + F6 is good to use. If you want to switch to next/previous tab, you need to do CTRL+Page Down / CTRL+Page Up.
The default is Ctrl + F6. You can change it by going to Window preferences. I usually change it to Ctrl + Tab, the same we use in switching tabs in a browser and other stuff.
Shortcut key to back to the previous tab
Alt + LeftArrow to go back.
Custom KeyBinding sequence example : CTRL + TAB to switch between visilble Modules or Editors Forward direction using Eclipse RCP.
you press CTRL + TAB second time to open
another editor and close previous editor using RCP Eclipse.
package rcp_demo.Toolbar;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import rcp_demo.Editor.EmployeeEditor;
import rcp_demo.Editor.EmployeeEditorInput;
import rcp_demo.Editor.ProductEditor;
import rcp_demo.Editor.ProductEditorInput;
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
public class Forward_Editor extends AbstractHandler{
static String Editor_name; // Active Editor name store in Temporary
static int cnt; // close editor count this variable
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
UserEditorInput std_input = new UserEditorInput();
EmployeeEditorInput emp_input=new EmployeeEditorInput();
ProductEditorInput product_input=new ProductEditorInput();
IEditorReference[] editors = page.getEditorReferences();
//Blank Editor Window to execute..
if(editors.length==0)
{
//First time close editor can open Student_Editor
if(cnt==1 && Editor_name.equals("Student_Editor"))
{
try {
page.openEditor(emp_input, EmployeeEditor.Id);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("EMP>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//First time close editor can open Employee_Editor
else if(cnt==1 && Editor_name.equals("Employee_Editor"))
{
try {
page.openEditor(product_input,ProductEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("PRO>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {e.printStackTrace();
}
}
//First time close editor can open Product_Editor
else if(cnt==1 && Editor_name.equals("Product_Editor"))
{
try {
page.openEditor(std_input, UserEditor.ID);
System.out.println("student Editor open");
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("Close::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//First Time call // empty editors
else{
try {
page.openEditor(std_input, UserEditor.ID);
System.out.println("student Editor open");
Editor_name=page.getActiveEditor().getTitle();
} catch (PartInitException e) {
e.printStackTrace();
}
}
}//End if condition
//AvtiveEditor(Student_Editor) close to open Employee Editor
else if(page.getActiveEditor().getTitle().equals("Student_Editor"))
{
try {
//page.closeAllEditors(true);
page.closeEditor(page.getActiveEditor(), true);
page.openEditor(emp_input, EmployeeEditor.Id);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("EMP>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//AvtiveEditor(Employee_Editor) close to open Product Editor
else if(page.getActiveEditor().getTitle().equals("Employee_Editor"))
{
try {
page.closeAllEditors(true);
page.openEditor(product_input,ProductEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("PRO>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//AvtiveEditor(Product_Editor) close to open Student Editor
else if(page.getActiveEditor().getTitle().equals("Product_Editor"))
{
try {
page.closeAllEditors(true);
page.openEditor(std_input, UserEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("stud>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//by default open Student Editor
else
{
try {
page.closeAllEditors(true);
page.openEditor(std_input, UserEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("stud_else>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
return null;
}
}
>Custom KeyBinding sequence example : <kbd> SHIFT + TAB </kbd> to switch between visilble Modules or Editors **Backword** direction using Eclipse RCP.
package rcp_demo.Toolbar;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import rcp_demo.Editor.EmployeeEditor;
import rcp_demo.Editor.EmployeeEditorInput;
import rcp_demo.Editor.ProductEditor;
import rcp_demo.Editor.ProductEditorInput;
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
public class Backword_Editor extends AbstractHandler{
static String Editor_name; // Active Editor name store in Temporary
static int cnt;
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
//Three object create in EditorInput
UserEditorInput std_input = new UserEditorInput();
EmployeeEditorInput emp_input=new EmployeeEditorInput();
ProductEditorInput product_input=new ProductEditorInput();
IEditorReference[] editors = page.getEditorReferences();
System.out.println("Length : "+editors.length);
if(editors.length==0)
{
//First time close editor can open Student_Editor
if(cnt==1 && Editor_name.equals("Product_Editor"))
{
try {
page.openEditor(emp_input, EmployeeEditor.Id);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("EMP>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//First time close editor can open Employee_Editor
else if(cnt==1 && Editor_name.equals("Employee_Editor"))
{
try {
page.openEditor(std_input, UserEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("Student>>Len:: "+editors.length+"..student::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//First time close editor can open Product_Editor
else if(cnt==1 && Editor_name.equals("Student_Editor"))
{
try {
page.openEditor(product_input,ProductEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("PRO>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//First Time or empty editors to check this condition
else{
try {
page.openEditor(product_input,ProductEditor.ID);
System.out.println("product Editor open");
} catch (PartInitException e) {
e.printStackTrace();
}
}
}
//AvtiveEditor(Product_Editor) close to open Employee Editor
else if(page.getActiveEditor().getTitle().equals("Product_Editor"))
{
System.out.println("Product:: "+page.getActiveEditor().getTitle());
try {
page.closeAllEditors(true);
page.openEditor(emp_input, EmployeeEditor.Id);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("Employee Editor open");
} catch (PartInitException e) {
e.printStackTrace();
}
}
//AvtiveEditor(Employee_Editor) close to open Student Editor
else if(page.getActiveEditor().getTitle().equals("Employee_Editor"))
{
System.out.println("Emp:: "+page.getActiveEditor().getTitle());
try {
page.closeAllEditors(true);
page.openEditor(std_input, UserEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("student Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//AvtiveEditor(Student_Editor) close to open Product Editor
else if(page.getActiveEditor().getTitle().equals("Student_Editor"))
{
System.out.println("Product:: "+page.getActiveEditor().getTitle());
try {
page.closeAllEditors(true);
page.openEditor(product_input,ProductEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("product Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//by default open Student Editor
else
{
try {
page.closeAllEditors(true);
page.openEditor(product_input,ProductEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("product Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
}
Custom KeyBinding sequence example : SHIFT + TAB to switch between visilble Modules or Editors Backword direction using Eclipse RCP.
package rcp_demo.Toolbar;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import rcp_demo.Editor.EmployeeEditor;
import rcp_demo.Editor.EmployeeEditorInput;
import rcp_demo.Editor.ProductEditor;
import rcp_demo.Editor.ProductEditorInput;
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
public class Backword_Editor extends AbstractHandler{
static String Editor_name; // Active Editor name store in Temporary
static int cnt;
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
//Three object create in EditorInput
UserEditorInput std_input = new UserEditorInput();
EmployeeEditorInput emp_input=new EmployeeEditorInput();
ProductEditorInput product_input=new ProductEditorInput();
IEditorReference[] editors = page.getEditorReferences();
System.out.println("Length : "+editors.length);
if(editors.length==0)
{
//First time close editor can open Student_Editor
if(cnt==1 && Editor_name.equals("Product_Editor"))
{
try {
page.openEditor(emp_input, EmployeeEditor.Id);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("EMP>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//First time close editor can open Employee_Editor
else if(cnt==1 && Editor_name.equals("Employee_Editor"))
{
try {
page.openEditor(std_input, UserEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("Student>>Len:: "+editors.length+"..student::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//First time close editor can open Product_Editor
else if(cnt==1 && Editor_name.equals("Student_Editor"))
{
try {
page.openEditor(product_input,ProductEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("PRO>>Len:: "+editors.length+"..EDi::"+Editor_name);
} catch (PartInitException e) {
e.printStackTrace();
}
}
//First Time or empty editors to check this condition
else{
try {
page.openEditor(product_input,ProductEditor.ID);
System.out.println("product Editor open");
} catch (PartInitException e) {
e.printStackTrace();
}
}
}
//AvtiveEditor(Product_Editor) close to open Employee Editor
else if(page.getActiveEditor().getTitle().equals("Product_Editor"))
{
System.out.println("Product:: "+page.getActiveEditor().getTitle());
try {
page.closeAllEditors(true);
page.openEditor(emp_input, EmployeeEditor.Id);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("Employee Editor open");
} catch (PartInitException e) {
e.printStackTrace();
}
}
//AvtiveEditor(Employee_Editor) close to open Student Editor
else if(page.getActiveEditor().getTitle().equals("Employee_Editor"))
{
System.out.println("Emp:: "+page.getActiveEditor().getTitle());
try {
page.closeAllEditors(true);
page.openEditor(std_input, UserEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("student Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//AvtiveEditor(Student_Editor) close to open Product Editor
else if(page.getActiveEditor().getTitle().equals("Student_Editor"))
{
System.out.println("Product:: "+page.getActiveEditor().getTitle());
try {
page.closeAllEditors(true);
page.openEditor(product_input,ProductEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("product Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//by default open Student Editor
else
{
try {
page.closeAllEditors(true);
page.openEditor(product_input,ProductEditor.ID);
cnt=1;
Editor_name=page.getActiveEditor().getTitle();
System.out.println("product Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
}
Key Sequence
M1 means CTRL
M2 means SHIFT
plugin.xml
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="rcp_demo.Toolbar.Forward_Editor"
id="RCP_Demo.Toolbar.Forward_editor_open_cmd"
name="Forward_Editor">
</command>
<command
defaultHandler="rcp_demo.Toolbar.Backword_Editor"
id="RCP_Demo.Toolbar.backwards_editor_open_cmd"
name="Backword_Editor">
</command>
</extension>
<extension point="org.eclipse.ui.bindings">
<key
commandId="RCP_Demo.Toolbar.Forward_editor_open_cmd"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+TAB">
</key>
<key
commandId="RCP_Demo.Toolbar.backwards_editor_open_cmd"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M2+TAB">
</key>
</extension>
3 line AutoHotKey script (on Windows, anyway):
#IfWinActive ahk_class SWT_Window0
^+Tab::^PgUp
^Tab::^PgDn
Put this in your startup folder (save it as *.ahk, must have AutoHotKey installed) and Eclipse tabs will now work like Chrome or Firefox.
Solved!!
Change Scheme to Microsoft Visual Studio
Window>Preferences>General>Keys
Look for Schemes dropdown
My eclipse version:
Eclipse Java EE IDE for Web Developers.
Version: Juno Service Release 1
Build id: 20120920-0800
Nobody will ever read my answer, but anyway... If you are on Mac OS X you will love multi touch gestures for history navigation in Eclipse: http://sourceforge.net/apps/mediawiki/eclipsemultitch/
On windows if you have a 5 button mouse, you can use forward and back in lieu of ALT+Left and ALT+Right.
Right to left : ctrl+ shift + 9 or ctrl + shift + Page Up or ctrl + Page Up
Left to right : ctrl + shift + 3 or ctrl + shift + Page Down or ctrl + Page Down
One way to do it is to use the VI Plugin, and then you just do :n (and :N) to go between files.
That's what I do.
You can set the hotkeys in Preferences -> General -> Keys (or just type "keys" into the filter field at the top of the Preferences dialog.
Once the Keys section is selected, find Next Tab and Previous Tab and assign them your own hotkey by clicking in the "Binding" field and then typing your hotkeys.
Hit Apply or OK to finish the process.
If you want to simply switch between your current and your previous tab selections, using CTRL + F6 will switch you back and forth. To navigate to a tab further back in your history, you need to use the UP / DOWN keys while the Editors window is open. This works with Helios (Eclipse 3.6); not sure if this is true for older versions of Eclipse.
I quote VonC response, adding something.
Ctrl+PgUp(PgDn) to switch between tabs in the current stack (both editors and view)
Ctrl+E to switch between tabs in the current stack, using a filtered list
Ctrl+F6 to switch between editors, no matter which stack
Ctrl+F7 to switch between views, no matter which stack
Plus, there is Bug 206299 open to request using Ctrl+Tab for switching tabs instead of Ctrl+PgUp(PgDn).
As this would break accessibility, the user should set a preference for this. Perhaps there should be a question in the Welcome Questionnaire during to the Oomph installs.
If not satisfied, you can assign yourself the Key Binding, from Window > Preferences > General > Keys.
For some reason my Eclipse settings were corrupted so I had to manually edit the file /.plugins/org.eclipse.e4.workbench/workbench.xmi
I must have previously set Ctrl+Tab to Browser-like tab switching, and even resetting all key bindings in Eclipse preferences wouldn't get rid of the shortcuts (they were not displayed anywhere either). I opened the above mentioned file and removed the <bindings> elements marked with <tags>type:user</tags> related to the non-functioning shortcuts.
Hold CTRL and press F6 until you reached the editor you want, then release. The UI is not as pretty as the window selection, but the functionality is the same.
On a SLES12 machine you can use Ctrl+PageUp and Ctrl+PageDown to navigate between tabs by default. You can always change these keys from Preferences window by browsing through "keys" section under "General" category.
This process is well explained by Victor and VonC above.
How can I switch between opened windows in Eclipse
CTRL+F7 works here - Eclipse Photon on Windows.
For some reason, just adding a new binding doesn't seem to work (eclipse 2021-06).
Instead:
use Copy Command to clone Next Tab and Previous Tab
change "When" to In Windows
add your new binding
Apply and Close
#Gillfish mentioned this in a comment on another answer, but i thought its better to surface the solution explicitly.
Versions of Eclipse up to 2022-03 used to have CTRL + Tab switch between editors in an LRU order, same as CTRL + E - I believe it was the same functionality. Starting with the 2022 versions, this was no longer the case with CTRL + Tab instead using to move to a different pane (i.e. move from the editor to the bottom pane, or from the bottom pane to the one of the side bars).
In either case, the CTRL + Tab isn't shown as a used binding in the Windows->Preferences->General->Keys configuration dialog - it seems to be hard-coded.
It really annoyed me because I'm very used to using CTRL + Tab to switch tabs in a multi-tab application and regardless, it is a much easier shortcut than CTRL + E.
My solution was to go into the keys configuration dialog and replace the "Quick Switch Editor" shortcut from CTRL + E to CTRL + Tab.
The "Quick Switch Editor" is basically what I need - press once and quickly release, and you go back to the previously used editor; press once and hold the modifier - you get a menu where you can navigate to a different editor in LRU order.

Open a new browser session in a different window in Selenium

I am new to Selenium and just started to use it. I want to open a new browser session in a different window from my script and do not know how to do it.
I tried using the open command and gave the Firefox Url but it opened in the same window.
Any ideas?
Try using openWindow instead of open. If you get a message that Firefox blocked a popup, allow popups. This will probably open a tab instead of a window, but maybe that will suit your needs.
#Test
public void Test01() throws Exception {
openTab("http://www.xyz.com");
}
This will open a different Firefox window. And then Handle to switch the new window.
public void trigger(String script, WebElement element) {
((JavascriptExecutor) driver).executeScript(script, element);
}
public Object trigger(String script) {
return ((JavascriptExecutor) driver).executeScript(script);
}
public void openTab(String url) {
String script = "var d=document,a=d.createElement('a');a.target='_blank';a.href='%s';a.innerHTML='.';d.body.appendChild(a);return a";
Object element = trigger(String.format(script, url));
if (element instanceof WebElement) {
WebElement anchor = (WebElement) element;
anchor.click();
trigger("var a=arguments[0];a.parentNode.removeChild(a);", anchor);
} else {
throw new JavaScriptException(element, "Unable to open Window", 1);
}
}