Commit e5b73694 authored by Alexander Diewald's avatar Alexander Diewald

Merge remote-tracking branch 'origin/master' into 4008

Conflicts:
	org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/.ratings
	org.fortiss.tooling.base/src/org/fortiss/tooling/base/utils/AnnotationUtils.java
Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parents dadda0ef 270f598a
ContextMenuUtil.java 6d270ba4c239c35ee487192427d02797e73ee109 GREEN
CurvedLinkLayoutedContentAnchorangeController.java e22faedbe98c3dab660b5d2df8ebd004e116c5ba GREEN CurvedLinkLayoutedContentAnchorangeController.java e22faedbe98c3dab660b5d2df8ebd004e116c5ba GREEN
CurvedLinkLayoutedDiagramAnchorangeController.java f2e5e2a7cc9b6a070871e200e57371286bb15222 GREEN CurvedLinkLayoutedDiagramAnchorangeController.java f2e5e2a7cc9b6a070871e200e57371286bb15222 GREEN
EObjectDiagramController.java 18cbb2f092409adeb728233dae6e084faf357d6d GREEN EObjectDiagramController.java 27b008c02e174d66184ba8ad76ae81b082f1069f GREEN
EObjectEllipticResizableContentControllerBase.java 958d3856daf5337cd75d0a6f163a27dcc8717160 GREEN EObjectEllipticResizableContentControllerBase.java f12e8f5a646a23fe428ed4768bf041c8b885ec81 GREEN
EObjectModelChangeProvider.java f4b60cebb088a5c81ca92a41614e1a5d40030502 GREEN EObjectModelChangeProvider.java f4b60cebb088a5c81ca92a41614e1a5d40030502 GREEN
EObjectRectangularResizableContentControllerBase.java 7cbc3e89b7b74106d56b8b4f845087e96e13d109 GREEN EObjectRectangularResizableContentControllerBase.java cde6c13659611d927691c03ecd2621cff2414b03 GREEN
KernelServiceBasedModelChangeProviderBase.java 8d1f8ef79ecd383ff74e5a2bbcf24345aabe70af GREEN KernelServiceBasedModelChangeProviderBase.java 8d1f8ef79ecd383ff74e5a2bbcf24345aabe70af GREEN
LayoutedContentAnchorageController.java 83f066a151dd2984c4bef64daf8165a0cd53b00f GREEN LayoutedContentAnchorageController.java 83f066a151dd2984c4bef64daf8165a0cd53b00f GREEN
LayoutedCurveLinkBendPointController.java d963a5e227de7bd8ba910c733df2ac7acf4fa1fa GREEN LayoutedCurveLinkBendPointController.java d963a5e227de7bd8ba910c733df2ac7acf4fa1fa GREEN
...@@ -13,5 +12,5 @@ LayoutedEllipticResizableContentController.java 1c50e80121512de7ae1f2ba09e0e1f4d ...@@ -13,5 +12,5 @@ LayoutedEllipticResizableContentController.java 1c50e80121512de7ae1f2ba09e0e1f4d
LayoutedLineLinkBendPointController.java f49c994a0c90612c44ec83d42cf858e476662e1f GREEN LayoutedLineLinkBendPointController.java f49c994a0c90612c44ec83d42cf858e476662e1f GREEN
LayoutedLinkBendPointController.java d06736b49b6ac9a073237b989895469891500e7f GREEN LayoutedLinkBendPointController.java d06736b49b6ac9a073237b989895469891500e7f GREEN
LayoutedRectangularResizableContentController.java 341f4a7da0d69360d7026af6d9b3d44dfd7d9bb1 GREEN LayoutedRectangularResizableContentController.java 341f4a7da0d69360d7026af6d9b3d44dfd7d9bb1 GREEN
ModelElementFXEditorUIProviderBase.java b81bf7fc945d40f1f842876f07ba70799ab65f6d GREEN ModelElementFXEditorUIProviderBase.java 6bdd31d033228315e99c973b4986cdabc135ec9f GREEN
NamedCommentedLayoutModelChangeProvider.java 223e82c1b1cba842f6fae115182f5d0c6acb44b0 GREEN NamedCommentedLayoutModelChangeProvider.java 223e82c1b1cba842f6fae115182f5d0c6acb44b0 GREEN
...@@ -15,10 +15,10 @@ package org.fortiss.tooling.base.ui.editor.fx.controller; ...@@ -15,10 +15,10 @@ package org.fortiss.tooling.base.ui.editor.fx.controller;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createAutoLayoutMenu; import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createAutoLayoutMenu;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createDisplayMenu; import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createDisplayMenu;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createElementCompositionContext; import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createElementCompositionContext;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createPrototypeMenu; import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createPrototypeMenu;
import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.canCompose; import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.canCompose;
import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.compose; import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.compose;
......
...@@ -15,8 +15,8 @@ package org.fortiss.tooling.base.ui.editor.fx.controller; ...@@ -15,8 +15,8 @@ package org.fortiss.tooling.base.ui.editor.fx.controller;
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createElementCompositionContext; import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createElementCompositionContext;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createPrototypeMenu; import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createPrototypeMenu;
import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.canCompose; import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.canCompose;
import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.compose; import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.compose;
......
...@@ -17,9 +17,9 @@ import static java.lang.Math.max; ...@@ -17,9 +17,9 @@ import static java.lang.Math.max;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_HEIGHT; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_HEIGHT;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_WIDTH; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_SHAPE_MINIMUM_WIDTH;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createElementCompositionContext;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createPrototypeMenu;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.RECTANGLE_INSETS; import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.RECTANGLE_INSETS;
import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createElementCompositionContext;
import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createPrototypeMenu;
import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.canCompose; import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.canCompose;
import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.compose; import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.compose;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.controller; package org.fortiss.tooling.base.ui.editor.fx.controller;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createPrototypeMenu; import static org.fortiss.tooling.base.ui.utils.ContextMenuUtils.createPrototypeMenu;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
......
AbstractNameEditingSupport.java c57336a0e0da18711a1610ca667dfea76728807f GREEN AbstractNameEditingSupport.java c57336a0e0da18711a1610ca667dfea76728807f GREEN
ActionUtils.java 322f43d4f92f992daef8ac88eb0f9197c840c89b GREEN ActionUtils.java 322f43d4f92f992daef8ac88eb0f9197c840c89b GREEN
ContextMenuUtils.java 434d6b7aad095ce726caa4de42913391ed6e6832 GREEN
DragAndDropBaseUtils.java d375377f9124f6113b2a295e6b0e09ac8966e564 GREEN DragAndDropBaseUtils.java d375377f9124f6113b2a295e6b0e09ac8966e564 GREEN
EllipseLayoutUIUtils.java 4dd9dbd96a45e8c455c019caa19e4a50f18336af GREEN EllipseLayoutUIUtils.java 4dd9dbd96a45e8c455c019caa19e4a50f18336af GREEN
FXDNDUtils.java 6ce94e239e68f9e2b3cc0524b072606f4a120076 GREEN FXDNDUtils.java 6ce94e239e68f9e2b3cc0524b072606f4a120076 GREEN
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
| See the License for the specific language governing permissions and | | See the License for the specific language governing permissions and |
| limitations under the License. | | limitations under the License. |
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.controller; package org.fortiss.tooling.base.ui.utils;
import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createPoint; import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createPoint;
...@@ -42,7 +42,7 @@ import javafx.scene.control.MenuItem; ...@@ -42,7 +42,7 @@ import javafx.scene.control.MenuItem;
* *
* @author hoelzl * @author hoelzl
*/ */
public final class ContextMenuUtil { public final class ContextMenuUtils {
/** Creates the menu populated with composable prototypes. */ /** Creates the menu populated with composable prototypes. */
public static List<MenuItem> createPrototypeMenu(EObject target, public static List<MenuItem> createPrototypeMenu(EObject target,
IElementCompositionContext context) { IElementCompositionContext context) {
...@@ -70,6 +70,21 @@ public final class ContextMenuUtil { ...@@ -70,6 +70,21 @@ public final class ContextMenuUtil {
return result; return result;
} }
/** Creates a delete menu entry */
public static MenuItem createDeleteMenu(EObject target) {
IElementCompositorService ecs = IElementCompositorService.getInstance();
ICommandStackService css = ICommandStackService.getInstance();
MenuItem deleteMenuItem = new MenuItem("Delete");
deleteMenuItem.setOnAction(evt -> {
css.runAsCommand(target, () -> {
ecs.decompose(target);
});
});
return deleteMenuItem;
}
/** Creates an auto-layout menu entry for {@link IHierarchicElement}s. */ /** Creates an auto-layout menu entry for {@link IHierarchicElement}s. */
public static MenuItem createAutoLayoutMenu(IHierarchicElement target) { public static MenuItem createAutoLayoutMenu(IHierarchicElement target) {
final String MENU_NAME = "Automatic layout"; final String MENU_NAME = "Automatic layout";
......
AnnotationEntry.java 928240a722fb5177da232619266c0d0dadcfa151 GREEN AnnotationEntry.java 928240a722fb5177da232619266c0d0dadcfa151 GREEN
AnnotationValueService.java 19906a1c7a2a33897651a0d7e207c4e5a285d2ff GREEN AnnotationValueService.java 01fc46fb381854b16ce78779217ffc7c29036c14 GREEN
IAnnotationValueService.java 50cea844f4b4ff3308ec1286ba8aadf253d2f3b1 GREEN IAnnotationValueService.java 81ff274a7b2d4c58e7b8485db857eb83f99710d0 GREEN
...@@ -156,8 +156,10 @@ public class AnnotationValueService ...@@ -156,8 +156,10 @@ public class AnnotationValueService
* Prepares the {@link AnnotationEntry} for a given {@link IModelElement} and ensures that all * Prepares the {@link AnnotationEntry} for a given {@link IModelElement} and ensures that all
* {@link IAnnotatedSpecification}s are instantiated. * {@link IAnnotatedSpecification}s are instantiated.
*/ */
private void prepareAnnotationEntry(final IModelElement element, AnnotationEntry entry, private void prepareAnnotationEntry(final IModelElement element, AnnotationEntry entry) {
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers) { final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers =
getRegisteredHandlers(element.getClass());
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) { for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) {
IAnnotatedSpecification annotatedSpecification = EcoreUtils.pickFirstInstanceOf( IAnnotatedSpecification annotatedSpecification = EcoreUtils.pickFirstInstanceOf(
...@@ -214,14 +216,16 @@ public class AnnotationValueService ...@@ -214,14 +216,16 @@ public class AnnotationValueService
getAnnotationEntry(element, false); getAnnotationEntry(element, false);
} }
/** /** {@inheritDoc} */
* Predicate if for the given {@link IModelElement}, {@link #getAnnotationEntry(IModelElement)} @Override
* will actually instantiate an annotation, i.e. modify the model. public boolean requiresAnnotationInstantiation(final IModelElement element) {
*/ final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers =
private boolean requiresAnnotationInstantiation(final IModelElement element, getRegisteredHandlers(element.getClass());
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers) { if(registeredHandlers == null) {
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) { return false;
}
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) {
IAnnotatedSpecification annotatedSpecification = pickFirstInstanceOf( IAnnotatedSpecification annotatedSpecification = pickFirstInstanceOf(
annotationProvider.getAnnotationClazz(), element.getSpecifications()); annotationProvider.getAnnotationClazz(), element.getSpecifications());
...@@ -252,30 +256,24 @@ public class AnnotationValueService ...@@ -252,30 +256,24 @@ public class AnnotationValueService
return null; return null;
} }
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers =
getRegisteredHandlers(element.getClass());
final AnnotationEntry result = new AnnotationEntry(element); final AnnotationEntry result = new AnnotationEntry(element);
if(registeredHandlers != null && !registeredHandlers.isEmpty()) {
// Wrap instantiation of new annotation into command if this method is invoked from the
final ITopLevelElement modelContext = // GUI context, i.e. from getAnnotationEntry(final IModelElement element), but only if
IPersistencyService.getInstance().getTopLevelElementFor(element); // prepareAnnotationEntry() would actually modify the underlying model, and a model
// context is available.
// Wrap instantiation of new annotation into command if this method is invoked from the final ITopLevelElement modelContext =
// GUI context, i.e. from getAnnotationEntry(final IModelElement element), but only if IPersistencyService.getInstance().getTopLevelElementFor(element);
// prepareAnnotationEntry() would actually modify the underlying model, and a model if(requiresAnnotationInstantiation(element) && modelContext != null) {
// context is available. modelContext.runAsCommand(new Runnable() {
if(requiresAnnotationInstantiation(element, registeredHandlers) &&
modelContext != null) { @Override
modelContext.runAsCommand(new Runnable() { public void run() {
prepareAnnotationEntry(element, result);
@Override }
public void run() { });
prepareAnnotationEntry(element, result, registeredHandlers); } else {
} prepareAnnotationEntry(element, result);
});
} else {
prepareAnnotationEntry(element, result, registeredHandlers);
}
} }
// Only put element into AnnotationEntry <-> IModelElement cache if method is invoked from // Only put element into AnnotationEntry <-> IModelElement cache if method is invoked from
......
...@@ -58,4 +58,12 @@ public interface IAnnotationValueService { ...@@ -58,4 +58,12 @@ public interface IAnnotationValueService {
* </p> * </p>
*/ */
void instantiateAnnotations(IModelElement element); void instantiateAnnotations(IModelElement element);
/**
* Predicate if the given {@link IModelElement} is missing some of the {@link AnnotationEntry}s
* corresponding to the {@link IAnnotatedSpecification}s declared for its type.
* Calling {@link #getAnnotationEntry(IModelElement)} will actually instantiate an annotation,
* i.e. modify the model.
*/
boolean requiresAnnotationInstantiation(final IModelElement element);
} }
AddMissingAnnotationsMigrationProvider.java ebc5b9348b61ffb23493942949ecccf1c1fa2ae1 GREEN AddMissingAnnotationsMigrationProvider.java 283f11372ce778a26362d0c83dcffdea3290b4df GREEN
RemoveDuplicatedAnnotationsMigrationProvider.java 6920909f8f211b9c5b5990644b5abcd8c4abaa3a GREEN RemoveDuplicatedAnnotationsMigrationProvider.java 6920909f8f211b9c5b5990644b5abcd8c4abaa3a GREEN
RemoveOutdatedAnnotationInstanceMigrationProvider.java 245530d6026f9ff29ffc577983d9de03ae5e75e5 GREEN RemoveOutdatedAnnotationInstanceMigrationProvider.java 245530d6026f9ff29ffc577983d9de03ae5e75e5 GREEN
...@@ -17,10 +17,13 @@ package org.fortiss.tooling.base.migration; ...@@ -17,10 +17,13 @@ package org.fortiss.tooling.base.migration;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static org.fortiss.tooling.base.utils.AnnotationUtils.instantiateAnnotationsRecursive; import static org.fortiss.tooling.base.utils.AnnotationUtils.instantiateAnnotationsRecursive;
import static org.fortiss.tooling.base.utils.AnnotationUtils.requiresAnnotationInstantiation;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstChildWith;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xml.type.AnyType; import org.eclipse.emf.ecore.xml.type.AnyType;
...@@ -45,7 +48,19 @@ public class AddMissingAnnotationsMigrationProvider implements IMigrationProvide ...@@ -45,7 +48,19 @@ public class AddMissingAnnotationsMigrationProvider implements IMigrationProvide
if(migratedProjects.contains(modelElement)) { if(migratedProjects.contains(modelElement)) {
return false; return false;
} }
return true;
Predicate<EObject> annotationTest = eObj -> {
if(eObj instanceof IModelElement &&
requiresAnnotationInstantiation((IModelElement)eObj)) {
return true;
}
return false;
};
if(getFirstChildWith(modelElement.getRootModelElement(), annotationTest) != null) {
return true;
}
return false;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
......
AngleUtils.java 462551eae71738ff51f92c9906bff9a21a375d2b GREEN AngleUtils.java 462551eae71738ff51f92c9906bff9a21a375d2b GREEN
AnnotationUtils.java 58a2a4706b9d2823022e8278fc9a9cd2692d68f8 YELLOW AnnotationUtils.java 357a9f40ee658d3ed60428e12ef35cad64f5cc53 YELLOW
BaseMathUtils.java 65f6c39b641cba3c984a38f42b1bbf7dbf3287a3 GREEN BaseMathUtils.java 65f6c39b641cba3c984a38f42b1bbf7dbf3287a3 GREEN
BaseModelElementUtils.java b8775b7a462efc168cf79a017aa3377a782d10f6 GREEN BaseModelElementUtils.java b8775b7a462efc168cf79a017aa3377a782d10f6 GREEN
DimensionUtils.java 0dc67f9de11a84e6e4c6e1eb627817dee91ff30a GREEN DimensionUtils.java 0dc67f9de11a84e6e4c6e1eb627817dee91ff30a GREEN
......
...@@ -250,4 +250,11 @@ public class AnnotationUtils { ...@@ -250,4 +250,11 @@ public class AnnotationUtils {
as.instantiateAnnotations(child); as.instantiateAnnotations(child);
} }
} }
/**
* Compact method to determine whether an {@link IModelElement} requires its annotations to be
* instantiated.
*/
public static boolean requiresAnnotationInstantiation(IModelElement element) {
return IAnnotationValueService.getInstance().requiresAnnotationInstantiation(element);
}
} }
DynamicTreeContentProviderBase.java 6760a6dc5721175b1dada8f30fd9da05f7bcc4b3 GREEN DynamicTreeContentProviderBase.java 6760a6dc5721175b1dada8f30fd9da05f7bcc4b3 GREEN
DynamicTreeItem.java 75dc5534b119ffdb3c10a65810c2a0f330b7955e GREEN DynamicTreeItem.java 75dc5534b119ffdb3c10a65810c2a0f330b7955e GREEN
DynamicTreeTableUIProviderBase.java f4fd20e3d267bc39a33a3bbb18416312779ea886 GREEN DynamicTreeTableUIProviderBase.java ea7de1e0fd824b61b46010d2317f93422bab6144 GREEN
DynamicTreeTableViewer.java 431ac62cbd6ad7df25852fce1b5a62a05ba510e3 GREEN DynamicTreeTableViewer.java 431ac62cbd6ad7df25852fce1b5a62a05ba510e3 GREEN
DynamicTreeUIProviderBase.java e9b68607683de279d0cb8712a28dc131c5c33ece GREEN DynamicTreeUIProviderBase.java e9b68607683de279d0cb8712a28dc131c5c33ece GREEN
DynamicTreeViewer.java e9f19d16a2a7e5a1b03b8a8b543453ac7eb6a051 GREEN DynamicTreeViewer.java 725f41f4fb4b6bfa813f010fb9083ab02eea164a GREEN
DynamicTreeViewerBase.java a2013538b62d86f6a09efdf2cd78babac2072484 GREEN DynamicTreeViewerBase.java a2013538b62d86f6a09efdf2cd78babac2072484 GREEN
IDoubleClickHandler.java 447f7769dead9a106b3ea3139ef0da51eb0b9a89 GREEN IDoubleClickHandler.java 447f7769dead9a106b3ea3139ef0da51eb0b9a89 GREEN
...@@ -13,15 +13,20 @@ ...@@ -13,15 +13,20 @@
*******************************************************************************/ *******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.control.treetableview; package org.fortiss.tooling.common.ui.javafx.control.treetableview;
import static org.apache.commons.lang3.SystemUtils.IS_OS_LINUX;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableCell; import javafx.scene.control.TreeTableCell;
import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.cell.TextFieldTreeTableCell; import javafx.scene.control.cell.TextFieldTreeTableCell;
import javafx.scene.input.Dragboard; import javafx.scene.input.Dragboard;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.util.Callback; import javafx.util.Callback;
import javafx.util.converter.DefaultStringConverter; import javafx.util.converter.DefaultStringConverter;
...@@ -233,15 +238,44 @@ public abstract class DynamicTreeTableUIProviderBase<T> { ...@@ -233,15 +238,44 @@ public abstract class DynamicTreeTableUIProviderBase<T> {
@Override @Override
protected void updateItem(String item, boolean empty) { protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty); super.updateItem(item, empty);
ContextMenu menu = null; ContextMenu menu = null;
Node icon = null; Node icon = null;
if(!empty && item != null) { if(!empty && item != null) {
T data = this.getTreeTableRow().getItem(); T data = this.getTreeTableRow().getItem();
menu = createContextMenu(data, colIndex);
icon = getIconNode(data, colIndex); icon = getIconNode(data, colIndex);
menu = createContextMenu(data, colIndex);
if(IS_OS_LINUX && menu != null) {
// JFX-builtin handling is non-operation in Linux.
addContextMenuHandler(menu, data);
}
} }
this.setContextMenu(menu);
this.setGraphic(icon); this.setGraphic(icon);
this.setContextMenu(menu);
}
/**
* Adds a handler for showing the context menu. Duplicate of the same method in
* {@link DynamicTreeViewer} due to the absence of proper selection interfaces in
* JFX.
*/
private void addContextMenuHandler(ContextMenu menu, T element) {
getTreeTableView().addEventHandler(MouseEvent.MOUSE_RELEASED, e -> {
if(e.getButton() == MouseButton.SECONDARY) {
TreeItem<T> selected =
getTreeTableView().getSelectionModel().getSelectedItem();
// We must check the element since all rows are evaluated.
if(selected != null && selected.getValue() == element) {
menu.show(this, e.getScreenX(), e.getScreenY());
e.consume();
}
} else {
// any other click cause hiding menu
menu.hide();
}
});
} }
}; };
cell.textProperty().bind(cell.itemProperty()); cell.textProperty().bind(cell.itemProperty());
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*******************************************************************************/ *******************************************************************************/
package org.fortiss.tooling.common.ui.javafx.control.treetableview; package org.fortiss.tooling.common.ui.javafx.control.treetableview;
import static org.apache.commons.lang3.SystemUtils.IS_OS_LINUX;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.TreeCell; import javafx.scene.control.TreeCell;
...@@ -23,6 +25,7 @@ import javafx.scene.control.TreeView; ...@@ -23,6 +25,7 @@ import javafx.scene.control.TreeView;
import javafx.scene.input.ClipboardContent; import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent; import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard; import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode; import javafx.scene.input.TransferMode;
...@@ -127,6 +130,11 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> { ...@@ -127,6 +130,11 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> {
ContextMenu menu = null; ContextMenu menu = null;
if(!empty && item != null) { if(!empty && item != null) {
menu = uiProvider.createContextMenu(item); menu = uiProvider.createContextMenu(item);
if(IS_OS_LINUX && menu != null) {
// JFX-builtin handling is non-operation in Linux.
addContextMenuHandler(menu, item);
}
this.setText(uiProvider.getLabel(item)); this.setText(uiProvider.getLabel(item));
this.setGraphic(uiProvider.getIconNode(item)); this.setGraphic(uiProvider.getIconNode(item));
this.setOnDragDetected(evt -> { this.setOnDragDetected(evt -> {
...@@ -149,6 +157,28 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> { ...@@ -149,6 +157,28 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> {
}); });
} }
/**
* Adds a handler for showing the context menu. Duplicate of the same method in
* {@link DynamicTreeTableUIProviderBase} due to the absence of proper selection interfaces in
* JFX.
*/
private void addContextMenuHandler(ContextMenu menu, T element) {
view.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> {
if(e.getButton() == MouseButton.SECONDARY) {
TreeItem<T> selected = view.getSelectionModel().getSelectedItem();
// We must check the element since all rows are evaluated.
if(selected != null && selected.getValue() == element) {
menu.show(view, e.getScreenX(), e.getScreenY());
e.consume();
}
} else {
// any other click cause hiding menu
menu.hide();
}
});
}
/** Called when an item in the tree is dragged. */ /** Called when an item in the tree is dragged. */
private void dragDetected(MouseEvent evt, TreeCell<T> cell, T item) { private void dragDetected(MouseEvent evt, TreeCell<T> cell, T item) {
ClipboardContent cbContent = uiProvider.getDragClipboardContent(item); ClipboardContent cbContent = uiProvider.getDragClipboardContent(item);
......
...@@ -8,10 +8,10 @@ FXEditorBase.java 40caf638c7b4c02da5aece0d9d58883bce630e76 GREEN ...@@ -8,10 +8,10 @@ FXEditorBase.java 40caf638c7b4c02da5aece0d9d58883bce630e76 GREEN
IListPropertySection.java 8bb00fe7959583e794ff9437b7a77404c9a9e70f GREEN IListPropertySection.java 8bb00fe7959583e794ff9437b7a77404c9a9e70f GREEN
LWFXEFEditorBase.java 86fb5b558794ffa6471ca343934592b6fa4277f6 GREEN LWFXEFEditorBase.java 86fb5b558794ffa6471ca343934592b6fa4277f6 GREEN
ModelEditorBindingBase.java b9b1a1c5a48a6e677d1f57ad55a6126d9703c4b5 GREEN ModelEditorBindingBase.java b9b1a1c5a48a6e677d1f57ad55a6126d9703c4b5 GREEN
ModelElementHandlerBase.java d0efc1e9ca2fbbefb861f1ae8176ad9ec08a08a8 GREEN ModelElementHandlerBase.java fbd38bcaec6615bcc95be7fdb847f85577c8cd47 GREEN
MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN MultiEObjectActionBase.java 9e237d8ea640c4194e4877af4a9cfce88698e543 GREEN
NamedCommentedModelElementHandlerBase.java 681b98b50b362f01abb7a36f108f4f11b9e51829 GREEN NamedCommentedModelElementHandlerBase.java 681b98b50b362f01abb7a36f108f4f11b9e51829 GREEN
PropertySectionBase.java 20fb1daea544123ea941743aafeb9ac59daf5356 GREEN PropertySectionBase.java a768b0b8f833999d31bdca1cf727f6bc48acc837 GREEN