Skip to content
Snippets Groups Projects
Commit 4286d713 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Kernel: added DND utility class.

parent 579ccc19
No related branches found
No related tags found
1 merge request!923921
ContextMenuUtil.java 405387151d45b09dffb3b6ba44f980313c8edcaf GREEN
CurvedLinkLayoutedContentAnchorangeController.java 67c20e31ddb82fe2fd499117193353b0545839a0 GREEN
EObjectDiagramController.java 9af59e8e586c8251d174108a2ce2fcdee5e75782 GREEN
EObjectDiagramController.java a34479522e68cd5f6dc64ca322eab3a56a95602a YELLOW
EObjectEllipticResizableContentControllerBase.java 3494d4f0dcdff5eb35f22f0e21d04df81b32e494 GREEN
EObjectModelChangeProvider.java f4b60cebb088a5c81ca92a41614e1a5d40030502 GREEN
EObjectRectangularResizableContentControllerBase.java f4a967591a60fadb20550ec3eaabccf240c9ec0d GREEN
......
......@@ -18,6 +18,8 @@ import static java.util.Objects.requireNonNull;
import static org.fortiss.tooling.base.ui.editor.fx.controller.ContextMenuUtil.createDisplayMenu;
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.utils.FXDNDUtils.canCompose;
import static org.fortiss.tooling.base.ui.utils.FXDNDUtils.compose;
import java.util.List;
......@@ -33,6 +35,7 @@ import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
import javafx.scene.Node;
import javafx.scene.control.MenuItem;
import javafx.scene.input.Dragboard;
/**
* Diagram controller that uses the {@link IElementCompositorService} to create context menu
......@@ -41,7 +44,6 @@ import javafx.scene.control.MenuItem;
* @author hoelzl
*/
public class EObjectDiagramController<T extends EObject> extends ControllerBase {
/** The model change provider. */
private final EObjectModelChangeProvider modelChangeProvider;
......@@ -85,4 +87,16 @@ public class EObjectDiagramController<T extends EObject> extends ControllerBase
result.add(createDisplayMenu(getViewer()));
return result;
}
/** {@inheritDoc} */
@Override
public boolean handleExternalDNDDragOver(Dragboard db, DiagramCoordinate diagramLocation) {
return canCompose(db, diagramLocation, getModelElement());
}
/** {@inheritDoc} */
@Override
public boolean handleExternalDNDDrop(Dragboard db, DiagramCoordinate diagramLocation) {
return compose(db, diagramLocation, getModelElement());
}
}
......@@ -2,6 +2,7 @@ AbstractNameEditingSupport.java c57336a0e0da18711a1610ca667dfea76728807f GREEN
ActionUtils.java 322f43d4f92f992daef8ac88eb0f9197c840c89b GREEN
DragAndDropBaseUtils.java d375377f9124f6113b2a295e6b0e09ac8966e564 GREEN
EllipseLayoutUIUtils.java 4dd9dbd96a45e8c455c019caa19e4a50f18336af GREEN
FXDNDUtils.java 5572358a950e932a65dfa053ca02e2fbbef5568e RED
FontUtils.java a167a05bdaa8da9853705cc5134f30f6d81bc9f2 GREEN
GCStateManager.java 983973a92376b5c757c1253b32e33d0666ccdf7b GREEN
LWFXEditorUtils.java c624d3f0f6487b6d426b168dad048b2c39e71114 GREEN
......
/*-------------------------------------------------------------------------+
| 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.utils;
import static org.fortiss.tooling.kernel.service.IPrototypeService.PROTOTYPE_DATA_FORMAT;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.fortiss.tooling.kernel.extension.data.Prototype;
import org.fortiss.tooling.kernel.service.ICommandStackService;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.service.IPrototypeService;
import javafx.scene.input.Dragboard;
/**
* Utility methods for JavaFX drag-and-drop.
*
* @author hoelzl
*/
public final class FXDNDUtils {
/** Returns whether element composition can be done via {@link IElementCompositorService}. */
public static boolean canCompose(Dragboard db, DiagramCoordinate location, EObject container) {
Prototype proto = extractPrototype(db);
if(proto != null) {
// FIXME: location
return IElementCompositorService.getInstance().canCompose(container,
proto.getPrototypeCopy(), null);
}
return false;
}
/** Extracts the prototype from the dragboard. */
private static Prototype extractPrototype(Dragboard db) {
Object data = db.getContent(PROTOTYPE_DATA_FORMAT);
if(data instanceof String) {
return IPrototypeService.getInstance().getPrototypeByUniqueID((String)data);
}
return null;
}
/** Composes the elements using {@link IElementCompositorService}. */
public static boolean compose(Dragboard db, DiagramCoordinate location, EObject container) {
Prototype proto = extractPrototype(db);
if(proto != null) {
IElementCompositorService ecs = IElementCompositorService.getInstance();
EObject copy = proto.getPrototypeCopy();
if(ecs.canCompose(container, copy, null)) {
// FIXME: location
ICommandStackService.getInstance().runAsCommand(container, () -> {
ecs.compose(container, copy, null);
});
return true;
}
}
return false;
}
/** Constructor. */
private FXDNDUtils() {
// prevent instantiation
}
}
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