Search in sources :

Example 1 with Action

use of aero.minova.rcp.form.menu.mdi.Main.Action 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 Action

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

the class MenuProcessor method createMenu.

/**
 * Diese Methode erstellt aus dem übergebenen menu ein MMenu inklusiver der Einträge
 *
 * @param menu_MDI
 * @param menu
 * @param actions_MDI
 * @param modelService
 * @param mApplication
 */
private MMenu createMenu(MenuType menu_MDI, HashMap<String, Action> actions_MDI, EModelService modelService, MApplication mApplication) {
    MMenu menuGen = modelService.createModelElement(MMenu.class);
    menuGen.getPersistedState().put("persistState", String.valueOf(false));
    menuGen.setElementId("generated" + menuId++);
    menuGen.setLabel(menu_MDI.getText());
    // TODO Sortierung des MENUS aus der MDI beachten!!!
    if (!menu_MDI.getEntryOrMenu().isEmpty() && menu_MDI.getEntryOrMenu() != null) {
        for (Object object : menu_MDI.getEntryOrMenu()) {
            if (object instanceof Entry) {
                Entry entryMDI = (Entry) object;
                if (!entryMDI.getType().equals("separator")) {
                    String id2 = ((Action) entryMDI.getId()).getId();
                    MHandledMenuItem handledMenuItem = createMenuEntry(entryMDI, actions_MDI.get(id2), modelService, mApplication);
                    menuGen.getChildren().add(handledMenuItem);
                }
            }
        }
    }
    return menuGen;
}
Also used : Entry(aero.minova.rcp.form.menu.mdi.Main.Entry) Action(aero.minova.rcp.form.menu.mdi.Main.Action) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu)

Example 3 with Action

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

the class MenuTest method checkEntries.

private int checkEntries(List<String> entries, int counter, Object menuOrEntry) {
    if (menuOrEntry instanceof MenuType) {
        String translated = translationService.translate(((MenuType) menuOrEntry).getText(), null);
        assertEquals(translated, entries.get(counter));
        counter++;
        for (Object o : ((MenuType) menuOrEntry).getEntryOrMenu()) {
            counter = checkEntries(entries, counter, o);
        }
    } else {
        Entry entry = (Entry) menuOrEntry;
        if (entry.getId() instanceof Action) {
            String name = ((Action) entry.getId()).getText();
            String translated = translationService.translate(name, null);
            assertEquals(translated, entries.get(counter));
            counter++;
        }
    }
    return counter;
}
Also used : Entry(aero.minova.rcp.form.menu.mdi.Main.Entry) Action(aero.minova.rcp.form.menu.mdi.Main.Action) MenuType(aero.minova.rcp.form.menu.mdi.MenuType)

Aggregations

Action (aero.minova.rcp.form.menu.mdi.Main.Action)3 Entry (aero.minova.rcp.form.menu.mdi.Main.Entry)2 MenuType (aero.minova.rcp.form.menu.mdi.MenuType)2 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)2 Main (aero.minova.rcp.form.menu.mdi.Main)1 HashMap (java.util.HashMap)1 JAXBException (javax.xml.bind.JAXBException)1 MHandledMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem)1 MMenuContribution (org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution)1