Skip to content

Commit

Permalink
Merge pull request eclipse-vorto#124 from bsinno/bug/92-EntityDropped…
Browse files Browse the repository at this point in the history
…OnEnums

Don't allow entities to be dropped to enums. Closes eclipse-vorto#92
  • Loading branch information
aedelmann committed Mar 28, 2016
2 parents 8f48306 + 76b2b0b commit 9618e25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.vorto.perspective.dnd.dropaction.CreateProjectDropAction;
import org.eclipse.vorto.perspective.dnd.dropaction.ModelProjectDropAction;
import org.eclipse.vorto.perspective.dnd.dropaction.RepositoryResourceDropAction;
import org.eclipse.vorto.perspective.dnd.dropvalidator.DatatypeValidator;
import org.eclipse.vorto.perspective.dnd.dropvalidator.ModelTypeValidator;
import org.eclipse.vorto.perspective.dnd.dropvalidator.TargetClassModelTypeValidator;
import org.eclipse.vorto.perspective.dnd.dropvalidator.TargetClassSourceClassValidator;
Expand All @@ -32,7 +33,7 @@ public class ModelDropListenerFactory {
public static DropTargetListener datatypeViewPartDropListener(Viewer viewer) {
return new ModelDropListener(viewer)
.addDropAction(
new TargetClassSourceClassValidator(
new DatatypeValidator(
DatatypeModelProject.class,
DatatypeModelProject.class),
new ModelProjectDropAction(DatatypeModelProject.class))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.eclipse.vorto.perspective.dnd.dropvalidator;

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.model.IModelProject;

public class DatatypeValidator extends TargetClassSourceClassValidator {

public DatatypeValidator(Class<?> targetClass, Class<?> sourceClass) {
super(targetClass, sourceClass);
}

@Override
public boolean allow(IModelProject receivingProject, Object droppedObject) {
boolean entityDroppedToEnum = entityDroppedToEnum(receivingProject.getModel(), ((IModelProject) droppedObject).getModel());
return super.allow(receivingProject, droppedObject) && !entityDroppedToEnum;
}

private boolean entityDroppedToEnum(Model targetModel, Model droppedModel) {
return targetModel instanceof Enum && droppedModel instanceof Entity;
}
}

0 comments on commit 9618e25

Please sign in to comment.