1

I have A one RCP application which is run on the windows platform.in this application so many command in tool bar, So i want to assign one short cut key to open one by one tool bar how to do this?

I have used key biding concept but, tool bar item = shortcut key happen , so i want only one key then how to do it possibleImage?

S-IT Java
  • 127
  • 13

2 Answers2

0

You can't do this. A key binding is always bound to a single command.

If you want to do things in a sequence use a Wizard with multiple pages or something like that.

Using a cheat sheet to guide the user through the actions might be another way.

greg-449
  • 102,836
  • 220
  • 90
  • 127
  • if i will put into if else if condition then it possible but how to identified this command? – S-IT Java Jan 31 '17 at 11:07
  • I don't understand what you mean. Added a note about cheats sheets which are a way to guide user's through multiple actions. – greg-449 Jan 31 '17 at 11:43
0

I have do it but different way. Whole toolbar item is passed via handler. I can share you code:

Forward Editor code:

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

}
}

Backward Editor code:

 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

  }
  }
S-IT Java
  • 127
  • 13