/**
   * Called when a component changed location within the layout
   *
   * @param event The drag and drop event
   */
  @Override
  protected void handleComponentReordering(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();

    // Get top-left pixel position
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

    ComponentPosition position = layout.getPosition(component);

    position.setLeft((float) leftPixelPosition, Sizeable.UNITS_PIXELS);
    position.setTop((float) topPixelPosition, Sizeable.UNITS_PIXELS);
  }
Ejemplo n.º 2
0
    @SuppressWarnings("static-access")
    void reload() {
      Collection<?> children =
          folder == null
              ? DDTest6.get().tree1.rootItemIds()
              : DDTest6.get().tree1.getChildren(folder);
      if (children == null) {
        l.removeAllComponents();
        return;
      } else {
        // make modifiable
        children = new HashSet<Object>(children);
      }
      Set<Component> removed = new HashSet<Component>();
      for (Iterator<Component> componentIterator = l.getComponentIterator();
          componentIterator.hasNext(); ) {
        FileIcon next = (FileIcon) componentIterator.next();
        if (!children.contains(next.file)) {
          removed.add(next);
        } else {
          children.remove(next.file);
        }
      }

      for (Component component : removed) {
        l.removeComponent(component);
      }

      for (Object object : children) {
        FileIcon fileIcon = new FileIcon((File) object);
        l.addComponent(fileIcon);
        ComponentPosition position = l.getPosition(fileIcon);
        position.setTop(Float.valueOf((y++ / 5) % 5 * 100), UNITS_PIXELS);
        position.setLeft(Float.valueOf(x++ % 5 * 100), UNITS_PIXELS);
      }
    }
Ejemplo n.º 3
0
  @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;
  }
Ejemplo n.º 4
0
    @Override
    @SuppressWarnings("static-access")
    public void drop(DragAndDropEvent dropEvent) {

      if (dropEvent.getTransferable().getSourceComponent() instanceof FileIcon) {
        // update the position

        DragAndDropWrapper.WrapperTransferable transferable =
            (WrapperTransferable) dropEvent.getTransferable();
        MouseEventDetails mouseDownEvent = transferable.getMouseDownEvent();

        WrapperTargetDetails dropTargetDetails =
            (WrapperTargetDetails) dropEvent.getTargetDetails();

        MouseEventDetails mouseEvent = dropTargetDetails.getMouseEvent();

        int deltaX = mouseEvent.getClientX() - mouseDownEvent.getClientX();
        int deltaY = mouseEvent.getClientY() - mouseDownEvent.getClientY();

        ComponentPosition position = l.getPosition(transferable.getSourceComponent());
        position.setTop(position.getTopValue() + deltaY, UNITS_PIXELS);
        position.setLeft(position.getLeftValue() + deltaX, UNITS_PIXELS);

      } else if (dropEvent.getTransferable().getSourceComponent() == tree1) {

        // dragged something from tree to the folder shown

        File draggedFile = (File) ((DataBoundTransferable) dropEvent.getTransferable()).getItemId();
        DDTest6.get().setParent(draggedFile, folder);
      } else {
        // expecting this to be an html5 drag
        WrapperTransferable tr = (WrapperTransferable) dropEvent.getTransferable();
        Html5File[] files2 = tr.getFiles();
        if (files2 != null) {
          for (Html5File html5File : files2) {
            String fileName = html5File.getFileName();
            // int bytes = html5File.getFileSize();
            final ByteArrayOutputStream bas = new ByteArrayOutputStream();

            StreamVariable streamVariable =
                new StreamVariable() {

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

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

                  @Override
                  public void onProgress(StreamingProgressEvent event) {}

                  @Override
                  public void streamingStarted(StreamingStartEvent event) {}

                  @Override
                  public void streamingFinished(StreamingEndEvent event) {}

                  @Override
                  public void streamingFailed(StreamingErrorEvent event) {}

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

            html5File.setStreamVariable(streamVariable);

            File file = new File(fileName, bas);
            file.setType(html5File.getType());
            // FF don't know csv
            if (fileName.endsWith(".csv")) {
              file.setType("text/csv");
            }
            DDTest6.get().fs1.addBean(file);
            DDTest6.get().tree1.setChildrenAllowed(file, false);
            DDTest6.get().setParent(file, folder);
          }
        }
      }
    }