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 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 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 /** {@inheritDoc} */ 049 @Override 050 public boolean isDataFlavorSupported(DataFlavor df) { 051 return df.equals(INFO_FLAVOR); 052 } 053 054 /** {@inheritDoc} */ 055 @Override 056 public Object getTransferData(DataFlavor df) 057 throws UnsupportedFlavorException, IOException { 058 if (!isDataFlavorSupported(df)) { 059 throw new UnsupportedFlavorException(df); 060 } 061 return this; 062 } 063 064 /** {@inheritDoc} */ 065 @Override 066 public DataFlavor[] getTransferDataFlavors() { 067 return FLAVORS; 068 } 069 070 /** 071 * Returns the nodes that are being dragged (and dropped). 072 * @return the nodes that are being dragged (and dropped). 073 */ 074 public BrowserNodeInfo[] getNodes() 075 { 076 return nodes; 077 } 078 079 /** 080 * Sets the nodes that are being dragged (and dropped). 081 * @param nodes the nodes that are being dragged (and dropped). 082 */ 083 public void setNodes(BrowserNodeInfo[] nodes) 084 { 085 this.nodes = nodes; 086 } 087 088 /** 089 * Returns the component that contains the nodes (for instance the tree in 090 * the LDAP browser). 091 * @return the component that contains the nodes (for instance the tree in 092 * the LDAP browser). 093 */ 094 public Component getParent() 095 { 096 return parent; 097 } 098 099 /** 100 * Sets the component that contains the nodes (for instance the tree in 101 * the LDAP browser). 102 * @param parent the component that contains the nodes. 103 */ 104 public void setParent(Component parent) 105 { 106 this.parent = parent; 107 } 108}