public Collection getAllModelElementsOfKind(Object nsa, Object type) {
    if (!(nsa instanceof Element)) {
      return new ArrayList<Element>();
    }
    Class theType = null;
    if (type instanceof String) {
      try {
        theType = Class.forName((String) type);
      } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e);
      }
    } else if (type instanceof Class) {
      theType = (Class) type;
    } else {
      throw new IllegalArgumentException("type must be instance of Class or String"); // $NON-NLS-1$
    }
    if (!Element.class.isAssignableFrom(theType)) {
      throw new IllegalArgumentException("type must represent an Element"); // $NON-NLS-1$
    }

    Collection<Element> result = new ArrayList<Element>();

    for (Element element : ((Namespace) nsa).allOwnedElements()) {
      if (theType.isAssignableFrom(element.getClass())) {
        result.add(element);
      }
    }

    return result;
  }
コード例 #2
0
 /**
  * Returns the image for the element
  *
  * @param editPart the edit part that displays the element
  * @return the image
  */
 public Image getImage(GraphicalEditPart editPart) {
   Element element = getUMLElement(editPart);
   String key = "";
   if (element instanceof NamedElement) {
     key = ((NamedElement) element).getName() + "::" + ((NamedElement) element).getVisibility();
   } else if (element != null) {
     key = element.getClass().getName();
   } else {
     return null;
   }
   ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
   Image image = imageRegistry.get(key);
   ImageDescriptor descriptor = null;
   if (image == null) {
     AdapterFactory factory = Activator.getDefault().getItemProvidersAdapterFactory();
     IItemLabelProvider labelProvider =
         (IItemLabelProvider) factory.adapt(getUMLElement(editPart), IItemLabelProvider.class);
     if (labelProvider != null) {
       descriptor =
           ExtendedImageRegistry.getInstance()
               .getImageDescriptor(labelProvider.getImage(getUMLElement(editPart)));
     }
     if (descriptor == null) {
       descriptor = ImageDescriptor.getMissingImageDescriptor();
     }
     imageRegistry.put(key, descriptor);
     image = imageRegistry.get(key);
   }
   return image;
 }