Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF Forms] Hide fields/controls programmaticaly in views
[EMF Forms] Hide fields/controls programmaticaly in views [message #1746272] Wed, 26 October 2016 10:20 Go to next message
Kristof Zalecki is currently offline Kristof ZaleckiFriend
Messages: 23
Registered: October 2013
Junior Member
Hi,

I created a ViewModelService for the custom model instance editor I have created in order to hide one certain control for an attribute of my model.
The problem I encountered is, that any element of my model instance is marked as invalid as soon as the view is opened and the ViewModelService executed.

Here's the code i wrote:

@Override
public void instantiate(ViewModelContext context) {
final VElement viewModel = context.getViewModel();
if (!(viewModel instanceof VView)) {
return;
}

final VView view = (VView) viewModel;
for (final VContainedElement child : view.getChildren()) {
if (child instanceof VControl) {
final VControl control = (VControl) child;
final VFeaturePathDomainModelReferenceImpl domainModelReference = (VFeaturePathDomainModelReferenceImpl) control
.getDomainModelReference();
final EStructuralFeature domainModelEFeature = domainModelReference.getDomainModelEFeature();
if (domainModelEFeature.getName().equals("modelElementId")) {
control.setVisible(false);
}
}
}
}

The method setVisible() seems to be the problem. My assumption was, that hiding the control would only affect the rendering of my view, but it also marks the element itself as invalid in the TreeViewer.

Since the attribute modelElementId is present in all of my modeled classes the programmatic way would be the best option.
Is there a way to get this to work with a ViewModelService?

Regards,
Kristof
Re: [EMF Forms] Hide fields/controls programmaticaly in views [message #1746283 is a reply to message #1746272] Wed, 26 October 2016 12:31 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 174
Registered: May 2015
Senior Member
Hi Kristof,
as far as I understand you are using the generated views?
If so, you can change in the genmodel the "property type" of the feature to "none". This way no control will be generated.

Nonetheless your ViewModelService should work.
Are you sure, that the validation error comes from the remove of the control from the view model, and is not a valid validation error?

Cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [EMF Forms] Hide fields/controls programmaticaly in views [message #1746492 is a reply to message #1746283] Mon, 31 October 2016 08:12 Go to previous messageGo to next message
Kristof Zalecki is currently offline Kristof ZaleckiFriend
Messages: 23
Registered: October 2013
Junior Member
Hi Eugen,

after some testing I realized, that the attribute itself is the problem. It's defined as an ID in the model. However, it is set in the class' constructor by an UUID generator and doesn't need to be initialized manually.
Since i cannot change the model in any way, the only option for me would be to disable the element in the view.
When using a view model for the creation of the view the problem does not occur. This approach does not seem to be feasible though, because the class containing the ID attribute is abstract and the base to a couple of thousand modeled classes (which at the same time are beeing changed/added on a regular basis) and would result in a horrendous amount of work to create view models for all of them.
Is there a way to replicate the exact behaviour of the view model programmaticaly or defining a view model for the single class, which would apply for all related classes?

Regards,
Kristof
Re: [EMF Forms] Hide fields/controls programmaticaly in views [message #1747019 is a reply to message #1746492] Tue, 08 November 2016 15:24 Go to previous message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 174
Registered: May 2015
Senior Member
Hi Kristof,
yes you can provide your own org.eclipse.emf.ecp.view.spi.provider.IViewProvider .
It can be registered as an OSGi Service or via the org.eclipse.emf.ecp.ui.view.viewModelProviders ExtensionPoint.
The default ViewModel generation is done in this class:
org.eclipse.emf.ecp.view.model.generator.ViewProvider

Cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Previous Topic:[EMFForm] transient feature are not rendered
Next Topic:[texo] JSONEMFConverter from texo web service response
Goto Forum:
  


Current Time: Thu Apr 25 03:59:57 GMT 2024

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

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

Back to the top