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();
}
}
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;
}
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);
}
}
}
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;
}
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);
}
}
Aggregations