1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.wizards.table; 24 25 import java.util.Vector; 26 27 import com.sun.star.beans.PropertyValue; 28 import com.sun.star.beans.XPropertySet; 29 import com.sun.star.container.XNameAccess; 30 import com.sun.star.lang.Locale; 31 import com.sun.star.lang.XMultiServiceFactory; 32 import com.sun.star.uno.UnoRuntime; 33 import com.sun.star.wizards.common.Configuration; 34 import com.sun.star.wizards.common.Properties; 35 import com.sun.star.wizards.common.PropertyNames; 36 37 public class FieldDescription 38 { 39 private String tablename = PropertyNames.EMPTY_STRING; 40 // String fieldname; 41 private String keyname; 42 private XNameAccess xNameAccessTableNode; 43 private XPropertySet xPropertySet; 44 private Vector aPropertyValues; 45 // PropertyValue[] aPropertyValues; 46 private Integer Type; 47 private Integer Scale; 48 private Integer Precision; 49 private Boolean DefaultValue; 50 private String Name; 51 private XMultiServiceFactory xMSF; 52 private Locale aLocale; 53 FieldDescription(XMultiServiceFactory _xMSF, Locale _aLocale, ScenarioSelector _curscenarioselector, String _fieldname, String _keyname, int _nmaxcharCount)54 public FieldDescription(XMultiServiceFactory _xMSF, Locale _aLocale, ScenarioSelector _curscenarioselector, String _fieldname, String _keyname, int _nmaxcharCount) 55 { 56 xMSF = _xMSF; 57 aLocale = _aLocale; 58 tablename = _curscenarioselector.getTableName(); 59 Name = _fieldname; 60 keyname = _keyname; 61 aPropertyValues = new Vector(); 62 xNameAccessTableNode = _curscenarioselector.oCGTable.xNameAccessFieldsNode; 63 XNameAccess xNameAccessFieldNode; 64 if (_curscenarioselector.bcolumnnameislimited) 65 { 66 xNameAccessFieldNode = Configuration.getChildNodebyDisplayName(xMSF, aLocale, xNameAccessTableNode, keyname, "ShortName", _nmaxcharCount); 67 } 68 else 69 { 70 xNameAccessFieldNode = Configuration.getChildNodebyDisplayName(xMSF, aLocale, xNameAccessTableNode, keyname, PropertyNames.PROPERTY_NAME, _nmaxcharCount); 71 } 72 setFieldProperties(xNameAccessFieldNode); 73 } 74 FieldDescription(String _fieldname)75 public FieldDescription(String _fieldname) 76 { 77 Name = _fieldname; 78 aPropertyValues = new Vector(); 79 Type = new Integer(com.sun.star.sdbc.DataType.VARCHAR); 80 aPropertyValues.addElement(Properties.createProperty(PropertyNames.PROPERTY_NAME, _fieldname)); 81 aPropertyValues.addElement(Properties.createProperty("Type", Type)); 82 } 83 setName(String _newfieldname)84 public void setName(String _newfieldname) 85 { 86 for (int i = 0; i < aPropertyValues.size(); i++) 87 { 88 PropertyValue aPropertyValue = (PropertyValue) aPropertyValues.get(i); 89 if (aPropertyValue.Name.equals(PropertyNames.PROPERTY_NAME)) 90 { 91 aPropertyValue.Value = _newfieldname; 92 aPropertyValues.set(i, aPropertyValue); 93 Name = _newfieldname; 94 return; 95 } 96 } 97 } 98 getName()99 public String getName() 100 { 101 return Name; 102 } 103 gettablename()104 public String gettablename() 105 { 106 return tablename; 107 } 108 propertyexists(String _propertyname)109 private boolean propertyexists(String _propertyname) 110 { 111 boolean bexists = false; 112 try 113 { 114 if (xPropertySet.getPropertySetInfo().hasPropertyByName(_propertyname)) 115 { 116 Object oValue = xPropertySet.getPropertyValue(_propertyname); 117 bexists = (!com.sun.star.uno.AnyConverter.isVoid(oValue)); 118 } 119 } 120 catch (Exception e) 121 { 122 e.printStackTrace(System.out); 123 } 124 return bexists; 125 } 126 setFieldProperties(XNameAccess _xNameAccessFieldNode)127 public void setFieldProperties(XNameAccess _xNameAccessFieldNode) 128 { 129 try 130 { 131 xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, _xNameAccessFieldNode); 132 // Integer Index = (Integer) xPropertySet.getPropertyValue("Index"); 133 if (propertyexists(PropertyNames.PROPERTY_NAME)) 134 { 135 aPropertyValues.addElement(Properties.createProperty(PropertyNames.PROPERTY_NAME, Name)); 136 } 137 if (propertyexists("Type")) 138 { 139 aPropertyValues.addElement(Properties.createProperty("Type", xPropertySet.getPropertyValue("Type"))); 140 } 141 if (propertyexists("Scale")) 142 { 143 aPropertyValues.addElement(Properties.createProperty("Scale", xPropertySet.getPropertyValue("Scale"))); 144 // Scale = 145 } 146 if (propertyexists("Precision")) 147 { 148 aPropertyValues.addElement(Properties.createProperty("Precision", xPropertySet.getPropertyValue("Precision"))); 149 // Precision = (Integer) xPropertySet.getPropertyValue("Precision"); 150 } 151 if (propertyexists("DefaultValue")) 152 { 153 aPropertyValues.addElement(Properties.createProperty("DefaultValue", xPropertySet.getPropertyValue("DefaultValue")));// DefaultValue = (Boolean) xPropertySet.getPropertyValue("DefaultValue"); 154 //Type = 4; // TODO wo ist der Fehler?(Integer) xPropertySet.getPropertyValue("Type"); 155 } 156 } 157 catch (Exception e) 158 { 159 e.printStackTrace(System.out); 160 } 161 } 162 getPropertyValues()163 public PropertyValue[] getPropertyValues() 164 { 165 if (aPropertyValues != null) 166 { 167 PropertyValue[] aProperties = new PropertyValue[aPropertyValues.size()]; 168 aPropertyValues.toArray(aProperties); 169 return aProperties; 170 } 171 return null; 172 } 173 } 174