下面列出了org.eclipse.ui.navigator.CommonDropAdapter#getCurrentTransfer ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public IStatus handleDrop(CommonDropAdapter dropAdapter,
DropTargetEvent event, Object target) {
try {
// drop in folder
if (target instanceof IXdsFolderContainer ||
target instanceof IProject ||
target instanceof IContainer ||
(dropAdapter.getCurrentOperation() == DND.DROP_COPY && (
target instanceof IFile ||
target instanceof IXdsResource))) {
final Object data= event.data;
if (data == null) {
return Status.CANCEL_STATUS;
}
final IContainer destination= getDestination(target);
if (destination == null) {
return Status.CANCEL_STATUS;
}
IResource[] resources = null;
TransferData currentTransfer = dropAdapter.getCurrentTransfer();
final int dropOperation = dropAdapter.getCurrentOperation();
if (LocalSelectionTransfer.getTransfer().isSupportedType(
currentTransfer)) {
resources = getSelectedResources();
} else if (ResourceTransfer.getInstance().isSupportedType(
currentTransfer)) {
resources = (IResource[]) event.data;
}
if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
final String[] names = (String[]) data;
// Run the import operation asynchronously.
// Otherwise the drag source (e.g., Windows Explorer) will be blocked
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
getShell().forceActive();
CopyFilesAndFoldersOperation op= new CopyFilesAndFoldersOperation(getShell());
op.copyOrLinkFiles(names, destination, dropOperation);
}
});
} else if (event.detail == DND.DROP_COPY || event.detail == DND.DROP_LINK) {
return performResourceCopy(dropAdapter, getShell(), resources);
} else {
ReadOnlyStateChecker checker = new ReadOnlyStateChecker(
getShell(),
"Move Resource Action", //$NON-NLS-1$
"Move Resource Action");//$NON-NLS-1$
resources = checker.checkReadOnlyResources(resources);
MoveFilesAndFoldersOperation operation = new MoveFilesAndFoldersOperation(getShell());
operation.copyResources(resources, destination);
}
return Status.OK_STATUS;
}
}
finally {
// The drag source listener must not perform any operation
// since this drop adapter did the remove of the source even
// if we moved something.
event.detail= DND.DROP_NONE;
}
return Status.CANCEL_STATUS;
}
public IStatus handleDrop(CommonDropAdapter aDropAdapter,
DropTargetEvent aDropTargetEvent, Object aTarget) {
if (Policy.DEBUG_DND) {
System.out
.println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$
}
// alwaysOverwrite = false;
if (aTarget == null || aDropTargetEvent.data == null) {
return Status.CANCEL_STATUS;
}
IStatus status = null;
IResource[] resources = null;
TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
if (LocalSelectionTransfer.getTransfer().isSupportedType(
currentTransfer)) {
resources = getSelectedResources();
} else if (ResourceTransfer.getInstance().isSupportedType(
currentTransfer)) {
resources = (IResource[]) aDropTargetEvent.data;
}
if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
status = performFileDrop(aDropAdapter, aDropTargetEvent.data);
} else if (resources != null && resources.length > 0) {
if ((aDropAdapter.getCurrentOperation() == DND.DROP_COPY)
|| (aDropAdapter.getCurrentOperation() == DND.DROP_LINK)) {
if (Policy.DEBUG_DND) {
System.out
.println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$
}
status = performResourceCopy(aDropAdapter, getShell(),
resources);
} else {
if (Policy.DEBUG_DND) {
System.out
.println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$
}
status = performResourceMove(aDropAdapter, resources);
}
}
openError(status);
IContainer target = getActualTarget((IResource) aTarget);
if (target != null && target.isAccessible()) {
try {
target.refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e) {
}
}
return status;
}
public IStatus handleDrop(CommonDropAdapter aDropAdapter,
DropTargetEvent aDropTargetEvent, Object aTarget) {
if (Policy.DEBUG_DND) {
System.out
.println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$
}
// alwaysOverwrite = false;
if (aTarget == null || aDropTargetEvent.data == null) {
return Status.CANCEL_STATUS;
}
IStatus status = null;
IResource[] resources = null;
TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
if (LocalSelectionTransfer.getTransfer().isSupportedType(
currentTransfer)) {
resources = getSelectedResources();
} else if (ResourceTransfer.getInstance().isSupportedType(
currentTransfer)) {
resources = (IResource[]) aDropTargetEvent.data;
}
if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
status = performFileDrop(aDropAdapter, aDropTargetEvent.data);
} else if (resources != null && resources.length > 0) {
if ((aDropAdapter.getCurrentOperation() == DND.DROP_COPY)
|| (aDropAdapter.getCurrentOperation() == DND.DROP_LINK)) {
if (Policy.DEBUG_DND) {
System.out
.println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$
}
status = performResourceCopy(aDropAdapter, getShell(),
resources);
} else {
if (Policy.DEBUG_DND) {
System.out
.println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$
}
status = performResourceMove(aDropAdapter, resources);
}
}
openError(status);
IContainer target = getActualTarget((IResource) aTarget);
if (target != null && target.isAccessible()) {
try {
target.refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e) {
}
}
return status;
}
@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
// aTarget = getActual(aTarget);
if (DEBUG) {
System.out.println("ResourceDropAdapterAssistant.handleDrop (begin)"); //$NON-NLS-1$
}
// alwaysOverwrite = false;
if (getCurrentTarget(aDropAdapter) == null || aDropTargetEvent.data == null) {
return Status.CANCEL_STATUS;
}
IStatus status = null;
IResource[] resources = null;
TransferData currentTransfer = aDropAdapter.getCurrentTransfer();
if (LocalSelectionTransfer.getTransfer().isSupportedType(currentTransfer)) {
resources = getSelectedResources();
} else if (ResourceTransfer.getInstance().isSupportedType(currentTransfer)) {
resources = (IResource[]) aDropTargetEvent.data;
}
if (FileTransfer.getInstance().isSupportedType(currentTransfer)) {
status = performFileDrop(aDropAdapter, aDropTargetEvent.data);
} else if (resources != null && resources.length > 0) {
if (aDropAdapter.getCurrentOperation() == DND.DROP_COPY) {
if (DEBUG) {
System.out.println("ResourceDropAdapterAssistant.handleDrop executing COPY."); //$NON-NLS-1$
}
status = performResourceCopy(aDropAdapter, getShell(), resources);
} else {
if (DEBUG) {
System.out.println("ResourceDropAdapterAssistant.handleDrop executing MOVE."); //$NON-NLS-1$
}
status = performResourceMove(aDropAdapter, resources);
}
}
openError(status);
IContainer target = getActualTarget((IResource) getCurrentTarget(aDropAdapter));
if (target != null && target.isAccessible()) {
try {
target.refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e) {
}
}
return status;
}