Skip to content
Snippets Groups Projects
Commit 03fe1ebe authored by Andreas Bayha's avatar Andreas Bayha
Browse files

JavaFX Editors: Added possibility to get context menu items from service


Extended the IContextMenuService and added a util method to create
JavaFX context menu items for EObjects according to the
IContentMenuService.

Issue-ref: 4256
Issue-URL: af3#4256

Signed-off-by: default avatarAndreas Bayha <bayha@fortiss.org>
parent 38ab6bde
No related branches found
No related tags found
1 merge request!1854256
Pipeline #36401 passed
Pipeline: maven-releng

#36402

    AbstractNameEditingSupport.java c57336a0e0da18711a1610ca667dfea76728807f GREEN
    ActionUtils.java 322f43d4f92f992daef8ac88eb0f9197c840c89b GREEN
    ContextMenuUtils.java 1b4f2a63dfca9ad363942baf320c93145c251836 GREEN
    ContextMenuUtils.java ac3ce102c5b0cf00ed6ef5d91078c91581d169de YELLOW
    EllipseLayoutUIUtils.java 0af2cfc038661828b1bb8c51c0a3816d453e8313 GREEN
    FXDNDUtils.java 6ce94e239e68f9e2b3cc0524b072606f4a120076 GREEN
    FontUtils.java a167a05bdaa8da9853705cc5134f30f6d81bc9f2 GREEN
    ......
    ......@@ -21,6 +21,9 @@ import java.util.ArrayList;
    import java.util.List;
    import org.eclipse.emf.ecore.EObject;
    import org.eclipse.jface.action.ActionContributionItem;
    import org.eclipse.jface.action.IAction;
    import org.eclipse.jface.action.IContributionItem;
    import org.fortiss.tooling.base.dnd.ElementDropContext;
    import org.fortiss.tooling.base.layout.IAutoLayouter;
    import org.fortiss.tooling.base.layout.KielerAutoLayouter;
    ......@@ -33,6 +36,8 @@ import org.fortiss.tooling.kernel.service.ICommandStackService;
    import org.fortiss.tooling.kernel.service.IElementCompositorService;
    import org.fortiss.tooling.kernel.service.IPrototypeService;
    import org.fortiss.tooling.kernel.ui.extension.IModelEditor;
    import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
    import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
    import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
    import javafx.scene.control.Menu;
    ......@@ -149,4 +154,36 @@ public final class ContextMenuUtils {
    Point loc = createPoint((int)x, (int)y, "CompositionPoint");
    return new ElementDropContext(target, loc, isRoot, zoom);
    }
    /**
    * Creates javafx context {@link MenuItem}s for the given 'target' {@link EObject}, using the
    * {@link IContextMenuService}.
    *
    * @param target
    * The {@link EObject} to create context {@link MenuItem}s.
    * @param contextProvider
    * The {@link ContextMenuContextProvider} to provide for the
    * {@link IContextMenuService}.
    * @return A {@link List} of {@link MenuItem}s for the given 'target'
    */
    public static List<MenuItem> createContextMenuEntriesFromService(EObject target,
    ContextMenuContextProvider contextProvider) {
    List<MenuItem> ret = new ArrayList<MenuItem>();
    List<IContributionItem> contributions = IContextMenuService.getInstance()
    .getContextMenuContributions(target, contextProvider);
    for(IContributionItem c : contributions) {
    if(c instanceof ActionContributionItem) {
    IAction action = ((ActionContributionItem)c).getAction();
    MenuItem menuItem = new MenuItem(action.getText());
    menuItem.setOnAction(evt -> {
    action.run();
    });
    ret.add(menuItem);
    }
    }
    return ret;
    }
    }
    ActionService.java e29126b5947c9fd2f1d82bb87001b9d0ead50c3b GREEN
    ContextMenuService.java 802b6d0ade78f91478cd8959cfb423b9963d43bf GREEN
    ContextMenuService.java d6800cadce942b9b63cf2376a208aad876980b6a YELLOW
    MarkerService.java 0bfe2c67638db4e506ea5dc7680765f2a8d632e1 GREEN
    ModelEditorBindingService.java f304addb514cd2de443997e0b52cef7a3a9897bf GREEN
    ModelElementHandlerService.java 34adeef844bf98c69f1b9a7252f34d0a2b741b54 GREEN
    ......
    ......@@ -280,4 +280,22 @@ public class ContextMenuService implements IContextMenuService, IIntrospectiveKe
    public IIntrospectionDetailsItem getDetailsItem() {
    return new ContextMenuKISSDetailsItem(contextMenuContributorList);
    }
    /** {@inheritDoc} */
    @Override
    public List<IContributionItem> getContextMenuContributions(EObject element,
    ContextMenuContextProvider contextProvider) {
    List<IContributionItem> ret = new ArrayList<IContributionItem>();
    // Iterate all ContextMenuContributors to collect menu items.
    for(IContextMenuContributor contributor : contextMenuContributorList) {
    List<IContributionItem> contributions =
    contributor.getContributedItems(element, contextProvider);
    if(contributions != null) {
    ret.addAll(contributions);
    }
    }
    return ret;
    }
    }
    IActionService.java 22eafafc8708cbff7f855f7b1b9bef042c127f25 GREEN
    IContextMenuService.java cfb6b8237b6cd2b0e461991a9ceb95969f330265 GREEN
    IContextMenuService.java 63a03829f2b437e68cdc9956f7981c3aefc2f1ab YELLOW
    IMarkerService.java 82486a5656cd907926fcdf1ca1ab801290f8514c GREEN
    IModelEditorBindingService.java ce2ae1957e2232bb0fac1d1d262103f9adfc5266 GREEN
    IModelElementHandlerService.java 23353de6b85af0e9d44a1c926174fa4ed5152af0 GREEN
    ......
    ......@@ -15,6 +15,10 @@
    +--------------------------------------------------------------------------*/
    package org.fortiss.tooling.kernel.ui.service;
    import java.util.List;
    import org.eclipse.emf.ecore.EObject;
    import org.eclipse.jface.action.IContributionItem;
    import org.eclipse.jface.action.MenuManager;
    import org.eclipse.ui.IWorkbenchActionConstants;
    import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
    ......@@ -74,4 +78,19 @@ public interface IContextMenuService {
    /** Registers the given contributor with the kernel. */
    void registerContextMenuContributor(IContextMenuContributor contributor);
    /**
    * Retrieves all context menu {@link IContributionItem}s for the given 'element' and the given
    * 'ContextProvider'.
    *
    * @param element
    * The {@link EObject} to get the menu contributions for.
    * @param contextProvider
    * The {@link ContextMenuContextProvider} to adhere when getting the contect menu
    * contibutions.
    * @return A {@link List} if {@link IContributionItem} for the given 'element' and the given
    * 'contentProvider'.
    */
    public List<IContributionItem> getContextMenuContributions(EObject element,
    ContextMenuContextProvider contextProvider);
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment