Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Changing Palette Icons programmatically
Changing Palette Icons programmatically [message #658462] Tue, 08 March 2011 15:40 Go to next message
Dave is currently offline DaveFriend
Messages: 5
Registered: March 2011
Junior Member
Hi,

I want to use two different styles of icons in my gmf palette. So I need to change the icon of a tool during runtime depending on the user settings (preference page). Is there a way to do this?

Thanks in advance
Re: Changing Palette Icons programmatically [message #658636 is a reply to message #658462] Wed, 09 March 2011 10:56 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 08-03-11 16:40, comander@flippancy.de wrote:
> Hi,
>
> I want to use two different styles of icons in my gmf palette. So I need
> to change the icon of a tool during runtime depending on the user
> settings (preference page). Is there a way to do this?


Yes, this should be possible.

You could consider reloading your palette with different tool entries,
when the preference changes. (See how it's initally loaded in your
DiagramEditor class, method createPaletteRoot(PaletteRoot
existingPaletteRoot)

You would create a customized ToolEntry (Which extends PaletteEntry) and
override getSmallIcon() / getLargeIcon().

ToolEntry classes are return from the generated paletteFactory.

Have fun!
Christophe
Re: Changing Palette Icons programmatically [message #661098 is a reply to message #658636] Wed, 23 March 2011 07:39 Go to previous messageGo to next message
Dave is currently offline DaveFriend
Messages: 5
Registered: March 2011
Junior Member
Thanks for the hint.
I managed to find the related source code but unfortunatly I don't know how to change it, since my code is generated with GMF and is regenerated regulary. So I thought I can use an extension somewhere to override the existing code but that wasn't successful either. Do you have an idea how to change the generated code for a palette entries?


Thank you very much indeed!


Cheers
Dave
Re: Changing Palette Icons programmatically [message #661106 is a reply to message #661098] Wed, 23 March 2011 08:06 Go to previous messageGo to next message
Mariot Chauvin is currently offline Mariot ChauvinFriend
Messages: 174
Registered: July 2009
Senior Member
Hi Dave,

Comments below.

Le 23/03/2011 08:39, Dave a écrit :
> Thanks for the hint.
> I managed to find the related source code but unfortunatly I don't know
> how to change it, since my code is generated with GMF and is regenerated
> regulary. So I thought I can use an extension somewhere to override the
> existing code but that wasn't successful either. Do you have an idea how
> to change the generated code for a palette entries?
>
>
> Thank you very much indeed!
>
>
> Cheers
> Dave

You have third options :

- Use the palette provider extension point, see
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. gmf.doc/tutorials/diagram/paletteConfigurationTutorial.html

- Modify the templates, see
http://www.bonitasoft.org/blog/eclipse/customize-your-gmf-ed itor-by-customizing-templates/

- Mark the method you modified as not generated (or the method when your
instantiate your own custom implementation of PaletteFactory)

Regards,

Mariot
--
Mariot Chauvin @ Obeo

Blog : http://mariot-thoughts.blogspot.com
Twitter :http://twitter.com/mchv
Professional support : http://obeo.fr/pages/maintenance-and-support/
Re: Changing Palette Icons programmatically [message #661213 is a reply to message #661098] Wed, 23 March 2011 15:14 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
inlined....

On 23-03-11 00:39, Dave wrote:
> Thanks for the hint.
> I managed to find the related source code but unfortunatly I don't know
> how to change it, since my code is generated with GMF and is regenerated
> regulary. So I thought I can use an extension somewhere to override the
> existing code but that wasn't successful either. Do you have an idea how
> to change the generated code for a palette entries?
>
I am not sure why you want to override the palettefactory. What you
really want (At least, if I understand from the original post), is to
subscribe to preference changes, and then reload the palette right? So
from the palette factory, you simply re-use the parts which make sense
like this:

I found this comment in the EditingDomain.setPaletteRoot(..)

/**
* Sets the PalatteRoot for this EditDomain. If the EditDomain already
knows
* about a PaletteViewer, this root will be set into the palette viewer
* also. Loads the default Tool after the root has been set.
* <p>
* It is recommended that the palette root not be set multiple times. Some
* components (such as the PaletteCustomizerDialog for the PaletteViewer)
* might still hold on to the old root. If the input has changed or
needs to
* be refreshed, just remove all the children from the root and add the new
* ones.
*
* @param root
* the palette's root
*/

so, obviously not a good idea to reset the root.
You would need to play (Add/remove) with this:

this.getEditDomain().getPaletteViewer().getPaletteRoot().get Children()

Please let us know the result!


>
> Thank you very much indeed!
>
>
> Cheers
> Dave
Re: Changing Palette Icons programmatically [message #661238 is a reply to message #661213] Wed, 23 March 2011 16:19 Go to previous messageGo to next message
Dave is currently offline DaveFriend
Messages: 5
Registered: March 2011
Junior Member
Hi guys

thanks for all your ideas.
Since I only want to change the shape and color of an icon I don't want to change the whole palette implementation.

As Mariot suggested I used the PaletteFactory.xpt and extended some functions a bit. I basically addd a function call, which returns the currently selected icon theme in the preference page.

So during code generation this function call gets also genereted in the java files and I only need to add one dependency to the package which contains the function call implementation.

Here the xpt excerpt:

«DEFINE setSmallImage(toolVarName : String, palette : gmfgen::Palette) FOR gmfgen::EntryBase-»
«IF null <> smallIconPath-»
«toolVarName».setSmallIcon(«palette.activatorFQN()».findImageDescriptor("«smallIconPath»"+AbstractImage.getColorSchemeFromSetting()+".png"));«EXPAND xpt::Common::nonNLS»
«ELSEIF not (Sequence { self })[gmfgen::ToolEntry].elements->isEmpty()-»
«LET self.oclAsType(gmfgen::ToolEntry) AS toolEntry-»
«toolVarName».setSmallIcon(«palette.diagram.getElementTypesQualifiedClassName()».getImageDescriptor(«EXPAND xpt::providers::ElementTypes::accessElementType FOR toolEntry.elements->first()»));
«ENDLET-»
«ENDIF-»
«ENDDEFINE»


AbstractImage.getColorSchemeFromSetting() returns a string with currently selected icon style.

The only disadvantage with this approach is that I have to restart my editor window to see the newly loaded images. Do you guys have an idea how to master this last task?


Thanks for all your help!
Dave

Re: Changing Palette Icons programmatically [message #661277 is a reply to message #661238] Wed, 23 March 2011 20:08 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
inline....

On 23-03-11 17:20, Dave wrote:
> Hi guys
>
> thanks for all your ideas.
> Since I only want to change the shape and color of an icon I don't want
> to change the whole palette implementation.
I just found below in PaletteViewer Class It already listens to the
preferences and update the parts by calling refreshAllEditParts()

So you could do the same in your prefernece listener. You can get access
to the PaletteRoot, through the Editor with
xxxDiagramEditor().getEditDomain().getPaletteViewer().getPal etteRoot()

You can get the editor, through the workbench... this will work for sure.


****

private class PreferenceListener implements PropertyChangeListener {
/**
* @see
java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt) {
String property = evt.getPropertyName();
EditPart root = getRootEditPart().getContents();
if (property.equals(PaletteViewerPreferences.PREFERENCE_FONT)) {
updateFont();
refreshAllEditParts(root);
} else if (property
.equals(PaletteViewerPreferences.PREFERENCE_LAYOUT)
|| property
.equals(PaletteViewerPreferences.PREFERENCE_AUTO_COLLAPSE)
|| property
.equals(DefaultPaletteViewerPreferences
.convertLayoutToPreferenceName(getPaletteViewerPreferences()
.getLayoutSetting()))) {
refreshAllEditParts(root);
}
}

private void refreshAllEditParts(EditPart part) {
part.refresh();
List children = part.getChildren();
for (Iterator iter = children.iterator(); iter.hasNext();) {
EditPart child = (EditPart) iter.next();
refreshAllEditParts(child);
}
}
}



> As Mariot suggested I used the PaletteFactory.xpt and extended some
> functions a bit. I basically addd a function call, which returns the
> currently selected icon theme in the preference page.
> So during code generation this function call gets also genereted in the
> java files and I only need to add one dependency to the package which
> contains the function call implementation.
>
> Here the xpt excerpt:
>
>
> «DEFINE setSmallImage(toolVarName : String, palette : gmfgen::Palette)
> FOR gmfgen::EntryBase-»
> «IF null <> smallIconPath-»
> «toolVarName».setSmallIcon(«palette.activatorFQN()».find ImageDescriptor( "«smallIconPath»"+AbstractImage.getColorSchemeFromSetting()+ ".png"));«EXPAND
> xpt::Common::nonNLS»
> «ELSEIF not (Sequence { self })[gmfgen::ToolEntry].elements->isEmpty()-»
> «LET self.oclAsType(gmfgen::ToolEntry) AS toolEntry-»
> «toolVarName».setSmallIcon(«palette.diagram.getElementTyp esQualifiedClassName()».getImageDescriptor(«EXPAND
> xpt::providers::ElementTypes::accessElementType FOR
> toolEntry.elements->first()»));
> «ENDLET-»
> «ENDIF-»
> «ENDDEFINE»
>
>
> AbstractImage.getColorSchemeFromSetting() returns a string with
> currently selected icon style.
>
> The only disadvantage with this approach is that I have to restart my
> editor window to see the newly loaded images. Do you guys have an idea
> how to master this last task?
>
>
> Thanks for all your help!
> Dave
>
>
Re: Changing Palette Icons programmatically [message #665857 is a reply to message #661277] Sun, 17 April 2011 09:56 Go to previous message
Dave is currently offline DaveFriend
Messages: 5
Registered: March 2011
Junior Member
Hi,

sorry for the continued delay in my message.

I was playing around with PaletteViewer and PaletteRoot and it seems the palette is refreshed but eclipse is using cached images. So there is no visible change. Can you confirm this?


Since I need to refresh the my editor edit part images as well I thought I can write a global class for doing that. When I close my editor and restart it again, I see the changed images in both palette and editor. Any ideas on how to accomplish that in a simple class programmatically?


Thank you very much indeed
Dave
Previous Topic:Draw on editor canvas
Next Topic:External labels on node - question on positioning
Goto Forum:
  


Current Time: Fri Mar 29 02:25:33 GMT 2024

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

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

Back to the top