/** * Verifies if the element is an instance of a class with a given class name. If direct match * fails, implementing interfaces will be tested, then recursively all superclasses and their * interfaces. */ private boolean verifyClass(Object element, String className) { Class eclass = element.getClass(); Class clazz = eclass; boolean match = false; while (clazz != null) { // test the class itself if (clazz.getName().equals(className)) { match = true; break; } // test all the interfaces it implements Class[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (interfaces[i].getName().equals(className)) { match = true; break; } } if (match == true) { break; } // get the superclass clazz = clazz.getSuperclass(); } return match; }
/** * Check if the receiver is enabled for the given selection. * * @param selection * @return <code>true</code> if the given selection matches the conditions specified in <code> * IConfirgurationElement</code>. */ public boolean isEnabledForSelection(ISelection selection) { // Optimize it. if (mode == UNKNOWN) { return false; } // Handle undefined selections. if (selection == null) { selection = StructuredSelection.EMPTY; } // According to the dictionary, a selection is "one that // is selected", or "a collection of selected things". // In reflection of this, we deal with one or a collection. // special case: structured selections if (selection instanceof IStructuredSelection) { return isEnabledFor((IStructuredSelection) selection); } // special case: text selections // Code should read // if (selection instanceof ITextSelection) { // int count = ((ITextSelection) selection).getLength(); // return isEnabledFor(selection, count); // } // use Java reflection to avoid dependence of org.eclipse.jface.text // which is in an optional part of the generic workbench Class tselClass = getTextSelectionClass(); if (tselClass != null && tselClass.isInstance(selection)) { try { Method m = tselClass.getDeclaredMethod("getLength", new Class[0]); // $NON-NLS-1$ Object r = m.invoke(selection, new Object[0]); if (r instanceof Integer) { return isEnabledFor(selection, ((Integer) r).intValue()); } // should not happen - but enable if it does return true; } catch (NoSuchMethodException e) { // should not happen - fall through if it does } catch (IllegalAccessException e) { // should not happen - fall through if it does } catch (InvocationTargetException e) { // should not happen - fall through if it does } } // all other cases return isEnabledFor(selection); }
@Override protected final T createCellEditorOn(Composite composite) { InstallOptionsModelTypeDef typeDef = ((InstallOptionsWidget) getEditPart().getModel()).getTypeDef(); if (typeDef == null || !typeDef.getSettings().contains(getDirectEditProperty())) { return null; } else { return mEditorType.cast(createCellEditor(composite)); } }
protected T createCellEditor(Composite composite) { return mEditorType.cast(super.createCellEditorOn(composite)); }