Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » EMF Forms: Customize derived field - Modification is ignored
EMF Forms: Customize derived field - Modification is ignored [message #1755845] Wed, 08 March 2017 14:37 Go to next message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
Hi,

I have a very strange behaviour:
I have 2 fields:
utilizationCode
utilization

utilizationCode is a normal Integer field
utilization is a derived field which contains the label corresponding to the utilizationCode

in my EMF Forms I display only the derived utilization field = utilization label, and I customized it with an additional button.

When you click on the button, you have a popup to select the utilization from list.
of course, after clicking ok, I have to set the utilizationCode field and refresh the derived utilization field.

Here is the 2 trials I did:
******************
code 1:
DOES NOT WORK: It seems that the setUtilizationCode method is never called?

if (result == IDialogConstants.OK_ID){
Integer value = (Integer)dialogUtilization.getSelectedObject().getColumnValue("value", 0);
EditingDomain domain = getEditingDomain(getViewModelContext().getDomainModel());
Command cmdSet = SetCommand.create(domain, getViewModelContext().getDomainModel(), QuotingPackage.QUOTE__UTILIZATION, value);
domain.getCommandStack().execute(cmdSet);
}



*****************
code 2: it works but the model is not in a modified state. I have not the star *, on my EMF file.

if (result == IDialogConstants.OK_ID){
Integer value = (Integer)dialogUtilization.getSelectedObject().getColumnValue("value", 0);
((Quote)getViewModelContext().getDomainModel()).setUtilizationCode(value);
}


*******************
code : my set code, which refresh the derived field as well
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
public void setUtilizationCode(Integer newUtilizationCode) {
Integer oldUtilizationCode = utilizationCode;
String oldUtilization = getUtilization();
utilizationCode = newUtilizationCode;
String utilization = getUtilization();
if (eNotificationRequired()){
eNotify(new ENotificationImpl(this, Notification.SET, QuotingPackage.QUOTE__UTILIZATION_CODE, oldUtilizationCode, utilizationCode));
eNotify(new ENotificationImpl(this, Notification.SET, QuotingPackage.QUOTE__UTILIZATION, oldUtilization, utilization));
}
}


it is strange or am I strange?

Jim
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755859 is a reply to message #1755845] Wed, 08 March 2017 16:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Given there is both QUOTE__UTILIZATION and QUOTE__UTILIZATION_CODE and that you're specifying the former in the set command creation argument, you should expect setUtilization to be called not setUtilizationCode. Furthermore, utilization is apparently a feature of type String, but you're passing an Integer value, so the set command can't execute so setUtilization wouldn't be called either.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755867 is a reply to message #1755859] Wed, 08 March 2017 17:31 Go to previous messageGo to next message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
setUtilization does not exist, because utilization is a derived attribute.
so I expect really to call setUtilizationCode.

I have a mistake in my code, here is the correct code1:
Integer value = (Integer)dialogUtilization.getSelectedObject().getColumnValue("value", 0);
EditingDomain domain = getEditingDomain(getViewModelContext().getDomainModel());
Command cmdSet = SetCommand.create(domain, getViewModelContext().getDomainModel(), QuotingPackage.QUOTE__UTILIZATION_CODE, value);
domain.getCommandStack().execute(cmdSet);


Result is the same setUtilizationCode is not called.

Jim
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755876 is a reply to message #1755867] Wed, 08 March 2017 20:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Only a feature with unchangeable set to true doesn't have a setter. So I guess that's the case too... In any case, you can use the debugger to see how the command is created, to see why the command isn't executable when you execute it on the command stack, and/or to see what it does when it is executed.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755905 is a reply to message #1755876] Thu, 09 March 2017 08:53 Go to previous messageGo to next message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
Is it the right SetCommand that I have to use?
I just want to set an integer attribute on my EMF object.

When I debug the execution, I see that the canExecute return false because in the prepare method, the feature= null.

When I debug the constructor of SetCommand, It goes to the ItemProviderAdapter, then this function is called:
getSetFeature(commandParameter.getEOwner(), commandParameter.getValue())

protected EStructuralFeature getSetFeature(Object object, Object value)
{
// Iterate over all the set feature to factor each child to the right reference.
//
for (EStructuralFeature eStructuralFeature : getSetFeatures(object))
{
if (isValidValue(object, value, eStructuralFeature))
{
return eStructuralFeature;
}
}

return null;
}

The list is empty so the feature is then null.

So my question is: I am not sure the SetCommand is appropriate to set an integer attribute?


Re: EMF Forms: Customize derived field - Modification is ignored [message #1755910 is a reply to message #1755905] Thu, 09 March 2017 09:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Your call looks like it's passing the feature along. I imagine that in org.eclipse.emf.edit.command.SetCommand.create(EditingDomain, Object, Object, Object, int) it calls return domain.createCommand(SetCommand.class, new CommandParameter(owner, feature, value, index)); passing along the feature, and eventually gets to org.eclipse.emf.edit.provider.ItemProviderAdapter.createCommand(Object, EditingDomain, Class<? extends Command>, CommandParameter) where the feature should be non-null and used directly.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755920 is a reply to message #1755910] Thu, 09 March 2017 10:06 Go to previous messageGo to next message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
Yep but what is the solution?

Why I cannot set a basic attribute on my object???
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755931 is a reply to message #1755920] Thu, 09 March 2017 11:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Without being able to reproduce your problem, I can only make educated guesses. From what you tell me, I expect it reaches this code in ItemProviderAdapter:
  public Command createCommand(Object object, EditingDomain domain, Class<? extends Command> commandClass, CommandParameter commandParameter)
  {
    // Commands should operate on the values, not their wrappers.  If the command's values needed to be unwrapped,
    // we'll back get a new CommandParameter.
    //
    CommandParameter oldCommandParameter = commandParameter;
    commandParameter = unwrapCommandValues(commandParameter, commandClass);

    Command result = UnexecutableCommand.INSTANCE;

    if (commandClass == SetCommand.class)
    {
      result =
        createSetCommand
          (domain, 
           commandParameter.getEOwner(), 
           commandParameter.getEStructuralFeature() != null ?
             commandParameter.getEStructuralFeature() :
             getSetFeature(commandParameter.getEOwner(), commandParameter.getValue()),
           commandParameter.getValue(),
           commandParameter.getIndex());
    }
Your previous comments implied that getSetFeature is getting called here, which suggests that commandParameter.getEStructuralFeature() == null. But that's not what I expect. I expect commandParameter.getEStructuralFeature() returns the structural feature you passed in. So the best I can suggest is to set a breakpoint in this method, and look up the call stack to see where in that stack the feature goes missing between calling SetCommand.create(domain, getViewModelContext().getDomainModel(), QuotingPackage.QUOTE__UTILIZATION_CODE, value); and getting to that point above in the code where one would expect the feature to be passed.

Of course now that I look at what you typed previously, I think it should be QuotingPackage.Literals.QUOTE__UTILIZATION_CODE. I.e., it looks like you're passing the integer constant for the feature rather than the actual feature instance to the call, and of course that Integer value isn't an EStructuralFeature instance, so that would explain the null returned from commandParameter.getEStructuralFeature() and the use of getSetFeature.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755939 is a reply to message #1755931] Thu, 09 March 2017 12:52 Go to previous messageGo to next message
Jim 20100 is currently offline Jim 20100Friend
Messages: 69
Registered: June 2016
Member
Hi,

I found a solution:
Here is the code:

Integer value = (Integer)dialogUtilization.getSelectedObject().getColumnValue("value", 0);
EditingDomain domain = getEditingDomain(getViewModelContext().getDomainModel());
EStructuralFeature featureUtilizationCode = null;
for (EStructuralFeature feature : getViewModelContext().getDomainModel().eClass().getEAllStructuralFeatures()){
if (feature.getFeatureID()==QuotingPackage.QUOTE__UTILIZATION_CODE){
System.out.println(feature.getFeatureID());
featureUtilizationCode = feature;
}
}
Command cmdSet1 = SetCommand.create(domain, getViewModelContext().getDomainModel(), featureUtilizationCode, value);
domain.getCommandStack().execute(cmdSet1);

Really annoying to spend hours for a ridiculous set method.
Thx for your help.

Jim
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755971 is a reply to message #1755939] Thu, 09 March 2017 16:19 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Why not use QuotingPackage.Literals.QUOTE__UTILIZATION_CODE as suggested?

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF Forms: How to disable the add button for references field
Next Topic:EMF Forms: Format correctly a custom field
Goto Forum:
  


Current Time: Fri Mar 29 13:35:49 GMT 2024

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

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

Back to the top