Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF Forms] multi-row controls
[EMF Forms] multi-row controls [message #1715956] Sun, 29 November 2015 11:47 Go to next message
Klim Tow is currently offline Klim TowFriend
Messages: 49
Registered: September 2015
Member
Hi

I try to render something called "text area" - in SWT it is called "multi-line text", however it does not work. I subclassed TextControlSWTRenderer like this:
public class DescriptionControlRenderer extends TextControlSWTRenderer {
	
	private final static int ROWS = 10;
	
	@Inject
	public DescriptionControlRenderer(VControl vElement, ViewModelContext viewContext, ReportService reportService,
			EMFFormsDatabinding emfFormsDatabinding, EMFFormsLabelProvider emfFormsLabelProvider,
			VTViewTemplateProvider vtViewTemplateProvider, EMFFormsEditSupport emfFormsEditSupport) {
		super(vElement, viewContext, reportService, emfFormsDatabinding, emfFormsLabelProvider, vtViewTemplateProvider,
				emfFormsEditSupport);
	}
	
	@Override
	protected Control createSWTControl(Composite parent) {
		final Text text = new Text(parent, getTextWidgetStyle());
		GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, true);
		gridData.minimumHeight = ROWS * text.getLineHeight();
		gridData.heightHint = ROWS * text.getLineHeight();
		text.setLayoutData(gridData);
		return text;
	}
	
	@Override
	public SWTGridDescription getGridDescription(SWTGridDescription gridDescription) {
		int columns;
		switch (getVElement().getLabelAlignment()) {
			case DEFAULT:
			case LEFT:
				columns = 3;
				break;
			case NONE:
				columns = 2;
				break;
			default:
				getReportService().report(new AbstractReport(MessageFormat.format(
						"Label alignment {0} is not supported by renderer {1}. Label alignment set to default.",
						getVElement().getLabelAlignment().getLiteral(), getClass().getName()), IStatus.INFO));
				getVElement().setLabelAlignment(LabelAlignment.DEFAULT);
				columns = 3;
		}
		SWTGridDescription description = GridDescriptionFactory.INSTANCE.createSimpleGrid(ROWS, columns, this);
		for (int i = 0; i < description.getGrid().size() - 1; i++) {
			SWTGridCell swtGridCell = description.getGrid().get(i);
			swtGridCell.setHorizontalGrab(false);
		}
		return description;
	}
	
	@Override
	protected int getTextWidgetStyle() {
		return SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | getAlignment();
	}
	
	private int getAlignment() {
		if (getVTViewTemplateProvider() == null) {
			return getDefaultAlignment();
		}
		final Set<VTStyleProperty> styleProperties = getVTViewTemplateProvider()
			.getStyleProperties(getVElement(), getViewModelContext());
		for (final VTStyleProperty styleProperty : styleProperties) {
			if (VTAlignmentStyleProperty.class.isInstance(styleProperty)) {
				if (VTAlignmentStyleProperty.class.cast(styleProperty).getType() == AlignmentType.LEFT) {
					return SWT.LEFT;
				} else if (VTAlignmentStyleProperty.class.cast(styleProperty).getType() == AlignmentType.RIGHT) {
					return SWT.RIGHT;
				}
			}
		}
		return getDefaultAlignment();
	}
}


That is I set the number of rows in getGridDescription(), as well the height of the multi-line control but nothing seem to work.

Is it a limitation of EMF Forms: always the one-row? Or can it be achieved with custom areas? Looking at the custom area example gives no clarity on this topic, because the example uses 2 1*1 grids instead of 1 2*1... how can we render text area in EMF Forms?
Re: [EMF Forms] multi-row controls [message #1715967 is a reply to message #1715956] Sun, 29 November 2015 18:11 Go to previous messageGo to next message
Klim Tow is currently offline Klim TowFriend
Messages: 49
Registered: September 2015
Member
well, the custom area would be to much - I think the way is to subclass AbstractSWTRenderer

multi-line text controls are required in most form-based applications
there should be some MultiLineTextSWTRenderer in EMF Forms
at the moment multi-line text goes rendered into one-line control with scroll-bar

thanks again
Re: [EMF Forms] multi-row controls [message #1716001 is a reply to message #1715967] Mon, 30 November 2015 11:42 Go to previous messageGo to next message
Klim Tow is currently offline Klim TowFriend
Messages: 49
Registered: September 2015
Member
even better would be setting property "multiline" to "true" in gen-model... then text area will be rendered by default Laughing oh boy.. is it documented somewhere?

although I would see this "multiline" property as explicit part of the view model, not of the gen-model
Re: [EMF Forms] multi-row controls [message #1716056 is a reply to message #1716001] Mon, 30 November 2015 21:48 Go to previous message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 161
Registered: May 2015
Senior Member
Hi Klim,
good that you found the option.
Yeah the multi-line thing is strange.
On the one hand site the genmodel has this optional so it makes sense to reuse it. On the other hand one could make this explicit.

So could you please open a bug report for this. Maybe we will find some time to fix this.

Thanks and cheers,
Eugen


--
Eugen Neufeld

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Previous Topic:[Texo] NoSuchMethodError
Next Topic:[EMF Forms] Error running org.eclipse.emf.ecp.makeithappen.application.sample.e3
Goto Forum:
  


Current Time: Wed Aug 05 06:01:51 GMT 2020

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

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

Back to the top