1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  *   Licensed to the Apache Software Foundation (ASF) under one or more
11  *   contributor license agreements. See the NOTICE file distributed
12  *   with this work for additional information regarding copyright
13  *   ownership. The ASF licenses this file to you under the Apache
14  *   License, Version 2.0 (the "License"); you may not use this file
15  *   except in compliance with the License. You may obtain a copy of
16  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 package com.sun.star.wizards.document;
19 
20 import com.sun.star.awt.Point;
21 import com.sun.star.awt.Size;
22 import com.sun.star.awt.XControlModel;
23 import com.sun.star.beans.XPropertySet;
24 import com.sun.star.wizards.common.*;
25 import com.sun.star.wizards.db.FieldColumn;
26 import com.sun.star.sdbc.*;
27 import com.sun.star.uno.Exception;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.container.XNameAccess;
30 import com.sun.star.container.XNameContainer;
31 import com.sun.star.form.XGridColumnFactory;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.lang.XMultiServiceFactory;
34 
35 public class GridControl extends Shape
36 {
37 
38     public XNameContainer xNameContainer;
39     public XGridColumnFactory xGridColumnFactory;
40     public XPropertySet xPropertySet;
41     XNameAccess xNameAccess;
42     public XComponent xComponent;
43 
GridControl(XMultiServiceFactory _xMSF, String _sname, FormHandler _oFormHandler, XNameContainer _xFormName, FieldColumn[] _fieldcolumns, Point _aPoint, Size _aSize)44     public GridControl(XMultiServiceFactory _xMSF, String _sname, FormHandler _oFormHandler, XNameContainer _xFormName, FieldColumn[] _fieldcolumns, Point _aPoint, Size _aSize)
45     {
46         super(_oFormHandler, _aPoint, _aSize);
47         try
48         {
49             Object oGridModel = oFormHandler.xMSFDoc.createInstance(oFormHandler.sModelServices[FormHandler.SOGRIDCONTROL]);
50             xNameContainer = UnoRuntime.queryInterface( XNameContainer.class, oGridModel );
51             xNameAccess = UnoRuntime.queryInterface( XNameAccess.class, oGridModel );
52             _xFormName.insertByName(_sname, oGridModel);
53             XControlModel xControlModel = UnoRuntime.queryInterface( XControlModel.class, oGridModel );
54             // test if the interface was available
55             if (xControlModel == null) {
56                 throw new Exception(
57                     "Error: GridModel does not export XControlModel interface");
58             }
59 
60             if (xControlShape == null) {
61                 throw new Exception(
62                     "Error: GridModel does not have a XControlShape");
63             }
64 
65             xControlShape.setControl(xControlModel);
66             xPropertySet = UnoRuntime.queryInterface( XPropertySet.class, oGridModel );
67             oFormHandler.xDrawPage.add(xShape);
68             xGridColumnFactory = UnoRuntime.queryInterface( XGridColumnFactory.class, oGridModel );
69             xComponent = UnoRuntime.queryInterface( XComponent.class, oGridModel );
70 
71             for (int i = 0; i < _fieldcolumns.length; i++)
72             {
73                 FieldColumn curfieldcolumn = _fieldcolumns[i];
74                 if (curfieldcolumn.getFieldType() == DataType.TIMESTAMP)
75                 {
76                     new TimeStampControl(new Resource(_xMSF), this, curfieldcolumn);
77                 }
78                 else
79                 {
80                     new DatabaseControl(this, curfieldcolumn);
81                 }
82             }
83 
84         }
85         catch (Exception e)
86         {
87             e.printStackTrace(System.err);
88         }
89     }
90 }
91