Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Re-setting a property depending on another property
Re-setting a property depending on another property [message #418971] Tue, 06 May 2008 13:14 Go to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi,

In my editor property x only is editable if property y is set to true. To
achieve this I implemented an XXXItemProviderDescriptor which checks the
value of property y in the canSetProperty() method.

Like this if property y is true I can add a text to property x. Now if
property y is set to false again I would like to reset the value of x to
"". But I don't know how to notify x about that fact. Do I have to do it
in the notifyChanged() method of the corresponding XXXItemProvider? And if
yes how exactly?

Thank you for your help,

Greets
Marsha
Re: Re-setting a property depending on another property [message #418974 is a reply to message #418971] Tue, 06 May 2008 14:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Marsha,

Maybe it's best to specialize the ItemPropertyDescriptor's
canSetProperty method to return true or false depending on the state of
the other feature.


Marsha wrote:
> Hi,
>
> In my editor property x only is editable if property y is set to true.
> To achieve this I implemented an XXXItemProviderDescriptor which
> checks the value of property y in the canSetProperty() method.
> Like this if property y is true I can add a text to property x. Now if
> property y is set to false again I would like to reset the value of x
> to "". But I don't know how to notify x about that fact. Do I have to
> do it in the notifyChanged() method of the corresponding
> XXXItemProvider? And if yes how exactly?
>
> Thank you for your help,
>
> Greets
> Marsha
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Re-setting a property depending on another property [message #418977 is a reply to message #418974] Tue, 06 May 2008 14:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Ed,

Thank you for your answer. This is what I did actually and it works. My
problem now is to reset feature x to null or the empty string if freature
y is set to false again.

So let's say I set feature y to true. As defined in my custom
ItemPropertyDescriptor the feature x gets editable. I enter a string, then
I change my mind and I set the feature y to false again. In that case
feature x isn't editable anymore which is correct. But the string I
entered remains. What i like is to reset the value at the same time, this
is set it to null or the empty string again.

How is this possible?

Thanks,
Marsha
Re: Re-setting a property depending on another property [message #418978 is a reply to message #418977] Tue, 06 May 2008 14:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Marsha,

You could specialize the setPropertyValue logic to use a compound
command that sets y to false and unsets x as well.


Marsha wrote:
> Hi Ed,
>
> Thank you for your answer. This is what I did actually and it works.
> My problem now is to reset feature x to null or the empty string if
> freature y is set to false again.
>
> So let's say I set feature y to true. As defined in my custom
> ItemPropertyDescriptor the feature x gets editable. I enter a string,
> then I change my mind and I set the feature y to false again. In that
> case feature x isn't editable anymore which is correct. But the string
> I entered remains. What i like is to reset the value at the same time,
> this is set it to null or the empty string again.
>
> How is this possible?
>
> Thanks,
> Marsha
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Re-setting a property depending on another property [message #419214 is a reply to message #418978] Tue, 13 May 2008 08:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Ed,

> You could specialize the setPropertyValue logic to use a compound
> command that sets y to false and unsets x as well.

I think this is the solution I need. But I'm wondering how to get the
feature of x or said differently how to unset the value of x.

I specified a customized ItemPropertyDescriptor for value y and I try to
implement setPropertyValue like this:

public void setPropertyValue(Object object, Object value) {
EditingDomain editingDomain = getEditingDomain(object);
if(value instanceof MaxInstances){
MaxInstances maxInst = (MaxInstances) value;


if(maxInst.getLiteral().equals("zero")){
CompoundCommand cCmd = new
CompoundCommand(CompoundCommand.LAST_COMMAND_ALL);
cCmd.append(SetCommand.create(editingDomain, getCommandOwner(object),
feature, value));

editingDomain.getCommandStack().execute(cCmd);
}
}

super.setPropertyValue(object, value);
}

My problem now is how to reset the value of x...how can I get the feature?
Or do I have to do it with the object something like: ((Step)
object).setX("") If I have to do it in that way which kind of command will
I need?

Thank you for your help
Marsha
Re: Re-setting a property depending on another property [message #419222 is a reply to message #419214] Tue, 13 May 2008 14:49 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Marsha,

You can get at the feature using XyzPackage.Literals.CLASS__FEATURE.
And SetCommand.UNSET_VALUE can be used to unset a feature.


Marsha wrote:
> Hi Ed,
>
>> You could specialize the setPropertyValue logic to use a compound
>> command that sets y to false and unsets x as well.
>
> I think this is the solution I need. But I'm wondering how to get the
> feature of x or said differently how to unset the value of x.
>
> I specified a customized ItemPropertyDescriptor for value y and I try
> to implement setPropertyValue like this:
>
> public void setPropertyValue(Object object, Object value) {
> EditingDomain editingDomain = getEditingDomain(object);
> if(value instanceof MaxInstances){
> MaxInstances maxInst = (MaxInstances) value;
>
>
> if(maxInst.getLiteral().equals("zero")){
> CompoundCommand cCmd = new
> CompoundCommand(CompoundCommand.LAST_COMMAND_ALL);
> cCmd.append(SetCommand.create(editingDomain,
> getCommandOwner(object), feature, value));
>
> editingDomain.getCommandStack().execute(cCmd);
> }
> }
>
> super.setPropertyValue(object, value);
> }
>
> My problem now is how to reset the value of x...how can I get the
> feature? Or do I have to do it with the object something like: ((Step)
> object).setX("") If I have to do it in that way which kind of command
> will I need?
>
> Thank you for your help
> Marsha
>
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Re-setting a property depending on another property [message #419225 is a reply to message #419222] Tue, 13 May 2008 15:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Ed,

Thank you this works fine. But now I have another problem. The changes
aren't visualized in the properties sheet. I think the command does not go
through the whole stack. Can you see where is my mistake?

@Override
public void setPropertyValue(Object object, Object value) {
EditingDomain editingDomain = getEditingDomain(object);
if(value instanceof MaxInstances){

MaxInstances maxInst = (MaxInstances) value;
if(maxInst.getLiteral().equals("one")){
CompoundCommand cCmd = new CompoundCommand();
cCmd.append(SetCommand.create(editingDomain, getCommandOwner(object),
feature, value));
cCmd.append(SetCommand.create(editingDomain, getCommandOwner(object),
GamePackage.eINSTANCE.STEP__INSTANTIATION_CONDITION,
SetCommand.UNSET_VALUE));
editingDomain.getCommandStack().execute(cCmd);
}else super.setPropertyValue(object, value);
}
}

Thank you for your help,
Marsha
Re: Re-setting a property depending on another property [message #419226 is a reply to message #419225] Tue, 13 May 2008 16:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030105060406000708000404
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Marsha,

Comments below.

Marsha wrote:
> Hi Ed,
>
> Thank you this works fine. But now I have another problem. The changes
> aren't visualized in the properties sheet. I think the command does
> not go through the whole stack. Can you see where is my mistake?
>
> @Override
> public void setPropertyValue(Object object, Object value) {
> EditingDomain editingDomain = getEditingDomain(object);
> if(value instanceof MaxInstances){
>
> MaxInstances maxInst = (MaxInstances) value;
> if(maxInst.getLiteral().equals("one")){
> CompoundCommand cCmd = new CompoundCommand();
> cCmd.append(SetCommand.create(editingDomain,
> getCommandOwner(object), feature, value));
> cCmd.append(SetCommand.create(editingDomain,
> getCommandOwner(object),
> GamePackage.eINSTANCE.STEP__INSTANTIATION_CONDITION,
> SetCommand.UNSET_VALUE));
> editingDomain.getCommandStack().execute(cCmd);
Have you stepped through the code to see if the command is actually
executable and being executed? Normally the properties view would be
updated because the code in the editor that listens to the command stack
executing a command will explicitly tell the properties view to refresh
itself.

// Add a listener to set the most recent command's affected objects
to be the selection of the viewer with focus.
//
commandStack.addCommandStackListener
(new CommandStackListener()
{
public void commandStackChanged(final EventObject event)
{
getContainer().getDisplay().asyncExec
(new Runnable()
{
public void run()
{
firePropertyChange(IEditorPart.PROP_DIRTY);

// Try to select the affected objects.
//
Command mostRecentCommand =
((CommandStack)event.getSource()).getMostRecentCommand();
if (mostRecentCommand != null)
{

setSelectionToViewer(mostRecentCommand.getAffectedObjects()) ;
}
if (propertySheetPage != null &&
!propertySheetPage.getControl().isDisposed())
{
propertySheetPage.refresh();
}
}
});
}
});

> }else super.setPropertyValue(object, value);
> }
> }
>
> Thank you for your help,
> Marsha
>


--------------030105060406000708000404
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Marsha,<br>
<br>
Comments below.<br>
<br>
Marsha wrote:
<blockquote
cite="mid:44075b2d52fa5c6eb6f54decfbedbe1f$1@www.eclipse.org"
type="cite">Hi Ed,
<br>
<br>
Thank you this works fine. But now I have another problem. The changes
aren't visualized in the properties sheet. I think the command does not
go through the whole stack. Can you see where is my mistake?
<br>
<br>
@Override
<br>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Re-setting a property depending on another property [message #419234 is a reply to message #419226] Wed, 14 May 2008 07:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Ed,

Your help is very useful to me, but since I'm not that experienced with
Commands I still have some problems, sorry for that.

> Have you stepped through the code to see if the command is actually
> executable and being executed?
I debuged my code and I found out that my CompoundCommand is executed as
expected (update property sheet write changes into model) if I comment out
the reset of the InstantiationCondition:
cCmd.append(SetCommand.create(editingDomain, getCommandOwner(object),
GamePackage.STEP__INSTANTIATION_CONDITION, SetCommand.UNSET_VALUE));
Nevertheless if I check the isExecutable flag of my CompoundCommand it is
set to false.
As soon as I uncomment the line above the CompoundCommand isn't executed
correctly (property sheet and model not updated). What I found out is that
the feature in the SetCommand is null, where I want to reset the
Step_InstantiationCondition (line above). The isExecutable flag of the
cCmd still is false as before.

I tried to initialize the CompoundComand in those three ways, which had no
effect on the execution:
CompoundCommand cCmd = new CompoundCommand();
CompoundCommand cCmd = new
CompoundCommand(CompoundCommand.LAST_COMMAND_ALL);
CompoundCommand cCmd = new
CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL);

What I tried to change as well is using
GamePackage.STEP__INSTANTIATION_CONDITION instead of
GamePackage.eINSTANCE.STEP__INSTANTIATION_CONDITION since I get a warning
saying that I should not access in a static manner.

Unfortunately now I already ran out of ideas...do you have an idea where
my problem is? Do I need a function to get the feature? Why is the
isExecutable flag of my CompoundComand false?

> Normally the properties view would be
> updated because the code in the editor that listens to the command stack
> executing a command will explicitly tell the properties view to refresh
> itself.
Since my CompoundCommand does not update the model either I think that the
problem is in the command itself.

Thanks a lot,
Marsha
Re: Re-setting a property depending on another property [message #419240 is a reply to message #419234] Wed, 14 May 2008 14:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010407000600020607050204
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Marsha,


Comments below.

Marsha wrote:
> Hi Ed,
>
> Your help is very useful to me, but since I'm not that experienced
> with Commands I still have some problems, sorry for that.
>
>> Have you stepped through the code to see if the command is actually
>> executable and being executed?
> I debuged my code and I found out that my CompoundCommand is executed
> as expected (update property sheet write changes into model) if I
> comment out the reset of the InstantiationCondition:
> cCmd.append(SetCommand.create(editingDomain, getCommandOwner(object),
> GamePackage.STEP__INSTANTIATION_CONDITION, SetCommand.UNSET_VALUE));
> Nevertheless if I check the isExecutable flag of my CompoundCommand it
> is set to false.
> As soon as I uncomment the line above the CompoundCommand isn't
> executed correctly (property sheet and model not updated). What I
> found out is that the feature in the SetCommand is null, where I want
> to reset the Step_InstantiationCondition (line above). The
> isExecutable flag of the cCmd still is false as before.
>
> I tried to initialize the CompoundComand in those three ways, which
> had no effect on the execution:
> CompoundCommand cCmd = new CompoundCommand();
> CompoundCommand cCmd = new
> CompoundCommand(CompoundCommand.LAST_COMMAND_ALL);
> CompoundCommand cCmd = new
> CompoundCommand(CompoundCommand.MERGE_COMMAND_ALL);
>
> What I tried to change as well is using
> GamePackage.STEP__INSTANTIATION_CONDITION instead of
> GamePackage.eINSTANCE.STEP__INSTANTIATION_CONDITION since I get a
> warning saying that I should not access in a static manner.
Oh dear. You're accessing the numeric feature ID not the actual feature
object. You need to use
GamePackage.*Literals*.STEP__INSTANTIATION_CONDITION which will be the
same object as GamePackage.eINSTANCE.getStep__InstantiationCondition()...
>
> Unfortunately now I already ran out of ideas...do you have an idea
> where my problem is? Do I need a function to get the feature? Why is
> the isExecutable flag of my CompoundComand false?
>
>> Normally the properties view would be updated because the code in the
>> editor that listens to the command stack executing a command will
>> explicitly tell the properties view to refresh itself.
> Since my CompoundCommand does not update the model either I think that
> the problem is in the command itself.
Yes.
>
> Thanks a lot,
> Marsha
>
>


--------------010407000600020607050204
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Marsha,<br>
<br>
<br>
Comments below.<br>
<br>
Marsha wrote:
<blockquote
cite="mid:d063a560c6b531a8b8721c474766a68f$1@www.eclipse.org"
type="cite">Hi Ed,
<br>
<br>
Your help is very useful to me, but since I'm not that experienced with
Commands I still have some problems, sorry for that.
<br>
<br>
<blockquote type="cite">Have you stepped through the code to see if
the command is actually executable and being executed?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Re-setting a property depending on another property [message #419259 is a reply to message #419240] Thu, 15 May 2008 10:57 Go to previous message
Eclipse UserFriend
Originally posted by: marsha.rohrer.swisscom.com

Hi Ed,

That was stupid :-$ Thank you for your help now it works perfectly.

Greets,
Marsha
Previous Topic:Ecore lower/upper bounds don't match XSD schema
Next Topic:Dynamic constraint in java
Goto Forum:
  


Current Time: Fri Mar 29 09:35:38 GMT 2024

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

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

Back to the top