[EMFForms] Adding model instances to the "running" instance [message #1741646] |
Fri, 26 August 2016 10:45  |
Eclipse User |
|
|
|
Hi,
i'm currently struggling to add model instances (created programatically) to an emfforms "instance".
Background:
I have modeled a class(A) with a containment reference to another class(B).
I create a renderer with an instance of A as DomainModel for my view. In the UI I want to add multiple references to B (via the "Link" button and the Search Dialog) which are created programmatically beforehand (the concrete instances can only be created at runtime).
How to insert / add / inject these instances to the running "EMFForms Dialog" / EMF instance so that they can be used for the reference?
Bonus Questions:
1. how to prevent the "create and link" button in the UI for the instances of B? (only adding and removing of the predefined instances should be possible)
2. how to customize the icons and toolltip of the "link model instance" and "delete link" buttons in the UI?
Thanks for any hints.
peter
|
|
|
|
Re: [EMFForms] Adding model instances to the "running" instance [message #1741898 is a reply to message #1741709] |
Tue, 30 August 2016 09:56   |
Eclipse User |
|
|
|
Hi Jonas,
thanks for the pointer - that helped get going.
I now use a custom ReferenceService which extends from DefaultReferenceService. Because I wanted to provide a pre-defined List of Objects for my reference I did the following:
@Override
public void addExistingModelElements(final EObject eObject, final EReference eReference) {
if (eReference.getEReferenceType().getInstanceClass().equals(MyRole.class)) {
final Set<EObject> elements = createRoleObjects();//loads them from DB and creates instances
ECPControlHelper.removeExistingReferences(eObject, eReference, elements);
final Set<EObject> addedElements = SelectModelElementWizardFactory.openModelElementSelectionDialog(elements,
eReference.isMany());
ECPControlHelper.addModelElementsInReference(eObject, addedElements, eReference, editingDomain);
} else {
super.addExistingModelElements(eObject, eReference);
}
}
Since I'm very new to EMF and EMFForms I guess it's not the A+ solution, but it works for now (any hints on improving are welcome!)
Additionally I wanted to remove the "Add Button" and customize the icons. The UI seems to come from the class MultiReferenceSWTRenderer. What would be the best way to customize the ui (remove button, change images)?
Since the class is in an internal package, a lot of code would have to be copied to create a customized version of the renderer, just for changing the name of an image and to implement showAddNewButton() to return false....
Thanks for any hints!
regards, peter
|
|
|
|
Re: [EMFForms] Adding model instances to the "running" instance [message #1742606 is a reply to message #1742253] |
Tue, 06 September 2016 03:10  |
Eclipse User |
|
|
|
Hi Jonas,
in the end i adopted the icons by interceptiong the getImages() method and overriding the showAddNewButton in my derived renderer class like this:
@Override
protected Image getImage(final String path) {
switch (path) {
case ICON_ADD_EXISTING:
case ICON_ADD_NEW:
case ICON_DELETE:
return imageRegistryService.getImage(FrameworkUtil.getBundle(MyMultiReferenceSWTRenderer.class), path);
default:
return super.getImage(path);
}
}
@Override
protected boolean showAddNewButton() {
return false;
}
easy enough from my point of view.
thanks for the hints!
bye, peter
|
|
|
Powered by
FUDForum. Page generated in 0.47992 seconds