Exemplo n.º 1
0
  /**
   * Internal call back for frame action events, triggered by the used OnewayExecutor thread we
   * started in frameAction(). We use it to update our interception on the internal saved frame.
   *
   * @param aEvent describes the action
   */
  private void impl_frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent) {
    synchronized (this) {
      if (m_bDead) return;
    }

    // deregistration will be done every time...
    // But may it's not necessary to establish a new registration!
    // Don't look for ignoring actions - it was done already inside original frameAction() call!
    boolean bRegister = false;

    // analyze the event and decide which reaction is useful
    switch (aEvent.Action.getValue()) {
      case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value:
        bRegister = true;
        break;
      case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value:
        bRegister = true;
        break;
      case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value:
        bRegister = false;
        break;
    }

    com.sun.star.frame.XFrame xFrame = null;
    boolean bIsRegistered = false;
    synchronized (this) {
      bIsRegistered = m_bIsRegistered;
      m_bIsRegistered = false;
      xFrame = m_xFrame;
    }

    com.sun.star.frame.XDispatchProviderInterception xRegistration =
        UnoRuntime.queryInterface(com.sun.star.frame.XDispatchProviderInterception.class, xFrame);

    if (xRegistration == null) return;

    if (bIsRegistered) xRegistration.releaseDispatchProviderInterceptor(this);

    if (!bRegister) return;

    xRegistration.registerDispatchProviderInterceptor(this);
    synchronized (this) {
      m_bIsRegistered = true;
    }
  }
Exemplo n.º 2
0
  /**
   * call back for frame action events We use it to update our interception. Because if a new
   * component was loaded into the frame or another interceptor was registered, we should refresh
   * our connection to the frame. Otherwhise we can't guarantee full functionality here.
   *
   * <p>Note: Don't react synchronous in an asynchronous listener callback. So use a thread here to
   * update anything.
   *
   * @seealso impl_frameAction()
   * @param aEvent describes the action
   */
  public /*ONEWAY*/ void frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent) {
    synchronized (this) {
      if (m_bDead) return;
    }

    boolean bHandle = false;
    switch (aEvent.Action.getValue()) {
      case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value:
        bHandle = true;
        break;
      case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value:
        bHandle = true;
        break;
      case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value:
        bHandle = true;
        break;
        // Don't react for CONTEXT_CHANGED here. Ok it indicates, that may another interceptor
        // was registered at the frame ... but if we register ourself there - we get a context
        // changed too :-( Best way to produce a never ending recursion ...
        // May be that somewhere find a safe mechanism to detect own produced frame action events
        // and ignore it.
      case com.sun.star.frame.FrameAction.CONTEXT_CHANGED_value:
        System.out.println(
            "Time to update interception ... but may it will start a recursion. So I let it :-(");
        bHandle = false;
        break;
    }

    // ignore some events
    if (!bHandle) return;

    // pack the event and start thread - which call us back later
    ArrayList<Object> lOutParams = new ArrayList<Object>();
    lOutParams.add(aEvent);

    OnewayExecutor aExecutor =
        new OnewayExecutor(this, OnewayExecutor.REQUEST_FRAMEACTION, lOutParams);
    aExecutor.start();
  }