예제 #1
0
파일: Tree.java 프로젝트: morenos/vaadin
  /*
   * (non-Javadoc)
   *
   * @see com.vaadin.event.dd.DragSource#getTransferable(java.util.Map)
   */
  @Override
  public Transferable getTransferable(Map<String, Object> payload) {
    TreeTransferable transferable = new TreeTransferable(this, payload);
    // updating drag source variables
    Object object = payload.get("itemId");
    if (object != null) {
      transferable.setData("itemId", itemIdMapper.get((String) object));
    }

    return transferable;
  }
  @Override
  protected void exportDone(JComponent source, Transferable data, int action) {
    if (source == null
        || dropLocation == null
        || data == null
        || !(data instanceof TreeTransferable)) return;

    TreeTransferable t = (TreeTransferable) data;
    LayerTreeModel model = layersTree.getLayerModel();

    Boolean moveIntoFolders = null;

    int i = 0;
    for (TreePath path : t.getPaths()) {
      if (source == layersTree) {
        INode node = (INode) path.getLastPathComponent();
        addNodeToTree(dropLocation, model, node, true, i++);
      } else if (source == datasetTree) {
        DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (dmtn != null && dmtn.getUserObject() instanceof ILayerDefinition) {
          if (moveIntoFolders == null) {
            String message =
                "Would you like to include the folder hierarchy with the dragged layers?";
            int result =
                JOptionPane.showConfirmDialog(
                    layersTree,
                    message,
                    "Include folders",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
            moveIntoFolders = result == JOptionPane.YES_OPTION;
          }

          ILayerDefinition definition = (ILayerDefinition) dmtn.getUserObject();
          if (moveIntoFolders) {
            layersTree.getLayerModel().addLayer(definition, path.getPath());
          } else {
            INode node = LayerNode.createFromLayerDefinition(definition);
            addNodeToTree(dropLocation, model, node, false, i++);
          }

          Rectangle bounds = datasetTree.getPathBounds(path);
          if (bounds != null) datasetTree.repaint(bounds);
        }
      }
    }

    layersTree.getUI().relayout();
    dropLocation = null;
  }