/**
   * Handle a drop from another layout
   *
   * @param event The drag and drop event
   */
  @Override
  protected void handleDropFromLayout(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();
    Component source = event.getTransferable().getSourceComponent();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

    // Check that we are not dragging an outer layout into an
    // inner
    // layout
    Component parent = source.getParent();
    while (parent != null) {
      parent = parent.getParent();
    }

    // remove component from source using filter
    if (source instanceof ComponentContainer) {
      ComponentContainer sourceLayout = (ComponentContainer) source;
      sourceLayout.removeComponent(component);
    }

    // Add component to absolute layout
    layout.addComponent(
        component, "left:" + leftPixelPosition + "px;top:" + topPixelPosition + "px");
  }
Example #2
0
 @Override
 public Set<HasComponents> apply(Set<? extends Component> cs) {
   Set<HasComponents> result = Util.set();
   for (Component c : cs) {
     if (c.getParent() != null) {
       result.add(c.getParent());
     }
   }
   return result;
 }
  @Override
  public void replaceComponent(Component oldComponent, Component newComponent) {

    // Ignore if component is replaced with itself
    if (oldComponent == newComponent) {
      return;
    }

    // Remove new component from children to allow position calculations
    if (newComponent.getParent() == this) {
      removeComponent(newComponent);
    }

    // Resolve column
    ColumnLayoutState.ColumnState column = findColumn(oldComponent);
    if (column == null) {
      throw new IllegalArgumentException("Old component not found");
    }

    // Resolve position inside column
    int index = column.children.indexOf(oldComponent);

    // Remove old and add new to same position in column
    removeComponent(oldComponent);
    addComponent(newComponent, column, index);
  }
Example #4
0
 @Override
 public Set<HasComponents> apply(Set<? extends Component> cs) {
   Set<HasComponents> result = Util.set();
   for (Component c : cs) {
     HasComponents parent = c.getParent();
     while (parent != null) {
       result.add(parent);
       parent = parent.getParent();
     }
   }
   return result;
 }
  private void setLayout(Layout newLayout) {
    if (layout == null) {
      layoutParent.addComponent(newLayout, 0);
    } else {
      layoutParent.replaceComponent(layout, newLayout);
    }
    layout = newLayout;

    for (Component c : components) {
      if (c.getParent() != layout) {
        layout.addComponent(c);
      }
    }
  }
 @Override
 public Iterator<Component> iterator() {
   Set<Component> children = new HashSet<Component>();
   if (visibleComponents != null) {
     children.addAll(visibleComponents);
   }
   if (initDone) {
     for (Object key : columnIdToFilterMap.keySet()) {
       Component filter = columnIdToFilterMap.get(key);
       if (equals(filter.getParent())) {
         children.add(filter);
       }
     }
   }
   return children.iterator();
 }
  @Override
  public void drop(DragAndDropEvent event) {

    WrapperTargetDetails ed = (WrapperTargetDetails) event.getTargetDetails();
    Transferable ctr = event.getTransferable();
    // use "component" (from DragDropPane) if available, else take
    // the source component
    Component component = null;
    if (ctr instanceof WrapperTransferable) {
      component = ((WrapperTransferable) ctr).getDraggedComponent();
    } else if (ctr instanceof DataBoundTransferable) {
      // Item has been dragged, construct a Label from
      // Item id
      Label l = new Label();
      l.setSizeUndefined();
      l.setValue("ItemId : " + ((DataBoundTransferable) ctr).getItemId());
      component = l;
    }

    if (component != null) {

      if (component.getParent() != root) {

        root.addComponent(component);

        Integer left = ed.getAbsoluteLeft();
        Integer top = ed.getAbsoluteTop();

        MouseEventDetails eventDetails = ed.getMouseEvent();

        int clientX = eventDetails.getClientX();
        int clientY = eventDetails.getClientY();

        try {
          root.getPosition(component).setTopValue(Float.valueOf(clientY - top));
          root.getPosition(component).setLeftValue(Float.valueOf(clientX - left));
        } catch (Exception e) {
        }
      } else {
        // drag started and ended inside the this Pane

        MouseEventDetails start =
            ((WrapperTransferable) event.getTransferable()).getMouseDownEvent();
        MouseEventDetails eventDetails = ed.getMouseEvent();

        int deltaX = eventDetails.getClientX() - start.getClientX();
        int deltaY = eventDetails.getClientY() - start.getClientY();

        ComponentPosition p = root.getPosition(component);
        p.setTopValue(p.getTopValue() + deltaY);
        p.setLeftValue(p.getLeftValue() + deltaX);
      }
    } else {
      // drag coming outside of Vaadin

      WrapperTransferable wtr = (WrapperTransferable) ctr;

      String object = wtr.getText();
      // String html = wtr.getHtml();
      // String url = (String) ctr.getData("Url");

      final Label l = new Label();
      l.setCaption("Generated from HTML5 drag:");
      if (object != null) {
        if (object.length() > 80) {
          object = object.substring(0, 79);
        }
        l.setValue(object);
      } else {
        l.setValue("HTML5 dd");
      }

      Html5File[] files = wtr.getFiles();
      if (files != null) {
        for (Html5File html5File : files) {
          l.setCaption(html5File.getFileName());
          html5File.setStreamVariable(
              new StreamVariable() {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

                @Override
                public OutputStream getOutputStream() {
                  return byteArrayOutputStream;
                }

                @Override
                public boolean listenProgress() {
                  return false;
                }

                @Override
                public void onProgress(StreamingProgressEvent event) {}

                @Override
                public void streamingStarted(StreamingStartEvent event) {}

                @Override
                public void streamingFinished(StreamingEndEvent event) {
                  l.setValue(
                      (new String(byteArrayOutputStream.toByteArray()).substring(0, 80) + "..."));
                }

                @Override
                public void streamingFailed(StreamingErrorEvent event) {}

                @Override
                public boolean isInterrupted() {
                  return false;
                }
              });
        }
      }

      l.setSizeUndefined();

      root.addComponent(l);
    }
    return;
  }