Discussion:
Grid control on OOo 3.3.0
Bernard Marcelly
2011-02-03 14:09:34 UTC
Permalink
Hi,
Ad an exercise I have tried to add a simple Grid control in a dialog, using the
API documentation and the Wiki page.

Remark on c.s.s.awt.grid.UnoControlGridModel IDL documentation
- Property DataModel does not exist. Real name is : GridDataModel
- Property LineColor does not exist. Real name is : GridLineColor (I suppose)

I followed, in Basic, the numerous steps : add columns to a defaultColumnModel,
create a DefaultGridDataModel, add rows, create a UnoControlGridModel, set its
position, width, height, set color to the grid lines and text, assign the
GridDataModel and the ColumnModel properties, etc, then insert the GridModel
into the dialog model.

The code runs OK. But at dialog execute, I don't see the grid :-(

I tried setVisible(True) on the grid control.... OOo crash.
The grid.OutputSize is : 0, 0 :-(

Can the Grid control be displayed on OOo 3.3.0 ?

Regards
Bernard
Frank Schönheit
2011-02-03 14:21:33 UTC
Permalink
Hi Bernard,
Post by Bernard Marcelly
Can the Grid control be displayed on OOo 3.3.0 ?
It can, but there's a number of ... undocumented traps. Without
investigating your concrete use case, it is difficult to tell what you
miss - but there sure is something, I already saw living grid controls
in a 3.3 :), though I don't have the code at hand right now.

Note that there's a CWS caled "gridsort" where both the grid control API
and the grid control implementation got some refactoring. The API won't
be compatible in 3.4 anymore (see my mail from 4 days ago), and the
implementation will be more robust (i.e. it will less often crash :) ).
Also, using a grid control will require less special knowledge - it runs
much better out of the box. For instance, you won't need to instantiate
the default column/data model anymore, this is done by the grid model
itself.

If you have some urgent need getting the grid control to fly in 3.3, you
should elaborate on what you do, so we can try to nail down the problem.

Of course, you're also invited to test the gridsort CWS, which currently
is in QA - I could provide a snapshot, so you could play with the new
API/implementation.

Ciao
Frank
Bernard Marcelly
2011-02-03 15:14:47 UTC
Permalink
Post by Frank Schönheit
Hi Bernard,
Post by Bernard Marcelly
Can the Grid control be displayed on OOo 3.3.0 ?
It can, but there's a number of ... undocumented traps. Without
investigating your concrete use case, it is difficult to tell what you
miss - but there sure is something, I already saw living grid controls
in a 3.3 :), though I don't have the code at hand right now.
I saw your message about GridSort, but OOo 3.3 should be enough for a first try.
Attached is my test dialogue, in library CtrlGrid, if you can see what is wrong
or missing.

Regards
Bernard
Oliver Brinzing
2011-02-03 17:40:06 UTC
Permalink
Hi Bernard Marcelly,

some time ago i played with the new grid control:
source code should run with oo 3.3 ...

OPTION EXPLICIT

Sub GridControlTest()

Dim oColumnModel as Object
Dim oColumn1 as Object
Dim oColumn2 as Object
Dim oDataModel as Object
Dim oGridModel as Object
Dim oGridControl as Object

Dim oDialogModel as Object
Dim oDialogControl as Object
Dim i as Integer

Dim rBounds as new com.sun.star.awt.Rectangle
Dim oContWin as Object
Dim oFrame as Object
Dim oToolkit as Object
Dim wd as new com.sun.star.awt.WindowDescriptor

Dim oListener

oColumnModel = createUnoService("com.sun.star.awt.grid.DefaultGridColumnModel")

oColumn1 = createUnoService("com.sun.star.awt.grid.GridColumn")

oColumn1.Title = "City"
oColumn1.ColumnWidth = 30
oColumn2 = createUnoService("com.sun.star.awt.grid.GridColumn")
oColumn2.Title = "Country"
oColumn2.ColumnWidth = 50

oColumnModel.addColumn(oColumn1)
oColumnModel.addColumn(oColumn2)

oDataModel = createUnoService("com.sun.star.awt.grid.DefaultGridDataModel")
For i = 0 To 10
oDataModel.addRow (""&i, Array(Chr(97+i), Chr(65+i)))
Next i

oDialogModel = createUnoService("com.sun.star.awt.UnoControlDialogModel")
oDialogModel.Title = "GridControl Test"
oDialogControl = createUnoService("com.sun.star.awt.UnoControlDialog")
oDialogControl.setModel( oDialogModel )
oDialogControl.setPosSize( 100, 100, 300, 200, com.sun.star.awt.PosSize.POSSIZE)

oGridModel = oDialogModel.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
oGridModel.Name = "MyGrid"
oGridModel.GridDataModel = oDataModel
oGridModel.ColumnModel = oColumnModel
oGridModel.ShowColumnHeader = True
oGridModel.ShowRowHeader = True
oGridModel.HScroll = True
oGridModel.VScroll = True
oGridModel.Sizeable = True

oGridControl = createUnoService("com.sun.star.awt.grid.UnoControlGrid")
oGridControl.setModel(oGridModel)

oDialogControl.addControl("MyGrid", oGridControl)
oGridControl.setPosSize(10, 10, 280, 180, com.sun.star.awt.PosSize.POSSIZE)

oToolkit = createUnoService("com.sun.star.awt.Toolkit")

rBounds.X = oDialogControl.PosSize.X
rBounds.Y = oDialogControl.PosSize.Y
rBounds.Width = oDialogControl.PosSize.Width
rBounds.Height = oDialogControl.PosSize.Height

wd.Type = com.sun.star.awt.WindowClass.TOP
wd.Bounds = rBounds
With com.sun.star.awt.WindowAttribute
wd.WindowAttributes = .BORDER + .MOVEABLE + .SIZEABLE + .CLOSEABLE
End With
wd.WindowServiceName = "window"

oContWin = oToolkit.createWindow(wd)

oFrame = createUnoService("com.sun.star.frame.Frame")
oFrame.initialize(oContWin)
StarDesktop.getFrames().append(oFrame)
oFrame.Name = "TestGridFrame"
oFrame.Title = "TestGridTitle"

oGridControl.createPeer(oToolkit, oContWin)
oContWin.setVisible(True)

oListener = CreateUnoListener("XGridSelection_", "com.sun.star.awt.grid.XGridSelectionListener")
oGridControl.addSelectionListener(oListener)

End Sub

Sub XGridSelection_selectionChanged(oEvt)
MsgBox "selected row: " & oEvt.Row
End Sub

Sub XGridSelection_disposing(oEvt)
End Sub


Regards

Oliver
--
GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45
Bernard Marcelly
2011-02-03 19:23:10 UTC
Permalink
OK, found my bug !
I had declared one column too many. The column of the row headers must not be
defined.

Using Oliver code adding the control to the dialog, my grid example throws
GridInvalidDataException : number of items per row does not match the number of
columns.

With the method of inserting the control model to the dialog model, there is no
exception and no display. In my opinion the same exception should be raised.

I see that the row header column cannot be resized with the mouse. If the
RowHeaderWidth is set too low some headers may be unreadable. It would be a nice
improvement to allow resize by mouse.

I will continue to play with the Grid control :-)
Bernard
Fernand Vanrie
2011-02-04 08:19:36 UTC
Permalink
Bernard , Frank, Oliver,

Folowed this thread with great interest, because i believe that Dialogs
are the way to make a controllable Frontend to our databases. One remark:

We can also implement a DatasourceBrowser in a dialog, less coding with
more functionality (for the moment).

My hope is that we finaly can add some "contional" colors to rows and
clomuns in this new Grid Control and it will become as easy as
implementing a DatsourceBrowser :-)

Greetz

Fernand.
Post by Bernard Marcelly
OK, found my bug !
I had declared one column too many. The column of the row headers must
not be defined.
Using Oliver code adding the control to the dialog, my grid example
throws GridInvalidDataException : number of items per row does not
match the number of columns.
With the method of inserting the control model to the dialog model,
there is no exception and no display. In my opinion the same exception
should be raised.
I see that the row header column cannot be resized with the mouse. If
the RowHeaderWidth is set too low some headers may be unreadable. It
would be a nice improvement to allow resize by mouse.
I will continue to play with the Grid control :-)
Bernard
---------------------------------------------------------------------
Frank Schönheit
2011-02-08 09:55:41 UTC
Permalink
Hi Bernard,
Post by Bernard Marcelly
Attached is my test dialogue, in library CtrlGrid, if you can see what is wrong
or missing.
You add 4 columns to the column model, but only 3 columns to each row of
the data model. This inconsistency prevents the grid control peer from
being created. Adding a forth column to all 3 data rows shows the control.

Note that you are not required to set the columns' Index property, this
is done automatically by the implementation. Also, in the changed API,
Index is not writable anymore (but read-only), so I recommend removing
those lines, anyway. After having done so, the script runs (and works)
with the new implementations as well.

Ciao
Frank
--
ORACLE
Frank Schönheit | Software Engineer | ***@oracle.com
Oracle Office Productivity: http://www.oracle.com/office
Bernard Marcelly
2011-02-08 11:13:56 UTC
Permalink
Hi Frank,
Post by Frank Schönheit
Hi Bernard,
Post by Bernard Marcelly
Attached is my test dialogue, in library CtrlGrid, if you can see what is wrong
or missing.
You add 4 columns to the column model, but only 3 columns to each row of
the data model. This inconsistency prevents the grid control peer from
being created. Adding a forth column to all 3 data rows shows the control.
Yes, I already found that error (see my second message, february 3rd).
Also yes, there is more code than necessary because I tested various things to
make it work.

After further tests I have created issues 116827 to 116831, I think they are
also valid in the new implementation.

Thanks for your message,
Bernard
Frank Schönheit
2011-02-08 11:32:28 UTC
Permalink
Hi Bernard,
Post by Bernard Marcelly
Yes, I already found that error (see my second message, february 3rd).
hmm, seems I didn't get this message.
Post by Bernard Marcelly
After further tests I have created issues 116827 to 116831, I think they are
also valid in the new implementation.
I just closed one as FIXED (the fix will manifest in master with the
integration of CWS gridsort), and grabbed the other one. Implementing a
resizable row header column would be pretty easy, though I am not sure
about the implications ... For the moment, I just grabbed the issue,
let's see.

Ciao
Frank
--
ORACLE
Frank Schönheit | Software Engineer | ***@oracle.com
Oracle Office Productivity: http://www.oracle.com/office
Loading...