Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » One CreateFeature for many palette entries
One CreateFeature for many palette entries [message #903410] Thu, 23 August 2012 14:10 Go to next message
Stefan WülfrathFriend
Messages: 18
Registered: February 2012
Junior Member
Hi,

how can a CreateFeature detect which PaletteEntry was used to call it?

In my metamodel I have so called "Element"s and "ElementType"s. Each element has an element type. The list of element types is dynamic (depending on included element type libraries).

The graphical representation of an element is always the same. There is only another "type" string in the shape.

My current approach is, that the palette contains a list of all available element types. The user should select the palette entry with the desired element type and create an element of that type.

So, the element's CreateFeature has to set the element's type according to the selected palette entry. How can I achieve this?

Thank you very much for your help!

Best regards,
Stefan
Re: One CreateFeature for many palette entries [message #903561 is a reply to message #903410] Fri, 24 August 2012 10:44 Go to previous messageGo to next message
Aljoscha Hark is currently offline Aljoscha HarkFriend
Messages: 24
Registered: March 2012
Junior Member
hi,

you could easily create the following CreateFeature and instantiate it in your ToolBehaviorProvider/the place where you configure the palette with different arguments using enumeration literals or any other identification for all possible values.

package editor.features.create;

import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;

public class CreateElementFeature extends AbstractCreateFeature {
  private ElementType type;

  public CreateElementFeature(IFeatureProvider fp, ElementType type) {
    super(fp, null, null);

    this.type = type;
  }

  @Override
  public Object[] create(ICreateContext context) {
    Element element = doCreate(context);

    addGraphicalRepresentation(context, element);

    return new Object[] { element };
  }

  protected Element doCreate(ICreateContext context) {
    ContainerShape cpe = context.getTargetContainer();
    ElementContainer cbo = (ElementContainer) getBusinessObjectForPictogramElement(cpe);

    Element bo = new Element();
    bo.setType(type);

    cbo.getElements().add(bo);

    return bo;
  }

  @Override
  public String getCreateName() {
    switch (type) {
    case TYPE1:
      return "Type 1";
    case TYPE2:
      return "Type 2";
    default:
      return super.getCreateImageId();
    }
  }

  @Override
  public String getCreateDescription() {
    switch (type) {
    case TYPE1:
      return "Create Type 1";
    case TYPE2:
      return "Create Type 2";
    default:
      return super.getCreateImageId();
    }
  }

  @Override
  public String getCreateImageId() {
    switch (type) {
    case TYPE1:
      return "type1";
    case TYPE2:
      return "type2";
    default:
      return super.getCreateImageId();
    }
  }

  @Override
  public boolean canCreate(ICreateContext context) {
    ContainerShape pe = context.getTargetContainer();
    Object bo = getBusinessObjectForPictogramElement(pe);

    return bo instanceof ElementContainer;
  }
}


greetings,
aljoscha
Re: One CreateFeature for many palette entries [message #903711 is a reply to message #903410] Fri, 24 August 2012 07:13 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Stefan,

the create feature provides a name that is used for showing it in the
palette. Could you use that to identify the type?

Michael
Re: One CreateFeature for many palette entries [message #903890 is a reply to message #903711] Mon, 27 August 2012 07:40 Go to previous messageGo to next message
Stefan WülfrathFriend
Messages: 18
Registered: February 2012
Junior Member
Hi Aljoscha and Michael,

thank you very much for your answers!

The approach with the extended constructor is a good suggestion!

I want to use the Graphiti patterns framework to implement the features. Do you have an idea how to implement the mentioned behaviour with Patterns?

An alternative approach could be the registration of several ElementPattern instances using different constructor parameters for the different element types but with the same implementation.

Would this be a good idea?

Thank you very much for your help!

Best regards,
Stefan

[Updated on: Mon, 27 August 2012 07:42]

Report message to a moderator

Re: One CreateFeature for many palette entries [message #904281 is a reply to message #903890] Tue, 28 August 2012 06:56 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Stefan,

I think it is a good idea. It sounds like the solution Aljoscha proposed for
features.

Michael
Previous Topic:Delete Feature does not work in MPE
Next Topic:Create dynamically anchors on a shape
Goto Forum:
  


Current Time: Fri Mar 29 05:49:23 GMT 2024

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

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

Back to the top