Abstract:

Vincenzo Giuliano wrote:

>I am not able to open new view on calc document
>  
>

Whoever seeks will find.
I writed this method which is fit for every OO Document and it opens
always the view.
what do you think of it?
Can I improve it?



/**return XController if the model exists
     * return null if the model does not exist */
    private static XController createView(String url)throws
java.lang.Exception{
        /**Bootstrap- Service Manager*/
        com.sun.star.uno.XComponentContext remoteContext =
com.sun.star.comp.helper.Bootstrap.bootstrap();
        System.out.println("Connected to a running office ...");
        com.sun.star.lang.XMultiComponentFactory serviceManager =
remoteContext.getServiceManager();
        String available = (serviceManager != null ? "available" : "not
available");
        System.out.println( "remote ServiceManager is " + available );
        /***/
       
        /**I create tje instance of desktop service*/
        XInterface desktop     =
(XInterface)serviceManager.createInstanceWithContext("com.sun.star.frame.Desktop",remoteContext);
       
        /**I Search the Components*/
        XDesktop xd =
(XDesktop)UnoRuntime.queryInterface(XDesktop.class,desktop);
        XEnumerationAccess xea = xd.getComponents();
        XEnumeration xe = xea.createEnumeration();
       
        /**I search the model affiliated to url*/
        XModel currentModel = null;
        boolean found = false;
        while(xe.hasMoreElements() && found==false){
           
            currentModel =
(XModel)UnoRuntime.queryInterface(XModel.class,xe.nextElement());
            if(currentModel!=null){
                found =
currentModel.getURL().trim().toLowerCase().equals(url.trim().toLowerCase());
            }
            else{
               
            }
           
        }
        /**If the model exists I create the new view*/
        if(found){           
       
            XDispatchHelper xdh =
(XDispatchHelper)UnoRuntime.queryInterface(XDispatchHelper.class,
                                   
serviceManager.createInstanceWithContext("com.sun.star.frame.DispatchHelper",remoteContext));

            XDispatchProvider xdp =
(XDispatchProvider)UnoRuntime.queryInterface(XDispatchProvider.class,currentModel.getCurrentController().getFrame());
           
           
            DispatchResultEvent dre =
(DispatchResultEvent)AnyConverter.toObject(DispatchResultEvent.class,
                                           
xdh.executeDispatch(xdp,".uno:NewWindow","",FrameSearchFlag.AUTO,new
PropertyValue[0]));
           
           
            return currentModel.getCurrentController();
        }
        else{
            return null;
        }
   

Regards, Vincenzo.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to