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 K
Messages: 26
Registered: March 2013
Location: germany
Junior Member
Hello!

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


Andrej
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 Traetteberg
Messages: 601
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...

Hallvard

@Override
public IPaletteCompartmentEntry[] getPalette() {
IPaletteCompartmentEntry[] superCompartments = super.getPalette();
List<IPaletteCompartmentEntry> libraryCompartments =
getLibraryCompartments();
List<IPaletteCompartmentEntry> allCompartments = new
ArrayList<IPaletteCompartmentEntry>(Arrays.asList(superCompartments));
allCompartments.addAll(libraryCompartments);
return allCompartments.toArray(new
IPaletteCompartmentEntry[allCompartments.size()]);
}

private Collection<EObject> defaultLibraryContainers = null;

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

EObject libraryContainer =
modelFacade.createEntity(ModelFacade.EntityKind.ACTOR_CONTAINER,
"Default library", null);

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

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

defaultLibraryContainers = new ArrayList<EObject>();
defaultLibraryContainers.add(libraryContainer);
}
return defaultLibraryContainers;
}

private List<IPaletteCompartmentEntry> getLibraryCompartments() {
List<IPaletteCompartmentEntry> compartments = new
ArrayList<IPaletteCompartmentEntry>();
DiagramBehavior diagramBehavior = (DiagramBehavior)
getDiagramTypeProvider().getDiagramBehavior();
EObject bo =
Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagramBehavior.getDiagramTypeProvider().getDiagram());
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 =
getDslInjector().getInstance(IScopeProvider.class);
IQualifiedNameConverter qualifiedNameConverter =
getDslInjector().getInstance(IQualifiedNameConverter.class);
// 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,
XactorPackage.eINSTANCE.getEntityFolder_EntityContainers());
// for (IEObjectDescription element :
scope.getElements(qualifiedNameConverter.toQualifiedName(qName))) {
// EObject eObject = EcoreUtil.resolve(element.getEObjectOrProxy(),
model);
// 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 =
getDslInjector().getInstance(IQualifiedNameConverter.class);
QualifiedName qName =
qualifiedNameConverter.toQualifiedName(modelFacade.getQualifiedEntityName(container));
if (qName.getSegmentCount() > 2) {
qName = qName.skipFirst(qName.getSegmentCount() - 2);
}
PaletteCompartmentEntry compartmentEntry = new
PaletteCompartmentEntry(qualifiedNameConverter.toString(qName), null);
for (EObject entity : modelFacade.getEntities(container)) {
compartmentEntry.addToolEntry(createEntityCreationToolEntry(entity));
}
compartments.add(compartmentEntry);
}
}

@Inject
private Injector editorInjector;

private IObjectCreationToolEntry createEntityCreationToolEntry(EObject
actor) {
String label = modelFacade.getName(actor);
AbstractCreateActorFeature createEntityFeature = new
CreateActorInstanceFeature(getFeatureProvider(),
modelFacade.getName(actor), actor, true);
editorInjector.injectMembers(createEntityFeature);
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 K
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 Wenz
Messages: 1621
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...

Michael
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 message
Andrej K is currently offline Andrej K
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)

weblogs.java.net/blog/javakiddy/archive/2007/11/card_sharp.html
Previous Topic:Different PropertySheets for different tools
Next Topic:Property View - changes cause undo problems
Goto Forum:
  


Current Time: Thu Oct 30 15:19:04 GMT 2014

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

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