Skip to main content



      Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF Forms] Setting the size of controls programmatically
[EMF Forms] Setting the size of controls programmatically [message #1740998] Mon, 22 August 2016 05:38 Go to next message
Eclipse UserFriend
Hi everybody!

I would like to set the size (primarily the height) of a TextControl.
I tried to override the render(SWTGriCell, Composite)-method of the TextControlSWTRenderer and set the preferred size of the cell there, but that resulted in an invalid layout of the complete form, also i just changed it for one specific field.
Using a static Template is no option, because our software is highly customizable.

Am i doing something wrong or is this a known issue?

Kind regards,
André

[Updated on: Mon, 22 August 2016 05:43] by Moderator

Re: [EMF Forms] Setting the size of controls programmatically [message #1741175 is a reply to message #1740998] Tue, 23 August 2016 09:53 Go to previous messageGo to next message
Eclipse UserFriend
Hi Andre,
I would recommend to overwrite the createSWTControl method in this way:
@Override
protected Control createSWTControl(Composite parent) {
final Control control = super.createSWTControl(parent);
final Composite composite = Composite.class.cast(control);
final Control textControl = composite.getChildren()[0];
GridData.class.cast(textControl .getLayoutData()).heightHint = 100;
return control;
}

This should do the trick.

Cheers,
Eugen
Re: [EMF Forms] Setting the size of controls programmatically [message #1741179 is a reply to message #1741175] Tue, 23 August 2016 10:21 Go to previous message
Eclipse UserFriend
Hi Eugene,

thank you for your reply!
The code you posted didn't work as expected, because the layoutData of the control that is being returned by createSWTControl, is overridden later by ContainerSWTRenderer#setLayoutDataForControl.
Anyway: you led me the way to the solution. Because i already had overridden the createSWTControl-method, i instanciated an anonymous class of Text, in which i overrode the setLayoutData-method as following:

text = new Text(parent, getTextWidgetStyle()) {
private static final long serialVersionUID = -3354554595303103830L;

@Override
public void setLayoutData(Object layoutData) {
if (layoutData instanceof GridData) {
GridData gridData = (GridData) layoutData;
gridData.heightHint = dimensionOption.getHeight();
gridData.widthHint = dimensionOption.getWidth();
}
super.setLayoutData(layoutData);
}
};

I know this is not an ideal solution, because it presumes that the LayoutData is GridData, but we haven't had any case, where it's not like this - till now.

Thank you and have a nice day everybody! Smile
Previous Topic:EMF Forms UI
Next Topic:EMF Forms UI
Goto Forum:
  


Current Time: Fri Jul 04 09:37:35 EDT 2025

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

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

Back to the top