Example #1
0
  private void updateJoaUtil() {

    final long timeout = 10 * 1000;
    final long t1 = System.currentTimeMillis();

    synchronized (OfficeAddin.class) {
      while (true) {

        if (joaUtil != null) {
          break;
        }

        CoAppType app = getApplication();
        if (app == null) {
          break;
        }
        Object disp = app._get("COMAddIns");
        if (disp == null) {
          break;
        }
        COMAddIns addins = Dispatch.as(disp, COMAddIns.class);
        if (addins == null) {
          break;
        }

        COMAddIn addin = addins.Item("JoaUtilAddin.Class");
        if (addin != null) {
          if (!addin.getConnect()) {
            addin.setConnect(Boolean.TRUE);
          }
          IJoaUtilAddin x = Dispatch.as(addin.getObject(), IJoaUtilAddin.class);
          joaUtil = x;
          OfficeAddin.class.notifyAll();

          /// -- break while(true)
          break;
        } else {
          try {
            OfficeAddin.class.wait(500);
          } catch (InterruptedException e) {
            e.printStackTrace();
            break;
          }
        }

        long t2 = System.currentTimeMillis();
        if (t1 + timeout >= t2) {
          break;
        }
      }
    }
  }
Example #2
0
  @Override
  public void onConnection(
      IDispatch app, ext_ConnectMode connectMode, IDispatch addin, ByRef<Object[]> custom)
      throws ComException {
    applicationObject = app.as(applicationClass);
    applicationObject.withEvents(this);

    // Put this object into the COMAddIn wrapper supplied by the Office
    // application.
    // This is required to support folder views in Outlook.
    COMAddInImpl coAddin = addin.as(COMAddInImpl.class);
    coAddin.setObject(this);
  }