Ejemplo n.º 1
0
  public void drop(final DropTargetDropEvent dtde) {
    if (dragHandler == null) {
      dtde.rejectDrop();
      return;
    }
    try {
      if (ElementMetaDataTransferable.ELEMENT_FLAVOR.equals(getFlavor())) {
        final ElementMetaData metaData = (ElementMetaData) getTransferData();
        dragHandler.drop(dtde, editorContext, metaData, null);
        return;
      }

      if (FieldDescriptionTransferable.ELEMENT_FLAVOR.equals(getFlavor())) {
        final String fieldName = (String) getTransferData();
        final ElementMetaData metaData = createMetaData(fieldName);
        dragHandler.drop(dtde, editorContext, metaData, fieldName);
        return;
      }
      dtde.rejectDrop();
    } finally {
      editorContext.getRepresentationContainer().revalidate();
      editorContext.getRepresentationContainer().repaint();
      dragHandler = null;
    }
  }
Ejemplo n.º 2
0
  protected int updateDragOver(final DropTargetDragEvent event) {
    try {
      if (ElementMetaDataTransferable.ELEMENT_FLAVOR.equals(getFlavor())) {
        final ElementMetaData data = (ElementMetaData) getTransferData();
        if (data == null) {
          return DnDConstants.ACTION_NONE;
        }

        if (dragHandler == null) {
          dragHandler = createDragHandler(data);
          if (dragHandler == null) {
            return DnDConstants.ACTION_NONE;
          }
          return dragHandler.dragStarted(event, editorContext, data, null);
        } else {
          return dragHandler.dragUpdated(event, editorContext, data, null);
        }
      }

      if (FieldDescriptionTransferable.ELEMENT_FLAVOR.equals(getFlavor())) {
        final String fieldName = (String) getTransferData();
        final ElementMetaData data = createMetaData(fieldName);
        if (data == null) {
          return DnDConstants.ACTION_NONE;
        }

        if (dragHandler == null) {
          dragHandler = createDragHandler(data);
          if (dragHandler == null) {
            return DnDConstants.ACTION_NONE;
          }
          return dragHandler.dragStarted(event, editorContext, data, fieldName);
        } else {
          return dragHandler.dragUpdated(event, editorContext, data, fieldName);
        }
      }

      return DnDConstants.ACTION_NONE;
    } finally {
      editorContext.getRepresentationContainer().revalidate();
      editorContext.getRepresentationContainer().repaint();
    }
  }