@SuppressWarnings("unchecked") protected void setUp() throws Exception { super.setUp(); Display display = Display.getCurrent(); shell = new Shell(display.getActiveShell()); shell.setLayout(new FillLayout()); SimpleFeatureType ft = DataUtilities.createType("type", "name:String,id:int"); // $NON-NLS-1$//$NON-NLS-2$ feature1 = SimpleFeatureBuilder.build( ft, new Object[] {"feature1", 1}, "feature1"); // $NON-NLS-1$ //$NON-NLS-2$ feature2 = SimpleFeatureBuilder.build( ft, new Object[] {"feature2", 2}, "feature2"); // $NON-NLS-1$ //$NON-NLS-2$ feature3 = SimpleFeatureBuilder.build( ft, new Object[] {"feature3", 3}, "feature3"); // $NON-NLS-1$ //$NON-NLS-2$ feature4 = SimpleFeatureBuilder.build( ft, new Object[] {"feature4", 4}, "feature4"); // $NON-NLS-1$ //$NON-NLS-2$ features = FeatureCollections.newCollection(); features.add(feature1); features.add(feature2); features.add(feature3); features.add(feature4); UiPlugin.getDefault().getPreferenceStore().setValue(FeatureTableControl.CACHING_WARNING, true); table = new FeatureTableControl( new StaticProvider<IProgressMonitor>(new NullProgressMonitor()), shell, features); shell.open(); shell.redraw(); while (Display.getCurrent().readAndDispatch()) ; }
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; }