Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Caching of features(Can features be created once and given out by the feature provider several times?)
Caching of features [message #1092844] Fri, 23 August 2013 08:58 Go to next message
Albert Hofkamp is currently offline Albert HofkampFriend
Messages: 41
Registered: August 2009
Member
While working on layout features, I noticed the following pattern:

1. The feature provider finds which feature to provide for layout of an element.
2. When found, it creates the new feature.
3. The feature itself has a check (canLayout) whether an element can be layout.

Before today, I just duplicated those checks. Today, I did the following.
In the layout feature:
public class EventLayoutFeature extends AbstractLayoutFeature {
    ...

    public static boolean canLayout(PictogramElement pe) {
        String val = pes.getPropertyValue(pe, EVENT_ELEMENT);
        return val != null && val.equals(NAME);
    }

    @Override
    public boolean canLayout(ILayoutContext context) {
        PictogramElement pe = context.getPictogramElement();
        return canLayout(pe);
    }

    @Override
    public boolean layout(ILayoutContext context) {
        ...
    }
}


And in the feature provider:
    @Override
    public ILayoutFeature getLayoutFeature(ILayoutContext context) {
        PictogramElement pe = context.getPictogramElement();
        if (EventLayoutFeature.canLayout(pe)) {
            return new EventLayoutFeature(this);
        }
        ...
    }
I literally perform the same check in both occasions, except I cannot call "canLayout(ILayoutContext context)", because it is an instance method.

This leads to the question whether you cannot make an EventLayoutFeature once, and use that instead (the layout feature class has no state in my code). It would simplify the feature provider code to "if(instance.canLayout(context)) return instance;".

However, is this allowed by Graphiti, and is this wanted. Does eg Graphiti itself have this caching? (although in the latter case, you may want to just give all features to graphiti at startup instead of this querying and creation on demand.



Looking at other places in the feature provider, I now realize I do this everywhere. It would reduce code duplication, and possibly eliminate creation of many feature objects.
Re:Caching of features [message #1093855 is a reply to message #1092844] Sat, 24 August 2013 19:48 Go to previous message
Felix Velasco is currently offline Felix VelascoFriend
Messages: 43
Registered: July 2009
Member
There is no caching of features in the framework, since you could
possibly return different features for the same context due to
the state of the diagram, or many other reasons. However, nothing
prevents you either from implementing such a caching yourself. A
LayoutFeature can be very easily implemented with the Singleton
Pattern, if it needs no state.

----Android NewsGroup Reader----
http://www.piaohong.tk/newsgroup
Previous Topic:rolling back model changes
Next Topic:Integration with eclipse launch fwk
Goto Forum:
  


Current Time: Fri Mar 29 07:52:26 GMT 2024

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

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

Back to the top