Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » MultiPageEditorActionBarContributor problems
icon5.gif  MultiPageEditorActionBarContributor problems [message #653691] Thu, 10 February 2011 17:41
Kazan  is currently offline Kazan Friend
Messages: 5
Registered: July 2009
Junior Member
Will someone please help me? I have been struggling with this for 8 hours.

I am trying to get actions to work in a multipage editor.

I took the shapes example and modified it to fit in a multipage editor.

If I run it as a multipageeditor, then the delete action won't work. If I run it as a one page editor, then the delete action works ok.

When I launch the multipageeditor, the delete button shows up, but it is disabled.

The delete key does not work either.

Please help. I have searched all over, tried everything, and it still won't work.





import java.util.ArrayList;
import java.util.List;

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;

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.gef.ui.actions.ZoomComboContributionItem;

//http://dev.eclipse.org/newslists/news.eclipse.platform/msg67341.html
public class TourSheetEditorActionBarContributor extends MultiPageEditorActionBarContributor{
  // public class TourSheetEditorActionBarContributor extends
  // EditorActionBarContributor{
  private ActionRegistry registry = new ActionRegistry();
  private List retargetActions = new ArrayList();
  private List globalActionKeys = new ArrayList();

  public TourSheetEditorActionBarContributor(){
    super();
  }

  public void init(IActionBars bars){
    System.out.println("init.test.1->" + bars);
    buildActions();
    declareGlobalActionKeys();
    super.init(bars);
  }

  protected void buildActions(){
    System.out.println("protected void buildActions.test.1");
    addRetargetAction(new DeleteRetargetAction());
    addRetargetAction(new UndoRetargetAction());
    addRetargetAction(new RedoRetargetAction());
  }

  protected void addRetargetAction(RetargetAction action){
    addAction(action);
    retargetActions.add(action);
    getPage().addPartListener(action);
    addGlobalActionKey(action.getId());
  }

  protected void declareGlobalActionKeys(){
    // currently none
  }

  public void dispose(){
    for(int i = 0; i < retargetActions.size(); i++){
      RetargetAction action = (RetargetAction) retargetActions.get(i);
      getPage().removePartListener(action);
      action.dispose();
    }
    registry.dispose();
    retargetActions = null;
    registry = null;
  }

  protected IAction getAction(String id){
    return getActionRegistry().getAction(id);
  }

  protected ActionRegistry getActionRegistry(){
    return registry;
  }

  public void contributeToToolBar(IToolBarManager toolBarManager){
    super.contributeToToolBar(toolBarManager);
    System.out.println("public void contributeToToolBar.test.1");
    toolBarManager.add(getAction(ActionFactory.UNDO.getId()));
    toolBarManager.add(getAction(ActionFactory.REDO.getId()));
    toolBarManager.add(new ZoomComboContributionItem(getPage()));
  }

  protected void addAction(IAction action){
    getActionRegistry().registerAction(action);
  }

  protected void addGlobalActionKey(String key){
    globalActionKeys.add(key);
  }

  public void setActivePage(IEditorPart activeEditor){
    System.out.println("setActivePage.test.1=" + activeEditor);
    try{
      ActionRegistry registry = (ActionRegistry) activeEditor.getAdapter(ActionRegistry.class);
      IActionBars bars = getActionBars();
      for(int i = 0; i < globalActionKeys.size(); i++){
        String id = (String) globalActionKeys.get(i);
        System.out.println("  " + id);
        bars.setGlobalActionHandler(id, registry.getAction(id));
      }
      getActionBars().updateActionBars();
      System.out.println("setActivePage.test.2=" + activeEditor);
      init(bars);
      System.out.println("setActivePage.test.3=" + activeEditor);
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }
}
Previous Topic:Using direct edit
Next Topic:How to expand collapse palette
Goto Forum:
  


Current Time: Thu Apr 18 12:25:08 GMT 2024

Powered by FUDForum. Page generated in 0.02083 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top