Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMFForms] Adding model instances to the "running" instance
[EMFForms] Adding model instances to the "running" instance [message #1741646] Fri, 26 August 2016 14:45 Go to next message
Peter Hermsdorf is currently offline Peter HermsdorfFriend
Messages: 25
Registered: August 2011
Junior Member
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 #1741709 is a reply to message #1741646] Sun, 28 August 2016 11:15 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi Peter,

you can implement a custom reference service to customize the selection
dialog including the available elements:
http://eclipsesource.com/blogs/tutorials/how-to-customize-emf-forms/#reference-service

Best regards
Jonas

On 26.08.2016 16:45, Peter Hermsdorf wrote:
> 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 13:56 Go to previous messageGo to next message
Peter Hermsdorf is currently offline Peter HermsdorfFriend
Messages: 25
Registered: August 2011
Junior Member
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 Wink (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 &quot;running&quot; instance [message #1742253 is a reply to message #1741898] Thu, 01 September 2016 07:06 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 65
Registered: September 2016
Member
About the reference service:
The implementation looks fine. You migh want to remove existing references after the user has confirmed the dialog with OK.

About the reference renderer: Could you report that as a Bug Report that it should be possible to adapt the icosn e.g. by making the renderer SPI...
Re: [EMFForms] Adding model instances to the &quot;running&quot; instance [message #1742606 is a reply to message #1742253] Tue, 06 September 2016 07:10 Go to previous message
Peter Hermsdorf is currently offline Peter HermsdorfFriend
Messages: 25
Registered: August 2011
Junior Member
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
Previous Topic:[EEF] problem on EEF Tutorials/First Generation
Next Topic:[EMF Forms] Integration with tabbed property sheet
Goto Forum:
  


Current Time: Tue Apr 24 10:17:10 GMT 2018

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

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