1*34dd1e25SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir import com.sun.star.beans.Property; 25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 26cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 27cdf0e10cSrcweir import com.sun.star.reflection.TypeDescriptionSearchDepth; 28cdf0e10cSrcweir import com.sun.star.reflection.XConstantTypeDescription; 29cdf0e10cSrcweir import com.sun.star.reflection.XPropertyTypeDescription; 30cdf0e10cSrcweir import com.sun.star.reflection.XServiceTypeDescription; 31cdf0e10cSrcweir import com.sun.star.reflection.XTypeDescription; 32cdf0e10cSrcweir import com.sun.star.reflection.XTypeDescriptionEnumeration; 33cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 34cdf0e10cSrcweir import com.sun.star.uno.TypeClass; 35cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 36cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 37cdf0e10cSrcweir import javax.swing.tree.DefaultMutableTreeNode; 38cdf0e10cSrcweir 39cdf0e10cSrcweir public class UnoPropertyNode extends UnoNode{ 40cdf0e10cSrcweir 41cdf0e10cSrcweir Property aProperty; 42cdf0e10cSrcweir PropertyValue aPropertyValue; 43cdf0e10cSrcweir String m_sPropertyName; 44cdf0e10cSrcweir Object m_oUnoReturnObject; 45cdf0e10cSrcweir private int m_nPropertyType = XUnoPropertyNode.nDEFAULT; 46cdf0e10cSrcweir private String sLabel = ""; 47cdf0e10cSrcweir 48cdf0e10cSrcweir private static XConstantTypeDescription[] xPropertyAttributesTypeDescriptions = null; 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir /** Creates a new instance of UnoMethodNode */ UnoPropertyNode(Property _aProperty, Object _oUnoObject, Object _oUnoReturnObject)52cdf0e10cSrcweir public UnoPropertyNode(Property _aProperty, Object _oUnoObject, Object _oUnoReturnObject) { 53cdf0e10cSrcweir super(_oUnoObject); 54cdf0e10cSrcweir aProperty = _aProperty; 55cdf0e10cSrcweir m_sPropertyName = aProperty.Name; 56cdf0e10cSrcweir m_oUnoReturnObject = _oUnoReturnObject; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir UnoPropertyNode(Property _aProperty)60cdf0e10cSrcweir public UnoPropertyNode(Property _aProperty){ 61cdf0e10cSrcweir super(null); 62cdf0e10cSrcweir aProperty = _aProperty; 63cdf0e10cSrcweir m_sPropertyName = aProperty.Name; 64cdf0e10cSrcweir m_oUnoReturnObject = null; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir UnoPropertyNode(PropertyValue _aPropertyValue, Object _oUnoObject, Object _oUnoReturnObject)67cdf0e10cSrcweir public UnoPropertyNode(PropertyValue _aPropertyValue, Object _oUnoObject, Object _oUnoReturnObject) { 68cdf0e10cSrcweir super(_oUnoObject); 69cdf0e10cSrcweir m_oUnoReturnObject = _oUnoReturnObject; 70cdf0e10cSrcweir aPropertyValue = _aPropertyValue; 71cdf0e10cSrcweir m_sPropertyName = aPropertyValue.Name; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir getPropertyNodeType()75cdf0e10cSrcweir public int getPropertyNodeType(){ 76cdf0e10cSrcweir return m_nPropertyType; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir setPropertyNodeType(int _nPropertyType)80cdf0e10cSrcweir public void setPropertyNodeType(int _nPropertyType){ 81cdf0e10cSrcweir m_nPropertyType = _nPropertyType; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir getPropertyName()85cdf0e10cSrcweir public String getPropertyName(){ 86cdf0e10cSrcweir return m_sPropertyName; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir getName()89cdf0e10cSrcweir public String getName(){ 90cdf0e10cSrcweir return this.m_sPropertyName; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir getClassName()94cdf0e10cSrcweir public String getClassName(){ 95cdf0e10cSrcweir String sClassName = ""; 96cdf0e10cSrcweir if (m_oUnoObject != null){ 97cdf0e10cSrcweir XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, m_oUnoObject); 98cdf0e10cSrcweir if (xServiceInfo != null){ 99cdf0e10cSrcweir String[] sServiceNames = xServiceInfo.getSupportedServiceNames(); 100cdf0e10cSrcweir for (int i = 0; i < sServiceNames.length; i++){ 101cdf0e10cSrcweir if (doesServiceSupportProperty(sServiceNames[i], m_sPropertyName)){ 102cdf0e10cSrcweir sClassName = sServiceNames[i]; 103cdf0e10cSrcweir break; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir } 108cdf0e10cSrcweir else{ 109cdf0e10cSrcweir sClassName = "com.sun.star.beans.Property"; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir return sClassName; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir getAnchor()115cdf0e10cSrcweir public String getAnchor(){ 116cdf0e10cSrcweir return m_sPropertyName; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir 120cdf0e10cSrcweir doesServiceSupportProperty(String _sServiceName, String _sPropertyName)121cdf0e10cSrcweir protected boolean doesServiceSupportProperty(String _sServiceName, String _sPropertyName){ 122cdf0e10cSrcweir try { 123cdf0e10cSrcweir XPropertyTypeDescription[] xPropertyTypeDescriptions = Introspector.getIntrospector().getPropertyDescriptionsOfService(_sServiceName); 124cdf0e10cSrcweir for (int i = 0; i < xPropertyTypeDescriptions.length; i++){ 125cdf0e10cSrcweir if (xPropertyTypeDescriptions[i].getName().equals(_sServiceName + "." + _sPropertyName)){ 126cdf0e10cSrcweir return true; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir } 129cdf0e10cSrcweir } catch ( java.lang.Exception e) { 130cdf0e10cSrcweir System.out.println(System.out); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir return false; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir getUnoReturnObject()136cdf0e10cSrcweir public Object getUnoReturnObject(){ 137cdf0e10cSrcweir return m_oUnoReturnObject; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir isPrimitive()141cdf0e10cSrcweir private boolean isPrimitive(){ 142cdf0e10cSrcweir boolean bIsPrimitive = true; 143cdf0e10cSrcweir if (getUnoReturnObject() != null){ 144cdf0e10cSrcweir if (getProperty() != null){ 145cdf0e10cSrcweir bIsPrimitive = Introspector.isObjectPrimitive(getUnoReturnObject().getClass(), getProperty().Type.getTypeClass()); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir else{ 148cdf0e10cSrcweir bIsPrimitive = Introspector.isObjectPrimitive(getUnoReturnObject().getClass()); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir } 151cdf0e10cSrcweir else{ 152cdf0e10cSrcweir bIsPrimitive = Introspector.isObjectPrimitive(aProperty.Type.getTypeClass()); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir return bIsPrimitive; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir isFoldable()158cdf0e10cSrcweir protected boolean isFoldable(){ 159cdf0e10cSrcweir boolean bIsFoldable = false; 160cdf0e10cSrcweir if (! isPrimitive()){ 161cdf0e10cSrcweir String sTypeName = getUnoReturnObject().getClass().getName(); 162cdf0e10cSrcweir bIsFoldable = (!sTypeName.equals("com.sun.star.uno.Type")); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir return bIsFoldable; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir getLabel()168cdf0e10cSrcweir protected String getLabel(){ 169cdf0e10cSrcweir if (!sLabel.equals("")){ 170cdf0e10cSrcweir if (! isPrimitive()){ 171cdf0e10cSrcweir if (isFoldable()){ 172cdf0e10cSrcweir sLabel = getPropertyTypeDescription(aProperty, getUnoReturnObject()); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir else{ 175cdf0e10cSrcweir sLabel = getStandardPropertyDescription(aProperty, getUnoReturnObject()); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir else { 179cdf0e10cSrcweir sLabel = getStandardPropertyDescription(aProperty, getUnoReturnObject()); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir return sLabel; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir getProperty()185cdf0e10cSrcweir public Property getProperty(){ 186cdf0e10cSrcweir return aProperty; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir getPropertyTypeDescription(Property _aProperty, Object _oUnoObject)189cdf0e10cSrcweir protected static String getPropertyTypeDescription(Property _aProperty, Object _oUnoObject){ 190cdf0e10cSrcweir return _aProperty.Type.getTypeName() + " " + _aProperty.Name + " = " + _oUnoObject.toString(); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir getStandardPropertyDescription(Property _aProperty, Object _objectElement)194cdf0e10cSrcweir protected static String getStandardPropertyDescription(Property _aProperty, Object _objectElement){ 195cdf0e10cSrcweir if (!Introspector.isObjectPrimitive(_objectElement)){ 196cdf0e10cSrcweir return _aProperty.Name + " = (" + _aProperty.Type.getTypeName() + ") "; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir else{ 199cdf0e10cSrcweir return _aProperty.Name + " (" + _aProperty.Type.getTypeName() + ") = " + getDisplayValueOfPrimitiveType(_objectElement); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir getStandardPropertyValueDescription(PropertyValue _aPropertyValue)204cdf0e10cSrcweir protected static String getStandardPropertyValueDescription(PropertyValue _aPropertyValue){ 205cdf0e10cSrcweir if (!Introspector.isObjectPrimitive(_aPropertyValue.Value)){ 206cdf0e10cSrcweir return _aPropertyValue.Name; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir else{ 209cdf0e10cSrcweir return _aPropertyValue.Name + " : " + UnoNode.getDisplayValueOfPrimitiveType(_aPropertyValue.Value); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir } 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir 215