/**
  * 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 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);
      }
    }
Пример #3
0
  /**
   * First an instance of text content is created using relation and inserted into text. Then the
   * number of contents is checked using the relation. Second a <code>null</code> content is tried
   * to insert.
   *
   * <p>Has <b> OK </b> status if in the first case after inserting number of content objects is
   * greater than zero and in the second case <code>IllegalArgumentException</code> is thrown.
   *
   * <p>
   */
  public void _insertTextContent() {
    boolean result = false;
    info = (XInstCreator) tEnv.getObjRelation("XTEXTINFO");
    oInt = info.createInstance();

    // write to log what we try next
    log.println("test for createTextCursor()");
    oCursor = oObj.createTextCursor();

    // write to log what we try next
    log.println("test for insertTextContent()");
    try {
      oObj.insertTextContent(oCursor, (XTextContent) oInt, false);
    } catch (com.sun.star.lang.IllegalArgumentException iaE) {
      throw new StatusException("Couldn't insert textcontent", iaE);
      // Status.failed(iaE.toString());
      // return;
    }

    // get indexaccess to the tablecollection
    XIndexAccess xIA = info.getCollection();

    // this comparison works just because it has to be at least one
    // table at this point regardless which thread inserted it
    // there is although the possibility that the first threads call
    // failed, the second not and comparison happens after second threads
    // otherwise if something fails it should have thrown an exception
    // tRes.tested("insertTextContent()",    xIA.getCount() > 0 );

    if (xIA != null) {
      result = (xIA.getCount() > 0);
    } else {
      result = true;
    }

    if (!result) log.println("The TextContent wasn't inserted");

    // try to insert an invalid TextContent
    log.println("test for insertTextContent");
    try {
      oObj.insertTextContent(oCursor, null, false);
      log.println("The expected Exception doesn't occurred");
      result &= false;
    } catch (com.sun.star.lang.IllegalArgumentException iaE) {
      // Some exception.FAILED
      log.println("Expected Exception occurred");
      String msg = iaE.getMessage();
      if (msg.equals("")) {
        log.println("But there is not detailed message");
      } else {
        log.println("Detailed message: " + msg);
      }

      result &= true;
    }

    tRes.tested("insertTextContent()", result);
  }
Пример #4
0
  /**
   * retrieves the radio button model with the given name and the given tag
   *
   * @param form the parent form of the radio button model to find
   * @param name the name of the radio button
   * @param tag the tag of the radio button
   */
  public XPropertySet getRadioModelByTag(XPropertySet form, String name, String tag)
      throws com.sun.star.uno.Exception, java.lang.Exception {
    XIndexAccess indexAccess = UnoRuntime.queryInterface(XIndexAccess.class, form);

    for (int i = 0; i < indexAccess.getCount(); ++i) {
      XPropertySet control = UNO.queryPropertySet(indexAccess.getByIndex(i));

      if (((String) control.getPropertyValue("Name")).equals(name))
        if (((String) control.getPropertyValue("Tag")).equals(tag)) return control;
    }
    return null;
  }
 private String getViewID(XIndexAccess xAccess) {
   String retValue = null;
   int count = xAccess.getCount();
   try {
     if (count > 0) {
       oldProps = (PropertyValue[]) xAccess.getByIndex(0);
       for (int j = 0; j < oldProps.length; j++) {
         if (oldProps[j].Name.equals("ViewId")) {
           retValue = (String) newProps[j].Value;
         }
       }
     }
   } catch (Exception e) {
     e.printStackTrace(log);
   }
   return retValue;
 }
 private void setViewID(XIndexAccess xAccess, String value) {
   XIndexContainer xIndexContainer = UnoRuntime.queryInterface(XIndexContainer.class, xAccess);
   int count = xAccess.getCount();
   try {
     if (count > 0) {
       oldProps = (PropertyValue[]) xAccess.getByIndex(0);
       newProps = new PropertyValue[oldProps.length];
       for (int j = 0; j < oldProps.length; j++) {
         newProps[j] = new PropertyValue();
         newProps[j].Name = oldProps[j].Name;
         newProps[j].Handle = oldProps[j].Handle;
         newProps[j].State = oldProps[j].State;
         if (oldProps[j].Name.equals("ViewId")) {
           newProps[j].Value = value;
         }
       }
       xIndexContainer.insertByIndex(0, newProps);
     }
   } catch (Exception e) {
     e.printStackTrace(log);
   }
 }
Пример #7
0
  /**
   * Replaces all aliases ${bandname.paramname} in document text.
   *
   * @throws com.haulmont.yarg.exception.ReportingException If there is not appropriate band or
   *     alias is bad
   */
  protected void replaceAllAliasesInDocument() {
    XTextDocument xTextDocument = as(XTextDocument.class, xComponent);
    XReplaceable xReplaceable = as(XReplaceable.class, xTextDocument);
    XSearchDescriptor searchDescriptor = xReplaceable.createSearchDescriptor();
    searchDescriptor.setSearchString(ALIAS_WITH_BAND_NAME_REGEXP);
    try {
      searchDescriptor.setPropertyValue(SEARCH_REGULAR_EXPRESSION, true);
    } catch (Exception e) {
      throw new OpenOfficeException(
          "An error occurred while setting search properties in Open office", e);
    }

    XIndexAccess indexAccess = xReplaceable.findAll(searchDescriptor);
    for (int i = 0; i < indexAccess.getCount(); i++) {
      try {
        XTextRange textRange = as(XTextRange.class, indexAccess.getByIndex(i));
        String alias = unwrapParameterName(textRange.getString());

        BandPathAndParameterName bandAndParameter = separateBandNameAndParameterName(alias);

        BandData band = findBandByPath(bandAndParameter.getBandPath());

        if (band != null) {
          insertValue(textRange.getText(), textRange, band, bandAndParameter.getParameterName());
        } else {
          throw wrapWithReportingException(String.format("No band for alias [%s] found", alias));
        }
      } catch (ReportingException e) {
        throw e;
      } catch (Exception e) {
        throw wrapWithReportingException(
            String.format(
                "An error occurred while replacing aliases in document. Regexp [%s]. Replacement number [%d]",
                ALIAS_WITH_BAND_NAME_REGEXP, i),
            e);
      }
    }
  }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Using SOffice ServiceManager an
   * instance of <code>com.sun.star.sheet.TableAutoFormatField</code> service is created. From this
   * collection one Format is retrieved as object tested.
   */
  public TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {

    XInterface oObj = null;
    XMultiServiceFactory oMSF = (XMultiServiceFactory) tParam.getMSF();
    try {
      XInterface formats = (XInterface) oMSF.createInstance("com.sun.star.sheet.TableAutoFormats");
      XIndexAccess formatsIndex = UnoRuntime.queryInterface(XIndexAccess.class, formats);
      oObj =
          (XInterface)
              AnyConverter.toObject(
                  new Type(XInterface.class), formatsIndex.getByIndex(formatsIndex.getCount() - 1));

      XNamed objNamed = UnoRuntime.queryInterface(XNamed.class, oObj);
      log.println("AutoFormat name is '" + objNamed.getName() + "'");
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Unexpected exception", e);
    }

    TestEnvironment tEnv = new TestEnvironment(oObj);

    return tEnv;
  }
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws Exception {
    XInterface oObj = null;
    XInterface datapilotfield = null;

    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("Creating a test environment");

    // the cell range
    CellRangeAddress sCellRangeAdress = new CellRangeAddress();
    sCellRangeAdress.Sheet = 0;
    sCellRangeAdress.StartColumn = 1;
    sCellRangeAdress.StartRow = 0;
    sCellRangeAdress.EndColumn = mMaxFieldIndex - 1;
    sCellRangeAdress.EndRow = mMaxFieldIndex - 1;

    // position of the data pilot table
    CellAddress sCellAdress = new CellAddress();
    sCellAdress.Sheet = 0;
    sCellAdress.Column = 7;
    sCellAdress.Row = 8;

    log.println("Getting a sheet");

    XSpreadsheets xSpreadsheets = xSheetDoc.getSheets();
    XSpreadsheet oSheet = null;
    XSpreadsheet oSheet2 = null;
    XIndexAccess oIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
    // Make sure there are at least two sheets
    xSpreadsheets.insertNewByName("Some Sheet", (short) 0);

    oSheet =
        (XSpreadsheet)
            AnyConverter.toObject(new Type(XSpreadsheet.class), oIndexAccess.getByIndex(0));
    oSheet2 =
        (XSpreadsheet)
            AnyConverter.toObject(new Type(XSpreadsheet.class), oIndexAccess.getByIndex(1));

    log.println("Filling a table");

    for (int i = 1; i < mMaxFieldIndex; i++) {
      oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
      oSheet.getCellByPosition(0, i).setFormula("Row" + i);
      oSheet2.getCellByPosition(i, 0).setFormula("Col" + i);
      oSheet2.getCellByPosition(0, i).setFormula("Row" + i);
    }

    for (int i = 1; i < mMaxFieldIndex; i++) {
      for (int j = 1; j < mMaxFieldIndex; j++) {
        oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
        oSheet2.getCellByPosition(i, j).setValue(i * (j + 2));
      }
    }

    oSheet.getCellByPosition(1, 1).setFormula("aName");
    oSheet.getCellByPosition(1, 2).setFormula("otherName");
    oSheet.getCellByPosition(1, 3).setFormula("una");
    oSheet.getCellByPosition(1, 4).setFormula("otherName");
    oSheet.getCellByPosition(1, 5).setFormula("somethingelse");

    oSheet.getCellByPosition(1, 5);

    int x = sCellAdress.Column;
    int y = sCellAdress.Row + 3;

    oSheet.getCellByPosition(x, y);

    // create the test objects
    log.println("Getting test objects");

    XDataPilotTablesSupplier DPTS =
        UnoRuntime.queryInterface(XDataPilotTablesSupplier.class, oSheet);
    XDataPilotTables DPT = DPTS.getDataPilotTables();
    XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor();
    DPDsc.setSourceRange(sCellRangeAdress);

    XPropertySet fieldPropSet = null;

    Object oDataPilotField = DPDsc.getDataPilotFields().getByIndex(0);
    fieldPropSet = UnoRuntime.queryInterface(XPropertySet.class, oDataPilotField);
    fieldPropSet.setPropertyValue("Orientation", com.sun.star.sheet.DataPilotFieldOrientation.ROW);
    oDataPilotField = DPDsc.getDataPilotFields().getByIndex(1);
    fieldPropSet = UnoRuntime.queryInterface(XPropertySet.class, oDataPilotField);
    fieldPropSet.setPropertyValue("Function", com.sun.star.sheet.GeneralFunction.SUM);
    fieldPropSet.setPropertyValue("Orientation", com.sun.star.sheet.DataPilotFieldOrientation.DATA);
    oDataPilotField = DPDsc.getDataPilotFields().getByIndex(2);
    fieldPropSet = UnoRuntime.queryInterface(XPropertySet.class, oDataPilotField);
    fieldPropSet.setPropertyValue(
        "Orientation", com.sun.star.sheet.DataPilotFieldOrientation.COLUMN);

    log.println("Insert the DataPilotTable");

    if (DPT.hasByName("DataPilotTable")) {
      DPT.removeByName("DataPilotTable");
    }

    DPT.insertNewByName("DataPilotTable", sCellAdress, DPDsc);
    XIndexAccess xIA = UnoRuntime.queryInterface(XIndexAccess.class, DPTS.getDataPilotTables());
    XIndexAccess IA = null;
    XDataPilotDescriptor xDPT =
        UnoRuntime.queryInterface(XDataPilotDescriptor.class, xIA.getByIndex(0));
    IA = xDPT.getRowFields();
    System.out.println("COUNT: " + IA.getCount());
    datapilotfield =
        (XInterface) AnyConverter.toObject(new Type(XInterface.class), IA.getByIndex(0));

    try {
      XDataPilotFieldGrouping dpfg =
          UnoRuntime.queryInterface(XDataPilotFieldGrouping.class, datapilotfield);
      String[] elements = new String[] {"aName", "otherName"};
      dpfg.createNameGroup(elements);
      DataPilotFieldGroupInfo dpgi = null;
      xIA = UnoRuntime.queryInterface(XIndexAccess.class, DPTS.getDataPilotTables());
      XDataPilotDescriptor xDPT2 =
          UnoRuntime.queryInterface(XDataPilotDescriptor.class, xIA.getByIndex(0));
      IA = xDPT2.getRowFields();
      for (int i = 0; i < IA.getCount(); i++) {
        datapilotfield =
            (XInterface) AnyConverter.toObject(new Type(XInterface.class), IA.getByIndex(i));
        XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, IA.getByIndex(i));
        if (((Boolean) xPropertySet.getPropertyValue("IsGroupField")).booleanValue()) {
          xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, datapilotfield);
          XNamed xNamed = UnoRuntime.queryInterface(XNamed.class, IA.getByIndex(i));
          System.out.println("name: " + xNamed.getName());
          dpgi = (DataPilotFieldGroupInfo) xPropertySet.getPropertyValue("GroupInfo");
        }
      }
      oObj = dpgi.Groups;
    } catch (Exception e) {
      e.printStackTrace();
    }

    log.println("Creating object - " + ((oObj == null) ? "FAILED" : "OK"));

    TestEnvironment tEnv = new TestEnvironment(oObj);

    log.println("Implementationname: " + util.utils.getImplName(oObj));

    // Other parameters required for interface tests
    return tEnv;
  }
  /** * creating a Testenvironment for the interfaces to be tested */
  protected synchronized TestEnvironment createTestEnvironment(
      TestParameters Param, PrintWriter log) {
    if (xTextDoc != null) {
      try {
        XCloseable closer = UnoRuntime.queryInterface(XCloseable.class, xTextDoc);
        closer.close(true);
      } catch (com.sun.star.util.CloseVetoException e) {
        log.println("couldn't close document");
      } catch (com.sun.star.lang.DisposedException e) {
        log.println("couldn't close document");
      }

      log.println("Existing document disposed");
    }

    log.println("creating a text document");
    xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) Param.getMSF()));

    // initialize test table
    if (isMySQLDB) {
      try {
        dbTools.initTestTableUsingJDBC(tableName, srcInf);
      } catch (java.sql.SQLException e) {
        e.printStackTrace(log);
        throw new StatusException(Status.failed("Couldn't " + " init test table. SQLException..."));
      } catch (java.lang.ClassNotFoundException e) {
        throw new StatusException(Status.failed("Couldn't " + "register mysql driver"));
      }
    }

    XInterface oObj = null;
    XShapes oShapes = null;
    XInterface oInstance = null;
    XConnection connection = null;

    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("creating a test environment");

    XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage(xTextDoc));

    try {
      String[] formNames = forms.getElementNames();

      for (int i = 0; i < formNames.length; i++) {
        log.println("Removing form '" + formNames[i] + "' ...");
        forms.removeByName(formNames[i]);
      }
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.container.NoSuchElementException e) {
      e.printStackTrace(log);
    }

    String[] formNames = forms.getElementNames();
    FormTools.insertForm(xTextDoc, forms, "MyForm");
    formNames = forms.getElementNames();

    XLoadable formLoader = null;

    try {
      formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName, tableName);
    } catch (com.sun.star.uno.Exception e) {
      log.println(
          "Cann't bind the form to source '" + dbSourceName + "', table '" + tableName + "' :");
      e.printStackTrace(log);
      throw new StatusException("Cann't bind a form", e);
    }

    // DEBUG
    log.println("Forms before adding controls : ");
    formNames = forms.getElementNames();

    for (int i = 0; i < formNames.length; i++) {
      log.println("    '" + formNames[i] + "'");
    }

    XControlShape shape1 = null;
    XControlShape shape2 = null;

    try {

      log.println("Elements in the 'MyForm' :");

      XIndexAccess formElements1 =
          UnoRuntime.queryInterface(XIndexAccess.class, forms.getByName("MyForm"));

      for (int i = 0; i < formElements1.getCount(); i++) {
        XNamed elemName = UnoRuntime.queryInterface(XNamed.class, formElements1.getByIndex(i));
        log.println("   '" + elemName.getName() + "'");
      }

      // END DEBUG
      // put something on the drawpage
      log.println("inserting some ControlShapes");
      oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc));
      shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 1000, "CommandButton");
      shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500, 5000, "TextField");

      XControlShape shape3 =
          FormTools.createControlShape(xTextDoc, 2000, 1500, 1000, 1000, "CheckBox");
      oShapes.add(shape1);
      oShapes.add(shape2);
      oShapes.add(shape3);
    } catch (Exception e) {
      e.printStackTrace(log);
    }

    log.println("Forms after adding controls : ");
    formNames = forms.getElementNames();

    for (int i = 0; i < formNames.length; i++) {
      log.println("    '" + formNames[i] + "'");
    }

    try {
      log.println("Elements in the 'MyForm' :");

      XIndexAccess formElements1 =
          UnoRuntime.queryInterface(XIndexAccess.class, forms.getByName("MyForm"));

      for (int i = 0; i < formElements1.getCount(); i++) {
        XNamed elemName = UnoRuntime.queryInterface(XNamed.class, formElements1.getByIndex(i));
        log.println("   '" + elemName.getName() + "'");
      }
    } catch (Exception e) {
      e.printStackTrace(log);
    }

    formLoader.load();

    try {
      oObj =
          (XForm)
              AnyConverter.toObject(
                  new Type(XForm.class),
                  (FormTools.getForms(WriterTools.getDrawPage(xTextDoc))).getByName("MyForm"));

      XPropertySet xSetProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
      connection =
          (XConnection)
              AnyConverter.toObject(
                  new Type(XConnection.class), xSetProp.getPropertyValue("ActiveConnection"));
    } catch (com.sun.star.uno.Exception e) {
      log.println("Couldn't get Form");
      e.printStackTrace(log);
    }

    // get a control
    oInstance = FormTools.createControl(xTextDoc, "TextField");

    log.println("creating a new environment for drawpage object");

    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation for closing connection while environment disposing.
    this.conn = connection;

    // adding relation for XSubmit
    XControlModel the_Model = shape2.getControl();
    XControlAccess the_access =
        UnoRuntime.queryInterface(XControlAccess.class, xTextDoc.getCurrentController());
    XControl cntrl = null;

    // now get the OEditControl
    try {
      cntrl = the_access.getControl(the_Model);
      log.println(cntrl.getClass().getName());
    } catch (com.sun.star.container.NoSuchElementException e) {
      log.println("Couldn't get OEditControl");
      e.printStackTrace(log);
      throw new StatusException("Couldn't get OEditControl", e);
    }

    XResultSet the_set = UnoRuntime.queryInterface(XResultSet.class, oObj);

    try {
      the_set.first();
    } catch (SQLException e) {
      log.println("Cann't move cursor to the first row.");
      e.printStackTrace();
      throw new StatusException("Can't move cursor to the first row.", e);
    }

    tEnv.addObjRelation("Model1", shape1.getControl());
    tEnv.addObjRelation("Model2", shape2.getControl());

    // adding an object for XNameReplace testing
    log.println("adding oInstace as obj relation to environment");
    tEnv.addObjRelation("INSTANCE", oInstance);

    // INDEX : _XNameContainer
    log.println("adding INDEX as obj relation to environment");
    tEnv.addObjRelation("INDEX", "0");

    // INDEX : _XNameReplace
    log.println("adding NameReplaceIndex as obj relation to environment");
    tEnv.addObjRelation("XNameReplaceINDEX", "2");

    // INSTANCEn : _XNameContainer; _XNameReplace
    log.println("adding INSTANCEn as obj relation to environment");

    // XComponent xComp = (XComponent)
    //    UnoRuntime.queryInterface(XComponent.class, xDrawDoc);
    String tc = (String) Param.get("THRCNT");
    int THRCNT = 1;

    if (tc != null) {
      THRCNT = Integer.parseInt(tc);
    }

    for (int n = 1; n < (2 * (THRCNT + 1)); n++) {
      log.println("adding INSTANCE" + n + " as obj relation to environment");
      tEnv.addObjRelation("INSTANCE" + n, FormTools.createControl(xTextDoc, "CheckBox"));
    }

    // adding relation for XNameContainer
    tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object());

    // adding relation for XPersistObject
    tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form");

    if (the_set != null) {
      log.println("The Form has a not empty ResultSet");
    }

    // Adding obj relation for XRowSetApproveBroadcaster test
    final XResultSet xResSet = UnoRuntime.queryInterface(XResultSet.class, oObj);
    final XResultSetUpdate xResSetUpdate = UnoRuntime.queryInterface(XResultSetUpdate.class, oObj);
    final XRowSet xRowSet = UnoRuntime.queryInterface(XRowSet.class, oObj);
    final PrintWriter logF = log;
    tEnv.addObjRelation(
        "XRowSetApproveBroadcaster.ApproveChecker",
        new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() {
          public void moveCursor() {
            try {
              xResSet.beforeFirst();
              xResSet.afterLast();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :");
              e.printStackTrace(logF);
            }
          }

          public RowChangeEvent changeRow() {
            try {
              xResSet.first();

              XRowUpdate row = UnoRuntime.queryInterface(XRowUpdate.class, xResSet);
              row.updateString(1, "1");
              xResSetUpdate.updateRow();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :");
              e.printStackTrace(logF);
            }

            RowChangeEvent ev = new RowChangeEvent();
            ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE;
            ev.Rows = 1;

            return ev;
          }

          public void changeRowSet() {
            try {
              xRowSet.execute();
            } catch (com.sun.star.sdbc.SQLException e) {
              logF.println(
                  "### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :");
              e.printStackTrace(logF);
            }
          }
        });

    // Adding relation for XColumnLocate test
    tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F);

    // Adding relation for XParameters ifc test
    ArrayList<Object> params = new ArrayList<Object>();

    /** *** statement parameter types and their initial values must be added here as relation. */
    params.add("SAU99");
    params.add(new Boolean(false));
    params.add(new Byte((byte) 123));
    params.add(new Short((short) 234));
    params.add(new Integer(12345));
    params.add(new Long(23456));
    params.add(new Float(1.234));
    params.add(new Double(2.345));
    params.add(new byte[] {1, 2, 3});
    Date d = new Date();
    d.Day = 26;
    d.Month = 1;
    d.Year = 2001;
    params.add(d);
    Time t = new Time();
    t.Hours = 1;
    t.NanoSeconds = 123456789;
    t.Minutes = 25;
    t.Seconds = 14;
    params.add(t);
    DateTime dt = new DateTime();
    dt.Day = 26;
    dt.Month = 1;
    dt.Year = 2001;
    dt.Hours = 1;
    dt.NanoSeconds = 123456789;
    dt.Minutes = 25;
    dt.Seconds = 14;
    params.add(dt);
    tEnv.addObjRelation("XParameters.ParamValues", params);

    // Adding relation for XCompletedExecution
    tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl());

    // Adding for XWarningSupplier
    tEnv.addObjRelation("CheckWarningsSupplier", new Boolean(isMySQLDB));

    // Adding relation for XDatabaseParameterBroadcaster
    tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl());
    XPropertySet xSetProp = UnoRuntime.queryInterface(XPropertySet.class, oObj);
    try {
      xSetProp.setPropertyValue("DataSourceName", dbSourceName);
      if (isMySQLDB) {
        xSetProp.setPropertyValue(
            "Command", "SELECT Column0  FROM soffice_test_table  WHERE ( (  Column0 = :param1 ) )");
      } else {
        xSetProp.setPropertyValue(
            "Command",
            "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )");
      }

      xSetProp.setPropertyValue("CommandType", new Integer(CommandType.COMMAND));
    } catch (Exception e) {
    }

    // Adding relation for XResultSetUpdate
    final XRowUpdate xRowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, oObj);
    final XRow xRow = UnoRuntime.queryInterface(XRow.class, oObj);

    tEnv.addObjRelation(
        "XResultSetUpdate.UpdateTester",
        new ifc.sdbc._XResultSetUpdate.UpdateTester() {
          String lastUpdate = null;

          public int rowCount() throws SQLException {
            int prevPos = xResSet.getRow();
            xResSet.last();

            int count = xResSet.getRow();
            xResSet.absolute(prevPos);

            return count;
          }

          public void update() throws SQLException {
            lastUpdate = xRow.getString(1);
            lastUpdate += "_";
            xRowUpdate.updateString(1, lastUpdate);
          }

          public boolean wasUpdated() throws SQLException {
            String getStr = xRow.getString(1);

            return lastUpdate.equals(getStr);
          }

          public int currentRow() throws SQLException {
            return xResSet.getRow();
          }
        });

    // Adding relations for XRow as a Vector with all data
    // of current row of RowSet.

    ArrayList<Object> rowData = new ArrayList<Object>();

    for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) {
      rowData.add(DBTools.TST_TABLE_VALUES[0][i]);
    }

    tEnv.addObjRelation("CurrentRowData", rowData);

    // Adding relation for XRowUpdate
    XRow row = UnoRuntime.queryInterface(XRow.class, oObj);
    tEnv.addObjRelation("XRowUpdate.XRow", row);

    tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle");

    PropertyValue propVal = new PropertyValue();
    propVal.Name = "Name";
    propVal.Value = "Text since XPropertyAccess";

    tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal);

    return tEnv;
  } // finish method getTestEnvironment
  // XRefreshable
  public void refresh() throws RuntimeException {
    // recycle shapes in first call, if document was loaded
    if (maBottomLine == null || maTopLine == null) {
      // try to recycle loaded shapes
      XPropertySet aDocProp = UnoRuntime.queryInterface(XPropertySet.class, maChartDocument);
      if (aDocProp != null) {
        try {
          XIndexAccess aShapesIA =
              UnoRuntime.queryInterface(
                  XIndexAccess.class, aDocProp.getPropertyValue("AdditionalShapes"));
          if (aShapesIA != null && aShapesIA.getCount() > 0) {
            XShape aShape;
            String aName;
            for (int i = aShapesIA.getCount() - 1; i >= 0; --i) {
              aShape = UnoRuntime.queryInterface(XShape.class, aShapesIA.getByIndex(i));
              if (aShape != null) {
                XPropertySet aProp = UnoRuntime.queryInterface(XPropertySet.class, aShape);
                aName = (String) aProp.getPropertyValue("Name");

                if (aName.equals("top")) {
                  maTopLine = aShape;
                } else if (aName.equals("bottom")) {
                  maBottomLine = aShape;
                }
              }
            }
          }
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE);
        }
      }
    }

    // create top line if it does not yet exist
    try {
      if (maTopLine == null) {
        maTopLine =
            UnoRuntime.queryInterface(
                XShape.class, maShapeFactory.createInstance("com.sun.star.drawing.LineShape"));
        maDrawPage.add(maTopLine);

        // make line red and thicker
        XPropertySet aShapeProp = UnoRuntime.queryInterface(XPropertySet.class, maTopLine);

        aShapeProp.setPropertyValue("LineColor", new Integer(0xe01010));
        aShapeProp.setPropertyValue("LineWidth", new Integer(50));
        aShapeProp.setPropertyValue("Name", "top");
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE);
    }

    // create bottom line if it does not yet exist
    try {
      if (maBottomLine == null) {
        maBottomLine =
            UnoRuntime.queryInterface(
                XShape.class, maShapeFactory.createInstance("com.sun.star.drawing.LineShape"));
        maDrawPage.add(maBottomLine);

        // make line green and thicker
        XPropertySet aShapeProp = UnoRuntime.queryInterface(XPropertySet.class, maBottomLine);

        aShapeProp.setPropertyValue("LineColor", new Integer(0x10e010));
        aShapeProp.setPropertyValue("LineWidth", new Integer(50));
        aShapeProp.setPropertyValue("Name", "bottom");
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE);
    }

    if (maTopLine == null || maBottomLine == null) {
      JOptionPane.showMessageDialog(
          null, "One of the lines is still null", "Assertion", JOptionPane.WARNING_MESSAGE);
      return;
    }

    // position lines

    // get data
    XChartDataArray aDataArray =
        UnoRuntime.queryInterface(XChartDataArray.class, maChartDocument.getData());
    double aData[][] = aDataArray.getData();

    // get axes
    XDiagram aDiagram = maChartDocument.getDiagram();
    XShape aXAxis =
        UnoRuntime.queryInterface(
            XShape.class, UnoRuntime.queryInterface(XAxisXSupplier.class, aDiagram).getXAxis());
    XShape aYAxis =
        UnoRuntime.queryInterface(
            XShape.class, UnoRuntime.queryInterface(XAxisYSupplier.class, aDiagram).getYAxis());

    // calculate points for hull
    final int nLength = aData.length;
    int i, j;
    double fMax, fMin;

    Point aMaxPtSeq[][] = new Point[1][];
    aMaxPtSeq[0] = new Point[nLength];
    Point aMinPtSeq[][] = new Point[1][];
    aMinPtSeq[0] = new Point[nLength];

    for (i = 0; i < nLength; i++) {
      fMin = fMax = aData[i][1];
      for (j = 1; j < aData[i].length; j++) {
        if (aData[i][j] > fMax) fMax = aData[i][j];
        else if (aData[i][j] < fMin) fMin = aData[i][j];
      }
      aMaxPtSeq[0][i] =
          new Point(
              getAxisPosition(aXAxis, aData[i][0], false), getAxisPosition(aYAxis, fMax, true));
      aMinPtSeq[0][i] =
          new Point(
              getAxisPosition(aXAxis, aData[i][0], false), getAxisPosition(aYAxis, fMin, true));
    }

    // apply point sequences to lines
    try {
      XPropertySet aShapeProp = UnoRuntime.queryInterface(XPropertySet.class, maTopLine);
      aShapeProp.setPropertyValue("PolyPolygon", aMaxPtSeq);

      aShapeProp = UnoRuntime.queryInterface(XPropertySet.class, maBottomLine);
      aShapeProp.setPropertyValue("PolyPolygon", aMinPtSeq);
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE);
    }
  }
Пример #12
0
 /** returns the sheet with the given index */
 public XCellRange getSheet(int index) throws com.sun.star.uno.Exception {
   XIndexAccess sheets = UnoRuntime.queryInterface(XIndexAccess.class, getSheets());
   return UnoRuntime.queryInterface(XCellRange.class, sheets.getByIndex(index));
 }