Search in sources :

Example 1 with MHandledToolItem

use of org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem in project aero.minova.rcp by minova-afis.

the class WFCDetailPart method createToolItemInPartToolbar.

private ButtonAccessor createToolItemInPartToolbar(aero.minova.rcp.form.model.xsd.Button btn) {
    // Kein Gruppenname: Element nur in Toolbar, kein Menü
    if (btn.getGroup() == null) {
        MHandledToolItem handledToolItem = eModelService.createModelElement(MHandledToolItem.class);
        fillMHandledItemWithValues(handledToolItem, btn);
        mPart.getToolbar().getChildren().add(handledToolItem);
        return new ButtonAccessor(handledToolItem);
    }
    // Menü für Gruppennamen finden
    MMenu groupMenu = null;
    if (btn.getGroup() != null) {
        for (MToolBarElement element : mPart.getToolbar().getChildren()) {
            if (btn.getGroup().equalsIgnoreCase(element.getPersistedState().get(Constants.GROUP_NAME))) {
                groupMenu = ((MHandledToolItem) element).getMenu();
                break;
            }
        }
    }
    MHandledToolItem handledToolItem = null;
    // Erstes Vorkommen des Gruppennamens: Element in Toolbar, Menü muss noch erstellt werden
    if (groupMenu == null) {
        handledToolItem = eModelService.createModelElement(MHandledToolItem.class);
        fillMHandledItemWithValues(handledToolItem, btn);
        mPart.getToolbar().getChildren().add(handledToolItem);
        groupMenu = eModelService.createModelElement(MMenu.class);
        handledToolItem.getPersistedState().put(Constants.GROUP_NAME, btn.getGroup());
        handledToolItem.setMenu(groupMenu);
    }
    // Wenn Gruppenname gegeben ist soll der Button immer auch in das Dropdown-Menü
    MHandledMenuItem menuEntry = eModelService.createModelElement(MHandledMenuItem.class);
    fillMHandledItemWithValues(menuEntry, btn);
    groupMenu.getChildren().add(menuEntry);
    return new ButtonAccessor(handledToolItem, menuEntry);
}
Also used : ButtonAccessor(aero.minova.rcp.rcp.accessor.ButtonAccessor) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) MToolBarElement(org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement) MHandledToolItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu)

Example 2 with MHandledToolItem

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

the class ProgrammaticProgressView method createViewMenu.

private void createViewMenu() {
    MHandledToolItem clearAllButton = modelService.createModelElement(MHandledToolItem.class);
    clearAllButton.setIconURI(CLEAR_ALL_ICON_URI);
    clearAllButton.setCommand(clearAllCommand);
    MToolBar toolBar = modelService.createModelElement(MToolBar.class);
    toolBar.getChildren().add(clearAllButton);
    part.setToolbar(toolBar);
    MHandledMenuItem clearAllMenuItem = modelService.createModelElement(MHandledMenuItem.class);
    // $NON-NLS-1$
    clearAllMenuItem.setLabel("Clear All");
    clearAllMenuItem.setIconURI(CLEAR_ALL_ICON_URI);
    clearAllMenuItem.setCommand(clearAllCommand);
    MHandledMenuItem preferencesMenuItem = modelService.createModelElement(MHandledMenuItem.class);
    // $NON-NLS-1$
    preferencesMenuItem.setLabel("Preferences");
    preferencesMenuItem.setCommand(showPreferencesCommand);
    MMenu menu = modelService.createModelElement(MMenu.class);
    // required //$NON-NLS-1$
    menu.getTags().add("ViewMenu");
    menu.getChildren().add(clearAllMenuItem);
    menu.getChildren().add(preferencesMenuItem);
    part.getMenus().add(menu);
}
Also used : MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) MHandledMenuItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem) MHandledToolItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu)

Example 3 with MHandledToolItem

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

the class ToolBarManagerRenderer method processHandledItem.

private void processHandledItem(ToolBarManager parentManager, MHandledToolItem itemModel) {
    IContributionItem ici = getContribution(itemModel);
    if (ici != null) {
        return;
    }
    itemModel.setRenderer(this);
    final IEclipseContext lclContext = getContext(itemModel);
    HandledContributionItem ci = ContextInjectionFactory.make(HandledContributionItem.class, lclContext);
    ci.setModel(itemModel);
    ci.setVisible(itemModel.isVisible());
    addToManager(parentManager, itemModel, ci);
    linkModelToContribution(itemModel, ci);
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 4 with MHandledToolItem

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

the class ToolBarManagerRenderer method modelProcessSwitch.

private void modelProcessSwitch(ToolBarManager parentManager, MToolBarElement childME) {
    if (!childME.isToBeRendered()) {
        return;
    }
    if (OpaqueElementUtil.isOpaqueToolItem(childME)) {
        MToolItem itemModel = (MToolItem) childME;
        processOpaqueItem(parentManager, itemModel);
    } else if (childME instanceof MHandledToolItem) {
        MHandledToolItem itemModel = (MHandledToolItem) childME;
        processHandledItem(parentManager, itemModel);
    } else if (childME instanceof MDirectToolItem) {
        MDirectToolItem itemModel = (MDirectToolItem) childME;
        processDirectItem(parentManager, itemModel);
    } else if (childME instanceof MToolBarSeparator) {
        MToolBarSeparator itemModel = (MToolBarSeparator) childME;
        processSeparator(parentManager, itemModel);
    } else if (childME instanceof MToolControl) {
        MToolControl itemModel = (MToolControl) childME;
        processToolControl(parentManager, itemModel);
    }
}
Also used : MToolItem(org.eclipse.e4.ui.model.application.ui.menu.MToolItem) MToolControl(org.eclipse.e4.ui.model.application.ui.menu.MToolControl) MDirectToolItem(org.eclipse.e4.ui.model.application.ui.menu.MDirectToolItem) MToolBarSeparator(org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator) MHandledToolItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem)

Example 5 with MHandledToolItem

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

the class ModelAssemblerFragmentOrderingTests method testIncorrectIndexNotEmptyApplication.

@Test
public void testIncorrectIndexNotEmptyApplication() {
    // initial application elements
    MHandledToolItem x = MMenuFactory.INSTANCE.createHandledToolItem();
    x.setElementId("x");
    toolBar.getChildren().add(x);
    MHandledToolItem y = MMenuFactory.INSTANCE.createHandledToolItem();
    y.setElementId("y");
    toolBar.getChildren().add(y);
    MHandledToolItem z = MMenuFactory.INSTANCE.createHandledToolItem();
    z.setElementId("z");
    toolBar.getChildren().add(z);
    // the fragments
    Resource fragmentResource = factory.createResource(URI.createURI("fragmentvirtualuri"));
    resourceSet.getResources().add(fragmentResource);
    final String contributorName = "testIncorrectIndex1";
    final String contributorURI = fragmentResource.getURI().toString();
    // the contributed elements
    MHandledToolItem a = MMenuFactory.INSTANCE.createHandledToolItem();
    a.setElementId("a");
    MModelFragments fragmentsContainerA = MFragmentFactory.INSTANCE.createModelFragments();
    fragmentResource.getContents().add((EObject) fragmentsContainerA);
    ModelFragmentWrapper fragmentWrapperA = createFragmentWrapper(fragmentsContainerA, "children", MAIN_TOOLBAR_ID, Arrays.asList(a), "index:-70", contributorName, contributorURI, false);
    MHandledToolItem b = MMenuFactory.INSTANCE.createHandledToolItem();
    b.setElementId("b");
    MModelFragments fragmentsContainerB = MFragmentFactory.INSTANCE.createModelFragments();
    fragmentResource.getContents().add((EObject) fragmentsContainerB);
    ModelFragmentWrapper fragmentWrapperB = createFragmentWrapper(fragmentsContainerB, "children", MAIN_TOOLBAR_ID, Arrays.asList(b), "index:70", contributorName, contributorURI, false);
    Set<ModelFragmentWrapper> fragmentList = new TreeSet<>(new ModelFragmentComparator(application));
    fragmentList.addAll(Arrays.asList(fragmentWrapperA, fragmentWrapperB));
    Iterator<ModelFragmentWrapper> iterator = fragmentList.iterator();
    assertEquals(fragmentWrapperA, iterator.next());
    assertEquals(fragmentWrapperB, iterator.next());
    assertEquals(3, toolBar.getChildren().size());
    assertEquals(x, toolBar.getChildren().get(0));
    assertEquals(y, toolBar.getChildren().get(1));
    assertEquals(z, toolBar.getChildren().get(2));
    assembler.processFragmentWrappers(fragmentList);
    assertEquals(5, toolBar.getChildren().size());
    assertEquals(a, toolBar.getChildren().get(3));
    assertEquals(b, toolBar.getChildren().get(4));
}
Also used : TreeSet(java.util.TreeSet) E4XMIResource(org.eclipse.e4.ui.internal.workbench.E4XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) ModelFragmentComparator(org.eclipse.e4.ui.internal.workbench.ModelFragmentComparator) MHandledToolItem(org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem) ModelFragmentWrapper(org.eclipse.e4.ui.internal.workbench.ModelFragmentWrapper) MModelFragments(org.eclipse.e4.ui.model.fragment.MModelFragments) Test(org.junit.Test)

Aggregations

MHandledToolItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledToolItem)44 TreeSet (java.util.TreeSet)35 E4XMIResource (org.eclipse.e4.ui.internal.workbench.E4XMIResource)35 ModelFragmentComparator (org.eclipse.e4.ui.internal.workbench.ModelFragmentComparator)35 ModelFragmentWrapper (org.eclipse.e4.ui.internal.workbench.ModelFragmentWrapper)35 MModelFragments (org.eclipse.e4.ui.model.fragment.MModelFragments)35 Resource (org.eclipse.emf.ecore.resource.Resource)35 Test (org.junit.Test)35 MCommand (org.eclipse.e4.ui.model.application.commands.MCommand)3 MMenu (org.eclipse.e4.ui.model.application.ui.menu.MMenu)3 MToolBarElement (org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement)3 MParameter (org.eclipse.e4.ui.model.application.commands.MParameter)2 MHandledMenuItem (org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem)2 MToolBar (org.eclipse.e4.ui.model.application.ui.menu.MToolBar)2 MToolItem (org.eclipse.e4.ui.model.application.ui.menu.MToolItem)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 ButtonAccessor (aero.minova.rcp.rcp.accessor.ButtonAccessor)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1