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