예제 #1
0
파일: AutoSave.java 프로젝트: zzz99977/core
  private void saveDoc(XInterface xDoc, String sURL) {
    m_aLog.log(Protocol.TYPE_SCOPE_OPEN, "saveDoc('" + sURL + "') started ...");
    try {
      URL[] aURL = new URL[1];
      aURL[0] = new URL();
      aURL[0].Complete = ".uno:SaveAs";
      m_xURLParser.parseStrict(aURL);

      XModel xModel = UnoRuntime.queryInterface(XModel.class, xDoc);
      XDispatchProvider xProvider =
          UnoRuntime.queryInterface(XDispatchProvider.class, xModel.getCurrentController());
      XDispatch xDispatch = xProvider.queryDispatch(aURL[0], "_self", 0);

      PropertyValue[] lArgs = new PropertyValue[3];
      lArgs[0] = new PropertyValue();
      lArgs[0].Name = "URL";
      lArgs[0].Value = sURL;
      lArgs[1] = new PropertyValue();
      lArgs[1].Name = "Overwrite";
      lArgs[1].Value = Boolean.TRUE;
      lArgs[2] = new PropertyValue();
      lArgs[2].Name = "StoreTo";
      lArgs[2].Value = Boolean.TRUE;

      xDispatch.dispatch(aURL[0], lArgs);

      m_aLog.log(Protocol.TYPE_OK, "saveDoc('" + sURL + "') = OK.");
    } catch (Throwable ex) {
      m_aLog.log(ex);
    }
    m_aLog.log(Protocol.TYPE_SCOPE_CLOSE, "saveDoc('" + sURL + "') finished.");
  }
예제 #2
0
  @Override
  protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
    SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF());

    log.println("creating a textdocument");
    xTextDoc = SOF.createTextDoc(null);

    log.println("maximize the window size");
    XModel xModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
    XFrame xFrame = xModel.getCurrentController().getFrame();
    XWindow xWin = xFrame.getContainerWindow();

    Toolkit.getDefaultToolkit();
    Dimension dim = new Dimension(800, 600);

    Rectangle newPosSize = xWin.getPosSize();
    newPosSize.Width = new Double(dim.getWidth()).intValue();
    newPosSize.Height = new Double(dim.getHeight()).intValue();
    newPosSize.X = 0;
    newPosSize.Y = 0;

    xWin.setPosSize(
        newPosSize.X,
        newPosSize.Y,
        newPosSize.Width,
        newPosSize.Height,
        com.sun.star.awt.PosSize.POSSIZE);
  }
예제 #3
0
  /*
   * returns the <CODE>XUserInputInterception</CODE> from the <CODE>XModel</CODE>
   * @param xModel the XModel of a document
   * @return the <CODE>XUserInputInterception</CODE> of the document
   */
  private XUserInputInterception getUII(XModel xModel) {

    XController xController = xModel.getCurrentController();

    XUserInputInterception xUII =
        UnoRuntime.queryInterface(XUserInputInterception.class, xController);
    if (xUII == null) {
      fail("could not get XUserInputInterception from XContoller");
    }
    return xUII;
  }
 public void before() {
   aListener = new _XRangeSelection.MyRangeSelectionListener(log);
   // workaround for i34499
   XModel xModel = (XModel) tEnv.getObjRelation("FirstModel");
   if (xModel == null)
     throw new StatusException(Status.failed("Object relation FirstModel' not set."));
   XWindow xWindow = xModel.getCurrentController().getFrame().getContainerWindow();
   XTopWindow xTopWindow = UnoRuntime.queryInterface(XTopWindow.class, xWindow);
   xTopWindow.toFront();
   util.utils.shortWait(500);
 }
예제 #5
0
  /**
   * Called to create an instance of <code>TestEnvironment</code> with an object to test and related
   * objects. Subclasses should implement this method to provide the implementation and related
   * objects. The method is called from <code>getTestEnvironment()</code>.
   *
   * @param tParam test parameters
   * @param log writer to log information while testing
   * @see TestEnvironment
   * @see #getTestEnvironment
   */
  @Override
  protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log)
      throws Exception {

    log.println("creating a test environment");

    if (xTextDoc != null) {
      xTextDoc.dispose(); // get a soffice factory object
    }
    SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF());

    log.println("creating a text document");
    xTextDoc = SOF.createTextDoc(null);

    util.utils.waitForEventIdle(tParam.getMSF());

    XModel aModel1 = UnoRuntime.queryInterface(XModel.class, xTextDoc);

    XController secondController = aModel1.getCurrentController();

    XDispatchProvider aProv = UnoRuntime.queryInterface(XDispatchProvider.class, secondController);

    XDispatch getting = null;

    log.println("opening DatasourceBrowser");
    URL the_url = new URL();
    the_url.Complete = ".component:DB/DataSourceBrowser";
    getting = aProv.queryDispatch(the_url, "_beamer", 12);
    PropertyValue[] noArgs = new PropertyValue[0];
    getting.dispatch(the_url, noArgs);

    util.utils.waitForEventIdle(tParam.getMSF());

    XFrame the_frame1 = the_Desk.getCurrentFrame();

    if (the_frame1 == null) {
      log.println("Current frame was not found !!!");
    }

    XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);

    the_frame2.setName("DatasourceBrowser");

    XInterface oObj = null;

    final XSelectionSupplier xSelect =
        UnoRuntime.queryInterface(XSelectionSupplier.class, the_frame2.getController());

    PropertyValue[] params =
        new PropertyValue[] {new PropertyValue(), new PropertyValue(), new PropertyValue()};
    params[0].Name = "DataSourceName";
    params[0].Value = "Bibliography";
    params[1].Name = "CommandType";
    params[1].Value = Integer.valueOf(com.sun.star.sdb.CommandType.TABLE);
    params[2].Name = "Command";
    params[2].Value = "biblio";

    final PropertyValue[] fParams = params;

    util.utils.waitForEventIdle(tParam.getMSF());

    XWindow xWindow = secondController.getFrame().getContainerWindow();

    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    AccessibilityTools.printAccessibleTree(
        log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

    oObj =
        AccessibilityTools.getAccessibleObjectForRole(
            xRoot, AccessibleRole.PANEL, "", "AccessibleBrowseBox");

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

    TestEnvironment tEnv = new TestEnvironment(oObj);

    tEnv.addObjRelation(
        "EventProducer",
        new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {

          public void fireEvent() {
            try {
              xSelect.select(fParams);
            } catch (com.sun.star.lang.IllegalArgumentException e) {
              e.printStackTrace();
            }
          }
        });

    return tEnv;
  }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code>
   *
   * <p>The calc document is set as a target document for importer. Imported XML-data contains only
   * settings tags including tag with new number of iteration steps. After import 'IterationCount'
   * proeprty getting from target document is checked. Object relations created :
   *
   * <ul>
   *   <li><code>'XDocumentHandler.XMLData'</code> for {@link ifc.xml.sax._XDocumentHandler}
   *       interface
   *   <li><code>'XDocumentHandler.ImportChecker'</code> for {@link ifc.xml.sax._XDocumentHandler}
   *       interface
   *   <li><code>'TargetDocument'</code> for {@link ifc.document._XImporter} interface
   * </ul>
   */
  public synchronized TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log)
      throws StatusException {

    XInterface oObj = null;
    Object oInt = null;

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

    XMultiServiceFactory xMSF = (XMultiServiceFactory) tParam.getMSF();
    final XPropertySet xPropSet;

    try {
      oInt = xMSF.createInstance("com.sun.star.comp.Calc.XMLSettingsImporter");
      XImporter imp = UnoRuntime.queryInterface(XImporter.class, oInt);
      imp.setTargetDocument(comp);

      XModel xSheetModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
      XController xController = xSheetModel.getCurrentController();
      xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xController);
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Can't create component.", e);
    }

    oObj = (XInterface) oInt;

    // create testobject here
    log.println("creating a new environment for Paragraph object");
    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation
    tEnv.addObjRelation("TargetDocument", comp);

    // adding relation for XDocumentHandler
    String[][] xml =
        new String[][] {
          {
            "start",
            "office:document-settings",
            "xmlns:office",
            "CDATA",
            "http://openoffice.org/2000/office",
            "xmlns:xlink",
            "CDATA",
            "http://www.w3.org/1999/xlink",
            "xmlns:config",
            "CDATA",
            "http://openoffice.org/2001/config"
          },
          {"start", "office:settings"},
          {"start", "config:config-item-set", "config:name", "CDATA", "view-settings"},
          {"start", "config:config-item-map-indexed", "config:name", "CDATA", "Views"},
          {"start", "config:config-item-map-entry"},
          {
            "start",
            "config:config-item",
            "config:name",
            "CDATA",
            "ShowGrid",
            "config:type",
            "CDATA",
            "boolean"
          },
          {"chars", "false"},
          {"end", "config:config-item"},
          {
            "start",
            "config:config-item",
            "config:name",
            "CDATA",
            "ZoomType",
            "config:type",
            "CDATA",
            "short"
          },
          {"chars", "0"},
          {
            "start",
            "config:config-item",
            "config:name",
            "CDATA",
            "ZoomValue",
            "config:type",
            "CDATA",
            "int"
          },
          {"chars", "124"},
          {"end", "config:config-item"},
          {"end", "config:config-item"},
          {"end", "config:config-item-map-entry"},
          {"end", "config:config-item-map-indexed"},
          {"end", "config:config-item-set"},
          {"end", "office:settings"},
          {"end", "office:document-settings"}
        };

    tEnv.addObjRelation("XDocumentHandler.XMLData", xml);

    final PrintWriter logF = log;

    tEnv.addObjRelation(
        "XDocumentHandler.ImportChecker",
        new ifc.xml.sax._XDocumentHandler.ImportChecker() {
          public boolean checkImport() {
            try {
              Object gVal = xPropSet.getPropertyValue("ShowGrid");
              logF.println("ShowGrid = " + gVal);
              return "false".equals(gVal);
            } catch (com.sun.star.uno.Exception e) {
              logF.println("Exception occurred while checking filter :");
              e.printStackTrace(logF);
              return false;
            }
          }
        });

    return tEnv;
  } // finish method getTestEnvironment
  /**
   * Determine the current top window center and return this as a point.
   *
   * @return a point representing the sheet center.
   */
  protected Point getSheetCenter() {
    log.println("Trying to get AccessibleSpreadsheet");
    new AccessibilityTools();
    XComponent xSheetDoc = (XComponent) tEnv.getObjRelation("DOCUMENT");

    XModel xModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
    System.out.println("Name: " + xModel.getCurrentController().getFrame().getName());

    XWindow xWindow = AccessibilityTools.getCurrentWindow(xModel);
    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    XAccessibleContext ctx =
        AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);

    XAccessibleComponent AccessibleSpreadsheet =
        UnoRuntime.queryInterface(XAccessibleComponent.class, ctx);

    log.println("Got " + util.utils.getImplName(AccessibleSpreadsheet));

    Object toolkit = null;

    try {
      toolkit = tParam.getMSF().createInstance("com.sun.star.awt.Toolkit");
    } catch (com.sun.star.uno.Exception e) {
      log.println("Couldn't get toolkit");
      e.printStackTrace(log);
      throw new StatusException("Couldn't get toolkit", e);
    }

    XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class, toolkit);

    XTopWindow tw = null;

    int k = tk.getTopWindowCount();
    for (int i = 0; i < k; i++) {
      try {
        XTopWindow tw_temp = tk.getTopWindow(i);
        XAccessible xacc = UnoRuntime.queryInterface(XAccessible.class, tw_temp);
        if (xacc != null) {
          if (xacc.getAccessibleContext().getAccessibleName().indexOf("d2") > 0) {
            tw = tw_temp;
          }
        } else {
          log.println("\t unknown window");
        }

      } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
      }
    }
    if (tw == null) {
      System.out.println("No TopWindow :-(");
      return null;
    }

    Point point = AccessibleSpreadsheet.getLocationOnScreen();
    Rectangle rect = AccessibleSpreadsheet.getBounds();
    Point retPoint = new Point();
    retPoint.X = point.X + (rect.Width / 2);
    retPoint.Y = point.Y + (rect.Height / 2);
    return retPoint;
  }