/**************************************************************************/ /** provides a small wrapper around a document
*/ publicclass DocumentHelper
{ privatefinal XMultiServiceFactory m_orb; private XComponent m_documentComponent;
/* ------------------------------------------------------------------ */ /** retrieves the current view of the document @return theviewcomponent,queriedfortheinterfacedescribedbyaInterfaceClass
*/ public DocumentViewHelper getCurrentView( )
{ // get the model interface for the document
XModel xDocModel = UnoRuntime.queryInterface(XModel.class, m_documentComponent ); // get the current controller for the document - as a controller is tied to a view, // this gives us the currently active view for the document.
XController xController = xDocModel.getCurrentController();
/* ------------------------------------------------------------------ */ /** creates a new form which is a child of the given form components container
@paramxParentContainer Theparentcontainerforthenewform @paramsInitialName Theinitialnameoftheform.Maybenull,inthiscasethedefault(which isanimplementationdetail)applies.
*/ private XIndexContainer createSubForm( XIndexContainer xParentContainer, String sInitialName ) throws com.sun.star.uno.Exception
{ // create a new form
Object xNewForm = m_orb.createInstance( "com.sun.star.form.component.DataForm" );
// set the name if necessary if ( null != sInitialName )
{
XPropertySet xFormProps = dbfTools.queryPropertySet( xNewForm );
xFormProps.setPropertyValue( "Name", sInitialName );
}
// outta here return UnoRuntime.queryInterface( XIndexContainer.class, xNewForm );
}
/* ------------------------------------------------------------------ */ /** creates a new form which is a child of the given form components container
/* ------------------------------------------------------------------ */ /** creates a form which is a sibling of the given form @paramaForm Asinblingofthetobecreatedform.
@paramsInitialName Theinitialnameoftheform.Maybenull,inthiscasethedefault(which isanimplementationdetail)applies.
*/ public XIndexContainer createSiblingForm( Object aForm, String sInitialName ) throws com.sun.star.uno.Exception
{ // get the parent
XIndexContainer xContainer = (XIndexContainer)dbfTools.getParent(
aForm, XIndexContainer.class ); // append a new form to this parent container return createSubForm( xContainer, sInitialName );
}
/* ------------------------------------------------------------------ */ /** returns a URL which can be used to create a document of a certain type
*/ publicstatic String getDocumentFactoryURL( DocumentType eType )
{ if ( eType == DocumentType.WRITER ) return"private:factory/swriter"; if ( eType == DocumentType.CALC ) return"private:factory/scalc"; if ( eType == DocumentType.DRAWING ) return"private:factory/sdraw"; if ( eType == DocumentType.XMLFORM ) return"private:factory/swriter?slot=21053"; return"private:factory/swriter";
}
/* ------------------------------------------------------------------ */ /** retrieves a com.sun.star.drawing.DrawPage of the document, denoted by index *@paramindex *theindexofthedrawpage *@throws *com.sun.star.lang.IndexOutOfBoundsException *com.sun.star.lang.WrappedTargetException
*/ protected XDrawPage getDrawPage( int index ) throws com.sun.star.lang.IndexOutOfBoundsException, com.sun.star.lang.WrappedTargetException
{
XDrawPagesSupplier xSuppPages = UnoRuntime.queryInterface(
XDrawPagesSupplier.class, getDocument() );
XDrawPages xPages = xSuppPages.getDrawPages();
return UnoRuntime.queryInterface( XDrawPage.class, xPages.getByIndex( index ) );
}
/* ------------------------------------------------------------------ */ /** retrieves the <type scope="com.sun.star.drawing">DrawPage</type> of the document
*/ protected XDrawPage getMainDrawPage( ) throws com.sun.star.uno.Exception
{
XDrawPage xReturn;
// in case of a Writer document, this is rather easy: simply ask the XDrawPageSupplier
XDrawPageSupplier xSuppPage = UnoRuntime.queryInterface(
XDrawPageSupplier.class, getDocument() ); if ( null != xSuppPage )
xReturn = xSuppPage.getDrawPage(); else
{ // the model itself is no draw page supplier - okay, it may be a Writer or Calc document // (or any other multi-page document)
XDrawPagesSupplier xSuppPages = UnoRuntime.queryInterface(
XDrawPagesSupplier.class, getDocument() );
XDrawPages xPages = xSuppPages.getDrawPages();
// Note that this is no really error-proof code: If the document model does not support the // XDrawPagesSupplier interface, or if the pages collection returned is empty, this will break.
}
return xReturn;
}
/* ------------------------------------------------------------------ */ /** retrieves the root of the hierarchy of form components
*/ protected XNameContainer getFormComponentTreeRoot( ) throws com.sun.star.uno.Exception
{
XFormsSupplier xSuppForms = UnoRuntime.queryInterface(
XFormsSupplier.class, getMainDrawPage( ) );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.