/**
   * This adds to the menu bar a menu and some separators for editor additions, as well as the
   * sub-menus for object creation items.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  @Override
  public void contributeToMenu(IMenuManager menuManager) {
    super.contributeToMenu(menuManager);

    IMenuManager submenuManager =
        new MenuManager(DsmlEditorPlugin.INSTANCE.getString("_UI_DsmlEditor_menu"), "dsmlMenuID");
    menuManager.insertAfter("additions", submenuManager);
    submenuManager.add(new Separator("settings"));
    submenuManager.add(new Separator("actions"));
    submenuManager.add(new Separator("additions"));
    submenuManager.add(new Separator("additions-end"));

    // Prepare for CreateChild item addition or removal.
    //
    createChildMenuManager =
        new MenuManager(DsmlEditorPlugin.INSTANCE.getString("_UI_CreateChild_menu_item"));
    submenuManager.insertBefore("additions", createChildMenuManager);

    // Prepare for CreateSibling item addition or removal.
    //
    createSiblingMenuManager =
        new MenuManager(DsmlEditorPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item"));
    submenuManager.insertBefore("additions", createSiblingMenuManager);

    // Force an update because Eclipse hides empty menus now.
    //
    submenuManager.addMenuListener(
        new IMenuListener() {
          public void menuAboutToShow(IMenuManager menuManager) {
            menuManager.updateAll(true);
          }
        });

    addGlobalActions(submenuManager);
  }
  /**
   * This inserts global actions before the "additions-end" separator.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  protected void addGlobalActions(IMenuManager menuManager) {
    menuManager.insertAfter("additions-end", new Separator("ui-actions"));
    menuManager.insertAfter("ui-actions", showPropertiesViewAction);

    refreshViewerAction.setEnabled(refreshViewerAction.isEnabled());
    menuManager.insertAfter("ui-actions", refreshViewerAction);

    super.addGlobalActions(menuManager);
  }
  /**
   * This populates the pop-up menu before it appears.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  public void menuAboutToShow(IMenuManager menuManager) {
    super.menuAboutToShow(menuManager);
    MenuManager submenuManager = null;

    submenuManager =
        new MenuManager(EclipseconEditPlugin.INSTANCE.getString("_UI_CreateChild_menu_item"));
    populateManager(submenuManager, createChildActions, null);
    menuManager.insertBefore("additions", submenuManager);

    submenuManager =
        new MenuManager(EclipseconEditPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item"));
    populateManager(submenuManager, createSiblingActions, null);
    menuManager.insertBefore("additions", submenuManager);
  }
  /**
   * This populates the pop-up menu before it appears.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  @Override
  public void menuAboutToShow(IMenuManager menuManager) {
    super.menuAboutToShow(menuManager);
    MenuManager submenuManager = null;

    submenuManager =
        new MenuManager(CoordinationEditorPlugin.INSTANCE.getString("_UI_CreateChild_menu_item"));
    populateManager(submenuManager, createChildActions, null);
    menuManager.insertBefore("edit", submenuManager);

    submenuManager =
        new MenuManager(CoordinationEditorPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item"));
    populateManager(submenuManager, createSiblingActions, null);
    menuManager.insertBefore("edit", submenuManager);
  }
  /**
   * This populates the pop-up menu before it appears.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  @Override
  public void menuAboutToShow(IMenuManager menuManager) {
    super.menuAboutToShow(menuManager);
    MenuManager submenuManager = null;

    submenuManager =
        new MenuManager(
            SimpleUMLEditPlugin.INSTANCE.getString("_UI_CreateChild_menu_item")); // $NON-NLS-1$
    populateManager(submenuManager, createChildActions, null);
    menuManager.insertBefore("edit", submenuManager); // $NON-NLS-1$

    submenuManager =
        new MenuManager(
            SimpleUMLEditPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item")); // $NON-NLS-1$
    populateManager(submenuManager, createSiblingActions, null);
    menuManager.insertBefore("edit", submenuManager); // $NON-NLS-1$
  }
  /**
   * When the active editor changes, this remembers the change and registers with it as a selection
   * provider.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  public void setActiveEditor(IEditorPart part) {
    super.setActiveEditor(part);
    activeEditorPart = part;

    // Switch to the new selection provider.
    //
    if (selectionProvider != null) {
      selectionProvider.removeSelectionChangedListener(this);
    }
    if (part == null) {
      selectionProvider = null;
    } else {
      selectionProvider = part.getSite().getSelectionProvider();
      selectionProvider.addSelectionChangedListener(this);

      // Fake a selection changed event to update the menus.
      //
      if (selectionProvider.getSelection() != null) {
        selectionChanged(
            new SelectionChangedEvent(selectionProvider, selectionProvider.getSelection()));
      }
    }
  }
  /**
   * This populates the pop-up menu before it appears.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @param menuManager the menu manager
   * @generated_not
   */
  @Override
  public void menuAboutToShow(IMenuManager menuManager) {
    super.menuAboutToShow(menuManager);

    if (generateDataSourceMenu) {
      generateDataSourceSubMenusAndActions();
      menuManager.insertBefore("edit", dsMenuManager);
      generateDataSourceMenu = false;
    }

    if (generateQueryAndOperationAndResourceMenu) {
      if (config != null && StringUtils.isNotBlank(config.getId())) {
        menuManager.insertBefore("edit", configPropertyAction);
        menuManager.insertBefore("edit", queryAction);
        menuManager.insertBefore("edit", operationAction);
        menuManager.insertBefore("edit", resourceAction);
        generateQueryAndOperationAndResourceMenu = false;

      } else {
        displayError("Enter the DataSource Id to proceed.");
      }
    }

    if (generateQueryChildrenMenu) {
      if (query != null && StringUtils.isNotBlank(query.getId())) {
        menuManager.insertBefore("edit", queryPropertyGroupAction);
        menuManager.insertBefore("edit", resultAction);

        DataServiceImpl dsImpl = (DataServiceImpl) query.eContainer();

        // Get all the config elements in the tree
        Iterator<DataSourceConfiguration> iterator = dsImpl.getDataSources().iterator();

        // Get the config element that corresponds to the selected query
        while (iterator.hasNext()) {
          config = (DataSourceConfigurationImpl) iterator.next();
          if (config.getId() != null && config.getId().equals(query.getDataSourceId())) {
            break;
          }
        }

        // Check the type of the configuration (config). If the type is
        // not a csv, excel or gspread
        // (if the type is rdbms, jndi or carbon data source) show the
        // "Add Input Parameter" menu item.
        if (config != null) {
          String confProperty = config.getConfigurationProperties().get(0).getName();
          if (!(confProperty.equals(DSActionConstants.CSV_DATASOURCE_PROPERTY)
              || confProperty.equals(DSActionConstants.EXCEL_DATASOURCE_PROPERTY)
              || confProperty.equals(DSActionConstants.GSPREAD_DATASOURCE_PROPERTY))) {
            menuManager.insertBefore("edit", inputParamAction);
          }
        }
        menuManager.insertBefore("edit", eventTriggerAction);
        generateQueryChildrenMenu = false;

      } else {
        displayError("Enter the Query Id to proceed.");
      }
    }

    if (generateSubscriptionMenu) {
      if (eventTrigger != null && StringUtils.isNotBlank(eventTrigger.getId())) {
        menuManager.insertBefore("edit", subscriptionAction);
        generateSubscriptionMenu = false;
      } else {
        displayError("Enter the Event Id to proceed.");
      }
    }

    // To add an Output Mapping to a Result element, the Grouped By Element
    // and Row Name values should be provided.
    if (generateOutputMappingMenu) {
      if (result != null
          && (result.getElementName() == null || StringUtils.isBlank(result.getElementName()))) {
        displayError("Enter value for Grouped by Element");
      } else if (result != null
          && (result.getRowName() == null || (StringUtils.isBlank(result.getRowName())))) {
        displayError("Enter value for Row Name");
      } else {
        generateOutputMappingSubMenusAndActions();
        menuManager.insertBefore("edit", outputMappingsMenuManager);
        generateOutputMappingMenu = false;
      }
    }

    if (generateCallQueryInputMappingMenu) {
      menuManager.insertBefore("edit", callQueryInputMappingAction);
      generateCallQueryInputMappingMenu = false;
    }

    if (generateValidatorMenu) {
      generateValidatorSubMenusAndActions();
      menuManager.insertBefore("edit", validatorMenuManager);
      generateValidatorMenu = false;
    }

    if (generateCallQueryMenu) {
      menuManager.insertBefore("edit", callQueryAction);
      generateCallQueryMenu = false;
    }

    if (generateQueryPropertyListMenu) {
      menuManager.insertBefore("edit", queryPropertyAction);
      generateQueryPropertyListMenu = false;
    }
  }
  /**
   * This adds to the menu bar a menu and some separators for editor additions, as well as the
   * sub-menus for object creation items.
   * <!--
   * begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @param menuManager the menu manager
   * @generated_not
   */
  @Override
  public void contributeToMenu(IMenuManager menuManager) {
    super.contributeToMenu(menuManager);

    IMenuManager submenuManager =
        new MenuManager(
            DsEditorPlugin.INSTANCE.getString("_UI_DsEditor_menu"),
            "org.wso2.carbonstudio.eclipse.dsMenuID");
    menuManager.insertAfter("additions", submenuManager);
    submenuManager.add(new Separator("settings"));
    submenuManager.add(new Separator("actions"));
    submenuManager.add(new Separator("additions"));
    submenuManager.add(new Separator("additions-end"));

    // Prepare for item addition or removal.

    if (generateDataSourceMenu) {
      submenuManager.insertBefore("additions", dsMenuManager);
    }

    if (generateQueryAndOperationAndResourceMenu) {
      submenuManager.insertBefore("additions", configPropertyAction);
      submenuManager.insertBefore("additions", queryAction);
      submenuManager.insertBefore("additions", operationAction);
      submenuManager.insertBefore("additions", resourceAction);
    }

    if (generateQueryChildrenMenu) {
      submenuManager.insertBefore("additions", resultAction);
      submenuManager.insertBefore("additions", inputParamAction);
      submenuManager.insertBefore("additions", eventTriggerAction);
      submenuManager.insertBefore("additions", queryPropertyGroupAction);
    }

    if (generateSubscriptionMenu) {
      submenuManager.insertBefore("additions", subscriptionAction);
    }

    if (generateCallQueryInputMappingMenu) {
      submenuManager.insertBefore("additions", callQueryInputMappingAction);
    }

    if (generateOutputMappingMenu) {
      submenuManager.insertBefore("additions", outputMappingsMenuManager);
    }

    if (generateCallQueryMenu) {
      submenuManager.insertBefore("additions", callQueryAction);
    }

    if (generateValidatorMenu) {
      submenuManager.insertBefore("additions", validatorMenuManager);
    }

    if (generateQueryPropertyListMenu) {
      submenuManager.insertBefore("additions", queryPropertyAction);
    }

    // Force an update because Eclipse hides empty menus now.

    submenuManager.addMenuListener(
        new IMenuListener() {
          public void menuAboutToShow(IMenuManager menuManager) {
            menuManager.updateAll(true);
          }
        });

    addGlobalActions(submenuManager);
  }