Ejemplo n.º 1
0
  protected boolean compareProperties(XPropertySet props1, XPropertySet props2) {

    Property[] p1 = props1.getPropertySetInfo().getProperties();
    Property[] p2 = props2.getPropertySetInfo().getProperties();

    if (p1.length != p2.length) {
      log.println("Number of properties differs");
      return false;
    }

    boolean result = true;

    for (int i = 0; i < p1.length; i++) {
      String propName = p1[i].Name;

      log.print("Comparing property '" + propName + "' ...");
      boolean res = false;
      try {
        res =
            ValueComparer.equalValue(
                props1.getPropertyValue(propName), props2.getPropertyValue(propName));
      } catch (com.sun.star.beans.UnknownPropertyException e) {
        log.println("Not found !");
      } catch (com.sun.star.lang.WrappedTargetException e) {
        log.println(e);
      }

      if (res) log.println("OK.");
      else log.println("Different !");

      result &= res;
    }

    return result;
  }
  @Test
  public void methodToMethod() throws Exception {

    ShapeHelperWrapper shapeHelperWrapper = Mockito.mock(ShapeHelperWrapper.class);
    UnoRuntimeWrapper unoRuntimeWrapper = Mockito.mock(UnoRuntimeWrapper.class);

    XShape method1 = Mockito.mock(XShape.class);

    XShape method2 = Mockito.mock(XShape.class);
    Mockito.when(shapeHelperWrapper.getNodeType(method2)).thenReturn(Node.NodeType.MethodOfProcess);

    XConnectorShape link = Mockito.mock(XConnectorShape.class);
    XPropertySet linkPropertySet = Mockito.mock(XPropertySet.class);

    Mockito.when(shapeHelperWrapper.isConnectorShape(link)).thenReturn(true);

    Mockito.when(linkPropertySet.getPropertyValue(ConnectedShapes.START_SHAPE)).thenReturn(method2);
    Mockito.when(linkPropertySet.getPropertyValue(ConnectedShapes.END_SHAPE)).thenReturn(method1);

    Mockito.when(unoRuntimeWrapper.queryInterface(XPropertySet.class, link))
        .thenReturn(linkPropertySet);

    Injector injector = Guice.createInjector(new TestModule(shapeHelperWrapper, unoRuntimeWrapper));

    DiagramWalker diagramWalker = injector.getInstance(DiagramWalker.class);

    //        diagramWalker.walk(Sets.newHashSet());
  }
  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
Ejemplo n.º 4
0
  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;
  }
Ejemplo n.º 5
0
 /** get size of the given page */
 public static Size getPageSize(XDrawPage xDrawPage)
     throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException {
   XPropertySet xPageProperties =
       (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xDrawPage);
   return new Size(
       ((Integer) xPageProperties.getPropertyValue("Width")).intValue(),
       ((Integer) xPageProperties.getPropertyValue("Height")).intValue());
 }
  /**
   * 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.");
    }
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
  @Test
  public void checkSequenceAccess() throws com.sun.star.uno.Exception {
    System.out.println("checking PropertySetAccess via sequences");
    createStandardBag(false);

    // ---------------------------------
    // XPropertyAccess.setPropertyValues
    final PropertyValue expectedValues[] = {
      new PropertyValue("BoolValue", -1, Boolean.FALSE, PropertyState.DIRECT_VALUE),
      new PropertyValue("StringValue", -1, "some text", PropertyState.DIRECT_VALUE),
      new PropertyValue("IntegerValue", -1, Integer.valueOf(3), PropertyState.DIRECT_VALUE),
      new PropertyValue("InterfaceValue", -1, m_bag, PropertyState.DIRECT_VALUE)
    };
    m_access.setPropertyValues(expectedValues);

    for (int i = 0; i < expectedValues.length; ++i) {
      final Object value = m_set.getPropertyValue(expectedValues[i].Name);
      if (!value.equals(expectedValues[i].Value)) {
        System.out.println("property name : " + expectedValues[i].Name);
        System.out.println("expected value: " + expectedValues[i].Value.toString());
        System.out.println("current value : " + value.toString());
        fail(
            "retrieving a previously set property ("
                + expectedValues[i].Value.getClass().toString()
                + ") failed");
      }
    }

    // ---------------------------------
    // XPropertyAccess.getPropertyValues
    final PropertyValue currentValues[] = m_access.getPropertyValues();
    for (int i = 0; i < currentValues.length; ++i) {
      final String name = currentValues[i].Name;
      final Object value = currentValues[i].Value;
      for (int j = 0; j < expectedValues.length; ++j) {
        if (expectedValues[j].Name.equals(name)) {
          if (!expectedValues[j].Value.equals(value)) {
            System.out.println("property name : " + expectedValues[j].Name);
            System.out.println("expected value: " + expectedValues[j].Value.toString());
            System.out.println("current value : " + value.toString());
            fail("getPropertyValues failed for property '" + name + "' failed");
          }
          break;
        }
      }

      if (!m_set.getPropertyValue(name).equals(value)) {
        fail(
            "XPropertyAccess::getPropertyValues() and XPropertyset::getPropertyValue results are inconsistent");
      }
    }
  }
Ejemplo n.º 9
0
  /* ------------------------------------------------------------------ */
  public void propertyChange(PropertyChangeEvent aEvent) throws com.sun.star.uno.RuntimeException {
    try {
      // did it come from a radio button or checkbox?
      if (aEvent.PropertyName.equals("State")) { // yep
        Short aNewState = (Short) aEvent.NewValue;

        XPropertySet xModel = UNO.queryPropertySet(aEvent.Source);
        String sName = (String) xModel.getPropertyValue("Name");

        Short aClassId = (Short) xModel.getPropertyValue("ClassId");
        if (FormComponentType.RADIOBUTTON == aClassId.shortValue()) {
          String sRefValue = (String) xModel.getPropertyValue("RefValue");

          short nNewValue = ((Short) aEvent.NewValue).shortValue();
          if (sName.equals("KeyGen")) {
            // it's one of the options for key generation
            if (sRefValue.equals("none")) { // no automatic generation at all
              m_aSalesmanKeyGenerator.stopGenerator();
              m_aSalesKeyGenerator.stopGenerator();
            } else {
              boolean bGenerateOnReset = true;
              if (sRefValue.equals("update")) { // generate on update
                bGenerateOnReset = (0 == nNewValue);
              } else if (sRefValue.equals("reset")) { // generate on reset
                bGenerateOnReset = (0 != nNewValue);
              }
              m_aSalesmanKeyGenerator.activateKeyGenerator(bGenerateOnReset);
              m_aSalesKeyGenerator.activateKeyGenerator(bGenerateOnReset);
            }
          }
        } else if (FormComponentType.CHECKBOX == aClassId.shortValue()) {
          boolean bEnabled = (0 != aNewState.shortValue());
          if (sName.equals("defaultdate")) {
            m_bDefaultSalesDate = bEnabled;
          } else if (sName.equals("protectkeys")) {
            m_bProtectKeyFields = bEnabled;
            m_aSalesmenLocker.enableLock(m_bProtectKeyFields);
            m_aSalesLocker.enableLock(m_bProtectKeyFields);
          } else if (sName.equals("emptysales")) {
            m_bAllowEmptySales = bEnabled;
            m_aSalesNameValidator.enableColumnWatch(m_bAllowEmptySales);
          }
        }
      }
    } catch (com.sun.star.uno.Exception e) {
      System.out.println(e);
      e.printStackTrace();
    }
  }
Ejemplo n.º 10
0
  public boolean checkStorageProperties(
      XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode) {
    boolean bOk = false;

    // get access to the XPropertySet interface
    XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStorage);
    if (xPropSet != null) {
      try {
        // get "MediaType", "IsRoot" and "OpenMode" properties and control there values
        String sPropMediaType = AnyConverter.toString(xPropSet.getPropertyValue("MediaType"));
        boolean bPropIsRoot = AnyConverter.toBoolean(xPropSet.getPropertyValue("IsRoot"));
        int nPropMode = AnyConverter.toInt(xPropSet.getPropertyValue("OpenMode"));

        bOk = true;
        if (!sPropMediaType.equals(sMediaType)) {
          Error(
              "'MediaType' property contains wrong value, expected '"
                  + sMediaType
                  + "', set '"
                  + sPropMediaType
                  + "' !");
          bOk = false;
        }

        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, expected "
                  + nMode
                  + ", in reality "
                  + nPropMode
                  + "!");
          bOk = false;
        }
      } catch (Exception e) {
        Error("Can't get properties of substorage, exception: " + e);
      }
    } else {
      Error("Can't get XPropertySet implementation from storage!");
    }

    return bOk;
  }
Ejemplo n.º 11
0
  /* ------------------------------------------------------------------ */
  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;
  }
Ejemplo n.º 12
0
    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);
      }
    }
Ejemplo n.º 13
0
 /**
  * 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;
 }
  private int getAxisPosition(XShape aAxis, double fValue, boolean bVertical) {
    int nResult = 0;

    if (aAxis != null) {
      XPropertySet aAxisProp = UnoRuntime.queryInterface(XPropertySet.class, aAxis);

      try {
        double fMin, fMax;
        fMin = ((Double) aAxisProp.getPropertyValue("Min")).doubleValue();
        fMax = ((Double) aAxisProp.getPropertyValue("Max")).doubleValue();
        double fRange = fMax - fMin;

        if (fMin <= fValue && fValue <= fMax && fRange != 0) {
          if (bVertical) {
            nResult =
                aAxis.getPosition().Y
                    + (int) ((aAxis.getSize().Height) * (1.0 - ((fValue - fMin) / fRange)));
          } else {
            nResult =
                aAxis.getPosition().X
                    + (int) ((aAxis.getSize().Width) * ((fValue - fMin) / fRange));
          }
        }
      } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex, "Exception caught", JOptionPane.WARNING_MESSAGE);
      }
    }
    return nResult;
  }
  @Test
  public void portToMethod_simpleLink() throws Exception {

    final XShape method = Mockito.mock(XShape.class, "method");
    Mockito.when(shapeHelperWrapper.getNodeType(method)).thenReturn(Node.NodeType.MethodOfProcess);

    final XShape serverPort = Mockito.mock(XShape.class, "serverPort");
    Mockito.when(shapeHelperWrapper.getNodeType(serverPort)).thenReturn(Node.NodeType.ServerPort);

    XShape linkShape = Mockito.mock(XShape.class, "linkShape");
    XConnectorShape linkConnector = Mockito.mock(XConnectorShape.class, "linkConnectorShape");
    XPropertySet linkPropertySet = Mockito.mock(XPropertySet.class, "linkPropertySet");
    Mockito.when(linkPropertySet.getPropertyValue("Text")).thenReturn("msg");

    Mockito.when(shapeHelperWrapper.isConnectorShape(linkShape)).thenReturn(true);

    Mockito.when(linkPropertySet.getPropertyValue(ConnectedShapes.START_SHAPE))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                return serverPort;
              }
            });

    Mockito.when(linkPropertySet.getPropertyValue(ConnectedShapes.START_SHAPE))
        .thenReturn(serverPort);

    Mockito.when(linkPropertySet.getPropertyValue(ConnectedShapes.END_SHAPE)).thenReturn(method);

    Mockito.when(unoRuntimeWrapper.queryInterface(XPropertySet.class, linkConnector))
        .thenReturn(linkPropertySet);

    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, linkShape))
        .thenReturn(linkConnector);

    Mockito.when(unoRuntimeWrapper.queryInterface(XShape.class, serverPort)).thenReturn(serverPort);
    Mockito.when(unoRuntimeWrapper.queryInterface(XShape.class, method)).thenReturn(method);

    // link end

    diagramWalker.setDiagramType(DiagramType.Process);

    diagramWalker.walk(Sets.newHashSet(method, linkShape, serverPort));

    Assert.assertEquals(diagramWalker.visited.size(), 3);
  }
Ejemplo n.º 16
0
  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;
  }
Ejemplo n.º 17
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();
    }
  }
Ejemplo n.º 18
0
  /* ------------------------------------------------------------------ */
  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);
  }
Ejemplo n.º 19
0
  @Before
  public void before() throws Exception {
    xMSF = getMSF();
    param = new TestParameters();
    param.put("ServiceFactory", xMSF); // important for param.getMSF()

    assertNotNull("could not create MultiServiceFactory.", xMSF);
    XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xMSF);
    Object defaultCtx = xPropertySet.getPropertyValue("DefaultContext");
    xContext = UnoRuntime.queryInterface(XComponentContext.class, defaultCtx);
    assertNotNull("could not get component context.", xContext);

    tempDir = util.utils.getOfficeTemp /*Dir*/(xMSF);
    System.out.println("tempdir: " + tempDir);

    foo = URI.create(xContext, "uri:foo");
    assertNotNull("foo", foo);
    bar = URI.create(xContext, "uri:bar");
    assertNotNull("bar", bar);
    baz = URI.create(xContext, "uri:baz");
    assertNotNull("baz", baz);

    blank1 = BlankNode.create(xContext, "_:1");
    assertNotNull("blank1", blank1);
    blank2 = BlankNode.create(xContext, "_:2");
    assertNotNull("blank2", blank2);
    blank3 = BlankNode.create(xContext, "_:3");
    assertNotNull("blank3", blank3);
    blank4 = BlankNode.create(xContext, "_:4");
    assertNotNull("blank4", blank4);
    rdf_type = URI.createKnown(xContext, URIs.RDF_TYPE);
    assertNotNull("rdf_type", rdf_type);
    rdfs_label = URI.createKnown(xContext, URIs.RDFS_LABEL);
    assertNotNull("rdfs_label", rdfs_label);
    pkg_Document = URI.createKnown(xContext, URIs.PKG_DOCUMENT);
    assertNotNull("pkg_Document", pkg_Document);
    pkg_hasPart = URI.createKnown(xContext, URIs.PKG_HASPART);
    assertNotNull("pkg_hasPart", pkg_hasPart);
    pkg_MetadataFile = URI.createKnown(xContext, URIs.PKG_METADATAFILE);
    assertNotNull("pkg_MetadataFile", pkg_MetadataFile);
    odf_ContentFile = URI.createKnown(xContext, URIs.ODF_CONTENTFILE);
    assertNotNull("odf_ContentFile", odf_ContentFile);
    odf_StylesFile = URI.createKnown(xContext, URIs.ODF_STYLESFILE);
    assertNotNull("odf_StylesFile", odf_StylesFile);
    odf_Element = URI.createKnown(xContext, URIs.ODF_ELEMENT);
    assertNotNull("odf_Element", odf_Element);
  }
  public synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {

    XInterface oObj = null;
    TestEnvironment tEnv = null;

    try {

      // creation of testobject here
      XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
      oObj =
          (XInterface)
              AnyConverter.toObject(
                  new Type(XInterface.class), props.getPropertyValue("AreaLinks"));
      XAreaLinks links = null;

      // adding one link into collection (for best testing)
      links = UnoRuntime.queryInterface(XAreaLinks.class, oObj);
      CellAddress addr = new CellAddress((short) 1, 2, 3);
      String aSourceArea = util.utils.getFullTestURL("calcshapes.sxc");
      links.insertAtPosition(addr, aSourceArea, "a2:b5", "", "");

      XEnumerationAccess ea = UnoRuntime.queryInterface(XEnumerationAccess.class, oObj);

      oObj = ea.createEnumeration();

      log.println("ImplementationName: " + util.utils.getImplName(oObj));
      // creating test environment
      tEnv = new TestEnvironment(oObj);

      tEnv.addObjRelation("ENUM", ea);

    } catch (com.sun.star.beans.UnknownPropertyException e) {
      log.println("Exception occurred while creating test Object.");
      e.printStackTrace(log);
      throw new StatusException("Couldn't create test object", e);
    } catch (com.sun.star.lang.WrappedTargetException e) {
      log.println("Exception occurred while creating test Object.");
      e.printStackTrace(log);
      throw new StatusException("Couldn't create test object", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      log.println("Exception occurred while creating test Object.");
      e.printStackTrace(log);
      throw new StatusException("Couldn't create test object", e);
    }

    return tEnv;
  }
Ejemplo n.º 21
0
  @Override
  public void handle(Object aFormComponent) throws com.sun.star.uno.Exception {
    // check if it's a button
    XPropertySet xProps = UNO.queryPropertySet(aFormComponent);
    XPropertySetInfo xPI = null;
    if (null != xProps) xPI = xProps.getPropertySetInfo();
    if ((null != xPI) && xPI.hasPropertyByName("ClassId")) {
      Short nClassId = (Short) xProps.getPropertyValue("ClassId");
      if (FormComponentType.COMMANDBUTTON == nClassId.shortValue()) {
        // yes, it is
        m_aOperator.revokeButton(xProps);
      }
    }

    // let the super class step down the tree (if possible)
    super.handle(aFormComponent);
  }
Ejemplo n.º 22
0
  @Test
  public void checkDynamicSet() throws com.sun.star.uno.Exception {
    System.out.println("checking proper dynamic of the set");
    createStandardBag(false);

    final PropertyValue props[] = {
      new PropertyValue("BoolValue", -1, Boolean.FALSE, PropertyState.DIRECT_VALUE),
      new PropertyValue("StringValue", -1, "test", PropertyState.DIRECT_VALUE),
      new PropertyValue("SomeOtherStringValue", -1, "string value", PropertyState.DIRECT_VALUE)
    };

    // try setting some property values which are not existent
    boolean caughtExpected = false;
    try {
      m_access.setPropertyValues(props);
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      caughtExpected = true;
    } catch (com.sun.star.uno.Exception e) {
    }
    if (!caughtExpected) {
      fail("the set shouldn't accept unknown property values, if not explicitly told to do so");
    }

    // re-create the bag, this time allow it to implicitly add properties
    createStandardBag(true);
    boolean success = false;
    try {
      m_access.setPropertyValues(props);
      success = true;
    } catch (com.sun.star.uno.Exception e) {
    }
    if (!success) {
      fail("property bag failed to implicitly add unknown properties");
    }

    // see whether this property was really added, and not just ignored
    final PropertyValue newlyAdded = props[props.length - 1];
    try {
      if (!m_set.getPropertyValue(newlyAdded.Name).equals(newlyAdded.Value)) {
        fail("the new property was not really added, or not added with the proper value");
      }
    } catch (com.sun.star.uno.Exception e) {
    }
  }
Ejemplo n.º 23
0
  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;
  }
Ejemplo n.º 24
0
  /** 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);
  }
Ejemplo n.º 25
0
  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;
  }
Ejemplo n.º 26
0
  public boolean InternalCheckStream(
      XStream xStream,
      String sName,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes,
      boolean bCheckCompressed) {
    // get input stream of substream
    XInputStream xInput = xStream.getInputStream();
    if (xInput == null) {
      Error("Can't get XInputStream implementation from substream '" + sName + "'!");
      return false;
    }

    byte pContents[][] = new byte[1][]; // ???

    // read contents
    try {
      xInput.readBytes(pContents, pBytes.length + 1);
    } catch (Exception e) {
      Error("Can't read from stream '" + sName + "', exception: " + e);
      return false;
    }

    // check size of stream data
    if (pContents.length == 0) {
      Error("SubStream '" + sName + "' reading produced disaster!");
      return false;
    }

    if (pBytes.length != pContents[0].length) {
      Error(
          "SubStream '"
              + sName
              + "' contains wrong amount of data! ("
              + pContents[0].length
              + "/"
              + pBytes.length
              + ")");
      return false;
    }

    // check stream data
    for (int ind = 0; ind < pBytes.length; ind++) {
      if (pBytes[ind] != pContents[0][ind]) {
        Error(
            "SubStream '"
                + sName
                + "' contains wrong data! ( byte num. "
                + ind
                + " should be "
                + pBytes[ind]
                + " but it is "
                + pContents[0][ind]
                + ")");
        return false;
      }
    }

    // check properties
    boolean bOk = false;

    // get access to the XPropertySet interface
    XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStream);
    if (xPropSet != null) {
      try {
        // get "MediaType" and "Size" properties and control there values
        String sPropMediaType = AnyConverter.toString(xPropSet.getPropertyValue("MediaType"));
        long nPropSize = AnyConverter.toLong(xPropSet.getPropertyValue("Size"));
        boolean bPropCompress = AnyConverter.toBoolean(xPropSet.getPropertyValue("Compressed"));

        bOk = true;
        if (!sPropMediaType.equals(sMediaType)) {
          Error(
              "'MediaType' property contains wrong value for stream '"
                  + sName
                  + "',\nexpected: '"
                  + sMediaType
                  + "', set: '"
                  + sPropMediaType
                  + "'!");
          bOk = false;
        }

        if (nPropSize != pBytes.length) {
          Error("'Size' property contains wrong value for stream'" + sName + "'!");
          bOk = false;
        }

        if (bCheckCompressed && bPropCompress != bCompressed) {
          Error("'Compressed' property contains wrong value for stream'" + sName + "'!");
          bOk = false;
        }
      } catch (Exception e) {
        Error("Can't get properties of substream '" + sName + "', exception: " + e);
      }
    } else {
      Error("Can't get XPropertySet implementation from stream '" + sName + "'!");
    }

    return bOk;
  }
Ejemplo n.º 27
0
  @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;
  }
Ejemplo n.º 28
0
  public void drawOrganigram() throws java.lang.Exception {
    // get the remote office component context
    xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
    System.out.println("Connected to a running office ...");
    // get the remote service manager
    xRemoteServiceManager = xRemoteContext.getServiceManager();

    Object desktop =
        xRemoteServiceManager.createInstanceWithContext(
            "com.sun.star.frame.Desktop", xRemoteContext);
    XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop);

    PropertyValue[] loadProps = new PropertyValue[0];
    XComponent xDrawComponent =
        xComponentLoader.loadComponentFromURL("private:factory/sdraw", "_blank", 0, loadProps);

    // get draw page by index
    com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier =
        UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent);
    com.sun.star.drawing.XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
    Object drawPage = xDrawPages.getByIndex(0);
    com.sun.star.drawing.XDrawPage xDrawPage =
        UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, drawPage);

    com.sun.star.lang.XMultiServiceFactory xDocumentFactory =
        UnoRuntime.queryInterface(com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent);

    com.sun.star.beans.XPropertySet xPageProps =
        UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xDrawPage);

    int pageWidth = AnyConverter.toInt(xPageProps.getPropertyValue("Width"));
    int pageHeight = AnyConverter.toInt(xPageProps.getPropertyValue("Height"));
    int pageBorderTop = AnyConverter.toInt(xPageProps.getPropertyValue("BorderTop"));
    int pageBorderLeft = AnyConverter.toInt(xPageProps.getPropertyValue("BorderLeft"));
    int pageBorderRight = AnyConverter.toInt(xPageProps.getPropertyValue("BorderRight"));
    int drawWidth = pageWidth - pageBorderLeft - pageBorderRight;
    int horCenter = pageBorderLeft + drawWidth / 2;

    String[][] orgUnits = new String[2][4];
    orgUnits[0][0] = "Management";
    orgUnits[1][0] = "Production";
    orgUnits[1][1] = "Purchasing";
    orgUnits[1][2] = "IT Services";
    orgUnits[1][3] = "Sales";
    int[] levelCount = {1, 4};

    int horSpace = 300;
    int verSpace = 3000;

    int shapeWidth = (drawWidth - (levelCount[1] - 1) * horSpace) / levelCount[1];
    int shapeHeight = pageHeight / 20;
    int shapeX = pageWidth / 2 - shapeWidth / 2;
    int shapeY = pageBorderTop;

    int levelY;
    int levelX;

    com.sun.star.drawing.XShape xStartShape = null;

    for (int level = 0; level <= 1; level++) {
      levelY = pageBorderTop + 2000 + level * (shapeHeight + verSpace);
      for (int i = levelCount[level] - 1; i > -1; i--) {
        shapeX =
            horCenter
                - (levelCount[level] * shapeWidth + (levelCount[level] - 1) * horSpace) / 2
                + i * shapeWidth
                + i * horSpace;
        Object shape = xDocumentFactory.createInstance("com.sun.star.drawing.RectangleShape");
        com.sun.star.drawing.XShape xShape =
            UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, shape);
        xShape.setPosition(new com.sun.star.awt.Point(shapeX, levelY));
        xShape.setSize(new com.sun.star.awt.Size(shapeWidth, shapeHeight));
        xDrawPage.add(xShape);

        com.sun.star.text.XText xText =
            UnoRuntime.queryInterface(com.sun.star.text.XText.class, xShape);

        xText.setString(orgUnits[level][i]);

        // memorize the root shape
        if (level == 0 && i == 0) xStartShape = xShape;

        if (level == 1) {
          Object connector = xDocumentFactory.createInstance("com.sun.star.drawing.ConnectorShape");
          com.sun.star.beans.XPropertySet xConnectorProps =
              UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, connector);
          com.sun.star.drawing.XShape xConnector =
              UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, connector);
          xDrawPage.add(xConnector);
          xConnectorProps.setPropertyValue("StartShape", xStartShape);
          xConnectorProps.setPropertyValue("EndShape", xShape);
          xConnectorProps.setPropertyValue(
              "StartGluePointIndex", new Integer(2)); // 2 = bottom glue point
          xConnectorProps.setPropertyValue(
              "EndGluePointIndex", new Integer(0)); // 0 = top glue point
        }
      }
    }
  }
  @Test
  public void methodToMethodSuccessfullCase() throws Exception {

    final XShape method1 = Mockito.mock(XShape.class, "method1");
    Mockito.when(shapeHelperWrapper.getNodeType(method1)).thenReturn(Node.NodeType.MethodOfProcess);

    final XShape method2 = Mockito.mock(XShape.class, "method2");
    Mockito.when(shapeHelperWrapper.getNodeType(method2)).thenReturn(Node.NodeType.ServerPort);

    // link start
    XShape link1Shape = Mockito.mock(XShape.class, "link1Shape");
    XConnectorShape link1Connector = Mockito.mock(XConnectorShape.class, "link1ConnectorShape");
    XPropertySet link1PropertySet = Mockito.mock(XPropertySet.class, "link1PropertySet");

    XShape link2Shape = Mockito.mock(XShape.class, "link2Shape");
    XConnectorShape link2Connector = Mockito.mock(XConnectorShape.class, "link2ConnectorShape");
    XPropertySet link2PropertySet = Mockito.mock(XPropertySet.class, "link2PropertySet");

    XShape linkTextShape = Mockito.mock(XShape.class, "linkTextShape");
    XPropertySet linkTextPropertySet = Mockito.mock(XPropertySet.class);

    Mockito.when(shapeHelperWrapper.isConnectorShape(link1Shape)).thenReturn(true);
    Mockito.when(shapeHelperWrapper.isConnectorShape(link2Shape)).thenReturn(true);

    Mockito.when(link1PropertySet.getPropertyValue(ConnectedShapes.START_SHAPE))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                return method1;
              }
            });

    Mockito.when(link1PropertySet.getPropertyValue(ConnectedShapes.END_SHAPE))
        .thenReturn(linkTextShape);

    Mockito.when(link2PropertySet.getPropertyValue(ConnectedShapes.START_SHAPE))
        .thenReturn(linkTextShape);

    Mockito.when(link2PropertySet.getPropertyValue(ConnectedShapes.END_SHAPE)).thenReturn(method2);

    Mockito.when(unoRuntimeWrapper.queryInterface(XPropertySet.class, link1Connector))
        .thenReturn(link1PropertySet);

    Mockito.when(unoRuntimeWrapper.queryInterface(XPropertySet.class, link2Connector))
        .thenReturn(link2PropertySet);

    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, link1Shape))
        .thenReturn(link1Connector);
    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, link2Shape))
        .thenReturn(link2Connector);

    Mockito.when(unoRuntimeWrapper.queryInterface(XShape.class, method2)).thenReturn(method2);
    Mockito.when(unoRuntimeWrapper.queryInterface(XShape.class, method1)).thenReturn(method1);
    Mockito.when(unoRuntimeWrapper.queryInterface(XShape.class, linkTextShape))
        .thenReturn(linkTextShape);

    Mockito.when(shapeHelperWrapper.isTextShape(linkTextShape)).thenReturn(true);
    Mockito.when(linkTextPropertySet.getPropertyValue("Text")).thenReturn("+");

    Mockito.when(unoRuntimeWrapper.queryInterface(XPropertySet.class, linkTextShape))
        .thenReturn(linkTextPropertySet);

    // link end

    diagramWalker.setDiagramType(DiagramType.Process);

    diagramWalker.walk(Sets.newHashSet(method1, link1Shape, link2Shape, linkTextShape, method2));

    Assert.assertEquals(diagramWalker.visited.size(), 5);
  }
  /** Переход от порта к методу, если поступило данное сообщение */
  @Ignore // TODO
  @Test
  public void portToMethod() throws Exception {

    final XShape method = Mockito.mock(XShape.class, "method");
    Mockito.when(shapeHelperWrapper.getNodeType(method)).thenReturn(Node.NodeType.MethodOfProcess);

    final XShape serverPort = Mockito.mock(XShape.class, "serverPort");
    Mockito.when(shapeHelperWrapper.getNodeType(serverPort)).thenReturn(Node.NodeType.ServerPort);

    // link start
    XShape link1Shape = Mockito.mock(XShape.class, "link1Shape");
    final XConnectorShape link1Connector =
        Mockito.mock(XConnectorShape.class, "link1ConnectorShape");
    XPropertySet link1PropertySet = Mockito.mock(XPropertySet.class, "link1PropertySet");

    XShape link2Shape = Mockito.mock(XShape.class, "link2Shape");
    final XConnectorShape link2Connector =
        Mockito.mock(XConnectorShape.class, "link2ConnectorShape");
    XPropertySet link2PropertySet = Mockito.mock(XPropertySet.class, "link2PropertySet");

    XShape linkTextShape = Mockito.mock(XShape.class, "linkTextShape");
    XPropertySet linkTextPropertySet = Mockito.mock(XPropertySet.class);

    Mockito.when(shapeHelperWrapper.isConnectorShape(link1Shape)).thenReturn(true);
    Mockito.when(shapeHelperWrapper.isConnectorShape(link2Shape)).thenReturn(true);

    Mockito.when(link1PropertySet.getPropertyValue(ConnectedShapes.START_SHAPE))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                return serverPort;
              }
            });

    Mockito.when(link1PropertySet.getPropertyValue(ConnectedShapes.START_SHAPE))
        .thenReturn(serverPort);

    Mockito.when(link1PropertySet.getPropertyValue(ConnectedShapes.END_SHAPE))
        .thenReturn(linkTextShape);

    Mockito.when(link2PropertySet.getPropertyValue(ConnectedShapes.START_SHAPE))
        .thenReturn(linkTextShape);

    Mockito.when(link2PropertySet.getPropertyValue(ConnectedShapes.END_SHAPE)).thenReturn(method);

    Mockito.when(unoRuntimeWrapper.queryInterface(XPropertySet.class, link1Connector))
        .thenReturn(link1PropertySet);

    Mockito.when(unoRuntimeWrapper.queryInterface(XPropertySet.class, link2Connector))
        .thenReturn(link2PropertySet);

    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, link1Shape))
        .thenReturn(link1Connector);
    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, link2Shape))
        .thenReturn(link2Connector);

    Mockito.when(unoRuntimeWrapper.queryInterface(XShape.class, serverPort)).thenReturn(serverPort);
    Mockito.when(unoRuntimeWrapper.queryInterface(XShape.class, method)).thenReturn(method);
    Mockito.when(unoRuntimeWrapper.queryInterface(XShape.class, linkTextShape))
        .thenReturn(linkTextShape);

    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, link2Shape))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                return link2Connector;
              }
            });

    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, link1Shape))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                return (link1Connector);
              }
            });

    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, link1Connector))
        .thenReturn(link1Connector);
    Mockito.when(unoRuntimeWrapper.queryInterface(XConnectorShape.class, link2Connector))
        .thenReturn(link2Connector);

    Mockito.when(shapeHelperWrapper.isTextShape(linkTextShape)).thenReturn(true);
    Mockito.when(linkTextPropertySet.getPropertyValue("Text")).thenReturn("msg");

    Mockito.when(unoRuntimeWrapper.queryInterface(XPropertySet.class, linkTextShape))
        .thenReturn(linkTextPropertySet);

    // link end

    diagramWalker.setDiagramType(DiagramType.Process);

    Graph walk1 =
        diagramWalker.walk(
            Sets.newHashSet(method, link1Shape, link2Shape, linkTextShape, serverPort));
    List<ConnectedShapesComplex> walk =
        new ArrayList<>(diagramWalker.getConnectedShapesComplexes());

    Assert.assertEquals(diagramWalker.visited.size(), 5);
    Assert.assertEquals(walk.size(), 1);
    ConnectedShapesComplex connectedShapesComplex = walk.get(0);
    Assert.assertEquals(connectedShapesComplex.fromShape, serverPort);
    Assert.assertEquals(connectedShapesComplex.toShape, method);
    Assert.assertEquals(connectedShapesComplex.textShape, linkTextShape);
  }