diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/.ratings index 44d98da2ce23984aca266213e16a1a4c86a2522e..ad72377a790650658c2f3dafe4a165f41877507f 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/.ratings @@ -1,6 +1,6 @@ AbstractNameEditingSupport.java c57336a0e0da18711a1610ca667dfea76728807f GREEN ActionUtils.java 322f43d4f92f992daef8ac88eb0f9197c840c89b GREEN -ContextMenuUtils.java 1b4f2a63dfca9ad363942baf320c93145c251836 GREEN +ContextMenuUtils.java ac3ce102c5b0cf00ed6ef5d91078c91581d169de GREEN EllipseLayoutUIUtils.java 0af2cfc038661828b1bb8c51c0a3816d453e8313 GREEN FXDNDUtils.java 6ce94e239e68f9e2b3cc0524b072606f4a120076 GREEN FontUtils.java a167a05bdaa8da9853705cc5134f30f6d81bc9f2 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ContextMenuUtils.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ContextMenuUtils.java index 1b4f2a63dfca9ad363942baf320c93145c251836..ac3ce102c5b0cf00ed6ef5d91078c91581d169de 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ContextMenuUtils.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ContextMenuUtils.java @@ -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; + } } diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings index 8739f2bf5878a44bafe2c3ecf21573c59fbe563a..e547130574950ec69e1bdafc20cbb1261387f84b 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings @@ -5,7 +5,7 @@ DynamicTextFieldTreeTableCell.java 62fa0c08b11d87e0eed41f84be85505c2740e75d GREE DynamicTreeContentProviderBase.java 91896b1fb5104d126544c44c1ff8c30f2a13a8d6 GREEN DynamicTreeItem.java 7e81ea98038b5eca90df583e0268d4e8f37aaf25 GREEN DynamicTreeItemBase.java d883066ecc181120302ca32f328538de7a45b093 GREEN -DynamicTreeTableUIProviderBase.java 29aa753793ab90676d45e5b76b11f7b46ce02a97 GREEN +DynamicTreeTableUIProviderBase.java 360df9d5114c5d4a391a7a7afe70a5b8ad584490 GREEN DynamicTreeTableViewer.java 77e9995a3bee37d57578dad9434a53c702128efa YELLOW DynamicTreeUIProviderBase.java 82d3c051213f0147f4c67ad247a08696cee73110 GREEN DynamicTreeViewer.java 33066062a82101cf28410e4d04f85bb9c24251db GREEN diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java index 29aa753793ab90676d45e5b76b11f7b46ce02a97..360df9d5114c5d4a391a7a7afe70a5b8ad584490 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java @@ -322,6 +322,8 @@ public abstract class DynamicTreeTableUIProviderBase<T> { final Node icon = getIconNode(data, columnIndex); cell.setGraphic(icon); cell.setStyle(getCellStyle(data, columnIndex)); + + addContextMenuToCell(cell, columnIndex); } else { // reset icon for cases, in which a row was styled before, but became empty by now. cell.setGraphic(null); @@ -585,7 +587,7 @@ public abstract class DynamicTreeTableUIProviderBase<T> { * @param columnIndex * The column index of the given {@code cell}. */ - private void addContextMenuToCell(TreeTableCell<T, String> cell, int columnIndex) { + private void addContextMenuToCell(TreeTableCell<T, ?> cell, int columnIndex) { ContextMenu menu; T data = cell.getTreeTableRow().getItem(); @@ -603,7 +605,7 @@ public abstract class DynamicTreeTableUIProviderBase<T> { * {@link DynamicTreeViewer} due to the absence of proper selection interfaces in * JFX. */ - private void addContextMenuHandler(TreeTableCell<T, String> cell, ContextMenu menu, T element) { + private void addContextMenuHandler(TreeTableCell<T, ?> cell, ContextMenu menu, T element) { cell.getTreeTableView().addEventHandler(MouseEvent.MOUSE_RELEASED, e -> { if(e.getButton() == MouseButton.SECONDARY) { TreeItem<T> selected = diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/.ratings index d9c3d05742cc133f0d46752e4a9b6cb5ecd0d917..473d4378f0755d6597fb8c8a5f1baff1cb642eb7 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/.ratings @@ -1,5 +1,5 @@ ActionService.java e29126b5947c9fd2f1d82bb87001b9d0ead50c3b GREEN -ContextMenuService.java 9021e4eeb5d7be5d73d87e5947564bdf17f07b9d GREEN +ContextMenuService.java 16b469599cb8723a433bc97b88dc4a558b25568e GREEN MarkerService.java 0bfe2c67638db4e506ea5dc7680765f2a8d632e1 GREEN ModelEditorBindingService.java f304addb514cd2de443997e0b52cef7a3a9897bf GREEN ModelElementHandlerService.java 34adeef844bf98c69f1b9a7252f34d0a2b741b54 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ContextMenuService.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ContextMenuService.java index 9021e4eeb5d7be5d73d87e5947564bdf17f07b9d..16b469599cb8723a433bc97b88dc4a558b25568e 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ContextMenuService.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/ContextMenuService.java @@ -291,4 +291,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; + } } diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/.ratings index 5f78c6d9fe37070a5afe685ff64ce894d927ffbf..7b0c011d7d961e617bd33493159f8f7038cfa48a 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/.ratings @@ -1,5 +1,5 @@ IActionService.java 22eafafc8708cbff7f855f7b1b9bef042c127f25 GREEN -IContextMenuService.java cfb6b8237b6cd2b0e461991a9ceb95969f330265 GREEN +IContextMenuService.java b28f2b7e7375901a88b420654317c61d3d58d02c GREEN IMarkerService.java 82486a5656cd907926fcdf1ca1ab801290f8514c GREEN IModelEditorBindingService.java ce2ae1957e2232bb0fac1d1d262103f9adfc5266 GREEN IModelElementHandlerService.java 23353de6b85af0e9d44a1c926174fa4ed5152af0 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/IContextMenuService.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/IContextMenuService.java index cfb6b8237b6cd2b0e461991a9ceb95969f330265..b28f2b7e7375901a88b420654317c61d3d58d02c 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/IContextMenuService.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/service/IContextMenuService.java @@ -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 context 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); }