incubator-ooo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fernand Vanrie <...@pmgroup.be>
Subject Re: [API] Problem with currency formatter in text field
Date Mon, 27 Aug 2012 09:48:55 GMT
  Carsten ,

you need a "refresch" off the field ?

hope it helps

Fernand
> Hello, i have a problem with formatting of a text field. I create a 
> text field in Java and insert this in a document.
> The content is 0.0 and the format is the default currency. But the 
> content is not formatted. The document show me 0.0 and not 0,00 €.
> Why?
>
>     private void setTextField(Object[] value)
>     {
>         try
>         {
>             XTextDocument xTextDocument = (XTextDocument) 
> UnoRuntime.queryInterface(XTextDocument.class, oBean.getDocument());
>             XController xController = 
> xTextDocument.getCurrentController();
>             XTextViewCursorSupplier xTextViewCursorSupplier = 
> (XTextViewCursorSupplier) 
> UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController);
>             XTextViewCursor xDocTextCursor = 
> xTextViewCursorSupplier.getViewCursor();
>
>             XText xText = xDocTextCursor.getText();
>
>             xText.insertTextContent(xDocTextCursor, 
> createTextField(xTextDocument, (String) value[2], (String) value[1]), 
> false);
>         }
>         catch (Exception e)
>         {
>             logger.error(e);
>         }
>     }
>
> private XDependentTextField createTextField(XTextDocument 
> xTextDocument, String fieldName, String fieldValue)
>     {
>         XMultiServiceFactory xMultiServiceFactory = 
> (XMultiServiceFactory) 
> UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
>         XTextFieldsSupplier xTextFieldsSupplier = 
> (XTextFieldsSupplier) 
> UnoRuntime.queryInterface(XTextFieldsSupplier.class, xTextDocument);
>         XNameAccess xNamedFieldMasters = 
> xTextFieldsSupplier.getTextFieldMasters();
>         XDependentTextField userField = null;
>         XPropertySet masterPropSet = null;
>
>         try
>         {
>             // Create the field...
>             userField = (XDependentTextField) 
> UnoRuntime.queryInterface(XDependentTextField.class, 
> xMultiServiceFactory.createInstance("com.sun.star.text.TextField.User"));
>
>             if 
> (!xNamedFieldMasters.hasByName("com.sun.star.text.FieldMaster.User." + 
> fieldName))
>             {
>                 // Create the field master...
>                 masterPropSet = (XPropertySet) 
> UnoRuntime.queryInterface(XPropertySet.class, 
> xMultiServiceFactory.createInstance("com.sun.star.text.FieldMaster.User"));
>
>                 // Set the field name and content...
>                 masterPropSet.setPropertyValue("Name", fieldName);
>                 masterPropSet.setPropertyValue("Content", fieldValue);
>
>                 if (fieldValue.equals("0.0"))
>                 {
>                     // Query the number formats supplier of the document
>                     com.sun.star.util.XNumberFormatsSupplier 
> xNumberFormatsSupplier = (com.sun.star.util.XNumberFormatsSupplier) 
> UnoRuntime.queryInterface(com.sun.star.util.XNumberFormatsSupplier.class, 
> xTextDocument);
>
>                     // Get the number formats from the supplier
>                     com.sun.star.util.XNumberFormats xNumberFormats = 
> xNumberFormatsSupplier.getNumberFormats();
>
>                     // Query the XNumberFormatTypes interface
>                     com.sun.star.util.XNumberFormatTypes 
> xNumberFormatTypes = (com.sun.star.util.XNumberFormatTypes) 
> UnoRuntime.queryInterface(com.sun.star.util.XNumberFormatTypes.class, 
> xNumberFormats);
>
>                     // Get the number format index key of the default 
> currency
>                     // format,
>                     // note the empty locale for default locale
>                     com.sun.star.lang.Locale aLocale = new 
> com.sun.star.lang.Locale();
>                     int nCurrencyKey = 
> xNumberFormatTypes.getStandardFormat(com.sun.star.util.NumberFormat.CURRENCY, 
> aLocale);
>
>                     XPropertySet fieldProperties = (XPropertySet) 
> UnoRuntime.queryInterface(XPropertySet.class, userField);
> fieldProperties.setPropertyValue("NumberFormat", new 
> Integer(nCurrencyKey));
>
>                 }
>             }
>             else
>             {
>                 masterPropSet = (XPropertySet) 
> UnoRuntime.queryInterface(XPropertySet.class, 
> xNamedFieldMasters.getByName("com.sun.star.text.FieldMaster.User." + 
> fieldName));
>             }
>
>             // Attach the fieldmaster to the field...
>             userField.attachTextFieldMaster(masterPropSet);
>         }
>         catch (java.lang.Exception e)
>         {
>              logger.error(e);
>         }
>         return userField;
>     }
>
> Kind regrads
> Carsten
>
>
>


Mime
View raw message