Java源码示例:org.openide.util.datatransfer.MultiTransferObject
示例1
public void testMultiTransferableForCopy() throws Exception {
N node = new N();
N n2 = new N();
N[] arr = { node, n2 };
Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_COPY);
assertEquals("One call to copy", 1, node.copy);
assertEquals("One call to copy on n2", 1, n2.copy);
assertEquals("Also one call to drag which delegates to copy", 1, node.drag);
assertEquals("Also one call to drag which delegates to copy on n2", 1, n2.drag);
assertEquals("No call to cut", 0, node.cut);
assertEquals("No call to cut", 0, n2.cut);
assertNotNull("Call to convertor", last);
assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
Object obj = last.getTransferData(ExTransferable.multiFlavor);
if (!( obj instanceof MultiTransferObject)) {
fail("It should be MultiTransferObject: " + obj);
}
MultiTransferObject m = (MultiTransferObject)obj;
assertEquals("Two in multi", 2, m.getCount());
assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
示例2
public void testMultiTransferableForCut() throws Exception {
N node = new N();
N n2 = new N();
N[] arr = { node, n2 };
Transferable t = DragDropUtilities.getNodeTransferable(arr, NodeTransfer.DND_MOVE);
assertEquals("One call to cut ", 1, node.cut);
assertEquals("One call to cut on n2", 1, n2.cut);
assertEquals("No to drag", 0, node.drag);
assertEquals("No to drag on n2", 0, n2.drag);
assertEquals("No call to copy", 0, node.copy);
assertEquals("No call to copy on n2", 0, n2.copy);
assertNotNull("Call to convertor", last);
assertTrue("multi flavor supported", last.isDataFlavorSupported(ExTransferable.multiFlavor));
Object obj = last.getTransferData(ExTransferable.multiFlavor);
if (!( obj instanceof MultiTransferObject)) {
fail("It should be MultiTransferObject: " + obj);
}
MultiTransferObject m = (MultiTransferObject)obj;
assertEquals("Two in multi", 2, m.getCount());
assertTrue("Is string", m.getTransferData(0, DataFlavor.stringFlavor) instanceof String);
assertTrue("Is string2", m.getTransferData(1, DataFlavor.stringFlavor) instanceof String);
}
示例3
private boolean isDBFlavor(Transferable transferable) {
DataFlavor[] flavors = transferable.getTransferDataFlavors();
for (DataFlavor flavor : flavors) {
Object transferData = null;
try {
transferData = transferable.getTransferData(flavor);
} catch (UnsupportedFlavorException | IOException ex) {
}
if (DB_TYPE.equals(flavor.getSubType()) && PRIMARY_TYPE.equals(flavor.getPrimaryType())) {
return true;
} else if (transferData instanceof MultiTransferObject) {
MultiTransferObject multiTransfer = (MultiTransferObject) transferData;
for (int i = 0; i < multiTransfer.getCount(); i++) {
if (isDBFlavor(multiTransfer.getTransferableAt(i))) {
return true;
}
}
} else if ("org.netbeans.modules.db.explorer.node.TableListNode"
.equals(transferData.getClass().getName())
|| "org.netbeans.modules.db.explorer.node.SchemaNode"
.equals(transferData.getClass().getName())) {
return true;
} else if ("org.netbeans.modules.db.explorer.node.ConnectionNode"
.equals(transferData.getClass().getName())) {
return false;
}
}
return false;
}
示例4
@Override
public boolean canImport(TransferHandler.TransferSupport info) {
if(info.isDataFlavorSupported(DataFlavor.stringFlavor))
return true;
try {
if(info.getDataFlavors().length > 0) {
Object transferData = info.getTransferable().getTransferData(info.getDataFlavors()[0]);
if (transferData instanceof PNode) {
return true;
} else if(transferData instanceof MultiTransferObject) {
final MultiTransferObject multi = (MultiTransferObject) transferData;
boolean allPNode = true;
DataFlavor dataFlavor = multi.getTransferDataFlavors(0)[0];
for(int i=0; i < multi.getCount(); ++i) {
Object data = multi.getTransferData(i, dataFlavor);
if(!(data instanceof PNode)) {
allPNode = false;
break;
}
}
return allPNode;
}
}
} catch (Exception e) {
return false;
}
return false;
}