diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/.ratings index ef8aadc0677a7162ed8e0097cccf227e2fbd2fc4..eaf0f35f62bbb52f044234f5a81e2553c34f8456 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/.ratings @@ -8,3 +8,4 @@ LayoutedContentAnchorageController.java 73b103c06edcbf1762654e71a3e524f43c0c50c0 LayoutedDiagramAnchorageController.java 32d7d77daf252d021458c39ebcfe502f26f29a98 YELLOW LayoutedLinkBendPointController.java 6d5de856f513ca82eab805a0ad9cda8194be011d YELLOW LayoutedRectangularResizableContentController.java 3232d423572924363702898cf8ba240ce7042b65 YELLOW +ModelElementFXEditorUIProviderBase.java b81bf7fc945d40f1f842876f07ba70799ab65f6d YELLOW diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/ModelElementFXEditorUIProviderBase.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/ModelElementFXEditorUIProviderBase.java new file mode 100644 index 0000000000000000000000000000000000000000..b81bf7fc945d40f1f842876f07ba70799ab65f6d --- /dev/null +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/ModelElementFXEditorUIProviderBase.java @@ -0,0 +1,73 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2020 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.base.ui.editor.fx.controller; + +import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createPrototypeMenu; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.fortiss.tooling.base.model.element.IModelElement; +import org.fortiss.tooling.common.ui.javafx.control.treetableview.DynamicTreeTableUIProviderBase; +import org.fortiss.tooling.kernel.ui.extension.base.FXEditorBase; +import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; + +import javafx.scene.Node; +import javafx.scene.control.ContextMenu; + +/** + * Base implementation for FX UIProvider for ModelElements. + * + * @author bayha + */ +public abstract class ModelElementFXEditorUIProviderBase<T extends IModelElement> + extends DynamicTreeTableUIProviderBase<T> { + + /** The editor used to post selection changes. */ + protected final FXEditorBase<?> editor; + + /** Constructor. */ + public ModelElementFXEditorUIProviderBase(FXEditorBase<?> editor) { + this.editor = editor; + } + + /** {@inheritDoc} */ + @Override + public Node getIconNode(IModelElement element, int column) { + if(element == null) { + return null; + } + return IModelElementHandlerService.getInstance().getFXIcon(element); + } + + /** {@inheritDoc} */ + @Override + public ContextMenu createContextMenu(IModelElement element, int column) { + if(element == null || column != 0) { + return null; + } + ContextMenu contextMenu = new ContextMenu(); + contextMenu.getItems().addAll(createPrototypeMenu(element, null)); + return contextMenu; + } + + /** {@inheritDoc} */ + @Override + public void select(IModelElement oldValue, IModelElement newValue) { + IStructuredSelection selection = + newValue == null ? StructuredSelection.EMPTY : new StructuredSelection(newValue); + editor.getSite().getSelectionProvider().setSelection(selection); + } +}