I use linux and Sun JDK 1.3.1-RC1. With Sun 1.3.0_02 or IBM 1.3.0, result
is the same with just a different error :
message:java.awt.dnd.InvalidDnDOperationException: The operation requested
cannot be performed by the DnD system since it is not in the appropriate
state
The fact that only drag attempts followed by a sucessful drop make the next
one fails makes me think there is something incorrect in my drop code. But
i don't see what :
public void drop(DropTargetDropEvent ev) {
try {
Transferable tr = ev.getTransferable();
if
(tr.isDataFlavorSupported(WidgetSelection.CLASS_DESCRIPTION_FLAVOR)) {
ev.acceptDrop(DnDConstants.ACTION_REFERENCE);
ClassDescription desc = (ClassDescription)
tr.getTransferData(WidgetSelection.CLASS_DESCRIPTION_FLAVOR);
createClassFrame(desc, ev.getLocation());
ev.dropComplete(true);
} else {
ev.rejectDrop();
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
}
}
And here is the WidgetSelection class :
public class WidgetSelection implements Transferable {
public static final DataFlavor CLASS_DESCRIPTION_FLAVOR = new
DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + ";
class=fr.jussieu.snv.lis.osis.access.metadata.ClassDescription",
"Class description"
);
public static final DataFlavor PROPERTY_DESCRIPTION_FLAVOR = new
DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + ";
class=fr.jussieu.snv.lis.osis.access.metadata.PropertyDescription",
"Property description"
);
public static final DataFlavor DOMAIN_OBJECT_FLAVOR = new DataFlavor(
DataFlavor.javaJVMLocalObjectMimeType + "; class=java.lang.Object",
"Domain object"
);
private Object selection;
private DataFlavor currentFlavor;
public WidgetSelection(Object selection) {
this.selection = selection;
if (selection instanceof ClassDescription)
currentFlavor = CLASS_DESCRIPTION_FLAVOR;
else if (selection instanceof PropertyDescription)
currentFlavor = PROPERTY_DESCRIPTION_FLAVOR;
else
currentFlavor = DOMAIN_OBJECT_FLAVOR;
}
public Object getTransferData(DataFlavor flavor) throws
UnsupportedFlavorException, IOException {
if (flavor == currentFlavor)
return selection;
else
throw new UnsupportedFlavorException(flavor);
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
if (flavor == currentFlavor)
return true;
else
return false;
}
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {currentFlavor};
}
}
Any help appreciated !