Skip to content

Commit

Permalink
Hardcode adding DragSource to found classes in DevModeServletContextL…
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-vaadin authored and Denis committed Dec 4, 2019
1 parent 9da71da commit c9ed014
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
Expand All @@ -35,6 +34,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -315,6 +315,8 @@ public void contextInitialized(ServletContextEvent event) {
"Search for subclasses and classes with annotations took {} seconds",
(classScanning - start) / 1000);

classes.addAll(getOtherRequiredTypes());

try {
DevModeInitializer.initDevModeHandler(classes,
event.getServletContext(), config);
Expand All @@ -324,6 +326,30 @@ public void contextInitialized(ServletContextEvent event) {
}
}

private Collection<Class<?>> getOtherRequiredTypes() {
List<Class<?>> types = new ArrayList<>();

// DragSource and DropTarget, two interfaces in flow-dnd module that
// are essential for supporting drag and drop, are not scanned
// because Spring doesn't scan interfaces. So, we have to add them
// manually.
getClassByName("com.vaadin.flow.component.dnd.DragSource")
.ifPresent(types::add);
getClassByName("com.vaadin.flow.component.dnd.DropTarget")
.ifPresent(types::add);

return types;
}

private Optional<Class> getClassByName(String name) {
try {
return Optional.of(Class
.forName(name));
} catch (ClassNotFoundException e) {
return Optional.empty();
}
}

@Override
public void contextDestroyed(ServletContextEvent event) {
// NO-OP
Expand Down

0 comments on commit c9ed014

Please sign in to comment.