Transferable t = dropEvent.getTransferable();
Component src = t.getSourceComponent();
Object sourceItemId;
Object newItemId = null;
// Item subItem = null;
HierarchicalContainer container = (HierarchicalContainer) tree.getContainerDataSource();
if (src instanceof WidgetDragAndDropWrapper) {
WidgetDragAndDropWrapper dragAndDropWrapper = (WidgetDragAndDropWrapper) src;
Class cls = dragAndDropWrapper.getCls();
Object widgetElement = null;
try {
widgetElement = cls.newInstance();
/*subItem = */addTreeItem(widgetElement);
newItemId = widgetElement;
sourceItemId = widgetElement;
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
src.getApplication().getMainWindow().showNotification(getLocalizedMessage("widget-creation-failed"),
e.getClass().getName() + ", " + e.getMessage(),
Window.Notification.TYPE_ERROR_MESSAGE);
// if (subItem != null && widgetElement != null) {
// container.removeItem(widgetElement);
// }
return;
}
} else {
if (src != tree || !(t instanceof DataBoundTransferable)) {
return;
}
sourceItemId = ((DataBoundTransferable) t).getItemId();
}
Tree.TreeTargetDetails dropData = ((Tree.TreeTargetDetails) dropEvent
.getTargetDetails());
Object targetItemId = dropData.getItemIdOver();
VerticalDropLocation location = dropData.getDropLocation();
if (targetItemId instanceof WidgetsDefinitionElement) { //the can be only one! ... root element2
location = VerticalDropLocation.MIDDLE;
}
if (!moveNode(sourceItemId, targetItemId, location)) {
if (newItemId != null) {
container.removeItem(newItemId);
}
} else {
refreshRawXmlAndPreview();
}
}