Search in sources :

Example 1 with Main

use of aero.minova.rcp.form.menu.mdi.Main in project aero.minova.rcp by minova-afis.

the class MenuProcessor method processXML.

private void processXML(String fileContent) {
    Main mainMDI = null;
    MMenuContribution menuContribution = modelService.createModelElement(MMenuContribution.class);
    menuContribution.setParentId("org.eclipse.ui.main.menu");
    menuContribution.setPositionInParent("after=additions");
    menuContribution.setElementId("generated" + menuId++);
    menuContribution.getPersistedState().put("persistState", "false");
    mApplication.getMenuContributions().add(menuContribution);
    try {
        mainMDI = XmlProcessor.get(fileContent, Main.class);
        List<Object> menuOrEntry = mainMDI.getMenu().getMenuOrEntry();
        if (!menuOrEntry.isEmpty()) {
            HashMap<String, Action> actionsMDI = new HashMap<>();
            if (mainMDI.getAction() != null && !mainMDI.getAction().isEmpty()) {
                for (Action action : mainMDI.getAction()) {
                    actionsMDI.put(action.getId(), action);
                }
            }
            for (Object object : menuOrEntry) {
                if (object instanceof MenuType) {
                    MMenu createMenu = createMenu((MenuType) object, actionsMDI, modelService, mApplication);
                    menuContribution.getChildren().add(createMenu);
                }
            }
        }
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}
Also used : Action(aero.minova.rcp.form.menu.mdi.Main.Action) MenuType(aero.minova.rcp.form.menu.mdi.MenuType) HashMap(java.util.HashMap) JAXBException(javax.xml.bind.JAXBException) MMenuContribution(org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution) Main(aero.minova.rcp.form.menu.mdi.Main) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu)

Example 2 with Main

use of aero.minova.rcp.form.menu.mdi.Main in project aero.minova.rcp by minova-afis.

the class MenuTest method openPreferencesAndTestMenu.

@Test
public void openPreferencesAndTestMenu() {
    if (System.getProperty("os.name").startsWith("Linux")) {
        return;
    }
    // Einstellungen über Command öffnen
    Display.getDefault().asyncExec(() -> {
        ECommandService commandService = getEclipseContext().get(ECommandService.class);
        EHandlerService handlerService = getEclipseContext().get(EHandlerService.class);
        ParameterizedCommand cmd = commandService.createCommand("org.eclipse.ui.window.preferences", null);
        handlerService.executeHandler(cmd);
    });
    // Workspace-Ordner auslesen
    SWTBotShell shell = bot.shell("Preferences");
    assertNotNull(shell);
    SWTBot childBot = new SWTBot(shell.widget);
    SWTBotText currentWorkspaceText = childBot.text(1);
    assertNotNull(currentWorkspaceText);
    assertNotNull(currentWorkspaceText.getText());
    String pathWorkspace = currentWorkspaceText.getText();
    shell.close();
    // application.mdi einlesen und Menü überprüfen
    try {
        Path path = Path.of(pathWorkspace, "application.mdi");
        String applicationString = Files.readString(path);
        assertNotNull(applicationString);
        Main mainMDI = XmlProcessor.get(applicationString, Main.class);
        assertNotNull(mainMDI);
        // Liste mit Menueinträgen (depth-first)
        List<String> menuEntries = new ArrayList<>();
        Map<String, Integer> callsToMenu = new HashMap<>();
        SWTBotRootMenu menu = bot.menu();
        for (String menuEntry : menu.menuItems()) {
            int i = callsToMenu.get(menuEntry) == null ? 0 : callsToMenu.get(menuEntry);
            callsToMenu.put(menuEntry, i + 1);
            SWTBotMenu menu2 = bot.menu().menu(menuEntry, false, i);
            // File Menü überspringen (nicht von uns)
            if (menu2.getText().equals("File")) {
                continue;
            }
            getMenuEntries(menuEntries, menu2);
        }
        // TODO Reihenfolge in der mdi beachten (siehe MenuProcessor)
        int counter = 0;
        for (Object menuOrEntry : mainMDI.getMenu().getMenuOrEntry()) {
            counter = checkEntries(menuEntries, counter, menuOrEntry);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) EHandlerService(org.eclipse.e4.core.commands.EHandlerService) SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) HashMap(java.util.HashMap) SWTBotText(org.eclipse.swtbot.swt.finder.widgets.SWTBotText) ArrayList(java.util.ArrayList) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) SWTBotRootMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotRootMenu) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) Main(aero.minova.rcp.form.menu.mdi.Main) ECommandService(org.eclipse.e4.core.commands.ECommandService) Test(org.junit.jupiter.api.Test)

Aggregations

Main (aero.minova.rcp.form.menu.mdi.Main)2 HashMap (java.util.HashMap)2 Action (aero.minova.rcp.form.menu.mdi.Main.Action)1 MenuType (aero.minova.rcp.form.menu.mdi.MenuType)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 ECommandService (org.eclipse.e4.core.commands.ECommandService)1 EHandlerService (org.eclipse.e4.core.commands.EHandlerService)1 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)1 MMenuContribution (org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution)1 SWTBot (org.eclipse.swtbot.swt.finder.SWTBot)1 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)1 SWTBotRootMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotRootMenu)1 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)1 SWTBotText (org.eclipse.swtbot.swt.finder.widgets.SWTBotText)1 Test (org.junit.jupiter.api.Test)1