From 4d8db136844489e8f11ed736afa6e0b55c6b719a Mon Sep 17 00:00:00 2001 From: Erle Czar Mantos Date: Wed, 15 Feb 2017 14:30:14 +0800 Subject: [PATCH] Fixes #511 - Drag and Drop of enum within enum should be restricted.-s --- .../vorto/dnd/dropvalidation/DatatypeValidator.java | 9 ++++++++- .../dnd/dropvalidator/TargetClassModelTypeValidator.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bundles/org.eclipse.vorto.perspective.vorto/src/org/eclipse/vorto/perspective/vorto/dnd/dropvalidation/DatatypeValidator.java b/bundles/org.eclipse.vorto.perspective.vorto/src/org/eclipse/vorto/perspective/vorto/dnd/dropvalidation/DatatypeValidator.java index 06d5ee3136..b3b31ec48f 100644 --- a/bundles/org.eclipse.vorto.perspective.vorto/src/org/eclipse/vorto/perspective/vorto/dnd/dropvalidation/DatatypeValidator.java +++ b/bundles/org.eclipse.vorto.perspective.vorto/src/org/eclipse/vorto/perspective/vorto/dnd/dropvalidation/DatatypeValidator.java @@ -17,6 +17,7 @@ import org.eclipse.vorto.core.api.model.datatype.Entity; import org.eclipse.vorto.core.api.model.datatype.Enum; import org.eclipse.vorto.core.api.model.model.Model; +import org.eclipse.vorto.core.ui.MessageDisplayFactory; import org.eclipse.vorto.core.ui.model.IModelElement; import org.eclipse.vorto.perspective.dnd.dropvalidator.TargetClassSourceClassValidator; @@ -30,8 +31,10 @@ public DatatypeValidator(Class targetClass, Class sourceClass) { public boolean allow(Object receivingModelElement, Object droppedObject) { if (receivingModelElement instanceof IModelElement && droppedObject instanceof IModelElement) { boolean entityDroppedToEnum = entityDroppedToEnum(((IModelElement)receivingModelElement).getModel(), ((IModelElement) droppedObject).getModel()); - return super.allow(receivingModelElement, droppedObject) && !entityDroppedToEnum; + boolean enumDroppedToEnum = enumDroppedToEnum(((IModelElement)receivingModelElement).getModel(), ((IModelElement) droppedObject).getModel()); + return super.allow(receivingModelElement, droppedObject) && !entityDroppedToEnum && !enumDroppedToEnum; } else { + MessageDisplayFactory.getMessageDisplay().displayError("You cannot drop an Entity or Enum into an Enum"); return false; } } @@ -39,4 +42,8 @@ public boolean allow(Object receivingModelElement, Object droppedObject) { private boolean entityDroppedToEnum(Model targetModel, Model droppedModel) { return targetModel instanceof Enum && droppedModel instanceof Entity; } + + private boolean enumDroppedToEnum(Model targetModel, Model droppedModel) { + return targetModel instanceof Enum && droppedModel instanceof Enum; + } } diff --git a/framework/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/dropvalidator/TargetClassModelTypeValidator.java b/framework/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/dropvalidator/TargetClassModelTypeValidator.java index eedb7882a2..7d50ab9700 100644 --- a/framework/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/dropvalidator/TargetClassModelTypeValidator.java +++ b/framework/org.eclipse.vorto.perspective/src/org/eclipse/vorto/perspective/dnd/dropvalidator/TargetClassModelTypeValidator.java @@ -39,7 +39,7 @@ public boolean allow(Object receivingModelElement, Object droppedObject) { ModelResource model = (ModelResource) droppedObject; return model.getId().getModelType() == modelType; } else { - if (!targetClass.isInstance(receivingModelElement)) { + if (droppedObject instanceof ModelResource && !targetClass.isInstance(receivingModelElement)) { MessageDisplayFactory.getMessageDisplay().displayError("Please create a Project first before dropping models from the repository."); } return false;