| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque, |
| * Segastien Gemme - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.rcp.mainmenu.processors; |
| |
| import javax.inject.Inject; |
| |
| import org.eclipse.e4.core.contexts.IEclipseContext; |
| import org.eclipse.e4.core.di.annotations.Execute; |
| import org.eclipse.e4.core.di.annotations.Optional; |
| import org.eclipse.e4.ui.model.application.MApplication; |
| import org.eclipse.e4.ui.model.application.ui.menu.MMenu; |
| import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| public class MainMenuProcessor { |
| |
| private static final Logger Logger = LoggerFactory.getLogger(MainMenuProcessor.class); |
| |
| @Inject |
| protected MApplication app; |
| |
| @Execute |
| public void run(@Optional IEclipseContext context, MApplication app) { |
| /** |
| * This is used to fix the known e4 error that makes the menu dissapear when |
| * restarting the application. |
| */ |
| try { |
| MMenu menu = app.getChildren().get(0).getMainMenu(); |
| if (menu == null) { |
| menu = MMenuFactory.INSTANCE.createMenu(); |
| menu.setElementId("org.eclipse.ui.main.menu"); |
| app.getChildren().get(0).setMainMenu(menu); |
| } |
| } catch (Exception e) { |
| Logger.error("Error during the initialization of the main menu.", e); |
| } |
| } |
| } |