Jawaban:
Contoh urutan Custom KeyBinding: CTRL + TAB untuk beralih di antara Modul yang dapat dilihat atau Editor Arah maju menggunakan Eclipse RCP.
Anda menekan CTRL + TAB kedua kalinya untuk membuka editor lain dan menutup editor sebelumnya menggunakan RCP Eclipse.
public class Emp_editor_open extends AbstractHandler{
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
//Three object create in EditorInput
ProductEditorInput product_input=new ProductEditorInput();
EmployeeEditorInput emp_input=new EmployeeEditorInput();
UserEditorInput std_input = new UserEditorInput();
IEditorReference[] editors = page.getEditorReferences();
System.out.println("Length : "+editors.length);
if(editors.length==0){
//First Time or empty editors to check this condition
try {
page.openEditor(product_input,ProductEditor.ID);
System.out.println("product Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
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);
System.out.println("Employee Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
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);
System.out.println("student Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
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);
System.out.println("product Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
try {
page.closeAllEditors(true);
page.openEditor(product_input,ProductEditor.ID);
System.out.println("product Editor open");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
}
Plugin.xml
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="rcp_demo.Toolbar.Emp_editor_open"
id="RCP_Demo.Toolbar.emp_editor_open_cmd"
name="Employee_Editor_open">
</command>
</extension>
<extension point="org.eclipse.ui.bindings">
<key
commandId="RCP_Demo.Toolbar.emp_editor_open_cmd"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+TAB">
</key>
</extension>
Urutan kunci Pemetaan berarti M1 CTRL