summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorMiki <miki@vaadin.com>2015-02-06 15:27:59 +0200
committerVaadin Code Review <review@vaadin.com>2015-03-26 06:48:32 +0000
commitf38697786931944177c86498939d6b5993b1588d (patch)
tree42518d3cf73c5615180ed7fc27de7c62f7f1c14f /server
parentf665aed236f64da849862d4e463d80deecc33d9a (diff)
downloadvaadin-framework-f38697786931944177c86498939d6b5993b1588d.tar.gz
vaadin-framework-f38697786931944177c86498939d6b5993b1588d.zip
Fix declarative support for DragAndDropWrapper (#16324)
Change-Id: I132e37fe54fb5949748c0e0ec265bd411ff91ce3
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/DragAndDropWrapper.java37
-rw-r--r--server/tests/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropWrapperDeclarativeTest.java66
2 files changed, 102 insertions, 1 deletions
diff --git a/server/src/com/vaadin/ui/DragAndDropWrapper.java b/server/src/com/vaadin/ui/DragAndDropWrapper.java
index 6e4ec903d2..b813973861 100644
--- a/server/src/com/vaadin/ui/DragAndDropWrapper.java
+++ b/server/src/com/vaadin/ui/DragAndDropWrapper.java
@@ -24,6 +24,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.jsoup.nodes.Element;
+
import com.vaadin.event.Transferable;
import com.vaadin.event.TransferableImpl;
import com.vaadin.event.dd.DragSource;
@@ -38,6 +40,7 @@ import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.dd.HorizontalDropLocation;
import com.vaadin.shared.ui.dd.VerticalDropLocation;
import com.vaadin.shared.ui.draganddropwrapper.DragAndDropWrapperConstants;
+import com.vaadin.ui.declarative.DesignContext;
@SuppressWarnings("serial")
public class DragAndDropWrapper extends CustomComponent implements DropTarget,
@@ -185,7 +188,12 @@ public class DragAndDropWrapper extends CustomComponent implements DropTarget,
private Set<String> sentIds = new HashSet<String>();
- private DragAndDropWrapper() {
+ /**
+ * This is an internal constructor. Use
+ * {@link DragAndDropWrapper#DragAndDropWrapper(Component)} instead.
+ */
+ @Deprecated
+ public DragAndDropWrapper() {
super();
}
@@ -458,4 +466,31 @@ public class DragAndDropWrapper extends CustomComponent implements DropTarget,
}
+ @Override
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
+
+ for (Element child : design.children()) {
+ Component component = designContext.readDesign(child);
+ if (getDragStartMode() == DragStartMode.COMPONENT_OTHER
+ && child.hasAttr(":drag-image")) {
+ setDragImageComponent(component);
+ } else if (getCompositionRoot() == null) {
+ setCompositionRoot(component);
+ }
+ }
+ }
+
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+
+ design.appendChild(designContext.createElement(getCompositionRoot()));
+ if (getDragStartMode() == DragStartMode.COMPONENT_OTHER) {
+ Element child = designContext
+ .createElement(getDragImageComponent());
+ child.attr(":drag-image", "");
+ design.appendChild(child);
+ }
+ }
}
diff --git a/server/tests/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropWrapperDeclarativeTest.java b/server/tests/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropWrapperDeclarativeTest.java
new file mode 100644
index 0000000000..735216c474
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropWrapperDeclarativeTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.draganddropwrapper;
+
+import org.junit.Test;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.DragAndDropWrapper;
+import com.vaadin.ui.DragAndDropWrapper.DragStartMode;
+import com.vaadin.ui.declarative.DesignContext;
+
+public class DragAndDropWrapperDeclarativeTest extends
+ DeclarativeTestBase<DragAndDropWrapper> {
+
+ @Test
+ public void testDefaultDnDWrapper() {
+ Button okButton = new Button("OK");
+ String input = "<v-drag-and-drop-wrapper>"
+ + new DesignContext().createElement(okButton)
+ + "</v-drag-and-drop-wrapper>";
+ DragAndDropWrapper wrapper = new DragAndDropWrapper(okButton);
+ testWrite(input, wrapper);
+ testRead(input, wrapper);
+ }
+
+ @Test
+ public void testNoDragImage() {
+ Button okButton = new Button("OK");
+ String input = "<v-drag-and-drop-wrapper drag-start-mode='wrapper'>"
+ + new DesignContext().createElement(okButton)
+ + "</v-drag-and-drop-wrapper>";
+ DragAndDropWrapper wrapper = new DragAndDropWrapper(okButton);
+ wrapper.setDragStartMode(DragStartMode.WRAPPER);
+ testWrite(input, wrapper);
+ testRead(input, wrapper);
+ }
+
+ @Test
+ public void testWithDragImage() {
+ Button dragImage = new Button("Cancel");
+ Button okButton = new Button("OK");
+ String input = "<v-drag-and-drop-wrapper drag-start-mode='component_other'>"
+ + new DesignContext().createElement(okButton)
+ + new DesignContext().createElement(dragImage).attr(
+ ":drag-image", "") + "</v-drag-and-drop-wrapper>";
+ DragAndDropWrapper wrapper = new DragAndDropWrapper(okButton);
+ wrapper.setDragStartMode(DragStartMode.COMPONENT_OTHER);
+ wrapper.setDragImageComponent(dragImage);
+ testWrite(input, wrapper);
+ testRead(input, wrapper);
+ }
+}