- private String validateDrop(RequestProcessor processor, final Resource draggedResource, final Resource dropTarget) throws DatabaseException {
- return processor.syncRequest(new UniqueRead<String>() {
- @Override
- public String perform(ReadGraph graph) throws DatabaseException {
-// System.out.println("dragged resource: " + draggedResource);
-// System.out.println("drop target resource: " + dropTarget);
- Resource sourceModel = graph.syncRequest(new PossibleIndexRoot(draggedResource));
- Resource targetModel = graph.syncRequest(new PossibleIndexRoot(dropTarget));
-// System.out.println("source model: " + sourceModel);
-// System.out.println("target model: " + targetModel);
-
- // Prevent dragging data from one source model to another.
- // If source is not part of any model, everything is okay.
- if (sourceModel != null && !graph.syncRequest(new IsLinkedTo(targetModel, sourceModel))) {
- // Prevent a symbol instantiating within its own configuration.
- // NOTE: this doesn't handle transitive cycles.
- return "Cannot instantiate " + NameUtils.getSafeName(graph, draggedResource) + " into model "
- + NameUtils.getURIOrSafeNameInternal(graph, targetModel) + ". The source namespace ("
- + NameUtils.getURIOrSafeNameInternal(graph, sourceModel) + ") is not linked to the target model.";
- }
-
- // Prevent dragging to published components
- ModelingResources MOD = ModelingResources.getInstance(graph);
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
- Resource configuration = graph.getPossibleObject(dropTarget, MOD.DiagramToComposite);
- if (configuration != null) {
- Resource componentTypeFromDiagram = graph.getPossibleObject(configuration, STR.Defines);
- if(componentTypeFromDiagram != null) {
- if(Layer0Utils.isPublished(graph, componentTypeFromDiagram))
- return "Cannot create elements into a diagram that belongs to a published user component.";
- }
- }
+ private Object validateDrag(RequestProcessor processor, final Resource draggedResource, final Resource dropTarget, IHintContext dndHints) throws DatabaseException {
+ return processor.syncRequest((Read<Object>) graph -> {
+ List<DropSuggestion> suggestions = dndHints.getHint(KEY_SUGGESTIONS);
+ if (suggestions == null) {
+ suggestions = new ArrayList<>();
+ dndHints.setHint(KEY_SUGGESTIONS, suggestions);
+ }