001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2015 ForgeRock AS
026 */
027package org.opends.guitools.controlpanel.ui.nodes;
028
029import java.awt.Component;
030import java.awt.datatransfer.DataFlavor;
031import java.awt.datatransfer.Transferable;
032import java.awt.datatransfer.UnsupportedFlavorException;
033import java.io.IOException;
034
035/**
036 * An implementation of Transferable used in the LDAP entry browser to use
037 * drag and drop.  Currently drag and drop is used for instance to drag a
038 * number of entries from a browser and drop them in the list of members of
039 * a group.
040 */
041public class DndBrowserNodes implements Transferable {
042  /** The data flavor managed by this transferable. */
043  public static final DataFlavor INFO_FLAVOR =
044    new DataFlavor(BrowserNodeInfo.class, "Browse Node Information");
045
046  static DataFlavor[] FLAVORS = {INFO_FLAVOR };
047
048  private BrowserNodeInfo[] nodes;
049
050  /** The component that contains the nodes. */
051  private Component parent;
052
053  /**
054   * Transferable implementation
055   * ============================================
056   */
057
058  /** {@inheritDoc} */
059  @Override
060  public boolean isDataFlavorSupported(DataFlavor df) {
061    return df.equals(INFO_FLAVOR);
062  }
063
064  /** {@inheritDoc} */
065  @Override
066  public Object getTransferData(DataFlavor df)
067  throws UnsupportedFlavorException, IOException {
068    if (!isDataFlavorSupported(df)) {
069      throw new UnsupportedFlavorException(df);
070    }
071    return this;
072  }
073
074  /** {@inheritDoc} */
075  @Override
076  public DataFlavor[] getTransferDataFlavors() {
077    return FLAVORS;
078  }
079
080  /**
081   * Returns the nodes that are being dragged (and dropped).
082   * @return the nodes that are being dragged (and dropped).
083   */
084  public BrowserNodeInfo[] getNodes()
085  {
086    return nodes;
087  }
088
089  /**
090   * Sets the nodes that are being dragged (and dropped).
091   * @param nodes the nodes that are being dragged (and dropped).
092   */
093  public void setNodes(BrowserNodeInfo[] nodes)
094  {
095    this.nodes = nodes;
096  }
097
098  /**
099   * Returns the component that contains the nodes (for instance the tree in
100   * the LDAP browser).
101   * @return the component that contains the nodes (for instance the tree in
102   * the LDAP browser).
103   */
104  public Component getParent()
105  {
106    return parent;
107  }
108
109  /**
110   * Sets the component that contains the nodes (for instance the tree in
111   * the LDAP browser).
112   * @param parent the component that contains the nodes.
113   */
114  public void setParent(Component parent)
115  {
116    this.parent = parent;
117  }
118}