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

Fix for issue #58 #63

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
**/.settings
**/META-INF
**/build
**/bin

# Specific ignores
addon/src/main/webapp/VAADIN/
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/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HandlerRegistration> handlers = new ArrayList<HandlerRegistration>();

public static class HTML5DragHandler
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -154,6 +171,10 @@ public void onDragEnter(DragEnterEvent event) {
nativeEvent.preventDefault();
nativeEvent.stopPropagation();
}

if (globalDragEnterHandler != null) {
globalDragEnterHandler.onDragEnter(event);
}
}

private boolean validate(NativeEvent event) {
Expand Down Expand Up @@ -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;
}
}
39 changes: 27 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -17,25 +28,25 @@ task wrapper(type: Wrapper) {
* Vaadin addon project
*/
project(':addon'){

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'osgi'

configurations {
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 {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -141,4 +156,4 @@ project(':demo'){
dependsOn 'vaadinCompile'
systemProperties = System.properties
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down