Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Use one create feature for different elements
Use one create feature for different elements [message #1082244] Thu, 08 August 2013 05:37 Go to next message
Thomas Thonhofer is currently offline Thomas Thonhofer
Messages: 18
Registered: July 2013
Junior Member
Hello

I am working on a Graphiti editor and could use some help.

In my Editor I can add elements, called Activities. I have a domain object, an add feature and a create feature for it. There should be many different types of Activities, differentiated by certain attributes of the business object. The available types should not be hardcoded within the editor, because they are constantly changing. Therefore my editor reads the available types from a xml file and puts them into an arraylist. I want all the available types from this list to appear in the pallette of the editor. From there it should be possible to create the Activities with the special attributes from the specified type.

The porblem is: Because the number of types of Activities is not determinate, I can't make a create feature for every type. So I only have one create feature for Activities. My first thought was to create an instance of my Activity create feature for every type of Activity, add the attributes of the type to it and add those create features to the getCreateFeatures() method of the feature provider. It looks something like this:

public ICreateFeature[] getCreateFeatures() {

ActivityReader ar = new ActivityReader();

		List <ActivityDescriptor> act =  ar.readActivities();
	
		
		
		List <ICreateFeature> list = new ArrayList <ICreateFeature>();
for (int j = 0; j<k; j++){
						
			
			CreateActivityFeature caf = new CreateActivityFeature(this);
			caf.setDescriptorID(act.get(j).getId());
			caf.setCreateName(act.get(j).getName());
			caf.setDescription(act.get(j).getDescription());
			
				
			list.add(caf);
ICreateFeature[] cf =  list.toArray((new ICreateFeature[list.size()]));
		
		return cf;
}


The list "act" is the list of Activity types. In the loop the create features are created and the attributes of the type are set.

In the tool behavior provider I then add a Palette Compartment and add all the Activity create features to it:

PaletteCompartmentEntry compartmentEntry3 =
				new PaletteCompartmentEntry("Activities", null);
		ret.add(compartmentEntry3);

ICreateFeature[] createActivityFeatures = featureProvider.getCreateFeatures();
		for (ICreateFeature cf : createActivityFeatures) {
			if (cf instanceof CreateActivityFeature){
						ObjectCreationToolEntry objectCreationToolEntry = 
					new ObjectCreationToolEntry(cf.getCreateName(),
							cf.getCreateDescription(), cf.getCreateImageId(),
							cf.getCreateLargeImageId(), cf);
			compartmentEntry3.addToolEntry(objectCreationToolEntry);
			



The result of that is, that the different Activities are displayed in the pallete, but when I create one, no matter which one I take, the attributes of the business object are always the same.
It seems, that when I create an Activity, only the last create feature I added to the getCreateFeatures() method is used.

So my question is: Is there I way of using one create method for different elements and if there is, how could I use it for my case? If this is not possible, I would be very happy about any suggestions, how I could add my Activities to the pallette in a different way.

I hope its somewhat clear, what I need. Any help would be very appreciated.
Thank you.
Re: Use one create feature for different elements [message #1083039 is a reply to message #1082244] Fri, 09 August 2013 07:39 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard Traetteberg
Messages: 583
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

I think what you're doing should work, as I'm doing something similar. I
create a compartment entry, and add into it several CreationToolEntries
each with a creation feature specialized for a certain entity (similar
to your generic activity) type. The creation feature takes care to use
the entity type (a qualified name) to create the corresponding entity
instance (see below for sample code).

Are you sure that only that last creation tool is used, couldn't it be
that there is some state that is shared so all of them actually do the
same thing?

Hallvard

PaletteCompartmentEntry compartmentEntry = new
PaletteCompartmentEntry(qualifiedNameConverter.toString(qName), null);
for (EObject entity : actorContainerEditModel.getEntities(container)) {
compartmentEntry.addToolEntry(createEntityCreationToolEntry(entity));
}

@Inject
private Injector editorInjector;

private IObjectCreationToolEntry createEntityCreationToolEntry(EObject
actor) {
String label = entityViewModel.getName(actor);
AbstractCreateActorFeature createEntityFeature = new
CreateActorInstanceFeature(getFeatureProvider(),
entityViewModel.getName(actor), actor);
editorInjector.injectMembers(createEntityFeature);
ObjectCreationToolEntry toolEntry = new ObjectCreationToolEntry(label,
"Create a " + label, null, null, createEntityFeature);
return toolEntry;
}



On 08.08.13 11.37, Thomas Thonhofer wrote:
> Hello
>
> I am working on a Graphiti editor and could use some help.
> In my Editor I can add elements, called Activities. I have a domain
> object, an add feature and a create feature for it. There should be many
> different types of Activities, differentiated by certain attributes of
> the business object. The available types should not be hardcoded within
> the editor, because they are constantly changing. Therefore my editor
> reads the available types from a xml file and puts them into an
> arraylist. I want all the available types from this list to appear in
> the pallette of the editor. From there it should be possible to create
> the Activities with the special attributes from the specified type.
> The porblem is: Because the number of types of Activities is not
> determinate, I can't make a create feature for every type. So I only
> have one create feature for Activities. My first thought was to create
> an instance of my Activity create feature for every type of Activity,
> add the attributes of the type to it and add those create features to
> the getCreateFeatures() method of the feature provider. It looks
> something like this:
>
> public ICreateFeature[] getCreateFeatures() {
>
> ActivityReader ar = new ActivityReader();
>
> List <ActivityDescriptor> act = ar.readActivities();
>
>
>
> List <ICreateFeature> list = new ArrayList <ICreateFeature>();
> for (int j = 0; j<k; j++){
>
>
> CreateActivityFeature caf = new CreateActivityFeature(this);
> caf.setDescriptorID(act.get(j).getId());
> caf.setCreateName(act.get(j).getName());
> caf.setDescription(act.get(j).getDescription());
>
>
> list.add(caf);
> ICreateFeature[] cf = list.toArray((new ICreateFeature[list.size()]));
>
> return cf;
> }
> The list "act" is the list of Activity types. In the loop the create
> features are created and the attributes of the type are set.
>
> In the tool behavior provider I then add a Palette Compartment and add
> all the Activity create features to it:
>
> PaletteCompartmentEntry compartmentEntry3 =
> new PaletteCompartmentEntry("Activities", null);
> ret.add(compartmentEntry3);
>
> ICreateFeature[] createActivityFeatures =
> featureProvider.getCreateFeatures();
> for (ICreateFeature cf : createActivityFeatures) {
> if (cf instanceof CreateActivityFeature){
> ObjectCreationToolEntry objectCreationToolEntry
> = new ObjectCreationToolEntry(cf.getCreateName(),
> cf.getCreateDescription(),
> cf.getCreateImageId(),
> cf.getCreateLargeImageId(), cf);
> compartmentEntry3.addToolEntry(objectCreationToolEntry);
>
>
>
> The result of that is, that the different Activities are displayed in
> the pallete, but when I create one, no matter which one I take, the
> attributes of the business object are always the same. It seems, that
> when I create an Activity, only the last create feature I added to the
> getCreateFeatures() method is used.
> So my question is: Is there I way of using one create method for
> different elements and if there is, how could I use it for my case? If
> this is not possible, I would be very happy about any suggestions, how I
> could add my Activities to the pallette in a different way.
>
> I hope its somewhat clear, what I need. Any help would be very appreciated.
> Thank you.
Re: Use one create feature for different elements [message #1084917 is a reply to message #1082244] Mon, 12 August 2013 04:04 Go to previous message
Thomas Thonhofer is currently offline Thomas Thonhofer
Messages: 18
Registered: July 2013
Junior Member
Thank you for your answer

I already found my problem, it was just a stupid mistake. I accidentally set some attributes to static, so they existed only once, instead of for every instance. Then of course they always had the last value, I assigned to them, which made me think that the wrong instance was used.
After correcting that, everything works fine.
Previous Topic:are context buttons available for connections?
Next Topic:Making parent features available for the child
Goto Forum:
  


Current Time: Thu Apr 24 01:27:48 EDT 2014

Powered by FUDForum. Page generated in 0.03393 seconds