Hi Oliver,
Thanks for the reply. The handler was not a uno service. I added the inner class which was present in the Dialog demo to the class, but still it is not working :(

I'm attaching the new Event handler to the mail.

I didn't get you when you said namespaces in *.xdl and *.xcu files. The xmlns is defined in the beginning of the files. Am I supposed to add anything more? The name and the package should be project specific from what I read, so I've put those values.

Any help would be great.

-Karthik

PS : I'm really stuck with this, as I've an entire extension working but my configuration dialog is part of a menu. Since OpenOffice suggests Tools->Options as the correct place to put any configuration related information, I'm trying this out. If this dummy project works then I can put my real configuration data in the extension project and continue.


Oliver Brinzing wrote:
Hi,

  Can someone please help me with this? I don't know what exactly I'm
doing wrong here.

are you sure that your com.example.EventHandler class is an uno service ?

from the dialog demo:

public static class _DialogEventHandler extends WeakBase
  implements XServiceInfo, XContainerWindowEventHandler

BTW: i cannot find any namespace declarations in your *.xdl and *.xcu files

Oliver


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.example;

import com.sun.star.awt.XContainerWindowEventHandler;
import com.sun.star.awt.XControl;
import com.sun.star.awt.XControlModel;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameAccess;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Karthik
 */
public class EventHandler {

 public static class _DialogEventHandler extends WeakBase
    implements XServiceInfo, XContainerWindowEventHandler
  {
    /**
     * Names of supported options pages. The name derives from the
     * actual file names of the .xdl files not a XML attribute.
     */
    public static String[] SupportedWindowNames = {"DLDialog"};

    static private final String __serviceName = "com.example.EventHandler";

    private XComponentContext context;
        private Component frame = new JFrame();

    public _DialogEventHandler(XComponentContext xCompContext)
    {
      this.context = xCompContext;
    }

    /**
     * This method returns an array of all supported service names.
     * @return Array of supported service names.
     */
    public String[] getSupportedServiceNames()
    {
      return getServiceNames();
    }

    /**
     * This method is a simple helper function to used in the
     * static component initialisation functions as well as in
     * getSupportedServiceNames.
     */
    public static String[] getServiceNames()
    {
      String[] sSupportedServiceNames = { __serviceName };
      return sSupportedServiceNames;
    }

    /** This method returns true, if the given service will be
      * supported by the component.
      * @param sServiceName Service name.
      * @return True, if the given service name will be supported.
      */
    public boolean supportsService( String sServiceName )
    {
      return sServiceName.equals( __serviceName );
    }

    /**
     * Return the class name of the component.
     * @return Class name of the component.
     */
    public String getImplementationName()
    {
      return _DialogEventHandler.class.getName();
    }

    /**
     * Is called by the OOo event system.
     * @param aWindow
     * @param aEventObject
     * @param sMethod
     * @return
     * @throws com.sun.star.lang.WrappedTargetException
     */
    public boolean callHandlerMethod(com.sun.star.awt.XWindow aWindow, Object 
aEventObject, String sMethod)
      throws WrappedTargetException
    {

      if (sMethod.equals("external_event") )
      {
        try
        {
          return handleExternalEvent(aWindow, aEventObject);
        }
        catch (com.sun.star.uno.RuntimeException re)
        {
          throw re;
        }
        catch (com.sun.star.uno.Exception e)
        {
          e.printStackTrace();
          throw new WrappedTargetException(sMethod, this, e);
        }
      }

      // return false when event was not handled
      return false;
    }

    /**
     * @return A String array containing the method names supported by this 
handler.
     */
    public String[] getSupportedMethodNames()
    {
      return new String[] {"external_event"};
    }

        private boolean handleExternalEvent(com.sun.star.awt.XWindow aWindow, 
Object aEventObject)
                throws com.sun.star.uno.Exception {
                try {
                        String sMethod = AnyConverter.toString(aEventObject);
                        if (sMethod.equals("ok")) {
                                JOptionPane.showMessageDialog(frame, "Ok 
clicked");
                        } else if (sMethod.equals("back") || 
sMethod.equals("initialize")) {
                                JOptionPane.showMessageDialog(frame, "Back 
clicked");
                        }
                        return true;
                } catch (com.sun.star.lang.IllegalArgumentException e) {
                        throw new com.sun.star.lang.IllegalArgumentException(
                                "Method external_event requires a string in the 
event object argument.", this,
                                (short) -1);
                }
        }

  }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@openoffice.org
For additional commands, e-mail: dev-h...@openoffice.org

Reply via email to