Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Computational "Auto Size" of node images
Computational "Auto Size" of node images [message #1820612] Thu, 23 January 2020 21:33 Go to next message
Bernhard Edler is currently offline Bernhard EdlerFriend
Messages: 5
Registered: August 2014
Junior Member
My Goal: I wish to have nodes in a container, the container being resizable. The nodes should be displayed as images with fixed size, but should still be movable within the container. Edit: I failed to mention, the images should depend on model properties, and I dont want to have dozens of conditional styles that need maintaining in my .odesign file.

My status quo: The nodes are fixed in size(resize disabled, move still allowed), the correct Images are loaded.

My problem: The Images I wish are 100 by 100 px, yet when I create a new node using the palette tool I defined in my .odesign-file, the node is only 20 by 20px in size (In the attached image, see the violet "T"-shape in the left container). Since resizing is disabled, I have to manually hit "Auto Size" from the toolbar to have it correctly displayed (like the rightmost image).

Is there a way to programmatically "autosize" the image upon creation? Or better, a way to have the images created correctly sized in the first place?

A few samples of what I did, hopefully insightful:

public class StyleEditPartProvider extends AbstractEditPartProvider {
	protected Class getNodeEditPartClass(View view) {
		if (view.getElement() instanceof CustomStyle) {
			CustomStyle customStyle = (CustomStyle) view.getElement();
			if (customStyle.getId().equals(AnlageStyleEditPart.ID)) {
				return AnlageStyleEditPart.class;

public class AnlageStyleEditPart extends AbstractNotSelectableShapeNodeEditPart implements IStyleEditPart {
	public static final String ID = "";
	protected IFigure contentPane;
	protected ImageFigure primaryShape;

	public AnlageStyleEditPart(View view) {
		// here my model listeners are registert via addListenerFilter(...)

	private NodeFigure createNodePlate() {
		DefaultSizeNodeFigure result = new AirStyleDefaultSizeNodeFigure(100, 100);
		return result;

	public ImageFigure getPrimaryShape() {
		if (primaryShape == null) {
			primaryShape = new ImageFigure();
		return primaryShape;

	 * react to model changes from the properties view
	 * @generated NOT
	public void notifyChanged(Notification notification) {

	protected void refreshVisuals() {
		Optional<Image> imageOpt = getImage();
		if (imageOpt.isPresent()) {
			Image image = imageOpt.get();

	private Optional<Image> getImage() {
		//loads the correct image from my images-folder depending on model properties

public class EditPolicyProvider implements IEditPolicyProvider {

	public void createEditPolicies(EditPart editPart) {
		if (editPart instanceof DNodeContainerViewNodeContainerCompartmentEditPart) {
			editPart.installEditPolicy(EditPolicy.LAYOUT_ROLE, new FixedSizeContainerEditPolicy());

public class FixedSizeContainerEditPolicy extends AirXYLayoutEditPolicy {

	protected Command getResizeChildrenCommand(ChangeBoundsRequest request) {
		if (isResize(request)) {
			return DoNothingCommand.INSTANCE;
		Command superCommand = super.getResizeChildrenCommand(request);
		EditPart host = getHost();
		if (host instanceof IGraphicalEditPart) {
			TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) host).getEditingDomain();
			CompositeTransactionalCommand ctc = new CompositeTransactionalCommand(editingDomain,
			ctc.add(new CommandProxy(superCommand));

			ShiftEdgeIdentityAnchorOperation operation = new ShiftEdgeIdentityAnchorOperation(request);
			ICommand command = CommandFactory.createICommand(editingDomain, operation);
			return new ICommandProxy(ctc);
		return superCommand;

	private boolean isResize(ChangeBoundsRequest request) {
		return request.getSizeDelta().height != 0 || request.getSizeDelta().width != 0;
  • Attachment: editor.png
    (Size: 40.51KB, Downloaded 17 times)

[Updated on: Fri, 24 January 2020 06:22]

Report message to a moderator

Re: Computational "Auto Size" of node images [message #1820641 is a reply to message #1820612] Fri, 24 January 2020 09:09 Go to previous messageGo to next message
Florian Barbin is currently offline Florian BarbinFriend
Messages: 246
Registered: August 2010
Senior Member

Have you tried to set "-1" in your workspace image size computation expression? With this value, the node will automatically have the real image size.


Re: Computational "Auto Size" of node images [message #1820776 is a reply to message #1820641] Tue, 28 January 2020 15:33 Go to previous message
Bernhard Edler is currently offline Bernhard EdlerFriend
Messages: 5
Registered: August 2014
Junior Member
Thank you for your suggestion, it worked as expected. I got lost trying to dig so deep into GEF, i forgot the solutions in plain sight.

Previous Topic:adding nodes to the label area
Next Topic:Let missing on CASE/Default context menu
Goto Forum:

Current Time: Tue Oct 27 13:45:58 GMT 2020

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

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

Back to the top