Project

General

Profile

editpart-auto-size.patch

Simon Barner, 06/13/2018 04:27 PM

View differences:

org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editpart/ElementEditPartBase.java
15 15
+--------------------------------------------------------------------------*/
16 16
package org.fortiss.tooling.base.ui.editpart;
17 17

  
18
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getNodeBounds;
19 18
import static org.fortiss.tooling.base.ui.utils.SnapToGridUtils.snapToGridAdapter;
19
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeBounds;
20
import static org.fortiss.tooling.base.utils.LayoutDataUtils.setNodeBounds;
21
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.runAsCommand;
20 22

  
21 23
import java.util.ArrayList;
22 24
import java.util.List;
......
42 44
import org.eclipse.swt.SWT;
43 45
import org.eclipse.swt.graphics.Cursor;
44 46
import org.eclipse.swt.graphics.Font;
47
import org.eclipse.swt.graphics.GC;
45 48
import org.eclipse.swt.widgets.Display;
46 49
import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
50
import org.fortiss.tooling.base.model.element.IHierarchicElement;
47 51
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
48 52
import org.fortiss.tooling.base.ui.editpart.figure.TransparentLabel;
49 53
import org.fortiss.tooling.base.ui.editpart.policy.DirectConnectionAndReconnectionEditPolicy;
50 54
import org.fortiss.tooling.base.ui.editpart.policy.ElementLayoutEditPolicy;
51 55
import org.fortiss.tooling.base.ui.editpart.policy.RemoveEditPolicy;
56
import org.fortiss.tooling.base.ui.layout.auto.DiagramTapeMeasure;
57
import org.fortiss.tooling.base.ui.layout.auto.IAutoLayouterTapeMeasure;
58
import org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils;
52 59
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
53 60
import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler;
54 61
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
......
103 110
		return modelElementHandler.getConnectors(getModel());
104 111
	}
105 112

  
113
	/** Flag to prevent infinite recursion in {@link #determineBaseFigureBounds()}. */
114
	private boolean inDetermineBaseFigureBounds = false;
115

  
106 116
	/** {@inheritDoc} */
107 117
	@Override
108 118
	protected Rectangle determineBaseFigureBounds() {
109
		return getNodeBounds(getModel());
119
		T model = getModel();
120
		if(!inDetermineBaseFigureBounds && model instanceof IHierarchicElement) {
121
			inDetermineBaseFigureBounds = true;
122
			// Update element bounds to label text width
123
			GC gc = new GC(getViewer().getControl());
124
			IAutoLayouterTapeMeasure tapeMeasure = new DiagramTapeMeasure(getViewer(), gc);
125
			int labelWidth = tapeMeasure.getElementWidth((IHierarchicElement)model);
126
			gc.dispose();
127

  
128
			org.fortiss.tooling.base.model.layout.Rectangle bounds = getNodeBounds(model);
129
			if(labelWidth > bounds.getWidth()) {
130
				bounds.setWidth(labelWidth);
131
				runAsCommand(model, () -> setNodeBounds(model, bounds));
132
			}
133
			inDetermineBaseFigureBounds = false;
134
		}
135
		return LayoutDataUIUtils.getNodeBounds(model);
110 136
	}
111 137

  
112 138
	/** {@inheritDoc} */