Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Easy way of Filtering in EMF List Dialogs(EMF Default List Value Editors)
Easy way of Filtering in EMF List Dialogs [message #1758879] Tue, 04 April 2017 06:48 Go to next message
Oscar Slotosch is currently offline Oscar SlotoschFriend
Messages: 14
Registered: April 2012
Junior Member
Hello,
Is there an recommended / easy way to filter out the elements shown in the default list dialog?
I have a List-relation in my ecore model but I do not want to see all elements from the model in the dialog when assigning the elements of that list.
(As an example you might think of showing only the classes with the same package
compared to shwoing all classes of the complete model as alternatives in the dialog).

Easy would me, some lines of code in adapting the editor, an extension point,..
Re: Easy way of Filtering in EMF List Dialogs [message #1758887 is a reply to message #1758879] Tue, 04 April 2017 07:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29112
Registered: July 2009
Senior Member
Here's an example from org.eclipse.emf.ecore.provider.EReferenceItemProvider.addEKeysPropertyDescriptor(Object)
  /**
   * This adds a property descriptor for the Keys feature.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated NOT
   */
  protected void addEKeysPropertyDescriptor(Object object)
  {
    itemPropertyDescriptors.add
      (new ItemPropertyDescriptor
        (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
         getResourceLocator(),
         getString("_UI_EReference_eKeys_feature"),
         getString("_UI_EReference_eKeys_description"),
         EcorePackage.Literals.EREFERENCE__EKEYS,
         true,
         false,
         false,
         null,
         null,
         null)
      {
        @Override
        public Collection<?> getChoiceOfValues(Object object)
        {
          EReference eReference = (EReference)object;
          List<Object> result = new ArrayList<Object>();
          if (eReference.getEType() instanceof EClass)
          {
            result.addAll(eReference.getEReferenceType().getEAllAttributes());
          }
          return result;
        }
      });
  }
So the idea is just to specialize the item property descriptor's getChoiceOfValues method to return only the choices you want. You might call supergetChoiceOfValues and filter it down to what you want, or, as in this case, gather the choices in some other way.
Re: Easy way of Filtering in EMF List Dialogs [message #1759017 is a reply to message #1758887] Wed, 05 April 2017 09:28 Go to previous message
Oscar Slotosch is currently offline Oscar SlotoschFriend
Messages: 14
Registered: April 2012
Junior Member
Ed, thank you very much this fast and perfect answer!
That was exactly what I was looking for.
So I added your proposed method (modified for my model) into the generated ItemProviders.
Also using super.getChoiceOfValues (object) was helpful.
Previous Topic:custom labels
Next Topic:is there a way to ignore an EPackage during the java code generation ?
Goto Forum:
  


Current Time: Wed Jan 17 03:13:09 GMT 2018

Powered by FUDForum. Page generated in 0.02058 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software