Search in sources :

Example 1 with MMenuContribution

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution 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 MMenuContribution

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution in project eclipse.platform.ui by eclipse-platform.

the class ContributionsAnalyzer method processAddition.

public static boolean processAddition(final MMenu menuModel, final ArrayList<MMenuElement> menuContributionsToRemove, MMenuContribution menuContribution, final HashSet<String> existingMenuIds, HashSet<String> existingSeparatorNames) {
    int idx = getIndex(menuModel, menuContribution.getPositionInParent());
    if (idx == -1) {
        return false;
    }
    for (MMenuElement item : menuContribution.getChildren()) {
        if (item instanceof MMenu && existingMenuIds.contains(item.getElementId())) {
            // skip this, it's already there
            continue;
        } else if (item instanceof MMenuSeparator && existingSeparatorNames.contains(item.getElementId())) {
            // skip this, it's already there
            continue;
        }
        MMenuElement copy = (MMenuElement) EcoreUtil.copy((EObject) item);
        if (DEBUG) {
            // $NON-NLS-1$
            trace("addMenuContribution " + copy, menuModel.getWidget(), menuModel);
        }
        menuContributionsToRemove.add(copy);
        menuModel.getChildren().add(idx++, copy);
        if (copy instanceof MMenu && copy.getElementId() != null) {
            existingMenuIds.add(copy.getElementId());
        } else if (copy instanceof MMenuSeparator && copy.getElementId() != null) {
            existingSeparatorNames.add(copy.getElementId());
        }
    }
    return true;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) MMenuSeparator(org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MMenuElement(org.eclipse.e4.ui.model.application.ui.menu.MMenuElement)

Example 3 with MMenuContribution

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution in project eclipse.platform.ui by eclipse-platform.

the class MenuManagerRenderer method processContributions.

/**
 * @param menuModel
 * @param isMenuBar
 * @param isPopup
 */
public void processContributions(MMenu menuModel, String elementId, boolean isMenuBar, boolean isPopup) {
    if (elementId == null) {
        return;
    }
    final ArrayList<MMenuContribution> toContribute = new ArrayList<>();
    ContributionsAnalyzer.XXXgatherMenuContributions(menuModel, application.getMenuContributions(), elementId, toContribute, null, isPopup);
    generateContributions(menuModel, toContribute, isMenuBar);
    for (MMenuElement element : menuModel.getChildren()) {
        if (element instanceof MMenu) {
            processContributions((MMenu) element, element.getElementId(), false, isPopup);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MMenuContribution(org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MMenuElement(org.eclipse.e4.ui.model.application.ui.menu.MMenuElement)

Example 4 with MMenuContribution

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution in project eclipse.platform.ui by eclipse-platform.

the class MenuManagerRenderer method processAddition.

/**
 * @param menuModel
 * @param manager
 * @param menuContribution
 * @return true if the menuContribution was processed
 */
private boolean processAddition(MMenu menuModel, final MenuManager manager, MMenuContribution menuContribution, boolean menuBar) {
    final ContributionRecord record = new ContributionRecord(menuModel, menuContribution, this);
    if (!record.mergeIntoModel()) {
        return false;
    }
    if (menuBar || isPartMenu(menuModel)) {
        final IEclipseContext parentContext = getContext(menuModel);
        parentContext.runAndTrack(new RunAndTrack() {

            @Override
            public boolean changed(IEclipseContext context) {
                record.updateVisibility(parentContext.getActiveLeaf());
                scheduleManagerUpdate(manager);
                return true;
            }
        });
    }
    return true;
}
Also used : RunAndTrack(org.eclipse.e4.core.contexts.RunAndTrack) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 5 with MMenuContribution

use of org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution in project eclipse.platform.ui by eclipse-platform.

the class CocoaUIHandler method monitorMenuContributionsChanges.

/**
 * Watch for new menu contributions
 */
@Inject
@Optional
private void monitorMenuContributionsChanges(@UIEventTopic(UIEvents.MenuContributions.TOPIC_MENUCONTRIBUTIONS) Event event) {
    if (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuContribution && event.getProperty(UIEvents.EventTags.NEW_VALUE) != null) {
        MMenuContribution contribution = (MMenuContribution) event.getProperty(UIEvents.EventTags.ELEMENT);
        processMenuContribution(contribution);
    }
}
Also used : MMenuContribution(org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Aggregations

MMenuContribution (org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution)16 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)8 ArrayList (java.util.ArrayList)6 MMenuElement (org.eclipse.e4.ui.model.application.ui.menu.MMenuElement)6 MMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MMenuItem)3 MMenuSeparator (org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator)3 EObject (org.eclipse.emf.ecore.EObject)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 ContextFunction (org.eclipse.e4.core.contexts.ContextFunction)2 MApplication (org.eclipse.e4.ui.model.application.MApplication)2 MCoreExpression (org.eclipse.e4.ui.model.application.ui.MCoreExpression)2 MPopupMenu (org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu)2 MenuManager (org.eclipse.jface.action.MenuManager)2 Main (aero.minova.rcp.form.menu.mdi.Main)1 Action (aero.minova.rcp.form.menu.mdi.Main.Action)1 MenuType (aero.minova.rcp.form.menu.mdi.MenuType)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1