xref: /AOO41X/main/wizards/com/sun/star/wizards/table/FieldDescription.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package com.sun.star.wizards.table;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import java.util.Vector;
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
32*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
33*cdf0e10cSrcweir import com.sun.star.container.XNameAccess;
34*cdf0e10cSrcweir import com.sun.star.lang.Locale;
35*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
36*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
37*cdf0e10cSrcweir import com.sun.star.wizards.common.Configuration;
38*cdf0e10cSrcweir import com.sun.star.wizards.common.Properties;
39*cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir public class FieldDescription
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir     private String tablename = PropertyNames.EMPTY_STRING;
44*cdf0e10cSrcweir //  String fieldname;
45*cdf0e10cSrcweir     private String keyname;
46*cdf0e10cSrcweir     private XNameAccess xNameAccessTableNode;
47*cdf0e10cSrcweir     private XPropertySet xPropertySet;
48*cdf0e10cSrcweir     private Vector aPropertyValues;
49*cdf0e10cSrcweir //  PropertyValue[] aPropertyValues;
50*cdf0e10cSrcweir     private Integer Type;
51*cdf0e10cSrcweir     private Integer Scale;
52*cdf0e10cSrcweir     private Integer Precision;
53*cdf0e10cSrcweir     private Boolean DefaultValue;
54*cdf0e10cSrcweir     private String Name;
55*cdf0e10cSrcweir     private XMultiServiceFactory xMSF;
56*cdf0e10cSrcweir     private Locale aLocale;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     public FieldDescription(XMultiServiceFactory _xMSF, Locale _aLocale, ScenarioSelector _curscenarioselector, String _fieldname, String _keyname, int _nmaxcharCount)
59*cdf0e10cSrcweir     {
60*cdf0e10cSrcweir         xMSF = _xMSF;
61*cdf0e10cSrcweir         aLocale = _aLocale;
62*cdf0e10cSrcweir         tablename = _curscenarioselector.getTableName();
63*cdf0e10cSrcweir         Name = _fieldname;
64*cdf0e10cSrcweir         keyname = _keyname;
65*cdf0e10cSrcweir         aPropertyValues = new Vector();
66*cdf0e10cSrcweir         xNameAccessTableNode = _curscenarioselector.oCGTable.xNameAccessFieldsNode;
67*cdf0e10cSrcweir         XNameAccess xNameAccessFieldNode;
68*cdf0e10cSrcweir         if (_curscenarioselector.bcolumnnameislimited)
69*cdf0e10cSrcweir         {
70*cdf0e10cSrcweir             xNameAccessFieldNode = Configuration.getChildNodebyDisplayName(xMSF, aLocale, xNameAccessTableNode, keyname, "ShortName", _nmaxcharCount);
71*cdf0e10cSrcweir         }
72*cdf0e10cSrcweir         else
73*cdf0e10cSrcweir         {
74*cdf0e10cSrcweir             xNameAccessFieldNode = Configuration.getChildNodebyDisplayName(xMSF, aLocale, xNameAccessTableNode, keyname, PropertyNames.PROPERTY_NAME, _nmaxcharCount);
75*cdf0e10cSrcweir         }
76*cdf0e10cSrcweir         setFieldProperties(xNameAccessFieldNode);
77*cdf0e10cSrcweir     }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     public FieldDescription(String _fieldname)
80*cdf0e10cSrcweir     {
81*cdf0e10cSrcweir         Name = _fieldname;
82*cdf0e10cSrcweir         aPropertyValues = new Vector();
83*cdf0e10cSrcweir         Type = new Integer(com.sun.star.sdbc.DataType.VARCHAR);
84*cdf0e10cSrcweir         aPropertyValues.addElement(Properties.createProperty(PropertyNames.PROPERTY_NAME, _fieldname));
85*cdf0e10cSrcweir         aPropertyValues.addElement(Properties.createProperty("Type", Type));
86*cdf0e10cSrcweir     }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     public void setName(String _newfieldname)
89*cdf0e10cSrcweir     {
90*cdf0e10cSrcweir         for (int i = 0; i < aPropertyValues.size(); i++)
91*cdf0e10cSrcweir         {
92*cdf0e10cSrcweir             PropertyValue aPropertyValue = (PropertyValue) aPropertyValues.get(i);
93*cdf0e10cSrcweir             if (aPropertyValue.Name.equals(PropertyNames.PROPERTY_NAME))
94*cdf0e10cSrcweir             {
95*cdf0e10cSrcweir                 aPropertyValue.Value = _newfieldname;
96*cdf0e10cSrcweir                 aPropertyValues.set(i, aPropertyValue);
97*cdf0e10cSrcweir                 Name = _newfieldname;
98*cdf0e10cSrcweir                 return;
99*cdf0e10cSrcweir             }
100*cdf0e10cSrcweir         }
101*cdf0e10cSrcweir     }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     public String getName()
104*cdf0e10cSrcweir     {
105*cdf0e10cSrcweir         return Name;
106*cdf0e10cSrcweir     }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     public String gettablename()
109*cdf0e10cSrcweir     {
110*cdf0e10cSrcweir         return tablename;
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     private boolean propertyexists(String _propertyname)
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         boolean bexists = false;
116*cdf0e10cSrcweir         try
117*cdf0e10cSrcweir         {
118*cdf0e10cSrcweir             if (xPropertySet.getPropertySetInfo().hasPropertyByName(_propertyname))
119*cdf0e10cSrcweir             {
120*cdf0e10cSrcweir                 Object oValue = xPropertySet.getPropertyValue(_propertyname);
121*cdf0e10cSrcweir                 bexists = (!com.sun.star.uno.AnyConverter.isVoid(oValue));
122*cdf0e10cSrcweir             }
123*cdf0e10cSrcweir         }
124*cdf0e10cSrcweir         catch (Exception e)
125*cdf0e10cSrcweir         {
126*cdf0e10cSrcweir             e.printStackTrace(System.out);
127*cdf0e10cSrcweir         }
128*cdf0e10cSrcweir         return bexists;
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     public void setFieldProperties(XNameAccess _xNameAccessFieldNode)
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         try
134*cdf0e10cSrcweir         {
135*cdf0e10cSrcweir             xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, _xNameAccessFieldNode);
136*cdf0e10cSrcweir //      Integer Index = (Integer) xPropertySet.getPropertyValue("Index");
137*cdf0e10cSrcweir             if (propertyexists(PropertyNames.PROPERTY_NAME))
138*cdf0e10cSrcweir             {
139*cdf0e10cSrcweir                 aPropertyValues.addElement(Properties.createProperty(PropertyNames.PROPERTY_NAME, Name));
140*cdf0e10cSrcweir             }
141*cdf0e10cSrcweir             if (propertyexists("Type"))
142*cdf0e10cSrcweir             {
143*cdf0e10cSrcweir                 aPropertyValues.addElement(Properties.createProperty("Type", xPropertySet.getPropertyValue("Type")));
144*cdf0e10cSrcweir             }
145*cdf0e10cSrcweir             if (propertyexists("Scale"))
146*cdf0e10cSrcweir             {
147*cdf0e10cSrcweir                 aPropertyValues.addElement(Properties.createProperty("Scale", xPropertySet.getPropertyValue("Scale")));
148*cdf0e10cSrcweir //          Scale =
149*cdf0e10cSrcweir             }
150*cdf0e10cSrcweir             if (propertyexists("Precision"))
151*cdf0e10cSrcweir             {
152*cdf0e10cSrcweir                 aPropertyValues.addElement(Properties.createProperty("Precision", xPropertySet.getPropertyValue("Precision")));
153*cdf0e10cSrcweir //          Precision = (Integer) xPropertySet.getPropertyValue("Precision");
154*cdf0e10cSrcweir             }
155*cdf0e10cSrcweir             if (propertyexists("DefaultValue"))
156*cdf0e10cSrcweir             {
157*cdf0e10cSrcweir                 aPropertyValues.addElement(Properties.createProperty("DefaultValue", xPropertySet.getPropertyValue("DefaultValue")));//          DefaultValue = (Boolean) xPropertySet.getPropertyValue("DefaultValue");
158*cdf0e10cSrcweir             //Type =  4; // TODO wo ist der Fehler?(Integer) xPropertySet.getPropertyValue("Type");
159*cdf0e10cSrcweir             }
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir         catch (Exception e)
162*cdf0e10cSrcweir         {
163*cdf0e10cSrcweir             e.printStackTrace(System.out);
164*cdf0e10cSrcweir         }
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     public PropertyValue[] getPropertyValues()
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir         if (aPropertyValues != null)
170*cdf0e10cSrcweir         {
171*cdf0e10cSrcweir             PropertyValue[] aProperties = new PropertyValue[aPropertyValues.size()];
172*cdf0e10cSrcweir             aPropertyValues.toArray(aProperties);
173*cdf0e10cSrcweir             return aProperties;
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir         return null;
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir }
178