com.sun.star.frame.XDesktop Java Examples

The following examples show how to use com.sun.star.frame.XDesktop. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractOfficeApplication.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns desktop service of the application.
 * 
 * @return desktop service of the application
 * 
 * @throws OfficeApplicationException if the desktop service is not available
 * 
 * @author Andreas Bröker
 */
public IDesktopService getDesktopService() throws OfficeApplicationException {
  try {
    if (officeConnection == null)
      throw new OfficeApplicationException("Application is not active.");

    if (desktopService == null) {
      Object service = officeConnection.createService("com.sun.star.frame.Desktop");
      XDesktop desktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, service);
      desktopService = new DesktopService(desktop, officeConnection);
    }
    return desktopService;
  }
  catch (Exception exception) {
    OfficeApplicationException officeApplicationException = new OfficeApplicationException(exception.getMessage());
    officeApplicationException.initCause(exception);
    throw officeApplicationException;
  }
}
 
Example #2
Source File: DocumentService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns current documents of an application.
 * 
 * @return documents of an application
 * 
 * @throws DocumentException if the documents cannot be provided
 * 
 * @author Markus Krüger
 * @date 11.11.2008
 */
public static IDocument[] getCurrentDocuments(IServiceProvider serviceProvider)
    throws DocumentException {
  try {
    if (serviceProvider == null)
      return new IDocument[0];
    Object desktop = serviceProvider.createService("com.sun.star.frame.Desktop"); //$NON-NLS-1$
    XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
    XEnumeration aktComponents = xDesktop.getComponents().createEnumeration();
    List arrayList = new ArrayList();
    while (aktComponents.hasMoreElements()) {
      Any a = (Any) aktComponents.nextElement();
      arrayList.add(DocumentLoader.getDocument((XComponent) a.getObject(), serviceProvider, null));
    }
    IDocument[] documents = new IDocument[arrayList.size()];
    documents = (IDocument[]) arrayList.toArray(documents);
    return documents;
  }
  catch (Exception exception) {
    throw new DocumentException(exception);
  }
}
 
Example #3
Source File: DocumentService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns current number of documents of an application.
 * 
 * @param serviceProvider the serviceProvider to be used
 * 
 * @return number documents of an application
 * 
 * @author Markus Krüger
 * @date 11.11.2008
 */
public static int getCurrentDocumentCount(IServiceProvider serviceProvider)
    throws DocumentException {
  try {
    int i = 0;
    if (serviceProvider == null)
      return i;
    Object desktop = serviceProvider.createService("com.sun.star.frame.Desktop"); //$NON-NLS-1$
    XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
    XEnumeration aktComponents = xDesktop.getComponents().createEnumeration();
    while (aktComponents.hasMoreElements()) {
      aktComponents.nextElement();
      i++;
    }
    return i;
  }
  catch (Exception exception) {
    throw new DocumentException(exception);
  }
}
 
Example #4
Source File: ManagedOfficeProcess.java    From kkFileViewOfficeEdit with Apache License 2.0 5 votes vote down vote up
private void doStopProcess() {
	try {
		XDesktop desktop = OfficeUtils.cast(XDesktop.class, connection.getService(OfficeUtils.SERVICE_DESKTOP));
		desktop.terminate();
	} catch (DisposedException disposedException) {
		// expected
	} catch (Exception exception) {
		// in case we can't get hold of the desktop
		doTerminateProcess();
	}
	doEnsureProcessExited();
}
 
Example #5
Source File: ManagedOfficeProcess.java    From kkFileView with Apache License 2.0 5 votes vote down vote up
private void doStopProcess() {
	try {
		XDesktop desktop = OfficeUtils.cast(XDesktop.class, connection.getService(OfficeUtils.SERVICE_DESKTOP));
		desktop.terminate();
	} catch (DisposedException disposedException) {
		// expected
	} catch (Exception exception) {
		// in case we can't get hold of the desktop
		doTerminateProcess();
	}
	doEnsureProcessExited();
}
 
Example #6
Source File: DocumentHelper.java    From libreoffice-starter-extension with MIT License 5 votes vote down vote up
/** Returns the curerent XDesktop */
public static XDesktop getCurrentDesktop(XComponentContext xContext) {
	XMultiComponentFactory xMCF = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class,
			xContext.getServiceManager());
       Object desktop = null;
	try {
		desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
	} catch (Exception e) {
		return null;
	}
       return (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop);
}
 
Example #7
Source File: ManagedOfficeProcess.java    From wenku with MIT License 5 votes vote down vote up
private void doStopProcess() {
	try {
		XDesktop desktop = OfficeUtils.cast(XDesktop.class, connection.getService(OfficeUtils.SERVICE_DESKTOP));
		desktop.terminate();
	} catch (DisposedException disposedException) {
		// expected
	} catch (Exception exception) {
		// in case we can't get hold of the desktop
		doTerminateProcess();
	}
	doEnsureProcessExited();
}
 
Example #8
Source File: ServiceInterfaceSupplier.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the XDesktop interface from the OpenOffice.org desktop service.
 * 
 * @param xMultiServiceFactory factory in order to construct the service
 * 
 * @return XDesktop interface from the OpenOffice.org desktop service
 * 
 * @throws Exception if any error occurs
 */
public static XDesktop getXDesktop(XMultiServiceFactory xMultiServiceFactory) throws Exception {
	Object service = xMultiServiceFactory.createInstance("com.sun.star.frame.Desktop");
	if(service != null) {
		return (XDesktop)UnoRuntime.queryInterface(XDesktop.class, service);
	}
	else {
		return null;
	}
}
 
Example #9
Source File: ServiceInterfaceSupplier.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the XDesktop interface from the OpenOffice.org desktop service.
 * 
 * @param componentContext component context to be used
 * 
 * @return XDesktop interface from the OpenOffice.org desktop service
 * 
 * @throws Exception if any error occurs
 */
public static XDesktop getXDesktop(XComponentContext componentContext) throws Exception {
	Object service = componentContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", componentContext);
	if(service != null) {
		return (XDesktop)UnoRuntime.queryInterface(XDesktop.class, service);
	}
	else {
		return null;
	}
}
 
Example #10
Source File: BootstrapConnector.java    From yarg with Apache License 2.0 5 votes vote down vote up
/**
 * Disconnects from an OOo server using the connection string from the
 * previous connect.
 * 
 * If there has been no previous connect, the disconnects does nothing.
 * 
 * If there has been a previous connect, disconnect tries to terminate
 * the OOo server and kills the OOo server process the connect started.
 */
public void disconnect() {

    if (oooConnectionString == null)
        return;

    // call office to terminate itself
    try {
        // get local context
        XComponentContext xLocalContext = getLocalContext();

        // create a URL resolver
        XUnoUrlResolver xUrlResolver = UnoUrlResolver.create(xLocalContext);

        // get remote context
        XComponentContext xRemoteContext = getRemoteContext(xUrlResolver);

        // get desktop to terminate office
        Object desktop = xRemoteContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop",xRemoteContext);
        XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);
        xDesktop.terminate();
    }
    catch (Exception e) {
        // Bad luck, unable to terminate office
    }

    oooServer.kill();
    oooConnectionString = null;
}
 
Example #11
Source File: TerminationOpenoffice.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Gets the current component.
 * @return the current component
 * @throws Exception
 *             the exception
 */
public static XComponent getCurrentComponent() throws Exception {
	XComponentContext xRemoteContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
	// XComponentContext xRemoteContext =
	// com.sun.star.comp.helper.Bootstrap.bootstrap();

	XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager();

	Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xRemoteContext); //$NON-NLS-1$

	XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);

	XComponent currentComponent = xDesktop.getCurrentComponent();

	return currentComponent;
}
 
Example #12
Source File: TerminationOpenoffice.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Gets the current component.
 * @return the current component
 * @throws Exception
 *             the exception
 */
public static XComponent getCurrentComponent() throws Exception {
	XComponentContext xRemoteContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
	// XComponentContext xRemoteContext =
	// com.sun.star.comp.helper.Bootstrap.bootstrap();

	XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager();

	Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xRemoteContext); //$NON-NLS-1$

	XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop);

	XComponent currentComponent = xDesktop.getCurrentComponent();

	return currentComponent;
}
 
Example #13
Source File: OfficeResourceProvider.java    From yarg with Apache License 2.0 4 votes vote down vote up
protected XDesktop createDesktop() throws com.sun.star.uno.Exception {
    Object o = xComponentContext.getServiceManager().createInstanceWithContext(
            "com.sun.star.frame.Desktop", xComponentContext);
    return as(XDesktop.class, o);
}
 
Example #14
Source File: DesktopService.java    From noa-libre with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructs new DesktopService.
 * 
 * @param xDesktop OpenOffice.org XDesktop interface to be used
 * @param officeConnection connection to OpenOffice.org to be used
 * @param preventTermination indicates if the termination should be prevented
 * 
 * @throws IllegalArgumentException if the submitted OpenOffice.org XDesktop interface or the connection to OpenOffice.org
 * is not valid
 * 
 * @author Markus Krüger
 */
public DesktopService(XDesktop xDesktop, IOfficeConnection officeConnection, boolean preventTermination) throws IllegalArgumentException {
  if(xDesktop == null)
    throw new IllegalArgumentException("The submitted OpenOffice.org XDesktop interface is not valid.");
  this.xDesktop = xDesktop;
  
  if(officeConnection == null)
    throw new IllegalArgumentException("The submitted connection to OpenOffice.org is not valid.");
  this.officeConnection = officeConnection; 
  if(preventTermination)
    activateTerminationPrevention();
}
 
Example #15
Source File: DesktopService.java    From noa-libre with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Constructs new DesktopService.
 * 
 * @param xDesktop OpenOffice.org XDesktop interface to be used
 * @param officeConnection connection to OpenOffice.org to be used
 * 
 * @throws IllegalArgumentException if the submitted OpenOffice.org XDesktop interface or the connection to OpenOffice.org
 * is not valid
 * 
 * @author Andreas Bröker
 * @author Markus Krüger
 */
public DesktopService(XDesktop xDesktop, IOfficeConnection officeConnection) throws IllegalArgumentException {
  this(xDesktop,officeConnection,false);
}