2

I work on a Eclipse Plugin which have two TreeViewer, one of them with the parameter SWT.RIGHT_TO_LEFT. This looks like this: Plugin Screen

As you see the Tree Structure is drawn from right to left and that is what i need. But and here is my problem, the Text gets also inverted but only when special characters are in the string. PID.5.7 is transformed to 7.5.PID. Here is how i create TreeViewer and the Text:

xmlTreeOut = new TreeViewer(composite, SWT.RIGHT_TO_LEFT | SWT.DOUBLE_BUFFERED);
...
xmlTreeOut.getTree().addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
        //loop over treeItems and for each
        ...
        TextLayout textLayout = new TextLayout(Display.getDefault());
        textLayout.setText(xmlName + xmlValue);
        textLayout.draw(event.gc, root.getBounds().x + 2, root.getBounds().y + 1);
        ...
    }
});

Does anyone have a fix for this problem? I would like to have my String exactly as I write it in the TextLayout.

EDIT:

I added the mentioned

textLayout.setOrientation(SWT.RIGHT_TO_LEFT);

Now my output is like this:

enter image description here

As you can see it worked for Strings like PID.7.5 but if there are Strings seperated with space and only containing special characters its inversed. Like "MSH.1 |" becomes "| MSH.1"

(removed the Style2 and use only one style in TextLayout)

EDIT 2:

WORKAROUND SOLUTION:

I test now if my String starts with a "word" which has no a-z, A-Z I simply add a "x" with StyleColor = WHITE in front. This way all values are displeyed correctly.

Darkpara
  • 304
  • 1
  • 2
  • 14

1 Answers1

1

I haven't tested this, but the method TextLayout#setOrientation(int orientation) looks like what you need:

Sets the orientation of the receiver, which must be one of SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.

Just set it to SWT.LEFT_TO_RIGHT for both TreeViewers (or maybe SWT.RIGHT_TO_LEFT for the right TreeViewer to invert the previous right-to-left ?).

Baz
  • 36,440
  • 11
  • 68
  • 94
  • Thanks for the fast response, yes i saw the setOrientation but did not tryed to set it again RIGHT_TO_LEFT. It works but only half way. I add a screen of the "new" result to my first post. – Darkpara Jun 18 '14 at 09:18
  • @Darkpara Hm, I can't think of a better solution than splitting on the space character, inversing the array, joining it again and the using it... – Baz Jun 18 '14 at 09:27
  • Would be a possiblity if it would be allways the same. See new screen, the String only gets inversed when a "word" contains only special characters, in the case with two words (normal chars) it does not inverse.. it's realy strange – Darkpara Jun 18 '14 at 09:30
  • @Darkpara Well that's annoying... Sorry, I'm running out of ideas here. – Baz Jun 18 '14 at 10:02
  • @Darkpara [This](https://bugs.eclipse.org/bugs/show_bug.cgi?id=77790) seems related. – Baz Jun 18 '14 at 13:08
  • Thanks for your time. I got it fixed with a workaround added to my question at end. – Darkpara Jun 18 '14 at 14:48