/* ------------------------------------------------------------------ */ 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")); }
/** simulates a user's text input into a control given by model name */ private void userTextInput(String modelName, String text, boolean withCommit) throws com.sun.star.uno.Exception, java.lang.Exception { XPropertySet controlModel = getControlModel(modelName); // the form runtime environment (namely the form controller) rely on focus events for // recognizing // control content changes ... if (withCommit) m_document.getCurrentView().grabControlFocus(controlModel); m_formLayer.userTextInput(controlModel, text); // focus back to a dummy control model so the content of the model we just changed will // be committed to the underlying database column if (withCommit) m_document.getCurrentView().grabControlFocus(getControlModel("dummy")); }
/* ------------------------------------------------------------------ */ private XPropertySet getRadioModel(String name, String refValue) throws com.sun.star.uno.Exception, java.lang.Exception { return m_formLayer.getRadioModelByRefValue(m_masterForm, name, refValue); }
/* ------------------------------------------------------------------ */ private void createSampleDocument() throws com.sun.star.uno.Exception, java.lang.Exception { m_document = DocumentHelper.blankTextDocument(m_orb); m_formLayer = new FormLayer(m_document); // insert some controls XPropertySet xIDField = m_formLayer.insertControlLine("DatabaseNumericField", "ID", "", 3); m_formLayer.insertControlLine("DatabaseFormattedField", "f_integer", "", 11); m_formLayer.insertControlLine("DatabaseTextField", "f_text", "", 19); XPropertySet xReqField = m_formLayer.insertControlLine("DatabaseTextField", "f_required_text", "", 27); m_formLayer.insertControlLine("DatabaseNumericField", "f_decimal", "", 35); m_formLayer.insertControlLine("DatabaseDateField", "f_date", "", 43); XPropertySet xTimeField = m_formLayer.insertControlLine("DatabaseTimeField", "f_time", "", 51); m_formLayer.insertControlLine("DatabaseDateField", "f_timestamp", "_date", 59); m_formLayer.insertControlLine("DatabaseTimeField", "f_timestamp", "_time", 67); XPropertySet xImageField = m_formLayer.insertControlLine("DatabaseImageControl", "f_blob", "", 2, 75, 40); m_formLayer.insertControlLine("DatabaseTextField", "f_text_enum", "_text", 80, 25, 6); XPropertySet xCheckBox = m_formLayer.insertControlLine("DatabaseCheckBox", "f_tinyint", "", 80, 33, 6); m_formLayer.insertControlLine("DatabaseFormattedField", "f_tinyint", "_format", 80, 41, 6); m_formLayer.insertControlLine("DatabaseTextField", "dummy", "", 150); xIDField.setPropertyValue("DecimalAccuracy", new Short((short) 0)); xImageField.setPropertyValue("ScaleImage", new Boolean(true)); xImageField.setPropertyValue("Tabstop", new Boolean(true)); xCheckBox.setPropertyValue("TriState", new Boolean(true)); xCheckBox.setPropertyValue("DefaultState", new Short((short) 2)); xTimeField.setPropertyValue("TimeFormat", new Short((short) 1)); xTimeField.setPropertyValue("TimeMax", new Integer(23595999)); xReqField.setPropertyValue("ConvertEmptyToNull", new Boolean(false)); // the logical form m_masterForm = (XPropertySet) dbfTools.getParent(xIDField, XPropertySet.class); m_masterForm.setPropertyValue("DataSourceName", m_dataSourceProps.getPropertyValue("Name")); m_masterForm.setPropertyValue("CommandType", new Integer(CommandType.TABLE)); m_masterForm.setPropertyValue("Command", s_tableName); insertRadio(3, "none", "none"); insertRadio(10, "normal", "normal"); insertRadio(17, "important", "important"); // switch the forms into data entry mode m_document.getCurrentView().toggleFormDesignMode(); m_masterFormController = m_document.getCurrentView().getFormController(m_masterForm); XSQLErrorBroadcaster errorBroadcaster = UnoRuntime.queryInterface(XSQLErrorBroadcaster.class, m_masterFormController); errorBroadcaster.addSQLErrorListener(this); // set the focus to the ID control m_document.getCurrentView().grabControlFocus(xIDField); }
/** * very similar to checkCrossUpdates_checkBox - does nearly the same for the radio buttons. See * there for more explanations. */ public void checkCrossUpdates_radioButton() throws com.sun.star.uno.Exception, java.lang.Exception { // move to the first record moveToFirst(); if (!checkRadios((short) 1, (short) 0, (short) 0) || !checkStringValue("none", "f_text_enum_text", "Text")) { failed("huh? inconsistence in the test!"); return; } XPropertySet radioModel = getRadioModel("radio_group", "normal"); radioModel.setPropertyValue("State", new Short((short) 1)); // setting the state of the radio button needs to be reflected in the formatted field // immediately if (!checkStringValue("normal", "f_text_enum_text", "Text")) { failed( "cross-update failed: updating the radio button should result in updating the same-bound text field (1)!"); return; } // same for the "indetermined" state of the check box getRadioModel("radio_group", "important").setPropertyValue("State", new Short((short) 1)); if (!checkStringValue("important", "f_text_enum_text", "Text")) { failed( "cross-update failed: updating the radio button should result in updating the same-bound text field (2)!"); return; } // undo the changes done so far undoRecordByUI(); // and see if this is properly reflected in the controls if (!checkRadios((short) 1, (short) 0, (short) 0) || !checkStringValue("none", "f_text_enum_text", "Text")) { failed("either the radio button or the text field failed to recognize the UNDO!"); return; } // the other way round - when changing the formatted field - the change should *not* // be reflected to the check box, since the formatted field needs an explicit commit XPropertySet textModel = getControlModel("f_text_enum_text"); m_document.getCurrentView().grabControlFocus(textModel); m_formLayer.userTextInput(textModel, "normal"); if (!checkRadios((short) 1, (short) 0, (short) 0)) { failed( "the radio buttons should not be updated here! (did the formatted model commit immediately?)"); return; } // set the focus to *any* other control (since we just have it at hand, we use the check box // control) // this should result in the formatted control being committed, and thus in the check box // updating m_document.getCurrentView().grabControlFocus(radioModel); if (!checkRadios((short) 0, (short) 1, (short) 0)) { failed("text field did not commit (or radio button did not update)"); return; } // undo the changes done so far, so we leave the document in a clean state for the next test undoRecordByUI(); }
/** * This is both a test for controls which are bound to the same column (they must reflect each * others updates), and for the immediate updates which need to happen for both check boxes and * radio buttons: They must commit their content to the underlying column as soon as the change is * made, *not* only upon explicit commit */ public void checkCrossUpdates_checkBox() throws com.sun.star.uno.Exception, java.lang.Exception { // move to the first record moveToFirst(); if (!checkShortValue((short) 1, "f_tinyint", "State") || !checkDoubleValue(1, "f_tinyint_format", "EffectiveValue")) { failed("huh? inconsistence in the test!"); // we created the sample data in a way that the f_tinyint field should contain a "1" at the // first // record. We already asserted the proper function of the check box in checkFirstRow, so if // this // fails here, the script became inconsistent return; } XPropertySet checkModel = getControlModel("f_tinyint"); checkModel.setPropertyValue("State", new Short((short) 0)); // setting the state of the check box needs to be reflected in the formatted field immediately if (!checkDoubleValue(0, "f_tinyint_format", "EffectiveValue")) { failed( "cross-update failed: updating the check box should result in updating the same-bound formatted field (1)!"); return; } // same for the "indetermined" state of the check box checkModel.setPropertyValue("State", new Short((short) 2)); if (!checkNullValue("f_tinyint_format", "EffectiveValue")) { failed( "cross-update failed: updating the check box should result in updating the same-bound formatted field (2)!"); return; } // undo the changes done so far undoRecordByUI(); // and see if this is properly reflected in the controls if (!checkShortValue((short) 1, "f_tinyint", "State") || !checkDoubleValue(1, "f_tinyint_format", "EffectiveValue")) { failed("either the check box or the formatted field failed to recognize the UNDO!"); return; } // the other way round - when changing the formatted field - the change should *not* // be reflected to the check box, since the formatted field needs an explicit commit XPropertySet tinyFormattedModel = getControlModel("f_tinyint_format"); m_document.getCurrentView().grabControlFocus(tinyFormattedModel); m_formLayer.userTextInput(tinyFormattedModel, "0"); if (!checkShortValue((short) 1, "f_tinyint", "State")) { failed( "the check box should not be updated here! (did the formatted model commit immediately?)"); return; } // set the focus to *any* other control (since we just have it at hand, we use the check box // control) // this should result in the formatted control being committed, and thus in the check box // updating m_document.getCurrentView().grabControlFocus(checkModel); if (!checkShortValue((short) 0, "f_tinyint", "State")) { failed("formatted field did not commit (or check box did not update)"); return; } // undo the changes done so far, so we leave the document in a clean state for the next test undoRecordByUI(); }