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