1 11 package org.eclipse.pde.internal.ui.editor.schema; 12 13 import org.eclipse.jface.viewers.ViewerDropAdapter; 14 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; 15 import org.eclipse.pde.internal.core.ischema.ISchemaCompositor; 16 import org.eclipse.pde.internal.core.ischema.ISchemaElement; 17 import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference; 18 import org.eclipse.pde.internal.ui.editor.ModelDataTransfer; 19 import org.eclipse.swt.dnd.TransferData; 20 21 public class ElementSectionDropAdapter extends ViewerDropAdapter { 22 private TransferData fCurrentTransfer; 23 private ElementSection fSsection; 24 private ElementSectionDragAdapter fDragAdapter; 25 26 public ElementSectionDropAdapter(ElementSectionDragAdapter dragAdapter, ElementSection section) { 27 super(section.getTreeViewer()); 28 fSsection = section; 29 fDragAdapter = dragAdapter; 30 } 31 32 35 public boolean performDrop(Object data) { 36 fSsection.handleOp(getCurrentTarget(), fDragAdapter.getDragData(), getCurrentOperation()); 37 return true; 38 } 39 40 43 public boolean validateDrop(Object target, int operation, TransferData transferType) { 44 fCurrentTransfer = transferType; 45 if (!ModelDataTransfer.getInstance().isSupportedType(fCurrentTransfer)) 46 return false; 47 Object cargo = getSelectedObject(); 48 49 if (cargo instanceof ISchemaObjectReference) { if ((target instanceof ISchemaCompositor 52 || target instanceof ISchemaObjectReference)) 53 return true; 54 } else if (cargo instanceof ISchemaElement) { if (target instanceof ISchemaCompositor || target instanceof ISchemaObjectReference || isNonRefElement(target) || target == null) 57 return true; 58 } else if (cargo instanceof ISchemaCompositor) { if (isNonRefElement(target) || target instanceof ISchemaCompositor || target instanceof ISchemaObjectReference) 61 return true; 62 } else if (cargo instanceof ISchemaAttribute) { if (isNonRefElement(target) || target instanceof ISchemaAttribute) 65 return true; 66 } 67 return false; 68 } 69 70 private boolean isNonRefElement(Object obj) { 71 return (obj instanceof ISchemaElement && !(obj instanceof ISchemaObjectReference)); 72 } 73 } 74 | Popular Tags |