3

I´m currently developing an Eclipse4 RCP Application and I was wondering if there is a possibility to define tokens in SWT Text Fields, so that they are not accessible characterwise.

So for example I have a Text Field and I want to make tokens that match "[anytext]" not accessible characterwise. (Where the parenthesis define the token)

That means: I cannot put my cursor inside the parenthesis and if I press delete directly in front of the left parenthesis or backspace directly behind the right parenthesis, the whole token gets deleted.

I´m currently doing it with listeners but that seems somehow a little to complex and expensive, as I need a KeyListener with lots of logic and a mouse listener to prevent clicks inside the token and an adjusted Drop Listener as Drops inside token shouldn´t be allowed neither obviously.

Am I just missing some fancy way of doing it?

Hope you can help me, thank you!

HexFlex
  • 251
  • 1
  • 13
  • Just to clarify: are you making something similar to StackOwerflow tags functionality? – Alex K. Feb 07 '14 at 10:44
  • no, but in a way that´s what I need. To give you the big picture: I have a text, (call it a variable) and those variables can appear as tokens in other textfields (in these parenthesis: [variable]). As the text of the variable gets changed, all tokens change their text accordingly. The tokens shouldn´t get manipulated, but one should be able to delete them (the whole token). – HexFlex Feb 07 '14 at 10:46
  • 4
    There is no fancy way, lots of listeners is the way to do it. – greg-449 Feb 07 '14 at 11:18

1 Answers1

1

I would suggest you to use org.eclipse.swt.custom.StyledText that provides rich features than org.eclipse.swt.widgets.Text. JavaEditor does the same functionality that you are looking like refactor change variable name, change gets reflected whereever this variable is used.

sambi reddy
  • 3,065
  • 1
  • 13
  • 10