Hello Frank,
With regards to getting the frame from the desktop I used the
xDesktop.getCurrentFrame() API. This returned null.
With regards to Q2, I do initNew() the model:
class oooTests
{
static void controller( XMultiComponentFactory xServiceManager,
XComponentContext xComponentContext, LbaLogger lbaLogger )
throws java.lang.Exception
{
XModel xModel_A = null;
XModel xModel_B = null;
XInterface xInterface = (XInterface)
xServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop",
xComponentContext );
XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(
XDesktop.class, xInterface );
// XFrame xFrame = xDesktop.getCurrentFrame(); // This returns
null
PropertyValue[] openProperties = new PropertyValue[1];
openProperties[0] = new PropertyValue();
openProperties[0].Name = "Hidden";
openProperties[0].Value = new Boolean(true);
XComponentLoader xComponentLoader = (XComponentLoader)
UnoRuntime.queryInterface( XComponentLoader.class, xDesktop );
XComponent xComponent = xComponentLoader.loadComponentFromURL(
"private:factory/swriter", "_blank", 0, openProperties );
xModel_A = (XModel) UnoRuntime.queryInterface( XModel.class,
xComponent );
xInterface = (XInterface) xServiceManager.createInstanceWithContext(
"com.sun.star.text.TextDocument", xComponentContext );
xModel_B = (XModel) UnoRuntime.queryInterface( XModel.class,
xInterface );
xComponent = (XComponent) UnoRuntime.queryInterface(
XComponent.class, xInterface );
XLoadable xLoadable = (XLoadable) UnoRuntime.queryInterface(
XLoadable.class, xInterface );
xLoadable.initNew();
XController xController = xModel_A.getCurrentController();
if ( xController.attachModel( xModel_B ) )
lbaLogger.info( "Sucessfully attached xModel_B to desktop
controller" );
else
lbaLogger.info( "Did not sucessfully attach xModel_B to desktop
controller" );
} // oooTest
This returned: Did not sucessfully attach xModel_B to desktop controller
Meaning the xModel_B was not attached. Any reason why?
Thank you,
Daniel
> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: February 19, 2009 2:15 AM
> To: [email protected]
> Subject: Re: [api-dev] How to attach new Model to old Controller
>
> Hi Daniel,
>
> > Q1: Why can't I retieve the XFrame starting from the top (XDesktop)
> > while I can get it starting from the bottom (XModel)?
>
> Hard to answer without knowing how exactly you tried to
> retrieve the frame. I'd say that iterating over the frames at
> the desktop, and checking for a frame whose model is the one
> returned by loadComponentFromURL, should give you the frame.
> Is this what you do?
>
> > I sucessfully create a second XModel through the service manager
> > xServiceManager.createInstanceWithContext
> > ( "com.sun.star.text.TextDocument", xComponentContext )
> Call this
> > xModel_B
> >
> > Now what I would like to do is replace xModel_A with xModel_B.
> > I tried calling the XController.attachModel( xModel_B )
> which returns
> > False meaning the new model was not attached.
> >
> > Q2: How to I replace xModel_A with xModel_B in the
> > Frame-Controller-Model Structure?
>
> attachModel should be the right thing to do, however, I would
> not bet that all implementations properly support it.
>
> However, you did not mention that you initialized the second
> model after creating it. You should call one of the two
> XLoadable methods (initNew or load) before doing anything
> else with the model.
>
> Ciao
> Frank
>
> --
> - Frank Schönheit, Software Engineer
> [email protected] -
> - Sun Microsystems
> http://www.sun.com/staroffice -
> - OpenOffice.org Base
> http://dba.openoffice.org -
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - -
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]