Пример пользовательской последовательности связывания клавиш: CTRL + TAB для переключения между видимыми модулями или направлением редактора вперед с помощью Eclipse RCP.
Вы нажимаете CTRL + TAB второй раз, чтобы открыть другой редактор и закрыть предыдущий редактор, используя 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;
}
}
Пример пользовательской последовательности связывания клавиш: SHIFT + TAB для переключения между видимыми модулями или направлением обратного слова редактора с помощью 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;
}
}
Последовательность клавиш
М1 означает CTRL
М2 означает 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>