Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to align text elements of more lines(XText version 2.9)
How to align text elements of more lines [message #1697380] Wed, 03 June 2015 14:00 Go to next message
Jiang Li is currently offline Jiang LiFriend
Messages: 27
Registered: November 2014
Junior Member
I have text with following format:
dummy_command1      ?   my_condition
dummy_command123          ?  my_condition
dummy_command123456         ? my_condition


This demo text consists of more lines. Each line has the same format "command ? condition". Ich want to align the elements "? condition" for all lines
just like this:
dummy_command1                           ?   my_condition
dummy_command123                         ?   my_condition
dummy_command123456                      ?   my_condition


How can i do it ? Is there any better formatting api than "*.prepend/*.append/*.surround" ?

[Updated on: Wed, 03 June 2015 14:07]

Report message to a moderator

Re: How to align text elements of more lines [message #1697381 is a reply to message #1697380] Wed, 03 June 2015 14:02 Go to previous messageGo to next message
Jiang Li is currently offline Jiang LiFriend
Messages: 27
Registered: November 2014
Junior Member
No Message Body

[Updated on: Wed, 03 June 2015 14:07]

Report message to a moderator

Re: How to align text elements of more lines [message #1697394 is a reply to message #1697381] Wed, 03 June 2015 15:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
why not prepend/append

Model:
	lines+=Line*;
	
Line:
	name=ID '?' value=ID;
	def dispatch void format(Model model, extension IFormattableDocument document) {
		val width = model.lines.map[regionFor.feature(MyDslPackage.Literals.LINE__NAME).length].max
		for (Line line : model.getLines()) {
			val region = line.regionFor.feature(MyDslPackage.Literals.LINE__NAME)
			val s = Strings.repeat(" ", width-region.length+1)
			region.append[space = s]
			line.regionFor.keyword("?").append[space=" "]
			line.regionFor.feature(MyDslPackage.Literals.LINE__VALUE).append[newLine]
		}
	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to align text elements of more lines [message #1697481 is a reply to message #1697380] Thu, 04 June 2015 09:40 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
What's wrong with prepending and appending spaces to align the stuff?

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: How to align text elements of more lines [message #1697497 is a reply to message #1697481] Thu, 04 June 2015 12:05 Go to previous messageGo to next message
Jiang Li is currently offline Jiang LiFriend
Messages: 27
Registered: November 2014
Junior Member
@Christian
Thanks for your answer. I have the same idea as your. But your demo code is much more prettier than mein. Smile

@Sebastian
Nothing wrong with "append/prepend" methods. I am just not familiar to the new api of Formatter2. So i want to know whether there is any direct method for aligning the text elements. Smile
Re: How to align text elements of more lines [message #1702764 is a reply to message #1697481] Fri, 24 July 2015 13:40 Go to previous message
Jiang Li is currently offline Jiang LiFriend
Messages: 27
Registered: November 2014
Junior Member
Sebastian Zarnekow wrote on Thu, 04 June 2015 09:40
What's wrong with prepending and appending spaces to align the stuff?

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow


It does have a problem with prepending spaces to align the stuff. In my case, it works well if there is no other formattings before "?". But if there are other formatting before "?", Christian's code doesn't work any more. We could not calculate how many spaces will be inserted or removed before "?". It is relative dynamical.

Have you any resolution? Could we set the "fixed offset" for it?
Previous Topic:Resolve xtextLink
Next Topic:How to inject a mocked dependency into the tested instance?
Goto Forum:
  


Current Time: Tue Mar 19 02:22:50 GMT 2024

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

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

Back to the top