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 09:37  |
Eclipse User |
|
|
|
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 #1755910 is a reply to message #1755905] |
Thu, 09 March 2017 04:38   |
Eclipse User |
|
|
|
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.
|
|
| |
Re: EMF Forms: Customize derived field - Modification is ignored [message #1755931 is a reply to message #1755920] |
Thu, 09 March 2017 06:26   |
Eclipse User |
|
|
|
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.
|
|
| | |
Goto Forum:
Current Time: Fri Jun 20 22:53:13 EDT 2025
Powered by FUDForum. Page generated in 0.04668 seconds
|