Providing Resize Functionality

Creating a Resize Feature

In our current editor the resize functionality is already provided by the framework. Nevertheless this tutorial should explain how the resize behavior can be customized. Therefore we constructed the following example behavior:

Resizing EClasses should be restricted to EClasses whose name is longer than one character (just an example without logical reason).

Remember, that we already provided move functionality, which restricted the move of EClasses whose name is longer than one character. Now we want to additionally restrict the resize.

A resize feature has to implement the interface IResizeShapeFeature. Instead of implementing this directly you should extend one of the available base classes.

In this example we extend the base classDefaultResizeShapeFeature.

There are two methods to overwrite:

You can see the complete implementation of the resize feature here:

 

package org.eclipse.graphiti.examples.tutorial.features;
 
public class TutorialResizeEClassFeature extends DefaultResizeShapeFeature {
   
    public TutorialResizeEClassFeature(IFeatureProvider fp) {
        super(fp);
    }
 
    @Override
    public boolean canResizeShape(IResizeShapeContext context) {
        boolean canResize = super.canResizeShape(context);
 
        // perform further check only if move allowed by default feature
        if (canResize) {
            // don't allow resize if the class name has the length of 1
            Shape shape = context.getShape();
            Object bo = getBusinessObjectForPictogramElement(shape);
            if (bo instanceof EClass) {
                EClass c = (EClass) bo;
                if (c.getName() != null && c.getName().length() == 1) {
                    canResize = false;
                }
            }
        }
        return canResize;
    }
}

 

Additionally the feature provider has to deliver our newly created feature (overwrite the method getResizeShapeFeature).

This implementation can be seen here:

 

@Override
public IResizeShapeFeature getResizeShapeFeature(
        IResizeShapeContext context) {
    Shape shape = context.getShape();
    Object bo = getBusinessObjectForPictogramElement(shape);
    if (bo instanceof EClass) {
        return new TutorialResizeEClassFeature(this);
    }
    return super.getResizeShapeFeature(context);
}

 

Test: Resize EClass Is Restricted

Now start the editor again and test it: Just create a EClass whose name is only one character long. This EClass can no longer be resized, because on selection the resize-handles do not appear any more. For EClasses whose name has more than one character the resize should still work.