#809 FWT Table question

tcolar Mon 9 Nov 2009

I' working on an app that uses FWT to view/edit data.

I'm presenting the data in a table (ala Excell) and that works fine but i have a few question.

I want to propose actions(popup) when a CELL is right clicked(Ex: copy) ... there is such a method in Table but that seem to only give you infos about the ROW clicked, nothing about the actual cell(column), is that by design ??

Also at some point I'd like some of the data to be editable "in place" ... seem like table has no support for that at all, what would be the best approach to do this ? Do I have to build a Grid field with Text fields ? Or could I maybe extend Table ?

Thanks.

tcolar Tue 10 Nov 2009

Also side question: If I do s.addChar(\n')' (s is a StrBuf) then do s.toStr I would expect my \n to be a newline but it prints as a \ followed by a n

Is that normal ? How do I had a newline character to a string buffer ?

Thanks.

alexlamsl Tue 10 Nov 2009

I guess you can just do Table.colAt after capturing the pos from onMouseDown or something, but that might just defeat the whole point of this question...

KevinKelley Tue 10 Nov 2009

If I do s.addChar(\n')' (s is a StrBuf) then do s.toStr I would expect my \n to be a newline but it prints as a \ followed by a n

Not sure whether you've got a typo somewhere, or what, but this:

s := StrBuf.make
s.add("test")
s.addChar('\n')
s.add("test2")
echo("<$s>")

prints this:

<test
test2>

as expect.

brian Tue 10 Nov 2009

@tcolar

I think the key missing piece was that the mouse coordinates were not being passed to the onPopup event handler. I enhanced the eventing to include Event.pos - see changeset. With that change you can do this:

onPopup.add |Event e|
{
  Int? row := e.widget->rowAt(e.pos)
  Int? col := e.widget->colAt(e.pos)

Regarding edit-in-place, I haven't done a lot of investigation how that works in SWT. The first thing I would try is to layer the edit widget over the table cell using a custom layout Pane and see if you can make that work. But I'd be open to suggestions about how to enhance FWT to support it easier.

tcolar Tue 10 Nov 2009

@Brian e.pos is what I was looking for, thanks. For the edit in place i'll see what i can come up with.

As for the StringBuffer issue, researched it a bit more and here is the issue:

s := StrBuf.make
s.add("test")
s.addChar('\n')
s.add("test2")
echo("<$s>")  // works as expected
file := File(`/tmp/out.txt`)
file.writeObj(s.toStr) 

It prints out correctly to console:

<test
test2>

But the file(/tmp/out.txt) looks like this

<test\ntest2>

Is that a bug in writeObj ? or should i use something else to write to file ? (FYI: that's on Linux)

brian Tue 10 Nov 2009

What /tmp/out.txt should contain is:

"test\ntest2"

That is what I see. You aren't seeing the quotes for a proper string literal?

tcolar Tue 10 Nov 2009

Ok, I see writeObj serialize the object, I'm just using the wrong thing here. I just want to write my stringBuffer DATA "As is" to the file, what's the proper method to do that ? If that's not clear I want to do the equivalent of Java: OutputStream.write(s.getBytes()) or similar using printWriter.print(s)

brian Tue 10 Nov 2009

If you want to just write text, then use writeChar, writeChars, print, or printLine.

All of those methods will output text chars according to configured charset (defaults to UTF-8)

tcolar Tue 10 Nov 2009

Ha, I see it now, it's all in file.out. So file.out.writeChars

Thanks

In the meantime I've another issue with the fwt Table. It seem rowAt works fine, but colAt seem to always return null no matter what (There is a cell at the given location, I even tried to pass a manually created Point).

I'll try to find exactly where it's not happening, I notice colAt uses an SwtPos whereas rowAt does not, will try debug.

tcolar Tue 10 Nov 2009

Please disregard, of course I had to happen to be right on the "separator" between columns.

Yuri Strot Sat 14 Nov 2009

Respect to table/tree editing in FWT, I believe something like JFace Editing Support can be useful.

In this case, developer needs to provide simple editing support:

mixin EditingSupport
{
  abstract CellEditor? editor(Int col, Int row)
  abstract Obj? getValue(Int col, Int row)
  abstract Void setValue(Int col, Int row, Obj? value)
}

And use predefined cell editors: ComboBoxCellEditor, CheckboxCellEditor, TextCellEditor, etc. So you needn't care about how control created over the table (actually, there are a lot of code to correctly show/dispose cell editors).

Login or Signup to reply.