Eclipse rcp 如何将整个工具栏项传递到keybinding?
我有一个运行在windows平台上的单RCP应用程序。在这个应用程序中,工具栏中有很多命令,所以我想分配一个快捷键 要逐个打开工具栏,如何执行此操作Eclipse rcp 如何将整个工具栏项传递到keybinding?,eclipse-rcp,toolbar,Eclipse Rcp,Toolbar,我有一个运行在windows平台上的单RCP应用程序。在这个应用程序中,工具栏中有很多命令,所以我想分配一个快捷键 要逐个打开工具栏,如何执行此操作 我用过键投标的概念,但,工具栏项目=快捷键发生,所以我只想要一个键,那么如何做到这一点呢 你不能这么做。密钥绑定始终绑定到单个命令 如果要按顺序执行操作,请使用具有多个页面的向导或类似的工具 使用向导引导用户完成操作可能是另一种方式。您不能这样做。密钥绑定始终绑定到单个命令 如果要按顺序执行操作,请使用具有多个页面的向导或类似的工具 使用向导引导用
我用过键投标的概念,但,工具栏项目=快捷键发生,所以我只想要一个键,那么如何做到这一点呢 你不能这么做。密钥绑定始终绑定到单个命令 如果要按顺序执行操作,请使用具有多个页面的向导或类似的工具
使用向导引导用户完成操作可能是另一种方式。您不能这样做。密钥绑定始终绑定到单个命令 如果要按顺序执行操作,请使用具有多个页面的向导或类似的工具
使用向导引导用户完成操作可能是另一种方式。我已经这样做了,但方式不同。整个工具栏项通过处理程序传递。我可以与您共享代码: 转发编辑器代码:
package handler;
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.EnquiryEditor;
import rcp_demo.Editor.EnquiryEditorInput;
import rcp_demo.Editor.FoodDetailsEditor;
import rcp_demo.Editor.FoodDetailsEditorInput;
import rcp_demo.Editor.StaffdetailsEditor;
import rcp_demo.Editor.StaffdetailsEditorInput;
//Defauklt Editor ID
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
/**
* @author summet
*
*/
public class SwitchingHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
String tempEditorID = null;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("SwitchingHandler command call");
// TODO Auto-generated method stub
// HandlerUtil.getActiveWorkbenchWindow
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
// get the editor instance by given id (pEditorId)
if (page.getActiveEditor() == null || page.getActiveEditor().equals("")) {
// Default Editor Open via command
UserEditorInput input = new UserEditorInput();
try {
page.openEditor(input, UserEditor.ID);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} else {
// First check Temp ID;
String tempID = checkActiveEditorID(page);
if (tempID.equals(UserEditor.BID)) {
System.out.println("You are in UserEditor.ID");
page.closeAllEditors(true);
EmployeeEditorInput einput = new EmployeeEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(einput, EmployeeEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(EmployeeEditor.BID)) {
System.out.println("You are in EmployeeEditor.ID");
StaffdetailsEditorInput sinput = new StaffdetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(sinput, StaffdetailsEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(StaffdetailsEditor.BID)) {
System.out.println("You are in StaffdetailsEditor.ID");
FoodDetailsEditorInput finput = new FoodDetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(finput, FoodDetailsEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(FoodDetailsEditor.BID)) {
System.out.println("You are in FoodDetailsEditor.ID");
EnquiryEditorInput eeinput = new EnquiryEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(eeinput, EnquiryEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(EnquiryEditor.BID)) {
System.out.println("You are in EnquiryEditor.ID");
UserEditorInput uinput = new UserEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(uinput, UserEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private String checkActiveEditorID(IWorkbenchPage page) {
tempEditorID = page.getActiveEditor().getTitle();
return tempEditorID;
// TODO Auto-generated method stub
}
}
package handler;
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.EnquiryEditor;
import rcp_demo.Editor.EnquiryEditorInput;
import rcp_demo.Editor.FoodDetailsEditor;
import rcp_demo.Editor.FoodDetailsEditorInput;
import rcp_demo.Editor.StaffdetailsEditor;
import rcp_demo.Editor.StaffdetailsEditorInput;
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
public class BackEditorHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
String tempBackEditorID = null;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("BackEditorHandler call");
// TODO Auto-generated method stub
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
// get the editor instance by given id (pEditorId)
if (page.getActiveEditor() == null || page.getActiveEditor().equals("")) {
// Default Editor Open via command
UserEditorInput input = new UserEditorInput();
try {
page.openEditor(input, UserEditor.ID);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} else {
// First check Temp ID;
String tempBackID = checkActiveEditorID(page);
System.out.println("tempID:--" + tempBackID);
if (tempBackID.equals(UserEditor.BID)) {
System.out.println("You are in UserEditor.ID");
page.closeAllEditors(true);
EnquiryEditorInput eeinput = new EnquiryEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(eeinput, EnquiryEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(EmployeeEditor.BID)) {
System.out.println("You are in EmployeeEditor.ID");
UserEditorInput uinput = new UserEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(uinput, UserEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(StaffdetailsEditor.BID)) {
System.out.println("You are in StaffdetailsEditor.ID");
EmployeeEditorInput einput = new EmployeeEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(einput, EmployeeEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(FoodDetailsEditor.BID)) {
System.out.println("You are in FoodDetailsEditor.ID");
StaffdetailsEditorInput sinput = new StaffdetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(sinput, StaffdetailsEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(EnquiryEditor.BID)) {
System.out.println("You are in EnquiryEditor.ID");
FoodDetailsEditorInput finput = new FoodDetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(finput, FoodDetailsEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private String checkActiveEditorID(IWorkbenchPage page) {
tempBackEditorID = page.getActiveEditor().getTitle();
return tempBackEditorID;
// TODO Auto-generated method stub
}
}
反向编辑器代码:
package handler;
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.EnquiryEditor;
import rcp_demo.Editor.EnquiryEditorInput;
import rcp_demo.Editor.FoodDetailsEditor;
import rcp_demo.Editor.FoodDetailsEditorInput;
import rcp_demo.Editor.StaffdetailsEditor;
import rcp_demo.Editor.StaffdetailsEditorInput;
//Defauklt Editor ID
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
/**
* @author summet
*
*/
public class SwitchingHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
String tempEditorID = null;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("SwitchingHandler command call");
// TODO Auto-generated method stub
// HandlerUtil.getActiveWorkbenchWindow
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
// get the editor instance by given id (pEditorId)
if (page.getActiveEditor() == null || page.getActiveEditor().equals("")) {
// Default Editor Open via command
UserEditorInput input = new UserEditorInput();
try {
page.openEditor(input, UserEditor.ID);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} else {
// First check Temp ID;
String tempID = checkActiveEditorID(page);
if (tempID.equals(UserEditor.BID)) {
System.out.println("You are in UserEditor.ID");
page.closeAllEditors(true);
EmployeeEditorInput einput = new EmployeeEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(einput, EmployeeEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(EmployeeEditor.BID)) {
System.out.println("You are in EmployeeEditor.ID");
StaffdetailsEditorInput sinput = new StaffdetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(sinput, StaffdetailsEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(StaffdetailsEditor.BID)) {
System.out.println("You are in StaffdetailsEditor.ID");
FoodDetailsEditorInput finput = new FoodDetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(finput, FoodDetailsEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(FoodDetailsEditor.BID)) {
System.out.println("You are in FoodDetailsEditor.ID");
EnquiryEditorInput eeinput = new EnquiryEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(eeinput, EnquiryEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(EnquiryEditor.BID)) {
System.out.println("You are in EnquiryEditor.ID");
UserEditorInput uinput = new UserEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(uinput, UserEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private String checkActiveEditorID(IWorkbenchPage page) {
tempEditorID = page.getActiveEditor().getTitle();
return tempEditorID;
// TODO Auto-generated method stub
}
}
package handler;
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.EnquiryEditor;
import rcp_demo.Editor.EnquiryEditorInput;
import rcp_demo.Editor.FoodDetailsEditor;
import rcp_demo.Editor.FoodDetailsEditorInput;
import rcp_demo.Editor.StaffdetailsEditor;
import rcp_demo.Editor.StaffdetailsEditorInput;
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
public class BackEditorHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
String tempBackEditorID = null;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("BackEditorHandler call");
// TODO Auto-generated method stub
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
// get the editor instance by given id (pEditorId)
if (page.getActiveEditor() == null || page.getActiveEditor().equals("")) {
// Default Editor Open via command
UserEditorInput input = new UserEditorInput();
try {
page.openEditor(input, UserEditor.ID);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} else {
// First check Temp ID;
String tempBackID = checkActiveEditorID(page);
System.out.println("tempID:--" + tempBackID);
if (tempBackID.equals(UserEditor.BID)) {
System.out.println("You are in UserEditor.ID");
page.closeAllEditors(true);
EnquiryEditorInput eeinput = new EnquiryEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(eeinput, EnquiryEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(EmployeeEditor.BID)) {
System.out.println("You are in EmployeeEditor.ID");
UserEditorInput uinput = new UserEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(uinput, UserEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(StaffdetailsEditor.BID)) {
System.out.println("You are in StaffdetailsEditor.ID");
EmployeeEditorInput einput = new EmployeeEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(einput, EmployeeEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(FoodDetailsEditor.BID)) {
System.out.println("You are in FoodDetailsEditor.ID");
StaffdetailsEditorInput sinput = new StaffdetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(sinput, StaffdetailsEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(EnquiryEditor.BID)) {
System.out.println("You are in EnquiryEditor.ID");
FoodDetailsEditorInput finput = new FoodDetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(finput, FoodDetailsEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private String checkActiveEditorID(IWorkbenchPage page) {
tempBackEditorID = page.getActiveEditor().getTitle();
return tempBackEditorID;
// TODO Auto-generated method stub
}
}
我做这件事的方式不同。整个工具栏项通过处理程序传递。我可以与您共享代码: 转发编辑器代码:
package handler;
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.EnquiryEditor;
import rcp_demo.Editor.EnquiryEditorInput;
import rcp_demo.Editor.FoodDetailsEditor;
import rcp_demo.Editor.FoodDetailsEditorInput;
import rcp_demo.Editor.StaffdetailsEditor;
import rcp_demo.Editor.StaffdetailsEditorInput;
//Defauklt Editor ID
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
/**
* @author summet
*
*/
public class SwitchingHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
String tempEditorID = null;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("SwitchingHandler command call");
// TODO Auto-generated method stub
// HandlerUtil.getActiveWorkbenchWindow
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
// get the editor instance by given id (pEditorId)
if (page.getActiveEditor() == null || page.getActiveEditor().equals("")) {
// Default Editor Open via command
UserEditorInput input = new UserEditorInput();
try {
page.openEditor(input, UserEditor.ID);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} else {
// First check Temp ID;
String tempID = checkActiveEditorID(page);
if (tempID.equals(UserEditor.BID)) {
System.out.println("You are in UserEditor.ID");
page.closeAllEditors(true);
EmployeeEditorInput einput = new EmployeeEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(einput, EmployeeEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(EmployeeEditor.BID)) {
System.out.println("You are in EmployeeEditor.ID");
StaffdetailsEditorInput sinput = new StaffdetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(sinput, StaffdetailsEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(StaffdetailsEditor.BID)) {
System.out.println("You are in StaffdetailsEditor.ID");
FoodDetailsEditorInput finput = new FoodDetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(finput, FoodDetailsEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(FoodDetailsEditor.BID)) {
System.out.println("You are in FoodDetailsEditor.ID");
EnquiryEditorInput eeinput = new EnquiryEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(eeinput, EnquiryEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(EnquiryEditor.BID)) {
System.out.println("You are in EnquiryEditor.ID");
UserEditorInput uinput = new UserEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(uinput, UserEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private String checkActiveEditorID(IWorkbenchPage page) {
tempEditorID = page.getActiveEditor().getTitle();
return tempEditorID;
// TODO Auto-generated method stub
}
}
package handler;
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.EnquiryEditor;
import rcp_demo.Editor.EnquiryEditorInput;
import rcp_demo.Editor.FoodDetailsEditor;
import rcp_demo.Editor.FoodDetailsEditorInput;
import rcp_demo.Editor.StaffdetailsEditor;
import rcp_demo.Editor.StaffdetailsEditorInput;
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
public class BackEditorHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
String tempBackEditorID = null;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("BackEditorHandler call");
// TODO Auto-generated method stub
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
// get the editor instance by given id (pEditorId)
if (page.getActiveEditor() == null || page.getActiveEditor().equals("")) {
// Default Editor Open via command
UserEditorInput input = new UserEditorInput();
try {
page.openEditor(input, UserEditor.ID);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} else {
// First check Temp ID;
String tempBackID = checkActiveEditorID(page);
System.out.println("tempID:--" + tempBackID);
if (tempBackID.equals(UserEditor.BID)) {
System.out.println("You are in UserEditor.ID");
page.closeAllEditors(true);
EnquiryEditorInput eeinput = new EnquiryEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(eeinput, EnquiryEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(EmployeeEditor.BID)) {
System.out.println("You are in EmployeeEditor.ID");
UserEditorInput uinput = new UserEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(uinput, UserEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(StaffdetailsEditor.BID)) {
System.out.println("You are in StaffdetailsEditor.ID");
EmployeeEditorInput einput = new EmployeeEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(einput, EmployeeEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(FoodDetailsEditor.BID)) {
System.out.println("You are in FoodDetailsEditor.ID");
StaffdetailsEditorInput sinput = new StaffdetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(sinput, StaffdetailsEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(EnquiryEditor.BID)) {
System.out.println("You are in EnquiryEditor.ID");
FoodDetailsEditorInput finput = new FoodDetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(finput, FoodDetailsEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private String checkActiveEditorID(IWorkbenchPage page) {
tempBackEditorID = page.getActiveEditor().getTitle();
return tempBackEditorID;
// TODO Auto-generated method stub
}
}
反向编辑器代码:
package handler;
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.EnquiryEditor;
import rcp_demo.Editor.EnquiryEditorInput;
import rcp_demo.Editor.FoodDetailsEditor;
import rcp_demo.Editor.FoodDetailsEditorInput;
import rcp_demo.Editor.StaffdetailsEditor;
import rcp_demo.Editor.StaffdetailsEditorInput;
//Defauklt Editor ID
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
/**
* @author summet
*
*/
public class SwitchingHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
String tempEditorID = null;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("SwitchingHandler command call");
// TODO Auto-generated method stub
// HandlerUtil.getActiveWorkbenchWindow
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
// get the editor instance by given id (pEditorId)
if (page.getActiveEditor() == null || page.getActiveEditor().equals("")) {
// Default Editor Open via command
UserEditorInput input = new UserEditorInput();
try {
page.openEditor(input, UserEditor.ID);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} else {
// First check Temp ID;
String tempID = checkActiveEditorID(page);
if (tempID.equals(UserEditor.BID)) {
System.out.println("You are in UserEditor.ID");
page.closeAllEditors(true);
EmployeeEditorInput einput = new EmployeeEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(einput, EmployeeEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(EmployeeEditor.BID)) {
System.out.println("You are in EmployeeEditor.ID");
StaffdetailsEditorInput sinput = new StaffdetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(sinput, StaffdetailsEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(StaffdetailsEditor.BID)) {
System.out.println("You are in StaffdetailsEditor.ID");
FoodDetailsEditorInput finput = new FoodDetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(finput, FoodDetailsEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(FoodDetailsEditor.BID)) {
System.out.println("You are in FoodDetailsEditor.ID");
EnquiryEditorInput eeinput = new EnquiryEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(eeinput, EnquiryEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempID.equals(EnquiryEditor.BID)) {
System.out.println("You are in EnquiryEditor.ID");
UserEditorInput uinput = new UserEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(uinput, UserEditor.ID);
tempID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private String checkActiveEditorID(IWorkbenchPage page) {
tempEditorID = page.getActiveEditor().getTitle();
return tempEditorID;
// TODO Auto-generated method stub
}
}
package handler;
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.EnquiryEditor;
import rcp_demo.Editor.EnquiryEditorInput;
import rcp_demo.Editor.FoodDetailsEditor;
import rcp_demo.Editor.FoodDetailsEditorInput;
import rcp_demo.Editor.StaffdetailsEditor;
import rcp_demo.Editor.StaffdetailsEditorInput;
import rcp_demo.Editor.UserEditor;
import rcp_demo.Editor.UserEditorInput;
public class BackEditorHandler extends AbstractHandler {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
* ExecutionEvent)
*/
String tempBackEditorID = null;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("BackEditorHandler call");
// TODO Auto-generated method stub
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
// get the editor instance by given id (pEditorId)
if (page.getActiveEditor() == null || page.getActiveEditor().equals("")) {
// Default Editor Open via command
UserEditorInput input = new UserEditorInput();
try {
page.openEditor(input, UserEditor.ID);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} else {
// First check Temp ID;
String tempBackID = checkActiveEditorID(page);
System.out.println("tempID:--" + tempBackID);
if (tempBackID.equals(UserEditor.BID)) {
System.out.println("You are in UserEditor.ID");
page.closeAllEditors(true);
EnquiryEditorInput eeinput = new EnquiryEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(eeinput, EnquiryEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(EmployeeEditor.BID)) {
System.out.println("You are in EmployeeEditor.ID");
UserEditorInput uinput = new UserEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(uinput, UserEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(StaffdetailsEditor.BID)) {
System.out.println("You are in StaffdetailsEditor.ID");
EmployeeEditorInput einput = new EmployeeEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(einput, EmployeeEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(FoodDetailsEditor.BID)) {
System.out.println("You are in FoodDetailsEditor.ID");
StaffdetailsEditorInput sinput = new StaffdetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(sinput, StaffdetailsEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (tempBackID.equals(EnquiryEditor.BID)) {
System.out.println("You are in EnquiryEditor.ID");
FoodDetailsEditorInput finput = new FoodDetailsEditorInput();
try {
page.closeAllEditors(true);
page.openEditor(finput, FoodDetailsEditor.ID);
tempBackID = null;
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
private String checkActiveEditorID(IWorkbenchPage page) {
tempBackEditorID = page.getActiveEditor().getTitle();
return tempBackEditorID;
// TODO Auto-generated method stub
}
}
如果我将进入if-else-if条件,那么它是可能的,但是如何识别这个命令呢?我不明白你的意思。添加了一个关于作弊表的说明,这是一种引导用户进行多种操作的方法。如果我将输入if-else-if条件,那么这是可能的,但如何识别此命令?我不明白你的意思。添加了一个关于作弊表的说明,这是一种引导用户进行多种操作的方法。我希望这个答案是有用的。请访问此页面:我尽最大努力满足您的要求…谢谢兄弟…我希望这个答案是有用的。请访问此页面:我尽最大努力满足您的要求…谢谢兄弟。。。