diff --git a/.gitignore b/.gitignore index b8b7f885..ca03bfcf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ **/.settings **/META-INF **/build +**/bin # Specific ignores addon/src/main/webapp/VAADIN/ @@ -14,5 +15,3 @@ demo/src/main/webapp/VAADIN/gwt-unitCache/ demo/src/main/webapp/VAADIN/themes/demo/styles.css demo/src/main/webapp/VAADIN/widgetsets/ addon/GWT development mode for addon.launch -/build/ -/bin/ diff --git a/README.md b/README.md index 70afa5f7..cf0cf91b 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,4 @@ Please see the version table below to decide which version to use in your projec | 7.0.x+ | 1.0.x | | 7.2.x+ | 1.1.x | | 7.6.x+ | 1.2.x | +| 7.7.x+ | 1.3.x | diff --git a/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/VLayoutDragDropMouseHandler.java b/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/VLayoutDragDropMouseHandler.java index f0e3f91f..e04f4b3e 100644 --- a/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/VLayoutDragDropMouseHandler.java +++ b/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/VLayoutDragDropMouseHandler.java @@ -193,11 +193,10 @@ protected void initiateDragOnMove(final NativeEvent originalEvent) { // Stop event propagation and prevent default behaviour if // - target is *not* a VTabsheet.TabCaption or // - drag mode is caption mode and widget is caption - boolean isTabCaption = targetParent instanceof VTabsheet.TabCaption; + boolean isTabCaption = isTabCaptionText(target); boolean isCaption = VDragDropUtil.isCaptionOrCaptionless(targetParent); - if (dragMode == LayoutDragMode.CLONE && isTabCaption == false) { - + if (dragMode == LayoutDragMode.CLONE && !isTabCaption) { stopEventPropagation = true; // overwrite stopEventPropagation flag again if @@ -251,9 +250,26 @@ public void onPreviewNativeEvent(NativePreviewEvent event) { }); } + // Allow dragging only for caption text of Tab to avoid bugs on touch-devices + protected boolean isTabCaptionText(Widget target) { + Widget parent = target; + + while (parent != null) { + if (parent instanceof Tab) { + return true; + } + + parent = parent.getParent(); + } + + return false; + } + private boolean isElementNotDraggable(Element targetElement) { // do not try to drag tabsheet close button it breaks close on touch devices - return targetElement.getClassName().contains("v-tabsheet-caption-close"); + return targetElement.getClassName().contains("v-tabsheet-caption-close") + || (targetElement.getClassName().contains("v-caption") && + targetElement.getParentElement().getClassName().contains("v-tabsheet-tabitem")); } /** diff --git a/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/csslayout/VDDCssLayout.java b/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/csslayout/VDDCssLayout.java index a3c89177..402ed784 100644 --- a/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/csslayout/VDDCssLayout.java +++ b/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/csslayout/VDDCssLayout.java @@ -219,12 +219,31 @@ protected void updateDragDetails(VDragEvent event) { return; } + Element e= getElement(); Widget widget = (Widget) Util.findWidget(over, null); if (widget == null) { // Null check return; } - + else + { + // Solve https://github.com/johndevs/dragdroplayouts/issues/58 + Widget parentWidget= widget.getParent(); + Element pE= parentWidget != null ? parentWidget.getElement() : null; + // Check for direct child (not child of child) + while (widget != null && pE != null && !e.equals(pE)) + { + widget= widget.getParent(); + parentWidget= widget.getParent(); + pE= parentWidget != null ? parentWidget.getElement() : null; + } + if (widget != null) + { + event.setElementOver(widget.getElement()); + over= widget.getElement(); + } + } + int offset = 0; int index = -1; for (int i = 0; i < getElement().getChildCount(); i++) { diff --git a/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/util/HTML5Support.java b/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/util/HTML5Support.java index 3f0addb7..22c44c04 100644 --- a/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/util/HTML5Support.java +++ b/addon/src/main/java/fi/jasoft/dragdroplayouts/client/ui/util/HTML5Support.java @@ -46,6 +46,10 @@ */ public class HTML5Support { + protected static DragOverHandler globalDragOverHandler = null; + protected static DropHandler globalDropHandler = null; + protected static DragEnterHandler globalDragEnterHandler = null; + private final List handlers = new ArrayList(); public static class HTML5DragHandler @@ -89,6 +93,12 @@ public void onDrop(DropEvent event) { nativeEvent.preventDefault(); nativeEvent.stopPropagation(); + // event stopped, just notify global handler + // Haulmont API + if (globalDropHandler != null) { + globalDropHandler.onDrop(event); + } + vaadinDragEvent.setCurrentGwtEvent(nativeEvent); VDragAndDropManager.get().setCurrentDropHandler(dropHandler); @@ -116,6 +126,13 @@ public void onDragOver(DragOverEvent event) { if (validate(nativeEvent) && vaadinDragEvent != null) { nativeEvent.preventDefault(); nativeEvent.stopPropagation(); + + // event stopped, just notify global handler + // Haulmont API + if (globalDragOverHandler != null) { + globalDragOverHandler.onDragOver(event); + } + vaadinDragEvent.setCurrentGwtEvent(nativeEvent); VDragAndDropManager.get().setCurrentDropHandler(dropHandler); dropHandler.dragOver(vaadinDragEvent); @@ -154,6 +171,10 @@ public void onDragEnter(DragEnterEvent event) { nativeEvent.preventDefault(); nativeEvent.stopPropagation(); } + + if (globalDragEnterHandler != null) { + globalDragEnterHandler.onDragEnter(event); + } } private boolean validate(NativeEvent event) { @@ -217,4 +238,34 @@ public void disable() { } handlers.clear(); } + + // Haulmont API + public static DragOverHandler getGlobalDragOverHandler() { + return globalDragOverHandler; + } + + // Haulmont API + public static void setGlobalDragOverHandler(DragOverHandler globalDragOverHandler) { + HTML5Support.globalDragOverHandler = globalDragOverHandler; + } + + // Haulmont API + public static DropHandler getGlobalDropHandler() { + return globalDropHandler; + } + + // Haulmont API + public static void setGlobalDropHandler(DropHandler globalDropHandler) { + HTML5Support.globalDropHandler = globalDropHandler; + } + + // Haulmont API + public static DragEnterHandler getGlobalDragEnterHandler() { + return globalDragEnterHandler; + } + + // Haulmont API + public static void setGlobalDragEnterHandler(DragEnterHandler globalDragEnterHandler) { + HTML5Support.globalDragEnterHandler = globalDragEnterHandler; + } } diff --git a/build.gradle b/build.gradle index 19602c9f..07be7133 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,23 @@ +plugins { + id 'fi.jasoft.plugin.vaadin' version '1.0' apply false +} + allprojects { - group='fi.jasoft' + group = 'org.vaadin.addons' version = project.hasProperty('BUILD_VERSION') ? getProperty('BUILD_VERSION') : 'development'; apply plugin: 'eclipse-wtp' } subprojects { - apply from: 'http://plugins.jasoft.fi/vaadin.plugin' - vaadin.version = '7.7.+' + apply plugin: 'fi.jasoft.plugin.vaadin' + vaadin { + version = '7.7.3' + } + sourceCompatibility = 1.7 + targetCompatibility = 1.7 + + javadoc.enabled = false + vaadinJavadocJar.enabled = false } task wrapper(type: Wrapper) { @@ -17,7 +28,7 @@ task wrapper(type: Wrapper) { * Vaadin addon project */ project(':addon'){ - + apply plugin: 'java' apply plugin: 'maven' apply plugin: 'osgi' @@ -25,17 +36,17 @@ project(':addon'){ deploy } - dependencies{ + dependencies { testCompile 'junit:junit:4.8.+' deploy 'org.apache.maven.wagon:wagon-ssh:2.2' } vaadin { - addon { - author 'John Ahlroos' - license 'Apache 2.0' - title 'DragDropLayouts' - } + addon { + author 'John Ahlroos' + license 'Apache 2.0' + title 'DragDropLayouts' + } } task createAddonPom { @@ -101,13 +112,17 @@ project(':addon'){ } } } -} + configurations.archives.artifacts.removeAll { + it.file =~ 'war' || it.file =~ 'javadoc' + } +} /* * Demo application for demonstrating the addon */ project(':demo'){ + apply plugin: 'java' dependencies { compile project(':addon') @@ -141,4 +156,4 @@ project(':demo'){ dependsOn 'vaadinCompile' systemProperties = System.properties } -} +} \ No newline at end of file diff --git a/demo/src/main/java/fi/jasoft/dragdroplayouts/demo/views/DragdropCssLayoutDemo.java b/demo/src/main/java/fi/jasoft/dragdroplayouts/demo/views/DragdropCssLayoutDemo.java index 12d89870..75421949 100644 --- a/demo/src/main/java/fi/jasoft/dragdroplayouts/demo/views/DragdropCssLayoutDemo.java +++ b/demo/src/main/java/fi/jasoft/dragdroplayouts/demo/views/DragdropCssLayoutDemo.java @@ -58,24 +58,15 @@ public boolean isDraggable(Component component) { new Label( "This is an CSS layout, the positions are defined by css rules. Try dragging the components around."); cssLayout.addComponent(lbl); - Button btn = new Button("Button 1", new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - Notification.show("Click!"); - } - }); - cssLayout.addComponent(btn); - btn = new Button("Button 2", new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - Notification.show("Click!"); - } - }); - cssLayout.addComponent(btn); - btn = new Button("Button 3", new Button.ClickListener() { - public void buttonClick(ClickEvent event) { - Notification.show("Click!"); - } - }); - cssLayout.addComponent(btn); + for (int i=0; i < 20; i++) + { + Button btn = new Button("Button "+i, new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + Notification.show("Click!"); + } + }); + cssLayout.addComponent(btn); + } // end-source return cssLayout; }