How to modify EMF elements from a GMF PropertySection.. [message #65553] |
Thu, 19 October 2006 06:59  |
Eclipse User |
|
|
|
Originally posted by: gabmecu.fiv.upv.es
Hi again! I'm trying to modify some EMF elements from a GMF property tab
sheet but I'm getting some problems. Basically I have a custom tab where
I show, in a SWT Text (a textbox), the value of one attribute of the
selected element in the diagram.
I accomplish this using getSelection in the refresh() method. This works
ok. The problem comes when I try to update one attribute of the selected
element.
I've made a listener for the nameTextField to modify the attribute every
time the nameTextField is changed:
public void createControls(Composite parent, TabbedPropertySheetPage
aTabbedPropertySheetPage)
{
...
// I add the listener to the nameTextField
nameTextField.addModifyListener(mlistener);
}
and the listener:
private ModifyListener mlistener = new ModifyListener()
{
public void modifyText(ModifyEvent e)
{
String tableName = nameTextField.getText();
StructuredSelection ss = (StructuredSelection)
getSelection();
if (ss != null)
{
Table table = (Table) ss.getFirstElement();
table.setName(tableName);
}
}
};
But this generates the exception:
Cannot modify resource set without a write transaction.
I've looking in the EMF help and I found that every modification must be
done through a transaction but I don't know how to do it. (I've read
that a EditDomain and a command is needed)
Can anybody help me, please?
Thanks in advance,
Gabriel
|
|
|
|
Re: (SOLVED) How to modify EMF elements from a GMF PropertySection.. [message #68932 is a reply to message #65766] |
Wed, 25 October 2006 05:55  |
Eclipse User |
|
|
|
Originally posted by: gabmecu.fiv.upv.es
Thank you for your answer Artem, but I finally resolved the problem
using the EditingDomain from the DiagramEditor. The code looks like this:
protected void handleTextModified()
{
// I get the new value from a Text widget
String tableName = nameTextField.getText();
// the same value as a object (not sure if necessary)
Object tableNameObject = tableName;
// I get de EditingDomain from de DiagramEditor
EditingDomain editingDomain = ( (XXXXDiagramEditor)
getPart()).getEditingDomain();
// Selected element by user
StructuredSelection ss = (StructuredSelection) getSelection();
EObject eObjectSelected = (EObject) ss.getFirstElement();
// I need the the EReference of the attribute Table->Name
EAttribute feature = XXXX.XXXXPackage.eINSTANCE.getTable_Name();
// From the editing domain a create a Set Command
editingDomain.getCommandStack().execute(
SetCommand.create(editingDomain, ObjectSelected, feature ,
tableNameObject)
);
}
Artem Tikhomirov wrote:
> Take a look at UndoableModelPropertySheetEntry#valueChanged
>
> "Gabriel Merin Cubero" <gabmecu@fiv.upv.es> wrote in message
> news:eh7lrb$bs0$1@utils.eclipse.org...
>> Hi again! I'm trying to modify some EMF elements from a GMF property tab
>> sheet but I'm getting some problems. Basically I have a custom tab where I
>> show, in a SWT Text (a textbox), the value of one attribute of the
>> selected element in the diagram.
>>
>> I accomplish this using getSelection in the refresh() method. This works
>> ok. The problem comes when I try to update one attribute of the selected
>> element.
>>
>> I've made a listener for the nameTextField to modify the attribute every
>> time the nameTextField is changed:
>>
>> public void createControls(Composite parent, TabbedPropertySheetPage
>> aTabbedPropertySheetPage)
>> {
>> ...
>> // I add the listener to the nameTextField
>> nameTextField.addModifyListener(mlistener);
>> }
>>
>> and the listener:
>>
>> private ModifyListener mlistener = new ModifyListener()
>> {
>> public void modifyText(ModifyEvent e)
>> {
>> String tableName = nameTextField.getText();
>> StructuredSelection ss = (StructuredSelection)
>> getSelection();
>> if (ss != null)
>> {
>> Table table = (Table) ss.getFirstElement();
>> table.setName(tableName);
>> } }
>>
>> };
>>
>> But this generates the exception:
>> Cannot modify resource set without a write transaction.
>>
>> I've looking in the EMF help and I found that every modification must be
>> done through a transaction but I don't know how to do it. (I've read that
>> a EditDomain and a command is needed)
>>
>> Can anybody help me, please?
>> Thanks in advance,
>> Gabriel
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.06955 seconds