- This topic has 1 reply, 2 voices, and was last updated 17 years, 5 months ago by Loyal Water.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
*alexandre*MemberHi,
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 :
or by implementing a “normal” actionbar and added setActivePage and setActiveEditor
but without having better result.Any idea welcome.
Thanks in advance.
Regards,
Alexandre
Loyal WaterMemberMoving to Off Topic >> Software Development
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)