private boolean resizable = true;
+ private boolean draggable = true;
+
private Element modalityCurtain;
private Element draggingCurtain;
if (uidl.getBooleanAttribute("resizable") != resizable) {
setResizable(!resizable);
}
+
+ setDraggable(!uidl.hasAttribute("fixedposition"));
}
if (client.updateComponent(this, uidl, false)) {
}
+ private void setDraggable(boolean draggable) {
+ if (this.draggable == draggable) {
+ return;
+ }
+
+ this.draggable = draggable;
+
+ if (!this.draggable) {
+ header.getStyle().setProperty("cursor", "default");
+ } else {
+ header.getStyle().setProperty("cursor", "");
+ }
+
+ }
+
private void setNaturalWidth() {
/*
* Use max(layout width, window width) i.e layout content width or
if (!isActive()) {
bringToFront();
}
- showDraggingCurtain(true);
- dragging = true;
- startX = DOM.eventGetScreenX(event);
- startY = DOM.eventGetScreenY(event);
- origX = DOM.getAbsoluteLeft(getElement());
- origY = DOM.getAbsoluteTop(getElement());
- DOM.setCapture(getElement());
- DOM.eventPreventDefault(event);
+ if (draggable) {
+ showDraggingCurtain(true);
+ dragging = true;
+ startX = DOM.eventGetScreenX(event);
+ startY = DOM.eventGetScreenY(event);
+ origX = DOM.getAbsoluteLeft(getElement());
+ origY = DOM.getAbsoluteTop(getElement());
+ DOM.setCapture(getElement());
+ DOM.eventPreventDefault(event);
+ }
break;
case Event.ONMOUSEUP:
dragging = false;
private boolean resizable = true;
+ private boolean draggable = true;
+
private boolean centerRequested = false;
private Focusable pendingFocus;
target.addAttribute("resizable", true);
}
+ if (!draggable) {
+ // Inverted to prevent an extra attribute for almost all sub windows
+ target.addAttribute("fixedposition", true);
+ }
+
if (centerRequested) {
target.addAttribute("center", true);
centerRequested = false;
* Note! For historical reasons readonly controls the closability of the sub
* window and therefore readonly and closable affect each other. Setting
* readonly to true will set closable to false and vice versa.
- *
+ * <p/>
* Closable only applies to sub windows, not to browser level windows.
*
* @return true if the sub window can be closed by the user.
}
/**
- * Set the closable status for the sub window. If a sub window is closable
+ * Sets the closable status for the sub window. If a sub window is closable
* it typically shows an X in the upper right corner. Clicking on the X
* sends a close event to the server. Setting closable to false will remove
* the X from the sub window and prevent the user from closing the window.
* Note! For historical reasons readonly controls the closability of the sub
* window and therefore readonly and closable affect each other. Setting
* readonly to true will set closable to false and vice versa.
- *
+ * <p/>
* Closable only applies to sub windows, not to browser level windows.
*
* @param closable
setReadOnly(!closable);
}
+ /**
+ * Indicates whether a sub window can be dragged or not. By default a sub
+ * window is draggable.
+ * <p/>
+ * Draggable only applies to sub windows, not to browser level windows.
+ *
+ * @param draggable
+ * true if the sub window can be dragged by the user
+ */
+ public boolean isDraggable() {
+ return draggable;
+ }
+
+ /**
+ * Enables or disables that a sub window can be dragged (moved) by the user.
+ * By default a sub window is draggable.
+ * <p/>
+ * Draggable only applies to sub windows, not to browser level windows.
+ *
+ * @param draggable
+ * true if the sub window can be dragged by the user
+ */
+ public void setDraggable(boolean draggable) {
+ this.draggable = draggable;
+ requestRepaint();
+ }
+
}
--- /dev/null
+package com.vaadin.tests.components.window;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class SubwindowDraggability extends TestBase {
+
+ @Override
+ protected void setup() {
+ final Window draggableSubWindow = new Window("Draggable sub window");
+ draggableSubWindow.setHeight("300px");
+ final Window fixedSubWindow = new Window("Fixed sub window");
+ fixedSubWindow.setHeight("200px");
+ fixedSubWindow.setDraggable(false);
+
+ fixedSubWindow.center();
+ getMainWindow().addWindow(draggableSubWindow);
+ getMainWindow().addWindow(fixedSubWindow);
+
+ Button b = new Button("Swap", new Button.ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ boolean b = draggableSubWindow.isDraggable();
+
+ draggableSubWindow.setDraggable(!b);
+ fixedSubWindow.setDraggable(b);
+
+ }
+
+ });
+ addComponent(b);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Two sub windows. One is draggable, the other one is fixed and cannot be moved by the user";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 3133;
+ }
+
+}