Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Re: how to set Stateful item provider adapters (NOT singleton)
Re: how to set Stateful item provider adapters (NOT singleton) [message #417646] Wed, 19 March 2008 22:12 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mircea,

Stateful item providers is a property on the GenClass that affects the
generation of the XyzItemProviderAdapter. I'm not sure what you're
needing it for based on this example though...


Mircea Luchian wrote:
> Hello,
>
> I am trying to set stateful item provider adapters for the tree in an
> EMF model.
>
> The way I do my initialization is:
> viewer.setContentProvider(new
> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
> customAdapterFactoryLabelProvider = new
> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>
> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>
> How can I set these providers as stateful and not singleton?
>
> I have tried many ways with no success.
>
> Thanks,
>
> Mircea


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to set Stateful item provider adapters (NOT singleton) [message #417654 is a reply to message #417646] Thu, 20 March 2008 14:45 Go to previous messageGo to next message
Mircea Luchian is currently offline Mircea LuchianFriend
Messages: 89
Registered: July 2009
Member
Thanks Ed,

I did change the property for each class, but it doesn't solve my
problem. Perhpas it's something else:

For some reason, when I have two or more editors of the same type and I
switch between them, I always get the CustomAdapterFactoryLabelProvider
(or the model) of the last initialized editor in the workbech. Having
cycled for the first time through all open editors, my
CustomAdapterFactoryLabelProvider has always access to the model that is
represented in the last initialized editor, indifferent of the currently
selected editor.
I checked the editor code and have no static references to panels, tree
viewer and other objects.

The problem is in the CustomAdapterFactoryLabelProvider's
public String getColumnText(Object object, int columnIndex) method.
The Object passed belongs to the model of the last initialized editor
and not the last selected.

What could be the problem? Am I missing something?

Thanks,

Mircea



Ed Merks wrote:
> Mircea,
>
> Stateful item providers is a property on the GenClass that affects the
> generation of the XyzItemProviderAdapter. I'm not sure what you're
> needing it for based on this example though...
>
>
> Mircea Luchian wrote:
>> Hello,
>>
>> I am trying to set stateful item provider adapters for the tree in an
>> EMF model.
>>
>> The way I do my initialization is:
>> viewer.setContentProvider(new
>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>> customAdapterFactoryLabelProvider = new
>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>
>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>
>> How can I set these providers as stateful and not singleton?
>>
>> I have tried many ways with no success.
>>
>> Thanks,
>>
>> Mircea
Re: how to set Stateful item provider adapters (NOT singleton) [message #417655 is a reply to message #417654] Thu, 20 March 2008 14:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mircea,

Comments below.

Mircea Luchian wrote:
> Thanks Ed,
>
> I did change the property for each class, but it doesn't solve my
> problem. Perhpas it's something else:
Yes, I suspected that...
>
> For some reason, when I have two or more editors of the same type and
> I switch between them, I always get the
> CustomAdapterFactoryLabelProvider (or the model) of the last
> initialized editor in the workbech.
I can't imagine how that could happen.
> Having cycled for the first time through all open editors, my
> CustomAdapterFactoryLabelProvider has always access to the model that
> is represented in the last initialized editor, indifferent of the
> currently selected editor.
Does your model instance live longer than the editor? The item
providers adapter factory uses its own instance as a key to locate
adapters on the instance object so unless you are sharing the adapter
factories themselves as well as the object instances, I don't see how
you'd have this kind of problem.
>
> I checked the editor code and have no static references to panels,
> tree viewer and other objects.
>
> The problem is in the CustomAdapterFactoryLabelProvider's
> public String getColumnText(Object object, int columnIndex) method.
> The Object passed belongs to the model of the last initialized editor
> and not the last selected.
I'm at a complete loss to think of how you'd get the kind of behavior
you describe. If you look at the object x and look at the
x.eResource() and x.eResource().getResourceSet(), does the resource set
correspond to the resource set of the editing domain in your editor? If
it does, then it's not an object from another editor...
>
> What could be the problem? Am I missing something?
I think there must be some subtlety that either your not understanding
or your not explaining...
>
> Thanks,
>
> Mircea
>
>
>
> Ed Merks wrote:
>> Mircea,
>>
>> Stateful item providers is a property on the GenClass that affects
>> the generation of the XyzItemProviderAdapter. I'm not sure what
>> you're needing it for based on this example though...
>>
>>
>> Mircea Luchian wrote:
>>> Hello,
>>>
>>> I am trying to set stateful item provider adapters for the tree in
>>> an EMF model.
>>>
>>> The way I do my initialization is:
>>> viewer.setContentProvider(new
>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>> customAdapterFactoryLabelProvider = new
>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>
>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>
>>> How can I set these providers as stateful and not singleton?
>>>
>>> I have tried many ways with no success.
>>>
>>> Thanks,
>>>
>>> Mircea


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to set Stateful item provider adapters (NOT singleton) [message #417658 is a reply to message #417655] Thu, 20 March 2008 15:44 Go to previous messageGo to next message
Mircea Luchian is currently offline Mircea LuchianFriend
Messages: 89
Registered: July 2009
Member
Hello Ed,

> I'm at a complete loss to think of how you'd get the kind of behavior
you describe.
> If you look at the object x and look at the x.eResource() and
x.eResource().getResourceSet(), does the resource
> set correspond to the resource set of the editing domain in your
editor? If it does, then it's not an object from another editor...

Precisely, I looked at the eResource().getResourceSet() for the root
object of the model. It does not to the current editing domain. My guess
is that the editing domain is not updated as I select the active editor.

Mircea


Ed Merks wrote:
> Mircea,
>
> Comments below.
>
> Mircea Luchian wrote:
>> Thanks Ed,
>>
>> I did change the property for each class, but it doesn't solve my
>> problem. Perhpas it's something else:
> Yes, I suspected that...
>>
>> For some reason, when I have two or more editors of the same type and
>> I switch between them, I always get the
>> CustomAdapterFactoryLabelProvider (or the model) of the last
>> initialized editor in the workbech.
> I can't imagine how that could happen.
>> Having cycled for the first time through all open editors, my
>> CustomAdapterFactoryLabelProvider has always access to the model that
>> is represented in the last initialized editor, indifferent of the
>> currently selected editor.
> Does your model instance live longer than the editor? The item
> providers adapter factory uses its own instance as a key to locate
> adapters on the instance object so unless you are sharing the adapter
> factories themselves as well as the object instances, I don't see how
> you'd have this kind of problem.
>>
>> I checked the editor code and have no static references to panels,
>> tree viewer and other objects.
>>
>> The problem is in the CustomAdapterFactoryLabelProvider's
>> public String getColumnText(Object object, int columnIndex) method.
>> The Object passed belongs to the model of the last initialized editor
>> and not the last selected.
> I'm at a complete loss to think of how you'd get the kind of behavior
> you describe. If you look at the object x and look at the
> x.eResource() and x.eResource().getResourceSet(), does the resource
> set correspond to the resource set of the editing domain in your
> editor? If it does, then it's not an object from another editor...
>>
>> What could be the problem? Am I missing something?
> I think there must be some subtlety that either your not understanding
> or your not explaining...
>>
>> Thanks,
>>
>> Mircea
>>
>>
>>
>> Ed Merks wrote:
>>> Mircea,
>>>
>>> Stateful item providers is a property on the GenClass that affects
>>> the generation of the XyzItemProviderAdapter. I'm not sure what
>>> you're needing it for based on this example though...
>>>
>>>
>>> Mircea Luchian wrote:
>>>> Hello,
>>>>
>>>> I am trying to set stateful item provider adapters for the tree in
>>>> an EMF model.
>>>>
>>>> The way I do my initialization is:
>>>> viewer.setContentProvider(new
>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>
>>>> customAdapterFactoryLabelProvider = new
>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>
>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>
>>>> How can I set these providers as stateful and not singleton?
>>>>
>>>> I have tried many ways with no success.
>>>>
>>>> Thanks,
>>>>
>>>> Mircea
Re: how to set Stateful item provider adapters (NOT singleton) [message #417660 is a reply to message #417658] Thu, 20 March 2008 17:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mircea,

In what context does this occur? The editor creates a new editing
domain and loads resources into that editing domains local resource
set. How are objects from other editors entering the picture. I.e,
where is the editing domain not being updated during activation?


Mircea Luchian wrote:
> Hello Ed,
>
> > I'm at a complete loss to think of how you'd get the kind of
> behavior you describe. > If you look at the object x and look at the
> x.eResource() and x.eResource().getResourceSet(), does the resource
> > set correspond to the resource set of the editing domain in your
> editor? If it does, then it's not an object from another editor...
>
> Precisely, I looked at the eResource().getResourceSet() for the root
> object of the model. It does not to the current editing domain. My
> guess is that the editing domain is not updated as I select the active
> editor.
>
> Mircea
>
>
> Ed Merks wrote:
>> Mircea,
>>
>> Comments below.
>>
>> Mircea Luchian wrote:
>>> Thanks Ed,
>>>
>>> I did change the property for each class, but it doesn't solve my
>>> problem. Perhpas it's something else:
>> Yes, I suspected that...
>>>
>>> For some reason, when I have two or more editors of the same type
>>> and I switch between them, I always get the
>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>> initialized editor in the workbech.
>> I can't imagine how that could happen.
>>> Having cycled for the first time through all open editors, my
>>> CustomAdapterFactoryLabelProvider has always access to the model
>>> that is represented in the last initialized editor, indifferent of
>>> the currently selected editor.
>> Does your model instance live longer than the editor? The item
>> providers adapter factory uses its own instance as a key to locate
>> adapters on the instance object so unless you are sharing the adapter
>> factories themselves as well as the object instances, I don't see how
>> you'd have this kind of problem.
>>>
>>> I checked the editor code and have no static references to panels,
>>> tree viewer and other objects.
>>>
>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>> public String getColumnText(Object object, int columnIndex) method.
>>> The Object passed belongs to the model of the last initialized
>>> editor and not the last selected.
>> I'm at a complete loss to think of how you'd get the kind of behavior
>> you describe. If you look at the object x and look at the
>> x.eResource() and x.eResource().getResourceSet(), does the resource
>> set correspond to the resource set of the editing domain in your
>> editor? If it does, then it's not an object from another editor...
>>>
>>> What could be the problem? Am I missing something?
>> I think there must be some subtlety that either your not
>> understanding or your not explaining...
>>>
>>> Thanks,
>>>
>>> Mircea
>>>
>>>
>>>
>>> Ed Merks wrote:
>>>> Mircea,
>>>>
>>>> Stateful item providers is a property on the GenClass that affects
>>>> the generation of the XyzItemProviderAdapter. I'm not sure what
>>>> you're needing it for based on this example though...
>>>>
>>>>
>>>> Mircea Luchian wrote:
>>>>> Hello,
>>>>>
>>>>> I am trying to set stateful item provider adapters for the tree in
>>>>> an EMF model.
>>>>>
>>>>> The way I do my initialization is:
>>>>> viewer.setContentProvider(new
>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>
>>>>> customAdapterFactoryLabelProvider = new
>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>
>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>
>>>>> How can I set these providers as stateful and not singleton?
>>>>>
>>>>> I have tried many ways with no success.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Mircea


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to set Stateful item provider adapters (NOT singleton) [message #417670 is a reply to message #417660] Thu, 20 March 2008 19:00 Go to previous messageGo to next message
Mircea Luchian is currently offline Mircea LuchianFriend
Messages: 89
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------050600000100050906060507
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hello Ed,

Actually, the editor is initialized with the correct editing domain. The
problem is in ScrolledPropertiesBlock.

Let me explain:

I created a CustomAdapterFactoryLabelProvider (extends
AdapterFactoryLabelProvider) for my tree so I can represent the nodes
with on a TableTree. The second column has some extra data next to the
nodes (a range of addresses). I do all sorts of operations (add / remove
/ move / delete and set in the right panel) that need to update the
CustomAdapterFactoryLabelProvider via the fireLabelProviderChanged()
method. The Label provider does some calculations for display purposes
as well.


At first, I declared the CustomAdapterFactoryLabelProvider as follows in
the ScrolledPropertyBlock:
public class ScrolledPropertiesBlock extends MasterDetailsBlock
implements ISelectionChangedListener
{
protected TreeViewer treeViewer;
private CustomAdapterFactoryLabelProvider
customAdapterFactoryLabelProvider;
[...]

public ScrolledPropertiesBlock(TreeViewer ourViewer,
RegisterfileEditor registerFileEditor)
{ [...] }

protected void createMasterPart(final IManagedForm managedForm,
Composite parent)
{
[...]
viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
viewer.setLabelProvider(customAdapterFactoryLabelProvider);
[...]
}
[...]

public void updateLabelProvider() //used to update provider from
the outside, (panels, undo, redo, etc)
{
if (customAdapterFactoryLabelProvider != null)
customAdapterFactoryLabelProvider.fireLabelProviderChanged() ;
}
}

In a debugger with a breakpoint at public String getColumnText(Object
object, int columnIndex) in CustomAdapterFactoryLabelProvider , and go
between two editors back and forth in the workbench and expand some
nodes in the tree in the same time.
The interesting thing is that I could see that the eResource setting at
the root note of the passed object was indeed wrong. It was pointing at
the wrong file, but the editor domain was correctly initialized in the
main editor class.
This happened also when I was trying to update the label provider via
the updateLabelProvider() function from my own panels.

I then set the label provider without using a global variable as follows:
viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
viewer.setLabelProvider(new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
While debugging, the eResource was correct all the time between editors
when I was expanding the nodes.

I don't understand this as in the first case, the variable private
CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider is
not declared static so it should be a different instance for every
editor. It is is clearly not the case.

I then changed updateLabelProvider() to reflect the above changes so I
could update the CustomAdapterFactoryLabelProvider from the outside:
protected void updateLabelProvider()
{
if
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() != null)

((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged();
}
While calling this function, the same thing happened: I got the wrong
eResource of the LabelPRovider stored in the treeViewer global variable.

Do you have any ideas? Could be because the xxxEditorPlugin.java class
is a singleton?

With this in mind, I think I should delcare my LabelProvider as not
global and all cosmetic calcualtions such as the ranges should be done
in the model implmentation without having the need to fire the provider
from the outside.

Mircea





Ed Merks wrote:
> Mircea,
>
> In what context does this occur? The editor creates a new editing
> domain and loads resources into that editing domains local resource
> set. How are objects from other editors entering the picture. I.e,
> where is the editing domain not being updated during activation?
>
>
> Mircea Luchian wrote:
>> Hello Ed,
>>
>> > I'm at a complete loss to think of how you'd get the kind of
>> behavior you describe. > If you look at the object x and look at
>> the x.eResource() and x.eResource().getResourceSet(), does the resource
>> > set correspond to the resource set of the editing domain in your
>> editor? If it does, then it's not an object from another editor...
>>
>> Precisely, I looked at the eResource().getResourceSet() for the root
>> object of the model. It does not to the current editing domain. My
>> guess is that the editing domain is not updated as I select the
>> active editor.
>>
>> Mircea
>>
>>
>> Ed Merks wrote:
>>> Mircea,
>>>
>>> Comments below.
>>>
>>> Mircea Luchian wrote:
>>>> Thanks Ed,
>>>>
>>>> I did change the property for each class, but it doesn't solve my
>>>> problem. Perhpas it's something else:
>>> Yes, I suspected that...
>>>>
>>>> For some reason, when I have two or more editors of the same type
>>>> and I switch between them, I always get the
>>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>>> initialized editor in the workbech.
>>> I can't imagine how that could happen.
>>>> Having cycled for the first time through all open editors, my
>>>> CustomAdapterFactoryLabelProvider has always access to the model
>>>> that is represented in the last initialized editor, indifferent of
>>>> the currently selected editor.
>>> Does your model instance live longer than the editor? The item
>>> providers adapter factory uses its own instance as a key to locate
>>> adapters on the instance object so unless you are sharing the
>>> adapter factories themselves as well as the object instances, I
>>> don't see how you'd have this kind of problem.
>>>>
>>>> I checked the editor code and have no static references to panels,
>>>> tree viewer and other objects.
>>>>
>>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>>> public String getColumnText(Object object, int columnIndex) method.
>>>> The Object passed belongs to the model of the last initialized
>>>> editor and not the last selected.
>>> I'm at a complete loss to think of how you'd get the kind of
>>> behavior you describe. If you look at the object x and look at
>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>> resource set correspond to the resource set of the editing domain in
>>> your editor? If it does, then it's not an object from another
>>> editor...
>>>>
>>>> What could be the problem? Am I missing something?
>>> I think there must be some subtlety that either your not
>>> understanding or your not explaining...
>>>>
>>>> Thanks,
>>>>
>>>> Mircea
>>>>
>>>>
>>>>
>>>> Ed Merks wrote:
>>>>> Mircea,
>>>>>
>>>>> Stateful item providers is a property on the GenClass that affects
>>>>> the generation of the XyzItemProviderAdapter. I'm not sure what
>>>>> you're needing it for based on this example though...
>>>>>
>>>>>
>>>>> Mircea Luchian wrote:
>>>>>> Hello,
>>>>>>
>>>>>> I am trying to set stateful item provider adapters for the tree
>>>>>> in an EMF model.
>>>>>>
>>>>>> The way I do my initialization is:
>>>>>> viewer.setContentProvider(new
>>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>>
>>>>>> customAdapterFactoryLabelProvider = new
>>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>>
>>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>>
>>>>>> How can I set these providers as stateful and not singleton?
>>>>>>
>>>>>> I have tried many ways with no success.
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Mircea


--------------050600000100050906060507
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Ed, <br>
<br>
Actually, the editor is initialized with the correct editing domain.
The problem is in <font face="Courier New, Courier, monospace">ScrolledPropertiesBlock</font>.
<br>
<br>
Let me explain:<br>
<br>
I created a <font face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider
</font>(extends <font face="Courier New, Courier, monospace">AdapterFactoryLabelProvider</font>)
for my tree so I can represent the
nodes with on a <font face="Courier New, Courier, monospace">TableTree</font>.
The second column has some extra data next
to the nodes (a range of addresses). I do all sorts of operations (add
/ remove / move / delete and set in the right panel) that need to
update the <font face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider
</font>via the <font face="Courier New, Courier, monospace">fireLabelProviderChanged()</font>
method. The Label provider does some calculations for display purposes
as well.<br>
<br>
<br>
At first, I declared the <font face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider
</font>as follows in the <font face="Courier New, Courier, monospace">ScrolledPropertyBlock</font>:<br>
<font face="Courier New, Courier, monospace">public class
ScrolledPropertiesBlock extends MasterDetailsBlock implements
ISelectionChangedListener <br>
{<br>
&nbsp;&nbsp;&nbsp; protected TreeViewer treeViewer;<br>
&nbsp;&nbsp;&nbsp; private CustomAdapterFactoryLabelProvider
customAdapterFactoryLabelProvider;<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public ScrolledPropertiesBlock(TreeViewer ourViewer,
RegisterfileEditor registerFileEditor)<br>
&nbsp;&nbsp;&nbsp; { [...] }<br>
<br>
&nbsp;&nbsp;&nbsp; protected void createMasterPart(final IManagedForm managedForm,
Composite parent)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider);<br >
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public void updateLabelProvider()&nbsp; //used to update provider from
the outside, (panels, undo, redo, etc)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (</font><font face="Courier New, Courier, monospace">customAdapterFactoryLabelProvider</font><font
face="Courier New, Courier, monospace"> != null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </font><font face="Courier New, Courier, monospace"> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ; </font><font
face="Courier New, Courier, monospace"><br>
&nbsp;&nbsp;&nbsp; }<br>
}</font><br>
<br>
In a debugger with a breakpoint at <font
face="Courier New, Courier, monospace">public String
getColumnText(Object object, int columnIndex)</font> in <font
face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider</font>
, and go between two editors back and forth in the workbench and expand
some nodes in the tree in the same time. <br>
The interesting thing is that I could see that the eResource setting at
the root note of the passed object was indeed wrong. It was pointing at
the wrong file, but the editor domain was correctly initialized in the
main editor class.<br>
This happened also when I was trying to update the label provider via
the <font face="Courier New, Courier, monospace">updateLabelProvider()
</font>function from my own panels.<br>
<br>
I then set the label provider without using a global variable as
follows: <br>
<font face="Courier New, Courier, monospace">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; viewer.setLabelProvider(new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory())); </font><br>
While debugging, the eResource was correct all the time between editors
when I was expanding the nodes.<br>
<br>
I don't understand this as in the first case, the variable <font
face="Courier New, Courier, monospace">private
CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider</font>&nbsp;
is not declared static so it should be a different instance for every
editor. It is is clearly not the case.<br>
<br>
I then changed <font face="Courier New, Courier, monospace">updateLabelProvider()</font>
to reflect the above changes so I could update the <font
face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider
</font>from the outside:<br>
<font face="Courier New, Courier, monospace">&nbsp;&nbsp;&nbsp; protected void
updateLabelProvider()<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() !=
null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged(); <br>
&nbsp;&nbsp;&nbsp; }<br>
</font>While calling this function, the same thing happened: I got the
wrong eResource of the LabelPRovider stored in the <font
face="Courier New, Courier, monospace">treeViewer </font>global
variable. <br>
<br>
Do you have any ideas? Could be because the xxxEditorPlugin.java class
is a singleton? <br>
<br>
With this in mind, I think I should delcare my LabelProvider as not
global and all cosmetic calcualtions such as the ranges should be done
in the model implmentation without having the need to fire the provider
from the outside. <br>
<br>
Mircea<br>
<br>
<br>
<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfru74n$fs6$1@build.eclipse.org" type="cite">Mircea,
<br>
<br>
In what context does this occur?&nbsp; The editor creates a new editing
domain and loads resources into that editing domains local resource
set.&nbsp; How are objects from other editors entering the picture.&nbsp; I.e,
where is the editing domain not being updated during activation?
<br>
<br>
<br>
Mircea Luchian wrote:
<br>
<blockquote type="cite">Hello Ed,
<br>
<br>
&gt; I'm at a complete loss to think of how you'd get the kind of
behavior you describe.&nbsp;&nbsp; &gt; If you look at the object x and look at
the x.eResource() and x.eResource().getResourceSet(), does the resource
<br>
&gt; set correspond to the resource set of&nbsp; the editing domain in your
editor?&nbsp; If it does, then it's not an object from another editor...
<br>
<br>
Precisely, I looked at the eResource().getResourceSet() for the root
object of the model. It does not to the current editing domain. My
guess is that the editing domain is not updated as I select the active
editor.
<br>
<br>
Mircea
<br>
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Mircea,
<br>
<br>
Comments below.
<br>
<br>
Mircea Luchian wrote:
<br>
<blockquote type="cite">Thanks Ed,
<br>
<br>
I did change the property for each class, but it doesn't solve my
problem. Perhpas it's something else:
<br>
</blockquote>
Yes, I suspected that...
<br>
<blockquote type="cite"><br>
For some reason, when I have two or more editors of the same type and I
switch between them, I always get the CustomAdapterFactoryLabelProvider
(or the model) of the last initialized editor in the workbech.
<br>
</blockquote>
I can't imagine how that could happen.
<br>
<blockquote type="cite">&nbsp; Having cycled for the first time
through all open editors, my CustomAdapterFactoryLabelProvider has
always access to the model that is represented in the last initialized
editor, indifferent of the currently selected editor.
<br>
</blockquote>
Does your model instance live longer than the editor?&nbsp; The item
providers adapter factory uses its own instance as a key to locate
adapters on the instance object so unless you are sharing the adapter
factories themselves as well as the object instances, I don't see how
you'd have this kind of problem.
<br>
<blockquote type="cite"><br>
I checked the editor code and have no static references to panels, tree
viewer and other objects.
<br>
<br>
The problem is in the CustomAdapterFactoryLabelProvider's
<br>
public String getColumnText(Object object, int columnIndex) method.
<br>
The Object passed belongs to the model of the last initialized editor
and not the last selected.
<br>
</blockquote>
I'm at a complete loss to think of how you'd get the kind of behavior
you describe.&nbsp;&nbsp;&nbsp; If you look at the object x and look at the
x.eResource() and x.eResource().getResourceSet(), does the resource set
correspond to the resource set of the editing domain in your editor?&nbsp;
If it does, then it's not an object from another editor...
<br>
<blockquote type="cite"><br>
What could be the problem? Am I missing something?
<br>
</blockquote>
I think there must be some subtlety that either your not understanding
or your not explaining...
<br>
<blockquote type="cite"><br>
Thanks,
<br>
<br>
Mircea
<br>
<br>
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Mircea,
<br>
<br>
Stateful item providers is a property on the GenClass that affects the
generation of the XyzItemProviderAdapter.&nbsp; I'm not sure what you're
needing it for based on this example though...
<br>
<br>
<br>
Mircea Luchian wrote:
<br>
<blockquote type="cite">Hello,
<br>
<br>
I am trying to set stateful item provider adapters for the tree in an
EMF model.
<br>
<br>
The way I do my initialization is:
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider);
<br>
<br>
How can I set these providers as stateful and not singleton?
<br>
<br>
I have tried many ways with no success.
<br>
<br>
Thanks,
<br>
<br>
Mircea
<br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------050600000100050906060507--
Re: how to set Stateful item provider adapters (NOT singleton) [message #417674 is a reply to message #417670] Thu, 20 March 2008 20:50 Go to previous messageGo to next message
Steve Blass is currently offline Steve BlassFriend
Messages: 276
Registered: July 2009
Senior Member
> the treeViewer global variable

Could it be that that should be using the ourViewer passed in to the
ScrolledPropertiesBlock constructor instead?

-
Steve




Mircea Luchian wrote:
> Hello Ed,
>
> Actually, the editor is initialized with the correct editing domain. The
> problem is in ScrolledPropertiesBlock.
>
> Let me explain:
>
> I created a CustomAdapterFactoryLabelProvider (extends
> AdapterFactoryLabelProvider) for my tree so I can represent the nodes
> with on a TableTree. The second column has some extra data next to the
> nodes (a range of addresses). I do all sorts of operations (add / remove
> / move / delete and set in the right panel) that need to update the
> CustomAdapterFactoryLabelProvider via the fireLabelProviderChanged()
> method. The Label provider does some calculations for display purposes
> as well.
>
>
> At first, I declared the CustomAdapterFactoryLabelProvider as follows in
> the ScrolledPropertyBlock:
> public class ScrolledPropertiesBlock extends MasterDetailsBlock
> implements ISelectionChangedListener
> {
> protected TreeViewer treeViewer;
> private CustomAdapterFactoryLabelProvider
> customAdapterFactoryLabelProvider;
> [...]
>
> public ScrolledPropertiesBlock(TreeViewer ourViewer,
> RegisterfileEditor registerFileEditor)
> { [...] }
>
> protected void createMasterPart(final IManagedForm managedForm,
> Composite parent)
> {
> [...]
> viewer.setContentProvider(new
> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
> customAdapterFactoryLabelProvider = new
> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
> [...]
> }
> [...]
>
> public void updateLabelProvider() //used to update provider from
> the outside, (panels, undo, redo, etc)
> {
> if (customAdapterFactoryLabelProvider != null)
> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ;
> }
> }
>
> In a debugger with a breakpoint at public String getColumnText(Object
> object, int columnIndex) in CustomAdapterFactoryLabelProvider , and go
> between two editors back and forth in the workbench and expand some
> nodes in the tree in the same time.
> The interesting thing is that I could see that the eResource setting at
> the root note of the passed object was indeed wrong. It was pointing at
> the wrong file, but the editor domain was correctly initialized in the
> main editor class.
> This happened also when I was trying to update the label provider via
> the updateLabelProvider() function from my own panels.
>
> I then set the label provider without using a global variable as follows:
> viewer.setContentProvider(new
> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
> viewer.setLabelProvider(new
> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
> While debugging, the eResource was correct all the time between editors
> when I was expanding the nodes.
>
> I don't understand this as in the first case, the variable private
> CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider is
> not declared static so it should be a different instance for every
> editor. It is is clearly not the case.
>
> I then changed updateLabelProvider() to reflect the above changes so I
> could update the CustomAdapterFactoryLabelProvider from the outside:
> protected void updateLabelProvider()
> {
> if
> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() != null)
>
> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged();
> }
> While calling this function, the same thing happened: I got the wrong
> eResource of the LabelPRovider stored in the treeViewer global variable.
>
> Do you have any ideas? Could be because the xxxEditorPlugin.java class
> is a singleton?
>
> With this in mind, I think I should delcare my LabelProvider as not
> global and all cosmetic calcualtions such as the ranges should be done
> in the model implmentation without having the need to fire the provider
> from the outside.
>
> Mircea
>
>
>
>
>
> Ed Merks wrote:
>> Mircea,
>>
>> In what context does this occur? The editor creates a new editing
>> domain and loads resources into that editing domains local resource
>> set. How are objects from other editors entering the picture. I.e,
>> where is the editing domain not being updated during activation?
>>
>>
>> Mircea Luchian wrote:
>>> Hello Ed,
>>>
>>> > I'm at a complete loss to think of how you'd get the kind of
>>> behavior you describe. > If you look at the object x and look at
>>> the x.eResource() and x.eResource().getResourceSet(), does the resource
>>> > set correspond to the resource set of the editing domain in your
>>> editor? If it does, then it's not an object from another editor...
>>>
>>> Precisely, I looked at the eResource().getResourceSet() for the root
>>> object of the model. It does not to the current editing domain. My
>>> guess is that the editing domain is not updated as I select the
>>> active editor.
>>>
>>> Mircea
>>>
>>>
>>> Ed Merks wrote:
>>>> Mircea,
>>>>
>>>> Comments below.
>>>>
>>>> Mircea Luchian wrote:
>>>>> Thanks Ed,
>>>>>
>>>>> I did change the property for each class, but it doesn't solve my
>>>>> problem. Perhpas it's something else:
>>>> Yes, I suspected that...
>>>>>
>>>>> For some reason, when I have two or more editors of the same type
>>>>> and I switch between them, I always get the
>>>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>>>> initialized editor in the workbech.
>>>> I can't imagine how that could happen.
>>>>> Having cycled for the first time through all open editors, my
>>>>> CustomAdapterFactoryLabelProvider has always access to the model
>>>>> that is represented in the last initialized editor, indifferent of
>>>>> the currently selected editor.
>>>> Does your model instance live longer than the editor? The item
>>>> providers adapter factory uses its own instance as a key to locate
>>>> adapters on the instance object so unless you are sharing the
>>>> adapter factories themselves as well as the object instances, I
>>>> don't see how you'd have this kind of problem.
>>>>>
>>>>> I checked the editor code and have no static references to panels,
>>>>> tree viewer and other objects.
>>>>>
>>>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>>>> public String getColumnText(Object object, int columnIndex) method.
>>>>> The Object passed belongs to the model of the last initialized
>>>>> editor and not the last selected.
>>>> I'm at a complete loss to think of how you'd get the kind of
>>>> behavior you describe. If you look at the object x and look at
>>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>>> resource set correspond to the resource set of the editing domain in
>>>> your editor? If it does, then it's not an object from another
>>>> editor...
>>>>>
>>>>> What could be the problem? Am I missing something?
>>>> I think there must be some subtlety that either your not
>>>> understanding or your not explaining...
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Mircea
>>>>>
>>>>>
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Mircea,
>>>>>>
>>>>>> Stateful item providers is a property on the GenClass that affects
>>>>>> the generation of the XyzItemProviderAdapter. I'm not sure what
>>>>>> you're needing it for based on this example though...
>>>>>>
>>>>>>
>>>>>> Mircea Luchian wrote:
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am trying to set stateful item provider adapters for the tree
>>>>>>> in an EMF model.
>>>>>>>
>>>>>>> The way I do my initialization is:
>>>>>>> viewer.setContentProvider(new
>>>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>>>
>>>>>>> customAdapterFactoryLabelProvider = new
>>>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>>>
>>>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>>>
>>>>>>> How can I set these providers as stateful and not singleton?
>>>>>>>
>>>>>>> I have tried many ways with no success.
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Mircea
>
Re: how to set Stateful item provider adapters (NOT singleton) [message #417675 is a reply to message #417674] Thu, 20 March 2008 21:01 Go to previous messageGo to next message
Mircea Luchian is currently offline Mircea LuchianFriend
Messages: 89
Registered: July 2009
Member
Hello Steve,

The treeViewer is initialized in the constructor with ourEditor, just
like in the Eclipse forms source on this forum.

Mircea

Steve Blass wrote:
> > the treeViewer global variable
>
> Could it be that that should be using the ourViewer passed in to the
> ScrolledPropertiesBlock constructor instead?
>
> -
> Steve
>
>
>
>
> Mircea Luchian wrote:
>> Hello Ed,
>>
>> Actually, the editor is initialized with the correct editing domain.
>> The problem is in ScrolledPropertiesBlock.
>>
>> Let me explain:
>>
>> I created a CustomAdapterFactoryLabelProvider (extends
>> AdapterFactoryLabelProvider) for my tree so I can represent the nodes
>> with on a TableTree. The second column has some extra data next to
>> the nodes (a range of addresses). I do all sorts of operations (add /
>> remove / move / delete and set in the right panel) that need to
>> update the CustomAdapterFactoryLabelProvider via the
>> fireLabelProviderChanged() method. The Label provider does some
>> calculations for display purposes as well.
>>
>>
>> At first, I declared the CustomAdapterFactoryLabelProvider as follows
>> in the ScrolledPropertyBlock:
>> public class ScrolledPropertiesBlock extends MasterDetailsBlock
>> implements ISelectionChangedListener
>> {
>> protected TreeViewer treeViewer;
>> private CustomAdapterFactoryLabelProvider
>> customAdapterFactoryLabelProvider;
>> [...]
>>
>> public ScrolledPropertiesBlock(TreeViewer ourViewer,
>> RegisterfileEditor registerFileEditor)
>> { [...] }
>>
>> protected void createMasterPart(final IManagedForm managedForm,
>> Composite parent)
>> {
>> [...]
>> viewer.setContentProvider(new
>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>> customAdapterFactoryLabelProvider = new
>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>
>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>> [...]
>> }
>> [...]
>>
>> public void updateLabelProvider() //used to update provider from
>> the outside, (panels, undo, redo, etc)
>> {
>> if (customAdapterFactoryLabelProvider != null)
>>
>> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ;
>> }
>> }
>>
>> In a debugger with a breakpoint at public String getColumnText(Object
>> object, int columnIndex) in CustomAdapterFactoryLabelProvider , and
>> go between two editors back and forth in the workbench and expand
>> some nodes in the tree in the same time.
>> The interesting thing is that I could see that the eResource setting
>> at the root note of the passed object was indeed wrong. It was
>> pointing at the wrong file, but the editor domain was correctly
>> initialized in the main editor class.
>> This happened also when I was trying to update the label provider via
>> the updateLabelProvider() function from my own panels.
>>
>> I then set the label provider without using a global variable as
>> follows:
>> viewer.setContentProvider(new
>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>> viewer.setLabelProvider(new
>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
>>
>> While debugging, the eResource was correct all the time between
>> editors when I was expanding the nodes.
>>
>> I don't understand this as in the first case, the variable private
>> CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider
>> is not declared static so it should be a different instance for every
>> editor. It is is clearly not the case.
>>
>> I then changed updateLabelProvider() to reflect the above changes so
>> I could update the CustomAdapterFactoryLabelProvider from the outside:
>> protected void updateLabelProvider()
>> {
>> if
>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() !=
>> null)
>>
>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged();
>>
>> }
>> While calling this function, the same thing happened: I got the wrong
>> eResource of the LabelPRovider stored in the treeViewer global variable.
>>
>> Do you have any ideas? Could be because the xxxEditorPlugin.java
>> class is a singleton?
>>
>> With this in mind, I think I should delcare my LabelProvider as not
>> global and all cosmetic calcualtions such as the ranges should be
>> done in the model implmentation without having the need to fire the
>> provider from the outside.
>>
>> Mircea
>>
>>
>>
>>
>>
>> Ed Merks wrote:
>>> Mircea,
>>>
>>> In what context does this occur? The editor creates a new editing
>>> domain and loads resources into that editing domains local resource
>>> set. How are objects from other editors entering the picture. I.e,
>>> where is the editing domain not being updated during activation?
>>>
>>>
>>> Mircea Luchian wrote:
>>>> Hello Ed,
>>>>
>>>> > I'm at a complete loss to think of how you'd get the kind of
>>>> behavior you describe. > If you look at the object x and look at
>>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>>> resource
>>>> > set correspond to the resource set of the editing domain in your
>>>> editor? If it does, then it's not an object from another editor...
>>>>
>>>> Precisely, I looked at the eResource().getResourceSet() for the
>>>> root object of the model. It does not to the current editing
>>>> domain. My guess is that the editing domain is not updated as I
>>>> select the active editor.
>>>>
>>>> Mircea
>>>>
>>>>
>>>> Ed Merks wrote:
>>>>> Mircea,
>>>>>
>>>>> Comments below.
>>>>>
>>>>> Mircea Luchian wrote:
>>>>>> Thanks Ed,
>>>>>>
>>>>>> I did change the property for each class, but it doesn't solve my
>>>>>> problem. Perhpas it's something else:
>>>>> Yes, I suspected that...
>>>>>>
>>>>>> For some reason, when I have two or more editors of the same type
>>>>>> and I switch between them, I always get the
>>>>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>>>>> initialized editor in the workbech.
>>>>> I can't imagine how that could happen.
>>>>>> Having cycled for the first time through all open editors, my
>>>>>> CustomAdapterFactoryLabelProvider has always access to the model
>>>>>> that is represented in the last initialized editor, indifferent
>>>>>> of the currently selected editor.
>>>>> Does your model instance live longer than the editor? The item
>>>>> providers adapter factory uses its own instance as a key to locate
>>>>> adapters on the instance object so unless you are sharing the
>>>>> adapter factories themselves as well as the object instances, I
>>>>> don't see how you'd have this kind of problem.
>>>>>>
>>>>>> I checked the editor code and have no static references to
>>>>>> panels, tree viewer and other objects.
>>>>>>
>>>>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>>>>> public String getColumnText(Object object, int columnIndex) method.
>>>>>> The Object passed belongs to the model of the last initialized
>>>>>> editor and not the last selected.
>>>>> I'm at a complete loss to think of how you'd get the kind of
>>>>> behavior you describe. If you look at the object x and look at
>>>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>>>> resource set correspond to the resource set of the editing domain
>>>>> in your editor? If it does, then it's not an object from another
>>>>> editor...
>>>>>>
>>>>>> What could be the problem? Am I missing something?
>>>>> I think there must be some subtlety that either your not
>>>>> understanding or your not explaining...
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Mircea
>>>>>>
>>>>>>
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>> Mircea,
>>>>>>>
>>>>>>> Stateful item providers is a property on the GenClass that
>>>>>>> affects the generation of the XyzItemProviderAdapter. I'm not
>>>>>>> sure what you're needing it for based on this example though...
>>>>>>>
>>>>>>>
>>>>>>> Mircea Luchian wrote:
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> I am trying to set stateful item provider adapters for the tree
>>>>>>>> in an EMF model.
>>>>>>>>
>>>>>>>> The way I do my initialization is:
>>>>>>>> viewer.setContentProvider(new
>>>>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>>>>
>>>>>>>> customAdapterFactoryLabelProvider = new
>>>>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>>>>
>>>>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>>>>
>>>>>>>> How can I set these providers as stateful and not singleton?
>>>>>>>>
>>>>>>>> I have tried many ways with no success.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Mircea
>>
Re: how to set Stateful item provider adapters (NOT singleton) [message #417677 is a reply to message #417670] Thu, 20 March 2008 21:32 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070502000904080504090009
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Mircea,

It sounds like you have a view that takes selected objects as input and
can retarget whatever editor has focus. Such a view should determine
the adapter factory to use from the adapter factory editing domain of
the selected object. Probably each time the selection changes, you
should use
AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) to get
the right editing domain and create your label/content providers from
the adapter factory of that...


Mircea Luchian wrote:
> Hello Ed,
>
> Actually, the editor is initialized with the correct editing domain.
> The problem is in ScrolledPropertiesBlock.
>
> Let me explain:
>
> I created a CustomAdapterFactoryLabelProvider (extends
> AdapterFactoryLabelProvider) for my tree so I can represent the nodes
> with on a TableTree. The second column has some extra data next to the
> nodes (a range of addresses). I do all sorts of operations (add /
> remove / move / delete and set in the right panel) that need to update
> the CustomAdapterFactoryLabelProvider via the
> fireLabelProviderChanged() method. The Label provider does some
> calculations for display purposes as well.
>
>
> At first, I declared the CustomAdapterFactoryLabelProvider as follows
> in the ScrolledPropertyBlock:
> public class ScrolledPropertiesBlock extends MasterDetailsBlock
> implements ISelectionChangedListener
> {
> protected TreeViewer treeViewer;
> private CustomAdapterFactoryLabelProvider
> customAdapterFactoryLabelProvider;
> [...]
>
> public ScrolledPropertiesBlock(TreeViewer ourViewer,
> RegisterfileEditor registerFileEditor)
> { [...] }
>
> protected void createMasterPart(final IManagedForm managedForm,
> Composite parent)
> {
> [...]
> viewer.setContentProvider(new
> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
> customAdapterFactoryLabelProvider = new
> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
> [...]
> }
> [...]
>
> public void updateLabelProvider() //used to update provider from
> the outside, (panels, undo, redo, etc)
> {
> if (customAdapterFactoryLabelProvider != null)
> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ;
> }
> }
>
> In a debugger with a breakpoint at public String getColumnText(Object
> object, int columnIndex) in CustomAdapterFactoryLabelProvider , and go
> between two editors back and forth in the workbench and expand some
> nodes in the tree in the same time.
> The interesting thing is that I could see that the eResource setting
> at the root note of the passed object was indeed wrong. It was
> pointing at the wrong file, but the editor domain was correctly
> initialized in the main editor class.
> This happened also when I was trying to update the label provider via
> the updateLabelProvider() function from my own panels.
>
> I then set the label provider without using a global variable as follows:
> viewer.setContentProvider(new
> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
> viewer.setLabelProvider(new
> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
> While debugging, the eResource was correct all the time between
> editors when I was expanding the nodes.
>
> I don't understand this as in the first case, the variable private
> CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider
> is not declared static so it should be a different instance for every
> editor. It is is clearly not the case.
>
> I then changed updateLabelProvider() to reflect the above changes so I
> could update the CustomAdapterFactoryLabelProvider from the outside:
> protected void updateLabelProvider()
> {
> if
> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() != null)
>
> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged();
> }
> While calling this function, the same thing happened: I got the wrong
> eResource of the LabelPRovider stored in the treeViewer global variable.
>
> Do you have any ideas? Could be because the xxxEditorPlugin.java class
> is a singleton?
>
> With this in mind, I think I should delcare my LabelProvider as not
> global and all cosmetic calcualtions such as the ranges should be done
> in the model implmentation without having the need to fire the
> provider from the outside.
>
> Mircea
>
>
>
>
>
> Ed Merks wrote:
>> Mircea,
>>
>> In what context does this occur? The editor creates a new editing
>> domain and loads resources into that editing domains local resource
>> set. How are objects from other editors entering the picture. I.e,
>> where is the editing domain not being updated during activation?
>>
>>
>> Mircea Luchian wrote:
>>> Hello Ed,
>>>
>>> > I'm at a complete loss to think of how you'd get the kind of
>>> behavior you describe. > If you look at the object x and look at
>>> the x.eResource() and x.eResource().getResourceSet(), does the resource
>>> > set correspond to the resource set of the editing domain in your
>>> editor? If it does, then it's not an object from another editor...
>>>
>>> Precisely, I looked at the eResource().getResourceSet() for the root
>>> object of the model. It does not to the current editing domain. My
>>> guess is that the editing domain is not updated as I select the
>>> active editor.
>>>
>>> Mircea
>>>
>>>
>>> Ed Merks wrote:
>>>> Mircea,
>>>>
>>>> Comments below.
>>>>
>>>> Mircea Luchian wrote:
>>>>> Thanks Ed,
>>>>>
>>>>> I did change the property for each class, but it doesn't solve my
>>>>> problem. Perhpas it's something else:
>>>> Yes, I suspected that...
>>>>>
>>>>> For some reason, when I have two or more editors of the same type
>>>>> and I switch between them, I always get the
>>>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>>>> initialized editor in the workbech.
>>>> I can't imagine how that could happen.
>>>>> Having cycled for the first time through all open editors, my
>>>>> CustomAdapterFactoryLabelProvider has always access to the model
>>>>> that is represented in the last initialized editor, indifferent of
>>>>> the currently selected editor.
>>>> Does your model instance live longer than the editor? The item
>>>> providers adapter factory uses its own instance as a key to locate
>>>> adapters on the instance object so unless you are sharing the
>>>> adapter factories themselves as well as the object instances, I
>>>> don't see how you'd have this kind of problem.
>>>>>
>>>>> I checked the editor code and have no static references to panels,
>>>>> tree viewer and other objects.
>>>>>
>>>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>>>> public String getColumnText(Object object, int columnIndex) method.
>>>>> The Object passed belongs to the model of the last initialized
>>>>> editor and not the last selected.
>>>> I'm at a complete loss to think of how you'd get the kind of
>>>> behavior you describe. If you look at the object x and look at
>>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>>> resource set correspond to the resource set of the editing domain
>>>> in your editor? If it does, then it's not an object from another
>>>> editor...
>>>>>
>>>>> What could be the problem? Am I missing something?
>>>> I think there must be some subtlety that either your not
>>>> understanding or your not explaining...
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Mircea
>>>>>
>>>>>
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Mircea,
>>>>>>
>>>>>> Stateful item providers is a property on the GenClass that
>>>>>> affects the generation of the XyzItemProviderAdapter. I'm not
>>>>>> sure what you're needing it for based on this example though...
>>>>>>
>>>>>>
>>>>>> Mircea Luchian wrote:
>>>>>>> Hello,
>>>>>>>
>>>>>>> I am trying to set stateful item provider adapters for the tree
>>>>>>> in an EMF model.
>>>>>>>
>>>>>>> The way I do my initialization is:
>>>>>>> viewer.setContentProvider(new
>>>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>>>
>>>>>>> customAdapterFactoryLabelProvider = new
>>>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>>>
>>>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>>>
>>>>>>> How can I set these providers as stateful and not singleton?
>>>>>>>
>>>>>>> I have tried many ways with no success.
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Mircea
>


--------------070502000904080504090009
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Mircea,<br>
<br>
It sounds like you have a view that takes selected objects as input and
can retarget whatever editor has focus.&nbsp; Such a view should determine
the adapter factory to use from the adapter factory editing domain of
the selected object.&nbsp;&nbsp; Probably each time the selection changes, you
should use
AdapterFactoryEditingDomain.getEditingDomainFor(&lt;sele ctedObject&gt;)
to get the right editing domain and create your label/content providers
from the adapter factory of that...<br>
<br>
<br>
Mircea Luchian wrote:
<blockquote cite="mid:fruc87$ets$1@build.eclipse.org" type="cite">
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
Hello Ed, <br>
<br>
Actually, the editor is initialized with the correct editing domain.
The problem is in <font face="Courier New, Courier, monospace">ScrolledPropertiesBlock</font>.
<br>
<br>
Let me explain:<br>
<br>
I created a <font face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider
</font>(extends <font face="Courier New, Courier, monospace">AdapterFactoryLabelProvider</font>)
for my tree so I can represent the
nodes with on a <font face="Courier New, Courier, monospace">TableTree</font>.
The second column has some extra data next
to the nodes (a range of addresses). I do all sorts of operations (add
/ remove / move / delete and set in the right panel) that need to
update the <font face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider
</font>via the <font face="Courier New, Courier, monospace">fireLabelProviderChanged()</font>
method. The Label provider does some calculations for display purposes
as well.<br>
<br>
<br>
At first, I declared the <font face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider
</font>as follows in the <font face="Courier New, Courier, monospace">ScrolledPropertyBlock</font>:<br>
<font face="Courier New, Courier, monospace">public class
ScrolledPropertiesBlock extends MasterDetailsBlock implements
ISelectionChangedListener <br>
{<br>
&nbsp;&nbsp;&nbsp; protected TreeViewer treeViewer;<br>
&nbsp;&nbsp;&nbsp; private CustomAdapterFactoryLabelProvider
customAdapterFactoryLabelProvider;<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public ScrolledPropertiesBlock(TreeViewer ourViewer,
RegisterfileEditor registerFileEditor)<br>
&nbsp;&nbsp;&nbsp; { [...] }<br>
<br>
&nbsp;&nbsp;&nbsp; protected void createMasterPart(final IManagedForm managedForm,
Composite parent)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider);<br >
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public void updateLabelProvider()&nbsp; //used to update provider from
the outside, (panels, undo, redo, etc)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (</font><font face="Courier New, Courier, monospace">customAdapterFactoryLabelProvider</font><font
face="Courier New, Courier, monospace"> != null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </font><font face="Courier New, Courier, monospace"> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ; </font><font
face="Courier New, Courier, monospace"><br>
&nbsp;&nbsp;&nbsp; }<br>
}</font><br>
<br>
In a debugger with a breakpoint at <font
face="Courier New, Courier, monospace">public String
getColumnText(Object object, int columnIndex)</font> in <font
face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider</font>
, and go between two editors back and forth in the workbench and expand
some nodes in the tree in the same time. <br>
The interesting thing is that I could see that the eResource setting at
the root note of the passed object was indeed wrong. It was pointing at
the wrong file, but the editor domain was correctly initialized in the
main editor class.<br>
This happened also when I was trying to update the label provider via
the <font face="Courier New, Courier, monospace">updateLabelProvider()
</font>function from my own panels.<br>
<br>
I then set the label provider without using a global variable as
follows: <br>
<font face="Courier New, Courier, monospace">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; viewer.setLabelProvider(new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory())); </font><br>
While debugging, the eResource was correct all the time between editors
when I was expanding the nodes.<br>
<br>
I don't understand this as in the first case, the variable <font
face="Courier New, Courier, monospace">private
CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider</font>&nbsp;
is not declared static so it should be a different instance for every
editor. It is is clearly not the case.<br>
<br>
I then changed <font face="Courier New, Courier, monospace">updateLabelProvider()</font>
to reflect the above changes so I could update the <font
face="Courier New, Courier, monospace">CustomAdapterFactoryLabelProvider
</font>from the outside:<br>
<font face="Courier New, Courier, monospace">&nbsp;&nbsp;&nbsp; protected void
updateLabelProvider()<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() !=
null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged(); <br>
&nbsp;&nbsp;&nbsp; }<br>
</font>While calling this function, the same thing happened: I got
the
wrong eResource of the LabelPRovider stored in the <font
face="Courier New, Courier, monospace">treeViewer </font>global
variable. <br>
<br>
Do you have any ideas? Could be because the xxxEditorPlugin.java class
is a singleton? <br>
<br>
With this in mind, I think I should delcare my LabelProvider as not
global and all cosmetic calcualtions such as the ranges should be done
in the model implmentation without having the need to fire the provider
from the outside. <br>
<br>
Mircea<br>
<br>
<br>
<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfru74n$fs6$1@build.eclipse.org" type="cite">Mircea,
<br>
<br>
In what context does this occur?&nbsp; The editor creates a new editing
domain and loads resources into that editing domains local resource
set.&nbsp; How are objects from other editors entering the picture.&nbsp; I.e,
where is the editing domain not being updated during activation? <br>
<br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Hello Ed, <br>
<br>
&gt; I'm at a complete loss to think of how you'd get the kind of
behavior you describe.&nbsp;&nbsp; &gt; If you look at the object x and look at
the x.eResource() and x.eResource().getResourceSet(), does the resource
<br>
&gt; set correspond to the resource set of&nbsp; the editing domain in your
editor?&nbsp; If it does, then it's not an object from another editor... <br>
<br>
Precisely, I looked at the eResource().getResourceSet() for the root
object of the model. It does not to the current editing domain. My
guess is that the editing domain is not updated as I select the active
editor. <br>
<br>
Mircea <br>
<br>
<br>
Ed Merks wrote: <br>
<blockquote type="cite">Mircea, <br>
<br>
Comments below. <br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Thanks Ed, <br>
<br>
I did change the property for each class, but it doesn't solve my
problem. Perhpas it's something else: <br>
</blockquote>
Yes, I suspected that... <br>
<blockquote type="cite"><br>
For some reason, when I have two or more editors of the same type and I
switch between them, I always get the CustomAdapterFactoryLabelProvider
(or the model) of the last initialized editor in the workbech. <br>
</blockquote>
I can't imagine how that could happen. <br>
<blockquote type="cite">&nbsp; Having cycled for the first time
through all open editors, my CustomAdapterFactoryLabelProvider has
always access to the model that is represented in the last initialized
editor, indifferent of the currently selected editor. <br>
</blockquote>
Does your model instance live longer than the editor?&nbsp; The item
providers adapter factory uses its own instance as a key to locate
adapters on the instance object so unless you are sharing the adapter
factories themselves as well as the object instances, I don't see how
you'd have this kind of problem. <br>
<blockquote type="cite"><br>
I checked the editor code and have no static references to panels, tree
viewer and other objects. <br>
<br>
The problem is in the CustomAdapterFactoryLabelProvider's <br>
public String getColumnText(Object object, int columnIndex) method. <br>
The Object passed belongs to the model of the last initialized editor
and not the last selected. <br>
</blockquote>
I'm at a complete loss to think of how you'd get the kind of behavior
you describe.&nbsp;&nbsp;&nbsp; If you look at the object x and look at the
x.eResource() and x.eResource().getResourceSet(), does the resource set
correspond to the resource set of the editing domain in your editor?&nbsp;
If it does, then it's not an object from another editor... <br>
<blockquote type="cite"><br>
What could be the problem? Am I missing something? <br>
</blockquote>
I think there must be some subtlety that either your not understanding
or your not explaining... <br>
<blockquote type="cite"><br>
Thanks, <br>
<br>
Mircea <br>
<br>
<br>
<br>
Ed Merks wrote: <br>
<blockquote type="cite">Mircea, <br>
<br>
Stateful item providers is a property on the GenClass that affects the
generation of the XyzItemProviderAdapter.&nbsp; I'm not sure what you're
needing it for based on this example though... <br>
<br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Hello, <br>
<br>
I am trying to set stateful item provider adapters for the tree in an
EMF model. <br>
<br>
The way I do my initialization is: <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider); <br>
<br>
How can I set these providers as stateful and not singleton? <br>
<br>
I have tried many ways with no success. <br>
<br>
Thanks, <br>
<br>
Mircea <br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>

--------------070502000904080504090009--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to set Stateful item provider adapters (NOT singleton) [message #417679 is a reply to message #417677] Thu, 20 March 2008 21:45 Go to previous messageGo to next message
Mircea Luchian is currently offline Mircea LuchianFriend
Messages: 89
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------090101060407040706010602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hello Ed,

Just to confirm: where, more precisely should I use
AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) ? Is
the selected editor object or the node in the model?

Thanks,

Mircea


Ed Merks wrote:
> Mircea,
>
> It sounds like you have a view that takes selected objects as input
> and can retarget whatever editor has focus. Such a view should
> determine the adapter factory to use from the adapter factory editing
> domain of the selected object. Probably each time the selection
> changes, you should use
> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) to
> get the right editing domain and create your label/content providers
> from the adapter factory of that...
>
>
> Mircea Luchian wrote:
>> Hello Ed,
>>
>> Actually, the editor is initialized with the correct editing domain.
>> The problem is in ScrolledPropertiesBlock .
>>
>> Let me explain:
>>
>> I created a CustomAdapterFactoryLabelProvider (extends
>> AdapterFactoryLabelProvider ) for my tree so I can represent the
>> nodes with on a TableTree . The second column has some extra data
>> next to the nodes (a range of addresses). I do all sorts of
>> operations (add / remove / move / delete and set in the right panel)
>> that need to update the CustomAdapterFactoryLabelProvider via the
>> fireLabelProviderChanged() method. The Label provider does some
>> calculations for display purposes as well.
>>
>>
>> At first, I declared the CustomAdapterFactoryLabelProvider as follows
>> in the ScrolledPropertyBlock :
>> public class ScrolledPropertiesBlock extends MasterDetailsBlock
>> implements ISelectionChangedListener
>> {
>> protected TreeViewer treeViewer;
>> private CustomAdapterFactoryLabelProvider
>> customAdapterFactoryLabelProvider;
>> [...]
>>
>> public ScrolledPropertiesBlock(TreeViewer ourViewer,
>> RegisterfileEditor registerFileEditor)
>> { [...] }
>>
>> protected void createMasterPart(final IManagedForm managedForm,
>> Composite parent)
>> {
>> [...]
>> viewer.setContentProvider(new
>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>> customAdapterFactoryLabelProvider = new
>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>> [...]
>> }
>> [...]
>>
>> public void updateLabelProvider() //used to update provider from
>> the outside, (panels, undo, redo, etc)
>> {
>> if ( customAdapterFactoryLabelProvider != null)
>>
>> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ;
>> }
>> }
>>
>> In a debugger with a breakpoint at public String getColumnText(Object
>> object, int columnIndex) in CustomAdapterFactoryLabelProvider , and
>> go between two editors back and forth in the workbench and expand
>> some nodes in the tree in the same time.
>> The interesting thing is that I could see that the eResource setting
>> at the root note of the passed object was indeed wrong. It was
>> pointing at the wrong file, but the editor domain was correctly
>> initialized in the main editor class.
>> This happened also when I was trying to update the label provider via
>> the updateLabelProvider() function from my own panels.
>>
>> I then set the label provider without using a global variable as
>> follows:
>> viewer.setContentProvider(new
>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>> viewer.setLabelProvider(new
>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
>>
>> While debugging, the eResource was correct all the time between
>> editors when I was expanding the nodes.
>>
>> I don't understand this as in the first case, the variable private
>> CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider
>> is not declared static so it should be a different instance for every
>> editor. It is is clearly not the case.
>>
>> I then changed updateLabelProvider() to reflect the above changes so
>> I could update the CustomAdapterFactoryLabelProvider from the outside:
>> protected void updateLabelProvider()
>> {
>> if
>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() !=
>> null)
>>
>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged();
>> }
>> While calling this function, the same thing happened: I got the wrong
>> eResource of the LabelPRovider stored in the treeViewer global variable.
>>
>> Do you have any ideas? Could be because the xxxEditorPlugin.java
>> class is a singleton?
>>
>> With this in mind, I think I should delcare my LabelProvider as not
>> global and all cosmetic calcualtions such as the ranges should be
>> done in the model implmentation without having the need to fire the
>> provider from the outside.
>>
>> Mircea
>>
>>
>>
>>
>>
>> Ed Merks wrote:
>>> Mircea,
>>>
>>> In what context does this occur? The editor creates a new editing
>>> domain and loads resources into that editing domains local resource
>>> set. How are objects from other editors entering the picture. I.e,
>>> where is the editing domain not being updated during activation?
>>>
>>>
>>> Mircea Luchian wrote:
>>>> Hello Ed,
>>>>
>>>> > I'm at a complete loss to think of how you'd get the kind of
>>>> behavior you describe. > If you look at the object x and look at
>>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>>> resource
>>>> > set correspond to the resource set of the editing domain in your
>>>> editor? If it does, then it's not an object from another editor...
>>>>
>>>> Precisely, I looked at the eResource().getResourceSet() for the
>>>> root object of the model. It does not to the current editing
>>>> domain. My guess is that the editing domain is not updated as I
>>>> select the active editor.
>>>>
>>>> Mircea
>>>>
>>>>
>>>> Ed Merks wrote:
>>>>> Mircea,
>>>>>
>>>>> Comments below.
>>>>>
>>>>> Mircea Luchian wrote:
>>>>>> Thanks Ed,
>>>>>>
>>>>>> I did change the property for each class, but it doesn't solve my
>>>>>> problem. Perhpas it's something else:
>>>>> Yes, I suspected that...
>>>>>>
>>>>>> For some reason, when I have two or more editors of the same type
>>>>>> and I switch between them, I always get the
>>>>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>>>>> initialized editor in the workbech.
>>>>> I can't imagine how that could happen.
>>>>>> Having cycled for the first time through all open editors, my
>>>>>> CustomAdapterFactoryLabelProvider has always access to the model
>>>>>> that is represented in the last initialized editor, indifferent
>>>>>> of the currently selected editor.
>>>>> Does your model instance live longer than the editor? The item
>>>>> providers adapter factory uses its own instance as a key to locate
>>>>> adapters on the instance object so unless you are sharing the
>>>>> adapter factories themselves as well as the object instances, I
>>>>> don't see how you'd have this kind of problem.
>>>>>>
>>>>>> I checked the editor code and have no static references to
>>>>>> panels, tree viewer and other objects.
>>>>>>
>>>>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>>>>> public String getColumnText(Object object, int columnIndex) method.
>>>>>> The Object passed belongs to the model of the last initialized
>>>>>> editor and not the last selected.
>>>>> I'm at a complete loss to think of how you'd get the kind of
>>>>> behavior you describe. If you look at the object x and look at
>>>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>>>> resource set correspond to the resource set of the editing domain
>>>>> in your editor? If it does, then it's not an object from another
>>>>> editor...
>>>>>>
>>>>>> What could be the problem? Am I missing something?
>>>>> I think there must be some subtlety that either your not
>>>>> understanding or your not explaining...
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Mircea
>>>>>>
>>>>>>
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>> Mircea,
>>>>>>>
>>>>>>> Stateful item providers is a property on the GenClass that
>>>>>>> affects the generation of the XyzItemProviderAdapter. I'm not
>>>>>>> sure what you're needing it for based on this example though...
>>>>>>>
>>>>>>>
>>>>>>> Mircea Luchian wrote:
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> I am trying to set stateful item provider adapters for the tree
>>>>>>>> in an EMF model.
>>>>>>>>
>>>>>>>> The way I do my initialization is:
>>>>>>>> viewer.setContentProvider(new
>>>>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>>>>
>>>>>>>> customAdapterFactoryLabelProvider = new
>>>>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>>>>
>>>>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>>>>
>>>>>>>> How can I set these providers as stateful and not singleton?
>>>>>>>>
>>>>>>>> I have tried many ways with no success.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Mircea
>>
>


--------------090101060407040706010602
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Ed, <br>
<br>
Just to confirm: where, more precisely should I use
AdapterFactoryEditingDomain.getEditingDomainFor(&lt;sele ctedObject&gt;)
? Is the selected editor object or the node in the model? <br>
<br>
Thanks, <br>
<br>
Mircea<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfrul6a$btn$1@build.eclipse.org" type="cite">
<meta http-equiv="Context-Type"
content="text/html; charset=ISO-8859-1">
Mircea,<br>
<br>
It sounds like you have a view that takes selected objects as input and
can retarget whatever editor has focus.&nbsp; Such a view should determine
the adapter factory to use from the adapter factory editing domain of
the selected object.&nbsp;&nbsp; Probably each time the selection changes, you
should use
AdapterFactoryEditingDomain.getEditingDomainFor(&lt;sele ctedObject&gt;)
to get the right editing domain and create your label/content providers
from the adapter factory of that...<br>
<br>
<br>
Mircea Luchian wrote:
<blockquote cite="mid:fruc87$ets$1@build.eclipse.org" type="cite">
Hello Ed, <br>
<br>
Actually, the editor is initialized with the correct editing domain.
The problem is in ScrolledPropertiesBlock . <br>
<br>
Let me explain:<br>
<br>
I created a CustomAdapterFactoryLabelProvider (extends
AdapterFactoryLabelProvider )
for my tree so I can represent the
nodes with on a TableTree .
The second column has some extra data next
to the nodes (a range of addresses). I do all sorts of operations (add
/ remove / move / delete and set in the right panel) that need to
update the CustomAdapterFactoryLabelProvider via the
fireLabelProviderChanged() method. The Label provider does some
calculations for display purposes
as well.<br>
<br>
<br>
At first, I declared the CustomAdapterFactoryLabelProvider as follows
in the ScrolledPropertyBlock :<br>
public class
ScrolledPropertiesBlock extends MasterDetailsBlock implements
ISelectionChangedListener <br>
{<br>
&nbsp;&nbsp;&nbsp; protected TreeViewer treeViewer;<br>
&nbsp;&nbsp;&nbsp; private CustomAdapterFactoryLabelProvider
customAdapterFactoryLabelProvider;<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public ScrolledPropertiesBlock(TreeViewer ourViewer,
RegisterfileEditor registerFileEditor)<br>
&nbsp;&nbsp;&nbsp; { [...] }<br>
<br>
&nbsp;&nbsp;&nbsp; protected void createMasterPart(final IManagedForm managedForm,
Composite parent)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider);<br >
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public void updateLabelProvider()&nbsp; //used to update provider from
the outside, (panels, undo, redo, etc)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( customAdapterFactoryLabelProvider != null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
customAdapterFactoryLabelProvider.fireLabelProviderChanged() ; <br>
&nbsp;&nbsp;&nbsp; }<br>
} <br>
<br>
In a debugger with a breakpoint at public String
getColumnText(Object object, int columnIndex) in
CustomAdapterFactoryLabelProvider , and go between two editors back and
forth in the workbench and expand
some nodes in the tree in the same time. <br>
The interesting thing is that I could see that the eResource setting at
the root note of the passed object was indeed wrong. It was pointing at
the wrong file, but the editor domain was correctly initialized in the
main editor class.<br>
This happened also when I was trying to update the label provider via
the updateLabelProvider() function from my own panels.<br>
<br>
I then set the label provider without using a global variable as
follows: <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; viewer.setLabelProvider(new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
<br>
While debugging, the eResource was correct all the time between editors
when I was expanding the nodes.<br>
<br>
I don't understand this as in the first case, the variable private
CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider &nbsp;
is not declared static so it should be a different instance for every
editor. It is is clearly not the case.<br>
<br>
I then changed updateLabelProvider() to reflect the above changes so I
could update the CustomAdapterFactoryLabelProvider from the outside:<br>
&nbsp;&nbsp;&nbsp; protected void
updateLabelProvider()<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() !=
null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged(); <br>
&nbsp;&nbsp;&nbsp; }<br>
While calling this function, the same thing happened: I got
the
wrong eResource of the LabelPRovider stored in the treeViewer global
variable. <br>
<br>
Do you have any ideas? Could be because the xxxEditorPlugin.java class
is a singleton? <br>
<br>
With this in mind, I think I should delcare my LabelProvider as not
global and all cosmetic calcualtions such as the ranges should be done
in the model implmentation without having the need to fire the provider
from the outside. <br>
<br>
Mircea<br>
<br>
<br>
<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfru74n$fs6$1@build.eclipse.org" type="cite">Mircea,
<br>
<br>
In what context does this occur?&nbsp; The editor creates a new editing
domain and loads resources into that editing domains local resource
set.&nbsp; How are objects from other editors entering the picture.&nbsp; I.e,
where is the editing domain not being updated during activation? <br>
<br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Hello Ed, <br>
<br>
&gt; I'm at a complete loss to think of how you'd get the kind of
behavior you describe.&nbsp;&nbsp; &gt; If you look at the object x and look at
the x.eResource() and x.eResource().getResourceSet(), does the resource
<br>
&gt; set correspond to the resource set of&nbsp; the editing domain in your
editor?&nbsp; If it does, then it's not an object from another editor... <br>
<br>
Precisely, I looked at the eResource().getResourceSet() for the root
object of the model. It does not to the current editing domain. My
guess is that the editing domain is not updated as I select the active
editor. <br>
<br>
Mircea <br>
<br>
<br>
Ed Merks wrote: <br>
<blockquote type="cite">Mircea, <br>
<br>
Comments below. <br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Thanks Ed, <br>
<br>
I did change the property for each class, but it doesn't solve my
problem. Perhpas it's something else: <br>
</blockquote>
Yes, I suspected that... <br>
<blockquote type="cite"><br>
For some reason, when I have two or more editors of the same type and I
switch between them, I always get the CustomAdapterFactoryLabelProvider
(or the model) of the last initialized editor in the workbech. <br>
</blockquote>
I can't imagine how that could happen. <br>
<blockquote type="cite">&nbsp; Having cycled for the first time
through all open editors, my CustomAdapterFactoryLabelProvider has
always access to the model that is represented in the last initialized
editor, indifferent of the currently selected editor. <br>
</blockquote>
Does your model instance live longer than the editor?&nbsp; The item
providers adapter factory uses its own instance as a key to locate
adapters on the instance object so unless you are sharing the adapter
factories themselves as well as the object instances, I don't see how
you'd have this kind of problem. <br>
<blockquote type="cite"><br>
I checked the editor code and have no static references to panels, tree
viewer and other objects. <br>
<br>
The problem is in the CustomAdapterFactoryLabelProvider's <br>
public String getColumnText(Object object, int columnIndex) method. <br>
The Object passed belongs to the model of the last initialized editor
and not the last selected. <br>
</blockquote>
I'm at a complete loss to think of how you'd get the kind of behavior
you describe.&nbsp;&nbsp;&nbsp; If you look at the object x and look at the
x.eResource() and x.eResource().getResourceSet(), does the resource set
correspond to the resource set of the editing domain in your editor?&nbsp;
If it does, then it's not an object from another editor... <br>
<blockquote type="cite"><br>
What could be the problem? Am I missing something? <br>
</blockquote>
I think there must be some subtlety that either your not understanding
or your not explaining... <br>
<blockquote type="cite"><br>
Thanks, <br>
<br>
Mircea <br>
<br>
<br>
<br>
Ed Merks wrote: <br>
<blockquote type="cite">Mircea, <br>
<br>
Stateful item providers is a property on the GenClass that affects the
generation of the XyzItemProviderAdapter.&nbsp; I'm not sure what you're
needing it for based on this example though... <br>
<br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Hello, <br>
<br>
I am trying to set stateful item provider adapters for the tree in an
EMF model. <br>
<br>
The way I do my initialization is: <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider); <br>
<br>
How can I set these providers as stateful and not singleton? <br>
<br>
I have tried many ways with no success. <br>
<br>
Thanks, <br>
<br>
Mircea <br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>

--------------090101060407040706010602--
Re: how to set Stateful item provider adapters (NOT singleton) [message #417680 is a reply to message #417679] Thu, 20 March 2008 21:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040201020709060102060804
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Mircea,

I'm quite confused by the whole thing. I.e., the outline and properties
views display a different viewer depending on who is using it and each
will be initialized properly without the type of problem you've
described here. It's still entirely unclear how the view ends up
dealing with objects from a different editing domain. To me it says the
editing domain it's using should be changed as editors are being
activated and likely as the input to the view is changing, but I don't
see where that's happening in your design.


Mircea Luchian wrote:
> Hello Ed,
>
> Just to confirm: where, more precisely should I use
> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) ? Is
> the selected editor object or the node in the model?
>
> Thanks,
>
> Mircea
>
>
> Ed Merks wrote:
>> Mircea,
>>
>> It sounds like you have a view that takes selected objects as input
>> and can retarget whatever editor has focus. Such a view should
>> determine the adapter factory to use from the adapter factory editing
>> domain of the selected object. Probably each time the selection
>> changes, you should use
>> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) to
>> get the right editing domain and create your label/content providers
>> from the adapter factory of that...
>>
>>
>> Mircea Luchian wrote:
>>> Hello Ed,
>>>
>>> Actually, the editor is initialized with the correct editing domain.
>>> The problem is in ScrolledPropertiesBlock .
>>>
>>> Let me explain:
>>>
>>> I created a CustomAdapterFactoryLabelProvider (extends
>>> AdapterFactoryLabelProvider ) for my tree so I can represent the
>>> nodes with on a TableTree . The second column has some extra data
>>> next to the nodes (a range of addresses). I do all sorts of
>>> operations (add / remove / move / delete and set in the right panel)
>>> that need to update the CustomAdapterFactoryLabelProvider via the
>>> fireLabelProviderChanged() method. The Label provider does some
>>> calculations for display purposes as well.
>>>
>>>
>>> At first, I declared the CustomAdapterFactoryLabelProvider as
>>> follows in the ScrolledPropertyBlock :
>>> public class ScrolledPropertiesBlock extends MasterDetailsBlock
>>> implements ISelectionChangedListener
>>> {
>>> protected TreeViewer treeViewer;
>>> private CustomAdapterFactoryLabelProvider
>>> customAdapterFactoryLabelProvider;
>>> [...]
>>>
>>> public ScrolledPropertiesBlock(TreeViewer ourViewer,
>>> RegisterfileEditor registerFileEditor)
>>> { [...] }
>>>
>>> protected void createMasterPart(final IManagedForm managedForm,
>>> Composite parent)
>>> {
>>> [...]
>>> viewer.setContentProvider(new
>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>> customAdapterFactoryLabelProvider = new
>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>> [...]
>>> }
>>> [...]
>>>
>>> public void updateLabelProvider() //used to update provider
>>> from the outside, (panels, undo, redo, etc)
>>> {
>>> if ( customAdapterFactoryLabelProvider != null)
>>>
>>> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ;
>>> }
>>> }
>>>
>>> In a debugger with a breakpoint at public String
>>> getColumnText(Object object, int columnIndex) in
>>> CustomAdapterFactoryLabelProvider , and go between two editors back
>>> and forth in the workbench and expand some nodes in the tree in the
>>> same time.
>>> The interesting thing is that I could see that the eResource setting
>>> at the root note of the passed object was indeed wrong. It was
>>> pointing at the wrong file, but the editor domain was correctly
>>> initialized in the main editor class.
>>> This happened also when I was trying to update the label provider
>>> via the updateLabelProvider() function from my own panels.
>>>
>>> I then set the label provider without using a global variable as
>>> follows:
>>> viewer.setContentProvider(new
>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>> viewer.setLabelProvider(new
>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
>>>
>>> While debugging, the eResource was correct all the time between
>>> editors when I was expanding the nodes.
>>>
>>> I don't understand this as in the first case, the variable private
>>> CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider
>>> is not declared static so it should be a different instance for
>>> every editor. It is is clearly not the case.
>>>
>>> I then changed updateLabelProvider() to reflect the above changes so
>>> I could update the CustomAdapterFactoryLabelProvider from the outside:
>>> protected void updateLabelProvider()
>>> {
>>> if
>>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() !=
>>> null)
>>>
>>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged();
>>> }
>>> While calling this function, the same thing happened: I got the
>>> wrong eResource of the LabelPRovider stored in the treeViewer global
>>> variable.
>>>
>>> Do you have any ideas? Could be because the xxxEditorPlugin.java
>>> class is a singleton?
>>>
>>> With this in mind, I think I should delcare my LabelProvider as not
>>> global and all cosmetic calcualtions such as the ranges should be
>>> done in the model implmentation without having the need to fire the
>>> provider from the outside.
>>>
>>> Mircea
>>>
>>>
>>>
>>>
>>>
>>> Ed Merks wrote:
>>>> Mircea,
>>>>
>>>> In what context does this occur? The editor creates a new editing
>>>> domain and loads resources into that editing domains local resource
>>>> set. How are objects from other editors entering the picture.
>>>> I.e, where is the editing domain not being updated during activation?
>>>>
>>>>
>>>> Mircea Luchian wrote:
>>>>> Hello Ed,
>>>>>
>>>>> > I'm at a complete loss to think of how you'd get the kind of
>>>>> behavior you describe. > If you look at the object x and look at
>>>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>>>> resource
>>>>> > set correspond to the resource set of the editing domain in
>>>>> your editor? If it does, then it's not an object from another
>>>>> editor...
>>>>>
>>>>> Precisely, I looked at the eResource().getResourceSet() for the
>>>>> root object of the model. It does not to the current editing
>>>>> domain. My guess is that the editing domain is not updated as I
>>>>> select the active editor.
>>>>>
>>>>> Mircea
>>>>>
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Mircea,
>>>>>>
>>>>>> Comments below.
>>>>>>
>>>>>> Mircea Luchian wrote:
>>>>>>> Thanks Ed,
>>>>>>>
>>>>>>> I did change the property for each class, but it doesn't solve
>>>>>>> my problem. Perhpas it's something else:
>>>>>> Yes, I suspected that...
>>>>>>>
>>>>>>> For some reason, when I have two or more editors of the same
>>>>>>> type and I switch between them, I always get the
>>>>>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>>>>>> initialized editor in the workbech.
>>>>>> I can't imagine how that could happen.
>>>>>>> Having cycled for the first time through all open editors, my
>>>>>>> CustomAdapterFactoryLabelProvider has always access to the model
>>>>>>> that is represented in the last initialized editor, indifferent
>>>>>>> of the currently selected editor.
>>>>>> Does your model instance live longer than the editor? The item
>>>>>> providers adapter factory uses its own instance as a key to
>>>>>> locate adapters on the instance object so unless you are sharing
>>>>>> the adapter factories themselves as well as the object instances,
>>>>>> I don't see how you'd have this kind of problem.
>>>>>>>
>>>>>>> I checked the editor code and have no static references to
>>>>>>> panels, tree viewer and other objects.
>>>>>>>
>>>>>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>>>>>> public String getColumnText(Object object, int columnIndex) method.
>>>>>>> The Object passed belongs to the model of the last initialized
>>>>>>> editor and not the last selected.
>>>>>> I'm at a complete loss to think of how you'd get the kind of
>>>>>> behavior you describe. If you look at the object x and look at
>>>>>> the x.eResource() and x.eResource().getResourceSet(), does the
>>>>>> resource set correspond to the resource set of the editing domain
>>>>>> in your editor? If it does, then it's not an object from another
>>>>>> editor...
>>>>>>>
>>>>>>> What could be the problem? Am I missing something?
>>>>>> I think there must be some subtlety that either your not
>>>>>> understanding or your not explaining...
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Mircea
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Ed Merks wrote:
>>>>>>>> Mircea,
>>>>>>>>
>>>>>>>> Stateful item providers is a property on the GenClass that
>>>>>>>> affects the generation of the XyzItemProviderAdapter. I'm not
>>>>>>>> sure what you're needing it for based on this example though...
>>>>>>>>
>>>>>>>>
>>>>>>>> Mircea Luchian wrote:
>>>>>>>>> Hello,
>>>>>>>>>
>>>>>>>>> I am trying to set stateful item provider adapters for the
>>>>>>>>> tree in an EMF model.
>>>>>>>>>
>>>>>>>>> The way I do my initialization is:
>>>>>>>>> viewer.setContentProvider(new
>>>>>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>>>>>
>>>>>>>>> customAdapterFactoryLabelProvider = new
>>>>>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>>>>>
>>>>>>>>> How can I set these providers as stateful and not singleton?
>>>>>>>>>
>>>>>>>>> I have tried many ways with no success.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>> Mircea
>>>
>>
>


--------------040201020709060102060804
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Mircea,<br>
<br>
I'm quite confused by the whole thing.&nbsp; I.e., the outline and
properties views display a different viewer depending on who is using
it and each will be initialized properly without the type of problem
you've described here.&nbsp;&nbsp; It's still entirely unclear how the view ends
up dealing with objects from a different editing domain. To me it says
the editing domain it's using should be changed as editors are being
activated and likely as the input to the view is changing, but I don't
see where that's happening in your design.&nbsp; <br>
<br>
<br>
Mircea Luchian wrote:
<blockquote cite="mid:frulu9$fdb$1@build.eclipse.org" type="cite">
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
Hello Ed, <br>
<br>
Just to confirm: where, more precisely should I use
AdapterFactoryEditingDomain.getEditingDomainFor(&lt;sele ctedObject&gt;)
? Is the selected editor object or the node in the model? <br>
<br>
Thanks, <br>
<br>
Mircea<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfrul6a$btn$1@build.eclipse.org" type="cite">
<meta http-equiv="Context-Type"
content="text/html; charset=ISO-8859-1">
Mircea,<br>
<br>
It sounds like you have a view that takes selected objects as input and
can retarget whatever editor has focus.&nbsp; Such a view should determine
the adapter factory to use from the adapter factory editing domain of
the selected object.&nbsp;&nbsp; Probably each time the selection changes, you
should use
AdapterFactoryEditingDomain.getEditingDomainFor(&lt;sele ctedObject&gt;)
to get the right editing domain and create your label/content providers
from the adapter factory of that...<br>
<br>
<br>
Mircea Luchian wrote:
<blockquote cite="mid:fruc87$ets$1@build.eclipse.org" type="cite">Hello
Ed, <br>
<br>
Actually, the editor is initialized with the correct editing domain.
The problem is in ScrolledPropertiesBlock . <br>
<br>
Let me explain:<br>
<br>
I created a CustomAdapterFactoryLabelProvider (extends
AdapterFactoryLabelProvider )
for my tree so I can represent the
nodes with on a TableTree .
The second column has some extra data next
to the nodes (a range of addresses). I do all sorts of operations (add
/ remove / move / delete and set in the right panel) that need to
update the CustomAdapterFactoryLabelProvider via the
fireLabelProviderChanged() method. The Label provider does some
calculations for display purposes
as well.<br>
<br>
<br>
At first, I declared the CustomAdapterFactoryLabelProvider as follows
in the ScrolledPropertyBlock :<br>
public class
ScrolledPropertiesBlock extends MasterDetailsBlock implements
ISelectionChangedListener <br>
{<br>
&nbsp;&nbsp;&nbsp; protected TreeViewer treeViewer;<br>
&nbsp;&nbsp;&nbsp; private CustomAdapterFactoryLabelProvider
customAdapterFactoryLabelProvider;<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public ScrolledPropertiesBlock(TreeViewer ourViewer,
RegisterfileEditor registerFileEditor)<br>
&nbsp;&nbsp;&nbsp; { [...] }<br>
<br>
&nbsp;&nbsp;&nbsp; protected void createMasterPart(final IManagedForm managedForm,
Composite parent)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider);<br >
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public void updateLabelProvider()&nbsp; //used to update provider from
the outside, (panels, undo, redo, etc)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( customAdapterFactoryLabelProvider != null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
customAdapterFactoryLabelProvider.fireLabelProviderChanged() ; <br>
&nbsp;&nbsp;&nbsp; }<br>
} <br>
<br>
In a debugger with a breakpoint at public String
getColumnText(Object object, int columnIndex) in
CustomAdapterFactoryLabelProvider , and go between two editors back and
forth in the workbench and expand
some nodes in the tree in the same time. <br>
The interesting thing is that I could see that the eResource setting at
the root note of the passed object was indeed wrong. It was pointing at
the wrong file, but the editor domain was correctly initialized in the
main editor class.<br>
This happened also when I was trying to update the label provider via
the updateLabelProvider() function from my own panels.<br>
<br>
I then set the label provider without using a global variable as
follows: <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; viewer.setLabelProvider(new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
<br>
While debugging, the eResource was correct all the time between editors
when I was expanding the nodes.<br>
<br>
I don't understand this as in the first case, the variable private
CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider &nbsp;
is not declared static so it should be a different instance for every
editor. It is is clearly not the case.<br>
<br>
I then changed updateLabelProvider() to reflect the above changes so I
could update the CustomAdapterFactoryLabelProvider from the outside:<br>
&nbsp;&nbsp;&nbsp; protected void
updateLabelProvider()<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() !=
null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged(); <br>
&nbsp;&nbsp;&nbsp; }<br>
While calling this function, the same thing happened: I got
the
wrong eResource of the LabelPRovider stored in the treeViewer global
variable. <br>
<br>
Do you have any ideas? Could be because the xxxEditorPlugin.java class
is a singleton? <br>
<br>
With this in mind, I think I should delcare my LabelProvider as not
global and all cosmetic calcualtions such as the ranges should be done
in the model implmentation without having the need to fire the provider
from the outside. <br>
<br>
Mircea<br>
<br>
<br>
<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfru74n$fs6$1@build.eclipse.org" type="cite">Mircea,
<br>
<br>
In what context does this occur?&nbsp; The editor creates a new editing
domain and loads resources into that editing domains local resource
set.&nbsp; How are objects from other editors entering the picture.&nbsp; I.e,
where is the editing domain not being updated during activation? <br>
<br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Hello Ed, <br>
<br>
&gt; I'm at a complete loss to think of how you'd get the kind of
behavior you describe.&nbsp;&nbsp; &gt; If you look at the object x and look at
the x.eResource() and x.eResource().getResourceSet(), does the resource
<br>
&gt; set correspond to the resource set of&nbsp; the editing domain in your
editor?&nbsp; If it does, then it's not an object from another editor... <br>
<br>
Precisely, I looked at the eResource().getResourceSet() for the root
object of the model. It does not to the current editing domain. My
guess is that the editing domain is not updated as I select the active
editor. <br>
<br>
Mircea <br>
<br>
<br>
Ed Merks wrote: <br>
<blockquote type="cite">Mircea, <br>
<br>
Comments below. <br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Thanks Ed, <br>
<br>
I did change the property for each class, but it doesn't solve my
problem. Perhpas it's something else: <br>
</blockquote>
Yes, I suspected that... <br>
<blockquote type="cite"><br>
For some reason, when I have two or more editors of the same type and I
switch between them, I always get the CustomAdapterFactoryLabelProvider
(or the model) of the last initialized editor in the workbech. <br>
</blockquote>
I can't imagine how that could happen. <br>
<blockquote type="cite">&nbsp; Having cycled for the first time
through all open editors, my CustomAdapterFactoryLabelProvider has
always access to the model that is represented in the last initialized
editor, indifferent of the currently selected editor. <br>
</blockquote>
Does your model instance live longer than the editor?&nbsp; The item
providers adapter factory uses its own instance as a key to locate
adapters on the instance object so unless you are sharing the adapter
factories themselves as well as the object instances, I don't see how
you'd have this kind of problem. <br>
<blockquote type="cite"><br>
I checked the editor code and have no static references to panels, tree
viewer and other objects. <br>
<br>
The problem is in the CustomAdapterFactoryLabelProvider's <br>
public String getColumnText(Object object, int columnIndex) method. <br>
The Object passed belongs to the model of the last initialized editor
and not the last selected. <br>
</blockquote>
I'm at a complete loss to think of how you'd get the kind of behavior
you describe.&nbsp;&nbsp;&nbsp; If you look at the object x and look at the
x.eResource() and x.eResource().getResourceSet(), does the resource set
correspond to the resource set of the editing domain in your editor?&nbsp;
If it does, then it's not an object from another editor... <br>
<blockquote type="cite"><br>
What could be the problem? Am I missing something? <br>
</blockquote>
I think there must be some subtlety that either your not understanding
or your not explaining... <br>
<blockquote type="cite"><br>
Thanks, <br>
<br>
Mircea <br>
<br>
<br>
<br>
Ed Merks wrote: <br>
<blockquote type="cite">Mircea, <br>
<br>
Stateful item providers is a property on the GenClass that affects the
generation of the XyzItemProviderAdapter.&nbsp; I'm not sure what you're
needing it for based on this example though... <br>
<br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Hello, <br>
<br>
I am trying to set stateful item provider adapters for the tree in an
EMF model. <br>
<br>
The way I do my initialization is: <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider); <br>
<br>
How can I set these providers as stateful and not singleton? <br>
<br>
I have tried many ways with no success. <br>
<br>
Thanks, <br>
<br>
Mircea <br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>

--------------040201020709060102060804--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to set Stateful item provider adapters (NOT singleton) [message #417683 is a reply to message #417680] Thu, 20 March 2008 22:22 Go to previous messageGo to next message
Mircea Luchian is currently offline Mircea LuchianFriend
Messages: 89
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------060603060306070908080201
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Ed,

I think there was some source of confusion. I don't use the Properties
or the Outline view and I removed their contributions. I use the Eclipse
forms based editor, with a panel on the right hand side. Please have a
look at this link: http://www.conceptualprocessengineering.com/library/
My work is based on the "Form Page" you see on the screenshot (it comes
with a ScolledPropertiesBlock class or inner class).

This is not generated by the EMF JET templates.

I think I have a workaround, and I will post further progress on the
issue if it works.

Thanks,

Mircea


Ed Merks wrote:
> Mircea,
>
> I'm quite confused by the whole thing. I.e., the outline and
> properties views display a different viewer depending on who is using
> it and each will be initialized properly without the type of problem
> you've described here. It's still entirely unclear how the view ends
> up dealing with objects from a different editing domain. To me it says
> the editing domain it's using should be changed as editors are being
> activated and likely as the input to the view is changing, but I don't
> see where that's happening in your design.
>
>
> Mircea Luchian wrote:
>> Hello Ed,
>>
>> Just to confirm: where, more precisely should I use
>> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) ?
>> Is the selected editor object or the node in the model?
>>
>> Thanks,
>>
>> Mircea
>>
>>
>> Ed Merks wrote:
>>> Mircea,
>>>
>>> It sounds like you have a view that takes selected objects as input
>>> and can retarget whatever editor has focus. Such a view should
>>> determine the adapter factory to use from the adapter factory
>>> editing domain of the selected object. Probably each time the
>>> selection changes, you should use
>>> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) to
>>> get the right editing domain and create your label/content providers
>>> from the adapter factory of that...
>>>
>>>
>>> Mircea Luchian wrote:
>>>> Hello Ed,
>>>>
>>>> Actually, the editor is initialized with the correct editing
>>>> domain. The problem is in ScrolledPropertiesBlock .
>>>>
>>>> Let me explain:
>>>>
>>>> I created a CustomAdapterFactoryLabelProvider (extends
>>>> AdapterFactoryLabelProvider ) for my tree so I can represent the
>>>> nodes with on a TableTree . The second column has some extra data
>>>> next to the nodes (a range of addresses). I do all sorts of
>>>> operations (add / remove / move / delete and set in the right
>>>> panel) that need to update the CustomAdapterFactoryLabelProvider
>>>> via the fireLabelProviderChanged() method. The Label provider does
>>>> some calculations for display purposes as well.
>>>>
>>>>
>>>> At first, I declared the CustomAdapterFactoryLabelProvider as
>>>> follows in the ScrolledPropertyBlock :
>>>> public class ScrolledPropertiesBlock extends MasterDetailsBlock
>>>> implements ISelectionChangedListener
>>>> {
>>>> protected TreeViewer treeViewer;
>>>> private CustomAdapterFactoryLabelProvider
>>>> customAdapterFactoryLabelProvider;
>>>> [...]
>>>>
>>>> public ScrolledPropertiesBlock(TreeViewer ourViewer,
>>>> RegisterfileEditor registerFileEditor)
>>>> { [...] }
>>>>
>>>> protected void createMasterPart(final IManagedForm managedForm,
>>>> Composite parent)
>>>> {
>>>> [...]
>>>> viewer.setContentProvider(new
>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>> customAdapterFactoryLabelProvider = new
>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>> [...]
>>>> }
>>>> [...]
>>>>
>>>> public void updateLabelProvider() //used to update provider
>>>> from the outside, (panels, undo, redo, etc)
>>>> {
>>>> if ( customAdapterFactoryLabelProvider != null)
>>>>
>>>> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ;
>>>> }
>>>> }
>>>>
>>>> In a debugger with a breakpoint at public String
>>>> getColumnText(Object object, int columnIndex) in
>>>> CustomAdapterFactoryLabelProvider , and go between two editors back
>>>> and forth in the workbench and expand some nodes in the tree in the
>>>> same time.
>>>> The interesting thing is that I could see that the eResource
>>>> setting at the root note of the passed object was indeed wrong. It
>>>> was pointing at the wrong file, but the editor domain was correctly
>>>> initialized in the main editor class.
>>>> This happened also when I was trying to update the label provider
>>>> via the updateLabelProvider() function from my own panels.
>>>>
>>>> I then set the label provider without using a global variable as
>>>> follows:
>>>> viewer.setContentProvider(new
>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>> viewer.setLabelProvider(new
>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
>>>>
>>>> While debugging, the eResource was correct all the time between
>>>> editors when I was expanding the nodes.
>>>>
>>>> I don't understand this as in the first case, the variable private
>>>> CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider
>>>> is not declared static so it should be a different instance for
>>>> every editor. It is is clearly not the case.
>>>>
>>>> I then changed updateLabelProvider() to reflect the above changes
>>>> so I could update the CustomAdapterFactoryLabelProvider from the
>>>> outside:
>>>> protected void updateLabelProvider()
>>>> {
>>>> if
>>>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()
>>>> != null)
>>>>
>>>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged();
>>>> }
>>>> While calling this function, the same thing happened: I got the
>>>> wrong eResource of the LabelPRovider stored in the treeViewer
>>>> global variable.
>>>>
>>>> Do you have any ideas? Could be because the xxxEditorPlugin.java
>>>> class is a singleton?
>>>>
>>>> With this in mind, I think I should delcare my LabelProvider as not
>>>> global and all cosmetic calcualtions such as the ranges should be
>>>> done in the model implmentation without having the need to fire the
>>>> provider from the outside.
>>>>
>>>> Mircea
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Ed Merks wrote:
>>>>> Mircea,
>>>>>
>>>>> In what context does this occur? The editor creates a new editing
>>>>> domain and loads resources into that editing domains local
>>>>> resource set. How are objects from other editors entering the
>>>>> picture. I.e, where is the editing domain not being updated
>>>>> during activation?
>>>>>
>>>>>
>>>>> Mircea Luchian wrote:
>>>>>> Hello Ed,
>>>>>>
>>>>>> > I'm at a complete loss to think of how you'd get the kind of
>>>>>> behavior you describe. > If you look at the object x and look
>>>>>> at the x.eResource() and x.eResource().getResourceSet(), does the
>>>>>> resource
>>>>>> > set correspond to the resource set of the editing domain in
>>>>>> your editor? If it does, then it's not an object from another
>>>>>> editor...
>>>>>>
>>>>>> Precisely, I looked at the eResource().getResourceSet() for the
>>>>>> root object of the model. It does not to the current editing
>>>>>> domain. My guess is that the editing domain is not updated as I
>>>>>> select the active editor.
>>>>>>
>>>>>> Mircea
>>>>>>
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>> Mircea,
>>>>>>>
>>>>>>> Comments below.
>>>>>>>
>>>>>>> Mircea Luchian wrote:
>>>>>>>> Thanks Ed,
>>>>>>>>
>>>>>>>> I did change the property for each class, but it doesn't solve
>>>>>>>> my problem. Perhpas it's something else:
>>>>>>> Yes, I suspected that...
>>>>>>>>
>>>>>>>> For some reason, when I have two or more editors of the same
>>>>>>>> type and I switch between them, I always get the
>>>>>>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>>>>>>> initialized editor in the workbech.
>>>>>>> I can't imagine how that could happen.
>>>>>>>> Having cycled for the first time through all open editors, my
>>>>>>>> CustomAdapterFactoryLabelProvider has always access to the
>>>>>>>> model that is represented in the last initialized editor,
>>>>>>>> indifferent of the currently selected editor.
>>>>>>> Does your model instance live longer than the editor? The item
>>>>>>> providers adapter factory uses its own instance as a key to
>>>>>>> locate adapters on the instance object so unless you are sharing
>>>>>>> the adapter factories themselves as well as the object
>>>>>>> instances, I don't see how you'd have this kind of problem.
>>>>>>>>
>>>>>>>> I checked the editor code and have no static references to
>>>>>>>> panels, tree viewer and other objects.
>>>>>>>>
>>>>>>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>>>>>>> public String getColumnText(Object object, int columnIndex)
>>>>>>>> method.
>>>>>>>> The Object passed belongs to the model of the last initialized
>>>>>>>> editor and not the last selected.
>>>>>>> I'm at a complete loss to think of how you'd get the kind of
>>>>>>> behavior you describe. If you look at the object x and look
>>>>>>> at the x.eResource() and x.eResource().getResourceSet(), does
>>>>>>> the resource set correspond to the resource set of the editing
>>>>>>> domain in your editor? If it does, then it's not an object from
>>>>>>> another editor...
>>>>>>>>
>>>>>>>> What could be the problem? Am I missing something?
>>>>>>> I think there must be some subtlety that either your not
>>>>>>> understanding or your not explaining...
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Mircea
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Ed Merks wrote:
>>>>>>>>> Mircea,
>>>>>>>>>
>>>>>>>>> Stateful item providers is a property on the GenClass that
>>>>>>>>> affects the generation of the XyzItemProviderAdapter. I'm not
>>>>>>>>> sure what you're needing it for based on this example though...
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Mircea Luchian wrote:
>>>>>>>>>> Hello,
>>>>>>>>>>
>>>>>>>>>> I am trying to set stateful item provider adapters for the
>>>>>>>>>> tree in an EMF model.
>>>>>>>>>>
>>>>>>>>>> The way I do my initialization is:
>>>>>>>>>> viewer.setContentProvider(new
>>>>>>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>>>>>>
>>>>>>>>>> customAdapterFactoryLabelProvider = new
>>>>>>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>>>>>>
>>>>>>>>>> How can I set these providers as stateful and not singleton?
>>>>>>>>>>
>>>>>>>>>> I have tried many ways with no success.
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>>
>>>>>>>>>> Mircea
>>>>
>>>
>>
>


--------------060603060306070908080201
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Ed, <br>
<br>
I think there was some source of confusion. I don't use the Properties
or the Outline view and I removed their contributions. I use the
Eclipse forms based editor, with a panel on the right hand side. Please
have a look at this link:
<a class="moz-txt-link-freetext" href="http://www.conceptualprocessengineering.com/library/">http://www.conceptualprocessengineering.com/library/</a>&nbsp; My work is based
on the "Form Page" you see on the screenshot (it comes with a
ScolledPropertiesBlock class or inner class). <br>
<br>
This is not generated by the EMF JET templates. <br>
<br>
I think I have a workaround, and I will post further progress on the
issue if it works.<br>
<br>
Thanks, <br>
<br>
Mircea<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfrummt$j3p$1@build.eclipse.org" type="cite">
<meta http-equiv="Context-Type"
content="text/html; charset=ISO-8859-1">
Mircea,<br>
<br>
I'm quite confused by the whole thing.&nbsp; I.e., the outline and
properties views display a different viewer depending on who is using
it and each will be initialized properly without the type of problem
you've described here.&nbsp;&nbsp; It's still entirely unclear how the view ends
up dealing with objects from a different editing domain. To me it says
the editing domain it's using should be changed as editors are being
activated and likely as the input to the view is changing, but I don't
see where that's happening in your design.&nbsp; <br>
<br>
<br>
Mircea Luchian wrote:
<blockquote cite="mid:frulu9$fdb$1@build.eclipse.org" type="cite">
Hello Ed, <br>
<br>
Just to confirm: where, more precisely should I use
AdapterFactoryEditingDomain.getEditingDomainFor(&lt;sele ctedObject&gt;)
? Is the selected editor object or the node in the model? <br>
<br>
Thanks, <br>
<br>
Mircea<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfrul6a$btn$1@build.eclipse.org" type="cite">
Mircea,<br>
<br>
It sounds like you have a view that takes selected objects as input and
can retarget whatever editor has focus.&nbsp; Such a view should determine
the adapter factory to use from the adapter factory editing domain of
the selected object.&nbsp;&nbsp; Probably each time the selection changes, you
should use
AdapterFactoryEditingDomain.getEditingDomainFor(&lt;sele ctedObject&gt;)
to get the right editing domain and create your label/content providers
from the adapter factory of that...<br>
<br>
<br>
Mircea Luchian wrote:
<blockquote cite="mid:fruc87$ets$1@build.eclipse.org" type="cite">Hello
Ed, <br>
<br>
Actually, the editor is initialized with the correct editing domain.
The problem is in ScrolledPropertiesBlock . <br>
<br>
Let me explain:<br>
<br>
I created a CustomAdapterFactoryLabelProvider (extends
AdapterFactoryLabelProvider )
for my tree so I can represent the
nodes with on a TableTree .
The second column has some extra data next
to the nodes (a range of addresses). I do all sorts of operations (add
/ remove / move / delete and set in the right panel) that need to
update the CustomAdapterFactoryLabelProvider via the
fireLabelProviderChanged() method. The Label provider does some
calculations for display purposes
as well.<br>
<br>
<br>
At first, I declared the CustomAdapterFactoryLabelProvider as follows
in the ScrolledPropertyBlock :<br>
public class
ScrolledPropertiesBlock extends MasterDetailsBlock implements
ISelectionChangedListener <br>
{<br>
&nbsp;&nbsp;&nbsp; protected TreeViewer treeViewer;<br>
&nbsp;&nbsp;&nbsp; private CustomAdapterFactoryLabelProvider
customAdapterFactoryLabelProvider;<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public ScrolledPropertiesBlock(TreeViewer ourViewer,
RegisterfileEditor registerFileEditor)<br>
&nbsp;&nbsp;&nbsp; { [...] }<br>
<br>
&nbsp;&nbsp;&nbsp; protected void createMasterPart(final IManagedForm managedForm,
Composite parent)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider);<br >
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; [...]<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; [...]<br>
<br>
&nbsp;&nbsp;&nbsp; public void updateLabelProvider()&nbsp; //used to update provider from
the outside, (panels, undo, redo, etc)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ( customAdapterFactoryLabelProvider != null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
customAdapterFactoryLabelProvider.fireLabelProviderChanged() ; <br>
&nbsp;&nbsp;&nbsp; }<br>
} <br>
<br>
In a debugger with a breakpoint at public String
getColumnText(Object object, int columnIndex) in
CustomAdapterFactoryLabelProvider , and go between two editors back and
forth in the workbench and expand
some nodes in the tree in the same time. <br>
The interesting thing is that I could see that the eResource setting at
the root note of the passed object was indeed wrong. It was pointing at
the wrong file, but the editor domain was correctly initialized in the
main editor class.<br>
This happened also when I was trying to update the label provider via
the updateLabelProvider() function from my own panels.<br>
<br>
I then set the label provider without using a global variable as
follows: <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory())); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; viewer.setLabelProvider(new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
<br>
While debugging, the eResource was correct all the time between editors
when I was expanding the nodes.<br>
<br>
I don't understand this as in the first case, the variable private
CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider &nbsp;
is not declared static so it should be a different instance for every
editor. It is is clearly not the case.<br>
<br>
I then changed updateLabelProvider() to reflect the above changes so I
could update the CustomAdapterFactoryLabelProvider from the outside:<br>
&nbsp;&nbsp;&nbsp; protected void
updateLabelProvider()<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der() !=
null)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged(); <br>
&nbsp;&nbsp;&nbsp; }<br>
While calling this function, the same thing happened: I got
the
wrong eResource of the LabelPRovider stored in the treeViewer global
variable. <br>
<br>
Do you have any ideas? Could be because the xxxEditorPlugin.java class
is a singleton? <br>
<br>
With this in mind, I think I should delcare my LabelProvider as not
global and all cosmetic calcualtions such as the ranges should be done
in the model implmentation without having the need to fire the provider
from the outside. <br>
<br>
Mircea<br>
<br>
<br>
<br>
<br>
<br>
Ed Merks wrote:
<blockquote cite="midfru74n$fs6$1@build.eclipse.org" type="cite">Mircea,
<br>
<br>
In what context does this occur?&nbsp; The editor creates a new editing
domain and loads resources into that editing domains local resource
set.&nbsp; How are objects from other editors entering the picture.&nbsp; I.e,
where is the editing domain not being updated during activation? <br>
<br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Hello Ed, <br>
<br>
&gt; I'm at a complete loss to think of how you'd get the kind of
behavior you describe.&nbsp;&nbsp; &gt; If you look at the object x and look at
the x.eResource() and x.eResource().getResourceSet(), does the resource
<br>
&gt; set correspond to the resource set of&nbsp; the editing domain in your
editor?&nbsp; If it does, then it's not an object from another editor... <br>
<br>
Precisely, I looked at the eResource().getResourceSet() for the root
object of the model. It does not to the current editing domain. My
guess is that the editing domain is not updated as I select the active
editor. <br>
<br>
Mircea <br>
<br>
<br>
Ed Merks wrote: <br>
<blockquote type="cite">Mircea, <br>
<br>
Comments below. <br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Thanks Ed, <br>
<br>
I did change the property for each class, but it doesn't solve my
problem. Perhpas it's something else: <br>
</blockquote>
Yes, I suspected that... <br>
<blockquote type="cite"><br>
For some reason, when I have two or more editors of the same type and I
switch between them, I always get the CustomAdapterFactoryLabelProvider
(or the model) of the last initialized editor in the workbech. <br>
</blockquote>
I can't imagine how that could happen. <br>
<blockquote type="cite">&nbsp; Having cycled for the first
time
through all open editors, my CustomAdapterFactoryLabelProvider has
always access to the model that is represented in the last initialized
editor, indifferent of the currently selected editor. <br>
</blockquote>
Does your model instance live longer than the editor?&nbsp; The item
providers adapter factory uses its own instance as a key to locate
adapters on the instance object so unless you are sharing the adapter
factories themselves as well as the object instances, I don't see how
you'd have this kind of problem. <br>
<blockquote type="cite"><br>
I checked the editor code and have no static references to panels, tree
viewer and other objects. <br>
<br>
The problem is in the CustomAdapterFactoryLabelProvider's <br>
public String getColumnText(Object object, int columnIndex) method. <br>
The Object passed belongs to the model of the last initialized editor
and not the last selected. <br>
</blockquote>
I'm at a complete loss to think of how you'd get the kind of behavior
you describe.&nbsp;&nbsp;&nbsp; If you look at the object x and look at the
x.eResource() and x.eResource().getResourceSet(), does the resource set
correspond to the resource set of the editing domain in your editor?&nbsp;
If it does, then it's not an object from another editor... <br>
<blockquote type="cite"><br>
What could be the problem? Am I missing something? <br>
</blockquote>
I think there must be some subtlety that either your not understanding
or your not explaining... <br>
<blockquote type="cite"><br>
Thanks, <br>
<br>
Mircea <br>
<br>
<br>
<br>
Ed Merks wrote: <br>
<blockquote type="cite">Mircea, <br>
<br>
Stateful item providers is a property on the GenClass that affects the
generation of the XyzItemProviderAdapter.&nbsp; I'm not sure what you're
needing it for based on this example though... <br>
<br>
<br>
Mircea Luchian wrote: <br>
<blockquote type="cite">Hello, <br>
<br>
I am trying to set stateful item provider adapters for the tree in an
EMF model. <br>
<br>
The way I do my initialization is: <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setContentProvider(new
AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customAdapterFactoryLabelProvider = new
CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewer.setLabelProvider(customAdapterFactoryLabelProvider); <br>
<br>
How can I set these providers as stateful and not singleton? <br>
<br>
I have tried many ways with no success. <br>
<br>
Thanks, <br>
<br>
Mircea <br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>

--------------060603060306070908080201--
Re: how to set Stateful item provider adapters (NOT singleton) [message #417685 is a reply to message #417683] Thu, 20 March 2008 22:51 Go to previous messageGo to next message
Steve Blass is currently offline Steve BlassFriend
Messages: 276
Registered: July 2009
Senior Member
Mircea,

There's a selection changed method in the ScrolledPropertiesBlock and/or
the details page if I remember correctly and that's probably the easiest
place to call
AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) for
the newly selected input object.

That example form editor does rely on the generated edit plugin for the
model and so I can imagine a couple of ways you might get (cough)
interesting behavior while moving between two editors in the same
debugging workbench. My question about the treeViewer and the one
that's passed into the constructor was driven by the fact that I am not
sure I did that right in the first place and so you shouldn't take too
much comfort in having followed the example there. Follow the debugger.

Hope that helps some.

-
Steve


Mircea Luchian wrote:
> Hi Ed,
>
> I think there was some source of confusion. I don't use the Properties
> or the Outline view and I removed their contributions. I use the Eclipse
> forms based editor, with a panel on the right hand side. Please have a
> look at this link: http://www.conceptualprocessengineering.com/library/
> My work is based on the "Form Page" you see on the screenshot (it comes
> with a ScolledPropertiesBlock class or inner class).
>
> This is not generated by the EMF JET templates.
>
> I think I have a workaround, and I will post further progress on the
> issue if it works.
>
> Thanks,
>
> Mircea
>
>
> Ed Merks wrote:
>> Mircea,
>>
>> I'm quite confused by the whole thing. I.e., the outline and
>> properties views display a different viewer depending on who is using
>> it and each will be initialized properly without the type of problem
>> you've described here. It's still entirely unclear how the view ends
>> up dealing with objects from a different editing domain. To me it says
>> the editing domain it's using should be changed as editors are being
>> activated and likely as the input to the view is changing, but I don't
>> see where that's happening in your design.
>>
>>
>> Mircea Luchian wrote:
>>> Hello Ed,
>>>
>>> Just to confirm: where, more precisely should I use
>>> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) ?
>>> Is the selected editor object or the node in the model?
>>>
>>> Thanks,
>>>
>>> Mircea
>>>
>>>
>>> Ed Merks wrote:
>>>> Mircea,
>>>>
>>>> It sounds like you have a view that takes selected objects as input
>>>> and can retarget whatever editor has focus. Such a view should
>>>> determine the adapter factory to use from the adapter factory
>>>> editing domain of the selected object. Probably each time the
>>>> selection changes, you should use
>>>> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) to
>>>> get the right editing domain and create your label/content providers
>>>> from the adapter factory of that...
>>>>
>>>>
>>>> Mircea Luchian wrote:
>>>>> Hello Ed,
>>>>>
>>>>> Actually, the editor is initialized with the correct editing
>>>>> domain. The problem is in ScrolledPropertiesBlock .
>>>>>
>>>>> Let me explain:
>>>>>
>>>>> I created a CustomAdapterFactoryLabelProvider (extends
>>>>> AdapterFactoryLabelProvider ) for my tree so I can represent the
>>>>> nodes with on a TableTree . The second column has some extra data
>>>>> next to the nodes (a range of addresses). I do all sorts of
>>>>> operations (add / remove / move / delete and set in the right
>>>>> panel) that need to update the CustomAdapterFactoryLabelProvider
>>>>> via the fireLabelProviderChanged() method. The Label provider does
>>>>> some calculations for display purposes as well.
>>>>>
>>>>>
>>>>> At first, I declared the CustomAdapterFactoryLabelProvider as
>>>>> follows in the ScrolledPropertyBlock :
>>>>> public class ScrolledPropertiesBlock extends MasterDetailsBlock
>>>>> implements ISelectionChangedListener
>>>>> {
>>>>> protected TreeViewer treeViewer;
>>>>> private CustomAdapterFactoryLabelProvider
>>>>> customAdapterFactoryLabelProvider;
>>>>> [...]
>>>>>
>>>>> public ScrolledPropertiesBlock(TreeViewer ourViewer,
>>>>> RegisterfileEditor registerFileEditor)
>>>>> { [...] }
>>>>>
>>>>> protected void createMasterPart(final IManagedForm managedForm,
>>>>> Composite parent)
>>>>> {
>>>>> [...]
>>>>> viewer.setContentProvider(new
>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>> customAdapterFactoryLabelProvider = new
>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>> [...]
>>>>> }
>>>>> [...]
>>>>>
>>>>> public void updateLabelProvider() //used to update provider
>>>>> from the outside, (panels, undo, redo, etc)
>>>>> {
>>>>> if ( customAdapterFactoryLabelProvider != null)
>>>>>
>>>>> customAdapterFactoryLabelProvider.fireLabelProviderChanged() ;
>>>>> }
>>>>> }
>>>>>
>>>>> In a debugger with a breakpoint at public String
>>>>> getColumnText(Object object, int columnIndex) in
>>>>> CustomAdapterFactoryLabelProvider , and go between two editors back
>>>>> and forth in the workbench and expand some nodes in the tree in the
>>>>> same time.
>>>>> The interesting thing is that I could see that the eResource
>>>>> setting at the root note of the passed object was indeed wrong. It
>>>>> was pointing at the wrong file, but the editor domain was correctly
>>>>> initialized in the main editor class.
>>>>> This happened also when I was trying to update the label provider
>>>>> via the updateLabelProvider() function from my own panels.
>>>>>
>>>>> I then set the label provider without using a global variable as
>>>>> follows:
>>>>> viewer.setContentProvider(new
>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>> viewer.setLabelProvider(new
>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory()));
>>>>>
>>>>> While debugging, the eResource was correct all the time between
>>>>> editors when I was expanding the nodes.
>>>>>
>>>>> I don't understand this as in the first case, the variable private
>>>>> CustomAdapterFactoryLabelProvider customAdapterFactoryLabelProvider
>>>>> is not declared static so it should be a different instance for
>>>>> every editor. It is is clearly not the case.
>>>>>
>>>>> I then changed updateLabelProvider() to reflect the above changes
>>>>> so I could update the CustomAdapterFactoryLabelProvider from the
>>>>> outside:
>>>>> protected void updateLabelProvider()
>>>>> {
>>>>> if
>>>>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()
>>>>> != null)
>>>>>
>>>>> ((CustomAdapterFactoryLabelProvider)treeViewer.getLabelProvi der()).fireLabelProviderChanged();
>>>>> }
>>>>> While calling this function, the same thing happened: I got the
>>>>> wrong eResource of the LabelPRovider stored in the treeViewer
>>>>> global variable.
>>>>>
>>>>> Do you have any ideas? Could be because the xxxEditorPlugin.java
>>>>> class is a singleton?
>>>>>
>>>>> With this in mind, I think I should delcare my LabelProvider as not
>>>>> global and all cosmetic calcualtions such as the ranges should be
>>>>> done in the model implmentation without having the need to fire the
>>>>> provider from the outside.
>>>>>
>>>>> Mircea
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Mircea,
>>>>>>
>>>>>> In what context does this occur? The editor creates a new editing
>>>>>> domain and loads resources into that editing domains local
>>>>>> resource set. How are objects from other editors entering the
>>>>>> picture. I.e, where is the editing domain not being updated
>>>>>> during activation?
>>>>>>
>>>>>>
>>>>>> Mircea Luchian wrote:
>>>>>>> Hello Ed,
>>>>>>>
>>>>>>> > I'm at a complete loss to think of how you'd get the kind of
>>>>>>> behavior you describe. > If you look at the object x and look
>>>>>>> at the x.eResource() and x.eResource().getResourceSet(), does the
>>>>>>> resource
>>>>>>> > set correspond to the resource set of the editing domain in
>>>>>>> your editor? If it does, then it's not an object from another
>>>>>>> editor...
>>>>>>>
>>>>>>> Precisely, I looked at the eResource().getResourceSet() for the
>>>>>>> root object of the model. It does not to the current editing
>>>>>>> domain. My guess is that the editing domain is not updated as I
>>>>>>> select the active editor.
>>>>>>>
>>>>>>> Mircea
>>>>>>>
>>>>>>>
>>>>>>> Ed Merks wrote:
>>>>>>>> Mircea,
>>>>>>>>
>>>>>>>> Comments below.
>>>>>>>>
>>>>>>>> Mircea Luchian wrote:
>>>>>>>>> Thanks Ed,
>>>>>>>>>
>>>>>>>>> I did change the property for each class, but it doesn't solve
>>>>>>>>> my problem. Perhpas it's something else:
>>>>>>>> Yes, I suspected that...
>>>>>>>>>
>>>>>>>>> For some reason, when I have two or more editors of the same
>>>>>>>>> type and I switch between them, I always get the
>>>>>>>>> CustomAdapterFactoryLabelProvider (or the model) of the last
>>>>>>>>> initialized editor in the workbech.
>>>>>>>> I can't imagine how that could happen.
>>>>>>>>> Having cycled for the first time through all open editors, my
>>>>>>>>> CustomAdapterFactoryLabelProvider has always access to the
>>>>>>>>> model that is represented in the last initialized editor,
>>>>>>>>> indifferent of the currently selected editor.
>>>>>>>> Does your model instance live longer than the editor? The item
>>>>>>>> providers adapter factory uses its own instance as a key to
>>>>>>>> locate adapters on the instance object so unless you are sharing
>>>>>>>> the adapter factories themselves as well as the object
>>>>>>>> instances, I don't see how you'd have this kind of problem.
>>>>>>>>>
>>>>>>>>> I checked the editor code and have no static references to
>>>>>>>>> panels, tree viewer and other objects.
>>>>>>>>>
>>>>>>>>> The problem is in the CustomAdapterFactoryLabelProvider's
>>>>>>>>> public String getColumnText(Object object, int columnIndex)
>>>>>>>>> method.
>>>>>>>>> The Object passed belongs to the model of the last initialized
>>>>>>>>> editor and not the last selected.
>>>>>>>> I'm at a complete loss to think of how you'd get the kind of
>>>>>>>> behavior you describe. If you look at the object x and look
>>>>>>>> at the x.eResource() and x.eResource().getResourceSet(), does
>>>>>>>> the resource set correspond to the resource set of the editing
>>>>>>>> domain in your editor? If it does, then it's not an object from
>>>>>>>> another editor...
>>>>>>>>>
>>>>>>>>> What could be the problem? Am I missing something?
>>>>>>>> I think there must be some subtlety that either your not
>>>>>>>> understanding or your not explaining...
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>> Mircea
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Ed Merks wrote:
>>>>>>>>>> Mircea,
>>>>>>>>>>
>>>>>>>>>> Stateful item providers is a property on the GenClass that
>>>>>>>>>> affects the generation of the XyzItemProviderAdapter. I'm not
>>>>>>>>>> sure what you're needing it for based on this example though...
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Mircea Luchian wrote:
>>>>>>>>>>> Hello,
>>>>>>>>>>>
>>>>>>>>>>> I am trying to set stateful item provider adapters for the
>>>>>>>>>>> tree in an EMF model.
>>>>>>>>>>>
>>>>>>>>>>> The way I do my initialization is:
>>>>>>>>>>> viewer.setContentProvider(new
>>>>>>>>>>> AdapterFactoryContentProvider(registerFileEditor.getAdapterF actory()));
>>>>>>>>>>>
>>>>>>>>>>> customAdapterFactoryLabelProvider = new
>>>>>>>>>>> CustomAdapterFactoryLabelProvider(registerFileEditor.getAdap terFactory());
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> viewer.setLabelProvider(customAdapterFactoryLabelProvider);
>>>>>>>>>>>
>>>>>>>>>>> How can I set these providers as stateful and not singleton?
>>>>>>>>>>>
>>>>>>>>>>> I have tried many ways with no success.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>>
>>>>>>>>>>> Mircea
>>>>>
>>>>
>>>
>>
>
Re: how to set Stateful item provider adapters (NOT singleton) [message #417695 is a reply to message #417685] Fri, 21 March 2008 14:52 Go to previous messageGo to next message
Mircea Luchian is currently offline Mircea LuchianFriend
Messages: 89
Registered: July 2009
Member
Hi Steve,

I tried your solution and still doesn't work.

However, I found a workaround which involves in attaching extra
variables to the model that are responsible only for the label provider
display.
Instead of letting the label provider do the display calculation based
on the model and then update it, I simply display the values I wish and
then calculate them directly in the model implementation classes. This
takes care of the problem as the Label provider is not a global variable
and any auto calculation I do, it will be done in the model, not the
provider itself. I'm not obliged to call the label provider from
anywhere and in addition, there is no fireProviderChanged() called.
Calling this method was causing some very small flicker in the tree.

I am, however clueless about the solution to the original problem.

Thanks,

Mircea


Steve Blass wrote:
> Mircea,
>
> There's a selection changed method in the ScrolledPropertiesBlock
> and/or the details page if I remember correctly and that's probably
> the easiest place to call
> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) for
> the newly selected input object.
>
> That example form editor does rely on the generated edit plugin for
> the model and so I can imagine a couple of ways you might get (cough)
> interesting behavior while moving between two editors in the same
> debugging workbench. My question about the treeViewer and the one
> that's passed into the constructor was driven by the fact that I am
> not sure I did that right in the first place and so you shouldn't take
> too much comfort in having followed the example there. Follow the
> debugger.
>
> Hope that helps some.
>
> -
> Steve
>
Re: how to set Stateful item provider adapters (NOT singleton) [message #417696 is a reply to message #417695] Fri, 21 March 2008 15:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mircea,

If you can package up the original problem as exported projects that I
can import to see the problem in action, I'll have a look at that, if
you like. You can send it to merks at ca dot ibm dot com if you don't
want to broadcast it to the newsgroup.


Mircea Luchian wrote:
> Hi Steve,
>
> I tried your solution and still doesn't work.
>
> However, I found a workaround which involves in attaching extra
> variables to the model that are responsible only for the label
> provider display.
> Instead of letting the label provider do the display calculation based
> on the model and then update it, I simply display the values I wish
> and then calculate them directly in the model implementation classes.
> This takes care of the problem as the Label provider is not a global
> variable and any auto calculation I do, it will be done in the model,
> not the provider itself. I'm not obliged to call the label provider
> from anywhere and in addition, there is no fireProviderChanged()
> called. Calling this method was causing some very small flicker in the
> tree.
>
> I am, however clueless about the solution to the original problem.
>
> Thanks,
>
> Mircea
>
>
> Steve Blass wrote:
>> Mircea,
>>
>> There's a selection changed method in the ScrolledPropertiesBlock
>> and/or the details page if I remember correctly and that's probably
>> the easiest place to call
>> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >) for
>> the newly selected input object.
>>
>> That example form editor does rely on the generated edit plugin for
>> the model and so I can imagine a couple of ways you might get (cough)
>> interesting behavior while moving between two editors in the same
>> debugging workbench. My question about the treeViewer and the one
>> that's passed into the constructor was driven by the fact that I am
>> not sure I did that right in the first place and so you shouldn't
>> take too much comfort in having followed the example there. Follow
>> the debugger.
>>
>> Hope that helps some.
>>
>> -
>> Steve
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: how to set Stateful item provider adapters (NOT singleton) [message #417700 is a reply to message #417696] Fri, 21 March 2008 16:57 Go to previous message
Mircea Luchian is currently offline Mircea LuchianFriend
Messages: 89
Registered: July 2009
Member
Thanks Ed and Steve,

For my original issue, I discovered a problem with my action listeners
that were used to update the label provider from other classes. I
somehow got the reference of the wrong custom action listener (I was
overwriting it when a new editor was created); the listener called the
label provider update function for the wrong editor afterwards.

Sorry for the trouble,

Mircea


Ed Merks wrote:
> Mircea,
>
> If you can package up the original problem as exported projects that I
> can import to see the problem in action, I'll have a look at that, if
> you like. You can send it to merks at ca dot ibm dot com if you don't
> want to broadcast it to the newsgroup.
>
>
> Mircea Luchian wrote:
>> Hi Steve,
>>
>> I tried your solution and still doesn't work.
>>
>> However, I found a workaround which involves in attaching extra
>> variables to the model that are responsible only for the label
>> provider display.
>> Instead of letting the label provider do the display calculation
>> based on the model and then update it, I simply display the values I
>> wish and then calculate them directly in the model implementation
>> classes. This takes care of the problem as the Label provider is not
>> a global variable and any auto calculation I do, it will be done in
>> the model, not the provider itself. I'm not obliged to call the label
>> provider from anywhere and in addition, there is no
>> fireProviderChanged() called. Calling this method was causing some
>> very small flicker in the tree.
>>
>> I am, however clueless about the solution to the original problem.
>>
>> Thanks,
>>
>> Mircea
>>
>>
>> Steve Blass wrote:
>>> Mircea,
>>>
>>> There's a selection changed method in the ScrolledPropertiesBlock
>>> and/or the details page if I remember correctly and that's probably
>>> the easiest place to call
>>> AdapterFactoryEditingDomain.getEditingDomainFor(<selectedObject >)
>>> for the newly selected input object.
>>>
>>> That example form editor does rely on the generated edit plugin for
>>> the model and so I can imagine a couple of ways you might get
>>> (cough) interesting behavior while moving between two editors in the
>>> same debugging workbench. My question about the treeViewer and the
>>> one that's passed into the constructor was driven by the fact that I
>>> am not sure I did that right in the first place and so you shouldn't
>>> take too much comfort in having followed the example there. Follow
>>> the debugger.
>>>
>>> Hope that helps some.
>>>
>>> -
>>> Steve
>>>
Previous Topic:using ecore-model in eclipse view
Next Topic:NullPointerException @ getEPackage while loading EMF model
Goto Forum:
  


Current Time: Fri Apr 26 22:09:20 GMT 2024

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

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

Back to the top