Skip to content

Commit

Permalink
Fixes #511 - Drag and Drop of enum within enum should be restricted (#…
Browse files Browse the repository at this point in the history
…525)

Signed-off-by: Erle Czar Mantos <[email protected]>
  • Loading branch information
Erle Czar Mantos authored and aedelmann committed Feb 15, 2017
1 parent 5751b42 commit b4015d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,13 +31,19 @@ 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;
}
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b4015d3

Please sign in to comment.