IOp getOperation() { if (operation == null) { try { operation = (IOp) configElem.createExecutableExtension("class"); // $NON-NLS-1$ } catch (CoreException e) { UiPlugin.log("Error loading operation implementation", e); // $NON-NLS-1$ final Display display = Display.getDefault(); Runnable runnable = new Runnable() { public void run() { setEnabled(false); MessageDialog.openError( display.getActiveShell(), Messages.get("OpAction_errorTitle"), Messages.get("OpAction_errorMessage")); } }; loadingError = true; display.asyncExec(runnable); } } return operation; }
protected IStatus run(final IProgressMonitor monitor) { try { final Object target; if (enablesForData.minHits == 1 && enablesForData.exactMatch) { try { target = AdapterUtil.instance.adapt(targetClass, selection.getFirstElement(), monitor); if (target == null) { UiPlugin.log( "Factory adapting " + selection.getFirstElement().getClass().getName() + " to a " + //$NON-NLS-1$ //$NON-NLS-2$ targetClass + " is returning null even though it is advertising that it can " + //$NON-NLS-1$ "do the adaptation", null); //$NON-NLS-1$ return Status.OK_STATUS; } } catch (Throwable e) { UiPlugin.log(null, e); return Status.OK_STATUS; } } else { List<Object> targets = new LinkedList<Object>(); for (Iterator iter = selection.iterator(); iter.hasNext(); ) { @SuppressWarnings("unchecked") Object entry = iter.next(); try { Object operationTarget = AdapterUtil.instance.adapt(targetClass, entry, monitor); if (operationTarget == null) { UiPlugin.log( "Factory adapting " + entry.getClass().getName() + " to a " + //$NON-NLS-1$ //$NON-NLS-2$ targetClass + " is returning null even though it is advertising that it can " + //$NON-NLS-1$ "do the adaptation", null); //$NON-NLS-1$ return Status.OK_STATUS; } else { targets.add(operationTarget); } } catch (Throwable e) { UiPlugin.log(null, e); return Status.OK_STATUS; } } Class targetClass = targets.get(0).getClass(); Object[] tmp = (Object[]) Array.newInstance(targetClass, targets.size()); if (enablesForData.minHits == 1 && enablesForData.exactMatch) { target = targets.size() > 0 ? targets.get(0) : null; } else { target = targets.toArray(tmp); } } final IOp op = getOperation(); UICallBack.runNonUIThreadWithFakeContext( display, new Runnable() { public void run() { try { op.op(display, target, monitor); } catch (Exception e) { e.printStackTrace(); } } }); } catch (Throwable e) { UiPlugin.log(null, e); } return Status.OK_STATUS; }