This tutorial is an EMF tutorial and is compatible with GMF. To go fast, it takes the output of the GMF tutorial 7 as an input (in order not to have to build a new ecore model).
It shows how to change the element label in the list dialog opened from the properties view.
This is helpful when your model has several elements with the same label that you cannot distinguish in the default generated EMF list.
This tutorial is based on the model built in the seventh GMF tutorial wich is availabale through :
This tutorial has been built with :
Let's imagine we've created a School model in which we have several classrooms like this (notice that the 3 classrooms have a student named Beck) :
If you select a Student and click on the Friends property, a dialog appears in which you see three Beck but it is not possible to know which Beck belongs to which Classroom :
In that case, it would be interesting to put the classroom's name before each student.
In order to do that, we have to modify the ItemProvider associated to the Student entity in the edit plugin.
/School.edit/src/jfb/examples/gmf/school/provider/StudentItemProvider.java fileaddFriendsPropertyDescriptor methodNOT after the @generate string.createItemPropertyDescriptor by new ItemPropertyDescriptorgetLabelProvider method like this :/** * This adds a property descriptor for the Friends feature. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ protected void addFriendsPropertyDescriptor(Object object) { itemPropertyDescriptors.add (new ItemPropertyDescriptor (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), getResourceLocator(), getString("_UI_Student_friends_feature"), getString("_UI_PropertyDescriptor_description", "_UI_Student_friends_feature", "_UI_Student_type"), SchoolPackage.Literals.STUDENT__FRIENDS, true, false, true, null, null, null) { @Override public IItemLabelProvider getLabelProvider(Object object) { final IItemLabelProvider defaultLabelProvider = super.getLabelProvider(object); return new IItemLabelProvider() { @Override public String getText(Object object) { // If the object is a student if (object instanceof Student) { Student student = (Student) object; Classroom classroom = (Classroom) student.eContainer(); return student.getName() + " [" + classroom.getName() + "]"; } // Other cases (student list) else { return defaultLabelProvider.getText(object); } } @Override public Object getImage(Object object) { return defaultLabelProvider.getImage(object); } }; } }); }
School modelFriends editor dialogBeck comes from which Classroom :
I hope that this material will be helpful for you. If you want to support it, your help is welcome :
Discussion