1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package com.sun.star.comp.beans; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir // @requirement FUNC.PERF.LRN/0.6 33*cdf0e10cSrcweir // @requirement FUNC.PERF.LOC/0.6 34*cdf0e10cSrcweir // @requirement FUNC.PERF.FIX/0.6 35*cdf0e10cSrcweir /** This is the basic JavaBean for all OOo application modules. 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir @requirement FUNC.RES.OTH/0.2 38*cdf0e10cSrcweir No other resources are needed yet. 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir @since OOo 2.0.0 41*cdf0e10cSrcweir */ 42*cdf0e10cSrcweir public class OOoBean 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir // @requirement FUNC.BEAN.VIEW/0.4 45*cdf0e10cSrcweir extends java.awt.Container 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir implements 48*cdf0e10cSrcweir // @requirement FUNC.PER/0.2 49*cdf0e10cSrcweir java.io.Externalizable 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir // timeout values (milli secs) 52*cdf0e10cSrcweir int nOOoStartTimeOut = 60000; 53*cdf0e10cSrcweir int nOOoCallTimeOut = 3000; 54*cdf0e10cSrcweir int nOOoCheckCycle = 1000; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir // This member contains the connection to an OOo instance if established. 57*cdf0e10cSrcweir private transient OfficeConnection iConnection; 58*cdf0e10cSrcweir private transient EventListener xConnectionListener; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // @requirement FUNC.BEAN.VIEW/0.4 61*cdf0e10cSrcweir // @requirement FUNC.BEAN.EDIT/0.4 62*cdf0e10cSrcweir // This member contains the OOo window 63*cdf0e10cSrcweir // if a connection is established. 64*cdf0e10cSrcweir // It is a child of the OOoBean canvas. 65*cdf0e10cSrcweir private OfficeWindow xFrameWindow; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir // application environment 68*cdf0e10cSrcweir private transient com.sun.star.lang.XMultiServiceFactory xServiceFactory; 69*cdf0e10cSrcweir private transient com.sun.star.frame.XDesktop xDesktop; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // document and frame 72*cdf0e10cSrcweir private transient Frame aFrame; 73*cdf0e10cSrcweir private transient Controller aController; 74*cdf0e10cSrcweir private transient OfficeDocument aDocument; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // slot command execution environment 77*cdf0e10cSrcweir private transient com.sun.star.frame.XDispatchProvider xDispatcher; 78*cdf0e10cSrcweir private transient com.sun.star.util.XURLTransformer xURLTransformer; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir // properties 81*cdf0e10cSrcweir private boolean bIgnoreVisibility = false; // to show even if already visible 82*cdf0e10cSrcweir private boolean bMenuBarVisible = true; 83*cdf0e10cSrcweir private boolean bStandardBarVisible = true; 84*cdf0e10cSrcweir private boolean bToolBarVisible = true; 85*cdf0e10cSrcweir private boolean bStatusBarVisible = true; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // debugging method 89*cdf0e10cSrcweir private void dbgPrint( String aMessage ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir // System.err.println( "OOoBean: " + aMessage ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir // @requirement FUNC.PER/0.2 95*cdf0e10cSrcweir /** @internal 96*cdf0e10cSrcweir * @deprecated 97*cdf0e10cSrcweir */ 98*cdf0e10cSrcweir public void writeExternal( java.io.ObjectOutput aObjOut ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir // TBD 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // @requirement FUNC.PER/0.2 104*cdf0e10cSrcweir /** @internal 105*cdf0e10cSrcweir * @deprecated 106*cdf0e10cSrcweir */ 107*cdf0e10cSrcweir public void readExternal( java.io.ObjectInput aObjIn ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir // TBD 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir /** Generic constructor of the OOoBean. 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir Neither a connection is established nor any document loaded. 115*cdf0e10cSrcweir */ 116*cdf0e10cSrcweir public OOoBean() 117*cdf0e10cSrcweir {} 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // @requirement FUNC.CON.MULT/0.3 120*cdf0e10cSrcweir /** Constructor for an OOoBean which uses a specific office connection. 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir The connection must be established but no document is loaded. 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir @throws NoConnectionException 125*cdf0e10cSrcweir if the connection is not established. 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir @deprecated Clients could use the getOOoConnection to obtain an OfficeConnection 128*cdf0e10cSrcweir and use it as argument in a constructor for another OOoBean instance. Calling 129*cdf0e10cSrcweir the dispose method of the OfficeConnection or the OOoBean's stopOOoConnection 130*cdf0e10cSrcweir method would make all instances of OOoBean stop working. 131*cdf0e10cSrcweir */ 132*cdf0e10cSrcweir public OOoBean( OfficeConnection iConnection ) 133*cdf0e10cSrcweir throws NoConnectionException 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir try { setOOoConnection( iConnection ); } 136*cdf0e10cSrcweir catch ( HasConnectionException aExc ) 137*cdf0e10cSrcweir { /* impossible here */ } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir /** Sets the timeout for methods which launch OOo in milli seconds. 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir This method does not need a connection to an OOo instance. 143*cdf0e10cSrcweir */ 144*cdf0e10cSrcweir public void setOOoStartTimeOut( int nMilliSecs ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir nOOoStartTimeOut = nMilliSecs; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir /** Sets the timeout for normal OOO methods calls in milli seconds. 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir This method does not need a connection to an OOo instance. 152*cdf0e10cSrcweir */ 153*cdf0e10cSrcweir public void setOOoCallTimeOut( int nMilliSecs ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir nOOoCallTimeOut = nMilliSecs; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir /** Sets the period length in milli seconds to check the OOo connection. 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir This method does not need a connection to an OOo instance. 161*cdf0e10cSrcweir */ 162*cdf0e10cSrcweir public void setOOoCheckCycle( int nMilliSecs ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir nOOoCheckCycle = nMilliSecs; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir /** Sets the a connection to an OOo instance. 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir @internal 170*cdf0e10cSrcweir */ 171*cdf0e10cSrcweir private synchronized void setOOoConnection( OfficeConnection iNewConnection ) 172*cdf0e10cSrcweir throws HasConnectionException, NoConnectionException 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir // the connection cannot be exchanged 175*cdf0e10cSrcweir if ( iConnection != null ) 176*cdf0e10cSrcweir throw new HasConnectionException(); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // is there a real connection, not just the proxy? 179*cdf0e10cSrcweir com.sun.star.uno.XComponentContext xComponentContext = null; 180*cdf0e10cSrcweir try { xComponentContext = iNewConnection.getComponentContext(); } 181*cdf0e10cSrcweir catch ( java.lang.Throwable aExc ) 182*cdf0e10cSrcweir { throw new NoConnectionException(); } 183*cdf0e10cSrcweir if ( xComponentContext == null ) 184*cdf0e10cSrcweir throw new NoConnectionException(); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // set the connection 187*cdf0e10cSrcweir iConnection = iNewConnection; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // get notified when connection dies 190*cdf0e10cSrcweir if ( xConnectionListener != null ) 191*cdf0e10cSrcweir xConnectionListener.end(); 192*cdf0e10cSrcweir xConnectionListener = this.new EventListener("setOOoConnection"); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // @requirement FUNC.CON.STRT/0.4 196*cdf0e10cSrcweir /** Starts a connection to an OOo instance which is lauched if not running. 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir @throws HasConnectionException 199*cdf0e10cSrcweir if a connection was already established. 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir @throws NoConnectionException 202*cdf0e10cSrcweir if the specified connection cannot be established 203*cdf0e10cSrcweir */ 204*cdf0e10cSrcweir public void startOOoConnection( String aConnectionURL ) 205*cdf0e10cSrcweir throws java.net.MalformedURLException, 206*cdf0e10cSrcweir HasConnectionException, 207*cdf0e10cSrcweir NoConnectionException 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir // create a new connection from the given connection URL 210*cdf0e10cSrcweir LocalOfficeConnection aConnection = new LocalOfficeConnection(); 211*cdf0e10cSrcweir aConnection.setUnoUrl( aConnectionURL ); 212*cdf0e10cSrcweir setOOoConnection( aConnection ); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // @requirement FUNC.CON.CHK/0.7 216*cdf0e10cSrcweir /** Returns true if this OOoBean is connected to an OOo instance, 217*cdf0e10cSrcweir false otherwise. 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir @deprecated This method is not useful in a multithreaded environment. Then 220*cdf0e10cSrcweir all threads accessing the instance would have to be synchronized in order to 221*cdf0e10cSrcweir make is method work. It is better 222*cdf0e10cSrcweir to call OOoBean's methods and be prepared to catch a NoConnectionException. 223*cdf0e10cSrcweir */ 224*cdf0e10cSrcweir public boolean isOOoConnected() 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir return iConnection != null; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // @requirement FUNC.CON.STOP/0.4 230*cdf0e10cSrcweir /** Disconnects from the connected OOo instance. 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir If there was no connection yet or anymore, this method can be called 233*cdf0e10cSrcweir anyway. 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir When the OOoBean is displayed in an applet by a web browser, then this 236*cdf0e10cSrcweir method must be called from within java.applet.Applet.stop. 237*cdf0e10cSrcweir */ 238*cdf0e10cSrcweir public synchronized void stopOOoConnection() 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir // clear OOo document, frame etc. 241*cdf0e10cSrcweir clear(); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir // cut the connection 244*cdf0e10cSrcweir OfficeConnection iExConnection = iConnection; 245*cdf0e10cSrcweir if ( iConnection != null ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir if ( xConnectionListener != null ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir xConnectionListener.end(); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir iConnection = null; 252*cdf0e10cSrcweir iExConnection.dispose(); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir // @requirement FUNC.CON.STOP/0.4 (via XComponent.dispose()) 258*cdf0e10cSrcweir // @requirement FUNC.CON.NTFY/0.4 (via XComponent.addEventListener()) 259*cdf0e10cSrcweir /** Returns the a connection to an OOo instance. 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir If no connection exists, a default connection will be created. An OfficeConnection 262*cdf0e10cSrcweir can be used to register listeners of type com.sun.star.lang.EventListener, 263*cdf0e10cSrcweir which are notified when the connection to the 264*cdf0e10cSrcweir office dies. One should not call the dispose method, because this may result 265*cdf0e10cSrcweir in receiving com.sun.star.lang.DisposedExceptions when calling 266*cdf0e10cSrcweir {@link #stopOOoConnection stopOOoConnection} or other API methods. If other instances share the 267*cdf0e10cSrcweir same connection then they will stop function properly, because they loose their 268*cdf0e10cSrcweir connection as well. The recommended way to end the connection is 269*cdf0e10cSrcweir calling {@link #stopOOoConnection stopOOoConnection}. 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir @throws NoConnectionException 272*cdf0e10cSrcweir if no connection can be established 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir */ 275*cdf0e10cSrcweir public synchronized OfficeConnection getOOoConnection() 276*cdf0e10cSrcweir throws NoConnectionException 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir if ( iConnection == null ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir try { setOOoConnection( new LocalOfficeConnection() ); } 281*cdf0e10cSrcweir catch ( HasConnectionException aExc ) 282*cdf0e10cSrcweir { /* impossible here */ } 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir if ( iConnection.getComponentContext() == null ) 285*cdf0e10cSrcweir throw new NoConnectionException(); 286*cdf0e10cSrcweir return iConnection; 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir /** Returns the service factory used by this OOoBean instance. 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir @throws NoConnectionException 292*cdf0e10cSrcweir if no connection is established and no default connection can be established. 293*cdf0e10cSrcweir */ 294*cdf0e10cSrcweir public synchronized com.sun.star.lang.XMultiServiceFactory getMultiServiceFactory() 295*cdf0e10cSrcweir throws NoConnectionException 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir if ( xServiceFactory == null ) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir // avoid concurrent access from multiple threads 300*cdf0e10cSrcweir final OfficeConnection iConn = getOOoConnection(); 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir Thread aConnectorThread = new Thread() { 303*cdf0e10cSrcweir public void run() 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir com.sun.star.lang.XMultiComponentFactory aFactory = 306*cdf0e10cSrcweir iConn.getComponentContext().getServiceManager(); 307*cdf0e10cSrcweir xServiceFactory = (com.sun.star.lang.XMultiServiceFactory) 308*cdf0e10cSrcweir UnoRuntime.queryInterface( 309*cdf0e10cSrcweir com.sun.star.lang.XMultiServiceFactory.class, aFactory ); 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir }; 312*cdf0e10cSrcweir aConnectorThread.start(); 313*cdf0e10cSrcweir try { aConnectorThread.join(nOOoStartTimeOut); } 314*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 315*cdf0e10cSrcweir { throw new NoConnectionException(); } 316*cdf0e10cSrcweir if ( xServiceFactory == null ) 317*cdf0e10cSrcweir throw new NoConnectionException(); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir return xServiceFactory; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir /** Returns the XDesktop interface of the OOo instance used by this OOoBean. 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir @throws NoConnectionException 326*cdf0e10cSrcweir if no connection is established and no default connection can be established. 327*cdf0e10cSrcweir */ 328*cdf0e10cSrcweir public synchronized com.sun.star.frame.XDesktop getOOoDesktop() 329*cdf0e10cSrcweir throws NoConnectionException 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir if ( xDesktop == null ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir try 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir Object aObject = getMultiServiceFactory().createInstance( "com.sun.star.frame.Desktop"); 336*cdf0e10cSrcweir xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface( 337*cdf0e10cSrcweir com.sun.star.frame.XDesktop.class, aObject ); 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir catch ( com.sun.star.uno.Exception aExc ) 340*cdf0e10cSrcweir {} // TBD: what if no connection exists? 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir return xDesktop; 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir /** Resets this bean to an empty document. 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir If a document is loaded and the content modified, 349*cdf0e10cSrcweir the changes are dismissed. Otherwise nothing happens. 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir This method is intended to be overridden in derived classes. 352*cdf0e10cSrcweir This implementation simply calls clear. 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir @param bClearStateToo 355*cdf0e10cSrcweir Not only the document content but also the state of the bean, 356*cdf0e10cSrcweir like visibility of child components is cleared. 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir @deprecated There is currently no way to dismiss changes, except for loading 359*cdf0e10cSrcweir of the unchanged initial document. Furthermore it is unclear how derived classes 360*cdf0e10cSrcweir handle this and what exactly their state is (e.g. what members make up their state). 361*cdf0e10cSrcweir Calling this method on a derived class requires knowledge about their implementation. 362*cdf0e10cSrcweir Therefore a deriving class should declare their own clearDocument if needed. Clients 363*cdf0e10cSrcweir should call the clearDocument of the deriving class or {@link #clear} which discards 364*cdf0e10cSrcweir the currently displayed document. 365*cdf0e10cSrcweir */ 366*cdf0e10cSrcweir public synchronized void clearDocument( boolean bClearStateToo ) 367*cdf0e10cSrcweir throws 368*cdf0e10cSrcweir com.sun.star.util.CloseVetoException, 369*cdf0e10cSrcweir NoConnectionException 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir // TBD 372*cdf0e10cSrcweir clear(); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir /** Resets the OOoBean to an empty status. 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir Any loaded document is unloaded, no matter whether it is modified or not. 378*cdf0e10cSrcweir After calling this method, the OOoBean has no office document and no frame 379*cdf0e10cSrcweir anymore. The connection will stay, though. 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir This method works with or without an established connection. 382*cdf0e10cSrcweir */ 383*cdf0e10cSrcweir public synchronized void clear() 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir dbgPrint( "clear()" ); 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir try 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir CallWatchThread aCallWatchThread = 390*cdf0e10cSrcweir new CallWatchThread( nOOoCallTimeOut, "clear" ); 391*cdf0e10cSrcweir //By closing the frame we avoid that dialogs are displayed, for example when 392*cdf0e10cSrcweir //the document is modified. 393*cdf0e10cSrcweir com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable) 394*cdf0e10cSrcweir UnoRuntime.queryInterface( com.sun.star.util.XCloseable.class, aFrame ); 395*cdf0e10cSrcweir if ( xCloseable != null ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir try 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir xCloseable.close(true); 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir catch (com.sun.star.util.CloseVetoException exc) 402*cdf0e10cSrcweir { // a print job may be running 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir aDocument = null; 407*cdf0e10cSrcweir xDispatcher = null; 408*cdf0e10cSrcweir aFrame = null; 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir // clear xFrameWindow 411*cdf0e10cSrcweir if ( xFrameWindow != null ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir try { releaseSystemWindow(); } 414*cdf0e10cSrcweir catch ( NoConnectionException aExc ) 415*cdf0e10cSrcweir {} // ignore 416*cdf0e10cSrcweir catch ( SystemWindowException aExc ) 417*cdf0e10cSrcweir {} // ignore 418*cdf0e10cSrcweir remove( xFrameWindow.getAWTComponent() ); 419*cdf0e10cSrcweir xFrameWindow = null; 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir // clear xURTTransformer 423*cdf0e10cSrcweir if ( xURLTransformer != null ) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir try 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir com.sun.star.lang.XComponent xComp = (com.sun.star.lang.XComponent) 428*cdf0e10cSrcweir UnoRuntime.queryInterface( 429*cdf0e10cSrcweir com.sun.star.lang.XComponent.class, xURLTransformer ); 430*cdf0e10cSrcweir if ( xComp != null ) 431*cdf0e10cSrcweir xComp.dispose(); 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir catch ( java.lang.Throwable aExc ) 434*cdf0e10cSrcweir {} // ignore 435*cdf0e10cSrcweir xURLTransformer = null; 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir xDesktop = null; 439*cdf0e10cSrcweir xServiceFactory = null; 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir aCallWatchThread.cancel(); 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 444*cdf0e10cSrcweir { /* can be ignored */ } 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir // @requirement FUNC.PAR.LWP/0.4 448*cdf0e10cSrcweir /** This method causes the office window to be displayed. 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir If no document is loaded and the instance is added to a Java container that 451*cdf0e10cSrcweir is showing, then this method needs not to be called. If later one of the methods 452*cdf0e10cSrcweir {@link #loadFromURL loadFromURL}, {@link #loadFromStream loadFromStream1}, 453*cdf0e10cSrcweir or {@link #loadFromByteArray loadFromByteArray} 454*cdf0e10cSrcweir is called, then the document is automatically displayed. 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir Should one of the load methods have been called before the Java container 457*cdf0e10cSrcweir was showing, then this method needs to be called after the container window 458*cdf0e10cSrcweir was made visible (java.lang.Component.setVisible(true)). 459*cdf0e10cSrcweir <p> 460*cdf0e10cSrcweir Another scenario is that a OOoBean contains a document and is removed 461*cdf0e10cSrcweir from a Java container and later added again. Then aquireSystemWindow needs 462*cdf0e10cSrcweir to be called after the container window is displayed. 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir @throws SystemWindowException 465*cdf0e10cSrcweir if no system window can be aquired. 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir @throws NoConnectionException 468*cdf0e10cSrcweir if the connection is not established. 469*cdf0e10cSrcweir */ 470*cdf0e10cSrcweir public synchronized void aquireSystemWindow() 471*cdf0e10cSrcweir throws 472*cdf0e10cSrcweir SystemWindowException, 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 475*cdf0e10cSrcweir NoConnectionException 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir if ( iConnection == null ) 478*cdf0e10cSrcweir throw new NoConnectionException(); 479*cdf0e10cSrcweir if ( !isShowing() ) 480*cdf0e10cSrcweir throw new SystemWindowException(); 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir if ( xFrameWindow != null ) 483*cdf0e10cSrcweir xFrameWindow.getAWTComponent().setVisible(true); 484*cdf0e10cSrcweir doLayout(); 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir // @requirement FUNC.PAR.RWL/0.4 488*cdf0e10cSrcweir // @estimation 16h 489*cdf0e10cSrcweir /** This method must be called when the OOoBean before the 490*cdf0e10cSrcweir sytem window may be released by it's parent AWT/Swing component. 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir This is the case when java.awt.Component.isDisplayable() returns 493*cdf0e10cSrcweir true. This is definitely the case when the OOoBean is removed 494*cdf0e10cSrcweir from it's parent container. 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir @throws SystemWindowException 497*cdf0e10cSrcweir if system window is not aquired. 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir @throws NoConnectionException 500*cdf0e10cSrcweir if the connection is not established. 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir @deprecated When Component.removeNotify of the parent window of the actual 503*cdf0e10cSrcweir office window is called, then the actions are performed for which this method 504*cdf0e10cSrcweir needed to be called previously. 505*cdf0e10cSrcweir */ 506*cdf0e10cSrcweir public synchronized void releaseSystemWindow() 507*cdf0e10cSrcweir throws 508*cdf0e10cSrcweir SystemWindowException, 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 511*cdf0e10cSrcweir NoConnectionException 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir if ( iConnection == null ) 514*cdf0e10cSrcweir throw new NoConnectionException(); 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir try { xFrameWindow.getAWTComponent().setVisible(false); } 517*cdf0e10cSrcweir catch ( com.sun.star.lang.DisposedException aExc ) 518*cdf0e10cSrcweir { throw new NoConnectionException(); } 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir // @requirement FUNC.BEAN.LOAD/0.4 522*cdf0e10cSrcweir // @requirement FUNC.CON.AUTO/0.3 523*cdf0e10cSrcweir /** Loads the bean from the given URL. 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir If a document is already loaded and the content modified, 526*cdf0e10cSrcweir the changes are dismissed. 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir If no connection exists, a default connection is established. 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir @throws IllegalArgumentException 531*cdf0e10cSrcweir if either of the arguments is out of the specified range. 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir @throws java.io.IOException 534*cdf0e10cSrcweir if an IO error occurs reading the ressource specified by the URL. 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir @throws com.sun.star.lang.NoConnectionException 537*cdf0e10cSrcweir if no connection can be established. 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir @throws com.sun.star.util.CloseVetoException 540*cdf0e10cSrcweir if the currently displayed document cannot be closed because it is 541*cdf0e10cSrcweir still be used, for example it is printed. 542*cdf0e10cSrcweir */ 543*cdf0e10cSrcweir public void loadFromURL( 544*cdf0e10cSrcweir final String aURL, 545*cdf0e10cSrcweir final com.sun.star.beans.PropertyValue aArguments[] ) 546*cdf0e10cSrcweir throws 547*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 548*cdf0e10cSrcweir NoConnectionException, 549*cdf0e10cSrcweir java.io.IOException, 550*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, 551*cdf0e10cSrcweir com.sun.star.util.CloseVetoException 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir dbgPrint( "loadFromURL()" ); 554*cdf0e10cSrcweir // try loading 555*cdf0e10cSrcweir try 556*cdf0e10cSrcweir { 557*cdf0e10cSrcweir boolean bLoaded = false; 558*cdf0e10cSrcweir while ( !bLoaded ) 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir // watch loading in a thread with a timeout (if OOo hangs) 561*cdf0e10cSrcweir CallWatchThread aCallWatchThread = 562*cdf0e10cSrcweir new CallWatchThread( nOOoStartTimeOut, "loadFromURL" ); 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir try 565*cdf0e10cSrcweir { 566*cdf0e10cSrcweir // get window from OOo on demand 567*cdf0e10cSrcweir if ( xFrameWindow == null ) 568*cdf0e10cSrcweir { 569*cdf0e10cSrcweir // Establish the connection by request of the ServiceFactory. 570*cdf0e10cSrcweir getMultiServiceFactory(); 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir // remove existing child windows 573*cdf0e10cSrcweir removeAll(); 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir // Create the OfficeWindow. 576*cdf0e10cSrcweir xFrameWindow = getOOoConnection().createOfficeWindow(OOoBean.this); 577*cdf0e10cSrcweir add( xFrameWindow.getAWTComponent() ); 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir // create the document frame from UNO window. 581*cdf0e10cSrcweir if ( aFrame == null ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir // create the frame 584*cdf0e10cSrcweir com.sun.star.awt.XWindow xWindow = 585*cdf0e10cSrcweir (com.sun.star.awt.XWindow) UnoRuntime.queryInterface( 586*cdf0e10cSrcweir com.sun.star.awt.XWindow.class, xFrameWindow.getUNOWindowPeer()); 587*cdf0e10cSrcweir Object xFrame = xServiceFactory.createInstance( "com.sun.star.frame.Frame"); 588*cdf0e10cSrcweir aFrame = new Frame( (com.sun.star.frame.XFrame)UnoRuntime.queryInterface( 589*cdf0e10cSrcweir com.sun.star.frame.XFrame.class, xFrame ) ); 590*cdf0e10cSrcweir aFrame.initialize( xWindow ); 591*cdf0e10cSrcweir aFrame.setName( aFrame.toString() ); 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir // register the frame at the desktop 594*cdf0e10cSrcweir com.sun.star.frame.XFrames xFrames = 595*cdf0e10cSrcweir ( (com.sun.star.frame.XFramesSupplier)UnoRuntime.queryInterface( 596*cdf0e10cSrcweir com.sun.star.frame.XFramesSupplier.class, getOOoDesktop() ) ).getFrames(); 597*cdf0e10cSrcweir xFrames.append( aFrame ); 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir // Initializes the slot command execution environment. 601*cdf0e10cSrcweir xURLTransformer = (com.sun.star.util.XURLTransformer) UnoRuntime.queryInterface( 602*cdf0e10cSrcweir com.sun.star.util.XURLTransformer.class, 603*cdf0e10cSrcweir xServiceFactory.createInstance( "com.sun.star.util.URLTransformer") ); 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir try 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir xDispatcher = UnoRuntime.queryInterface(com.sun.star.frame.XDispatchProvider.class, aFrame); 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir catch (Exception e) 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir /*ignore!*/ 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir // get XComponentLoader from frame 615*cdf0e10cSrcweir com.sun.star.frame.XComponentLoader xLoader = (com.sun.star.frame.XComponentLoader) 616*cdf0e10cSrcweir UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader.class, aFrame ); 617*cdf0e10cSrcweir if ( xLoader == null ) 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir throw new java.lang.RuntimeException( 620*cdf0e10cSrcweir "com.sun.star.frame.Frame(" + aFrame + 621*cdf0e10cSrcweir ") without com.sun.star.frame.XComponentLoader" ); 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir // Avoid Dialog 'Document changed' while reloading 625*cdf0e10cSrcweir if ( aDocument != null ) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir try { 628*cdf0e10cSrcweir aDocument.setModified(false); 629*cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException ep) { 630*cdf0e10cSrcweir //it dosn't make sense to throw the exception here. The interface does not 631*cdf0e10cSrcweir //offer a way to add/remove respective listeners. 632*cdf0e10cSrcweir } catch (com.sun.star.lang.DisposedException ed) { 633*cdf0e10cSrcweir // can be disposed if user closed document via UI 634*cdf0e10cSrcweir } 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir com.sun.star.frame.XController xOldController = null; 637*cdf0e10cSrcweir if ( aFrame != null ) 638*cdf0e10cSrcweir xOldController = aFrame.getController(); 639*cdf0e10cSrcweir 640*cdf0e10cSrcweir try 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir if ( aFrame != null && xOldController != null ) 644*cdf0e10cSrcweir if (xOldController.suspend(true) == false) 645*cdf0e10cSrcweir throw new com.sun.star.util.CloseVetoException( 646*cdf0e10cSrcweir "Dokument is still being used and cannot be closed.", this); 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir } 649*cdf0e10cSrcweir catch (java.lang.IllegalStateException exp) 650*cdf0e10cSrcweir {} 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir // load the document. 654*cdf0e10cSrcweir com.sun.star.beans.PropertyValue aArgs[] = 655*cdf0e10cSrcweir addArgument( aArguments, new com.sun.star.beans.PropertyValue( 656*cdf0e10cSrcweir "MacroExecutionMode", -1, 657*cdf0e10cSrcweir new Short( com.sun.star.document.MacroExecMode.USE_CONFIG ), 658*cdf0e10cSrcweir com.sun.star.beans.PropertyState.DIRECT_VALUE ) ); 659*cdf0e10cSrcweir //String fn = aFRame.getName(); 660*cdf0e10cSrcweir 661*cdf0e10cSrcweir com.sun.star.lang.XComponent xComponent = xLoader.loadComponentFromURL( 662*cdf0e10cSrcweir aURL, /*aFrame.getName()*/"_self", 0, aArgs ); 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir // nothing loaded? 665*cdf0e10cSrcweir if ( xComponent == null && aDocument != null ) 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir // reactivate old document 668*cdf0e10cSrcweir if ( aFrame != null && aFrame.getController() != null ) 669*cdf0e10cSrcweir aFrame.getController().suspend(false); 670*cdf0e10cSrcweir aDocument.setModified(true); 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir // throw exception 673*cdf0e10cSrcweir throw new java.io.IOException( 674*cdf0e10cSrcweir "Can not load a document: \"" + aURL + "\""); 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir // mDocumentURL = aURL; TBD: still needed? 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir // Get document's XModifiable interface if any. 679*cdf0e10cSrcweir aDocument = new OfficeDocument( 680*cdf0e10cSrcweir (com.sun.star.frame.XModel) UnoRuntime.queryInterface( 681*cdf0e10cSrcweir com.sun.star.frame.XModel.class, xComponent ) ); 682*cdf0e10cSrcweir bLoaded = true; 683*cdf0e10cSrcweir } 684*cdf0e10cSrcweir catch ( NoConnectionException aExc ) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir // stop, clear and retry 687*cdf0e10cSrcweir stopOOoConnection(); 688*cdf0e10cSrcweir } 689*cdf0e10cSrcweir catch ( com.sun.star.lang.DisposedException aExc ) 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir // stop, clear and retry 692*cdf0e10cSrcweir stopOOoConnection(); 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir catch ( com.sun.star.uno.Exception aExc ) 695*cdf0e10cSrcweir { 696*cdf0e10cSrcweir // TDB: handling failure in createInstance 697*cdf0e10cSrcweir aExc.printStackTrace(); 698*cdf0e10cSrcweir throw new java.io.IOException(); 699*cdf0e10cSrcweir } 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir aCallWatchThread.cancel(); 702*cdf0e10cSrcweir if ( xServiceFactory == null ) 703*cdf0e10cSrcweir throw new NoConnectionException(); 704*cdf0e10cSrcweir } 705*cdf0e10cSrcweir if ( iConnection == null ) 706*cdf0e10cSrcweir { 707*cdf0e10cSrcweir throw new NoConnectionException(); 708*cdf0e10cSrcweir } 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir applyToolVisibilities(); 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir throw new NoConnectionException(); 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir /** Loads a document from a Java stream. 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir See loadFromURL() for further information. 721*cdf0e10cSrcweir */ 722*cdf0e10cSrcweir public void loadFromStream( 723*cdf0e10cSrcweir final java.io.InputStream iInStream, 724*cdf0e10cSrcweir final com.sun.star.beans.PropertyValue aArguments[] ) 725*cdf0e10cSrcweir throws 726*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 727*cdf0e10cSrcweir NoConnectionException, 728*cdf0e10cSrcweir java.io.IOException, 729*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, 730*cdf0e10cSrcweir com.sun.star.util.CloseVetoException 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir // wrap Java stream into UNO stream 733*cdf0e10cSrcweir /* 734*cdf0e10cSrcweir com.sun.star.io.XInputStream xStream = 735*cdf0e10cSrcweir new com.sun.star.lib.uno.adapter.InputStreamToXInputStreamAdapter( 736*cdf0e10cSrcweir iInStream ); 737*cdf0e10cSrcweir */ 738*cdf0e10cSrcweir // copy stream.... 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir int s = 4096; 741*cdf0e10cSrcweir int r=0 ,n = 0; 742*cdf0e10cSrcweir byte[] buffer = new byte[s]; 743*cdf0e10cSrcweir byte[] newBuffer = null; 744*cdf0e10cSrcweir while ((r = iInStream.read(buffer, n, buffer.length-n))>0) { 745*cdf0e10cSrcweir n += r; 746*cdf0e10cSrcweir if (iInStream.available() > buffer.length - n) { 747*cdf0e10cSrcweir newBuffer = new byte[buffer.length*2]; 748*cdf0e10cSrcweir System.arraycopy(buffer, 0, newBuffer, 0, n); 749*cdf0e10cSrcweir buffer = newBuffer; 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir if (buffer.length != n) { 753*cdf0e10cSrcweir newBuffer = new byte[n]; 754*cdf0e10cSrcweir System.arraycopy(buffer, 0, newBuffer, 0, n); 755*cdf0e10cSrcweir buffer = newBuffer; 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir com.sun.star.io.XInputStream xStream = 758*cdf0e10cSrcweir new com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter(buffer); 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir // add stream to arguments 761*cdf0e10cSrcweir com.sun.star.beans.PropertyValue[] aExtendedArguments = 762*cdf0e10cSrcweir addArgument( aArguments, new com.sun.star.beans.PropertyValue( 763*cdf0e10cSrcweir "InputStream", -1, xStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) ); 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir // call normal load method 766*cdf0e10cSrcweir loadFromURL( "private:stream", aExtendedArguments ); 767*cdf0e10cSrcweir } 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir /** Loads a document from a byte array. 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir See loadFromURL() for further information. 772*cdf0e10cSrcweir */ 773*cdf0e10cSrcweir public void loadFromByteArray( 774*cdf0e10cSrcweir final byte aInBuffer[], 775*cdf0e10cSrcweir final com.sun.star.beans.PropertyValue aArguments[] ) 776*cdf0e10cSrcweir throws 777*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 778*cdf0e10cSrcweir NoConnectionException, 779*cdf0e10cSrcweir java.io.IOException, 780*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, 781*cdf0e10cSrcweir com.sun.star.util.CloseVetoException 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir // wrap byte arrray into UNO stream 784*cdf0e10cSrcweir com.sun.star.io.XInputStream xStream = 785*cdf0e10cSrcweir new com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter( 786*cdf0e10cSrcweir aInBuffer ); 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir // add stream to arguments 789*cdf0e10cSrcweir com.sun.star.beans.PropertyValue[] aExtendedArguments = 790*cdf0e10cSrcweir addArgument( aArguments, new com.sun.star.beans.PropertyValue( 791*cdf0e10cSrcweir "InputStream", -1, xStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) ); 792*cdf0e10cSrcweir 793*cdf0e10cSrcweir // call normal load method 794*cdf0e10cSrcweir loadFromURL( "private:stream", aExtendedArguments ); 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir 797*cdf0e10cSrcweir /** Stores a document to the given URL. 798*cdf0e10cSrcweir <p> 799*cdf0e10cSrcweir Due due a bug (50651) calling this method may cause the office to crash, 800*cdf0e10cSrcweir when at the same time the office writes a backup of the document. This bug 801*cdf0e10cSrcweir also affects {@link #storeToByteArray storeToByteArray} and 802*cdf0e10cSrcweir {@link #storeToStream storeToStream}. The workaround 803*cdf0e10cSrcweir is to start the office with the option -norestore, which disables the automatic 804*cdf0e10cSrcweir backup and recovery mechanism. OOoBean offers currently no supported way of providing 805*cdf0e10cSrcweir startup options for OOo. But it is possible to set a Java property when starting 806*cdf0e10cSrcweir Java, which is examined by OOoBean: 807*cdf0e10cSrcweir <pre> 808*cdf0e10cSrcweir java -Dcom.sun.star.officebean.Options=-norestore ... 809*cdf0e10cSrcweir </pre> 810*cdf0e10cSrcweir It is planned to offer a way of specifying startup options in a future version. 811*cdf0e10cSrcweir The property can be used until then. When using this property only one option 812*cdf0e10cSrcweir can be provided. 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir @throws IllegalArgumentException 815*cdf0e10cSrcweir if either of the arguments is out of the specified range. 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir @throws java.io.IOException 818*cdf0e10cSrcweir if an IO error occurs reading the ressource specified by the URL. 819*cdf0e10cSrcweir 820*cdf0e10cSrcweir @throws com.sun.star.lang.NoConnectionException 821*cdf0e10cSrcweir if no connection is established. 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir @throws NoDocumentException 824*cdf0e10cSrcweir if no document is loaded 825*cdf0e10cSrcweir */ 826*cdf0e10cSrcweir public void storeToURL( 827*cdf0e10cSrcweir final String aURL, 828*cdf0e10cSrcweir final com.sun.star.beans.PropertyValue aArguments[] ) 829*cdf0e10cSrcweir throws 830*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 831*cdf0e10cSrcweir NoConnectionException, 832*cdf0e10cSrcweir java.io.IOException, 833*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException, 834*cdf0e10cSrcweir NoDocumentException 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir // no document available? 837*cdf0e10cSrcweir if ( aDocument == null ) 838*cdf0e10cSrcweir throw new NoDocumentException(); 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir try 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir // start runtime timeout 843*cdf0e10cSrcweir CallWatchThread aCallWatchThread = 844*cdf0e10cSrcweir new CallWatchThread( nOOoCallTimeOut, "storeToURL" ); 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir // store the document 847*cdf0e10cSrcweir try { aDocument.storeToURL( aURL, aArguments ); } 848*cdf0e10cSrcweir catch ( com.sun.star.io.IOException aExc ) 849*cdf0e10cSrcweir { throw new java.io.IOException(); } 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir // end runtime timeout 852*cdf0e10cSrcweir aCallWatchThread.cancel(); 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 855*cdf0e10cSrcweir { throw new NoConnectionException(); } 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir /** Stores a document to a stream. 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir See {@link #storeToURL storeToURL} for further information. 861*cdf0e10cSrcweir @see #storeToURL storeToURL 862*cdf0e10cSrcweir */ 863*cdf0e10cSrcweir public java.io.OutputStream storeToStream( 864*cdf0e10cSrcweir java.io.OutputStream aOutStream, 865*cdf0e10cSrcweir final com.sun.star.beans.PropertyValue aArguments[] ) 866*cdf0e10cSrcweir throws 867*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 868*cdf0e10cSrcweir NoConnectionException, 869*cdf0e10cSrcweir NoDocumentException, 870*cdf0e10cSrcweir java.io.IOException, 871*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir { 874*cdf0e10cSrcweir // wrap Java stream into UNO stream 875*cdf0e10cSrcweir com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter aStream = 876*cdf0e10cSrcweir new com.sun.star.lib.uno.adapter.OutputStreamToXOutputStreamAdapter( 877*cdf0e10cSrcweir aOutStream ); 878*cdf0e10cSrcweir 879*cdf0e10cSrcweir // add stream to arguments 880*cdf0e10cSrcweir com.sun.star.beans.PropertyValue[] aExtendedArguments = 881*cdf0e10cSrcweir addArgument( aArguments, new com.sun.star.beans.PropertyValue( 882*cdf0e10cSrcweir "OutputStream", -1, aStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) ); 883*cdf0e10cSrcweir 884*cdf0e10cSrcweir // call normal store method 885*cdf0e10cSrcweir storeToURL( "private:stream", aExtendedArguments ); 886*cdf0e10cSrcweir 887*cdf0e10cSrcweir // get byte array from document stream 888*cdf0e10cSrcweir try { aStream.closeOutput(); } 889*cdf0e10cSrcweir catch ( com.sun.star.io.NotConnectedException aExc ) 890*cdf0e10cSrcweir { /* TDB */ } 891*cdf0e10cSrcweir catch ( com.sun.star.io.BufferSizeExceededException aExc ) 892*cdf0e10cSrcweir { /* TDB */ } 893*cdf0e10cSrcweir catch ( com.sun.star.io.IOException aExc ) 894*cdf0e10cSrcweir { throw new java.io.IOException(); } 895*cdf0e10cSrcweir return aOutStream; 896*cdf0e10cSrcweir } 897*cdf0e10cSrcweir 898*cdf0e10cSrcweir /** Stores a document to a byte array. 899*cdf0e10cSrcweir 900*cdf0e10cSrcweir See {@link #storeToURL storeToURL} for further information. 901*cdf0e10cSrcweir @see #storeToURL storeToURL 902*cdf0e10cSrcweir */ 903*cdf0e10cSrcweir public byte[] storeToByteArray( 904*cdf0e10cSrcweir byte aOutBuffer[], 905*cdf0e10cSrcweir final com.sun.star.beans.PropertyValue aArguments[] ) 906*cdf0e10cSrcweir throws 907*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 908*cdf0e10cSrcweir NoConnectionException, 909*cdf0e10cSrcweir NoDocumentException, 910*cdf0e10cSrcweir java.io.IOException, 911*cdf0e10cSrcweir com.sun.star.lang.IllegalArgumentException 912*cdf0e10cSrcweir { 913*cdf0e10cSrcweir // wrap byte arrray into UNO stream 914*cdf0e10cSrcweir com.sun.star.lib.uno.adapter.XOutputStreamToByteArrayAdapter aStream = 915*cdf0e10cSrcweir new com.sun.star.lib.uno.adapter.XOutputStreamToByteArrayAdapter( 916*cdf0e10cSrcweir aOutBuffer ); 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir // add stream to arguments 919*cdf0e10cSrcweir com.sun.star.beans.PropertyValue[] aExtendedArguments = 920*cdf0e10cSrcweir addArgument( aArguments, new com.sun.star.beans.PropertyValue( 921*cdf0e10cSrcweir "OutputStream", -1, aStream, com.sun.star.beans.PropertyState.DIRECT_VALUE ) ); 922*cdf0e10cSrcweir 923*cdf0e10cSrcweir // call normal store method 924*cdf0e10cSrcweir storeToURL( "private:stream", aExtendedArguments ); 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir // get byte array from document stream 927*cdf0e10cSrcweir try { aStream.closeOutput(); } 928*cdf0e10cSrcweir catch ( com.sun.star.io.NotConnectedException aExc ) 929*cdf0e10cSrcweir { /* TDB */ } 930*cdf0e10cSrcweir catch ( com.sun.star.io.BufferSizeExceededException aExc ) 931*cdf0e10cSrcweir { /* TDB */ } 932*cdf0e10cSrcweir catch ( com.sun.star.io.IOException aExc ) 933*cdf0e10cSrcweir { throw new java.io.IOException(); } 934*cdf0e10cSrcweir return aStream.getBuffer(); 935*cdf0e10cSrcweir } 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir // @requirement FUNC.BEAN.PROG/0.5 938*cdf0e10cSrcweir // @requirement API.SIM.SEAP/0.2 939*cdf0e10cSrcweir /** returns the <type scope="com::sun::star::frame">Frame</a> 940*cdf0e10cSrcweir of the bean. 941*cdf0e10cSrcweir 942*cdf0e10cSrcweir @returns 943*cdf0e10cSrcweir a Java class which implements all interfaces which the service 944*cdf0e10cSrcweir <type scope="com::sun::star::frame">Frame</a> implements. 945*cdf0e10cSrcweir Thus, methods can be called directly without queryInterface. 946*cdf0e10cSrcweir This feature might be implemented by UNO or explicitely coded. 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir @throws NoConnectionException 949*cdf0e10cSrcweir if the connection is not established. 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir @throws NotDocumentException 952*cdf0e10cSrcweir if no document is loaded an thus no frame is available. 953*cdf0e10cSrcweir */ 954*cdf0e10cSrcweir public Frame getFrame() 955*cdf0e10cSrcweir 956*cdf0e10cSrcweir throws 957*cdf0e10cSrcweir NoConnectionException // @requirement FUNC.CON.LOST/0.2 958*cdf0e10cSrcweir { 959*cdf0e10cSrcweir if ( iConnection == null ) 960*cdf0e10cSrcweir throw new NoConnectionException(); 961*cdf0e10cSrcweir return aFrame; 962*cdf0e10cSrcweir } 963*cdf0e10cSrcweir 964*cdf0e10cSrcweir // @requirement FUNC.BEAN.PROG/0.5 965*cdf0e10cSrcweir // @requirement API.SIM.SEAP/0.2 966*cdf0e10cSrcweir /** returns the <type scope="com::sun::star::frame::Controller"> of the bean. 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir @returns 969*cdf0e10cSrcweir a Java class which implements all interfaces which the service 970*cdf0e10cSrcweir <type scope="com::sun::star::frame">Controller</a> implements. 971*cdf0e10cSrcweir Thus, methods can be called directly without queryInterface. 972*cdf0e10cSrcweir This feature might be implemented by UNO or explicitely coded. 973*cdf0e10cSrcweir 974*cdf0e10cSrcweir @throws NoConnectionException 975*cdf0e10cSrcweir if the connection is not established. 976*cdf0e10cSrcweir */ 977*cdf0e10cSrcweir public Controller getController() 978*cdf0e10cSrcweir 979*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 980*cdf0e10cSrcweir throws NoConnectionException 981*cdf0e10cSrcweir { 982*cdf0e10cSrcweir if ( iConnection == null ) 983*cdf0e10cSrcweir throw new NoConnectionException(); 984*cdf0e10cSrcweir if ( aController == null ) 985*cdf0e10cSrcweir aController = new Controller( aFrame.getController() ); 986*cdf0e10cSrcweir return aController; 987*cdf0e10cSrcweir } 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir // @requirement FUNC.BEAN.PROG/0.5 990*cdf0e10cSrcweir // @requirement FUNC.BEAN.STOR/0.4 991*cdf0e10cSrcweir // @requirement FUNC.BEAN.PRNT/0.4 992*cdf0e10cSrcweir // @requirement API.SIM.SEAP/0.2 993*cdf0e10cSrcweir /** returns the <type scope="com::sun::star::document::OfficeDocument"> 994*cdf0e10cSrcweir of the bean. 995*cdf0e10cSrcweir 996*cdf0e10cSrcweir @returns 997*cdf0e10cSrcweir a Java class which implements all interfaces which the service 998*cdf0e10cSrcweir <type scope="com::sun::star::document">OfficeDocument</a> 999*cdf0e10cSrcweir implements. 1000*cdf0e10cSrcweir Thus, methods can be called directly without queryInterface. 1001*cdf0e10cSrcweir This feature might be implemented by UNO or explicitely coded. 1002*cdf0e10cSrcweir 1003*cdf0e10cSrcweir @throws NoConnectionException 1004*cdf0e10cSrcweir if the connection is not established. 1005*cdf0e10cSrcweir */ 1006*cdf0e10cSrcweir public OfficeDocument getDocument() 1007*cdf0e10cSrcweir 1008*cdf0e10cSrcweir // @requirement FUNC.CON.LOST/0.2 1009*cdf0e10cSrcweir throws NoConnectionException 1010*cdf0e10cSrcweir { 1011*cdf0e10cSrcweir if ( iConnection == null ) 1012*cdf0e10cSrcweir throw new NoConnectionException(); 1013*cdf0e10cSrcweir return aDocument; 1014*cdf0e10cSrcweir } 1015*cdf0e10cSrcweir 1016*cdf0e10cSrcweir /** Sets visibility of all tool bars known by this OOoBean version. 1017*cdf0e10cSrcweir 1018*cdf0e10cSrcweir Initially all tool bars are visible. By hiding all tool bars 1019*cdf0e10cSrcweir utilizing this method, it is possible to turn just a subset of 1020*cdf0e10cSrcweir tool bars on afterwards, no matter whether all available tool 1021*cdf0e10cSrcweir bars are known or not. 1022*cdf0e10cSrcweir <p> 1023*cdf0e10cSrcweir If an older OOoBean instance is used with a newer OOo instance, 1024*cdf0e10cSrcweir some tool bars might not be affected by this method. 1025*cdf0e10cSrcweir <p> 1026*cdf0e10cSrcweir If no connection is established or no document is loaded, 1027*cdf0e10cSrcweir the setting is memorized until a document is loaded. Same 1028*cdf0e10cSrcweir is valid when the connection dies within this function call. 1029*cdf0e10cSrcweir 1030*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1031*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. For example: 1032*cdf0e10cSrcweir <pre> 1033*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xPropSet = 1034*cdf0e10cSrcweir (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface( 1035*cdf0e10cSrcweir com.sun.star.beans.XPropertySet.class, aFrame ); 1036*cdf0e10cSrcweir com.sun.star.frame.XLayoutManager xLayoutManager = 1037*cdf0e10cSrcweir (com.sun.star.frame.XLayoutManager) UnoRuntime.queryInterface( 1038*cdf0e10cSrcweir com.sun.star.frame.XLayoutManager.class, 1039*cdf0e10cSrcweir xPropSet.getPropertyValue( "LayoutManager" ) ); 1040*cdf0e10cSrcweir xLayoutManager.showElement("private:resource/menubar/menubar"); 1041*cdf0e10cSrcweir </pre> 1042*cdf0e10cSrcweir */ 1043*cdf0e10cSrcweir public void setAllBarsVisible( boolean bVisible ) 1044*cdf0e10cSrcweir { 1045*cdf0e10cSrcweir bIgnoreVisibility = true; 1046*cdf0e10cSrcweir setMenuBarVisible( bVisible ); 1047*cdf0e10cSrcweir setStandardBarVisible( bVisible ); 1048*cdf0e10cSrcweir setToolBarVisible( bVisible ); 1049*cdf0e10cSrcweir setStatusBarVisible( bVisible ); 1050*cdf0e10cSrcweir bIgnoreVisibility = false; 1051*cdf0e10cSrcweir } 1052*cdf0e10cSrcweir 1053*cdf0e10cSrcweir //-------------------------------------------------------------------------- 1054*cdf0e10cSrcweir /** Applies all tool visiblities to the real thing. 1055*cdf0e10cSrcweir 1056*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1057*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1058*cdf0e10cSrcweir {@link #setAllBarsVisible setAllBarsVisible}. 1059*cdf0e10cSrcweir */ 1060*cdf0e10cSrcweir protected void applyToolVisibilities() 1061*cdf0e10cSrcweir throws 1062*cdf0e10cSrcweir java.lang.InterruptedException 1063*cdf0e10cSrcweir { 1064*cdf0e10cSrcweir bIgnoreVisibility = true; 1065*cdf0e10cSrcweir setMenuBarVisible( bMenuBarVisible ); 1066*cdf0e10cSrcweir setStandardBarVisible( bStandardBarVisible ); 1067*cdf0e10cSrcweir setToolBarVisible( bToolBarVisible ); 1068*cdf0e10cSrcweir setStatusBarVisible( bStatusBarVisible ); 1069*cdf0e10cSrcweir bIgnoreVisibility = false; 1070*cdf0e10cSrcweir } 1071*cdf0e10cSrcweir 1072*cdf0e10cSrcweir /** Helper method to set tool bar visibilty. 1073*cdf0e10cSrcweir 1074*cdf0e10cSrcweir @param bnewValue 1075*cdf0e10cSrcweir If false, the tool bar is disabled, 1076*cdf0e10cSrcweir If true, the tool bar is visible. 1077*cdf0e10cSrcweir 1078*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1079*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1080*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1081*cdf0e10cSrcweir */ 1082*cdf0e10cSrcweir protected boolean setToolVisible( String aProperty, String aResourceURL, 1083*cdf0e10cSrcweir boolean bOldValue, boolean bNewValue ) 1084*cdf0e10cSrcweir 1085*cdf0e10cSrcweir throws 1086*cdf0e10cSrcweir java.lang.InterruptedException 1087*cdf0e10cSrcweir { 1088*cdf0e10cSrcweir // start runtime timeout 1089*cdf0e10cSrcweir CallWatchThread aCallWatchThread = 1090*cdf0e10cSrcweir new CallWatchThread( nOOoCallTimeOut, "setToolVisible" ); 1091*cdf0e10cSrcweir 1092*cdf0e10cSrcweir // Does a frame exist? 1093*cdf0e10cSrcweir if ( aFrame != null ) 1094*cdf0e10cSrcweir { 1095*cdf0e10cSrcweir if ( bIgnoreVisibility || bOldValue != bNewValue ) 1096*cdf0e10cSrcweir { 1097*cdf0e10cSrcweir try 1098*cdf0e10cSrcweir { 1099*cdf0e10cSrcweir com.sun.star.beans.XPropertySet xPropSet = 1100*cdf0e10cSrcweir (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface( 1101*cdf0e10cSrcweir com.sun.star.beans.XPropertySet.class, aFrame ); 1102*cdf0e10cSrcweir com.sun.star.frame.XLayoutManager xLayoutManager = 1103*cdf0e10cSrcweir (com.sun.star.frame.XLayoutManager) UnoRuntime.queryInterface( 1104*cdf0e10cSrcweir com.sun.star.frame.XLayoutManager.class, 1105*cdf0e10cSrcweir xPropSet.getPropertyValue( "LayoutManager" ) ); 1106*cdf0e10cSrcweir if ( bNewValue ) 1107*cdf0e10cSrcweir xLayoutManager.showElement( aResourceURL ); 1108*cdf0e10cSrcweir else 1109*cdf0e10cSrcweir xLayoutManager.hideElement( aResourceURL ); 1110*cdf0e10cSrcweir } 1111*cdf0e10cSrcweir catch ( com.sun.star.beans.UnknownPropertyException aExc ) 1112*cdf0e10cSrcweir { 1113*cdf0e10cSrcweir throw new RuntimeException( "not layout manager found" ); 1114*cdf0e10cSrcweir } 1115*cdf0e10cSrcweir catch ( com.sun.star.lang.WrappedTargetException aExc ) 1116*cdf0e10cSrcweir { 1117*cdf0e10cSrcweir throw new RuntimeException( "not layout manager found" ); 1118*cdf0e10cSrcweir } 1119*cdf0e10cSrcweir 1120*cdf0e10cSrcweir // notify change 1121*cdf0e10cSrcweir firePropertyChange( aProperty, new Boolean(bOldValue), new Boolean(bNewValue) ); 1122*cdf0e10cSrcweir } 1123*cdf0e10cSrcweir } 1124*cdf0e10cSrcweir 1125*cdf0e10cSrcweir // end runtime timeout 1126*cdf0e10cSrcweir aCallWatchThread.cancel(); 1127*cdf0e10cSrcweir 1128*cdf0e10cSrcweir // the new value will be stored by caller 1129*cdf0e10cSrcweir return bNewValue; 1130*cdf0e10cSrcweir } 1131*cdf0e10cSrcweir 1132*cdf0e10cSrcweir /** Sets the visibility of the menu bar. 1133*cdf0e10cSrcweir 1134*cdf0e10cSrcweir Initially the menu bar is visible. 1135*cdf0e10cSrcweir <p> 1136*cdf0e10cSrcweir If not connected or no document loaded, the value is stored 1137*cdf0e10cSrcweir and automatically applied to the document after it is loaded. 1138*cdf0e10cSrcweir Same is valid when the connection dies within this function call. 1139*cdf0e10cSrcweir 1140*cdf0e10cSrcweir @param bVisible 1141*cdf0e10cSrcweir If false, the menu bar is disabled, 1142*cdf0e10cSrcweir If true, the menu bar is visible. 1143*cdf0e10cSrcweir 1144*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1145*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1146*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1147*cdf0e10cSrcweir */ 1148*cdf0e10cSrcweir public void setMenuBarVisible(boolean bVisible) 1149*cdf0e10cSrcweir { 1150*cdf0e10cSrcweir try 1151*cdf0e10cSrcweir { 1152*cdf0e10cSrcweir bMenuBarVisible = setToolVisible( "MenuBarVisible", 1153*cdf0e10cSrcweir "private:resource/menubar/menubar", bMenuBarVisible, bVisible ); 1154*cdf0e10cSrcweir } 1155*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 1156*cdf0e10cSrcweir { 1157*cdf0e10cSrcweir bMenuBarVisible = bVisible; 1158*cdf0e10cSrcweir } 1159*cdf0e10cSrcweir } 1160*cdf0e10cSrcweir 1161*cdf0e10cSrcweir /** Returns the visibility of the menu bar. 1162*cdf0e10cSrcweir 1163*cdf0e10cSrcweir This method works independently from a connetion or loaded document. 1164*cdf0e10cSrcweir If no connection is established or no document is loaded, 1165*cdf0e10cSrcweir this method just returns a memorized status. 1166*cdf0e10cSrcweir 1167*cdf0e10cSrcweir @return 1168*cdf0e10cSrcweir True if the menu bar is visible, 1169*cdf0e10cSrcweir false if the menu bar is hidden. 1170*cdf0e10cSrcweir 1171*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1172*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1173*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1174*cdf0e10cSrcweir */ 1175*cdf0e10cSrcweir public boolean isMenuBarVisible() 1176*cdf0e10cSrcweir { 1177*cdf0e10cSrcweir return bMenuBarVisible; 1178*cdf0e10cSrcweir } 1179*cdf0e10cSrcweir 1180*cdf0e10cSrcweir /** Sets the main function bar visibilty. 1181*cdf0e10cSrcweir 1182*cdf0e10cSrcweir Initially the standard bar is visible. 1183*cdf0e10cSrcweir 1184*cdf0e10cSrcweir If not connected or no document loaded, the value is stored 1185*cdf0e10cSrcweir and automatically applied to the document after it is loaded. 1186*cdf0e10cSrcweir Same is valid when the connection dies within this function call. 1187*cdf0e10cSrcweir 1188*cdf0e10cSrcweir @param bVisible 1189*cdf0e10cSrcweir If false, the main function bar is disabled, 1190*cdf0e10cSrcweir If true, the main function bar is visible. 1191*cdf0e10cSrcweir 1192*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1193*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1194*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1195*cdf0e10cSrcweir */ 1196*cdf0e10cSrcweir public void setStandardBarVisible(boolean bVisible) 1197*cdf0e10cSrcweir { 1198*cdf0e10cSrcweir try 1199*cdf0e10cSrcweir { 1200*cdf0e10cSrcweir bStandardBarVisible = setToolVisible( "StandardBarVisible", 1201*cdf0e10cSrcweir "private:resource/toolbar/standardbar", bStandardBarVisible, bVisible ); 1202*cdf0e10cSrcweir } 1203*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 1204*cdf0e10cSrcweir { 1205*cdf0e10cSrcweir bMenuBarVisible = bVisible; 1206*cdf0e10cSrcweir } 1207*cdf0e10cSrcweir } 1208*cdf0e10cSrcweir 1209*cdf0e10cSrcweir /** Returns the visibility of the main function bar. 1210*cdf0e10cSrcweir 1211*cdf0e10cSrcweir This method works independently from a connetion or loaded document. 1212*cdf0e10cSrcweir If no connection is established or no document is loaded, 1213*cdf0e10cSrcweir this method just returns a memorized status. 1214*cdf0e10cSrcweir 1215*cdf0e10cSrcweir @return 1216*cdf0e10cSrcweir True if the main function bar is visible, 1217*cdf0e10cSrcweir false if the main function bar is hidden. 1218*cdf0e10cSrcweir 1219*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1220*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1221*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1222*cdf0e10cSrcweir */ 1223*cdf0e10cSrcweir public boolean isStandardBarVisible() 1224*cdf0e10cSrcweir { 1225*cdf0e10cSrcweir return bStandardBarVisible; 1226*cdf0e10cSrcweir } 1227*cdf0e10cSrcweir 1228*cdf0e10cSrcweir /** Sets the tool function bar visibilty. 1229*cdf0e10cSrcweir 1230*cdf0e10cSrcweir Initially the tool bar is visible. 1231*cdf0e10cSrcweir 1232*cdf0e10cSrcweir If not connected or no document loaded, the value is stored 1233*cdf0e10cSrcweir and automatically applied to the document after it is loaded. 1234*cdf0e10cSrcweir Same is valid when the connection dies within this function call. 1235*cdf0e10cSrcweir 1236*cdf0e10cSrcweir @param bVisible 1237*cdf0e10cSrcweir If false, the tool function bar is disabled, 1238*cdf0e10cSrcweir If true, the tool function bar is visible. 1239*cdf0e10cSrcweir 1240*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1241*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1242*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1243*cdf0e10cSrcweir */ 1244*cdf0e10cSrcweir public void setToolBarVisible(boolean bVisible) 1245*cdf0e10cSrcweir { 1246*cdf0e10cSrcweir try 1247*cdf0e10cSrcweir { 1248*cdf0e10cSrcweir bToolBarVisible = setToolVisible( "ToolBarVisible", 1249*cdf0e10cSrcweir "private:resource/toolbar/toolbar", bToolBarVisible, bVisible ); 1250*cdf0e10cSrcweir } 1251*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 1252*cdf0e10cSrcweir { 1253*cdf0e10cSrcweir bMenuBarVisible = bVisible; 1254*cdf0e10cSrcweir } 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir 1257*cdf0e10cSrcweir /** Returns the visibility of the tool function bar. 1258*cdf0e10cSrcweir 1259*cdf0e10cSrcweir This method works independently from a connetion or loaded document. 1260*cdf0e10cSrcweir If no connection is established or no document is loaded, 1261*cdf0e10cSrcweir this method just returns a memorized status. 1262*cdf0e10cSrcweir 1263*cdf0e10cSrcweir @return 1264*cdf0e10cSrcweir True if the tool function bar is visible, 1265*cdf0e10cSrcweir false if the tool function bar is hidden. 1266*cdf0e10cSrcweir 1267*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1268*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1269*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1270*cdf0e10cSrcweir */ 1271*cdf0e10cSrcweir public boolean isToolBarVisible() 1272*cdf0e10cSrcweir { 1273*cdf0e10cSrcweir return bToolBarVisible; 1274*cdf0e10cSrcweir } 1275*cdf0e10cSrcweir 1276*cdf0e10cSrcweir /** Sets the status function bar visibilty. 1277*cdf0e10cSrcweir 1278*cdf0e10cSrcweir Initially the status bar is visible. 1279*cdf0e10cSrcweir 1280*cdf0e10cSrcweir If not connected or no document loaded, the value is stored 1281*cdf0e10cSrcweir and automatically applied to the document after it is loaded. 1282*cdf0e10cSrcweir Same is valid when the connection dies within this function call. 1283*cdf0e10cSrcweir 1284*cdf0e10cSrcweir @param bVisible 1285*cdf0e10cSrcweir If false, the status function bar is disabled, 1286*cdf0e10cSrcweir If true, the status function bar is visible. 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1289*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1290*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1291*cdf0e10cSrcweir */ 1292*cdf0e10cSrcweir public void setStatusBarVisible(boolean bVisible) 1293*cdf0e10cSrcweir { 1294*cdf0e10cSrcweir try 1295*cdf0e10cSrcweir { 1296*cdf0e10cSrcweir bStatusBarVisible = setToolVisible( "StatusBarVisible", 1297*cdf0e10cSrcweir "private:resource/statusbar/statusbar", bStatusBarVisible, bVisible ); 1298*cdf0e10cSrcweir } 1299*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 1300*cdf0e10cSrcweir { 1301*cdf0e10cSrcweir bMenuBarVisible = bVisible; 1302*cdf0e10cSrcweir } 1303*cdf0e10cSrcweir } 1304*cdf0e10cSrcweir 1305*cdf0e10cSrcweir /** Returns the visibility of the status function bar. 1306*cdf0e10cSrcweir 1307*cdf0e10cSrcweir This method works independently from a connetion or loaded document. 1308*cdf0e10cSrcweir If no connection is established or no document is loaded, 1309*cdf0e10cSrcweir this method just returns a memorized status. 1310*cdf0e10cSrcweir 1311*cdf0e10cSrcweir @return 1312*cdf0e10cSrcweir True if the status function bar is visible, 1313*cdf0e10cSrcweir false if the status function bar is hidden. 1314*cdf0e10cSrcweir 1315*cdf0e10cSrcweir @deprecated Clients should use the service com.sun.star.frame.LayoutManager, 1316*cdf0e10cSrcweir which can be obtained from a frame, to control toolbars. See also 1317*cdf0e10cSrcweir {@link #setAllBarsVisible}. 1318*cdf0e10cSrcweir */ 1319*cdf0e10cSrcweir public boolean isStatusBarVisible() 1320*cdf0e10cSrcweir { 1321*cdf0e10cSrcweir return bStatusBarVisible; 1322*cdf0e10cSrcweir } 1323*cdf0e10cSrcweir 1324*cdf0e10cSrcweir //=========================================================================== 1325*cdf0e10cSrcweir // Helper Methods / Internal Methods 1326*cdf0e10cSrcweir //--------------------------------------------------------------------------- 1327*cdf0e10cSrcweir 1328*cdf0e10cSrcweir // general instance intializer 1329*cdf0e10cSrcweir { 1330*cdf0e10cSrcweir setLayout(new java.awt.BorderLayout()); 1331*cdf0e10cSrcweir } 1332*cdf0e10cSrcweir 1333*cdf0e10cSrcweir /** 1334*cdf0e10cSrcweir @deprecated 1335*cdf0e10cSrcweir */ 1336*cdf0e10cSrcweir public void paint( java.awt.Graphics aGraphics ) 1337*cdf0e10cSrcweir { 1338*cdf0e10cSrcweir } 1339*cdf0e10cSrcweir 1340*cdf0e10cSrcweir /** Adds a single argument to an array of arguments. 1341*cdf0e10cSrcweir 1342*cdf0e10cSrcweir If the argument by its name is already in aArguments 1343*cdf0e10cSrcweir it is exchanged and aArguments is returned. 1344*cdf0e10cSrcweir <p> 1345*cdf0e10cSrcweir If the argument by its name is not yet in aArguments, 1346*cdf0e10cSrcweir a new array is created, aArgument added and the new 1347*cdf0e10cSrcweir array returned. 1348*cdf0e10cSrcweir */ 1349*cdf0e10cSrcweir protected com.sun.star.beans.PropertyValue[] addArgument( 1350*cdf0e10cSrcweir com.sun.star.beans.PropertyValue aArguments[], 1351*cdf0e10cSrcweir final com.sun.star.beans.PropertyValue aArgument ) 1352*cdf0e10cSrcweir { 1353*cdf0e10cSrcweir // get number of current arguments 1354*cdf0e10cSrcweir int nNumArgs = 0; 1355*cdf0e10cSrcweir if ( aArguments != null ) 1356*cdf0e10cSrcweir nNumArgs = aArguments.length; 1357*cdf0e10cSrcweir 1358*cdf0e10cSrcweir // is new argument already set? 1359*cdf0e10cSrcweir for ( int n = 0; n < nNumArgs; ++n ) 1360*cdf0e10cSrcweir { 1361*cdf0e10cSrcweir if ( aArguments[n].Name == aArgument.Name ) 1362*cdf0e10cSrcweir { 1363*cdf0e10cSrcweir // substitute this argument 1364*cdf0e10cSrcweir aArguments[n] = aArgument; 1365*cdf0e10cSrcweir 1366*cdf0e10cSrcweir // return current array 1367*cdf0e10cSrcweir return aArguments; 1368*cdf0e10cSrcweir } 1369*cdf0e10cSrcweir } 1370*cdf0e10cSrcweir 1371*cdf0e10cSrcweir // create extended arguments 1372*cdf0e10cSrcweir com.sun.star.beans.PropertyValue[] aExtendedArguments = 1373*cdf0e10cSrcweir new com.sun.star.beans.PropertyValue[ nNumArgs + 1 ]; 1374*cdf0e10cSrcweir 1375*cdf0e10cSrcweir // copy current arguments 1376*cdf0e10cSrcweir for ( int n = 0; n < nNumArgs; ++n ) 1377*cdf0e10cSrcweir aExtendedArguments[n] = aArguments[n]; 1378*cdf0e10cSrcweir 1379*cdf0e10cSrcweir // add new argument 1380*cdf0e10cSrcweir aExtendedArguments[ nNumArgs ] = aArgument; 1381*cdf0e10cSrcweir 1382*cdf0e10cSrcweir // return new arguments 1383*cdf0e10cSrcweir return aExtendedArguments; 1384*cdf0e10cSrcweir } 1385*cdf0e10cSrcweir 1386*cdf0e10cSrcweir //=========================================================================== 1387*cdf0e10cSrcweir // Helper Classes 1388*cdf0e10cSrcweir //--------------------------------------------------------------------------- 1389*cdf0e10cSrcweir 1390*cdf0e10cSrcweir /** Helper class to listen on the connection to learn when it dies. 1391*cdf0e10cSrcweir 1392*cdf0e10cSrcweir @internal 1393*cdf0e10cSrcweir */ 1394*cdf0e10cSrcweir private class EventListener 1395*cdf0e10cSrcweir extends Thread 1396*cdf0e10cSrcweir implements 1397*cdf0e10cSrcweir com.sun.star.lang.XEventListener, 1398*cdf0e10cSrcweir com.sun.star.frame.XTerminateListener 1399*cdf0e10cSrcweir { 1400*cdf0e10cSrcweir String aTag; 1401*cdf0e10cSrcweir 1402*cdf0e10cSrcweir EventListener( String aTag ) 1403*cdf0e10cSrcweir throws NoConnectionException 1404*cdf0e10cSrcweir { 1405*cdf0e10cSrcweir // init members 1406*cdf0e10cSrcweir this.aTag = aTag; 1407*cdf0e10cSrcweir 1408*cdf0e10cSrcweir // listen on a dying connection 1409*cdf0e10cSrcweir iConnection.addEventListener( this ); 1410*cdf0e10cSrcweir 1411*cdf0e10cSrcweir // listen on a terminating OOo 1412*cdf0e10cSrcweir getOOoDesktop().addTerminateListener( this ); 1413*cdf0e10cSrcweir 1414*cdf0e10cSrcweir // start this thread as a daemon 1415*cdf0e10cSrcweir setDaemon( true ); 1416*cdf0e10cSrcweir start(); 1417*cdf0e10cSrcweir } 1418*cdf0e10cSrcweir 1419*cdf0e10cSrcweir public void end() 1420*cdf0e10cSrcweir { 1421*cdf0e10cSrcweir // do not listen on a dying connection anymore 1422*cdf0e10cSrcweir try { 1423*cdf0e10cSrcweir iConnection.removeEventListener( this ); 1424*cdf0e10cSrcweir } 1425*cdf0e10cSrcweir catch ( Throwable aExc ) {}; 1426*cdf0e10cSrcweir 1427*cdf0e10cSrcweir // do not listen on a terminating OOo anymore 1428*cdf0e10cSrcweir try { 1429*cdf0e10cSrcweir getOOoDesktop().removeTerminateListener( this ); 1430*cdf0e10cSrcweir } 1431*cdf0e10cSrcweir catch ( Throwable aExc ) {}; 1432*cdf0e10cSrcweir 1433*cdf0e10cSrcweir // stop thread 1434*cdf0e10cSrcweir this.interrupt(); 1435*cdf0e10cSrcweir } 1436*cdf0e10cSrcweir 1437*cdf0e10cSrcweir /// gets called when the connection dies 1438*cdf0e10cSrcweir public void disposing( /*IN*/ com.sun.star.lang.EventObject Source ) 1439*cdf0e10cSrcweir { 1440*cdf0e10cSrcweir // empty the OOoBean and cut the connection 1441*cdf0e10cSrcweir stopOOoConnection(); 1442*cdf0e10cSrcweir } 1443*cdf0e10cSrcweir 1444*cdf0e10cSrcweir /// gets called when the user wants to terminate OOo 1445*cdf0e10cSrcweir public void queryTermination( /*IN*/ com.sun.star.lang.EventObject Event ) 1446*cdf0e10cSrcweir throws com.sun.star.frame.TerminationVetoException 1447*cdf0e10cSrcweir { 1448*cdf0e10cSrcweir // disallow termination of OOo while a OOoBean exists 1449*cdf0e10cSrcweir throw new com.sun.star.frame.TerminationVetoException(); 1450*cdf0e10cSrcweir } 1451*cdf0e10cSrcweir 1452*cdf0e10cSrcweir /// gets called when OOo terminates 1453*cdf0e10cSrcweir public void notifyTermination( /*IN*/ com.sun.star.lang.EventObject Event ) 1454*cdf0e10cSrcweir { 1455*cdf0e10cSrcweir // empty the OOoBean and cut the connection 1456*cdf0e10cSrcweir stopOOoConnection(); 1457*cdf0e10cSrcweir } 1458*cdf0e10cSrcweir 1459*cdf0e10cSrcweir /// watching the connection 1460*cdf0e10cSrcweir public void run() 1461*cdf0e10cSrcweir { 1462*cdf0e10cSrcweir dbgPrint( "EventListener(" + aTag + ").run()" ); 1463*cdf0e10cSrcweir 1464*cdf0e10cSrcweir // remote call might hang => watch try 1465*cdf0e10cSrcweir CallWatchThread aCallWatchThread = 1466*cdf0e10cSrcweir new CallWatchThread( nOOoCallTimeOut, "EventListener(" + aTag + ")" ); 1467*cdf0e10cSrcweir 1468*cdf0e10cSrcweir // continue to trying to connect the OOo instance 1469*cdf0e10cSrcweir long n = 0; 1470*cdf0e10cSrcweir while ( isInterrupted() == false 1471*cdf0e10cSrcweir && iConnection != null 1472*cdf0e10cSrcweir && iConnection.getComponentContext() != null ) 1473*cdf0e10cSrcweir { 1474*cdf0e10cSrcweir dbgPrint( "EventListener(" + aTag + ").running() #" + ++n ); 1475*cdf0e10cSrcweir 1476*cdf0e10cSrcweir // still alive? 1477*cdf0e10cSrcweir com.sun.star.lang.XMultiComponentFactory xServiceManager = null; 1478*cdf0e10cSrcweir try 1479*cdf0e10cSrcweir { 1480*cdf0e10cSrcweir // an arbitrary (but cheap) call into OOo 1481*cdf0e10cSrcweir xServiceManager = iConnection.getComponentContext().getServiceManager(); 1482*cdf0e10cSrcweir 1483*cdf0e10cSrcweir // call successfully performed, restart watch for next loop 1484*cdf0e10cSrcweir try 1485*cdf0e10cSrcweir { 1486*cdf0e10cSrcweir aCallWatchThread.restart(); 1487*cdf0e10cSrcweir } 1488*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 1489*cdf0e10cSrcweir { 1490*cdf0e10cSrcweir // ignore late interrupt 1491*cdf0e10cSrcweir } 1492*cdf0e10cSrcweir } 1493*cdf0e10cSrcweir catch ( java.lang.RuntimeException aExc ) 1494*cdf0e10cSrcweir { 1495*cdf0e10cSrcweir // hung 1496*cdf0e10cSrcweir OfficeConnection iDeadConn = iConnection; 1497*cdf0e10cSrcweir iConnection = null; 1498*cdf0e10cSrcweir iDeadConn.dispose(); 1499*cdf0e10cSrcweir } 1500*cdf0e10cSrcweir 1501*cdf0e10cSrcweir // sleep 1502*cdf0e10cSrcweir try { 1503*cdf0e10cSrcweir sleep(nOOoCheckCycle); 1504*cdf0e10cSrcweir } 1505*cdf0e10cSrcweir catch ( java.lang.InterruptedException aExc ) 1506*cdf0e10cSrcweir { 1507*cdf0e10cSrcweir dbgPrint("EventListener(" + aTag + ") interupted."); 1508*cdf0e10cSrcweir //thread can be ended by EvendListener.end(); 1509*cdf0e10cSrcweir break; 1510*cdf0e10cSrcweir } 1511*cdf0e10cSrcweir } 1512*cdf0e10cSrcweir } 1513*cdf0e10cSrcweir } 1514*cdf0e10cSrcweir 1515*cdf0e10cSrcweir } 1516*cdf0e10cSrcweir 1517*cdf0e10cSrcweir 1518*cdf0e10cSrcweir 1519