/** * creates a column in a grid * * @param xGridModel specifies the model of the grid where the new column should be inserted * @param sColumnService specifies the service name of the column to create (e.g. "NumericField") * @param sDataField specifies the database field to which the column should be bound * @param nWidth specifies the column width (in mm). If 0, no width is set. * @return the newly created column */ XPropertySet createGridColumn( Object aGridModel, String sColumnService, String sDataField, int nWidth) throws com.sun.star.uno.Exception { // the container to insert columns into XIndexContainer xColumnContainer = UNO.queryIndexContainer(aGridModel); // the factory for creating column models XGridColumnFactory xColumnFactory = UnoRuntime.queryInterface(XGridColumnFactory.class, aGridModel); // (let) create the new col XInterface xNewCol = xColumnFactory.createColumn(sColumnService); XPropertySet xColProps = UNO.queryPropertySet(xNewCol); // some props // the field the column is bound to xColProps.setPropertyValue("DataField", sDataField); // the "display name" of the column xColProps.setPropertyValue("Label", sDataField); // the name of the column within its parent xColProps.setPropertyValue("Name", sDataField); if (nWidth > 0) xColProps.setPropertyValue("Width", Integer.valueOf(nWidth * 10)); // insert xColumnContainer.insertByIndex(xColumnContainer.getCount(), xNewCol); // outta here return xColProps; }
/** * Makes a string unique by appending a numerical suffix. * * @param elementContainer The container the new element is going to be inserted to * @param elementName The name of the element */ public XTextComponent insertTextFrame(int posX, int posY, int width, String text) throws Exception { // Create a unique name String uniqueName = createUniqueName(xDialogModelNameContainer, "TextFrame"); // Create an editable text field control model Object oTextFrameModel = xMultiComponentFactoryDialogModel.createInstance("com.sun.star.text.TextFrame"); // Set the properties at the model XPropertySet xTextFramePropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTextFrameModel); xTextFramePropertySet.setPropertyValue("PositionX", new Integer(posX)); xTextFramePropertySet.setPropertyValue("PositionY", new Integer(posY)); xTextFramePropertySet.setPropertyValue("Height", new Integer(12)); xTextFramePropertySet.setPropertyValue("Width", new Integer(width)); xTextFramePropertySet.setPropertyValue("Text", (text != null) ? text : ""); xTextFramePropertySet.setPropertyValue("Name", uniqueName); // Add the model to the dialog model name container xDialogModelNameContainer.insertByName(uniqueName, xTextFramePropertySet); // Reference the control by the unique name XControl xEditableTextFieldControl = xDialogContainer.getControl(uniqueName); return (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xEditableTextFieldControl); }
/* ------------------------------------------------------------------ */ private void insertRadio(int nYPos, String label, String refValue) throws com.sun.star.uno.Exception, java.lang.Exception { XPropertySet xRadio = m_formLayer.createControlAndShape("DatabaseRadioButton", 106, nYPos, 25, 6); xRadio.setPropertyValue("Label", label); xRadio.setPropertyValue("RefValue", refValue); xRadio.setPropertyValue("Name", new String("radio_group")); xRadio.setPropertyValue("DataField", new String("f_text_enum")); }
/** * Check BackColor and IsLandscape properties, wait for an exception: test is ok if no exception * happened. */ public void checkChangeColor() { try { XMultiServiceFactory m_xMSF_ = (XMultiServiceFactory) param.getMSF(); XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface( XComponentLoader.class, m_xMSF_.createInstance("com.sun.star.frame.Desktop")); XComponent xDocument = (XComponent) UnoRuntime.queryInterface( XComponent.class, aLoader.loadComponentFromURL( "private:factory/swriter", "_blank", 0, new PropertyValue[0])); // xDocument.addEventListener( this ); XTextDocument oDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xDocument); XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); // XInterface xInterface = (XInterface) oDocMSF.createInstance( "com.sun.star.style.PageStyle" // ); // create a supplier to get the Style family collection XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, oDoc); // get the NameAccess interface from the Style family collection XNameAccess xNameAccess = xSupplier.getStyleFamilies(); XNameContainer xPageStyleCollection = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xNameAccess.getByName("PageStyles")); // create a PropertySet to set the properties for the new Pagestyle XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xPageStyleCollection.getByName("Standard")); log.println("BackColor @ " + xPropertySet.getPropertyValue("BackColor").toString()); log.println("IsLandscape @ " + xPropertySet.getPropertyValue("IsLandscape").toString()); log.println( "Size @ H:" + ((Size) xPropertySet.getPropertyValue("Size")).Height + " W:" + ((Size) xPropertySet.getPropertyValue("Size")).Width); log.println("Set Landscape"); xPropertySet.setPropertyValue("IsLandscape", new Boolean(true)); log.println("Set BackColor"); xPropertySet.setPropertyValue("BackColor", new Integer((int) 255000000)); } catch (Exception e) { e.printStackTrace(); failed("Exception."); } }
/// some tests with the image control public void checkImageControl() throws com.sun.star.uno.Exception, java.lang.Exception { // since we did not yet insert any image, the control should not display one ... moveToFirst(); if (!verifyReferenceImage(new byte[0])) { failed("image control failed to display empty image"); return; } // check if the image control is able to insert our sample image into the database // insert an XPropertySet xImageModel = getControlModel("f_blob"); xImageModel.setPropertyValue("ImageURL", m_sImageURL); if (!verifyReferenceImage(getSamplePictureBytes())) { failed("image control does not display the sample image as required"); return; } // save the record saveRecordByUI(); // still needs to be the sample image if (!verifyReferenceImage(getSamplePictureBytes())) { failed( "image control does not, after saving the record, display the sample image as required"); return; } // on the next record, the image should be empty moveToNext(); if (!verifyReferenceImage(new byte[0])) { failed("image control failed to display empty image, after coming from a non-empty image"); return; } // back to the record where we just inserted the image, it should be our sample image moveToFirst(); if (!verifyReferenceImage(getSamplePictureBytes())) { failed( "image control does not, after coming back to the record, display the sample image as required"); return; } // okay, now remove the image xImageModel.setPropertyValue("ImageURL", new String()); if (!verifyReferenceImage(new byte[0])) { failed("image control failed to remove the image"); return; } nextRecordByUI(); previousRecordByUI(); if (!verifyReferenceImage(new byte[0])) { failed("image still there after coming back, though we just removed it"); return; } }
public boolean WriteBytesToStream( XStream xStream, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes) { // get output stream of substream XOutputStream xOutput = xStream.getOutputStream(); if (xOutput == null) { Error("Can't get XOutputStream implementation from substream '" + sStreamName + "'!"); return false; } // get XTrucate implementation from output stream XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface(XTruncate.class, xOutput); if (xTruncate == null) { Error("Can't get XTruncate implementation from substream '" + sStreamName + "'!"); return false; } // write requested byte sequence try { xTruncate.truncate(); xOutput.writeBytes(pBytes); } catch (Exception e) { Error("Can't write to stream '" + sStreamName + "', exception: " + e); return false; } // get access to the XPropertySet interface XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStream); if (xPropSet == null) { Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!"); return false; } // set properties to the stream try { xPropSet.setPropertyValue("MediaType", sMediaType); xPropSet.setPropertyValue("Compressed", new Boolean(bCompressed)); } catch (Exception e) { Error("Can't set properties to substream '" + sStreamName + "', exception: " + e); return false; } // check size property of the stream try { long nSize = AnyConverter.toLong(xPropSet.getPropertyValue("Size")); if (nSize != pBytes.length) { Error("The 'Size' property of substream '" + sStreamName + "' contains wrong value!"); return false; } } catch (Exception e) { Error("Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e); return false; } return true; }
public void handle(XInteractionRequest xInteractionRequest) { log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called."); handlerWasUsed = true; Object o = xInteractionRequest.getRequest(); ParametersRequest req = (ParametersRequest) o; XIndexAccess params = req.Parameters; int count = params.getCount(); try { for (int i = 0; i < count; i++) { params.getByIndex(i); log.println( "### _XCompletedExecution.InteractionHandlerImpl: Parameter " + i + ": " + params.getByIndex(i)); XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i)); log.println( "### _XCompletedExecution.InteractionHandlerImpl: Parameter Name: '" + xProp.getPropertyValue("Name") + "' is set to Value '1'"); xProp.setPropertyValue("Value", new Integer(1)); handlerWasUsed = true; } } catch (Exception eI) { log.println("### _XCompletedExecution.InteractionHandlerImpl: Exception!"); eI.printStackTrace(log); } }
public boolean setStorageTypeAndCheckProps( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode) { boolean bOk = false; // get access to the XPropertySet interface XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xStorage); if (xPropSet != null) { try { // set "MediaType" property to the stream xPropSet.setPropertyValue("MediaType", sMediaType); // get "IsRoot" and "OpenMode" properties and control there values boolean bPropIsRoot = AnyConverter.toBoolean(xPropSet.getPropertyValue("IsRoot")); int nPropMode = AnyConverter.toInt(xPropSet.getPropertyValue("OpenMode")); bOk = true; if (bPropIsRoot != bIsRoot) { Error("'IsRoot' property contains wrong value!"); bOk = false; } if ((bIsRoot && (nPropMode | ElementModes.READ) != (nMode | ElementModes.READ)) || (!bIsRoot && (nPropMode & nMode) != nMode)) { Error("'OpenMode' property contains wrong value!"); bOk = false; } } catch (Exception e) { Error("Can't control properties of substorage, exception: " + e); } } else { Error("Can't get XPropertySet implementation from storage!"); } return bOk; }
public void changeProp(String name) { Object gValue = null; Object sValue = null; Object ValueToSet = null; try { // waitForAllThreads(); gValue = oObj.getPropertyValue(name); // waitForAllThreads(); if ((name.equals("LineEnd")) || (name.equals("LineStart"))) { if (gValue == null) gValue = newPoints(null); ValueToSet = newPoints((Point[]) gValue); } else { ValueToSet = ValueChanger.changePValue(gValue); } // waitForAllThreads(); oObj.setPropertyValue(name, ValueToSet); sValue = oObj.getPropertyValue(name); // check get-set methods if (gValue.equals(sValue)) { log.println("Value for '" + name + "' hasn't changed"); tRes.tested(name, false); } else { log.println("Property '" + name + "' OK"); tRes.tested(name, true); } } catch (Exception e) { log.println("Exception occurred while testing property '" + name + "'"); e.printStackTrace(log); tRes.tested(name, false); } } // end of ChangeProp
/** * Take the DataBaseParameterEvent and fill it with a meaningful value. * * @param e The database parameter that will be filled with a value. * @return True, if the value could be filled. */ public boolean approveParameter(DatabaseParameterEvent e) { log.println("### ParameterListenerImpl: approve called."); XIndexAccess params = e.Parameters; int count = params.getCount(); try { for (int i = 0; i < count; i++) { log.println( "### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter " + i + ": " + params.getByIndex(i)); XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i)); log.println( "### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter Name: '" + xProp.getPropertyValue("Name") + "' is set to Value '1'"); xProp.setPropertyValue("Value", new Integer(1)); listenerWasCalled = true; } } catch (Exception eI) { log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Exception!"); eI.printStackTrace(log); return false; } return true; }
public static XControlShape createGrid(XComponent oDoc, int height, int width, int x, int y) { Size size = new Size(); Point position = new Point(); XControlShape oCShape = null; XControlModel aControl = null; // get MSF XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); try { Object oInt = oDocMSF.createInstance("com.sun.star.drawing.ControlShape"); Object aCon = oDocMSF.createInstance("com.sun.star.form.component.GridControl"); XPropertySet model_props = UnoRuntime.queryInterface(XPropertySet.class, aCon); model_props.setPropertyValue( "DefaultControl", "com.sun.star.form.control.InteractionGridControl"); aControl = UnoRuntime.queryInterface(XControlModel.class, aCon); oCShape = UnoRuntime.queryInterface(XControlShape.class, oInt); size.Height = height; size.Width = width; position.X = x; position.Y = y; oCShape.setSize(size); oCShape.setPosition(position); } catch (com.sun.star.uno.Exception e) { // Some exception occurs.FAILED System.out.println("Couldn't create Grid" + e); throw new StatusException("Couldn't create Grid", e); } oCShape.setControl(aControl); return oCShape; } // finish createGrid
/* ------------------------------------------------------------------ */ private boolean ensureDataSource() throws Exception { m_orb = (XMultiServiceFactory) param.getMSF(); XNameAccess databaseContext = UnoRuntime.queryInterface( XNameAccess.class, m_orb.createInstance("com.sun.star.sdb.DatabaseContext")); XNamingService namingService = UnoRuntime.queryInterface(XNamingService.class, databaseContext); // revoke the data source, if it previously existed if (databaseContext.hasByName(m_dataSourceName)) namingService.revokeObject(m_dataSourceName); // // create a new ODB file, and register it with its URL m_databaseDocument = new HsqlDatabase(m_orb); String documentURL = m_databaseDocument.getDocumentURL(); namingService.registerObject(m_dataSourceName, databaseContext.getByName(documentURL)); m_dataSource = UnoRuntime.queryInterface(XDataSource.class, databaseContext.getByName(m_dataSourceName)); m_dataSourceProps = dbfTools.queryPropertySet(m_dataSource); XPropertySet dataSourceSettings = UnoRuntime.queryInterface( XPropertySet.class, m_dataSourceProps.getPropertyValue("Settings")); dataSourceSettings.setPropertyValue("FormsCheckRequiredFields", new Boolean(false)); return m_dataSource != null; }
private XTextComponent insertTextField( int posX, int posY, int width, int height, String text, char echoChar) throws Exception { // Create a unique name String uniqueName = createUniqueName(xDialogModelNameContainer, "TextField"); // Create an editable text field control model Object oTextFieldModel = xMultiComponentFactoryDialogModel.createInstance("com.sun.star.awt.UnoControlEditModel"); // Set the properties at the model XPropertySet xTextFieldPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTextFieldModel); xTextFieldPropertySet.setPropertyValue("PositionX", new Integer(posX)); xTextFieldPropertySet.setPropertyValue("PositionY", new Integer(posY)); xTextFieldPropertySet.setPropertyValue("Height", new Integer(height)); xTextFieldPropertySet.setPropertyValue("Width", new Integer(width)); xTextFieldPropertySet.setPropertyValue("Text", (text != null) ? text : ""); xTextFieldPropertySet.setPropertyValue("Name", uniqueName); xTextFieldPropertySet.setPropertyValue("MultiLine", false); xTextFieldPropertySet.setPropertyValue("ReadOnly", false); if (echoChar != 0 && echoChar != ' ') { // Useful for password fields xTextFieldPropertySet.setPropertyValue("EchoChar", new Short((short) echoChar)); } // Add the model to the dialog model name container xDialogModelNameContainer.insertByName(uniqueName, oTextFieldModel); // Reference the control by the unique name XControl xTextFieldControl = xDialogContainer.getControl(uniqueName); return (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xTextFieldControl); }
public void before() throws Exception { m_database = new CsvDatabase((XMultiServiceFactory) param.getMSF()); // proper settings final XPropertySet dataSourceSettings = m_database.getDataSource().geSettings(); dataSourceSettings.setPropertyValue("Extension", "csv"); dataSourceSettings.setPropertyValue("HeaderLine", Boolean.TRUE); dataSourceSettings.setPropertyValue("FieldDelimiter", " "); m_database.store(); // write the table(s) for our test final String tableLocation = m_database.getTableFileLocation().getAbsolutePath(); final PrintWriter tableWriter = new PrintWriter( new FileOutputStream(tableLocation + File.separatorChar + "dates.csv", false)); tableWriter.println("ID date"); tableWriter.println("1 2013-01-01"); tableWriter.println("2 2012-02-02"); tableWriter.println("3 2011-03-03"); tableWriter.close(); }
public Object insertButton( int posX, int posY, int width, String label, int pushButtonType, boolean enabled, String uniqueName) throws Exception { // Create a button control model Object oButtonModel = xMultiComponentFactoryDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel"); // Set the properties at the model XPropertySet xButtonPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oButtonModel); xButtonPropertySet.setPropertyValue("PositionX", new Integer(posX)); xButtonPropertySet.setPropertyValue("PositionY", new Integer(posY)); xButtonPropertySet.setPropertyValue("Height", new Integer(14)); xButtonPropertySet.setPropertyValue("Width", new Integer(width)); xButtonPropertySet.setPropertyValue("Label", (label != null) ? label : ""); xButtonPropertySet.setPropertyValue("PushButtonType", new Short((short) pushButtonType)); xButtonPropertySet.setPropertyValue("Name", uniqueName); xButtonPropertySet.setPropertyValue("Enabled", enabled); // Add the model to the dialog model name container xDialogModelNameContainer.insertByName(uniqueName, oButtonModel); return oButtonModel; }
public XFixedText insertFixedText(int posX, int posY, int height, int width, String label) throws Exception { // Create a unique name String uniqueName = createUniqueName(xDialogModelNameContainer, "FixedText"); // Create a fixed text control model Object oFixedTextModel = xMultiComponentFactoryDialogModel.createInstance( "com.sun.star.awt.UnoControlFixedTextModel"); // Set the properties at the model XPropertySet xFixedTextPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFixedTextModel); xFixedTextPropertySet.setPropertyValue("PositionX", new Integer(posX)); xFixedTextPropertySet.setPropertyValue("PositionY", new Integer(posY + 2)); xFixedTextPropertySet.setPropertyValue("Height", new Integer(height)); xFixedTextPropertySet.setPropertyValue("Width", new Integer(width)); xFixedTextPropertySet.setPropertyValue("Label", (label != null) ? label : ""); xFixedTextPropertySet.setPropertyValue("Name", uniqueName); // Add the model to the dialog model name container xDialogModelNameContainer.insertByName(uniqueName, oFixedTextModel); // Reference the control by the unique name XControl xFixedTextControl = xDialogContainer.getControl(uniqueName); return (XFixedText) UnoRuntime.queryInterface(XFixedText.class, xFixedTextControl); }
/** * creates the button used for demonstrating (amongst others) event handling * * @param nXPos x-position of the to be inserted shape * @param nYPos y-position of the to be inserted shape * @param nXSize width of the to be inserted shape * @param sName the name of the model in the form component hierarchy * @param sLabel the label of the button control * @param sActionURL the URL of the action which should be triggered by the button * @return the model of the newly created button */ protected XPropertySet createButton( int nXPos, int nYPos, int nXSize, String sName, String sLabel, short _formFeature) throws java.lang.Exception { XPropertySet xButton = m_formLayer.createControlAndShape("CommandButton", nXPos, nYPos, nXSize, 6); // the name for referring to it later: xButton.setPropertyValue("Name", sName); // the label xButton.setPropertyValue("Label", sLabel); // use the name as help text xButton.setPropertyValue("HelpText", sName); // don't want buttons to be accessible by the "tab" key - this would be uncomfortable when // traveling // with records with "tab" xButton.setPropertyValue("Tabstop", Boolean.FALSE); // similar, they should not steal the focus when clicked xButton.setPropertyValue("FocusOnClick", Boolean.FALSE); m_aOperator.addButton(xButton, _formFeature); return xButton; }
public XComboBox insertComboBox( int posX, int posY, int width, String[] stringItemList, String Name, String Text) { XComboBox xComboBox = null; try { // create a unique name by means of an own implementation... String sName = Name; // createUniqueName(xDialogModelNameContainer, "ComboBox"); // create a controlmodel at the multiservicefactory of the dialog model... Object oComboBoxModel = xMultiComponentFactoryDialogModel.createInstance( "com.sun.star.awt.UnoControlComboBoxModel"); XPropertySet xComboBOxPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oComboBoxModel); /* //######################Debug de propriedades######################### XPropertySetInfo xCursorPropsInfo = xComboBOxPropertySet.getPropertySetInfo(); Property[] aProps = xCursorPropsInfo.getProperties(); int i; for (i = 0; i < aProps.length; ++i) { // prints Property Name System.out.println(aProps[i].Name); } */ xComboBOxPropertySet.setPropertyValue("Dropdown", true); xComboBOxPropertySet.setPropertyValue("Step", 3); xComboBOxPropertySet.setPropertyValue("PositionX", new Integer(posX)); xComboBOxPropertySet.setPropertyValue("PositionY", new Integer(posY)); xComboBOxPropertySet.setPropertyValue("Height", new Integer(12)); xComboBOxPropertySet.setPropertyValue("Width", new Integer(width)); xComboBOxPropertySet.setPropertyValue("StringItemList", stringItemList); xComboBOxPropertySet.setPropertyValue("Name", sName); xComboBOxPropertySet.setPropertyValue("Text", Text); xDialogModelNameContainer.insertByName(sName, oComboBoxModel); XControl xControl = xDialogContainer.getControl(sName); // retrieve a ComboBox that is more convenient to work with than the Model of the ComboBox... xComboBox = (XComboBox) UnoRuntime.queryInterface(XComboBox.class, xControl); } catch (com.sun.star.uno.Exception ex) { SpeechOO.logger = org.apache.log4j.Logger.getLogger(TrainingDialog.class.getName()); SpeechOO.logger.error(ex); } return xComboBox; }
private void setPositionAndSize(Object obj, int x, int y, int width, int height) throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException { XPropertySet xFrameProps = query(XPropertySet.class, obj); xFrameProps.setPropertyValue(PROP_SIZETYPE, SizeType.FIX); xFrameProps.setPropertyValue(PROP_WIDTH, (int) (width * PIXEL_RATIO)); xFrameProps.setPropertyValue(PROP_HEIGHT, (int) (height * PIXEL_RATIO)); xFrameProps.setPropertyValue(PROP_HORIORIENT, HoriOrientation.NONE); xFrameProps.setPropertyValue(PROP_HORIPOSITION, (int) (x * PIXEL_RATIO)); xFrameProps.setPropertyValue(PROP_VERTORIENT, VertOrientation.NONE); xFrameProps.setPropertyValue(PROP_VERTPOSITION, (int) (y * PIXEL_RATIO)); }
/** * creates a line of controls, consisting of a label and a field for data input. * * <p>In opposite to the second form of this method, here the height of the field, as well as the * abscissa of the label, are under the control of the caller. * * @param sControlType specifies the type of the data input control * @param sFieldName specifies the field name the text field should be bound to * @param sControlNamePostfix specifies a postfix to append to the logical control names * @param nYPos specifies the Y position of the line to start at * @param nHeight the height of the field * @return the control model of the created data input field */ protected XPropertySet insertControlLine( String sControlType, String sFieldName, String sControlNamePostfix, int nXPos, int nYPos, int nHeight) throws java.lang.Exception { // insert the label control XPropertySet xLabelModel = createControlAndShape("FixedText", nXPos, nYPos, 25, 6); xLabelModel.setPropertyValue("Label", sFieldName); // insert the text field control XPropertySet xFieldModel = createControlAndShape(sControlType, nXPos + 26, nYPos, 40, nHeight); xFieldModel.setPropertyValue("DataField", sFieldName); // knit it to it's label component xFieldModel.setPropertyValue("LabelControl", xLabelModel); // some names, so later on we can find them xLabelModel.setPropertyValue("Name", sFieldName + sControlNamePostfix + "_Label"); xFieldModel.setPropertyValue("Name", sFieldName + sControlNamePostfix); return xFieldModel; }
public boolean WBToSubstrOfEncr( XStorage xStorage, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes, boolean bEncrypted) { // open substream element XStream xSubStream = null; try { Object oSubStream = xStorage.openStreamElement(sStreamName, ElementModes.WRITE); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamName + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamName + "', exception : " + e + "!"); return false; } // get access to the XPropertySet interface XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xSubStream); if (xPropSet == null) { Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!"); return false; } // set properties to the stream try { xPropSet.setPropertyValue("UseCommonStoragePasswordEncryption", new Boolean(bEncrypted)); } catch (Exception e) { Error( "Can't set 'UseCommonStoragePasswordEncryption' property to substream '" + sStreamName + "', exception: " + e); return false; } if (!WriteBytesToStream(xSubStream, sStreamName, sMediaType, bCompressed, pBytes)) return false; // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sStreamName)) return false; return true; }
private void init(int posX, int posY, int height, int width, String title, String name) throws Exception { xMultiComponentFactory = xComponentContext.getServiceManager(); Object oDialogModel = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", xComponentContext); // The XMultiServiceFactory of the dialogmodel is needed to instantiate the controls... xMultiComponentFactoryDialogModel = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel); // The named container is used to insert the created controls into... xDialogModelNameContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDialogModel); // create the dialog... Object oUnoDialog = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.awt.UnoControlDialog", xComponentContext); xDialogControl = (XControl) UnoRuntime.queryInterface(XControl.class, oUnoDialog); // The scope of the control container is public... xDialogContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog); // link the dialog and its model... XControlModel xControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oDialogModel); xDialogControl.setModel(xControlModel); // Create a unique name String uniqueName = createUniqueName(xDialogModelNameContainer, (name != null) ? name : "LiboDialog"); // Define the dialog at the model XPropertySet xDialogPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xDialogModelNameContainer); xDialogPropertySet.setPropertyValue("PositionX", new Integer(posX)); xDialogPropertySet.setPropertyValue("PositionY", new Integer(posY)); xDialogPropertySet.setPropertyValue("Height", new Integer(height)); xDialogPropertySet.setPropertyValue("Width", new Integer(width)); xDialogPropertySet.setPropertyValue( "Title", (title != null) ? title : "LibreOffice.org Dialog"); xDialogPropertySet.setPropertyValue("Name", uniqueName); xDialogPropertySet.setPropertyValue("Moveable", Boolean.TRUE); xDialogPropertySet.setPropertyValue("TabIndex", new Short((short) 0)); }
/* ------------------------------------------------------------------ */ public void resetted(EventObject aEvent) throws com.sun.star.uno.RuntimeException { // check if this reset occurred because we're on a new record XPropertySet xFormProps = UNO.queryPropertySet(aEvent.Source); try { Boolean aIsNew = (Boolean) xFormProps.getPropertyValue("IsNew"); if (aIsNew.booleanValue()) { // yepp if (!m_bDefaultSalesDate) { // we're interested to do all this only if the user told us to // default the sales date // to "today" // As date fields do this defaulting automatically, the semantics is inverted here: // If we're told to default, we must do nothing, if we should not default, we must // reset the value which the date field set automatically. Integer aConcurrency = (Integer) xFormProps.getPropertyValue("ResultSetConcurrency"); if (ResultSetConcurrency.READ_ONLY != aConcurrency.intValue()) { // we're going to modify the record, though after that, to the user, it should look // like it has not been modified // So we need to ensure that we do not change the IsModified property with whatever we // do Object aModifiedFlag = xFormProps.getPropertyValue("IsModified"); // get the columns of our master form XColumnsSupplier xSuppCols = UnoRuntime.queryInterface(XColumnsSupplier.class, xFormProps); XNameAccess xCols = xSuppCols.getColumns(); // and update the date column with a NULL value XColumnUpdate xDateColumn = UnoRuntime.queryInterface(XColumnUpdate.class, xCols.getByName("SALEDATE")); xDateColumn.updateNull(); // then restore the flag xFormProps.setPropertyValue("IsModified", aModifiedFlag); } } } } catch (com.sun.star.uno.Exception e) { System.out.println(e); e.printStackTrace(); } }
// XInitialization public void initialize(Object[] aArguments) throws Exception, RuntimeException { if (aArguments.length > 0) { maChartDocument = UnoRuntime.queryInterface(XChartDocument.class, aArguments[0]); XPropertySet aDocProp = UnoRuntime.queryInterface(XPropertySet.class, maChartDocument); if (aDocProp != null) { // set base diagram which will be extended in refresh() aDocProp.setPropertyValue("BaseDiagram", "com.sun.star.chart.XYDiagram"); } // get the draw page XDrawPageSupplier aPageSupp = UnoRuntime.queryInterface(XDrawPageSupplier.class, maChartDocument); if (aPageSupp != null) maDrawPage = UnoRuntime.queryInterface(XDrawPage.class, aPageSupp.getDrawPage()); // get a factory for creating shapes maShapeFactory = UnoRuntime.queryInterface(XMultiServiceFactory.class, maChartDocument); } }
/** * Creating a TestEnvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.comp.Chart.XMLExporter</code> with argument which is an implementation of * <code>XDocumentHandler</code> and which can check if required tags and character data is * exported. * * <p>The chart document is set as a source document for exporter created. A new 'main title' is * set for chart. This made for checking if this title is successfully exported within the * document content. Object relations created : * * <ul> * <li><code>'MediaDescriptor'</code> for {@link ifc.document._XFilter} interface * <li><code>'XFilter.Checker'</code> for {@link ifc.document._XFilter} interface * <li><code>'SourceDocument'</code> for {@link ifc.document._XExporter} interface * </ul> */ @Override public TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception { XMultiServiceFactory xMSF = tParam.getMSF(); XInterface oObj = null; final String exportStr = "XMLExporter test."; FilterChecker filter = new FilterChecker(log); Any arg = new Any(new Type(XDocumentHandler.class), filter); oObj = (XInterface) xMSF.createInstanceWithArguments( "com.sun.star.comp.Chart.XMLExporter", new Object[] {arg}); XExporter xEx = UnoRuntime.queryInterface(XExporter.class, oObj); xEx.setSourceDocument(xChartDoc); Object oTitle = xChartDoc.getTitle(); XPropertySet xTitleProp = UnoRuntime.queryInterface(XPropertySet.class, oTitle); xTitleProp.setPropertyValue("String", exportStr); filter.addTag(new XMLTools.Tag("office:document")); filter.addTagEnclosed(new XMLTools.Tag("office:meta"), new XMLTools.Tag("office:document")); filter.addTagEnclosed(new XMLTools.Tag("office:body"), new XMLTools.Tag("office:document")); filter.addCharactersEnclosed(exportStr, new XMLTools.Tag("chart:title")); // create testobject here log.println("creating a new environment"); TestEnvironment tEnv = new TestEnvironment(oObj); tEnv.addObjRelation( "MediaDescriptor", XMLTools.createMediaDescriptor( new String[] {"FilterName"}, new Object[] {"schart: StarOffice XML (Chart)"})); tEnv.addObjRelation("SourceDocument", xChartDoc); tEnv.addObjRelation("XFilter.Checker", filter); log.println("Implementation Name: " + util.utils.getImplName(oObj)); return tEnv; }
public String CreateTempFile(XMultiServiceFactory xMSF) { String sResult = null; // try to get temporary file representation XPropertySet xTempFileProps = null; try { Object oTempFile = xMSF.createInstance("com.sun.star.io.TempFile"); xTempFileProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTempFile); } catch (Exception e) { } if (xTempFileProps != null) { try { xTempFileProps.setPropertyValue("RemoveFile", new Boolean(false)); sResult = AnyConverter.toString(xTempFileProps.getPropertyValue("Uri")); } catch (Exception e) { Error("Can't control TempFile properties, exception: " + e); } } else { Error("Can't create temporary file representation!"); } // close temporary file explicitly try { XStream xStream = (XStream) UnoRuntime.queryInterface(XStream.class, xTempFileProps); if (xStream != null) { XOutputStream xOut = xStream.getOutputStream(); if (xOut != null) xOut.closeOutput(); XInputStream xIn = xStream.getInputStream(); if (xIn != null) xIn.closeInput(); } else Error("Can't close TempFile!"); } catch (Exception e) { Error("Can't close TempFile, exception: " + e); } return sResult; }
public boolean WBToSubstrOfEncr( XStorage xStorage, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes, boolean bEncrypted) { // open substream element XStream xSubStream = null; try { Object oSubStream = xStorage.openStreamElement(sStreamName, ElementModes.WRITE); xSubStream = UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamName + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamName + "', exception : " + e + "!"); return false; } // get access to the XPropertySet interface XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xSubStream); if (xPropSet == null) { Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!"); return false; } // set properties to the stream try { xPropSet.setPropertyValue("Encrypted", Boolean.valueOf(bEncrypted)); } catch (Exception e) { Error("Can't set 'Encrypted' property to substream '" + sStreamName + "', exception: " + e); return false; } return WriteBytesToStream(xSubStream, sStreamName, sMediaType, bCompressed, pBytes); }
/** add a specified table name to the table filter of the given data source. */ protected void makeTableVisible(XDataSource xDS, String sTableName) throws java.lang.Exception { // get the table filter XPropertySet xDSP = UNO.queryPropertySet(xDS); String[] aCurrentFilter = (String[]) xDSP.getPropertyValue("TableFilter"); // check if the table name is already part of it String sAllTables = "*"; // all tables for (int i = 0; i < aCurrentFilter.length; ++i) { String sCurrentTableFilter = aCurrentFilter[i]; if (sCurrentTableFilter.equals(sTableName)) return; if (sCurrentTableFilter.equals(sAllTables)) return; } // if we are here, we have to add our table to the filter sequence String[] aNewFilter = new String[aCurrentFilter.length + 1]; // copy the existent filter entries for (int i = 0; i < aCurrentFilter.length; ++i) aNewFilter[i] = aCurrentFilter[i]; // add our table aNewFilter[aCurrentFilter.length] = sTableName; xDSP.setPropertyValue("TableFilter", aNewFilter); }
public boolean WriteBytesToSubstreamDefaultCompressed( XStorage xStorage, String sStreamName, String sMediaType, byte[] pBytes) { // open substream element XStream xSubStream = null; try { Object oSubStream = xStorage.openStreamElement(sStreamName, ElementModes.WRITE); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamName + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamName + "', exception : " + e + "!"); return false; } // get output stream of substream XOutputStream xOutput = xSubStream.getOutputStream(); if (xOutput == null) { Error("Can't get XOutputStream implementation from substream '" + sStreamName + "'!"); return false; } // get XTrucate implementation from output stream XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface(XTruncate.class, xOutput); if (xTruncate == null) { Error("Can't get XTruncate implementation from substream '" + sStreamName + "'!"); return false; } // write requested byte sequence try { xTruncate.truncate(); xOutput.writeBytes(pBytes); } catch (Exception e) { Error("Can't write to stream '" + sStreamName + "', exception: " + e); return false; } // get access to the XPropertySet interface XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xSubStream); if (xPropSet == null) { Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!"); return false; } // set properties to the stream // do not set the compressed property try { xPropSet.setPropertyValue("MediaType", sMediaType); } catch (Exception e) { Error("Can't set properties to substream '" + sStreamName + "', exception: " + e); return false; } // check size property of the stream try { long nSize = AnyConverter.toLong(xPropSet.getPropertyValue("Size")); if (nSize != pBytes.length) { Error("The 'Size' property of substream '" + sStreamName + "' contains wrong value!"); return false; } } catch (Exception e) { Error("Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e); return false; } // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sStreamName)) return false; return true; }
public boolean WBToSubstrOfEncrH( XStorage xStorage, String sStreamPath, String sMediaType, boolean bCompressed, byte[] pBytes, boolean bEncrypted, boolean bCommit) { // open substream element XStream xSubStream = null; try { XHierarchicalStorageAccess xHStorage = (XHierarchicalStorageAccess) UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage); if (xHStorage == null) { Error("The storage does not support hierarchical access!"); return false; } Object oSubStream = xHStorage.openStreamElementByHierarchicalName(sStreamPath, ElementModes.WRITE); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamPath + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamPath + "', exception : " + e + "!"); return false; } // get access to the XPropertySet interface XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xSubStream); if (xPropSet == null) { Error("Can't get XPropertySet implementation from substream '" + sStreamPath + "'!"); return false; } // set properties to the stream try { xPropSet.setPropertyValue("UseCommonStoragePasswordEncryption", new Boolean(bEncrypted)); } catch (Exception e) { Error( "Can't set 'UseCommonStoragePasswordEncryption' property to substream '" + sStreamPath + "', exception: " + e); return false; } if (!WriteBytesToStream(xSubStream, sStreamPath, sMediaType, bCompressed, pBytes)) return false; XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, xSubStream); if (xTransact == null) { Error("Substream '" + sStreamPath + "', stream opened for writing must be transacted!"); return false; } if (bCommit) { try { xTransact.commit(); } catch (Exception e) { Error( "Can't commit storage after substream '" + sStreamPath + "' change, exception : " + e + "!"); return false; } } // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sStreamPath)) return false; return true; }