|
Lines 26-31
Link Here
|
| 26 |
import org.eclipse.core.runtime.Platform; |
26 |
import org.eclipse.core.runtime.Platform; |
| 27 |
import org.eclipse.swt.custom.BusyIndicator; |
27 |
import org.eclipse.swt.custom.BusyIndicator; |
| 28 |
import org.eclipse.swt.dnd.Transfer; |
28 |
import org.eclipse.swt.dnd.Transfer; |
|
|
29 |
import org.eclipse.swt.dnd.TransferData; |
| 29 |
import org.eclipse.wst.sse.ui.internal.extension.DropActionProxy; |
30 |
import org.eclipse.wst.sse.ui.internal.extension.DropActionProxy; |
| 30 |
import org.eclipse.wst.sse.ui.internal.extension.RegistryReader; |
31 |
import org.eclipse.wst.sse.ui.internal.extension.RegistryReader; |
| 31 |
import org.osgi.framework.Bundle; |
32 |
import org.osgi.framework.Bundle; |
|
Lines 61-66
Link Here
|
| 61 |
|
62 |
|
| 62 |
public static final String TRUE = "true"; //$NON-NLS-1$ |
63 |
public static final String TRUE = "true"; //$NON-NLS-1$ |
| 63 |
|
64 |
|
|
|
65 |
private boolean useProxy; |
| 66 |
|
| 67 |
class TransferProxyForDelayLoading extends Transfer { |
| 68 |
private IConfigurationElement element; |
| 69 |
private String classAttribute; |
| 70 |
private Transfer proxy; |
| 71 |
private Method getTypeIdsMethod, getTypeNamesMethod, javaToNativeMethod, nativeToJavaMethod; |
| 72 |
|
| 73 |
TransferProxyForDelayLoading() { |
| 74 |
super(); |
| 75 |
} |
| 76 |
|
| 77 |
TransferProxyForDelayLoading(IConfigurationElement elm, String clsAttr) { |
| 78 |
super(); |
| 79 |
this.element = elm; |
| 80 |
this.classAttribute = clsAttr; |
| 81 |
} |
| 82 |
|
| 83 |
private Transfer newInstance() { |
| 84 |
if ((element != null) && (classAttribute != null)) { |
| 85 |
Object o = createExtension(element, classAttribute); |
| 86 |
if (o instanceof Transfer) { |
| 87 |
element = null; |
| 88 |
classAttribute = null; |
| 89 |
return (Transfer)o; |
| 90 |
} |
| 91 |
} |
| 92 |
return null; |
| 93 |
} |
| 94 |
|
| 95 |
public TransferData[] getSupportedTypes() { |
| 96 |
if (proxy == null) { |
| 97 |
proxy = newInstance(); |
| 98 |
} |
| 99 |
if (proxy != null) { |
| 100 |
return proxy.getSupportedTypes(); |
| 101 |
} |
| 102 |
return new TransferData[0]; |
| 103 |
} |
| 104 |
protected int[] getTypeIds() { |
| 105 |
if (proxy == null) { |
| 106 |
proxy = newInstance(); |
| 107 |
} |
| 108 |
if (proxy != null) { |
| 109 |
if (getTypeIdsMethod == null) { |
| 110 |
Class runtimeClass = proxy.getClass(); |
| 111 |
NoSuchMethodException e = null; |
| 112 |
while (runtimeClass != null) { |
| 113 |
try { |
| 114 |
getTypeIdsMethod = runtimeClass.getDeclaredMethod("getTypeIds", new Class[0]);//$NON-NLS-1$ |
| 115 |
getTypeIdsMethod.setAccessible(true); |
| 116 |
break; |
| 117 |
} catch (NoSuchMethodException e1) { |
| 118 |
e = e1; |
| 119 |
runtimeClass = runtimeClass.getSuperclass(); |
| 120 |
} catch (SecurityException e2) { |
| 121 |
runtimeClass = runtimeClass.getSuperclass(); |
| 122 |
} |
| 123 |
} |
| 124 |
if ((getTypeIdsMethod == null) && (e != null)) { |
| 125 |
Logger.logException(e); |
| 126 |
} |
| 127 |
} |
| 128 |
if (getTypeIdsMethod != null) { |
| 129 |
try { |
| 130 |
// changed Integer[] return type to int[] |
| 131 |
int[] r = (int[])getTypeIdsMethod.invoke(proxy, new Object[0]); |
| 132 |
if ((r != null) && (r.length > 0)) { |
| 133 |
int[] ret = new int[r.length]; |
| 134 |
for(int i = 0; i < r.length; i++) { |
| 135 |
ret[i] = r[i]; |
| 136 |
} |
| 137 |
return ret; |
| 138 |
} |
| 139 |
} catch (IllegalAccessException e2) { |
| 140 |
Logger.logException(e2); |
| 141 |
} catch (InvocationTargetException e3) { |
| 142 |
Logger.logException(e3); |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
return new int[0]; |
| 147 |
} |
| 148 |
protected String[] getTypeNames() { |
| 149 |
if (proxy == null) { |
| 150 |
proxy = newInstance(); |
| 151 |
} |
| 152 |
if (proxy != null) { |
| 153 |
if (getTypeNamesMethod == null) { |
| 154 |
Class runtimeClass = proxy.getClass(); |
| 155 |
NoSuchMethodException e = null; |
| 156 |
while (runtimeClass != null) { |
| 157 |
try { |
| 158 |
getTypeNamesMethod = runtimeClass.getDeclaredMethod("getTypeNames", new Class[0]);//$NON-NLS-1$ |
| 159 |
getTypeNamesMethod.setAccessible(true); |
| 160 |
break; |
| 161 |
} catch (NoSuchMethodException e1) { |
| 162 |
e = e1; |
| 163 |
runtimeClass = runtimeClass.getSuperclass(); |
| 164 |
} catch (SecurityException e2) { |
| 165 |
runtimeClass = runtimeClass.getSuperclass(); |
| 166 |
} |
| 167 |
} |
| 168 |
if ((getTypeNamesMethod == null) && (e != null)) { |
| 169 |
Logger.logException(e); |
| 170 |
} |
| 171 |
} |
| 172 |
if (getTypeNamesMethod != null) { |
| 173 |
try { |
| 174 |
return (String[])getTypeNamesMethod.invoke(proxy, new Object[0]); |
| 175 |
} catch (IllegalAccessException e2) { |
| 176 |
Logger.logException(e2); |
| 177 |
} catch (InvocationTargetException e3) { |
| 178 |
Logger.logException(e3); |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
return new String[0]; |
| 183 |
} |
| 184 |
public boolean isSupportedType(TransferData transferData) { |
| 185 |
if (proxy == null) { |
| 186 |
proxy = newInstance(); |
| 187 |
} |
| 188 |
if (proxy != null) { |
| 189 |
return proxy.isSupportedType(transferData); |
| 190 |
} |
| 191 |
return false; |
| 192 |
} |
| 193 |
protected void javaToNative(Object object, TransferData transferData) { |
| 194 |
if (proxy == null) { |
| 195 |
proxy = newInstance(); |
| 196 |
} |
| 197 |
if (proxy != null) { |
| 198 |
if (javaToNativeMethod == null) { |
| 199 |
Class runtimeClass = proxy.getClass(); |
| 200 |
NoSuchMethodException e = null; |
| 201 |
while (runtimeClass != null) { |
| 202 |
try { |
| 203 |
javaToNativeMethod = runtimeClass.getDeclaredMethod("javaToNative", new Class[]{object.getClass(), transferData.getClass()});//$NON-NLS-1$ |
| 204 |
javaToNativeMethod.setAccessible(true); |
| 205 |
break; |
| 206 |
} catch (NoSuchMethodException e1) { |
| 207 |
e = e1; |
| 208 |
runtimeClass = runtimeClass.getSuperclass(); |
| 209 |
} catch (SecurityException e2) { |
| 210 |
runtimeClass = runtimeClass.getSuperclass(); |
| 211 |
} |
| 212 |
} |
| 213 |
if ((javaToNativeMethod == null) && (e != null)) { |
| 214 |
Logger.logException(e); |
| 215 |
} |
| 216 |
} |
| 217 |
if (javaToNativeMethod != null) { |
| 218 |
try { |
| 219 |
javaToNativeMethod.invoke(proxy, new Object[]{object, transferData}); |
| 220 |
} catch (IllegalAccessException e2) { |
| 221 |
Logger.logException(e2); |
| 222 |
} catch (InvocationTargetException e3) { |
| 223 |
Logger.logException(e3); |
| 224 |
} |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
protected Object nativeToJava(TransferData transferData) { |
| 229 |
if (proxy == null) { |
| 230 |
proxy = newInstance(); |
| 231 |
} |
| 232 |
if (proxy != null) { |
| 233 |
if (nativeToJavaMethod == null) { |
| 234 |
Class runtimeClass = proxy.getClass(); |
| 235 |
NoSuchMethodException e = null; |
| 236 |
while (runtimeClass != null) { |
| 237 |
try { |
| 238 |
nativeToJavaMethod = runtimeClass.getDeclaredMethod("nativeToJava", new Class[]{transferData.getClass()});//$NON-NLS-1$ |
| 239 |
nativeToJavaMethod.setAccessible(true); |
| 240 |
break; |
| 241 |
} catch (NoSuchMethodException e1) { |
| 242 |
e = e1; |
| 243 |
runtimeClass = runtimeClass.getSuperclass(); |
| 244 |
} catch (SecurityException e2) { |
| 245 |
runtimeClass = runtimeClass.getSuperclass(); |
| 246 |
} |
| 247 |
} |
| 248 |
if ((nativeToJavaMethod == null) && (e != null)) { |
| 249 |
Logger.logException(e); |
| 250 |
} |
| 251 |
} |
| 252 |
if (nativeToJavaMethod != null) { |
| 253 |
try { |
| 254 |
return nativeToJavaMethod.invoke(proxy, new Object[]{transferData}); |
| 255 |
} catch (IllegalAccessException e2) { |
| 256 |
Logger.logException(e2); |
| 257 |
} catch (InvocationTargetException e3) { |
| 258 |
Logger.logException(e3); |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
return new Object(); |
| 263 |
} |
| 264 |
Transfer getTransferClass() { |
| 265 |
if (proxy == null) { |
| 266 |
proxy = newInstance(); |
| 267 |
} |
| 268 |
return proxy; |
| 269 |
} |
| 270 |
} |
| 64 |
/** |
271 |
/** |
| 65 |
* @param element |
272 |
* @param element |
| 66 |
* @param classAttribute |
273 |
* @param classAttribute |
|
Lines 209-216
Link Here
|
| 209 |
* @return Transfer |
416 |
* @return Transfer |
| 210 |
*/ |
417 |
*/ |
| 211 |
protected Transfer createTransfer(IConfigurationElement element) { |
418 |
protected Transfer createTransfer(IConfigurationElement element) { |
| 212 |
Object obj = null; |
419 |
Object obj = null; |
| 213 |
obj = createExtension(element, ATT_CLASS); |
420 |
if (useProxy == true) { |
|
|
421 |
obj = new TransferProxyForDelayLoading(element, ATT_CLASS); |
| 422 |
} else { |
| 423 |
obj = createExtension(element, ATT_CLASS); |
| 424 |
} |
| 214 |
if (obj == null) |
425 |
if (obj == null) |
| 215 |
return null; |
426 |
return null; |
| 216 |
return (obj instanceof Transfer) ? (Transfer) obj : null; |
427 |
return (obj instanceof Transfer) ? (Transfer) obj : null; |
|
Lines 282-287
Link Here
|
| 282 |
} |
493 |
} |
| 283 |
|
494 |
|
| 284 |
/** |
495 |
/** |
|
|
496 |
* @deprecated use getDropActions(String editorId, Transfer transfer) for the performance |
| 285 |
* @param editorId |
497 |
* @param editorId |
| 286 |
* @param className |
498 |
* @param className |
| 287 |
* @return IDropAction[] |
499 |
* @return IDropAction[] |
|
Lines 289-297
Link Here
|
| 289 |
public IDropAction[] getDropActions(String editorId, String transferClassName) { |
501 |
public IDropAction[] getDropActions(String editorId, String transferClassName) { |
| 290 |
return getDropActions(new String[]{editorId}, transferClassName); |
502 |
return getDropActions(new String[]{editorId}, transferClassName); |
| 291 |
} |
503 |
} |
| 292 |
|
504 |
|
| 293 |
/** |
505 |
/** |
| 294 |
* @param editorId |
506 |
* @param editorId |
|
|
507 |
* @param class |
| 508 |
* @return IDropAction[] |
| 509 |
*/ |
| 510 |
public IDropAction[] getDropActions(String editorId, Transfer transfer) { |
| 511 |
return getDropActions(new String[]{editorId}, transfer); |
| 512 |
} |
| 513 |
/** |
| 514 |
* @deprecated use getDropActions(String[] editorIds, Transfer transfer) for the performance |
| 515 |
* @param editorId |
| 295 |
* @param className |
516 |
* @param className |
| 296 |
* @return IDropAction[] |
517 |
* @return IDropAction[] |
| 297 |
*/ |
518 |
*/ |
|
Lines 307-312
Link Here
|
| 307 |
|
528 |
|
| 308 |
/** |
529 |
/** |
| 309 |
* @param editorId |
530 |
* @param editorId |
|
|
531 |
* @param class |
| 532 |
* @return IDropAction[] |
| 533 |
*/ |
| 534 |
public IDropAction[] getDropActions(String[] editorIds, Transfer transfer) { |
| 535 |
String transferClassName; |
| 536 |
if (transfer instanceof TransferProxyForDelayLoading) { |
| 537 |
transferClassName = ((TransferProxyForDelayLoading)transfer).getTransferClass().getClass().getName(); |
| 538 |
} else { |
| 539 |
transferClassName = transfer.getClass().getName(); |
| 540 |
} |
| 541 |
return getDropActions(editorIds, transferClassName); |
| 542 |
} |
| 543 |
/** |
| 544 |
* @param editorId |
| 310 |
* @return Transfer[] |
545 |
* @return Transfer[] |
| 311 |
*/ |
546 |
*/ |
| 312 |
public Transfer[] getDropTargetTransfers(String editorId) { |
547 |
public Transfer[] getDropTargetTransfers(String editorId) { |
|
Lines 413-416
Link Here
|
| 413 |
readElementChildren(element); |
648 |
readElementChildren(element); |
| 414 |
return true; |
649 |
return true; |
| 415 |
} |
650 |
} |
|
|
651 |
/** |
| 652 |
* @deprecated - use TransferBuilder(boolean useProxy) for the performance |
| 653 |
*/ |
| 654 |
public TransferBuilder() { |
| 655 |
this(false); |
| 656 |
} |
| 657 |
|
| 658 |
public TransferBuilder(boolean useProxy) { |
| 659 |
super(); |
| 660 |
this.useProxy = useProxy; |
| 661 |
} |
| 416 |
} |
662 |
} |