package org.wso2.developerstudio.eclipse.gmf.esb.diagram.part;

import org.eclipse.emf.validation.internal.util.Log;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gmf.runtime.common.ui.action.global.GlobalActionId;
import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.ContributionItemService;
import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
import org.eclipse.gmf.runtime.common.ui.util.WorkbenchPartDescriptor;
import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
import org.eclipse.gmf.runtime.diagram.ui.internal.actions.ZoomContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.wso2.developerstudio.eclipse.gmf.esb.diagram.Activator;
import org.wso2.developerstudio.eclipse.logging.core.IDeveloperStudioLog;
import org.wso2.developerstudio.eclipse.logging.core.Logger;

/**
 * @generated
 */
public class EsbDiagramActionBarContributor extends MultiPageEditorActionBarContributor {

	private IWorkbenchPartDescriptor descriptor;
	private static IDeveloperStudioLog log = Logger.getLog(Activator.PLUGIN_ID);

    /**
     * @generated
     */
    protected Class getEditorClass() {
        return EsbDiagramEditor.class;
    }

    /**
     * @generated
     */
    protected String getEditorId() {
        return EsbDiagramEditor.ID;
    }

    /**
     * @generated NOT
     */
    public void init(IActionBars bars, IWorkbenchPage page) {
		super.init(bars, page);
		descriptor = new WorkbenchPartDescriptor(getEditorId(), getEditorClass(), getPage());
		try {
			ContributionItemService.getInstance().contributeToActionBars(bars, descriptor);
		} catch (Exception e) {
			log.error("Error while creating diagram action items", e);
		}
		bars.updateActionBars();
        bars.setGlobalActionHandler(GlobalActionId.SAVE, null);
        // print preview
        IMenuManager fileMenu = bars.getMenuManager().findMenuUsingPath(IWorkbenchActionConstants.M_FILE);
        assert fileMenu != null;
        fileMenu.remove("pageSetupAction"); //$NON-NLS-1$
        // Removing Diagram menu from ESB editor.
        IMenuManager diagramMenu = bars.getMenuManager().findMenuUsingPath(ActionIds.MENU_DIAGRAM);
        assert diagramMenu != null;
        bars.getMenuManager().remove("diagramMenu");

        // Remove Diagram toolbar from ESB editor..
        IToolBarManager toolBarManager = bars.getToolBarManager();
        assert toolBarManager != null;
        IContributionItem[] contributionItem = toolBarManager.getItems();
        for (int i = 0; i < contributionItem.length; ++i) {
            // Not removing "zoom" toolbar item.
            if (!(contributionItem[i] instanceof ZoomContributionItem)) {
                toolBarManager.remove(contributionItem[i]);
            }
        }
    }

	@Override
	public void setActivePage(IEditorPart activeEditor) {
		IActionBars actionBars = getActionBars();
		if (actionBars != null) {
			if (activeEditor instanceof ITextEditor) {
				ITextEditor editor = (activeEditor instanceof ITextEditor) ? (ITextEditor) activeEditor : null;
				actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
						getTextAction(editor, ITextEditorActionConstants.UNDO));
				actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
						getTextAction(editor, ITextEditorActionConstants.REDO));
				actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
						getTextAction(editor, ITextEditorActionConstants.SELECT_ALL));
				actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(),
						getTextAction(editor, ITextEditorActionConstants.CUT));
				actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
						getTextAction(editor, ITextEditorActionConstants.COPY));
				actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
						getTextAction(editor, ITextEditorActionConstants.PASTE));
				actionBars.updateActionBars();
			}
		}
	}

	private static IAction getTextAction(ITextEditor editor, String actionID) {
		return editor == null ? null : editor.getAction(actionID);
	}

}

@@ -80,403 +80,58 @@
 pse.
-emf.validation.internal.util.Log;%0Aimport org.eclipse.gef.ui.actions.ActionRegistry;%0Aimport org.eclipse.gmf.runtime.common.ui.action.global.GlobalActionId;%0Aimport org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.ContributionItemService;%0Aimport org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;%0Aimport org.eclipse.gmf.runtime.common.ui.util.WorkbenchPartDescriptor
+gmf.runtime.common.ui.action.global.GlobalActionId
 ;%0Aim
@@ -293,28 +293,64 @@
 pse.
-jface.action.IAction
+gmf.runtime.diagram.ui.parts.DiagramActionBarContributor
 ;%0Aim
@@ -532,43 +532,8 @@
 rs;%0A
-import org.eclipse.ui.IEditorPart;%0A
 impo
@@ -618,426 +618,8 @@
 age;
-%0Aimport org.eclipse.ui.actions.ActionFactory;%0Aimport org.eclipse.ui.part.MultiPageEditorActionBarContributor;%0Aimport org.eclipse.ui.texteditor.ITextEditor;%0Aimport org.eclipse.ui.texteditor.ITextEditorActionConstants;%0Aimport org.wso2.developerstudio.eclipse.gmf.esb.diagram.Activator;%0Aimport org.wso2.developerstudio.eclipse.logging.core.IDeveloperStudioLog;%0Aimport org.wso2.developerstudio.eclipse.logging.core.Logger;
 %0A%0A/*
@@ -694,23 +694,15 @@
 nds 
-MultiPageEditor
+Diagram
 Acti
@@ -725,133 +725,8 @@
  %7B%0A%0A
-%09private IWorkbenchPartDescriptor descriptor;%0A%09private static IDeveloperStudioLog log = Logger.getLog(Activator.PLUGIN_ID);%0A%0A
     
@@ -1054,18 +1054,24 @@
 page) %7B%0A
-%09%09
+        
 super.in
@@ -1090,305 +1090,49 @@
 e);%0A
-%09%09descriptor = new WorkbenchPartDescriptor(getEditorId(), getEditorClass(), getPage());%0A%09%09try %7B%0A%09%09%09ContributionItemService.getInstance().contributeToActionBars(bars, descriptor);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09log.error(%22Error while creating diagram action items%22, e);%0A%09%09%7D%0A%09%09bars.updateActionBars();
+        // registering global save action
 %0A   
@@ -2164,1267 +2164,6 @@
   %7D%0A
-%0A%09@Override%0A%09public void setActivePage(IEditorPart activeEditor) %7B%0A%09%09IActionBars actionBars = getActionBars();%0A%09%09if (actionBars != null) %7B%0A%09%09%09if (activeEditor instanceof ITextEditor) %7B%0A%09%09%09%09ITextEditor editor = (activeEditor instanceof ITextEditor) ? (ITextEditor) activeEditor : null;%0A%09%09%09%09actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),%0A%09%09%09%09%09%09getTextAction(editor, ITextEditorActionConstants.UNDO));%0A%09%09%09%09actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),%0A%09%09%09%09%09%09getTextAction(editor, ITextEditorActionConstants.REDO));%0A%09%09%09%09actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),%0A%09%09%09%09%09%09getTextAction(editor, ITextEditorActionConstants.SELECT_ALL));%0A%09%09%09%09actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(),%0A%09%09%09%09%09%09getTextAction(editor, ITextEditorActionConstants.CUT));%0A%09%09%09%09actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),%0A%09%09%09%09%09%09getTextAction(editor, ITextEditorActionConstants.COPY));%0A%09%09%09%09actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),%0A%09%09%09%09%09%09getTextAction(editor, ITextEditorActionConstants.PASTE));%0A%09%09%09%09actionBars.updateActionBars();%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09private static IAction getTextAction(ITextEditor editor, String actionID) %7B%0A%09%09return editor == null ? null : editor.getAction(actionID);%0A%09%7D%0A%0A
 %7D%0A

Revert "fix issue with undo/redo not working in eclipse 2020"