forked from amazingfate/loongoffice
2009-06-30 08:58:13 +0200 fs r273488 : merging latest changes from CWS dba32c 2009-06-29 11:40:42 +0200 oj r273459 : #i101652# fix token handling 2009-06-26 09:27:30 +0200 oj r273394 : #i101994# wrong condition checked 2009-06-22 12:09:04 +0200 fs r273210 : merging latest changes from CWS dba32c 2009-06-18 11:01:06 +0200 fs r273108 : merge latest changes from CWS dba32c 2009-06-17 14:19:33 +0200 oj r273072 : handle images at the correct position 2009-06-17 13:37:19 +0200 oj r273067 : compile error 2009-06-17 13:35:58 +0200 oj r273066 : #i102201# handle images 2009-06-17 13:27:21 +0200 oj r273065 : #i80917# disable checkbox for internal copy 2009-06-17 13:25:38 +0200 oj r273064 : #i80917# disable checkbox for internal copy 2009-06-15 12:59:16 +0200 fs r272978 : merging latest changes from CWS dba32c 2009-06-15 10:45:58 +0200 fs r272967 : CWS-TOOLING: rebase CWS dba32d to trunk@272827 (milestone: DEV300:m50) 2009-06-15 08:41:05 +0200 fs r272960 : merging changes from CWS dba32c (resulting from rebasing dba32c to m50) 2009-06-03 12:22:32 +0200 fs r272554 : merging latest changes from CWS dba32c 2009-06-03 11:11:27 +0200 fs r272549 : #i100818# special treatment for DataAwareness not needed anymore 2009-06-03 11:07:01 +0200 fs r272548 : #i10000# removed package declaration 2009-06-03 09:21:03 +0200 oj r272537 : #i93465# save window states 2009-06-03 08:56:25 +0200 oj r272535 : solve compiler warnings 2009-06-03 08:55:02 +0200 oj r272534 : #i102295# export shapes i the first cell 2009-06-03 07:35:18 +0200 oj r272533 : #i101994# check for - and + prefix 2009-06-03 06:51:38 +0200 oj r272531 : #i101463# use uncomposed table name 2009-06-03 06:33:06 +0200 oj r272530 : #i102019# word corrected 2009-06-02 14:58:28 +0200 fs r272507 : #i102443# call initializeParser from LoadFinished 2009-06-02 14:30:10 +0200 oj r272504 : #i102019# introduce static ints 2009-06-02 13:51:02 +0200 oj r272501 : #i102439# wrong method used 2009-06-02 13:44:09 +0200 fs r272500 : #i102440# when tampering with Order/GroupBy, reset the cached columns 2009-06-02 10:53:01 +0200 fs r272487 : #i102234# preserve the original filter when using a 0=1 filter 2009-06-02 10:21:21 +0200 oj r272486 : #i100535# handle time values as float 2009-06-02 10:19:07 +0200 fs r272485 : merging latest changes from CWS dba32c 2009-05-29 16:00:15 +0200 fs r272467 : merging latest changes from dba32c 2009-05-29 15:31:25 +0200 fs r272462 : merging latest changes from dba32c 2009-05-29 10:58:03 +0200 oj r272438 : #101135# export embedded-text 2009-05-29 08:17:57 +0200 oj r272431 : #i80917# make attribute not optional 2009-05-29 08:17:32 +0200 oj r272430 : remoe unused token 2009-05-29 07:17:15 +0200 oj r272429 : #i80917# make attribute not optional 2009-05-28 12:48:14 +0200 oj r272401 : #i102201# insert images in context menu 2009-05-28 12:47:44 +0200 oj r272400 : #i80917# add new attribute to handle first line 2009-05-28 12:16:12 +0200 oj r272397 : #i96134# add / to path when it doesn't exist 2009-05-28 12:11:08 +0200 oj r272390 : #i80917# add new attribute to handle first line 2009-05-28 11:33:35 +0200 oj r272388 : #i101652# add new checkbox to handle header line as column names 2009-05-28 11:30:15 +0200 oj r272387 : #i101652# add localize 2009-05-28 11:15:53 +0200 oj r272386 : merge from dba32c 2009-05-28 09:08:25 +0200 fs r272378 : merged a build fix from CWS dba32c
234 lines
8.0 KiB
Java
234 lines
8.0 KiB
Java
/*************************************************************************
|
|
*
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
*
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
|
*
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
*
|
|
* $RCSfile: DocumentBasedExample.java,v $
|
|
* $Revision: 1.4 $
|
|
*
|
|
* This file is part of OpenOffice.org.
|
|
*
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
* only, as published by the Free Software Foundation.
|
|
*
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License version 3 for more details
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
* <http://www.openoffice.org/license.html>
|
|
* for a copy of the LGPLv3 License.
|
|
*
|
|
************************************************************************/
|
|
package org.openoffice.sdk.forms;
|
|
|
|
import com.sun.star.bridge.XUnoUrlResolver;
|
|
import com.sun.star.lang.XMultiComponentFactory;
|
|
import com.sun.star.uno.UnoRuntime;
|
|
import com.sun.star.uno.XComponentContext;
|
|
import com.sun.star.util.XCloseable;
|
|
|
|
public abstract class DocumentBasedExample implements com.sun.star.lang.XEventListener
|
|
{
|
|
/// the intial remote context from the office
|
|
protected XComponentContext m_xCtx;
|
|
/// our current test document
|
|
protected DocumentHelper m_document;
|
|
protected FormLayer m_formLayer;
|
|
protected DocumentType m_documentType;
|
|
|
|
/** Creates a new instance of DocumentBasedExample */
|
|
public DocumentBasedExample( DocumentType documentType )
|
|
{
|
|
bootstrapUNO();
|
|
m_documentType = documentType;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
private void bootstrapUNO()
|
|
{
|
|
try
|
|
{
|
|
/*
|
|
final XComponentContext componentContext = com.sun.star.comp.helper.Bootstrap.
|
|
createInitialComponentContext( null );
|
|
final XMultiComponentFactory localServiceManager = componentContext.getServiceManager();
|
|
|
|
final XUnoUrlResolver urlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(
|
|
XUnoUrlResolver.class, localServiceManager.createInstanceWithContext(
|
|
"com.sun.star.bridge.UnoUrlResolver", componentContext) );
|
|
|
|
final String connectStr = "uno:pipe,name=<pipename>;urp;StarOffice.ComponentContext";
|
|
final Object initialObject = urlResolver.resolve( connectStr );
|
|
|
|
m_xCtx = (XComponentContext)UnoRuntime.queryInterface( XComponentContext.class,
|
|
initialObject );
|
|
*/
|
|
|
|
// get the remote office component context
|
|
m_xCtx = com.sun.star.comp.helper.Bootstrap.bootstrap();
|
|
System.out.println("Connected to a running office ...");
|
|
}
|
|
catch (java.lang.Exception e)
|
|
{
|
|
e.printStackTrace( System.err );
|
|
System.exit(1);
|
|
}
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** main method for running the sample
|
|
*/
|
|
public void run( String argv[] )
|
|
{
|
|
try
|
|
{
|
|
// collect whatever parameters were given
|
|
collectParameters( argv );
|
|
|
|
// prepare our sample document
|
|
prepareDocument();
|
|
|
|
// switch the document view's form layer to alive mode
|
|
m_document.getCurrentView().toggleFormDesignMode();
|
|
onFormsAlive();
|
|
|
|
// grab the focus to the first control
|
|
m_document.getCurrentView().grabControlFocus();
|
|
|
|
// ----------------------------------------------
|
|
// wait for the user to confirm that we can exit
|
|
if ( waitForUserInput() )
|
|
{
|
|
// clean up
|
|
cleanUp();
|
|
}
|
|
|
|
// if waitForUserInput returns false, the user closed the document manually - no need to do a clean up
|
|
// then
|
|
}
|
|
catch(com.sun.star.uno.Exception e)
|
|
{
|
|
System.out.println(e);
|
|
e.printStackTrace();
|
|
}
|
|
catch(java.lang.Exception e)
|
|
{
|
|
System.out.println(e);
|
|
e.printStackTrace();
|
|
}
|
|
|
|
System.exit(0);
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** collect the RuntimeArguments
|
|
*/
|
|
protected void collectParameters(String argv[])
|
|
{
|
|
// not interested in. Derived classes may want to use it.
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** prepares a new document to work with
|
|
*/
|
|
protected void prepareDocument() throws com.sun.star.uno.Exception, java.lang.Exception
|
|
{
|
|
m_document = DocumentHelper.blankDocument(m_xCtx, m_documentType);
|
|
m_document.getDocument( ).addEventListener( this );
|
|
m_formLayer = new FormLayer( m_document );
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** called when the form layer has been switched to alive mode
|
|
*/
|
|
protected void onFormsAlive()
|
|
{
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** performs any cleanup before exiting the program
|
|
*/
|
|
protected void cleanUp( ) throws java.lang.Exception
|
|
{
|
|
// do not listen at the document any longer
|
|
m_document.getDocument().removeEventListener( this );
|
|
|
|
// close the document
|
|
closeDocument();
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** closes our document, if we have an open one
|
|
*/
|
|
private void closeDocument()
|
|
{
|
|
try
|
|
{
|
|
// close our document
|
|
if ( m_document != null )
|
|
{
|
|
XCloseable closeDoc = (XCloseable)
|
|
UnoRuntime.queryInterface( XCloseable.class,
|
|
m_document.getDocument() );
|
|
if (closeDoc != null)
|
|
closeDoc.close( true );
|
|
else
|
|
m_document.getDocument().dispose();
|
|
}
|
|
}
|
|
catch ( com.sun.star.uno.Exception e )
|
|
{
|
|
e.printStackTrace( System.out );
|
|
}
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* internal methods */
|
|
/* ------------------------------------------------------------------ */
|
|
/** waits for the user to press a key (on the console where she started
|
|
the java program) or the document to be closed by the user.
|
|
|
|
@return <TRUE/> if the user pressed a key on the console,
|
|
<FALSE/> if she closed the document
|
|
*/
|
|
protected boolean waitForUserInput() throws java.lang.Exception
|
|
{
|
|
synchronized (this)
|
|
{
|
|
WaitForInput aWait = new WaitForInput( this );
|
|
aWait.start();
|
|
wait();
|
|
|
|
// if the waiter thread is done, the user pressed enter
|
|
boolean bKeyPressed = aWait.isDone();
|
|
if ( !bKeyPressed )
|
|
aWait.interrupt();
|
|
|
|
return bKeyPressed;
|
|
}
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* XEventListener overridables */
|
|
/* ------------------------------------------------------------------ */
|
|
public void disposing( com.sun.star.lang.EventObject eventObject )
|
|
{
|
|
if ( m_document.getDocument().equals( eventObject.Source ) )
|
|
{
|
|
// notify ourself that we can stop waiting for user input
|
|
synchronized (this)
|
|
{
|
|
notify();
|
|
}
|
|
}
|
|
}
|
|
}
|