Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Refactoring the generated editor
Refactoring the generated editor [message #828412] Sat, 24 March 2012 15:22 Go to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 365
Registered: September 2009
Senior Member
Hi,
I'm trying to understand how to reuse the editor EMF kindly generated
for my (simple) model.

It works and does a lot of things, unfortunately it does not do them in
the way I need them done.

What I need is a Form-based Master/Details set of pages.

I managed to convert the produced selection tree view into the
MasterPart of a MasterSetailsBlock.

I am now stuck in how to connect the IDetailsPage(s) with the model via
generated editor.

I tried blindly something like:

public class MachineDetailsPage implements IDetailsPage {
private final StatemEditor sme;
private IManagedForm managedForm;
private Text txtName;
public MachineDetailsPage(StatemEditor sme) {
this.sme = sme;
}

@Override
public void initialize(IManagedForm form) {
managedForm = form;
}
...

@Override
public void createContents(Composite parent) {
FormToolkit toolkit = managedForm.getToolkit();
GridLayout gl_parent = new GridLayout();
gl_parent.numColumns = 2;
parent.setLayout(gl_parent);

Label lblMachineName = new Label(parent, SWT.NONE);
lblMachineName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
toolkit.adapt(lblMachineName, true, true);
lblMachineName.setText("Machine Name:");

txtName = toolkit.createText(parent, "New Text", SWT.NONE);
txtName.setText("Name");
txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

Label lblInitialState = new Label(parent, SWT.NONE);
lblInitialState.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
toolkit.adapt(lblInitialState, true, true);
lblInitialState.setText("Initial State:");

ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE);
Combo combo = comboViewer.getCombo();
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
toolkit.paintBordersFor(combo);

Label lblStates = new Label(parent, SWT.NONE);
lblStates.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
toolkit.adapt(lblStates, true, true);
lblStates.setText("States:");

ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
List list = listViewer.getList();
list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
listViewer.setContentProvider(new AdapterFactoryContentProvider(sme.getAdapterFactory()));
listViewer.setLabelProvider(new AdapterFactoryLabelProvider(sme.getAdapterFactory()));
}

}

Needless to say it doesn't work.
listViewer appears empty even though I have something in the model (and I can see it in the masterBlock).

I think I really do not understand how all this is supposed to work.
I have a fair understanding of DataBinding, but this seems to be deeply wrapped in the AdapterFactories and I wasn't able to find documentation on that.
Even "EMF: Eclipse Modeling Framework, Second Edition" I recently bought does not seem to contain Information on how to do this.
I must confess I didn't study it cover-to-cover, but customization seems to be very ViewerPane-and-PropertyList-centric, while I would like to move to standard widgets and/or Forms.

Can someone point me to the relevant documentation?
I'm pretty sure what I want to do should be possible, but I'm getting lost.

Thanks in Advance
Mauro
Re: Refactoring the generated editor [message #828498 is a reply to message #828412] Sat, 24 March 2012 18:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 24529
Registered: July 2009
Senior Member
Mauro,

You might want to look at EEF. There's data binding support for EMF as
well, which works much like the bean versions...


On 24/03/2012 3:22 PM, Mauro Condarelli wrote:
> Hi,
> I'm trying to understand how to reuse the editor EMF kindly generated
> for my (simple) model.
>
> It works and does a lot of things, unfortunately it does not do them in
> the way I need them done.
>
> What I need is a Form-based Master/Details set of pages.
>
> I managed to convert the produced selection tree view into the
> MasterPart of a MasterSetailsBlock.
>
> I am now stuck in how to connect the IDetailsPage(s) with the model via
> generated editor.
>
> I tried blindly something like:
>
> public class MachineDetailsPage implements IDetailsPage {
> private final StatemEditor sme;
> private IManagedForm managedForm;
> private Text txtName;
> public MachineDetailsPage(StatemEditor sme) {
> this.sme = sme;
> }
>
> @Override
> public void initialize(IManagedForm form) {
> managedForm = form;
> }
> ...
>
> @Override
> public void createContents(Composite parent) {
> FormToolkit toolkit = managedForm.getToolkit();
> GridLayout gl_parent = new GridLayout();
> gl_parent.numColumns = 2;
> parent.setLayout(gl_parent);
>
> Label lblMachineName = new Label(parent, SWT.NONE);
> lblMachineName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
> toolkit.adapt(lblMachineName, true, true);
> lblMachineName.setText("Machine Name:");
>
> txtName = toolkit.createText(parent, "New Text", SWT.NONE);
> txtName.setText("Name");
> txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
>
> Label lblInitialState = new Label(parent, SWT.NONE);
> lblInitialState.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
> toolkit.adapt(lblInitialState, true, true);
> lblInitialState.setText("Initial State:");
>
> ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE);
> Combo combo = comboViewer.getCombo();
> combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
> toolkit.paintBordersFor(combo);
>
> Label lblStates = new Label(parent, SWT.NONE);
> lblStates.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
> toolkit.adapt(lblStates, true, true);
> lblStates.setText("States:");
>
> ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
> List list = listViewer.getList();
> list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
> listViewer.setContentProvider(new AdapterFactoryContentProvider(sme.getAdapterFactory()));
> listViewer.setLabelProvider(new AdapterFactoryLabelProvider(sme.getAdapterFactory()));
> }
>
> }
>
> Needless to say it doesn't work.
> listViewer appears empty even though I have something in the model (and I can see it in the masterBlock).
>
> I think I really do not understand how all this is supposed to work.
> I have a fair understanding of DataBinding, but this seems to be deeply wrapped in the AdapterFactories and I wasn't able to find documentation on that.
> Even "EMF: Eclipse Modeling Framework, Second Edition" I recently bought does not seem to contain Information on how to do this.
> I must confess I didn't study it cover-to-cover, but customization seems to be very ViewerPane-and-PropertyList-centric, while I would like to move to standard widgets and/or Forms.
>
> Can someone point me to the relevant documentation?
> I'm pretty sure what I want to do should be possible, but I'm getting lost.
>
> Thanks in Advance
> Mauro
Re: Refactoring the generated editor [message #828501 is a reply to message #828412] Sat, 24 March 2012 18:42 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 4462
Registered: July 2009
Senior Member
Without a Viewer#setInput() nothing can be shown! You've thrown in the
term databinding but you are not use databinding (at least not
EMF-Datadinding) so I'm not sure what you are aiming at.

Tom

Am 24.03.12 15:22, schrieb Mauro Condarelli:
> Hi,
> I'm trying to understand how to reuse the editor EMF kindly generated
> for my (simple) model.
>
> It works and does a lot of things, unfortunately it does not do them in
> the way I need them done.
>
> What I need is a Form-based Master/Details set of pages.
>
> I managed to convert the produced selection tree view into the
> MasterPart of a MasterSetailsBlock.
>
> I am now stuck in how to connect the IDetailsPage(s) with the model via
> generated editor.
>
> I tried blindly something like:
>
> public class MachineDetailsPage implements IDetailsPage {
> private final StatemEditor sme;
> private IManagedForm managedForm;
> private Text txtName;
> public MachineDetailsPage(StatemEditor sme) {
> this.sme = sme;
> }
>
> @Override
> public void initialize(IManagedForm form) {
> managedForm = form;
> }
> ...
>
> @Override
> public void createContents(Composite parent) {
> FormToolkit toolkit = managedForm.getToolkit();
> GridLayout gl_parent = new GridLayout();
> gl_parent.numColumns = 2;
> parent.setLayout(gl_parent);
>
> Label lblMachineName = new Label(parent, SWT.NONE);
> lblMachineName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
> toolkit.adapt(lblMachineName, true, true);
> lblMachineName.setText("Machine Name:");
>
> txtName = toolkit.createText(parent, "New Text", SWT.NONE);
> txtName.setText("Name");
> txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
>
> Label lblInitialState = new Label(parent, SWT.NONE);
> lblInitialState.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
> toolkit.adapt(lblInitialState, true, true);
> lblInitialState.setText("Initial State:");
>
> ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE);
> Combo combo = comboViewer.getCombo();
> combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
> toolkit.paintBordersFor(combo);
>
> Label lblStates = new Label(parent, SWT.NONE);
> lblStates.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
> toolkit.adapt(lblStates, true, true);
> lblStates.setText("States:");
>
> ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
> List list = listViewer.getList();
> list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
> listViewer.setContentProvider(new AdapterFactoryContentProvider(sme.getAdapterFactory()));
> listViewer.setLabelProvider(new AdapterFactoryLabelProvider(sme.getAdapterFactory()));
> }
>
> }
>
> Needless to say it doesn't work.
> listViewer appears empty even though I have something in the model (and I can see it in the masterBlock).
>
> I think I really do not understand how all this is supposed to work.
> I have a fair understanding of DataBinding, but this seems to be deeply wrapped in the AdapterFactories and I wasn't able to find documentation on that.
> Even "EMF: Eclipse Modeling Framework, Second Edition" I recently bought does not seem to contain Information on how to do this.
> I must confess I didn't study it cover-to-cover, but customization seems to be very ViewerPane-and-PropertyList-centric, while I would like to move to standard widgets and/or Forms.
>
> Can someone point me to the relevant documentation?
> I'm pretty sure what I want to do should be possible, but I'm getting lost.
>
> Thanks in Advance
> Mauro
Re: Refactoring the generated editor [message #828562 is a reply to message #828501] Sat, 24 March 2012 21:08 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 365
Registered: September 2009
Senior Member
I am aiming to understand if and how the code generated by EMF can be
bent to display the things in the way I like them.

I understand how to do EMF DataBinding (I think) as I used it in another
project.
In that code I used nothing of the facilities in .edit and .editor; I
rewrote the Editor from scratch.
Doing this I lost all benefits of using commands, including Undo/Redo
and such.

Now I started a very small project (model contains just three classes
with an handful of fields each) and I wanted to use it to understand
better the inner EMF machinery.

Nevertheless I would like to have a "standard"(?) Form-based editor with
master/detail forms. I do not want to use a generated Property editor
but a handcrafted Form.
All this, if possible, using commands to maintain undo capability.

The simplified model I currently use is in attach.

The Machine details page should essentially be a ListViewer of the
contained States, with a couple of buttons to add a new State, delete an
existing one and, perhaps to move up/down the States.
"initial" State should be a combo selecting one of the existing states.
"current" should not appear at all.
"name" should be a simple text field.

The State and Arc details pages would be a bit more complex, but on the
same lines.

Is it possible to (easily) do such a thing?
Is this a Bad Idea, for some reason?
Where should I go to get an overview of what I should do?

Thanks in Advance
Mauro


On 24/03/2012 23:42, Tom Schindl wrote:
> Without a Viewer#setInput() nothing can be shown! You've thrown in the
> term databinding but you are not use databinding (at least not
> EMF-Datadinding) so I'm not sure what you are aiming at.
>
> Tom
>
> Am 24.03.12 15:22, schrieb Mauro Condarelli:
>> Hi,
>> I'm trying to understand how to reuse the editor EMF kindly generated
>> for my (simple) model.
>>
>> It works and does a lot of things, unfortunately it does not do them in
>> the way I need them done.
>>
>> What I need is a Form-based Master/Details set of pages.
>>
>> I managed to convert the produced selection tree view into the
>> MasterPart of a MasterSetailsBlock.
>>
>> I am now stuck in how to connect the IDetailsPage(s) with the model via
>> generated editor.
>>
>> I tried blindly something like:
>>
>> public class MachineDetailsPage implements IDetailsPage {
>> private final StatemEditor sme;
>> private IManagedForm managedForm;
>> private Text txtName;
>> public MachineDetailsPage(StatemEditor sme) {
>> this.sme = sme;
>> }
>>
>> @Override
>> public void initialize(IManagedForm form) {
>> managedForm = form;
>> }
>> ...
>>
>> @Override
>> public void createContents(Composite parent) {
>> FormToolkit toolkit = managedForm.getToolkit();
>> GridLayout gl_parent = new GridLayout();
>> gl_parent.numColumns = 2;
>> parent.setLayout(gl_parent);
>>
>> Label lblMachineName = new Label(parent, SWT.NONE);
>> lblMachineName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
>> toolkit.adapt(lblMachineName, true, true);
>> lblMachineName.setText("Machine Name:");
>>
>> txtName = toolkit.createText(parent, "New Text", SWT.NONE);
>> txtName.setText("Name");
>> txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
>>
>> Label lblInitialState = new Label(parent, SWT.NONE);
>> lblInitialState.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
>> toolkit.adapt(lblInitialState, true, true);
>> lblInitialState.setText("Initial State:");
>>
>> ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE);
>> Combo combo = comboViewer.getCombo();
>> combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
>> toolkit.paintBordersFor(combo);
>>
>> Label lblStates = new Label(parent, SWT.NONE);
>> lblStates.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
>> toolkit.adapt(lblStates, true, true);
>> lblStates.setText("States:");
>>
>> ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
>> List list = listViewer.getList();
>> list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
>> listViewer.setContentProvider(new AdapterFactoryContentProvider(sme.getAdapterFactory()));
>> listViewer.setLabelProvider(new AdapterFactoryLabelProvider(sme.getAdapterFactory()));
>> }
>>
>> }
>>
>> Needless to say it doesn't work.
>> listViewer appears empty even though I have something in the model (and I can see it in the masterBlock).
>>
>> I think I really do not understand how all this is supposed to work.
>> I have a fair understanding of DataBinding, but this seems to be deeply wrapped in the AdapterFactories and I wasn't able to find documentation on that.
>> Even "EMF: Eclipse Modeling Framework, Second Edition" I recently bought does not seem to contain Information on how to do this.
>> I must confess I didn't study it cover-to-cover, but customization seems to be very ViewerPane-and-PropertyList-centric, while I would like to move to standard widgets and/or Forms.
>>
>> Can someone point me to the relevant documentation?
>> I'm pretty sure what I want to do should be possible, but I'm getting lost.
>>
>> Thanks in Advance
>> Mauro
>
  • Attachment: statem.png
    (Size: 20.23KB, Downloaded 40 times)
Re: Refactoring the generated editor [message #829242 is a reply to message #828562] Sun, 25 March 2012 23:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 24529
Registered: July 2009
Senior Member
Mauro,

Comments below.

On 24/03/2012 9:08 PM, Mauro Condarelli wrote:
> I am aiming to understand if and how the code generated by EMF can be
> bent to display the things in the way I like them.
>
> I understand how to do EMF DataBinding (I think) as I used it in another
> project.
> In that code I used nothing of the facilities in .edit and .editor; I
> rewrote the Editor from scratch.
> Doing this I lost all benefits of using commands, including Undo/Redo
> and such.
>
> Now I started a very small project (model contains just three classes
> with an handful of fields each) and I wanted to use it to understand
> better the inner EMF machinery.
>
> Nevertheless I would like to have a "standard"(?) Form-based editor with
> master/detail forms. I do not want to use a generated Property editor
> but a handcrafted Form.
> All this, if possible, using commands to maintain undo capability.
I think you want to use EMFEditProperties for your data binding needs.
It works much like the Bean data binding facility.
>
> The simplified model I currently use is in attach.
>
> The Machine details page should essentially be a ListViewer of the
> contained States, with a couple of buttons to add a new State, delete an
> existing one and, perhaps to move up/down the States.
> "initial" State should be a combo selecting one of the existing states.
> "current" should not appear at all.
> "name" should be a simple text field.
>
> The State and Arc details pages would be a bit more complex, but on the
> same lines.
>
> Is it possible to (easily) do such a thing?
> Is this a Bad Idea, for some reason?
> Where should I go to get an overview of what I should do?
>
> Thanks in Advance
> Mauro
>
>
> On 24/03/2012 23:42, Tom Schindl wrote:
>> Without a Viewer#setInput() nothing can be shown! You've thrown in the
>> term databinding but you are not use databinding (at least not
>> EMF-Datadinding) so I'm not sure what you are aiming at.
>>
>> Tom
>>
>> Am 24.03.12 15:22, schrieb Mauro Condarelli:
>>> Hi,
>>> I'm trying to understand how to reuse the editor EMF kindly generated
>>> for my (simple) model.
>>>
>>> It works and does a lot of things, unfortunately it does not do them in
>>> the way I need them done.
>>>
>>> What I need is a Form-based Master/Details set of pages.
>>>
>>> I managed to convert the produced selection tree view into the
>>> MasterPart of a MasterSetailsBlock.
>>>
>>> I am now stuck in how to connect the IDetailsPage(s) with the model via
>>> generated editor.
>>>
>>> I tried blindly something like:
>>>
>>> public class MachineDetailsPage implements IDetailsPage {
>>> private final StatemEditor sme;
>>> private IManagedForm managedForm;
>>> private Text txtName;
>>> public MachineDetailsPage(StatemEditor sme) {
>>> this.sme = sme;
>>> }
>>>
>>> @Override
>>> public void initialize(IManagedForm form) {
>>> managedForm = form;
>>> }
>>> ...
>>>
>>> @Override
>>> public void createContents(Composite parent) {
>>> FormToolkit toolkit = managedForm.getToolkit();
>>> GridLayout gl_parent = new GridLayout();
>>> gl_parent.numColumns = 2;
>>> parent.setLayout(gl_parent);
>>>
>>> Label lblMachineName = new Label(parent, SWT.NONE);
>>> lblMachineName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
>>> toolkit.adapt(lblMachineName, true, true);
>>> lblMachineName.setText("Machine Name:");
>>>
>>> txtName = toolkit.createText(parent, "New Text", SWT.NONE);
>>> txtName.setText("Name");
>>> txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
>>>
>>> Label lblInitialState = new Label(parent, SWT.NONE);
>>> lblInitialState.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
>>> toolkit.adapt(lblInitialState, true, true);
>>> lblInitialState.setText("Initial State:");
>>>
>>> ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE);
>>> Combo combo = comboViewer.getCombo();
>>> combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
>>> toolkit.paintBordersFor(combo);
>>>
>>> Label lblStates = new Label(parent, SWT.NONE);
>>> lblStates.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
>>> toolkit.adapt(lblStates, true, true);
>>> lblStates.setText("States:");
>>>
>>> ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
>>> List list = listViewer.getList();
>>> list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
>>> listViewer.setContentProvider(new AdapterFactoryContentProvider(sme.getAdapterFactory()));
>>> listViewer.setLabelProvider(new AdapterFactoryLabelProvider(sme.getAdapterFactory()));
>>> }
>>>
>>> }
>>>
>>> Needless to say it doesn't work.
>>> listViewer appears empty even though I have something in the model (and I can see it in the masterBlock).
>>>
>>> I think I really do not understand how all this is supposed to work.
>>> I have a fair understanding of DataBinding, but this seems to be deeply wrapped in the AdapterFactories and I wasn't able to find documentation on that.
>>> Even "EMF: Eclipse Modeling Framework, Second Edition" I recently bought does not seem to contain Information on how to do this.
>>> I must confess I didn't study it cover-to-cover, but customization seems to be very ViewerPane-and-PropertyList-centric, while I would like to move to standard widgets and/or Forms.
>>>
>>> Can someone point me to the relevant documentation?
>>> I'm pretty sure what I want to do should be possible, but I'm getting lost.
>>>
>>> Thanks in Advance
>>> Mauro
Re: Refactoring the generated editor [message #830391 is a reply to message #828412] Tue, 27 March 2012 11:09 Go to previous messageGo to next message
Maximilian Koegel is currently offline Maximilian Koegel
Messages: 117
Registered: July 2009
Senior Member
Hi Mauro,

you could also look at EMF Client Platform, if you would like to reuse
existing editors:
http://emfcp.org

Cheers,
Maximilian

Am 24.03.2012 15:22, schrieb Mauro Condarelli:
> Hi,
> I'm trying to understand how to reuse the editor EMF kindly generated
> for my (simple) model.
>
> It works and does a lot of things, unfortunately it does not do them in
> the way I need them done.
>
> What I need is a Form-based Master/Details set of pages.
>
> I managed to convert the produced selection tree view into the
> MasterPart of a MasterSetailsBlock.
>
> I am now stuck in how to connect the IDetailsPage(s) with the model via
> generated editor.
>
> I tried blindly something like:
>
> public class MachineDetailsPage implements IDetailsPage {
> private final StatemEditor sme;
> private IManagedForm managedForm;
> private Text txtName;
> public MachineDetailsPage(StatemEditor sme) {
> this.sme = sme;
> }
>
> @Override
> public void initialize(IManagedForm form) {
> managedForm = form;
> }
> ...
>
> @Override
> public void createContents(Composite parent) {
> FormToolkit toolkit = managedForm.getToolkit();
> GridLayout gl_parent = new GridLayout();
> gl_parent.numColumns = 2;
> parent.setLayout(gl_parent);
>
> Label lblMachineName = new Label(parent, SWT.NONE);
> lblMachineName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
> toolkit.adapt(lblMachineName, true, true);
> lblMachineName.setText("Machine Name:");
>
> txtName = toolkit.createText(parent, "New Text", SWT.NONE);
> txtName.setText("Name");
> txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
>
> Label lblInitialState = new Label(parent, SWT.NONE);
> lblInitialState.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
> toolkit.adapt(lblInitialState, true, true);
> lblInitialState.setText("Initial State:");
>
> ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE);
> Combo combo = comboViewer.getCombo();
> combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
> toolkit.paintBordersFor(combo);
>
> Label lblStates = new Label(parent, SWT.NONE);
> lblStates.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
> toolkit.adapt(lblStates, true, true);
> lblStates.setText("States:");
>
> ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
> List list = listViewer.getList();
> list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
> listViewer.setContentProvider(new AdapterFactoryContentProvider(sme.getAdapterFactory()));
> listViewer.setLabelProvider(new AdapterFactoryLabelProvider(sme.getAdapterFactory()));
> }
>
> }
>
> Needless to say it doesn't work.
> listViewer appears empty even though I have something in the model (and I can see it in the masterBlock).
>
> I think I really do not understand how all this is supposed to work.
> I have a fair understanding of DataBinding, but this seems to be deeply wrapped in the AdapterFactories and I wasn't able to find documentation on that.
> Even "EMF: Eclipse Modeling Framework, Second Edition" I recently bought does not seem to contain Information on how to do this.
> I must confess I didn't study it cover-to-cover, but customization seems to be very ViewerPane-and-PropertyList-centric, while I would like to move to standard widgets and/or Forms.
>
> Can someone point me to the relevant documentation?
> I'm pretty sure what I want to do should be possible, but I'm getting lost.
>
> Thanks in Advance
> Mauro
Re: Refactoring the generated editor [message #834044 is a reply to message #829242] Sun, 01 April 2012 05:52 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 365
Registered: September 2009
Senior Member
Sorry about resurrecting this thread after a while, but this is really some low priority learning project for me, so I'm free to work on it only during weekends.

Comments below.

On 26/03/2012 05:05, Ed Merks wrote:
>> Now I started a very small project (model contains just three classes
>> with an handful of fields each) and I wanted to use it to understand
>> better the inner EMF machinery.
>>
>> Nevertheless I would like to have a "standard"(?) Form-based editor with
>> master/detail forms. I do not want to use a generated Property editor
>> but a handcrafted Form.
>> All this, if possible, using commands to maintain undo capability.
> I think you want to use EMFEditProperties for your data binding needs.
> It works much like the Bean data binding facility.
Does this mean I should avoid generating the editor at all?

I wanted to understand how to use AdapterFactories (which currently is rather obscure to me).

I actually got a moderate degree of success by using two different strategies:

1) using EMFEditProperties:

private IObservableValue oMachine = new WritableValue();

private void createBindings() {
DataBindingContext dbc = new DataBindingContext();

ObservableListContentProvider cp = new ObservableListContentProvider();
comboViewer.setContentProvider(cp);
IObservableList oss = EMFEditProperties.list(smed, StatemPackage.Literals.MACHINE__STATES).observeDetail(oMachine);
//IObservableList osn = EMFEditProperties.value(smed, StatemPackage.Literals.STATE__NAME).observeDetail(oss);
comboViewer.setInput(oss);


IObservableValue ois = EMFEditProperties.value(smed, StatemPackage.Literals.MACHINE__INITIAL).observeDetail(oMachine);
IObservableValue bis = WidgetProperties.singleSelectionIndex().observeDelayed(400, comboViewer.getControl());
dbc.bindValue(bis, ois, new UpdateValueStrategy() {
@Override
public Object convert(Object value) {
int idx = (Integer) value;
State s = (State) comboViewer.getElementAt(idx);
return s;
}
}, new UpdateValueStrategy(){
@Override
public Object convert(Object value) {
State s = (State) value;
for (int idx = 0; ; idx++) {
Object o = comboViewer.getElementAt(idx);
if (o instanceof State) {
State t = (State) o;
if (s.equals(t))
return idx;
} else {
return -1;
}
}
}
});

ois = EMFEditProperties.value(smed, StatemPackage.Literals.MACHINE__NAME).observeDetail(oMachine);
bis = WidgetProperties.text(SWT.Modify).observeDelayed(400, txtName);
dbc.bindValue(bis, ois);
}
@Override
public void selectionChanged(IFormPart part, ISelection selection) {
if (selection instanceof StructuredSelection) {
StructuredSelection ss = (StructuredSelection) selection;
Object o = ss.getFirstElement();
if (o instanceof Machine) {
Machine m = (Machine) o;
oMachine.setValue(m);
}
}
}

2) trying to use the edit-generated factories:

private void createBindings() {
DataBindingContext dbc = new DataBindingContext();

comboViewer.setContentProvider(new AdapterFactoryContentProvider(sme.getAdapterFactory()));
comboViewer.setLabelProvider(new AdapterFactoryLabelProvider(sme.getAdapterFactory()));
comboViewer.setInput(oMachine);
...
}

public void selectionChanged(IFormPart part, ISelection selection) {
if (selection instanceof StructuredSelection) {
StructuredSelection ss = (StructuredSelection) selection;
Object o = ss.getFirstElement();
if (o instanceof Machine) {
Machine m = (Machine) o;
comboViewer.setInput(m);
}
}
}

Should I ditch completely approach (2) together with the generated editor?

My hope was to be able to reuse editor's hooks for editing, adding and removing model elements.

Any comment would be welcome.

Regards
Mauro
Re: Refactoring the generated editor [message #834066 is a reply to message #828412] Sun, 01 April 2012 06:45 Go to previous message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1115
Registered: July 2009
Senior Member
Ciao Marco

we're working on a project for providing emf components which are
(hopefully) easily reusable and customazible (among them, also viewers
and forms and editors based on mixes of them); the project is located here

http://code.google.com/a/eclipselabs.org/p/emf-components/

for the moment it is available only in source code format; but update
site and documentation should be ready soon.

Please feel free to ask me for starting up.

cheers
Lorenzo

On 03/24/2012 08:22 PM, Mauro Condarelli wrote:
> Hi,
> I'm trying to understand how to reuse the editor EMF kindly generated
> for my (simple) model.
>
> It works and does a lot of things, unfortunately it does not do them in
> the way I need them done.
>
> What I need is a Form-based Master/Details set of pages.
>
> I managed to convert the produced selection tree view into the
> MasterPart of a MasterSetailsBlock.
>
> I am now stuck in how to connect the IDetailsPage(s) with the model via
> generated editor.
>
> I tried blindly something like:
>
> public class MachineDetailsPage implements IDetailsPage {
> private final StatemEditor sme;
> private IManagedForm managedForm;
> private Text txtName;
> public MachineDetailsPage(StatemEditor sme) {
> this.sme = sme;
> }
>
> @Override
> public void initialize(IManagedForm form) {
> managedForm = form;
> }
> ...
>
> @Override
> public void createContents(Composite parent) {
> FormToolkit toolkit = managedForm.getToolkit();
> GridLayout gl_parent = new GridLayout();
> gl_parent.numColumns = 2;
> parent.setLayout(gl_parent);
>
> Label lblMachineName = new Label(parent, SWT.NONE);
> lblMachineName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
> toolkit.adapt(lblMachineName, true, true);
> lblMachineName.setText("Machine Name:");
>
> txtName = toolkit.createText(parent, "New Text", SWT.NONE);
> txtName.setText("Name");
> txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
>
> Label lblInitialState = new Label(parent, SWT.NONE);
> lblInitialState.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
> toolkit.adapt(lblInitialState, true, true);
> lblInitialState.setText("Initial State:");
>
> ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE);
> Combo combo = comboViewer.getCombo();
> combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
> toolkit.paintBordersFor(combo);
>
> Label lblStates = new Label(parent, SWT.NONE);
> lblStates.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
> toolkit.adapt(lblStates, true, true);
> lblStates.setText("States:");
>
> ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
> List list = listViewer.getList();
> list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
> listViewer.setContentProvider(new AdapterFactoryContentProvider(sme.getAdapterFactory()));
> listViewer.setLabelProvider(new AdapterFactoryLabelProvider(sme.getAdapterFactory()));
> }
>
> }
>
> Needless to say it doesn't work.
> listViewer appears empty even though I have something in the model (and I can see it in the masterBlock).
>
> I think I really do not understand how all this is supposed to work.
> I have a fair understanding of DataBinding, but this seems to be deeply wrapped in the AdapterFactories and I wasn't able to find documentation on that.
> Even "EMF: Eclipse Modeling Framework, Second Edition" I recently bought does not seem to contain Information on how to do this.
> I must confess I didn't study it cover-to-cover, but customization seems to be very ViewerPane-and-PropertyList-centric, while I would like to move to standard widgets and/or Forms.
>
> Can someone point me to the relevant documentation?
> I'm pretty sure what I want to do should be possible, but I'm getting lost.
>
> Thanks in Advance
> Mauro


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Previous Topic:Databinding To Combo?
Next Topic:[Teneo][Hibernate] ClassCastException:
Goto Forum:
  


Current Time: Sat May 18 15:43:52 EDT 2013

Powered by FUDForum. Page generated in 0.07271 seconds