Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Calling a function outside the ItemProvider
Calling a function outside the ItemProvider [message #427932] Fri, 06 March 2009 10:58 Go to next message
Matthias is currently offline MatthiasFriend
Messages: 19
Registered: July 2009
Junior Member
Hi,

I have a small question about the call of a function.

When I call for example the setName() function from a object which was
given with the tree selection within the TestActionBarContributor class,
the name will changed within the model and when I debug, the notification
will be called, but the save button will not be activated.

For example:

TreeSelection selectT = (TreeSelection)viewer.getSelection();
EObject eoParent = ((EObject)
selectT.getPaths()[0].getLastSegment)).eContainer();
msc.project_package.XYZ isParent = (XYZ) eoParent;
isParent.setName("Hallo");

Does anyone know a solution for this problem?

Thanks a lot

Matthias
Re: Calling a function outside the ItemProvider [message #427942 is a reply to message #427932] Fri, 06 March 2009 12:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Matthias,

Comments below.


Matthias wrote:
> Hi,
>
> I have a small question about the call of a function.
>
> When I call for example the setName() function from a object which was
> given with the tree selection within the TestActionBarContributor
> class, the name will changed within the model and when I debug, the
> notification will be called, but the save button will not be activated.
>
> For example:
>
> TreeSelection selectT = (TreeSelection)viewer.getSelection();
> EObject eoParent = ((EObject)
> selectT.getPaths()[0].getLastSegment)).eContainer();
> msc.project_package.XYZ isParent = (XYZ) eoParent;
> isParent.setName("Hallo");
>
> Does anyone know a solution for this problem?
Use a command. You must execute commands on the command stack to affect
the dirty state of the editor and of course so you can have undo
support. If you have a bunch of complex logic that you can't express
as a command or would involve a lot of duplicate to express also as a
command, you could use a ChangeCommand (which uses a ChangeRecorder to
record changes based on notifications about changes).
>
> Thanks a lot
>
> Matthias
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Calling a function outside the ItemProvider [message #427944 is a reply to message #427942] Fri, 06 March 2009 12:45 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 19
Registered: July 2009
Junior Member
Hi,

ok you mean I have to create the createAddCommand in the ItemProvider?

@Override
protected Command createAddCommand(EditingDomain domain, EObject owner,
EStructuralFeature feature, Collection<?> collection, int index) {
// TODO Auto-generated method stub
return super.createAddCommand(domain, owner, feature, collection, index);
}


Ed Merks wrote:

> Matthias,

> Comments below.


> Matthias wrote:
>> Hi,
>>
>> I have a small question about the call of a function.
>>
>> When I call for example the setName() function from a object which was
>> given with the tree selection within the TestActionBarContributor
>> class, the name will changed within the model and when I debug, the
>> notification will be called, but the save button will not be activated.
>>
>> For example:
>>
>> TreeSelection selectT = (TreeSelection)viewer.getSelection();
>> EObject eoParent = ((EObject)
>> selectT.getPaths()[0].getLastSegment)).eContainer();
>> msc.project_package.XYZ isParent = (XYZ) eoParent;
>> isParent.setName("Hallo");
>>
>> Does anyone know a solution for this problem?
> Use a command. You must execute commands on the command stack to affect
> the dirty state of the editor and of course so you can have undo
> support. If you have a bunch of complex logic that you can't express
> as a command or would involve a lot of duplicate to express also as a
> command, you could use a ChangeCommand (which uses a ChangeRecorder to
> record changes based on notifications about changes).
>>
>> Thanks a lot
>>
>> Matthias
>>
Re: Calling a function outside the ItemProvider [message #427945 is a reply to message #427944] Fri, 06 March 2009 12:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Matthias,

Likely you want
domain.getCommandStack().execute(SetCommand.create(domain, isParent,
ProjectPackage.Literals.XYZ_NAME, "Hallo")).

Matthias wrote:
> Hi,
>
> ok you mean I have to create the createAddCommand in the ItemProvider?
>
> @Override
> protected Command createAddCommand(EditingDomain domain, EObject owner,
> EStructuralFeature feature, Collection<?> collection, int index) {
> // TODO Auto-generated method stub
> return super.createAddCommand(domain, owner, feature, collection, index);
> }
>
>
> Ed Merks wrote:
>
>> Matthias,
>
>> Comments below.
>
>
>> Matthias wrote:
>>> Hi,
>>>
>>> I have a small question about the call of a function.
>>>
>>> When I call for example the setName() function from a object which
>>> was given with the tree selection within the
>>> TestActionBarContributor class, the name will changed within the
>>> model and when I debug, the notification will be called, but the
>>> save button will not be activated.
>>>
>>> For example:
>>>
>>> TreeSelection selectT = (TreeSelection)viewer.getSelection();
>>> EObject eoParent = ((EObject)
>>> selectT.getPaths()[0].getLastSegment)).eContainer();
>>> msc.project_package.XYZ isParent = (XYZ) eoParent;
>>> isParent.setName("Hallo");
>>>
>>> Does anyone know a solution for this problem?
>> Use a command. You must execute commands on the command stack to
>> affect the dirty state of the editor and of course so you can have
>> undo support. If you have a bunch of complex logic that you can't
>> express as a command or would involve a lot of duplicate to express
>> also as a command, you could use a ChangeCommand (which uses a
>> ChangeRecorder to record changes based on notifications about changes).
>>>
>>> Thanks a lot
>>>
>>> Matthias
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Calling a function outside the ItemProvider [message #427948 is a reply to message #427945] Fri, 06 March 2009 13:22 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 19
Registered: July 2009
Junior Member
Ok,

thats it.

But is it possible to disable the undo function for this command?

Thanks a lot
Matthias

Ed Merks wrote:

> Matthias,

> Likely you want
> domain.getCommandStack().execute(SetCommand.create(domain, isParent,
> ProjectPackage.Literals.XYZ_NAME, "Hallo")).

> Matthias wrote:
>> Hi,
>>
>> ok you mean I have to create the createAddCommand in the ItemProvider?
>>
>> @Override
>> protected Command createAddCommand(EditingDomain domain, EObject owner,
>> EStructuralFeature feature, Collection<?> collection, int index) {
>> // TODO Auto-generated method stub
>> return super.createAddCommand(domain, owner, feature, collection, index);
>> }
>>
>>
>> Ed Merks wrote:
>>
>>> Matthias,
>>
>>> Comments below.
>>
>>
>>> Matthias wrote:
>>>> Hi,
>>>>
>>>> I have a small question about the call of a function.
>>>>
>>>> When I call for example the setName() function from a object which
>>>> was given with the tree selection within the
>>>> TestActionBarContributor class, the name will changed within the
>>>> model and when I debug, the notification will be called, but the
>>>> save button will not be activated.
>>>>
>>>> For example:
>>>>
>>>> TreeSelection selectT = (TreeSelection)viewer.getSelection();
>>>> EObject eoParent = ((EObject)
>>>> selectT.getPaths()[0].getLastSegment)).eContainer();
>>>> msc.project_package.XYZ isParent = (XYZ) eoParent;
>>>> isParent.setName("Hallo");
>>>>
>>>> Does anyone know a solution for this problem?
>>> Use a command. You must execute commands on the command stack to
>>> affect the dirty state of the editor and of course so you can have
>>> undo support. If you have a bunch of complex logic that you can't
>>> express as a command or would involve a lot of duplicate to express
>>> also as a command, you could use a ChangeCommand (which uses a
>>> ChangeRecorder to record changes based on notifications about changes).
>>>>
>>>> Thanks a lot
>>>>
>>>> Matthias
>>>>
>>
>>
Re: Calling a function outside the ItemProvider [message #427952 is a reply to message #427948] Fri, 06 March 2009 13:52 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Matthias,

It's possible to make commands return false for canUndo, but that would
kill your entire undo stack. Why would you want to do that?


Matthias wrote:
> Ok,
>
> thats it.
> But is it possible to disable the undo function for this command?
>
> Thanks a lot
> Matthias
>
> Ed Merks wrote:
>
>> Matthias,
>
>> Likely you want
>> domain.getCommandStack().execute(SetCommand.create(domain, isParent,
>> ProjectPackage.Literals.XYZ_NAME, "Hallo")).
>
>> Matthias wrote:
>>> Hi,
>>>
>>> ok you mean I have to create the createAddCommand in the ItemProvider?
>>>
>>> @Override
>>> protected Command createAddCommand(EditingDomain domain, EObject owner,
>>> EStructuralFeature feature, Collection<?> collection, int index) {
>>> // TODO Auto-generated method stub
>>> return super.createAddCommand(domain, owner, feature, collection,
>>> index);
>>> }
>>>
>>>
>>> Ed Merks wrote:
>>>
>>>> Matthias,
>>>
>>>> Comments below.
>>>
>>>
>>>> Matthias wrote:
>>>>> Hi,
>>>>>
>>>>> I have a small question about the call of a function.
>>>>>
>>>>> When I call for example the setName() function from a object which
>>>>> was given with the tree selection within the
>>>>> TestActionBarContributor class, the name will changed within the
>>>>> model and when I debug, the notification will be called, but the
>>>>> save button will not be activated.
>>>>>
>>>>> For example:
>>>>>
>>>>> TreeSelection selectT = (TreeSelection)viewer.getSelection();
>>>>> EObject eoParent = ((EObject)
>>>>> selectT.getPaths()[0].getLastSegment)).eContainer();
>>>>> msc.project_package.XYZ isParent = (XYZ) eoParent;
>>>>> isParent.setName("Hallo");
>>>>>
>>>>> Does anyone know a solution for this problem?
>>>> Use a command. You must execute commands on the command stack to
>>>> affect the dirty state of the editor and of course so you can have
>>>> undo support. If you have a bunch of complex logic that you can't
>>>> express as a command or would involve a lot of duplicate to express
>>>> also as a command, you could use a ChangeCommand (which uses a
>>>> ChangeRecorder to record changes based on notifications about
>>>> changes).
>>>>>
>>>>> Thanks a lot
>>>>>
>>>>> Matthias
>>>>>
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] NullPointerException on reload
Next Topic:transaction and listeners
Goto Forum:
  


Current Time: Thu Apr 18 02:29:44 GMT 2024

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

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

Back to the top