Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Palette-Items Customize before/at Editor start
Palette-Items Customize before/at Editor start [message #1027668] Wed, 27 March 2013 08:54 Go to next message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member

I'm trying to build some editor and it needs to be very flexible/adjustable.
So i know which Elements i get in the Palette recently at Start or at run-time of my Editor. My idea is i load which Element-type i have from a File/Database and show all this Elements in my Palette (and can use them).
Something like that:
at the beginning i have just a Task,Role,Output,Input and Tool. So the User can have a possibility to add some another Elements to Editor at the run-time.
At this time i can just predefine my Elements and can show and use them in my Palette

i have a question, is it possible to "load" all Elements to the Palette at Start of the Editor? If it is possible can somebody give me an Idea how i should try? or much the better a code-snippet?

and another question is, is it possible to add .svg icons to my Objects/Elements? With .png/.jpg i have no problems but is it possible to add svg in Graphiti? (maybe with Apache Batik? I starting to try this, but it doesn't works yet)

I would be veeeery happy!I'm trying to solve this problem since 2 week's Sad

Re: Palette-Items Customize before/at Editor start [message #1028732 is a reply to message #1027668] Thu, 28 March 2013 16:59 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
I read the content of an existing (template) model and create palette
entries so you can drag'n drop them into new models. You essentially
read the model using normal API and create an appropriate palette
structure. I've pasted code from my tool behavior provider below,
hopefully you'll be able to understand the structure even though there's
a lot of noise...


public IPaletteCompartmentEntry[] getPalette() {
IPaletteCompartmentEntry[] superCompartments = super.getPalette();
List<IPaletteCompartmentEntry> libraryCompartments =
List<IPaletteCompartmentEntry> allCompartments = new
return allCompartments.toArray(new

private Collection<EObject> defaultLibraryContainers = null;

private Collection<EObject> getDefaultLibraryContainers() {
if (defaultLibraryContainers == null) {

EObject libraryContainer =
"Default library", null);

EObject actor1 =
"Input1Output1Actor", libraryContainer);
modelFacade.createPort(ModelFacade.PortKind.INPUT, "input", actor1);
modelFacade.createPort(ModelFacade.PortKind.OUTPUT, "output",

EObject actor2 =
"Input2Output1Actor", libraryContainer);
modelFacade.createPort(ModelFacade.PortKind.INPUT, "input1", actor2);
modelFacade.createPort(ModelFacade.PortKind.INPUT, "input2", actor2);
modelFacade.createPort(ModelFacade.PortKind.OUTPUT, "output",

defaultLibraryContainers = new ArrayList<EObject>();
return defaultLibraryContainers;

private List<IPaletteCompartmentEntry> getLibraryCompartments() {
List<IPaletteCompartmentEntry> compartments = new
DiagramBehavior diagramBehavior = (DiagramBehavior)
EObject bo =
EObject model = EcoreUtil.getRootContainer(bo);
// assume only the root can contain imports
if (modelFacade.isEntityKind(model,
ModelFacade.EntityKind.ACTOR_CONTAINER) && model.eContainer() == null) {
IScopeProvider scopeProvider =
IQualifiedNameConverter qualifiedNameConverter =
// for (ImportDirective importDirective : ((ActorModel)
model).getImports()) {
// String qName = importDirective.getImportedNamespace();
// if (qName.endsWith(".*")) {
// qName = qName.substring(0, qName.length() - 2);
// }
// IScope scope = scopeProvider.getScope(model,
// for (IEObjectDescription element :
scope.getElements(qualifiedNameConverter.toQualifiedName(qName))) {
// EObject eObject = EcoreUtil.resolve(element.getEObjectOrProxy(),
// if (eObject instanceof EntityContainer<?>) {
// addCompartmentEntries((EntityContainer<?>) eObject, compartments);
// }
// }
// }
if (compartments.isEmpty()) {
for (EObject entityContainer : getDefaultLibraryContainers()) {
addCompartmentEntries(entityContainer, compartments);
return compartments;

protected void addCompartmentEntries(EObject container,
List<IPaletteCompartmentEntry> compartments) {
if (! modelFacade.isEntityKind(container,
ModelFacade.EntityKind.COMPOSITE_ACTOR)) {
IQualifiedNameConverter qualifiedNameConverter =
QualifiedName qName =
if (qName.getSegmentCount() > 2) {
qName = qName.skipFirst(qName.getSegmentCount() - 2);
PaletteCompartmentEntry compartmentEntry = new
PaletteCompartmentEntry(qualifiedNameConverter.toString(qName), null);
for (EObject entity : modelFacade.getEntities(container)) {

private Injector editorInjector;

private IObjectCreationToolEntry createEntityCreationToolEntry(EObject
actor) {
String label = modelFacade.getName(actor);
AbstractCreateActorFeature createEntityFeature = new
modelFacade.getName(actor), actor, true);
ObjectCreationToolEntry toolEntry = new ObjectCreationToolEntry(label,
"Create a " + label, null, null, createEntityFeature);
return toolEntry;
Re: Palette-Items Customize before/at Editor start [message #1033492 is a reply to message #1028732] Thu, 04 April 2013 09:30 Go to previous messageGo to next message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member
Thank you for your answer!
it helps me just a little bit, but i found a way how i can reload my Palette and how i can add some new Entries during the run-time.

i have some another question, know somebody how i can load and add SVG file to an containerShape?
Its easy to add some jpg/png File's but know somebody how i can add svg?
Re: Palette-Items Customize before/at Editor start [message #1034397 is a reply to message #1033492] Fri, 05 April 2013 11:45 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1925
Registered: July 2009
Location: Walldorf, Germany
Senior Member
AFAIK, the underlying SWT Image class does not support SVG format, so I
would guess there's no way here...

Re: Palette-Items Customize before/at Editor start [message #1034464 is a reply to message #1034397] Fri, 05 April 2013 13:10 Go to previous messageGo to next message
Andrej K is currently offline Andrej KFriend
Messages: 26
Registered: March 2013
Location: germany
Junior Member
I found some solution if somebody have interest

its possible to add png? so the solution is to convert .svg in the needed size to .png and add this png to some shape or what ever.
during the element resizing in editor, i think it needed to be convert every time to get the right icon size.
I don't know if it is the best solution because i don't finish it, but it should be working
here is good example how to convert svg->png (with batik)
Re: Palette-Items Customize before/at Editor start [message #1690418 is a reply to message #1033492] Fri, 27 March 2015 09:15 Go to previous message
Ionut Ciprian Costan is currently offline Ionut Ciprian CostanFriend
Messages: 5
Registered: March 2015
Junior Member
Could you tell me how you contributed to the Palette during the run-time
Thank you in advance,
Previous Topic:Graphiti's missing features
Next Topic:Hide create feature of pattern from palette
Goto Forum:

Current Time: Fri Apr 16 00:37:25 GMT 2021

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

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

Back to the top