Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't allow entities to be dropped to enums. Closes #92 #124

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}