Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Refreshing after a Preference change
Refreshing after a Preference change [message #137728] Fri, 11 June 2004 05:39 Go to next message
Eclipse UserFriend
Originally posted by: bbdaffy.hotmail.com

Hi,

I have a preference in the PreferenceStore which denotes the background
colour of my Figures. When I change this preference value, I want the
Figures to be repainted in the new colour.

I understand that the proper way to do it is to use the
addPropertyChangeListener(IPropertyChangeListener) method of the
PreferenceStore. However, is it better to add the GraphicalEditor as the
listener or add each EditPart (upon activation) as a listener?

I add the GraphicalEditor as the listener, how do I trigger all the
Figures to be repainted?

Thanks.

Regards,
Lee
Re: Refreshing after a Preference change [message #137765 is a reply to message #137728] Fri, 11 June 2004 11:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

Hi,

> I have a preference in the PreferenceStore which denotes the backgroun=
d
> colour of my Figures. When I change this preference value, I want the
> Figures to be repainted in the new colour.
>
> I understand that the proper way to do it is to use the
> addPropertyChangeListener(IPropertyChangeListener) method of the
> PreferenceStore.

Thank you for giving me this very good idea, personnaly I would have don=
e =

smthg stupid there :D

> However, is it better to add the GraphicalEditor as the
> listener or add each EditPart (upon activation) as a listener?

I think that as the PreferenceStore stores persistent data which must be=
=

saved and restored between each editing session and as the view depends =
on =

the state of this object, the PreferenceStore is part your model like an=
y =

other model object and so it should be treated the same way. Moreover, n=
ot =

necessarily all figures depends on the state of the PreferenceStore, so =
=

maybe it is not necessary to add the listener for all the EditParts (but=
I =

would do so anyway) but only for the ones for which the figures depends =
on =

the preferences.
So I think it is more simple to add each EditPart which depends on the =

preferences (and maybe the others too for the future) as a listener in i=
ts =

activate method. I may be wrong, this is just what I would do.

> I add the GraphicalEditor as the listener, how do I trigger all the
> Figures to be repainted?

You can get the GraphicalViewer from there, and then you can get a Map =

between the model objects and the EditParts (model objs -> editparts) by=
=

calling getEditPartRegistry on the graphical viewer. Then you can get th=
e =

Collection of the values stored in this registry by calling Map.values()=
=

and iterate over this Collection to get each EditPart and call the =

refreshVisual method on each of them.
But be sure there is not two EditParts with the same model object in you=
r =

graphical viewer (bad idea but I did it one time and I had lots of =

problems) because if it is so when you iterate over the collection of =

values in the Map, you will miss one of them because there can be only o=
ne =

value (editpart) by key (model object) in this map.

r=E9gis

-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Re: Refreshing after a Preference change [message #137839 is a reply to message #137728] Fri, 11 June 2004 18:40 Go to previous messageGo to next message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
"Nicole" <bbdaffy@hotmail.com> wrote in message
news:cabgj0$4a1$1@eclipse.org...
> Hi,
>
> I have a preference in the PreferenceStore which denotes the background
> colour of my Figures. When I change this preference value, I want the
> Figures to be repainted in the new colour.
>
> I understand that the proper way to do it is to use the
> addPropertyChangeListener(IPropertyChangeListener) method of the
> PreferenceStore. However, is it better to add the GraphicalEditor as the
> listener or add each EditPart (upon activation) as a listener?

It's your call. However, it's probably not a good idea to have every
EditPart listen to the preference store. With a few editors open, you can
easily have the number of listeners be in
hundreds, if not thousands. Plus, with this approach, you will also have to
distribute a reference to the preference store to every EditPart (or provide
some other way for all of them to get to it).

>
> I add the GraphicalEditor as the listener, how do I trigger all the
> Figures to be repainted?

You need to refresh the edit parts in the graphical viewer, so that they can
set the new Color on their figures.

The palette does exactly this. PaletteViewer adds a listener to
PaletteViewerPreferences, and refreshes all
the editparts in the palette when a property changes. Look at
PaletteViewer.PreferenceListener.

>
> Thanks.
>
> Regards,
> Lee
>
Re: Refreshing after a Preference change [message #137875 is a reply to message #137839] Fri, 11 June 2004 20:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

So I was completly wrong.
Sorry Lee.


On Fri, 11 Jun 2004 14:40:47 -0400, Pratik Shah <ppshah@us.ibm.com> wrot=
e:

>
> "Nicole" <bbdaffy@hotmail.com> wrote in message
> news:cabgj0$4a1$1@eclipse.org...
>> Hi,
>>
>> I have a preference in the PreferenceStore which denotes the backgrou=
nd
>> colour of my Figures. When I change this preference value, I want the=

>> Figures to be repainted in the new colour.
>>
>> I understand that the proper way to do it is to use the
>> addPropertyChangeListener(IPropertyChangeListener) method of the
>> PreferenceStore. However, is it better to add the GraphicalEditor as =
the
>> listener or add each EditPart (upon activation) as a listener?
>
> It's your call. However, it's probably not a good idea to have every
> EditPart listen to the preference store. With a few editors open, you=
=

> can
> easily have the number of listeners be in
> hundreds, if not thousands. Plus, with this approach, you will also =

> have to
> distribute a reference to the preference store to every EditPart (or =

> provide
> some other way for all of them to get to it).
>
>>
>> I add the GraphicalEditor as the listener, how do I trigger all the
>> Figures to be repainted?
>
> You need to refresh the edit parts in the graphical viewer, so that th=
ey =

> can
> set the new Color on their figures.
>
> The palette does exactly this. PaletteViewer adds a listener to
> PaletteViewerPreferences, and refreshes all
> the editparts in the palette when a property changes. Look at
> PaletteViewer.PreferenceListener.
>
>>
>> Thanks.
>>
>> Regards,
>> Lee
>>
>
>



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Re: Refreshing after a Preference change [message #137964 is a reply to message #137875] Mon, 14 June 2004 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gaslade.yahoo.com

I think it is possibly a case by case decision. There are already
thousands of listeners and events getting fired off around the eclipse
workbench world so there is nothing new here and I don't think it is
necessarily wrong.
If you have a mixture of edit parts in your editor and some need to
listen to a preference and some do not then I think it is not
necessarily a bad thing to have just those who are interested in the
preference, listening, and those who are not, do not listen. Using this
approach does mean there is a little more management involved.... when
the edit part is disposed it must remember to unregister itself as a
prefernce listener.
Possibly in your case you need to update every figure and so every
corresponding edit part needs to listen.... in this case it may make
more sense to have a single listener who then tells all the edit parts
to refresh. I have a case where it makes more sense to have individual
edit parts listening and this is what I have done.

So régis, you be wrong in this particular senario but I don't think you
are wrong in all cases.


Guy

rlemaigr@ulb.ac.be wrote:

> So I was completly wrong.
> Sorry Lee.
>
>
> On Fri, 11 Jun 2004 14:40:47 -0400, Pratik Shah <ppshah@us.ibm.com> wrote:
>
>>
>> "Nicole" <bbdaffy@hotmail.com> wrote in message
>> news:cabgj0$4a1$1@eclipse.org...
>>
>>> Hi,
>>>
>>> I have a preference in the PreferenceStore which denotes the background
>>> colour of my Figures. When I change this preference value, I want the
>>> Figures to be repainted in the new colour.
>>>
>>> I understand that the proper way to do it is to use the
>>> addPropertyChangeListener(IPropertyChangeListener) method of the
>>> PreferenceStore. However, is it better to add the GraphicalEditor as the
>>> listener or add each EditPart (upon activation) as a listener?
>>
>>
>> It's your call. However, it's probably not a good idea to have every
>> EditPart listen to the preference store. With a few editors open,
>> you can
>> easily have the number of listeners be in
>> hundreds, if not thousands. Plus, with this approach, you will also
>> have to
>> distribute a reference to the preference store to every EditPart (or
>> provide
>> some other way for all of them to get to it).
>>
>>>
>>> I add the GraphicalEditor as the listener, how do I trigger all the
>>> Figures to be repainted?
>>
>>
>> You need to refresh the edit parts in the graphical viewer, so that
>> they can
>> set the new Color on their figures.
>>
>> The palette does exactly this. PaletteViewer adds a listener to
>> PaletteViewerPreferences, and refreshes all
>> the editparts in the palette when a property changes. Look at
>> PaletteViewer.PreferenceListener.
>>
>>>
>>> Thanks.
>>>
>>> Regards,
>>> Lee
>>>
>>
>>
>
>
>
Re: Refreshing after a Preference change [message #138096 is a reply to message #137964] Mon, 14 June 2004 20:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

Ok, thank you for your explanations !

r=E9gis

On Mon, 14 Jun 2004 09:00:33 -0400, Guy Slade <gaslade@yahoo.com> wrote:=


> I think it is possibly a case by case decision. There are already =

> thousands of listeners and events getting fired off around the eclipse=
=

> workbench world so there is nothing new here and I don't think it is =

> necessarily wrong.
> If you have a mixture of edit parts in your editor and some need to =

> listen to a preference and some do not then I think it is not =

> necessarily a bad thing to have just those who are interested in the =

> preference, listening, and those who are not, do not listen. Using thi=
s =

> approach does mean there is a little more management involved.... when=
=

> the edit part is disposed it must remember to unregister itself as a =

> prefernce listener.
> Possibly in your case you need to update every figure and so every =

> corresponding edit part needs to listen.... in this case it may make =

> more sense to have a single listener who then tells all the edit parts=
=

> to refresh. I have a case where it makes more sense to have individual=
=

> edit parts listening and this is what I have done.
>
> So r=E9gis, you be wrong in this particular senario but I don't think =
you =

> are wrong in all cases.
>
>
> Guy
>
> rlemaigr@ulb.ac.be wrote:
>
>> So I was completly wrong.
>> Sorry Lee.
>> On Fri, 11 Jun 2004 14:40:47 -0400, Pratik Shah <ppshah@us.ibm.com>=
=

>> wrote:
>>
>>>
>>> "Nicole" <bbdaffy@hotmail.com> wrote in message
>>> news:cabgj0$4a1$1@eclipse.org...
>>>
>>>> Hi,
>>>>
>>>> I have a preference in the PreferenceStore which denotes the =

>>>> background
>>>> colour of my Figures. When I change this preference value, I want t=
he
>>>> Figures to be repainted in the new colour.
>>>>
>>>> I understand that the proper way to do it is to use the
>>>> addPropertyChangeListener(IPropertyChangeListener) method of the
>>>> PreferenceStore. However, is it better to add the GraphicalEditor a=
s =

>>>> the
>>>> listener or add each EditPart (upon activation) as a listener?
>>>
>>>
>>> It's your call. However, it's probably not a good idea to have ever=
y
>>> EditPart listen to the preference store. With a few editors open, =

>>> you can
>>> easily have the number of listeners be in
>>> hundreds, if not thousands. Plus, with this approach, you will also=
=

>>> have to
>>> distribute a reference to the preference store to every EditPart (or=
=

>>> provide
>>> some other way for all of them to get to it).
>>>
>>>>
>>>> I add the GraphicalEditor as the listener, how do I trigger all the=

>>>> Figures to be repainted?
>>>
>>>
>>> You need to refresh the edit parts in the graphical viewer, so that =
=

>>> they can
>>> set the new Color on their figures.
>>>
>>> The palette does exactly this. PaletteViewer adds a listener to
>>> PaletteViewerPreferences, and refreshes all
>>> the editparts in the palette when a property changes. Look at
>>> PaletteViewer.PreferenceListener.
>>>
>>>>
>>>> Thanks.
>>>>
>>>> Regards,
>>>> Lee
>>>>
>>>
>>>
>>
>



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Re: Refreshing after a Preference change [message #139222 is a reply to message #138096] Tue, 22 June 2004 08:08 Go to previous message
Eclipse UserFriend
Originally posted by: bbdaffy.hotmail.com

Hi,

Yup, Thanks for all the advices. :)

Regards, Lee


rlemaigr@ulb.ac.be wrote:

> Ok, thank you for your explanations !

> régis

> On Mon, 14 Jun 2004 09:00:33 -0400, Guy Slade <gaslade@yahoo.com> wrote:

> > I think it is possibly a case by case decision. There are already
> > thousands of listeners and events getting fired off around the eclipse
> > workbench world so there is nothing new here and I don't think it is
> > necessarily wrong.
> > If you have a mixture of edit parts in your editor and some need to
> > listen to a preference and some do not then I think it is not
> > necessarily a bad thing to have just those who are interested in the
> > preference, listening, and those who are not, do not listen. Using this
> > approach does mean there is a little more management involved.... when
> > the edit part is disposed it must remember to unregister itself as a
> > prefernce listener.
> > Possibly in your case you need to update every figure and so every
> > corresponding edit part needs to listen.... in this case it may make
> > more sense to have a single listener who then tells all the edit parts
> > to refresh. I have a case where it makes more sense to have individual
> > edit parts listening and this is what I have done.
> >
> > So régis, you be wrong in this particular senario but I don't think you
> > are wrong in all cases.
> >
> >
> > Guy
> >
> > rlemaigr@ulb.ac.be wrote:
> >
> >> So I was completly wrong.
> >> Sorry Lee.
> >> On Fri, 11 Jun 2004 14:40:47 -0400, Pratik Shah <ppshah@us.ibm.com>
> >> wrote:
> >>
> >>>
> >>> "Nicole" <bbdaffy@hotmail.com> wrote in message
> >>> news:cabgj0$4a1$1@eclipse.org...
> >>>
> >>>> Hi,
> >>>>
> >>>> I have a preference in the PreferenceStore which denotes the
> >>>> background
> >>>> colour of my Figures. When I change this preference value, I want the
> >>>> Figures to be repainted in the new colour.
> >>>>
> >>>> I understand that the proper way to do it is to use the
> >>>> addPropertyChangeListener(IPropertyChangeListener) method of the
> >>>> PreferenceStore. However, is it better to add the GraphicalEditor as
> >>>> the
> >>>> listener or add each EditPart (upon activation) as a listener?
> >>>
> >>>
> >>> It's your call. However, it's probably not a good idea to have every
> >>> EditPart listen to the preference store. With a few editors open,
> >>> you can
> >>> easily have the number of listeners be in
> >>> hundreds, if not thousands. Plus, with this approach, you will also
> >>> have to
> >>> distribute a reference to the preference store to every EditPart (or
> >>> provide
> >>> some other way for all of them to get to it).
> >>>
> >>>>
> >>>> I add the GraphicalEditor as the listener, how do I trigger all the
> >>>> Figures to be repainted?
> >>>
> >>>
> >>> You need to refresh the edit parts in the graphical viewer, so that
> >>> they can
> >>> set the new Color on their figures.
> >>>
> >>> The palette does exactly this. PaletteViewer adds a listener to
> >>> PaletteViewerPreferences, and refreshes all
> >>> the editparts in the palette when a property changes. Look at
> >>> PaletteViewer.PreferenceListener.
> >>>
> >>>>
> >>>> Thanks.
> >>>>
> >>>> Regards,
> >>>> Lee
> >>>>
> >>>
> >>>
> >>
> >
Previous Topic:DND on text editor
Next Topic:Draw2d: Text figure with defined width and flexible height
Goto Forum:
  


Current Time: Fri Apr 26 17:17:59 GMT 2024

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

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

Back to the top