Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 09:38 Go to next message
Andre Doerscheln is currently offline Andre DoerschelnFriend
Messages: 7
Registered: June 2015
Junior Member
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 09:43]

Report message to a moderator

Re: [EMF Forms] Setting the size of controls programmatically [message #1741175 is a reply to message #1740998] Tue, 23 August 2016 13:53 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 174
Registered: May 2015
Senior Member
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


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [EMF Forms] Setting the size of controls programmatically [message #1741179 is a reply to message #1741175] Tue, 23 August 2016 14:21 Go to previous message
Andre Doerscheln is currently offline Andre DoerschelnFriend
Messages: 7
Registered: June 2015
Junior Member
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: Thu Apr 25 06:16:40 GMT 2024

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

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

Back to the top