facebook

MultiPageEditorActionBarContributor

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #273672 Reply

    *alexandre*
    Member

    Hi,

    I’m developping a new editor and I can’t get my actions working when I’m been using a MultiPageEditorActionBarContributor class.

    Here is my code :

    
    package com.odcgroup.page.ui.action;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.eclipse.gef.ui.actions.ActionRegistry;
    import org.eclipse.gef.ui.actions.DeleteRetargetAction;
    import org.eclipse.gef.ui.actions.RedoRetargetAction;
    import org.eclipse.gef.ui.actions.UndoRetargetAction;
    import org.eclipse.jface.action.IAction;
    import org.eclipse.jface.action.IToolBarManager;
    import org.eclipse.ui.IActionBars;
    import org.eclipse.ui.IEditorPart;
    import org.eclipse.ui.actions.ActionFactory;
    import org.eclipse.ui.actions.RetargetAction;
    import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
    
    /**
     * Represent the multi page editor contributor
     *
     * @author Alexandre Jaquet
     *
     */
    public class MultiPageUIActionBarContributor extends MultiPageEditorActionBarContributor {
        
        private List globalActionKeys = new ArrayList();
        private List retargetActions = new  ArrayList();
        private ActionRegistry registry = new ActionRegistry();
        
        /**
         * Initialization
         */
        public void init(IActionBars bars) {
              buildActions();
              declareGlobalActionKeys();
              super.init(bars);
         }
        /**
         * Builds the actions.
         *
         * @see org.eclipse.gef.ui.actions.ActionBarContributor#buildActions()
         */
        protected void buildActions() {
            addRetargetAction(new UndoRetargetAction());
            addRetargetAction(new RedoRetargetAction());
            addRetargetAction(new DeleteRetargetAction());
            addRetargetAction(new AddWidgetToPaletteRetargetAction());
            addRetargetAction(new CompileRetargetAction());
        }
        /**
         * Adds the retarded actions.
         *
         * @param action
         *             The action to add
         */
        protected void addRetargetAction(RetargetAction action) {       
            addAction(action);
            retargetActions.add(action);
            getPage().addPartListener(action);
            addGlobalActionKey(action.getId());
        }
        /**
         * Adds global action key.
         *
         * @param key
         *             The key to add
         */
        protected void addGlobalActionKey(String key) {       
            globalActionKeys.add(key);
        }
        /**
         * Adds to action registry an action.
         *
         * @param action
         *             The action to add
         */
        protected void addAction(IAction action) {
            getActionRegistry().registerAction(action);
        }
        /**
         * Gets the registry.
         *
         * @return ActionRegistry
         *                 The registry
         */
        protected ActionRegistry getActionRegistry() {       
            return registry;   
        }
        /**
         * Declares the global action keys.
         *
         * @see org.eclipse.gef.ui.actions.ActionBarContributor#declareGlobalActionKeys()
         */
         protected void declareGlobalActionKeys() {
              addGlobalActionKey(ActionFactory.UNDO.getId());
              addGlobalActionKey(ActionFactory.REDO.getId());
              addGlobalActionKey(ActionFactory.COPY.getId());
              addGlobalActionKey(ActionFactory.PASTE.getId());       
              addGlobalActionKey(ActionFactory.SELECT_ALL.getId());
              addGlobalActionKey(ActionFactory.DELETE.getId());
        }
        
        protected IAction getAction(String id) {
             return getActionRegistry().getAction(id);
        }
        /**
         * Adds the undo and redo items to the toolbar.
         *
         * @param tbm The IToolBarManager
         * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager)
         */
        public void contributeToToolBar(IToolBarManager tbm) {
            tbm.add(getAction(ActionFactory.UNDO.getId()));
            tbm.add(getAction(ActionFactory.REDO.getId()));       
            tbm.add(getAction(AddWidgetToPaletteAction.ID));
            tbm.add(getAction(CompileAction.ID));
           
        }
        /**
         * Sets the page to active status.
         *
         * @param activeEditor
         *                 The active editor
         */
        public void setActivePage(IEditorPart activeEditor) {
            ActionRegistry registry = (ActionRegistry)
            activeEditor.getAdapter(ActionRegistry.class);
            IActionBars bars = getActionBars();
            for (int i = 0; i < globalActionKeys.size(); i++) {
                String id = (String) globalActionKeys.get(i);
                bars.setGlobalActionHandler(id, registry.getAction(id));
            }
            getActionBars().updateActionBars();
        }
           
    } 
    

    I’ve try to register my actions in other ways :

    -like this http://www.koders.com/java/fid90607CEA88082F3BE6830636D105C90C0A7BDD59.aspx?s=actionBars.setGlobalActionHandler

    or by implementing a “normal” actionbar and added setActivePage and setActiveEditor
    but without having better result.

    Any idea welcome.

    Thanks in advance.

    Regards,
    Alexandre

    #273688 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: MultiPageEditorActionBarContributor

You must be logged in to post in the forum log in