1 11 12 package org.eclipse.ui.internal.navigator.dnd; 13 14 import org.eclipse.core.expressions.EvaluationContext; 15 import org.eclipse.core.expressions.EvaluationResult; 16 import org.eclipse.core.expressions.Expression; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.jface.viewers.IStructuredSelection; 20 import org.eclipse.ui.internal.navigator.CustomAndExpression; 21 import org.eclipse.ui.internal.navigator.NavigatorPlugin; 22 import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants; 23 import org.eclipse.ui.navigator.CommonDropAdapterAssistant; 24 import org.eclipse.ui.navigator.INavigatorContentDescriptor; 25 26 30 public final class CommonDropAdapterDescriptor implements 31 INavigatorContentExtPtConstants { 32 33 private final IConfigurationElement element; 34 35 private final INavigatorContentDescriptor contentDescriptor; 36 37 private Expression dropExpr; 38 39 CommonDropAdapterDescriptor( 40 IConfigurationElement aConfigElement, 41 INavigatorContentDescriptor aContentDescriptor) { 42 element = aConfigElement; 43 contentDescriptor = aContentDescriptor; 44 init(); 45 } 46 47 private void init() { 48 IConfigurationElement[] children = element.getChildren(TAG_POSSIBLE_DROP_TARGETS); 49 if (children.length == 1) { 50 dropExpr = new CustomAndExpression(children[0]); 51 } 52 } 53 54 61 public boolean isDragElementSupported(Object anElement) { 62 return contentDescriptor.isPossibleChild(anElement); 63 } 64 65 72 public boolean areDragElementsSupported(IStructuredSelection aSelection) { 73 if (aSelection.isEmpty()) { 74 return false; 75 } 76 return contentDescriptor.arePossibleChildren(aSelection); 77 } 78 79 86 public boolean isDropElementSupported(Object anElement) { 87 if (dropExpr != null && anElement != null) { 88 try { 89 EvaluationContext context = new EvaluationContext(null, anElement); 90 context.setAllowPluginActivation(true); 91 return dropExpr 92 .evaluate(context) == EvaluationResult.TRUE; 93 } catch (CoreException e) { 94 NavigatorPlugin.logError(0, e.getMessage(), e); 95 } 96 } 97 return false; 98 } 99 100 105 public CommonDropAdapterAssistant createDropAssistant() { 106 107 try { 108 return (CommonDropAdapterAssistant) element 109 .createExecutableExtension(ATT_CLASS); 110 } catch (CoreException e) { 111 NavigatorPlugin.logError(0, e.getMessage(), e); 112 } catch (RuntimeException re) { 113 NavigatorPlugin.logError(0, re.getMessage(), re); 114 } 115 return SkeletonCommonDropAssistant.INSTANCE; 116 } 117 118 122 public INavigatorContentDescriptor getContentDescriptor() { 123 return contentDescriptor; 124 } 125 126 } 127 | Popular Tags |